mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1169723 - Load view source frame script lazily. r=mconley
This commit is contained in:
parent
b3d251278f
commit
cca5c306a7
@ -986,7 +986,6 @@ var gBrowserInit = {
|
||||
mm.loadFrameScript("chrome://browser/content/content.js", true);
|
||||
mm.loadFrameScript("chrome://browser/content/content-UITour.js", true);
|
||||
mm.loadFrameScript("chrome://global/content/manifestMessages.js", true);
|
||||
mm.loadFrameScript("chrome://global/content/viewSource-content.js", true);
|
||||
|
||||
window.messageManager.addMessageListener("Browser:LoadURI", RedirectLoad);
|
||||
|
||||
|
@ -158,6 +158,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "TabStateFlusher",
|
||||
"resource:///modules/sessionstore/TabStateFlusher.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Utils",
|
||||
"resource:///modules/sessionstore/Utils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ViewSourceBrowser",
|
||||
"resource://gre/modules/ViewSourceBrowser.jsm");
|
||||
|
||||
/**
|
||||
* |true| if we are in debug mode, |false| otherwise.
|
||||
@ -2817,6 +2819,12 @@ let SessionStoreInternal = {
|
||||
}
|
||||
tabbrowser.updateBrowserRemotenessByURL(browser, uri);
|
||||
|
||||
// If the restored browser wants to show view source content, start up a
|
||||
// view source browser that will load the required frame script.
|
||||
if (uri && ViewSourceBrowser.isViewSource(uri)) {
|
||||
new ViewSourceBrowser(browser);
|
||||
}
|
||||
|
||||
// Start a new epoch to discard all frame script messages relating to a
|
||||
// previous epoch. All async messages that are still on their way to chrome
|
||||
// will be ignored and don't override any tab data set when restoring.
|
||||
|
@ -25,8 +25,14 @@ const BUNDLE_URL = "chrome://global/locale/viewSource.properties";
|
||||
const MARK_SELECTION_START = "\uFDD0";
|
||||
const MARK_SELECTION_END = "\uFDEF";
|
||||
|
||||
const FRAME_SCRIPT = "chrome://global/content/viewSource-content.js";
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["ViewSourceBrowser"];
|
||||
|
||||
// Keep a set of browsers we've seen before, so we can load our frame script as
|
||||
// needed into any new ones.
|
||||
let gKnownBrowsers = new WeakSet();
|
||||
|
||||
/**
|
||||
* ViewSourceBrowser manages the view source <browser> from the chrome side.
|
||||
* It's companion frame script, viewSource-content.js, needs to be loaded as a
|
||||
@ -37,9 +43,8 @@ this.EXPORTED_SYMBOLS = ["ViewSourceBrowser"];
|
||||
* The page script takes care of loading the companion frame script.
|
||||
*
|
||||
* For a view source tab (or some other non-window case), an instance of this is
|
||||
* created by viewSourceUtils.js to wrap the <browser>. The caller that manages
|
||||
* the <browser> is responsible for ensuring the companion frame script has been
|
||||
* loaded.
|
||||
* created by viewSourceUtils.js to wrap the <browser>. The frame script will
|
||||
* be loaded by this module at construction time.
|
||||
*/
|
||||
this.ViewSourceBrowser = function ViewSourceBrowser(aBrowser) {
|
||||
this._browser = aBrowser;
|
||||
@ -83,6 +88,14 @@ ViewSourceBrowser.prototype = {
|
||||
this.messages.forEach((msgName) => {
|
||||
this.mm.addMessageListener(msgName, this);
|
||||
});
|
||||
|
||||
// If we have a known <browser> already, load the frame script here. This
|
||||
// is not true for the window case, as the element does not exist until the
|
||||
// XUL document loads. For that case, the frame script is loaded by
|
||||
// viewSource.js.
|
||||
if (this._browser) {
|
||||
this.loadFrameScript();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -95,6 +108,16 @@ ViewSourceBrowser.prototype = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* For a new browser we've not seen before, load the frame script.
|
||||
*/
|
||||
loadFrameScript() {
|
||||
if (!gKnownBrowsers.has(this.browser)) {
|
||||
gKnownBrowsers.add(this.browser);
|
||||
this.mm.loadFrameScript(FRAME_SCRIPT, false);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Anything added to the messages array will get handled here, and should
|
||||
* get dispatched to a specific function for the message name.
|
||||
@ -652,3 +675,13 @@ ViewSourceBrowser.prototype = {
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to decide if a URI maps to view source content.
|
||||
* @param uri
|
||||
* String containing the URI
|
||||
*/
|
||||
ViewSourceBrowser.isViewSource = function(uri) {
|
||||
return uri.startsWith("view-source:") ||
|
||||
(uri.startsWith("data:") && uri.includes("MathML"));
|
||||
};
|
||||
|
@ -66,9 +66,7 @@ var gViewSourceUtils = {
|
||||
|
||||
/**
|
||||
* Displays view source in the provided <browser>. This allows for non-window
|
||||
* display methods, such as a tab from Firefox. The caller that manages
|
||||
* the <browser> is responsible for ensuring the companion frame script,
|
||||
* viewSource-content.js, has been loaded for the <browser>.
|
||||
* display methods, such as a tab from Firefox.
|
||||
*
|
||||
* @param aArgs
|
||||
* An object with the following properties:
|
||||
@ -95,9 +93,7 @@ var gViewSourceUtils = {
|
||||
/**
|
||||
* Displays view source for a selection from some document in the provided
|
||||
* <browser>. This allows for non-window display methods, such as a tab from
|
||||
* Firefox. The caller that manages the <browser> is responsible for ensuring
|
||||
* the companion frame script, viewSource-content.js, has been loaded for the
|
||||
* <browser>.
|
||||
* Firefox.
|
||||
*
|
||||
* @param aSelection
|
||||
* A Selection object for the content of interest.
|
||||
@ -112,9 +108,7 @@ var gViewSourceUtils = {
|
||||
/**
|
||||
* Displays view source for a MathML fragment from some document in the
|
||||
* provided <browser>. This allows for non-window display methods, such as a
|
||||
* tab from Firefox. The caller that manages the <browser> is responsible for
|
||||
* ensuring the companion frame script, viewSource-content.js, has been loaded
|
||||
* for the <browser>.
|
||||
* tab from Firefox.
|
||||
*
|
||||
* @param aNode
|
||||
* Some element within the fragment of interest.
|
||||
|
Loading…
Reference in New Issue
Block a user