Bug 1168095 - Repair view source from sidebar pages. r=Gijs
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 27 May 2015 20:17:18 -0500
changeset 246015 e88fd1006b84878c31b2ef9cec0e94459040d713
parent 246014 d93f6b15c00318f0cd0f0214afd37b9afc2cb9f5
child 246016 9e0263028c048f5741c1244b437864ebbf567808
push id60333
push userryanvm@gmail.com
push dateThu, 28 May 2015 14:20:47 +0000
treeherdermozilla-inbound@8225a3b75df6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1168095
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168095 - Repair view source from sidebar pages. r=Gijs
browser/base/content/browser.js
browser/base/content/nsContextMenu.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2358,21 +2358,29 @@ function BrowserViewSourceOfDocument(aAr
     args = { browser, outerWindowID, URL };
   } else {
     args = aArgsOrDocument;
   }
 
   let inTab = Services.prefs.getBoolPref("view_source.tab");
   if (inTab) {
     let viewSourceURL = `view-source:${args.URL}`;
-    let tab = gBrowser.loadOneTab(viewSourceURL, {
+    let tabBrowser = gBrowser;
+    // In the case of sidebars and chat windows, gBrowser is defined but null,
+    // because no #content element exists.  For these cases, we need to find
+    // the most recent browser window.
+    if (!tabBrowser) {
+      let browserWindow = RecentWindow.getMostRecentBrowserWindow();
+      tabBrowser = browserWindow.gBrowser;
+    }
+    let tab = tabBrowser.loadOneTab(viewSourceURL, {
       relatedToCurrent: true,
       inBackground: false
     });
-    args.viewSourceBrowser = gBrowser.getBrowserForTab(tab);
+    args.viewSourceBrowser = tabBrowser.getBrowserForTab(tab);
     top.gViewSourceUtils.viewSourceInBrowser(args);
   } else {
     top.gViewSourceUtils.viewSource(args);
   }
 }
 
 /**
  * Opens the View Source dialog for the source loaded in the root
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1002,21 +1002,29 @@ nsContextMenu.prototype = {
       reference = focusedWindow.getSelection();
     else if (aContext == "mathml")
       reference = this.target;
     else
       throw "not reached";
 
     let inTab = Services.prefs.getBoolPref("view_source.tab");
     if (inTab) {
-      let tab = gBrowser.loadOneTab("about:blank", {
+      let tabBrowser = gBrowser;
+      // In the case of sidebars and chat windows, gBrowser is defined but null,
+      // because no #content element exists.  For these cases, we need to find
+      // the most recent browser window.
+      if (!tabBrowser) {
+        let browserWindow = RecentWindow.getMostRecentBrowserWindow();
+        tabBrowser = browserWindow.gBrowser;
+      }
+      let tab = tabBrowser.loadOneTab("about:blank", {
         relatedToCurrent: true,
         inBackground: false
       });
-      let viewSourceBrowser = gBrowser.getBrowserForTab(tab);
+      let viewSourceBrowser = tabBrowser.getBrowserForTab(tab);
       if (aContext == "selection") {
         top.gViewSourceUtils
            .viewSourceFromSelectionInBrowser(reference, viewSourceBrowser);
       } else {
         top.gViewSourceUtils
            .viewSourceFromFragmentInBrowser(reference, aContext,
                                             viewSourceBrowser);
       }