Bug 741717 - Add a reload method to browser elements. r=jlebar
This commit is contained in:
@@ -121,6 +121,7 @@ BrowserElementChild.prototype = {
|
|||||||
addMsgListener("get-can-go-forward", this._recvCanGoForward);
|
addMsgListener("get-can-go-forward", this._recvCanGoForward);
|
||||||
addMsgListener("go-back", this._recvGoBack);
|
addMsgListener("go-back", this._recvGoBack);
|
||||||
addMsgListener("go-forward", this._recvGoForward);
|
addMsgListener("go-forward", this._recvGoForward);
|
||||||
|
addMsgListener("reload", this._recvReload);
|
||||||
addMsgListener("unblock-modal-prompt", this._recvStopWaiting);
|
addMsgListener("unblock-modal-prompt", this._recvStopWaiting);
|
||||||
addMsgListener("fire-ctx-callback", this._recvFireCtxCallback);
|
addMsgListener("fire-ctx-callback", this._recvFireCtxCallback);
|
||||||
|
|
||||||
@@ -468,6 +469,18 @@ BrowserElementChild.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_recvReload: function(data) {
|
||||||
|
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
|
||||||
|
let reloadFlags = data.json.hardReload ?
|
||||||
|
webNav.LOAD_FLAGS_BYPASS_PROXY | webNav.LOAD_FLAGS_BYPASS_CACHE :
|
||||||
|
webNav.LOAD_FLAGS_NONE;
|
||||||
|
try {
|
||||||
|
webNav.reload(reloadFlags);
|
||||||
|
} catch(e) {
|
||||||
|
// Silently swallow errors; these can happen if a used cancels reload
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_keyEventHandler: function(e) {
|
_keyEventHandler: function(e) {
|
||||||
if (whitelistedEvents.indexOf(e.keyCode) != -1 && !e.defaultPrevented) {
|
if (whitelistedEvents.indexOf(e.keyCode) != -1 && !e.defaultPrevented) {
|
||||||
sendAsyncMsg('keyevent', {
|
sendAsyncMsg('keyevent', {
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ function BrowserElementParent(frameLoader) {
|
|||||||
defineMethod('setVisible', this._setVisible);
|
defineMethod('setVisible', this._setVisible);
|
||||||
defineMethod('goBack', this._goBack);
|
defineMethod('goBack', this._goBack);
|
||||||
defineMethod('goForward', this._goForward);
|
defineMethod('goForward', this._goForward);
|
||||||
|
defineMethod('reload', this._reload);
|
||||||
defineDOMRequestMethod('getScreenshot', 'get-screenshot');
|
defineDOMRequestMethod('getScreenshot', 'get-screenshot');
|
||||||
defineDOMRequestMethod('getCanGoBack', 'get-can-go-back');
|
defineDOMRequestMethod('getCanGoBack', 'get-can-go-back');
|
||||||
defineDOMRequestMethod('getCanGoForward', 'get-can-go-forward');
|
defineDOMRequestMethod('getCanGoForward', 'get-can-go-forward');
|
||||||
@@ -336,6 +337,10 @@ BrowserElementParent.prototype = {
|
|||||||
this._sendAsyncMsg('go-forward');
|
this._sendAsyncMsg('go-forward');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_reload: function(hardReload) {
|
||||||
|
this._sendAsyncMsg('reload', {hardReload: hardReload});
|
||||||
|
},
|
||||||
|
|
||||||
_fireKeyEvent: function(data) {
|
_fireKeyEvent: function(data) {
|
||||||
let evt = this._window.document.createEvent("KeyboardEvent");
|
let evt = this._window.document.createEvent("KeyboardEvent");
|
||||||
evt.initKeyEvent(data.json.type, true, true, this._window,
|
evt.initKeyEvent(data.json.type, true, true, this._window,
|
||||||
|
|||||||
@@ -79,10 +79,15 @@ MOCHITEST_FILES = \
|
|||||||
test_browserElement_inproc_SecurityChange.html \
|
test_browserElement_inproc_SecurityChange.html \
|
||||||
file_browserElement_SecurityChange.html \
|
file_browserElement_SecurityChange.html \
|
||||||
browserElement_BackForward.js \
|
browserElement_BackForward.js \
|
||||||
|
file_bug741717.sjs \
|
||||||
|
browserElement_Reload.js \
|
||||||
browserElement_ContextmenuEvents.js \
|
browserElement_ContextmenuEvents.js \
|
||||||
test_browserElement_inproc_ContextmenuEvents.html \
|
test_browserElement_inproc_ContextmenuEvents.html \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
# Disabled due to https://bugzilla.mozilla.org/show_bug.cgi?id=774100
|
||||||
|
# test_browserElement_inproc_Reload.html \
|
||||||
|
|
||||||
# OOP tests don't work on Windows (bug 763081).
|
# OOP tests don't work on Windows (bug 763081).
|
||||||
#
|
#
|
||||||
# Note that there's no inproc equivalent of BackForward; that's intentional.
|
# Note that there's no inproc equivalent of BackForward; that's intentional.
|
||||||
@@ -111,6 +116,7 @@ MOCHITEST_FILES += \
|
|||||||
test_browserElement_oop_OpenWindowRejected.html \
|
test_browserElement_oop_OpenWindowRejected.html \
|
||||||
test_browserElement_oop_SecurityChange.html \
|
test_browserElement_oop_SecurityChange.html \
|
||||||
test_browserElement_oop_BackForward.html \
|
test_browserElement_oop_BackForward.html \
|
||||||
|
test_browserElement_oop_Reload.html \
|
||||||
test_browserElement_oop_ContextmenuEvents.html \
|
test_browserElement_oop_ContextmenuEvents.html \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
endif
|
endif
|
||||||
|
|||||||
59
dom/browser-element/mochitest/browserElement_Reload.js
Normal file
59
dom/browser-element/mochitest/browserElement_Reload.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* Any copyright is dedicated to the public domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
// Bug 741717 - Test the reload ability of <iframe mozbrowser>.
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
var iframeScript = function() {
|
||||||
|
sendAsyncMessage('test:innerHTML', {
|
||||||
|
data: XPCNativeWrapper.unwrap(content).document.body.innerHTML
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var mm;
|
||||||
|
var iframe;
|
||||||
|
var loadedEvents = 0;
|
||||||
|
var countAcc;
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
browserElementTestHelpers.setEnabledPref(true);
|
||||||
|
browserElementTestHelpers.addToWhitelist();
|
||||||
|
|
||||||
|
iframe = document.createElement('iframe');
|
||||||
|
iframe.mozbrowser = true;
|
||||||
|
|
||||||
|
iframe.addEventListener('mozbrowserloadend', mozbrowserLoaded);
|
||||||
|
|
||||||
|
iframe.src = 'file_bug741717.sjs';
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
}
|
||||||
|
|
||||||
|
function iframeBodyRecv(data) {
|
||||||
|
var previousCount = countAcc;
|
||||||
|
var currentCount = parseInt(data.json.data, 10);
|
||||||
|
countAcc = currentCount;
|
||||||
|
switch (loadedEvents) {
|
||||||
|
case 1:
|
||||||
|
iframe.reload();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ok(true, 'reload was triggered');
|
||||||
|
ok(previousCount === currentCount, 'reload was a soft reload');
|
||||||
|
iframe.reload(true);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ok(currentCount > previousCount, 'reload was a hard reload');
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mozbrowserLoaded() {
|
||||||
|
loadedEvents++;
|
||||||
|
mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
|
||||||
|
mm.addMessageListener('test:innerHTML', iframeBodyRecv);
|
||||||
|
mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
runTest();
|
||||||
27
dom/browser-element/mochitest/file_bug741717.sjs
Normal file
27
dom/browser-element/mochitest/file_bug741717.sjs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
function handleRequest(request, response)
|
||||||
|
{
|
||||||
|
function etag(count) {
|
||||||
|
return '"anetag' + count + '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
var count = parseInt(getState('count'));
|
||||||
|
if (!count)
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
// reload(false) will make a request with If-None-Match headers
|
||||||
|
var ifNoneMatch = request.hasHeader("If-None-Match") ?
|
||||||
|
request.getHeader("If-None-Match") : "";
|
||||||
|
|
||||||
|
if (ifNoneMatch === etag(count)) {
|
||||||
|
response.setStatusLine(request.httpVersion, "304", "Not Modified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
|
setState('count', count + '');
|
||||||
|
|
||||||
|
response.setHeader('Content-Type', 'text/html', false);
|
||||||
|
response.setHeader('Cache-Control', 'public, max-age=3600', false);
|
||||||
|
response.setHeader("ETag", etag(count), false);
|
||||||
|
response.write('<html><body>' + count + '</body></html>');
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test of browser element.</title>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="application/javascript;version=1.7" src="browserElement_Reload.js">
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test of browser element.</title>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="application/javascript;version=1.7" src="browserElement_Reload.js">
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user