Bug 1001957 - Don't use a CPOW for reload. r=felipe/mccr8/smaug

Original patch from billm.
This commit is contained in:
Blake Kaplan 2014-07-08 18:27:59 -07:00
parent 196c4d51c5
commit b573f69331
6 changed files with 134 additions and 19 deletions

View File

@ -2632,24 +2632,14 @@ function BrowserReloadWithFlags(reloadFlags) {
return; return;
} }
/* First, we'll try to use the session history object to reload so let windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
* that framesets are handled properly. If we're in a special .getInterface(Ci.nsIDOMWindowUtils);
* window (such as view-source) that has no session history, fall
* back on using the web navigation's reload method.
*/
var webNav = gBrowser.webNavigation; gBrowser.selectedBrowser
try { .messageManager
var sh = webNav.sessionHistory; .sendAsyncMessage("Browser:Reload",
if (sh) { flags: reloadFlags,
webNav = sh.QueryInterface(nsIWebNavigation); handlingUserInput: windowUtils.isHandlingUserInput });
} catch (e) {
}
try {
webNav.reload(reloadFlags);
} catch (e) {
}
} }
var PrintPreviewListener = { var PrintPreviewListener = {

View File

@ -34,6 +34,34 @@ addMessageListener("Browser:HideSessionRestoreButton", function (message) {
} }
}); });
addMessageListener("Browser:Reload", function(message) {
/* First, we'll try to use the session history object to reload so
* that framesets are handled properly. If we're in a special
* window (such as view-source) that has no session history, fall
* back on using the web navigation's reload method.
*/
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
try {
let sh = webNav.sessionHistory;
if (sh)
webNav = sh.QueryInterface(Ci.nsIWebNavigation);
} catch (e) {
}
let reloadFlags = message.data.flags;
let handlingUserInput;
try {
handlingUserInput = content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.setHandlingUserInput(message.data.handlingUserInput);
webNav.reload(reloadFlags);
} catch (e) {
} finally {
handlingUserInput.destruct();
}
});
addEventListener("DOMFormHasPassword", function(event) { addEventListener("DOMFormHasPassword", function(event) {
InsecurePasswordUtils.checkForInsecurePasswords(event.target); InsecurePasswordUtils.checkForInsecurePasswords(event.target);
LoginManagerContent.onFormPassword(event); LoginManagerContent.onFormPassword(event);

View File

@ -173,7 +173,13 @@ function MixedTest6B() {
function MixedTest6C() { function MixedTest6C() {
gTestBrowser.removeEventListener("load", MixedTest6C, true); gTestBrowser.removeEventListener("load", MixedTest6C, true);
waitForCondition(function() content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello", MixedTest6D, "Waited too long for mixed script to run in Test 6"); waitForCondition(function() {
try {
return content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello";
} catch (e) {
return false;
}
}, MixedTest6D, "Waited too long for mixed script to run in Test 6");
} }
function MixedTest6D() { function MixedTest6D() {
ok(content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 6"); ok(content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 6");

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sts=2 sw=2 et tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -3587,6 +3588,74 @@ nsDOMWindowUtils::GetOMTAStyle(nsIDOMElement* aElement,
return NS_OK; return NS_OK;
} }
namespace {
class HandlingUserInputHelper MOZ_FINAL : public nsIJSRAIIHelper
{
public:
HandlingUserInputHelper(bool aHandlingUserInput);
NS_DECL_ISUPPORTS
NS_DECL_NSIJSRAIIHELPER
private:
~HandlingUserInputHelper();
bool mHandlingUserInput;
bool mDestructCalled;
};
NS_IMPL_ISUPPORTS(HandlingUserInputHelper, nsIJSRAIIHelper)
HandlingUserInputHelper::HandlingUserInputHelper(bool aHandlingUserInput)
: mHandlingUserInput(aHandlingUserInput),
mDestructCalled(false)
{
if (aHandlingUserInput) {
EventStateManager::StartHandlingUserInput();
}
}
HandlingUserInputHelper::~HandlingUserInputHelper()
{
// We assert, but just in case, make sure we notify the ESM.
MOZ_ASSERT(mDestructCalled);
if (!mDestructCalled) {
Destruct();
}
}
NS_IMETHODIMP
HandlingUserInputHelper::Destruct()
{
if (NS_WARN_IF(mDestructCalled)) {
return NS_ERROR_FAILURE;
}
mDestructCalled = true;
if (mHandlingUserInput) {
EventStateManager::StopHandlingUserInput();
}
return NS_OK;
}
}
NS_IMETHODIMP
nsDOMWindowUtils::SetHandlingUserInput(bool aHandlingUserInput,
nsIJSRAIIHelper** aHelper)
{
if (!nsContentUtils::IsCallerChrome()) {
return NS_ERROR_DOM_SECURITY_ERR;
}
nsRefPtr<HandlingUserInputHelper> helper(
new HandlingUserInputHelper(aHandlingUserInput));
helper.forget(aHelper);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWindowUtils::GetContentAPZTestData(JSContext* aContext, nsDOMWindowUtils::GetContentAPZTestData(JSContext* aContext,
JS::MutableHandleValue aOutContentTestData) JS::MutableHandleValue aOutContentTestData)

View File

@ -76,6 +76,11 @@ function eventHandler(e) {
nbEvents--; nbEvents--;
// Prevent default for F5 because on desktop that reloads the page.
if (e.keyCode === Ci.nsIDOMKeyEvent.DOM_VK_F5) {
e.preventDefault();
}
if (nbEvents == 0) { if (nbEvents == 0) {
SimpleTest.finish(); SimpleTest.finish();
return; return;

View File

@ -47,8 +47,9 @@ interface nsIDOMEventTarget;
interface nsIRunnable; interface nsIRunnable;
interface nsICompositionStringSynthesizer; interface nsICompositionStringSynthesizer;
interface nsITranslationNodeList; interface nsITranslationNodeList;
interface nsIJSRAIIHelper;
[scriptable, uuid(46e3f206-9a8f-4d66-8248-7ec6a37de45a)] [scriptable, uuid(e156a9f5-d0e3-4a2f-a4a8-19c648d5ecb9)]
interface nsIDOMWindowUtils : nsISupports { interface nsIDOMWindowUtils : nsISupports {
/** /**
@ -1638,6 +1639,13 @@ interface nsIDOMWindowUtils : nsISupports {
*/ */
AString getOMTAStyle(in nsIDOMElement aElement, in AString aProperty); AString getOMTAStyle(in nsIDOMElement aElement, in AString aProperty);
/**
* If we are currently handling user input, this informs the event state
* manager. Remember to call destruct() on the return value!
* See also nsIDOMWindowUtils::isHandlingUserInput.
*/
nsIJSRAIIHelper setHandlingUserInput(in boolean aHandlingInput);
/** /**
* Get the content- and compositor-side APZ test data instances. * Get the content- and compositor-side APZ test data instances.
* The return values are of type APZTestData (see APZTestData.webidl). * The return values are of type APZTestData (see APZTestData.webidl).
@ -1674,3 +1682,12 @@ interface nsITranslationNodeList : nsISupports {
// which its parent is not a translation node. // which its parent is not a translation node.
boolean isTranslationRootAtIndex(in unsigned long index); boolean isTranslationRootAtIndex(in unsigned long index);
}; };
/**
* JS doesn't do RAII very well. We can use this interface to make remembering
* to destruct an object in a finally clause easier.
*/
[scriptable, uuid(52e5a996-d0a9-4efc-a6fa-24489c532b19)]
interface nsIJSRAIIHelper : nsISupports {
void destruct();
};