mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1146606 - forward and cache remote readyState updates and remove CPOWs usage. r=mossop
This commit is contained in:
parent
bb73b744eb
commit
9e1c8093b8
@ -3,12 +3,15 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const { Ci } = require('chrome');
|
||||
const system = require('sdk/system/events');
|
||||
const { frames } = require('sdk/remote/child');
|
||||
const { WorkerChild } = require('sdk/content/worker-child');
|
||||
|
||||
// map observer topics to tab event names
|
||||
const EVENTS = {
|
||||
'content-document-global-created': 'create',
|
||||
'chrome-document-global-created': 'create',
|
||||
'content-document-interactive': 'ready',
|
||||
'chrome-document-interactive': 'ready',
|
||||
'content-document-loaded': 'load',
|
||||
@ -17,12 +20,18 @@ const EVENTS = {
|
||||
}
|
||||
|
||||
function topicListener({ subject, type }) {
|
||||
let window = subject.defaultView;
|
||||
if (!window)
|
||||
// NOTE detect the window from the subject:
|
||||
// - on *-global-created the subject is the window
|
||||
// - in the other cases it is the document object
|
||||
let window = subject instanceof Ci.nsIDOMWindow ? subject : subject.defaultView;
|
||||
if (!window){
|
||||
return;
|
||||
let frame = frames.getFrameForWindow(subject.defaultView);
|
||||
if (frame)
|
||||
frame.port.emit('sdk/tab/event', EVENTS[type]);
|
||||
}
|
||||
let frame = frames.getFrameForWindow(window);
|
||||
if (frame) {
|
||||
let readyState = frame.content.document.readyState;
|
||||
frame.port.emit('sdk/tab/event', EVENTS[type], { readyState });
|
||||
}
|
||||
}
|
||||
|
||||
for (let topic in EVENTS)
|
||||
@ -31,8 +40,9 @@ for (let topic in EVENTS)
|
||||
// bug 1024105 - content-page-shown notification doesn't pass persisted param
|
||||
function eventListener({target, type, persisted}) {
|
||||
let frame = this;
|
||||
if (target === frame.content.document)
|
||||
if (target === frame.content.document) {
|
||||
frame.port.emit('sdk/tab/event', type, persisted);
|
||||
}
|
||||
}
|
||||
frames.addEventListener('pageshow', eventListener, true);
|
||||
|
||||
@ -40,3 +50,9 @@ frames.port.on('sdk/tab/attach', (frame, options) => {
|
||||
options.window = frame.content;
|
||||
new WorkerChild(options);
|
||||
});
|
||||
|
||||
// Forward the existent frames's readyState.
|
||||
for (let frame of frames) {
|
||||
let readyState = frame.content.document.readyState;
|
||||
frame.port.emit('sdk/tab/event', 'init', { readyState });
|
||||
}
|
||||
|
@ -44,6 +44,9 @@ function isClosed(tab) {
|
||||
return viewsFor.get(tab).closing;
|
||||
}
|
||||
|
||||
// private tab attribute where the remote cached value is stored
|
||||
const remoteReadyStateCached = Symbol("remoteReadyStateCached");
|
||||
|
||||
const Tab = Class({
|
||||
implements: [EventTarget],
|
||||
initialize: function(tabElement, options = null) {
|
||||
@ -125,8 +128,7 @@ const Tab = Class({
|
||||
},
|
||||
|
||||
get readyState() {
|
||||
// TODO: This will use CPOWs in e10s: bug 1146606
|
||||
return isDestroyed(this) ? undefined : browser(this).contentDocument.readyState;
|
||||
return isDestroyed(this) ? undefined : this[remoteReadyStateCached] || "uninitialized";
|
||||
},
|
||||
|
||||
pin: function() {
|
||||
@ -306,11 +308,21 @@ function tabEventListener(event, tabElement, ...args) {
|
||||
removeListItem(window.tabs, tab);
|
||||
// The tabs module will take care of removing from its internal list
|
||||
}
|
||||
else if (event == "ready" || event == "load") {
|
||||
else if (event == "init" || event == "create" || event == "ready" || event == "load") {
|
||||
// Ignore load events from before browser windows have fully loaded, these
|
||||
// are for about:blank in the initial tab
|
||||
if (isBrowser(domWindow) && !domWindow.gBrowserInit.delayedStartupFinished)
|
||||
return;
|
||||
|
||||
// update the cached remote readyState value
|
||||
let { readyState } = args[0] || {};
|
||||
tab[remoteReadyStateCached] = readyState;
|
||||
}
|
||||
|
||||
if (event == "init") {
|
||||
// Do not emit events for the detected existent tabs, we only need to cache
|
||||
// their current document.readyState value.
|
||||
return;
|
||||
}
|
||||
|
||||
tabEmit(tab, event, ...args);
|
||||
|
@ -9,7 +9,7 @@ const windows = require("sdk/windows").browserWindows;
|
||||
const app = require("sdk/system/xul-app");
|
||||
const { viewFor } = require("sdk/view/core");
|
||||
const { modelFor } = require("sdk/model/core");
|
||||
const { getTabId, isTab } = require("sdk/tabs/utils");
|
||||
const { getBrowserForTab, getTabId, isTab } = require("sdk/tabs/utils");
|
||||
const { defer } = require("sdk/lang/functional");
|
||||
|
||||
function tabExistenceInTabs(assert, found, tab, tabs) {
|
||||
@ -202,4 +202,14 @@ exports["test tab.readyState"] = (assert, done) => {
|
||||
});
|
||||
}
|
||||
|
||||
exports["test tab.readyState for existent tabs"] = (assert) => {
|
||||
assert.equal(tabs.length, 1, "tabs contains an existent tab");
|
||||
|
||||
for (let tab of tabs) {
|
||||
let browserForTab = getBrowserForTab(viewFor(tab));
|
||||
assert.equal(browserForTab.contentDocument.readyState, tab.readyState,
|
||||
"tab.readyState has the same value of the associated contentDocument.readyState CPOW");
|
||||
}
|
||||
}
|
||||
|
||||
require("sdk/test").run(module.exports);
|
||||
|
Loading…
Reference in New Issue
Block a user