From 41675e9698535395a9811935949a5762060b04d8 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Sun, 18 Mar 2018 20:23:52 -0700 Subject: [PATCH] #469, #399: more adblock hosts, faster StringBegins/End, any-link, base/srcdoc M1247359 M843579 M1238804 --- caps/nsScriptSecurityManager.cpp | 2 ++ dom/base/nsIDocument.h | 27 ++++++++++++++---- dom/html/HTMLSharedElement.cpp | 5 ++-- layout/inspector/inDOMUtils.cpp | 7 +++-- layout/style/nsCSSPseudoClassList.h | 2 ++ xpcom/string/nsReadableUtils.cpp | 44 +++++++++++++++++++++++++++++ xpcom/string/nsReadableUtils.h | 16 +++++------ 7 files changed, 85 insertions(+), 18 deletions(-) diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 62b1b8ea6..a1e644e93 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -915,6 +915,7 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal, BLOK("se.monetate.net") || BLOK("ad.crwdcntrl.net") || + BLOK("bcp.crwdcntrl.net") || BLOK("tags.crwdcntrl.net") || BLOK("cdn.nsstatic.net") || @@ -930,6 +931,7 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal, BLOK("stats.cloudwp.io") || BLOK("ap.lijit.com") || + BLOK("ce.lijit.com") || BLOK("tlx.3lift.com") || diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index c74f96dbd..ec9480b10 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -347,17 +347,32 @@ public: } /** - * Return the base URI for relative URIs in the document (the document uri - * unless it's overridden by SetBaseURI, HTML tags, etc.). The - * returned URI could be null if there is no document URI. If the document - * is a srcdoc document, return the parent document's base URL. + * Return the fallback base URL for this document, as defined in the HTML + * specification. Note that this can return null if there is no document URI. + * + * XXXbz: This doesn't implement the bits for about:blank yet. */ - nsIURI* GetDocBaseURI() const + nsIURI* GetFallbackBaseURI() const { if (mIsSrcdocDocument && mParentDocument) { return mParentDocument->GetDocBaseURI(); } - return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI; + return mDocumentURI; + } + + /** + * Return the base URI for relative URIs in the document (the document uri + * unless it's overridden by SetBaseURI, HTML tags, etc.). The + * returned URI could be null if there is no document URI. If the document is + * a srcdoc document and has no explicit base URL, return the parent + * document's base URL. + */ + nsIURI* GetDocBaseURI() const + { + if (mDocumentBaseURI) { + return mDocumentBaseURI; + } + return GetFallbackBaseURI(); } virtual already_AddRefed GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override; diff --git a/dom/html/HTMLSharedElement.cpp b/dom/html/HTMLSharedElement.cpp index 0b8099b4a..a2c6fc6d1 100644 --- a/dom/html/HTMLSharedElement.cpp +++ b/dom/html/HTMLSharedElement.cpp @@ -164,14 +164,15 @@ SetBaseURIUsingFirstBaseWithHref(nsIDocument* aDocument, nsIContent* aMustMatch) return; } - // Resolve the element's href relative to our document URI + // Resolve the element's href relative to our document's + // fallback base URI. nsAutoString href; child->GetAttr(kNameSpaceID_None, nsGkAtoms::href, href); nsCOMPtr newBaseURI; nsContentUtils::NewURIWithDocumentCharset( getter_AddRefs(newBaseURI), href, aDocument, - aDocument->GetDocumentURI()); + aDocument->GetFallbackBaseURI()); // Try to set our base URI. If that fails, try to set base URI to null nsresult rv = aDocument->SetBaseURI(newBaseURI); diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index 5f62252ae..f7f88fcbe 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -1176,10 +1176,13 @@ GetStatesForPseudoClass(const nsAString& aStatePseudo) nsCOMPtr atom = do_GetAtom(aStatePseudo); - // Ignore :moz-any-link so we don't give the element simultaneous + // Ignore :any-link so we don't give the element simultaneous // visited and unvisited style state if (nsCSSPseudoClasses::GetPseudoType(atom) == - nsCSSPseudoClasses::ePseudoClass_mozAnyLink) { + nsCSSPseudoClasses::ePseudoClass_mozAnyLink || +// XXX: this could be cleaned up. do it once it's building + nsCSSPseudoClasses::GetPseudoType(atom) == + nsCSSPseudoClasses::ePseudoClass_anyLink) { return EventStates(); } // Our array above is long enough that indexing into it with diff --git a/layout/style/nsCSSPseudoClassList.h b/layout/style/nsCSSPseudoClassList.h index bca620b5c..4883337c3 100644 --- a/layout/style/nsCSSPseudoClassList.h +++ b/layout/style/nsCSSPseudoClassList.h @@ -142,6 +142,8 @@ CSS_STATE_PSEUDO_CLASS(link, ":link", 0, "", NS_EVENT_STATE_UNVISITED) // what matches :link or :visited CSS_STATE_PSEUDO_CLASS(mozAnyLink, ":-moz-any-link", 0, "", NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED) +CSS_STATE_PSEUDO_CLASS(anyLink, ":any-link", 0, "", + NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED) CSS_STATE_PSEUDO_CLASS(visited, ":visited", 0, "", NS_EVENT_STATE_VISITED) CSS_STATE_PSEUDO_CLASS(active, ":active", 0, "", NS_EVENT_STATE_ACTIVE) diff --git a/xpcom/string/nsReadableUtils.cpp b/xpcom/string/nsReadableUtils.cpp index 879b4ef5c..d8904fe95 100644 --- a/xpcom/string/nsReadableUtils.cpp +++ b/xpcom/string/nsReadableUtils.cpp @@ -1026,6 +1026,17 @@ CountCharInReadable(const nsACString& aStr, char aChar) return count; } +bool +StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring) +{ + nsAString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, 0, sub_len).Equals(aSubstring); +} + bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, const nsStringComparator& aComparator) @@ -1038,6 +1049,17 @@ StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, return Substring(aSource, 0, sub_len).Equals(aSubstring, aComparator); } +bool +StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring) +{ + nsACString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, 0, sub_len).Equals(aSubstring); +} + bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, const nsCStringComparator& aComparator) @@ -1050,6 +1072,17 @@ StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, return Substring(aSource, 0, sub_len).Equals(aSubstring, aComparator); } +bool +StringEndsWith(const nsAString& aSource, const nsAString& aSubstring) +{ + nsAString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, src_len - sub_len, sub_len).Equals(aSubstring); +} + bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, const nsStringComparator& aComparator) @@ -1063,6 +1096,17 @@ StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, aComparator); } +bool +StringEndsWith(const nsACString& aSource, const nsACString& aSubstring) +{ + nsACString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, src_len - sub_len, sub_len).Equals(aSubstring); +} + bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring, const nsCStringComparator& aComparator) diff --git a/xpcom/string/nsReadableUtils.h b/xpcom/string/nsReadableUtils.h index 6a697d5ea..12b2e6746 100644 --- a/xpcom/string/nsReadableUtils.h +++ b/xpcom/string/nsReadableUtils.h @@ -386,18 +386,18 @@ uint32_t CountCharInReadable(const nsAString& aStr, uint32_t CountCharInReadable(const nsACString& aStr, char aChar); +bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring); bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, - const nsStringComparator& aComparator = - nsDefaultStringComparator()); + const nsStringComparator& aComparator); +bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring); bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, - const nsCStringComparator& aComparator = - nsDefaultCStringComparator()); + const nsCStringComparator& aComparator); +bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring); bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, - const nsStringComparator& aComparator = - nsDefaultStringComparator()); + const nsStringComparator& aComparator); +bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring); bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring, - const nsCStringComparator& aComparator = - nsDefaultCStringComparator()); + const nsCStringComparator& aComparator); const nsAFlatString& EmptyString(); const nsAFlatCString& EmptyCString();