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:
@@ -393,7 +393,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
|
||||
#endif
|
||||
mInitialized(false),
|
||||
mAllowSubframes(true),
|
||||
mAllowJavascript(true),
|
||||
mAllowMetaRedirects(true),
|
||||
mAllowImages(true),
|
||||
mAllowMedia(true),
|
||||
@@ -407,7 +406,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
|
||||
mDeviceSizeIsPageSize(false),
|
||||
mWindowDraggingAllowed(false),
|
||||
mInFrameSwap(false),
|
||||
mCanExecuteScripts(false),
|
||||
mFiredUnloadEvent(false),
|
||||
mEODForCurrentDocument(false),
|
||||
mURIResultedInDocument(false),
|
||||
@@ -1749,14 +1747,6 @@ nsDocShell::SetAllowPlugins(bool aAllowPlugins) {
|
||||
return mBrowsingContext->SetAllowPlugins(aAllowPlugins);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetAllowJavascript(bool* aAllowJavascript) {
|
||||
NS_ENSURE_ARG_POINTER(aAllowJavascript);
|
||||
|
||||
*aAllowJavascript = mAllowJavascript;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetCssErrorReportingEnabled(bool* aEnabled) {
|
||||
MOZ_ASSERT(aEnabled);
|
||||
@@ -1770,13 +1760,6 @@ nsDocShell::SetCssErrorReportingEnabled(bool aEnabled) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::SetAllowJavascript(bool aAllowJavascript) {
|
||||
mAllowJavascript = aAllowJavascript;
|
||||
RecomputeCanExecuteScripts();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing) {
|
||||
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
|
||||
@@ -2653,50 +2636,6 @@ Maybe<ClientInfo> nsDocShell::GetInitialClientInfo() const {
|
||||
return innerWindow->GetClientInfo();
|
||||
}
|
||||
|
||||
void nsDocShell::RecomputeCanExecuteScripts() {
|
||||
bool old = mCanExecuteScripts;
|
||||
RefPtr<nsDocShell> parent = GetInProcessParentDocshell();
|
||||
|
||||
// If we have no tree owner, that means that we've been detached from the
|
||||
// docshell tree (this is distinct from having no parent docshell, which
|
||||
// is the case for root docshells). It would be nice to simply disallow
|
||||
// script in detached docshells, but bug 986542 demonstrates that this
|
||||
// behavior breaks at least one website.
|
||||
//
|
||||
// So instead, we use our previous value, unless mAllowJavascript has been
|
||||
// explicitly set to false.
|
||||
if (!mTreeOwner) {
|
||||
mCanExecuteScripts = mCanExecuteScripts && mAllowJavascript;
|
||||
// If scripting has been explicitly disabled on our docshell, we're done.
|
||||
} else if (!mAllowJavascript) {
|
||||
mCanExecuteScripts = false;
|
||||
// If we have a parent, inherit.
|
||||
} else if (parent) {
|
||||
mCanExecuteScripts = parent->mCanExecuteScripts;
|
||||
// Otherwise, we're the root of the tree, and we haven't explicitly disabled
|
||||
// script. Allow.
|
||||
} else {
|
||||
mCanExecuteScripts = true;
|
||||
}
|
||||
|
||||
// Inform our active DOM window.
|
||||
//
|
||||
// This will pass the outer, which will be in the scope of the active inner.
|
||||
if (mScriptGlobal && mScriptGlobal->GetGlobalJSObject()) {
|
||||
xpc::Scriptability& scriptability =
|
||||
xpc::Scriptability::Get(mScriptGlobal->GetGlobalJSObject());
|
||||
scriptability.SetDocShellAllowsScript(mCanExecuteScripts);
|
||||
}
|
||||
|
||||
// If our value has changed, our children might be affected. Recompute their
|
||||
// value as well.
|
||||
if (old != mCanExecuteScripts) {
|
||||
for (auto* child : mChildList.ForwardRange()) {
|
||||
static_cast<nsDocShell*>(child)->RecomputeCanExecuteScripts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsDocShell::SetDocLoaderParent(nsDocLoader* aParent) {
|
||||
bool wasFrame = IsFrame();
|
||||
|
||||
@@ -2717,10 +2656,6 @@ nsresult nsDocShell::SetDocLoaderParent(nsDocLoader* aParent) {
|
||||
nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(parent));
|
||||
|
||||
if (parentAsDocShell) {
|
||||
if (mAllowJavascript &&
|
||||
NS_SUCCEEDED(parentAsDocShell->GetAllowJavascript(&value))) {
|
||||
SetAllowJavascript(value);
|
||||
}
|
||||
if (mAllowMetaRedirects &&
|
||||
NS_SUCCEEDED(parentAsDocShell->GetAllowMetaRedirects(&value))) {
|
||||
SetAllowMetaRedirects(value);
|
||||
@@ -2755,9 +2690,6 @@ nsresult nsDocShell::SetDocLoaderParent(nsDocLoader* aParent) {
|
||||
mContentListener->SetParentContentListener(parentURIListener);
|
||||
}
|
||||
|
||||
// Our parent has changed. Recompute scriptability.
|
||||
RecomputeCanExecuteScripts();
|
||||
|
||||
// Inform windows when they're being removed from their parent.
|
||||
if (!aParent) {
|
||||
MaybeClearStorageAccessFlag();
|
||||
@@ -2982,16 +2914,6 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) {
|
||||
}
|
||||
}
|
||||
|
||||
// Our tree owner has changed. Recompute scriptability.
|
||||
//
|
||||
// Note that this is near-redundant with the recomputation in
|
||||
// SetDocLoaderParent(), but not so for the root DocShell, where the call to
|
||||
// SetTreeOwner() happens after the initial AddDocLoaderAsChildOfRoot(),
|
||||
// and we never set another parent. Given that this is neither expensive nor
|
||||
// performance-critical, let's be safe and unconditionally recompute this
|
||||
// state whenever dependent state changes.
|
||||
RecomputeCanExecuteScripts();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -7658,9 +7580,6 @@ nsresult nsDocShell::RestoreFromHistory() {
|
||||
|
||||
// Make sure to not clobber the state of the child. Since AddChild
|
||||
// always clobbers it, save it off first.
|
||||
bool allowJavascript;
|
||||
childShell->GetAllowJavascript(&allowJavascript);
|
||||
|
||||
bool allowRedirects;
|
||||
childShell->GetAllowMetaRedirects(&allowRedirects);
|
||||
|
||||
@@ -7684,7 +7603,6 @@ nsresult nsDocShell::RestoreFromHistory() {
|
||||
// child inherits our mPrivateBrowsingId, which is what we want.
|
||||
AddChild(childItem);
|
||||
|
||||
childShell->SetAllowJavascript(allowJavascript);
|
||||
childShell->SetAllowMetaRedirects(allowRedirects);
|
||||
childShell->SetAllowSubframes(allowSubframes);
|
||||
childShell->SetAllowImages(allowImages);
|
||||
@@ -13091,12 +13009,6 @@ NS_IMETHODIMP nsDocShell::ExitPrintPreview() {
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetCanExecuteScripts(bool* aResult) {
|
||||
*aResult = mCanExecuteScripts;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [infallible] */
|
||||
NS_IMETHODIMP nsDocShell::GetIsTopLevelContentDocShell(
|
||||
bool* aIsTopLevelContentDocShell) {
|
||||
|
||||
Reference in New Issue
Block a user