Bug 1445630 - Don't show new tab message for distribution add-ons. r?aswan draft
authorMichael Kaply <mozilla@kaply.com>
Wed, 18 Apr 2018 16:44:41 -0500
changeset 785954 edd2dc1631a902375195fe57fe332039c7689874
parent 785829 bee2d724d7a940b3caa4f6eee2917c59b1555a9e
push id107370
push usermozilla@kaply.com
push dateFri, 20 Apr 2018 21:50:35 +0000
reviewersaswan
bugs1445630
milestone60.0
Bug 1445630 - Don't show new tab message for distribution add-ons. r?aswan MozReview-Commit-ID: HVVB13W59MU
browser/components/extensions/ext-url-overrides.js
--- a/browser/components/extensions/ext-url-overrides.js
+++ b/browser/components/extensions/ext-url-overrides.js
@@ -16,16 +16,17 @@ ChromeUtils.defineModuleGetter(this, "Ex
 
 XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService",
                                    "@mozilla.org/browser/aboutnewtab-service;1",
                                    "nsIAboutNewTabService");
 
 const STORE_TYPE = "url_overrides";
 const NEW_TAB_SETTING_NAME = "newTabURL";
 const NEW_TAB_CONFIRMED_TYPE = "newTabNotification";
+const PREF_BRANCH_INSTALLED_ADDON = "extensions.installedDistroAddon.";
 
 XPCOMUtils.defineLazyGetter(this, "strBundle", function() {
   return Services.strings.createBundle("chrome://global/locale/extensions.properties");
 });
 
 function userWasNotified(extensionId) {
   let setting = ExtensionSettingsStore.getSetting(NEW_TAB_CONFIRMED_TYPE, extensionId);
   return setting && setting.value;
@@ -58,24 +59,34 @@ function replaceUrlInTab(gBrowser, tab, 
       },
     });
   });
   gBrowser.loadURIWithFlags(
     url, {flags: Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY});
   return loaded;
 }
 
+let gDistributionAddonsList;
+
+function isDistributionAddon(id) {
+  if (!gDistributionAddonsList) {
+    gDistributionAddonsList = Services.prefs.getChildList(PREF_BRANCH_INSTALLED_ADDON)
+                                      .map(id => id.replace(PREF_BRANCH_INSTALLED_ADDON, ""));
+  }
+  return gDistributionAddonsList.includes(id);
+}
+
 async function handleNewTabOpened() {
   // We don't need to open the doorhanger again until the controlling add-on changes.
   // eslint-disable-next-line no-use-before-define
   removeNewTabObserver();
 
   let item = ExtensionSettingsStore.getSetting(STORE_TYPE, NEW_TAB_SETTING_NAME);
 
-  if (!item || !item.id || userWasNotified(item.id)) {
+  if (!item || !item.id || userWasNotified(item.id) || isDistributionAddon(item.id)) {
     return;
   }
 
   // Find the elements we need.
   let win = windowTracker.getCurrentWindow({});
   let doc = win.document;
   let panel = doc.getElementById("extension-notification-panel");
   let addon = await AddonManager.getAddonByID(item.id);