зеркало из https://github.com/mozilla/gecko-dev.git
Bug 581072. Fix the handling of long timeouts across timeout suspend/resume and add APIs to suspend/resume timeouts from trusted script. r=jst
This commit is contained in:
Родитель
13049a3c1a
Коммит
4bd66cc35a
|
@ -1382,3 +1382,27 @@ nsDOMWindowUtils::GetCurrentInnerWindowID(PRUint64 *aWindowID)
|
|||
*aWindowID = inner->mWindowID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SuspendTimeouts()
|
||||
{
|
||||
if (!IsUniversalXPConnectCapable()) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
}
|
||||
|
||||
mWindow->SuspendTimeouts();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::ResumeTimeouts()
|
||||
{
|
||||
if (!IsUniversalXPConnectCapable()) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
}
|
||||
|
||||
mWindow->ResumeTimeouts();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -9138,7 +9138,7 @@ nsGlobalWindow::SuspendTimeouts(PRUint32 aIncrease,
|
|||
for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) {
|
||||
// Set mTimeRemaining to be the time remaining for this timer.
|
||||
if (t->mWhen > now)
|
||||
t->mTimeRemaining = now - t->mWhen;
|
||||
t->mTimeRemaining = t->mWhen - now;
|
||||
else
|
||||
t->mTimeRemaining = TimeDuration(0);
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ interface nsIDOMEvent;
|
|||
interface nsITransferable;
|
||||
interface nsIQueryContentEventResult;
|
||||
|
||||
[scriptable, uuid(a6dbdbc9-5564-4e52-820a-4056c698f699)]
|
||||
[scriptable, uuid(1e042706-0343-4cba-a549-6a83eefb1835)]
|
||||
interface nsIDOMWindowUtils : nsISupports {
|
||||
|
||||
/**
|
||||
|
@ -691,4 +691,10 @@ interface nsIDOMWindowUtils : nsISupports {
|
|||
* Is the window is in a modal state? [See enterModalState()]
|
||||
*/
|
||||
boolean isInModalState();
|
||||
|
||||
/**
|
||||
* Suspend/resume timeouts on this window and its descendant windows.
|
||||
*/
|
||||
void suspendTimeouts();
|
||||
void resumeTimeouts();
|
||||
};
|
||||
|
|
|
@ -117,6 +117,7 @@ _TEST_FILES = \
|
|||
test_bug545314.html \
|
||||
test_bug548828.html \
|
||||
test_DOMWindowCreated_chromeonly.html \
|
||||
test_bug581072.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=581072
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 581072</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/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=581072">Mozilla Bug 581072</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
/** Test for Bug 581072 **/
|
||||
var longTimerFired = 0;
|
||||
|
||||
// Set up a one-hour timeout
|
||||
setTimeout(function() { longTimerFired = true; }, 3600000);
|
||||
|
||||
// Trigger suspend and resume timeouts
|
||||
(function() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||
utils.suspendTimeouts();
|
||||
utils.resumeTimeouts();
|
||||
})()
|
||||
|
||||
// Now set up another timeout which should fire before the one-hour one
|
||||
setTimeout(function() {
|
||||
is(longTimerFired, false, "One-hour timer should not fire before our 0ms one");
|
||||
SimpleTest.finish();
|
||||
}, 0);
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче