Bug 1385170 - show button string by checking if the platform support set default browser in background;r=mossop
authorgasolin <gasolin@gmail.com>
Fri, 28 Jul 2017 13:39:31 +0800
changeset 420879 d000d7961749d393a3521c2c13e6a0744ec4aa4e
parent 420878 1b823be2a09f602ee8d2121f2d3f3cfbe980407e
child 420880 814bf2e58ade5f5f2d114d1b7decbd1461c872d8
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1385170
milestone56.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 1385170 - show button string by checking if the platform support set default browser in background;r=mossop MozReview-Commit-ID: E71IN3QFsqo
browser/extensions/onboarding/content/onboarding-tour-agent.js
browser/extensions/onboarding/content/onboarding.js
--- a/browser/extensions/onboarding/content/onboarding-tour-agent.js
+++ b/browser/extensions/onboarding/content/onboarding-tour-agent.js
@@ -1,33 +1,46 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
  /* globals Mozilla */
 
 "use strict";
 
+document.addEventListener("Agent:CanSetDefaultBrowserInBackground", () => {
+  Mozilla.UITour.getConfiguration("appinfo", config => {
+    let canSetInBackGround = config.canSetDefaultBrowserInBackground;
+    let btn = document.getElementById("onboarding-tour-default-browser-button");
+    btn.setAttribute("data-cansetbg", canSetInBackGround);
+    btn.textContent = canSetInBackGround ? btn.getAttribute("data-bg") : btn.getAttribute("data-panel");
+  });
+});
+
 document.getElementById("onboarding-overlay")
-                        .addEventListener("click", evt => {
+  .addEventListener("click", evt => {
   switch (evt.target.id) {
     case "onboarding-tour-addons-button":
       Mozilla.UITour.showHighlight("addons");
       break;
     case "onboarding-tour-customize-button":
       Mozilla.UITour.showHighlight("customize");
       break;
     case "onboarding-tour-default-browser-button":
       Mozilla.UITour.getConfiguration("appinfo", (config) => {
         let isDefaultBrowser = config.defaultBrowser;
         let btn = document.getElementById("onboarding-tour-default-browser-button");
         let msg = document.getElementById("onboarding-tour-is-default-browser-msg");
-        if (isDefaultBrowser) {
+        let canSetInBackGround = btn.getAttribute("data-cansetbg") === "true";
+        if (isDefaultBrowser || canSetInBackGround) {
           btn.classList.add("onboarding-hidden");
           msg.classList.remove("onboarding-hidden");
+          if (canSetInBackGround) {
+            Mozilla.UITour.setConfiguration("defaultBrowser");
+          }
         } else {
           btn.disabled = true;
           Mozilla.UITour.setConfiguration("defaultBrowser");
         }
       });
       break;
     case "onboarding-tour-library-button":
       Mozilla.UITour.showHighlight("library");
--- a/browser/extensions/onboarding/content/onboarding.js
+++ b/browser/extensions/onboarding/content/onboarding.js
@@ -157,34 +157,39 @@ var onboardingTourset = {
       return {
         title: bundle.formatStringFromName("onboarding.notification.onboarding-tour-default-browser.title", [BRAND_SHORT_NAME], 1),
         message: bundle.formatStringFromName("onboarding.notification.onboarding-tour-default-browser.message", [BRAND_SHORT_NAME], 1),
         button: bundle.GetStringFromName("onboarding.button.learnMore"),
       };
     },
     getPage(win, bundle) {
       let div = win.document.createElement("div");
-      let defaultBrowserButtonId = win.matchMedia("(-moz-os-version: windows-win7)").matches ?
-        "onboarding.tour-default-browser.win7.button" : "onboarding.tour-default-browser.button";
+      let setFromBackGround = bundle.formatStringFromName("onboarding.tour-default-browser.win7.button", [BRAND_SHORT_NAME], 1);
+      let setFromPanel = bundle.GetStringFromName("onboarding.tour-default-browser.button");
       let isDefaultMessage = bundle.GetStringFromName("onboarding.tour-default-browser.is-default.message");
       let isDefault2ndMessage = bundle.formatStringFromName("onboarding.tour-default-browser.is-default.2nd-message", [BRAND_SHORT_NAME], 1);
       // eslint-disable-next-line no-unsanitized/property
       div.innerHTML = `
         <section class="onboarding-tour-description">
           <h1 data-l10n-id="onboarding.tour-default-browser.title2"></h1>
           <p data-l10n-id="onboarding.tour-default-browser.description2"></p>
         </section>
         <section class="onboarding-tour-content">
           <img src="resource://onboarding/img/figure_default.svg" role="presentation"/>
         </section>
         <aside class="onboarding-tour-button-container">
-          <button id="onboarding-tour-default-browser-button" class="onboarding-tour-action-button" data-l10n-id="${defaultBrowserButtonId}"></button>
+          <button id="onboarding-tour-default-browser-button" class="onboarding-tour-action-button"
+            data-bg="${setFromBackGround}" data-panel="${setFromPanel}"></button>
           <div id="onboarding-tour-is-default-browser-msg" class="onboarding-hidden">${isDefaultMessage}<br/>${isDefault2ndMessage}</div>
         </aside>
       `;
+
+      div.addEventListener("beforeshow", () => {
+        win.document.dispatchEvent(new Event("Agent:CanSetDefaultBrowserInBackground"));
+      });
       return div;
     },
   },
   "sync": {
     id: "onboarding-tour-sync",
     tourNameId: "onboarding.tour-sync2",
     getNotificationStrings(bundle) {
       return {