Bug 1392352 - Part 0.1 - Stop using the gBrowser name for view source windows draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Thu, 05 Oct 2017 15:58:45 -0700
changeset 755808 d7dd491bb29bc5202a89e4458ed78cd992d49180
parent 755533 9b69cc60e5848f2f8802c911fd00771b50eed41f
child 755809 a0b1511d5db512886bd1b8c7a50026e44ba1686b
push id99284
push userbgrinstead@mozilla.com
push dateThu, 15 Feb 2018 20:01:29 +0000
bugs1392352
milestone60.0a1
Bug 1392352 - Part 0.1 - Stop using the gBrowser name for view source windows MozReview-Commit-ID: C8tArCO8uNp
toolkit/components/viewsource/content/viewPartialSource.xul
toolkit/components/viewsource/content/viewSource.js
toolkit/components/viewsource/content/viewSource.xul
toolkit/components/viewsource/test/browser/browser_bug699356.js
toolkit/components/viewsource/test/browser/browser_contextmenu.js
toolkit/components/viewsource/test/browser/browser_gotoline.js
toolkit/components/viewsource/test/browser/browser_open_docgroup.js
toolkit/components/viewsource/test/browser/browser_viewsourceprefs.js
--- a/toolkit/components/viewsource/content/viewPartialSource.xul
+++ b/toolkit/components/viewsource/content/viewPartialSource.xul
@@ -34,17 +34,17 @@
   <script type="application/javascript" src="chrome://global/content/viewSource.js"/>
   <script type="application/javascript" src="chrome://global/content/viewPartialSource.js"/>
   <script type="application/javascript" src="chrome://global/content/viewZoomOverlay.js"/>
   <script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
 
   <stringbundle id="viewSourceBundle" src="chrome://global/locale/viewSource.properties"/>
 
   <command id="cmd_savePage" oncommand="ViewSourceSavePage();"/>
-  <command id="cmd_print" oncommand="PrintUtils.printWindow(gBrowser.outerWindowID, gBrowser);"/>
+  <command id="cmd_print" oncommand="PrintUtils.printWindow(viewSourceBrowser.outerWindowID, viewSourceBrowser);"/>
   <command id="cmd_printpreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
   <command id="cmd_pagesetup" oncommand="PrintUtils.showPageSetup();"/>
   <command id="cmd_close" oncommand="window.close();"/>
   <commandset id="editMenuCommands"/>
   <command id="cmd_find"
            oncommand="document.getElementById('FindToolbar').onFindCommand();"/>
   <command id="cmd_findAgain"
            oncommand="document.getElementById('FindToolbar').onFindAgainCommand(false);"/>
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -14,19 +14,19 @@ ChromeUtils.import("resource://gre/modul
 
 ChromeUtils.defineModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
 ChromeUtils.defineModuleGetter(this, "CharsetMenu",
   "resource://gre/modules/CharsetMenu.jsm");
 ChromeUtils.defineModuleGetter(this, "Deprecated",
   "resource://gre/modules/Deprecated.jsm");
 
-/* global gBrowser, gViewSourceBundle, gContextMenu */
+/* global viewSourceBrowser, gViewSourceBundle, gContextMenu */
 [
-  ["gBrowser",          "content"],
+  ["viewSourceBrowser",          "content"],
   ["gViewSourceBundle", "viewSourceBundle"],
   ["gContextMenu",      "viewSourceContextMenu"]
 ].forEach(function([name, id]) {
   Object.defineProperty(window, name, {
     configurable: true,
     enumerable: true,
     get() {
       var element = document.getElementById(id);
@@ -51,17 +51,17 @@ function ViewSourceChrome() {
 
 ViewSourceChrome.prototype = {
   __proto__: ViewSourceBrowser.prototype,
 
   /**
    * The <browser> that will be displaying the view source content.
    */
   get browser() {
-    return gBrowser;
+    return viewSourceBrowser;
   },
 
   /**
    * The context menu, when opened from the content process, sends
    * up a chunk of serialized data describing the items that the
    * context menu is being opened on. This allows us to avoid using
    * CPOWs.
    */
@@ -698,57 +698,57 @@ var PrintPreviewListener = {
 
   getPrintPreviewBrowser() {
     if (!this._ppBrowser) {
       this._ppBrowser = document.createElement("browser");
       this._ppBrowser.setAttribute("flex", "1");
       this._ppBrowser.setAttribute("type", "content");
     }
 
-    if (gBrowser.isRemoteBrowser) {
+    if (viewSourceBrowser.isRemoteBrowser) {
       this._ppBrowser.setAttribute("remote", "true");
     } else {
       this._ppBrowser.removeAttribute("remote");
     }
 
     let findBar = document.getElementById("FindToolbar");
     document.getElementById("appcontent")
             .insertBefore(this._ppBrowser, findBar);
 
     return this._ppBrowser;
   },
 
   getSourceBrowser() {
-    return gBrowser;
+    return viewSourceBrowser;
   },
 
   getNavToolbox() {
     return document.getElementById("appcontent");
   },
 
   onEnter() {
     let toolbox = document.getElementById("viewSource-toolbox");
     toolbox.hidden = true;
-    gBrowser.collapsed = true;
+    viewSourceBrowser.collapsed = true;
   },
 
   onExit() {
     this._ppBrowser.remove();
-    gBrowser.collapsed = false;
+    viewSourceBrowser.collapsed = false;
     document.getElementById("viewSource-toolbox").hidden = false;
   },
 
   activateBrowser(browser) {
     browser.docShellIsActive = true;
   },
 };
 
 // viewZoomOverlay.js uses this
 function getBrowser() {
-  return gBrowser;
+  return viewSourceBrowser;
 }
 
 Object.defineProperty(this, "gPageLoader", {
   configurable: true,
   enumerable: true,
   get() {
     var webnav = viewSourceChrome.webNav;
     if (!webnav)
@@ -757,19 +757,19 @@ Object.defineProperty(this, "gPageLoader
     this.gPageLoader = (webnav instanceof Ci.nsIWebPageDescriptor) ? webnav
                                                                    : null;
     return this.gPageLoader;
   },
 });
 
 // Strips the |view-source:| for internalSave()
 function ViewSourceSavePage() {
-  internalSave(gBrowser.currentURI.spec.replace(/^view-source:/i, ""),
+  internalSave(viewSourceBrowser.currentURI.spec.replace(/^view-source:/i, ""),
                null, null, null, null, null, "SaveLinkTitle",
-               null, null, gBrowser.contentDocumentAsCPOW, null,
+               null, null, viewSourceBrowser.contentDocumentAsCPOW, null,
                gPageLoader);
 }
 
 // Below are old deprecated functions and variables left behind for
 // compatibility reasons. These will be removed soon via bug 1159293.
 
 Object.defineProperty(this, "gLastLineFound", {
   configurable: true,
--- a/toolkit/components/viewsource/content/viewSource.xul
+++ b/toolkit/components/viewsource/content/viewSource.xul
@@ -34,17 +34,17 @@
   <script type="application/javascript" src="chrome://global/content/printUtils.js"/>
   <script type="application/javascript" src="chrome://global/content/viewSource.js"/>
   <script type="application/javascript" src="chrome://global/content/viewZoomOverlay.js"/>
   <script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
 
   <stringbundle id="viewSourceBundle" src="chrome://global/locale/viewSource.properties"/>
 
   <command id="cmd_savePage" oncommand="ViewSourceSavePage();"/>
-  <command id="cmd_print" oncommand="PrintUtils.printWindow(gBrowser.outerWindowID, gBrowser);"/>
+  <command id="cmd_print" oncommand="PrintUtils.printWindow(viewSourceBrowser.outerWindowID, viewSourceBrowser);"/>
   <command id="cmd_printpreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
   <command id="cmd_pagesetup" oncommand="PrintUtils.showPageSetup();"/>
   <command id="cmd_close" oncommand="window.close();"/>
   <commandset id="editMenuCommands"/>
   <command id="cmd_find"
            oncommand="document.getElementById('FindToolbar').onFindCommand();"/>
   <command id="cmd_findAgain"
            oncommand="document.getElementById('FindToolbar').onFindAgainCommand(false);"/>
--- a/toolkit/components/viewsource/test/browser/browser_bug699356.js
+++ b/toolkit/components/viewsource/test/browser/browser_bug699356.js
@@ -2,17 +2,17 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 function test() {
   let source = "about:blank";
 
   waitForExplicitFinish();
   openViewSourceWindow(source, function(aWindow) {
-    let gBrowser = aWindow.gBrowser;
+    let gBrowser = aWindow.viewSourceBrowser;
     let docEl = aWindow.document.documentElement;
 
     // eslint-disable-next-line mozilla/no-cpows-in-tests
     is(gBrowser.contentDocument.title, source, "Correct document title");
     is(docEl.getAttribute("title"),
       "Source of: " + source + ("nsILocalFileMac" in Components.interfaces ? "" : " - " + docEl.getAttribute("titlemodifier")),
       "Correct window title");
     closeViewSourceWindow(aWindow, finish);
--- a/toolkit/components/viewsource/test/browser/browser_contextmenu.js
+++ b/toolkit/components/viewsource/test/browser/browser_contextmenu.js
@@ -58,31 +58,31 @@ add_task(async function() {
 });
 
 async function onViewSourceWindowOpen(aWindow, aIsTab) {
   gViewSourceWindow = aWindow;
 
   gCopyLinkMenuItem = aWindow.document.getElementById(aIsTab ? "context-copylink" : "context-copyLink");
   gCopyEmailMenuItem = aWindow.document.getElementById(aIsTab ? "context-copyemail" : "context-copyEmail");
 
-  let browser = aIsTab ? gBrowser.selectedBrowser : gViewSourceWindow.gBrowser;
+  let browser = aIsTab ? gBrowser.selectedBrowser : gViewSourceWindow.viewSourceBrowser;
   await ContentTask.spawn(browser, null, async function(arg) {
     let tags = content.document.querySelectorAll("a[href]");
     Assert.equal(tags[0].href, "view-source:http://example.com/", "Link has correct href");
     Assert.equal(tags[1].href, "mailto:abc@def.ghi", "Link has correct href");
   });
 
   expectedData.push(["a[href]", true, false, "http://example.com/"]);
   expectedData.push(["a[href^=mailto]", false, true, "abc@def.ghi"]);
   expectedData.push(["span", false, false, null]);
 }
 
 async function checkMenuItems(contextMenu, isTab, selector, copyLinkExpected, copyEmailExpected, expectedClipboardContent) {
 
-  let browser = isTab ? gBrowser.selectedBrowser : gViewSourceWindow.gBrowser;
+  let browser = isTab ? gBrowser.selectedBrowser : gViewSourceWindow.viewSourceBrowser;
   await ContentTask.spawn(browser, { selector }, async function(arg) {
     content.document.querySelector(arg.selector).scrollIntoView();
   });
 
   let popupShownPromise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
   await BrowserTestUtils.synthesizeMouseAtCenter(selector,
           { type: "contextmenu", button: 2}, browser);
   await popupShownPromise;
--- a/toolkit/components/viewsource/test/browser/browser_gotoline.js
+++ b/toolkit/components/viewsource/test/browser/browser_gotoline.js
@@ -13,18 +13,18 @@ add_task(async function() {
   await BrowserTestUtils.closeWindow(win);
 
   win = await loadViewSourceWindow("data:text/plain," + encodeURIComponent(content));
   await checkViewSource(win);
   await BrowserTestUtils.closeWindow(win);
 });
 
 var checkViewSource = async function(aWindow) {
-  is(aWindow.gBrowser.contentDocument.body.textContent, content, "Correct content loaded");
+  is(aWindow.viewSourceBrowser.contentDocument.body.textContent, content, "Correct content loaded");
 
   for (let i = 1; i <= 3; i++) {
     aWindow.viewSourceChrome.goToLine(i);
-    await ContentTask.spawn(aWindow.gBrowser, i, async function(i) {
+    await ContentTask.spawn(aWindow.viewSourceBrowser, i, async function(i) {
       let selection = content.getSelection();
       Assert.equal(selection.toString(), "line " + i, "Correct text selected");
     });
   }
 };
--- a/toolkit/components/viewsource/test/browser/browser_open_docgroup.js
+++ b/toolkit/components/viewsource/test/browser/browser_open_docgroup.js
@@ -52,17 +52,17 @@ add_task(async function test_view_source
     ],
   });
 
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: "http://example.com",
   }, async function(browser) {
     let sourceWin = await openViewSource(browser);
-    await ContentTask.spawn(sourceWin.gBrowser, null, async function() {
+    await ContentTask.spawn(sourceWin.viewSourceBrowser, null, async function() {
       Assert.equal(content.document.body.id, "viewsource",
                    "View source mode enabled");
     });
 
     await closeViewSourceWindow(sourceWin);
   });
 
   await SpecialPowers.popPrefEnv();
--- a/toolkit/components/viewsource/test/browser/browser_viewsourceprefs.js
+++ b/toolkit/components/viewsource/test/browser/browser_viewsourceprefs.js
@@ -110,26 +110,26 @@ function simulateClick(aMenuItem) {
     aMenuItem.removeAttribute("checked");
   else
     aMenuItem.setAttribute("checked", "true");
 
   aMenuItem.click();
 }
 
 var checkStyle = async function(win, styleProperty, expected) {
-  let browser = win.gBrowser;
+  let browser = win.viewSourceBrowser;
   let value = await ContentTask.spawn(browser, styleProperty, async function(styleProperty) {
     let style = content.getComputedStyle(content.document.body);
     return style.getPropertyValue(styleProperty);
   });
   is(value, expected, "Correct value of " + styleProperty);
 };
 
 var checkHighlight = async function(win, expected) {
-  let browser = win.gBrowser;
+  let browser = win.viewSourceBrowser;
   let highlighted = await ContentTask.spawn(browser, {}, async function() {
     let spans = content.document.getElementsByTagName("span");
     return Array.some(spans, (span) => {
       let style = content.getComputedStyle(span);
       return style.getPropertyValue("color") !== "rgb(0, 0, 0)";
     });
   });
   is(highlighted, expected, "Syntax highlighting " + (expected ? "on" : "off"));