Skip to content

Commit

Permalink
Bug 1411532 part 1 - Add a pref for enabling stylo on chrome document…
Browse files Browse the repository at this point in the history
…s. r=bz

MozReview-Commit-ID: 7Zbh4Mf43xC

--HG--
extra : rebase_source : f9e4d0b6d1234cb8efcfbaaab2a349d2a082dd6e
  • Loading branch information
upsuper committed Oct 27, 2017
1 parent 59e80b6 commit b24625e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions dom/ipc/ContentPrefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = {
"javascript.use_us_english_locale",
"jsloader.shareGlobal",
#ifdef MOZ_STYLO
"layout.css.servo.chrome.enabled",
"layout.css.stylo-blocklist.blocked_domains",
"layout.css.stylo-blocklist.enabled",
#endif
Expand Down
18 changes: 17 additions & 1 deletion layout/base/nsLayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8152,7 +8152,8 @@ nsLayoutUtils::ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal)
// 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)) {
if (!StyloChromeEnabled() &&
nsContentUtils::IsSystemPrincipal(aPrincipal)) {
return false;
}
// Check any internal page which we need to explicitly blacklist.
Expand Down Expand Up @@ -8232,6 +8233,21 @@ nsLayoutUtils::RemoveFromStyloBlocklist(const nsACString& aBlockedDomain)
sStyloBlocklist = nullptr;
}
}

/* static */
bool
nsLayoutUtils::StyloChromeEnabled()
{
static bool sInitialized = false;
static bool sEnabled = false;
if (!sInitialized) {
// We intentionally don't allow dynamic toggling of this pref
// because it is rather risky to mix style backend in XUL.
sEnabled = Preferences::GetBool("layout.css.servo.chrome.enabled");
sInitialized = true;
}
return sEnabled;
}
#endif

/* static */
Expand Down
28 changes: 24 additions & 4 deletions layout/base/nsLayoutUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2526,13 +2526,33 @@ class nsLayoutUtils
#endif
}

// Whether Stylo should be allowed to be enabled in this process. This
// returns true for content processes and the non-e10s parent process.
// Whether Stylo should be allowed to be enabled in this process.
static bool StyloSupportedInCurrentProcess() {
return XRE_IsContentProcess() ||
(XRE_IsParentProcess() && !XRE_IsE10sParentProcess());
#ifdef MOZ_STYLO
if (XRE_IsContentProcess()) {
return true;
}
if (XRE_IsParentProcess()) {
// If Stylo is enabled for chrome document, we use it in all
// parent processes, regardless of whether it's e10s parent.
if (StyloChromeEnabled()) {
return true;
}
// Otherwise we only use stylo on non-e10s parent.
return !XRE_IsE10sParentProcess();
}
#endif
// Stylo is not enabled for any other process.
MOZ_DIAGNOSTIC_ASSERT(false, "We should not be creating any document "
"in processes other than content and parent");
return false;
}

#ifdef MOZ_STYLO
// Whether Stylo should be used on chrome documents.
static bool StyloChromeEnabled();
#endif

static uint32_t IdlePeriodDeadlineLimit() {
return sIdlePeriodDeadlineLimit;
}
Expand Down
5 changes: 5 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5818,6 +5818,11 @@ pref("layout.css.servo.enabled", true);
#else
pref("layout.css.servo.enabled", false);
#endif
// Whether Stylo is enabled for chrome document?
// If Stylo is not enabled, this pref doesn't take any effect.
// Note that this pref is only read once when requested. Changing it
// at runtime may have no effect.
pref("layout.css.servo.chrome.enabled", false);
#endif

// HSTS Priming
Expand Down

0 comments on commit b24625e

Please sign in to comment.