Bug 1646560: Part 2 - Move allowJavascript and friends from DocShell to BrowsingContext and WindowContext. r=jdescottes,nika,geckoview-reviewers,devtools-backward-compat-reviewers,agi

This is slightly complicated by the fact that the editor code wants to be able
to set this from the content process, so we really need separate
BrowsingContext and WindowContext flags, the latter of which can be set by the
owning process.

Differential Revision: https://phabricator.services.mozilla.com/D114899
This commit is contained in:
Kris Maglione
2021-06-15 04:40:11 +00:00
parent 6f088a3c1c
commit 799bf19224
36 changed files with 705 additions and 313 deletions

View File

@@ -262,6 +262,44 @@ bool WindowContext::CanSet(FieldIndex<IDX_HadLazyLoadImage>, const bool& aValue,
return IsTop();
}
bool WindowContext::CanSet(FieldIndex<IDX_AllowJavascript>, bool aValue,
ContentParent* aSource) {
return (XRE_IsParentProcess() && !aSource) || CheckOnlyOwningProcessCanSet(aSource);
}
void WindowContext::DidSet(FieldIndex<IDX_AllowJavascript>, bool aOldValue) {
RecomputeCanExecuteScripts();
}
void WindowContext::RecomputeCanExecuteScripts(bool aApplyChanges) {
const bool old = mCanExecuteScripts;
if (!AllowJavascript()) {
// Scripting has been explicitly disabled on our WindowContext.
mCanExecuteScripts = false;
} else {
// Otherwise, inherit.
mCanExecuteScripts = mBrowsingContext->CanExecuteScripts();
}
if (aApplyChanges && old != mCanExecuteScripts) {
// Inform our active DOM window.
if (nsGlobalWindowInner* window = GetInnerWindow()) {
// Only update scriptability if the window is current. Windows will have
// scriptability disabled when entering the bfcache and updated when
// coming out.
if (window->IsCurrentInnerWindow()) {
auto& scriptability = xpc::Scriptability::Get(
window->GetGlobalJSObject());
scriptability.SetWindowAllowsScript(mCanExecuteScripts);
}
}
for (const RefPtr<BrowsingContext>& child : Children()) {
child->RecomputeCanExecuteScripts();
}
}
}
void WindowContext::DidSet(FieldIndex<IDX_SHEntryHasUserInteraction>,
bool aOldValue) {
MOZ_ASSERT(
@@ -473,6 +511,7 @@ WindowContext::WindowContext(BrowsingContext* aBrowsingContext,
MOZ_ASSERT(mBrowsingContext);
MOZ_ASSERT(mInnerWindowId);
MOZ_ASSERT(mOuterWindowId);
RecomputeCanExecuteScripts(/* aApplyChanges */ false);
}
WindowContext::~WindowContext() {