Bug 1259574 - Disable docShell.useGlobalHistory on view source window browsers. r?jryans
MozReview-Commit-ID: FiSzSgxpduO
--- a/toolkit/components/viewsource/content/viewSource-content.js
+++ b/toolkit/components/viewsource/content/viewSource-content.js
@@ -63,16 +63,25 @@ var ViewSourceContent = {
* and removed on pagehide. When the initial about:blank is transitioned
* away from, a pagehide is fired without us having attached ourselves
* first. We use this boolean to keep track of whether or not we're
* attached, so we don't attempt to remove our listener when it's not
* yet there (which throws).
*/
selectionListenerAttached: false,
+ /**
+ * When viewing source, we don't want our visits within the browser
+ * to be entered into the global history database, so we turn off
+ * global history support once we show the source. We stash the
+ * original value of whether or not we were using the global history
+ * service here so that we can restore it when we pagehide.
+ */
+ oldUseGlobalHistory: undefined,
+
get isViewSource() {
let uri = content.document.documentURI;
return uri.startsWith("view-source:") ||
(uri.startsWith("data:") && uri.includes("MathML"));
},
get isAboutBlank() {
let uri = content.document.documentURI;
@@ -398,16 +407,23 @@ var ViewSourceContent = {
/**
* Handler for the pageshow event.
*
* @param event
* The pageshow event being handled.
*/
onPageShow(event) {
+ // We want to ensure that our visits to any viewsource pages don't
+ // get put into the global history. Stash the original value for
+ // using global history before disabling it, and we'll put it back
+ // on pagehide.
+ this.oldUseGlobalHistory = docShell.useGlobalHistory;
+ docShell.useGlobalHistory = false;
+
let selection = content.getSelection();
if (selection) {
selection.QueryInterface(Ci.nsISelectionPrivate)
.addSelectionListener(this);
this.selectionListenerAttached = true;
}
content.focus();
@@ -437,16 +453,18 @@ var ViewSourceContent = {
// ever set a selectionListener, so we have a boolean around
// to keep track of when the listener is attached.
if (this.selectionListenerAttached) {
content.getSelection()
.QueryInterface(Ci.nsISelectionPrivate)
.removeSelectionListener(this);
this.selectionListenerAttached = false;
}
+
+ docShell.useGlobalHistory = this.oldUseGlobalHistory;
sendAsyncMessage("ViewSource:SourceUnloaded");
},
onContextMenu(event) {
let addonInfo = {};
let subject = {
event: event,
addonInfo: addonInfo,
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -706,16 +706,17 @@ var viewSourceChrome = new ViewSourceChr
var PrintPreviewListener = {
_ppBrowser: null,
getPrintPreviewBrowser() {
if (!this._ppBrowser) {
this._ppBrowser = document.createElement("browser");
this._ppBrowser.setAttribute("flex", "1");
this._ppBrowser.setAttribute("type", "content");
+ this._ppBrowser.setAttribute("disableglobalhistory", "true");
}
if (gBrowser.isRemoteBrowser) {
this._ppBrowser.setAttribute("remote", "true");
} else {
this._ppBrowser.removeAttribute("remote");
}
--- a/toolkit/components/viewsource/content/viewSource.xul
+++ b/toolkit/components/viewsource/content/viewSource.xul
@@ -218,16 +218,19 @@
label="&menu_highlightSyntax.label;" accesskey="&menu_highlightSyntax.accesskey;"/>
</menupopup>
</menu>
</menubar>
</toolbox>
<vbox id="appcontent" flex="1">
+ <!-- Note that we don't set disableglobalhistory on this browser. This is because
+ the viewSource-content.js frame script will do this for us by touching the
+ nsIDocShell directly. -->
<browser id="content" type="content-primary" name="content" src="about:blank" flex="1"
context="viewSourceContextMenu" showcaret="true" tooltip="aHTMLTooltip" />
<findbar id="FindToolbar" browserid="content"/>
</vbox>
<statusbar id="status-bar" class="chromeclass-status">
<statusbarpanel id="statusbar-line-col" label="" flex="1"/>
</statusbar>