Bug 1050456 - Part 1: Prevent prerendered pages from showing the slow script dialog; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2015-01-23 17:46:26 -05:00
parent b02950208c
commit a0e86805c1
3 changed files with 96 additions and 0 deletions

View File

@ -11,3 +11,5 @@ support-files =
file_focuser.html
file_fullScreenPropertyAccessor.html
skip-if = e10s # prerendering doesn't work in e10s yet
[test_kill_longrunning_prerendered_content.xul]
skip-if = e10s # prerendering doesn't work in e10s yet

View File

@ -0,0 +1,85 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
onload="runTest();">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script class="testbody" type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
function Listener(aBrowser, aPrerendered, aCallback) {
this.init(aBrowser, aPrerendered, aCallback);
}
Listener.prototype = {
init: function(aBrowser, aCallback) {
this.mBrowser = aBrowser;
this.mCallback = aCallback;
},
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus) {
if ((aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) &&
(aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_DOCUMENT)) {
setTimeout(this.mCallback, 0);
}
},
onProgressChange : function(aWebProgress, aRequest,
aCurSelfProgress, aMaxSelfProgress,
aCurTotalProgress, aMaxTotalProgress) {},
onLocationChange : function(aWebProgress, aRequest, aLocation, aFlags) {},
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage) {},
onSecurityChange : function(aWebProgress, aRequest, aState) {},
mBrowser: null,
mPrerendered: false,
mCallback: null
};
var progress, progressListener;
function runTest() {
SpecialPowers.pushPrefEnv({
"set": [
["dom.max_script_run_time", 1]
]
}, function() {
test(function() {
ok("The page is successfully interrupted.");
SimpleTest.finish();
});
});
}
function test(aCallback) {
var browser = document.getElementById("prerendered");;
progressListener = new Listener(browser, aCallback);
var docShell = browser.docShell;
progress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebProgress);
progress.addProgressListener(progressListener,
Components.interfaces.nsIWebProgress.NOTIFY_ALL);
browser.loadURI("data:text/html,<script>;for(;;);</script" + ">");
}
]]>
</script>
<body id="html_body" xmlns="http://www.w3.org/1999/xhtml">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1050456">Mozilla Bug 1050456</a>
<p id="display"></p>
<pre id="test">
</pre>
</body>
<browser prerendered="true" id="prerendered"/>
</window>

View File

@ -20,6 +20,7 @@
#include "nsIMemoryReporter.h"
#include "nsIObserverService.h"
#include "nsIDebug2.h"
#include "nsIDocShell.h"
#include "amIAddonManager.h"
#include "nsPIDOMWindow.h"
#include "nsPrintfCString.h"
@ -1452,6 +1453,14 @@ XPCJSRuntime::InterruptCallback(JSContext *cx)
if (!win)
return true;
nsIDocShell* docShell = win->GetDocShell();
if (docShell && docShell->GetIsPrerendered()) {
// We cannot display a dialog if the page is being prerendered, so
// just kill the page.
mozilla::dom::HandlePrerenderingViolation(win);
return false;
}
// Show the prompt to the user, and kill if requested.
nsGlobalWindow::SlowScriptResponse response = win->ShowSlowScriptDialog();
if (response == nsGlobalWindow::KillSlowScript)