Files
palemoon27/toolkit/modules/RemoteWebProgress.jsm
roytam1 d69a2a05f1 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1238310: Part 1 - Allow setting zoom for background tabs. r=adw (24a28500ab)
- Bug 1238310: Part 2 - Return a promise from FullZoom.reset that resolves on completion. r=adw (ffc6478f51)
- Bug 1238310: Part 3 - Implement the base browser.tabs zoom API. r=aswan (3afd625e63)
- Bug 1248460 - pin during SSTabRestoring. r=kmag (50906f6d31)
- Bug 1228247 - use document.getFocus() for window.focused. r=enndeakin (847cea6764)
- Bug 1247493: [webext] Implement the tabId property of windows.create. r=billm (56d38a684a)
- Bug 1253132: [webext] Support window states in browser.windows APIs. r=billm (e6d684f09f)
- Bug 1237822 - Throw error if tabs.query is used without "tabs" permission with url param. r=kmag (bde19168ea)
- Bug 1245355 - Add a unit test for tabs.getAllInWindow. r=kmag (1b5b1c9e1c)
- Bug 1220124 - Add support for chrome.tabs.onhighlight. r=kmag (aa8ba35516)
- Bug 1238310: Part 4 - Refactor tab listener code. r=aswan (df19e35515)
- Bug 1215375 - Add support for checkboxes, radio groups, and icons. r=kmag (5471d99c35)
- Bug 1253128: [webext] Support type=popup in the browser.windows API. r=billm (1311eb5866)
- Bug 1253134 - Support drawAttention in browser.windows.update. r=kmag (ff969deda1)
- Bug 1253133: [webext] Support changing window geometry via windows.update. r=aswan (dfbeac0d55)
- Bug 1253130: [webext] Support the alwaysOnTop in the browser.windows API. r=gabor (9f62245702)
- Bug 1261949 - Complete test coverage for browser.windows events. r=kmag (b053dc252f)
- Bug 1262976 - browser.windows.onFocusChanged sometimes fires twice, even after the event listener is removed, r=kmag (ce0001804a)
- Bug 1190322 - Test coverage for |extension| extension API, r=kmag (ed1f783e5b)
- Bug 1236949: Split up browser_ext_tab_move_window.js. r=me (176cf6ff52)
- Bug 1257583 - Add test for bypassing the cache with tabs.reload. r=kmag (ea940f2355)
- Bug 1245353 - Add tests for tabs.reload. r=kmag (b0dd04e944)
- Bug 1262923 - Create schema for the history API. r=aswan (dd92ef65fb)
- Bug 1259859 - Add a test that looks for misused characters in user-facing strings. r=dolske,jryans (041611d201)
- Bug 1253673, r=jaws (001202f333)
- Bug 1239884: Follow-up: Fix ESLint error. (bb398cd7f2)
- Bug 1245649: Turn on use-isnan, no-unexpected-multiline, no-octal and no-self-compare. r=MattN (2bb29ab133)
- Bug 691614 - Make content zooming work with e10s Firefox. r=felipe (90184a47a9)
- Bug 1015721 - Detect zoom changes by listening for ZoomChangeUsingMouseWheel events instead of DOMMouseScroll events. r=dao (1f1c32630f)
- align to gecko and cleanup unused var (7eb6f670ba)
- Bug 1154277: Part 2 - support running Social API documents to run in a remote browser, i.e. the content process. f=mixedpuppy, r=Standard8 (5930ecb7b8)
- Bug 1254865 - Don't send disableglobalhistory state down to browser-child.js in sync message. r=Felipe (0afc597661)
- Bug 1254865 - Send init for AutoCompletePopup in async message from the parent. r=Felipe (48fc56cf52)
- Bug 1199934 - page shouldn't be able to trap/revert the location bar by hash/replacestate changes, r=jaws (aa314c2e88)
- remove duplicated (7c648ad3fd)
- Bug 1182987 - Part 5: Change mode of "readwrite" transaction to "cleanup" after QuotaExceeded is fired; r=baku (79d709970d)
- Bug 1257725 part 3. Get rid of ThreadsafeAutoJSContext usage in Promise code. r=bholley (405d3c03d4)
- Bug 1257725 part 1. Get rid of ThreadsafeAutoJSContext usage in JSEventHandler::HandleEvent. r=smaug (3222a73565)
- Bug 1257725 part 2. Fix permissions code to not make unwarranted assumptions about what happens when you reject a promise with an ErrorResult while a permission is pending on an on-stack JSContext. r=baku (1dea9c7c61)
- Bug 1257725 part 4. Get rid of ThreadsafeAutoJSContext usage in IndexedDB code, except for IDBRequest::CaptureCaller. r=khuey (8ad88560f0)
- Bug 1257725 part 5. Get rid of ThreadsafeAutoJSContext usage in IDBRequest::CaptureCaller. r=khuey (50a1f05ec9)
- Bug 1257725 part 6. Get rid of ThreadsafeAutoJSContext. r=bholley (8968c69fcc)
- Bug 1253233 - Make preparations to allow testing of remote browser elements in mochitest-chrome tests. r=felipe (5781cbd1bc)
- Bug 1247420 - part1: removeContentState. r=smaug (6c7a54b58e)
- Bug 1247420 - part2: IPC hover state management for select. r=Felipc (c7809aec7c)
- Bug 1223533 - Don't hide the select popup on irrelevant pagehide events. r=mconley (0cf218515a)
- Bug 1253486, [e10s only] hide select popups when the select element is removed, r=mconley (8a7049b6f1)
- Bug 1257790 - Don't propagate dragstart for mouse events originating in remote browsers. r=felipe (1efee0989e)
- bits of Bug 1053413 part 4 (f79bca021a)
- bits of Bug 1075670 - Make event.screen[XY] work in content processes (89bf0329c1)
- Bug 1180827 - Fix reuse of previous search results. r=MattN (6b4e65d318)
- Bug 1242208 - Fix cached form history results with a datalist present. r=MattN (10078ada31)
- Bug 1252074 - test_form_autocomplete.html and test_form_autocomplete_with_list.html should pass on e10s. r=paolo (8a9cf4a5f1)
- remove apparently obsolete code (ce805e25f1)
- Bug 1234449 - Cleanup reader telemetry r=margaret (cca93d78c0)
- Bug 1197163 - Update reader view "Loadingâ¦" string to use ellipsis character. r=margaret" (bb813ebfa3)
- Bug 1134940 - Modernize ReaderMode function declarations. r=nalexander (c5d7e43d6e)
- Bug 1130646 - Find non-hacky way to make back button dismiss reader mode popup, r=bnicholson (5acd9e5641)
- add missing test (94b8b6ca47)
- Bug 1260441 - Never pass a null js context to OpenCursor() r=bz (8d818b0257)
- Bug 1219895 - Cleanup the 'share.1' telemetry probes by adding extra context r=margaret (28526c5a3f)
- Bug 1226238 - (Part 1) Remove share button from reader view. r=ahunt,Gijs (2622d3c3cc)
- Bug 1226238 - (Part 2) Remove reader view footer. r=Gijs (c32877e0af)
- Bug 1226238 - (Part 3) Remove reading list button from reader view. r=Gijs (ba8c6fc96b)
- Bug 1226238 - (Part 4) Remove reading list toggle button from reader ¦view. r=ahunt,Gijs (65f93b79ca)
- Bug 1226238 - (Part 5) Update reader view toolbar styles. r=Gijs,ahunt (8276fe2707)
- no PP anymore (604e33632c)
- Bug 1170045 - part 2 - use SegmentedVector in the DeferredFinalize implementation; r=mccr8 (3954a5e390)
- Bug 1265770. Don't try to get a prototype for the interface object for an interface that's [NoInterfaceObject], since it's just unnecessary work that can't even be done at all in some cases (e.g. when the parent interface is also [NoInterfaceObject]). r=peterv (53d3077e31)
- Bug 1264187 - check for a ProtoAndIfaceCache before blindly destroying it; r=bz (97536e815b)
- Bug 1104955 part 3. Pass our unscopable names to CreateInterfaceObjects and have it define the right thing on the prototype. r=khuey (48386ab6b5)
- Bug 934889: Use JS_InitStandardClasses everywhere now that it works. r=bz (01d545259a)
- Bug 1258585. Remove some remaining vestiges of WebIDL quickstubs. r=peterv (3fa02388f1)
2024-05-03 10:30:22 +08:00

286 lines
9.7 KiB
JavaScript

// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
// 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
this.EXPORTED_SYMBOLS = ["RemoteWebProgressManager"];
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function newURI(spec)
{
return Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService)
.newURI(spec, null, null);
}
function RemoteWebProgressRequest(spec, originalSpec, requestCPOW)
{
this.wrappedJSObject = this;
this._uri = newURI(spec);
this._originalURI = newURI(originalSpec);
this._requestCPOW = requestCPOW;
}
RemoteWebProgressRequest.prototype = {
QueryInterface : XPCOMUtils.generateQI([Ci.nsIChannel]),
get URI() { return this._uri.clone(); },
get originalURI() { return this._originalURI.clone(); }
};
function RemoteWebProgress(aManager, aIsTopLevel) {
this.wrappedJSObject = this;
this._manager = aManager;
this._isLoadingDocument = false;
this._DOMWindow = null;
this._DOMWindowID = 0;
this._isTopLevel = aIsTopLevel;
this._loadType = 0;
}
RemoteWebProgress.prototype = {
NOTIFY_STATE_REQUEST: 0x00000001,
NOTIFY_STATE_DOCUMENT: 0x00000002,
NOTIFY_STATE_NETWORK: 0x00000004,
NOTIFY_STATE_WINDOW: 0x00000008,
NOTIFY_STATE_ALL: 0x0000000f,
NOTIFY_PROGRESS: 0x00000010,
NOTIFY_STATUS: 0x00000020,
NOTIFY_SECURITY: 0x00000040,
NOTIFY_LOCATION: 0x00000080,
NOTIFY_REFRESH: 0x00000100,
NOTIFY_ALL: 0x000001ff,
get isLoadingDocument() { return this._isLoadingDocument },
get DOMWindow() { return this._DOMWindow; },
get DOMWindowID() { return this._DOMWindowID; },
get isTopLevel() { return this._isTopLevel },
get loadType() { return this._loadType; },
addProgressListener: function (aListener) {
this._manager.addProgressListener(aListener);
},
removeProgressListener: function (aListener) {
this._manager.removeProgressListener(aListener);
}
};
function RemoteWebProgressManager (aBrowser) {
this._topLevelWebProgress = new RemoteWebProgress(this, true);
this._progressListeners = [];
this.swapBrowser(aBrowser);
}
RemoteWebProgressManager.argumentsForAddonListener = function(kind, args) {
function checkType(arg, typ) {
if (!arg) {
return false;
}
return (arg instanceof typ) ||
(arg instanceof Ci.nsISupports && arg.wrappedJSObject instanceof typ);
}
// Arguments for a tabs listener are shifted over one since the
// <browser> element is passed as the first argument.
let webProgressIndex = 0;
let requestIndex = 1;
if (kind == "tabs") {
webProgressIndex = 1;
requestIndex = 2;
}
if (checkType(args[webProgressIndex], RemoteWebProgress)) {
args[webProgressIndex] = args[webProgressIndex].wrappedJSObject._webProgressCPOW;
}
if (checkType(args[requestIndex], RemoteWebProgressRequest)) {
args[requestIndex] = args[requestIndex].wrappedJSObject._requestCPOW;
}
return args;
};
RemoteWebProgressManager.prototype = {
swapBrowser: function(aBrowser) {
if (this._messageManager) {
this._messageManager.removeMessageListener("Content:StateChange", this);
this._messageManager.removeMessageListener("Content:LocationChange", this);
this._messageManager.removeMessageListener("Content:SecurityChange", this);
this._messageManager.removeMessageListener("Content:StatusChange", this);
this._messageManager.removeMessageListener("Content:ProgressChange", this);
this._messageManager.removeMessageListener("Content:LoadURIResult", this);
}
this._browser = aBrowser;
this._messageManager = aBrowser.messageManager;
this._messageManager.addMessageListener("Content:StateChange", this);
this._messageManager.addMessageListener("Content:LocationChange", this);
this._messageManager.addMessageListener("Content:SecurityChange", this);
this._messageManager.addMessageListener("Content:StatusChange", this);
this._messageManager.addMessageListener("Content:ProgressChange", this);
this._messageManager.addMessageListener("Content:LoadURIResult", this);
},
get topLevelWebProgress() {
return this._topLevelWebProgress;
},
addProgressListener: function (aListener) {
let listener = aListener.QueryInterface(Ci.nsIWebProgressListener);
this._progressListeners.push(listener);
},
removeProgressListener: function (aListener) {
this._progressListeners =
this._progressListeners.filter(l => l != aListener);
},
_fixSSLStatusAndState: function (aStatus, aState) {
let deserialized = null;
if (aStatus) {
let helper = Cc["@mozilla.org/network/serialization-helper;1"]
.getService(Components.interfaces.nsISerializationHelper);
deserialized = helper.deserializeObject(aStatus)
deserialized.QueryInterface(Ci.nsISSLStatus);
}
return [deserialized, aState];
},
setCurrentURI: function (aURI) {
// This function is simpler than nsDocShell::SetCurrentURI since
// it doesn't have to deal with child docshells.
let remoteWebNav = this._browser._remoteWebNavigationImpl;
remoteWebNav._currentURI = aURI;
let webProgress = this.topLevelWebProgress;
for (let p of this._progressListeners) {
p.onLocationChange(webProgress, null, aURI);
}
},
_callProgressListeners: function(methodName, ...args) {
for (let p of this._progressListeners) {
if (p[methodName]) {
try {
p[methodName].apply(p, args);
} catch (ex) {
Cu.reportError("RemoteWebProgress failed to call " + methodName + ": " + ex + "\n");
}
}
}
},
receiveMessage: function (aMessage) {
let json = aMessage.json;
let objects = aMessage.objects;
// This message is a custom one we send as a result of a loadURI call.
// It shouldn't go through the same processing as all the forwarded
// webprogresslistener messages.
if (aMessage.name == "Content:LoadURIResult") {
this._browser.inLoadURI = false;
return;
}
let webProgress = null;
let isTopLevel = json.webProgress && json.webProgress.isTopLevel;
// The top-level WebProgress is always the same, but because we don't
// really have a concept of subframes/content we always create a new object
// for those.
if (json.webProgress) {
webProgress = isTopLevel ? this._topLevelWebProgress
: new RemoteWebProgress(this, false);
// Update the actual WebProgress fields.
webProgress._isLoadingDocument = json.webProgress.isLoadingDocument;
webProgress._DOMWindow = objects.DOMWindow;
webProgress._DOMWindowID = json.webProgress.DOMWindowID;
webProgress._loadType = json.webProgress.loadType;
webProgress._webProgressCPOW = objects.webProgress;
}
// The WebProgressRequest object however is always dynamic.
let request = null;
if (json.requestURI) {
request = new RemoteWebProgressRequest(json.requestURI,
json.originalRequestURI,
objects.request);
}
if (isTopLevel) {
this._browser._contentWindow = objects.contentWindow;
this._browser._documentContentType = json.documentContentType;
if (typeof json.inLoadURI != "undefined") {
this._browser.inLoadURI = json.inLoadURI;
}
if (json.charset) {
this._browser._characterSet = json.charset;
this._browser._mayEnableCharacterEncodingMenu = json.mayEnableCharacterEncodingMenu;
}
}
switch (aMessage.name) {
case "Content:StateChange":
if (isTopLevel) {
this._browser._documentURI = newURI(json.documentURI);
}
this._callProgressListeners("onStateChange", webProgress, request, json.stateFlags, json.status);
break;
case "Content:LocationChange":
let location = newURI(json.location);
let flags = json.flags;
let remoteWebNav = this._browser._remoteWebNavigationImpl;
// These properties can change even for a sub-frame navigation.
remoteWebNav.canGoBack = json.canGoBack;
remoteWebNav.canGoForward = json.canGoForward;
if (isTopLevel) {
remoteWebNav._currentURI = location;
this._browser._documentURI = newURI(json.documentURI);
this._browser._contentTitle = json.title;
this._browser._imageDocument = null;
this._browser._contentPrincipal = json.principal;
this._browser._isSyntheticDocument = json.synthetic;
this._browser._innerWindowID = json.innerWindowID;
}
this._callProgressListeners("onLocationChange", webProgress, request, location, flags);
break;
case "Content:SecurityChange":
let [status, state] = this._fixSSLStatusAndState(json.status, json.state);
if (isTopLevel) {
// Invoking this getter triggers the generation of the underlying object,
// which we need to access with ._securityUI, because .securityUI returns
// a wrapper that makes _update inaccessible.
void this._browser.securityUI;
this._browser._securityUI._update(status, state);
}
this._callProgressListeners("onSecurityChange", webProgress, request, state);
break;
case "Content:StatusChange":
this._callProgressListeners("onStatusChange", webProgress, request, json.status, json.message);
break;
case "Content:ProgressChange":
this._callProgressListeners("onProgressChange", webProgress, request, json.curSelf, json.maxSelf, json.curTotal, json.maxTotal);
break;
}
},
};