Skip to content

Commit

Permalink
#469, #399: more adblock hosts, faster StringBegins/End, any-link, ba…
Browse files Browse the repository at this point in the history
…se/srcdoc M1247359 M843579 M1238804
  • Loading branch information
classilla committed Mar 19, 2018
1 parent 8f266f3 commit 41675e9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 17 deletions.
2 changes: 2 additions & 0 deletions caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand All @@ -930,6 +931,7 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
BLOK("stats.cloudwp.io") ||

BLOK("ap.lijit.com") ||
BLOK("ce.lijit.com") ||

BLOK("tlx.3lift.com") ||

Expand Down
25 changes: 20 additions & 5 deletions dom/base/nsIDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,33 @@ class nsIDocument : public nsINode
return group.forget();
}

/**
* 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* GetFallbackBaseURI() const
{
if (mIsSrcdocDocument && mParentDocument) {
return mParentDocument->GetDocBaseURI();
}
return mDocumentURI;
}

/**
* Return the base URI for relative URIs in the document (the document uri
* unless it's overridden by SetBaseURI, HTML <base> 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.
* 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 (mIsSrcdocDocument && mParentDocument) {
return mParentDocument->GetDocBaseURI();
if (mDocumentBaseURI) {
return mDocumentBaseURI;
}
return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI;
return GetFallbackBaseURI();
}
virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override;

Expand Down
5 changes: 3 additions & 2 deletions dom/html/HTMLSharedElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ SetBaseURIUsingFirstBaseWithHref(nsIDocument* aDocument, nsIContent* aMustMatch)
return;
}

// Resolve the <base> element's href relative to our document URI
// Resolve the <base> element's href relative to our document's
// fallback base URI.
nsAutoString href;
child->GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);

nsCOMPtr<nsIURI> 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);
Expand Down
7 changes: 5 additions & 2 deletions layout/inspector/inDOMUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,10 +1176,13 @@ GetStatesForPseudoClass(const nsAString& aStatePseudo)

nsCOMPtr<nsIAtom> 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
Expand Down
2 changes: 2 additions & 0 deletions layout/style/nsCSSPseudoClassList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions xpcom/string/nsReadableUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions xpcom/string/nsReadableUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 41675e9

Please sign in to comment.