Skip to content

Commit

Permalink
#433: M1390980 M1376306 M1390550 M1376825 M1380824 M1385272
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Sep 2, 2017
1 parent 71b8c3d commit 94d5cb1
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 10 deletions.
2 changes: 2 additions & 0 deletions accessible/generic/DocAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,8 @@ DocAccessible::UnbindFromDocument(Accessible* aAccessible)
mNodeToAccessibleMap.Get(aAccessible->GetNode()) == aAccessible)
mNodeToAccessibleMap.Remove(aAccessible->GetNode());

aAccessible->mStateFlags |= eIsNotInDocument;

// Update XPCOM part.
xpcAccessibleDocument* xpcDoc = GetAccService()->GetCachedXPCDocument(this);
if (xpcDoc)
Expand Down
10 changes: 9 additions & 1 deletion dom/base/nsDocumentEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,14 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
return EncodeToStringWithMaxLength(0, aOutputString);
}

static bool ParentIsTR(nsIContent* aContent) {
mozilla::dom::Element* parent = aContent->GetParentElement();
if (!parent) {
return false;
}
return parent->IsHTMLElement(nsGkAtoms::tr);
}

NS_IMETHODIMP
nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength,
nsAString& aOutputString)
Expand Down Expand Up @@ -1153,7 +1161,7 @@ nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength,
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
if (content && content->IsHTMLElement(nsGkAtoms::tr)) {
if (content && content->IsHTMLElement(nsGkAtoms::tr) && MOZ_LIKELY(!ParentIsTR(content))) {
nsINode* n = content;
if (!prevNode) {
// Went from a non-<tr> to a <tr>
Expand Down
23 changes: 22 additions & 1 deletion editor/libeditor/nsEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4771,6 +4771,24 @@ nsEditor::InitializeSelection(nsIDOMEventTarget* aFocusEventTarget)
return NS_OK;
}

class RepaintSelectionRunner final : public nsRunnable {
public:
explicit RepaintSelectionRunner(nsISelectionController* aSelectionController)
: mSelectionController(aSelectionController)
{
}

NS_IMETHOD Run() override
{
mSelectionController->RepaintSelection(
nsISelectionController::SELECTION_NORMAL);
return NS_OK;
}

private:
nsCOMPtr<nsISelectionController> mSelectionController;
};

NS_IMETHODIMP
nsEditor::FinalizeSelection()
{
Expand Down Expand Up @@ -4819,7 +4837,10 @@ nsEditor::FinalizeSelection()
selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
}

selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
// FinalizeSelection might be called from ContentRemoved even if selection
// isn't updated. So we need to call RepaintSelection after updated it.
nsContentUtils::AddScriptRunner(
new RepaintSelectionRunner(selCon));
return NS_OK;
}

Expand Down
6 changes: 5 additions & 1 deletion gfx/thebes/gfxMacPlatformFontList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ static void GetStringForNSString(const NSString *aSrc, nsAString& aDist)
// (It is not likely to encounter these on 10.4 or 10.5.)
if (mRequiresAAT && (FamilyName().EqualsLiteral("Songti SC") ||
FamilyName().EqualsLiteral("Songti TC") ||
FamilyName().EqualsLiteral("STSong"))) {
// Bug 1390980: on 10.11, the Kaiti fonts are also affected.
// Again, this is mostly here if someone copied them from a later Mac.
FamilyName().EqualsLiteral("Kaiti SC") ||
FamilyName().EqualsLiteral("Kaiti TC") ||
FamilyName().EqualsLiteral("STKaiti"))) {
charmap->ClearRange(0x0f8c, 0x0f8f);
}
}
Expand Down
92 changes: 85 additions & 7 deletions toolkit/components/downloads/ApplicationReputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "nsIArray.h"
#include "nsIApplicationReputation.h"
#include "nsIChannel.h"
#include "nsICryptoHash.h"
#include "nsIHttpChannel.h"
#include "nsIIOService.h"
#include "nsIPrefService.h"
Expand Down Expand Up @@ -168,8 +169,11 @@ class PendingLookup final : public nsIStreamListener,
nsresult aResult,
bool* aShouldBlock);

// Return the hex-encoded hash of the whole URI.
nsresult GetSpecHash(nsACString& aSpec, nsACString& hexEncodedHash);

// Strip url parameters, fragments, and user@pass fields from the URI spec
// using nsIURL. If aURI is not an nsIURL, returns the original nsIURI.spec.
// using nsIURL. Hash data URIs and return blob URIs unfiltered.
nsresult GetStrippedSpec(nsIURI* aUri, nsACString& spec);

// Escape '/' and '%' in certificate attribute values.
Expand Down Expand Up @@ -278,8 +282,11 @@ PendingDBLookup::LookupSpec(const nsACString& aSpec,
mAllowlistOnly = aAllowlistOnly;
nsresult rv = LookupSpecInternal(aSpec);
if (NS_FAILED(rv)) {
LOG(("Error in LookupSpecInternal"));
return mPendingLookup->OnComplete(false, NS_OK);
// XXX: We don't have xpcom/base/ErrorNames.* yet. When we do, consider
// redoing the patch from M1376036, but make the lookup DEBUG only since
// it isn't cheap.
LOG(("Error in LookupSpecInternal()"));
return mPendingLookup->LookupNext(); // ignore this lookup and move to next
}
// LookupSpecInternal has called nsIUrlClassifierCallback.lookup, which is
// guaranteed to call HandleEvent.
Expand Down Expand Up @@ -670,17 +677,84 @@ PendingLookup::StartLookup()
return rv;
}

nsresult
PendingLookup::GetSpecHash(nsACString& aSpec, nsACString& hexEncodedHash)
{
nsresult rv;

nsCOMPtr<nsICryptoHash> cryptoHash =
do_CreateInstance("@mozilla.org/security/hash;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = cryptoHash->Init(nsICryptoHash::SHA256);
NS_ENSURE_SUCCESS(rv, rv);

rv = cryptoHash->Update(reinterpret_cast<const uint8_t*>(aSpec.BeginReading()),
aSpec.Length());
NS_ENSURE_SUCCESS(rv, rv);

nsAutoCString binaryHash;
rv = cryptoHash->Finish(false, binaryHash);
NS_ENSURE_SUCCESS(rv, rv);

// This needs to match HexEncode() in Chrome's
// src/base/strings/string_number_conversions.cc
static const char* const hex = "0123456789ABCDEF";
hexEncodedHash.SetCapacity(2 * binaryHash.Length());
for (size_t i = 0; i < binaryHash.Length(); ++i) {
auto c = static_cast<const unsigned char>(binaryHash[i]);
hexEncodedHash.Append(hex[(c >> 4) & 0x0F]);
hexEncodedHash.Append(hex[c & 0x0F]);
}

return NS_OK;
}

nsresult
PendingLookup::GetStrippedSpec(nsIURI* aUri, nsACString& escaped)
{
if (NS_WARN_IF(!aUri)) {
return NS_ERROR_INVALID_ARG;
}

nsresult rv;
rv = aUri->GetScheme(escaped);
NS_ENSURE_SUCCESS(rv, rv);

if (escaped.EqualsLiteral("blob")) {
aUri->GetSpec(escaped);
LOG(("PendingLookup::GetStrippedSpec(): blob URL left unstripped as '%s' [this = %p]",
PromiseFlatCString(escaped).get(), this));
return NS_OK;

} else if (escaped.EqualsLiteral("data")) {
// Replace URI with "data:<everything before comma>,SHA256(<whole URI>)"
aUri->GetSpec(escaped);
int32_t comma = escaped.FindChar(',');
if (comma > -1 &&
static_cast<nsCString::size_type>(comma) < escaped.Length() - 1) {
MOZ_ASSERT(comma > 4, "Data URIs start with 'data:'");
nsAutoCString hexEncodedHash;
rv = GetSpecHash(escaped, hexEncodedHash);
if (NS_SUCCEEDED(rv)) {
escaped.Truncate(comma + 1);
escaped.Append(hexEncodedHash);
}
}

LOG(("PendingLookup::GetStrippedSpec(): data URL stripped to '%s' [this = %p]",
PromiseFlatCString(escaped).get(), this));
return NS_OK;
}

// If aURI is not an nsIURL, we do not want to check the lists or send a
// remote query.
nsresult rv;
nsCOMPtr<nsIURL> url = do_QueryInterface(aUri, &rv);
NS_ENSURE_SUCCESS(rv, rv);

rv = url->GetScheme(escaped);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
LOG(("PendingLookup::GetStrippedSpec(): scheme '%s' is not supported [this = %p]",
PromiseFlatCString(escaped).get(), this));
return rv;
}

nsCString temp;
rv = url->GetHostPort(temp);
Expand All @@ -695,6 +769,8 @@ PendingLookup::GetStrippedSpec(nsIURI* aUri, nsACString& escaped)
// nsIUrl.filePath starts with '/'
escaped.Append(temp);

LOG(("PendingLookup::GetStrippedSpec(): URL stripped to '%s' [this = %p]",
PromiseFlatCString(escaped).get(), this));
return NS_OK;
}

Expand Down Expand Up @@ -760,6 +836,7 @@ PendingLookup::OnComplete(bool shouldBlock, nsresult rv)
mTimeoutTimer = nullptr;
}

#if(0)
Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_SHOULD_BLOCK,
shouldBlock);
double t = (TimeStamp::Now() - mStartTime).ToMilliseconds();
Expand All @@ -769,6 +846,7 @@ PendingLookup::OnComplete(bool shouldBlock, nsresult rv)
} else {
LOG(("Application Reputation check passed in %f ms [this = %p]", t, this));
}
#endif
nsresult res = mCallback->OnComplete(shouldBlock, rv);
return res;
}
Expand Down

0 comments on commit 94d5cb1

Please sign in to comment.