commit 3a69f6697799d7c6d0ed408df8aa28239b430556 Author: Kathy Brade brade@pearlcrescent.com Date: Wed Feb 13 11:32:13 2019 -0500
Bug 27486 Avoid about:blank tabs when opening onboarding pages.
Instead of using a simple <a href>, programmatically open onboarding web pages by using tabBrowser.addTab(). The same technique is now used for "See My Path", "See FAQs", and "Visit an Onion". --- browser/extensions/onboarding/bootstrap.js | 17 +++++++------- .../extensions/onboarding/content/onboarding.js | 26 +++++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/browser/extensions/onboarding/bootstrap.js b/browser/extensions/onboarding/bootstrap.js index 0762249ba1e9..a90bef0faaa2 100644 --- a/browser/extensions/onboarding/bootstrap.js +++ b/browser/extensions/onboarding/bootstrap.js @@ -91,16 +91,17 @@ function setPrefs(prefs) { }); }
-function openTorCircuitDisplayPage() { - let kFrameScript = "resource://onboarding/onboarding-tor-circuit-display.js"; - const kOnionURL = "https://3g2upl4pq6kufc4m.onion/"; // DuckDuckGo +function openTorTab(aURL, aFrameScript) { let win = Services.wm.getMostRecentWindow('navigator:browser'); if (win) { let tabBrowser = win.gBrowser; - let tab = tabBrowser.addTab(kOnionURL); + let tab = tabBrowser.addTab(aURL); tabBrowser.selectedTab = tab; - let b = tabBrowser.getBrowserForTab(tab); - b.messageManager.loadFrameScript(kFrameScript, true); + + if (aFrameScript) { + let b = tabBrowser.getBrowserForTab(tab); + b.messageManager.loadFrameScript(aFrameScript, true); + } } }
@@ -177,8 +178,8 @@ function initContentMessageListener() { isLoggedIn: syncTourChecker.isLoggedIn() }); break; - case "tor-open-circuit-display-page": - openTorCircuitDisplayPage(); + case "tor-open-tab": + openTorTab(msg.data.params.url, msg.data.params.frameScriptURL); break; #if 0 // No telemetry in Tor Browser. diff --git a/browser/extensions/onboarding/content/onboarding.js b/browser/extensions/onboarding/content/onboarding.js index 9d03a6fc82d8..5cb81852bb73 100644 --- a/browser/extensions/onboarding/content/onboarding.js +++ b/browser/extensions/onboarding/content/onboarding.js @@ -195,12 +195,9 @@ var onboardingTourset = { createOnboardingTourDescription(div, "onboarding.tour-tor-expect-differences.title", "onboarding.tour-tor-expect-differences.description"); createOnboardingTourContent(div, "resource://onboarding/img/figure_tor-expect-differences.png"); - let button = createOnboardingTourButton(div, + createOnboardingTourButton(div, "onboarding-tour-tor-expect-differences-button", - "onboarding.tour-tor-expect-differences.button", "a"); - let anchor = button.querySelector("a"); - anchor.setAttribute("href", "https://support.torproject.org/#faq"); - anchor.setAttribute("target", "_blank"); + "onboarding.tour-tor-expect-differences.button");
return div; }, @@ -214,12 +211,9 @@ var onboardingTourset = { createOnboardingTourDescription(div, "onboarding.tour-tor-onion-services.title", "onboarding.tour-tor-onion-services.description"); createOnboardingTourContent(div, "resource://onboarding/img/figure_tor-onion-services.png"); - let button = createOnboardingTourButton(div, + createOnboardingTourButton(div, "onboarding-tour-tor-onion-services-button", - "onboarding.tour-tor-onion-services.button", "a"); - let anchor = button.querySelector("a"); - anchor.setAttribute("href", "https://3g2upl4pq6kufc4m.onion/"); - anchor.setAttribute("target", "_blank"); + "onboarding.tour-tor-onion-services.button");
return div; }, @@ -836,6 +830,7 @@ class Onboarding { ({ id, classList } = target.firstChild); }
+ const kOnionURL = "https://3g2upl4pq6kufc4m.onion/"; // DuckDuckGo let handledTourActionClick = false; switch (id) { case "onboarding-overlay-button": @@ -918,7 +913,16 @@ class Onboarding { handledTourActionClick = true; break; case "onboarding-tour-tor-circuit-display-button": - sendMessageToChrome("tor-open-circuit-display-page"); + let kFrameScript = "resource://onboarding/onboarding-tor-circuit-display.js"; + sendMessageToChrome("tor-open-tab", + {url: kOnionURL, frameScriptURL: kFrameScript}); + break; + case "onboarding-tour-tor-expect-differences-button": + const kFAQURL = "https://support.torproject.org/#faq"; + sendMessageToChrome("tor-open-tab", {url: kFAQURL}); + break; + case "onboarding-tour-tor-onion-services-button": + sendMessageToChrome("tor-open-tab", {url: kOnionURL}); break; } if (classList.contains("onboarding-tour-item")) {