From 827375d5f89c2b5dc41b267afa22a15c6c4aca76 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 27 May 2015 20:17:18 -0500 Subject: [PATCH] Bug 1168095 - Repair view source from sidebar pages. r=Gijs --- browser/base/content/browser.js | 12 ++++++++++-- browser/base/content/nsContextMenu.js | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 60c1a4498cfc..e666b0b1f38c 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2363,11 +2363,19 @@ function BrowserViewSourceOfDocument(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); diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index 18cb420b0d4d..71081326ca32 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -1007,11 +1007,19 @@ nsContextMenu.prototype = { 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);