Bug 1259574 - Disable docShell.useGlobalHistory on view source window browsers. r?jryans draft
authorMike Conley <mconley@mozilla.com>
Thu, 24 Mar 2016 17:16:14 -0400
changeset 344577 62b7ad53a7fd2b8f1ab76fa9bd5cbc984d3540ac
parent 343695 c2da2b90880f0cc435a1714d1e875478ffc4e071
child 344578 d43bf084093fe16e6c0bf33f4d1f02ad7532e29e
push id13864
push usermconley@mozilla.com
push dateThu, 24 Mar 2016 21:51:31 +0000
reviewersjryans
bugs1259574
milestone48.0a1
Bug 1259574 - Disable docShell.useGlobalHistory on view source window browsers. r?jryans MozReview-Commit-ID: FiSzSgxpduO
toolkit/components/viewsource/content/viewSource-content.js
toolkit/components/viewsource/content/viewSource.js
toolkit/components/viewsource/content/viewSource.xul
--- 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>