Bug 1408235 part 1 - Move stylo checking logic into a separate function. r=heycam

MozReview-Commit-ID: 9fOyC4QUSDA

--HG--
extra : source : 024a940349c480c20d967e4e1e4ddd03fd4f05b3
This commit is contained in:
Xidorn Quan 2017-10-21 11:02:34 +11:00
parent 0e9020d337
commit 9808fc6a4b
3 changed files with 45 additions and 33 deletions

View File

@ -13615,29 +13615,6 @@ nsIDocument::ReportHasScrollLinkedEffect()
"ScrollLinkedEffectFound2");
}
#ifdef MOZ_STYLO
// URL-based blacklist for stylo.
static bool
ShouldUseGeckoBackend(nsIURI* aDocumentURI)
{
if (!aDocumentURI) {
return false;
}
bool isScheme = false;
if (NS_SUCCEEDED(aDocumentURI->SchemeIs("about", &isScheme))) {
nsAutoCString path;
aDocumentURI->GetFilePath(path);
// about:reader requires support of :scope pseudo-class so we have
// to use Gecko backend for now. See bug 1402094.
// This should be fixed by bug 1204818.
if (path.EqualsLiteral("reader")) {
return true;
}
}
return false;
}
#endif // MOZ_STYLO
void
nsIDocument::UpdateStyleBackendType()
{
@ -13648,16 +13625,9 @@ nsIDocument::UpdateStyleBackendType()
mStyleBackendType = StyleBackendType::Gecko;
#ifdef MOZ_STYLO
if (nsLayoutUtils::StyloEnabled()) {
// Disable stylo only for system principal. Other principals aren't
// able to use XUL by default, and the back door to enable XUL is
// mostly just for testing, which means they don't matter, and we
// shouldn't respect them at the same time.
if (!nsContentUtils::IsSystemPrincipal(NodePrincipal()) &&
!ShouldUseGeckoBackend(mDocumentURI) &&
!nsLayoutUtils::IsInStyloBlocklist(NodePrincipal())) {
mStyleBackendType = StyleBackendType::Servo;
}
if (nsLayoutUtils::StyloEnabled() &&
nsLayoutUtils::ShouldUseStylo(mDocumentURI, NodePrincipal())) {
mStyleBackendType = StyleBackendType::Servo;
}
#endif
}

View File

@ -8008,6 +8008,38 @@ nsLayoutUtils::Shutdown()
}
#ifdef MOZ_STYLO
/* static */
bool
nsLayoutUtils::ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal)
{
// Disable stylo for system principal because XUL hasn't been fully
// supported. Other principal aren't able to use XUL by default, and
// the back door to enable XUL is mostly just for testing, which means
// they don't matter, and we shouldn't respect them at the same time.
if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
return false;
}
// Check any internal page which we need to explicitly blacklist.
if (aDocumentURI) {
bool isAbout = false;
if (NS_SUCCEEDED(aDocumentURI->SchemeIs("about", &isAbout)) && isAbout) {
nsAutoCString path;
aDocumentURI->GetFilePath(path);
// about:reader requires support of scoped style, so we have to
// use Gecko backend for now. See bug 1402094.
// This should be fixed by bug 1204818.
if (path.EqualsLiteral("reader")) {
return false;
}
}
}
// Check the stylo block list.
if (IsInStyloBlocklist(aPrincipal)) {
return false;
}
return true;
}
/* static */
bool
nsLayoutUtils::IsInStyloBlocklist(nsIPrincipal* aPrincipal)

View File

@ -2547,6 +2547,12 @@ public:
static void Shutdown();
#ifdef MOZ_STYLO
/**
* Return whether stylo should be used for a given document URI and
* principal.
*/
static bool ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal);
/**
* Principal-based blocklist for stylo.
* Check if aPrincipal is blocked by stylo's blocklist and should fallback to
@ -2569,6 +2575,10 @@ public:
* So, NEVER use this in any other cases.
*/
static void RemoveFromStyloBlocklist(const nsACString& aBlockedDomain);
#else
static bool ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal) {
return false;
}
#endif
/**