Bug 1261842 - Make Marionette listener ensure that the loaded document is the one that was actually requested. r=ato

Before, it was assumed that the next load was the one that the Marionette client had
asked for, when this might not be the case. For example, when a new window opens,
it's possible for the initial about:blank load to be fired in content after the
parent has asked for a page to be loaded.

MozReview-Commit-ID: GPoJgbCvSju

--HG--
extra : rebase_source : 7b4c1638c2fe81a0a37d061a655e35aed0e2daa0
extra : source : b2e910bb1d726562548eba1148a81ec37300fb7b
This commit is contained in:
Mike Conley 2016-05-27 16:26:16 -04:00
Родитель 5f1bcd6334
Коммит 69b9435ec3
1 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -30,6 +30,8 @@ Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Task.jsm"); Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.importGlobalProperties(["URL"]);
var contentLog = new logging.ContentLogger(); var contentLog = new logging.ContentLogger();
var isB2G = false; var isB2G = false;
@ -927,13 +929,19 @@ function pollForReadyState(msg, start, callback) {
*/ */
function get(msg) { function get(msg) {
let start = new Date().getTime(); let start = new Date().getTime();
let requestedURL = new URL(msg.json.url).toString();
// Prevent DOMContentLoaded events from frames from invoking this // Prevent DOMContentLoaded events from frames from invoking this
// code, unless the event is coming from the frame associated with // code, unless the event is coming from the frame associated with
// the current window (i.e. someone has used switch_to_frame). // the current window (i.e. someone has used switch_to_frame).
onDOMContentLoaded = function onDOMContentLoaded(event) { onDOMContentLoaded = function onDOMContentLoaded(event) {
if (!event.originalTarget.defaultView.frameElement || let correctFrame =
event.originalTarget.defaultView.frameElement == curContainer.frame.frameElement) { !event.originalTarget.defaultView.frameElement ||
event.originalTarget.defaultView.frameElement == curContainer.frame.frameElement;
let correctURL = curContainer.frame.location == requestedURL;
if (correctFrame && correctURL) {
pollForReadyState(msg, start, () => { pollForReadyState(msg, start, () => {
removeEventListener("DOMContentLoaded", onDOMContentLoaded, false); removeEventListener("DOMContentLoaded", onDOMContentLoaded, false);
}); });
@ -949,12 +957,12 @@ function get(msg) {
} }
addEventListener("DOMContentLoaded", onDOMContentLoaded, false); addEventListener("DOMContentLoaded", onDOMContentLoaded, false);
if (isB2G) { if (isB2G) {
curContainer.frame.location = msg.json.url; curContainer.frame.location = requestedURL;
} else { } else {
// We need to move to the top frame before navigating // We need to move to the top frame before navigating
sendSyncMessage("Marionette:switchedToFrame", { frameValue: null }); sendSyncMessage("Marionette:switchedToFrame", { frameValue: null });
curContainer.frame = content; curContainer.frame = content;
curContainer.frame.location = msg.json.url; curContainer.frame.location = requestedURL;
} }
} }