mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Merge backout of changeset d1cbe16de6bf
This commit is contained in:
commit
731ad4df41
@ -1778,9 +1778,31 @@ nsScriptSecurityManager::CanExecuteScripts(JSContext* cx,
|
||||
docshell = window->GetDocShell();
|
||||
}
|
||||
|
||||
rv = docshell->GetCanExecuteScripts(result);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!*result) return NS_OK;
|
||||
nsCOMPtr<nsIDocShellTreeItem> globalObjTreeItem =
|
||||
do_QueryInterface(docshell);
|
||||
|
||||
if (globalObjTreeItem)
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(globalObjTreeItem);
|
||||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||
|
||||
// Walk up the docshell tree to see if any containing docshell disallows scripts
|
||||
do
|
||||
{
|
||||
rv = docshell->GetAllowJavascript(result);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!*result)
|
||||
return NS_OK; // Do not run scripts
|
||||
treeItem->GetParent(getter_AddRefs(parentItem));
|
||||
treeItem.swap(parentItem);
|
||||
docshell = do_QueryInterface(treeItem);
|
||||
#ifdef DEBUG
|
||||
if (treeItem && !docshell) {
|
||||
NS_ERROR("cannot get a docshell from a treeItem!");
|
||||
}
|
||||
#endif // DEBUG
|
||||
} while (treeItem && docshell);
|
||||
}
|
||||
|
||||
// OK, the docshell doesn't have script execution explicitly disabled.
|
||||
// Check whether our URI is an "about:" URI that allows scripts. If it is,
|
||||
|
@ -65,6 +65,7 @@ _TEST_FILES = test_bug1682.html \
|
||||
test_bug369370.html \
|
||||
bug369370-popup.png \
|
||||
test_bug380383.html \
|
||||
test_bug386495.html \
|
||||
test_bug391777.html \
|
||||
test_bug402680.html \
|
||||
test_bug403868.html \
|
||||
|
42
content/html/document/test/test_bug386495.html
Normal file
42
content/html/document/test/test_bug386495.html
Normal file
@ -0,0 +1,42 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=386495
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 386495</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=386495">Mozilla Bug 386495</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<iframe id="testIframe"></iframe>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 386495 **/
|
||||
|
||||
function finishTest() {
|
||||
is(document.getElementById("testIframe").contentWindow.timeoutFired, false, "Timeout shouldn't fire.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function testContentEditable() {
|
||||
document.getElementById('testIframe').style.display = 'block';
|
||||
document.getElementById('testIframe').contentWindow.timeoutFired = false;
|
||||
document.getElementById('testIframe').contentWindow.setTimeout("window.timeoutFired = true", 50);
|
||||
document.getElementById('testIframe').contentDocument.designMode = 'on';
|
||||
setTimeout(finishTest, 100);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(testContentEditable);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -11166,97 +11166,3 @@ nsDocShell::GetPrintPreview(nsIWebBrowserPrint** aPrintPreview)
|
||||
#ifdef DEBUG
|
||||
unsigned long nsDocShell::gNumberOfDocShells = 0;
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetCanExecuteScripts(PRBool *aResult, PRBool *aContinueLooking)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = PR_FALSE; // disallow by default
|
||||
|
||||
nsCOMPtr<nsIDocShell> docshell = this;
|
||||
nsCOMPtr<nsIDocShellTreeItem> globalObjTreeItem =
|
||||
do_QueryInterface(docshell);
|
||||
|
||||
if (globalObjTreeItem)
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(globalObjTreeItem);
|
||||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||
PRBool firstPass = PR_TRUE;
|
||||
PRBool lookForParents = PR_FALSE;
|
||||
|
||||
// Walk up the docshell tree to see if any containing docshell disallows scripts
|
||||
do
|
||||
{
|
||||
nsresult rv = docshell->GetAllowJavascript(aResult);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!*aResult) {
|
||||
nsDocShell* realDocshell = static_cast<nsDocShell*>(docshell.get());
|
||||
if (realDocshell->mContentViewer) {
|
||||
nsIDocument* doc = realDocshell->mContentViewer->GetDocument();
|
||||
if (doc && doc->HasFlag(NODE_IS_EDITABLE) &&
|
||||
realDocshell->mEditorData) {
|
||||
nsCOMPtr<nsIEditingSession> editSession;
|
||||
realDocshell->mEditorData->GetEditingSession(getter_AddRefs(editSession));
|
||||
PRBool jsDisabled = PR_FALSE;
|
||||
if (editSession &&
|
||||
NS_SUCCEEDED(rv = editSession->GetJsAndPluginsDisabled(&jsDisabled))) {
|
||||
if (firstPass) {
|
||||
if (jsDisabled) {
|
||||
// We have a docshell which has been explicitly set
|
||||
// to design mode, so we disallow scripts.
|
||||
return NS_OK;
|
||||
}
|
||||
// The docshell was not explicitly set to design mode,
|
||||
// so it must be so because a parent was explicitly
|
||||
// set to design mode. We don't need to look at higher
|
||||
// docshells.
|
||||
*aResult = PR_TRUE;
|
||||
break;
|
||||
} else if (lookForParents && jsDisabled) {
|
||||
// If a parent was explicitly set to design mode,
|
||||
// we should allow script execution on the child.
|
||||
*aResult = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
// If the child docshell allows scripting, and the
|
||||
// parent is inside design mode, we don't need to look
|
||||
// further.
|
||||
*aResult = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_WARNING("The editing session does not work?");
|
||||
return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
|
||||
}
|
||||
if (firstPass) {
|
||||
// Don't be too hard on docshells on the first pass.
|
||||
// There may be a parent docshell which has been set
|
||||
// to design mode, so look for it.
|
||||
lookForParents = PR_TRUE;
|
||||
} else {
|
||||
// We have a docshell which disallows scripts
|
||||
// and is not editable, so we shouldn't allow
|
||||
// scripts at all.
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
} else if (lookForParents) {
|
||||
// The parent docshell was not explicitly set to design
|
||||
// mode, so js on the child docshell was disabled for
|
||||
// another reason. Therefore, we need to disable js.
|
||||
return NS_OK;
|
||||
}
|
||||
firstPass = PR_FALSE;
|
||||
|
||||
treeItem->GetParent(getter_AddRefs(parentItem));
|
||||
treeItem.swap(parentItem);
|
||||
docshell = do_QueryInterface(treeItem);
|
||||
#ifdef DEBUG
|
||||
if (treeItem && !docshell) {
|
||||
NS_ERROR("cannot get a docshell from a treeItem!");
|
||||
}
|
||||
#endif // DEBUG
|
||||
} while (treeItem && docshell);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ interface nsIPrincipal;
|
||||
interface nsIWebBrowserPrint;
|
||||
interface nsIVariant;
|
||||
|
||||
[scriptable, uuid(8ac6b880-776a-44d4-b271-a7e64ae3debd)]
|
||||
[scriptable, uuid(3adde256-05a9-43a7-a190-f8fe75eecfd6)]
|
||||
interface nsIDocShell : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -511,14 +511,4 @@ interface nsIDocShell : nsISupports
|
||||
* is loaded.
|
||||
*/
|
||||
readonly attribute nsIWebBrowserPrint printPreview;
|
||||
|
||||
/**
|
||||
* Whether this docshell can execute scripts based on its hierarchy.
|
||||
* The rule of thumb here is that we disable js if this docshell or any
|
||||
* of its parents disallow scripting, unless the only reason for js being
|
||||
* disabled in this docshell is a parent docshell having a document that
|
||||
* is in design mode. In that case, we explicitly allow scripting on the
|
||||
* current docshell.
|
||||
*/
|
||||
readonly attribute boolean canExecuteScripts;
|
||||
};
|
||||
|
@ -43,7 +43,7 @@
|
||||
|
||||
interface nsIEditor;
|
||||
|
||||
[scriptable, uuid(24f3f4da-18a4-448d-876d-7360fefac029)]
|
||||
[scriptable, uuid(274cd32e-3675-47e1-9d8a-fc6504ded9ce)]
|
||||
|
||||
interface nsIEditingSession : nsISupports
|
||||
{
|
||||
@ -128,10 +128,5 @@ interface nsIEditingSession : nsISupports
|
||||
* to the window.
|
||||
*/
|
||||
void reattachToWindow(in nsIDOMWindow aWindow);
|
||||
|
||||
/**
|
||||
* Whether this session has disabled JS and plugins.
|
||||
*/
|
||||
readonly attribute boolean jsAndPluginsDisabled;
|
||||
};
|
||||
|
||||
|
@ -261,14 +261,6 @@ nsEditingSession::RestoreJSAndPlugins(nsIDOMWindow *aWindow)
|
||||
return docShell->SetAllowPlugins(mPluginsEnabled);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::GetJsAndPluginsDisabled(PRBool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = mDisabledJSAndPlugins;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
WindowIsEditable
|
||||
|
@ -48,7 +48,6 @@ _TEST_FILES = \
|
||||
test_bug348497.html \
|
||||
test_bug384147.html \
|
||||
test_bug389350.html \
|
||||
test_bug519928.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
@ -1,96 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=519928
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 519928</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=519928">Mozilla Bug 519928</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<iframe id="load-frame"></iframe>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
var iframe = document.getElementById("load-frame");
|
||||
|
||||
function enableJS() allowJS(true);
|
||||
function disableJS() allowJS(false);
|
||||
function allowJS(allow) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
iframe.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIWebNavigation)
|
||||
.QueryInterface(Components.interfaces.nsIDocShell)
|
||||
.allowJavascript = allow;
|
||||
}
|
||||
function expectJSAllowed(allowed, testCondition, callback) {
|
||||
window.ICanRunMyJS = false;
|
||||
var self_ = window;
|
||||
testCondition();
|
||||
|
||||
var doc = iframe.contentDocument;
|
||||
doc.body.innerHTML = "<iframe></iframe>";
|
||||
var innerFrame = doc.querySelector("iframe");
|
||||
innerFrame.addEventListener("load", function() {
|
||||
innerFrame.removeEventListener("load", arguments.callee, false);
|
||||
|
||||
var msg = "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript";
|
||||
is(self_.ICanRunMyJS, allowed, msg);
|
||||
callback();
|
||||
}, false);
|
||||
var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
|
||||
innerFrame.src = iframeSrc;
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(function() {
|
||||
var enterDesignMode = function() document.designMode = "on";
|
||||
var leaveDesignMode = function() document.designMode = "off";
|
||||
expectJSAllowed(false, disableJS, function() {
|
||||
expectJSAllowed(true, enableJS, function() {
|
||||
expectJSAllowed(true, enterDesignMode, function() {
|
||||
expectJSAllowed(true, leaveDesignMode, function() {
|
||||
expectJSAllowed(false, disableJS, function() {
|
||||
expectJSAllowed(false, enterDesignMode, function() {
|
||||
expectJSAllowed(false, leaveDesignMode, function() {
|
||||
expectJSAllowed(true, enableJS, function() {
|
||||
enterDesignMode = function() iframe.contentDocument.designMode = "on";
|
||||
leaveDesignMode = function() iframe.contentDocument.designMode = "off";
|
||||
expectJSAllowed(false, disableJS, function() {
|
||||
expectJSAllowed(true, enableJS, function() {
|
||||
expectJSAllowed(true, enterDesignMode, function() {
|
||||
expectJSAllowed(true, leaveDesignMode, function() {
|
||||
expectJSAllowed(false, disableJS, function() {
|
||||
expectJSAllowed(true, enterDesignMode, function() {
|
||||
expectJSAllowed(false, leaveDesignMode, function() {
|
||||
expectJSAllowed(true, enableJS, function() {
|
||||
SimpleTest.finish();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user