mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 1418245 - Move @-moz-document matching function out of css::DocumentRule. r=TYLin
MozReview-Commit-ID: 81dCiFosF0V --HG-- extra : rebase_source : 9852380c896530538e2b5b1415513cedb4b2e5e1
This commit is contained in:
parent
204ca9c9df
commit
1dbd7f57c6
@ -10,6 +10,8 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
using namespace mozilla::css;
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(CSSMozDocumentRule, css::ConditionRule)
|
||||
NS_IMPL_RELEASE_INHERITED(CSSMozDocumentRule, css::ConditionRule)
|
||||
|
||||
@ -54,5 +56,52 @@ CSSMozDocumentRule::WrapObject(JSContext* aCx,
|
||||
return CSSMozDocumentRuleBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
bool
|
||||
CSSMozDocumentRule::Match(nsIDocument* aDoc,
|
||||
nsIURI* aDocURI,
|
||||
const nsACString& aDocURISpec,
|
||||
const nsACString& aPattern,
|
||||
URLMatchingFunction aUrlMatchingFunction)
|
||||
{
|
||||
switch (aUrlMatchingFunction) {
|
||||
case URLMatchingFunction::eURL: {
|
||||
if (aDocURISpec == aPattern) {
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
case URLMatchingFunction::eURLPrefix: {
|
||||
if (StringBeginsWith(aDocURISpec, aPattern)) {
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
case URLMatchingFunction::eDomain: {
|
||||
nsAutoCString host;
|
||||
if (aDocURI) {
|
||||
aDocURI->GetHost(host);
|
||||
}
|
||||
int32_t lenDiff = host.Length() - aPattern.Length();
|
||||
if (lenDiff == 0) {
|
||||
if (host == aPattern) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (StringEndsWith(host, aPattern) &&
|
||||
host.CharAt(lenDiff - 1) == '.') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case URLMatchingFunction::eRegExp: {
|
||||
NS_ConvertUTF8toUTF16 spec(aDocURISpec);
|
||||
NS_ConvertUTF8toUTF16 regex(aPattern);
|
||||
if (nsContentUtils::IsPatternMatching(spec, regex, aDoc)) {
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define mozilla_dom_CSSMozDocumentRule_h
|
||||
|
||||
#include "mozilla/css/GroupRule.h"
|
||||
#include "mozilla/css/URLMatchingFunction.h"
|
||||
#include "nsIDOMCSSMozDocumentRule.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -26,6 +27,12 @@ public:
|
||||
int32_t GetType() const final override { return css::Rule::DOCUMENT_RULE; }
|
||||
using Rule::GetType;
|
||||
|
||||
static bool Match(nsIDocument* aDoc,
|
||||
nsIURI* aDocURI,
|
||||
const nsACString& aDocURISpec,
|
||||
const nsACString& aPattern,
|
||||
css::URLMatchingFunction aUrlMatchingFunction);
|
||||
|
||||
// nsIDOMCSSGroupingRule interface
|
||||
NS_DECL_NSIDOMCSSGROUPINGRULE
|
||||
|
||||
|
@ -2737,8 +2737,8 @@ Gecko_DocumentRule_UseForPresentation(RawGeckoPresContextBorrowed aPresContext,
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
}
|
||||
|
||||
return css::DocumentRule::UseForPresentation(doc, docURI, docURISpec,
|
||||
*aPattern, aURLMatchingFunction);
|
||||
return CSSMozDocumentRule::Match(doc, docURI, docURISpec, *aPattern,
|
||||
aURLMatchingFunction);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -591,7 +591,7 @@ DocumentRule::UseForPresentation(nsPresContext* aPresContext)
|
||||
}
|
||||
|
||||
for (URL *url = mURLs; url; url = url->next) {
|
||||
if (UseForPresentation(doc, docURI, docURISpec, url->url, url->func)) {
|
||||
if (Match(doc, docURI, docURISpec, url->url, url->func)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -599,53 +599,6 @@ DocumentRule::UseForPresentation(nsPresContext* aPresContext)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
DocumentRule::UseForPresentation(nsIDocument* aDoc,
|
||||
nsIURI* aDocURI,
|
||||
const nsACString& aDocURISpec,
|
||||
const nsACString& aPattern,
|
||||
URLMatchingFunction aUrlMatchingFunction)
|
||||
{
|
||||
switch (aUrlMatchingFunction) {
|
||||
case URLMatchingFunction::eURL: {
|
||||
if (aDocURISpec == aPattern) {
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
case URLMatchingFunction::eURLPrefix: {
|
||||
if (StringBeginsWith(aDocURISpec, aPattern)) {
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
case URLMatchingFunction::eDomain: {
|
||||
nsAutoCString host;
|
||||
if (aDocURI) {
|
||||
aDocURI->GetHost(host);
|
||||
}
|
||||
int32_t lenDiff = host.Length() - aPattern.Length();
|
||||
if (lenDiff == 0) {
|
||||
if (host == aPattern) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (StringEndsWith(host, aPattern) &&
|
||||
host.CharAt(lenDiff - 1) == '.') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case URLMatchingFunction::eRegExp: {
|
||||
NS_ConvertUTF8toUTF16 spec(aDocURISpec);
|
||||
NS_ConvertUTF8toUTF16 regex(aPattern);
|
||||
if (nsContentUtils::IsPatternMatching(spec, regex, aDoc)) {
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DocumentRule::URL::~URL()
|
||||
{
|
||||
NS_CSS_DELETE_LIST_MEMBER(DocumentRule::URL, this, next);
|
||||
|
@ -121,12 +121,6 @@ public:
|
||||
|
||||
bool UseForPresentation(nsPresContext* aPresContext);
|
||||
|
||||
static bool UseForPresentation(nsIDocument* aDoc,
|
||||
nsIURI* aDocURI,
|
||||
const nsACString& aDocURISpec,
|
||||
const nsACString& aPattern,
|
||||
URLMatchingFunction aUrlMatchingFunction);
|
||||
|
||||
struct URL {
|
||||
URLMatchingFunction func;
|
||||
nsCString url;
|
||||
|
Loading…
Reference in New Issue
Block a user