Skip to content

Instantly share code, notes, and snippets.

@mstriemer
Created March 20, 2018 19:01
Show Gist options
  • Save mstriemer/c52c8815672301d37b66e3af6328876e to your computer and use it in GitHub Desktop.
Save mstriemer/c52c8815672301d37b66e3af6328876e to your computer and use it in GitHub Desktop.
The last rebase for homepage doorhanger
changeset: 456453:8173c389b897
bookmark: 1397809-homepage-doorhanger-with-icon-link
user: Mark Striemer <[email protected]>
date: Tue Mar 20 13:39:00 2018 -0500
summary: Fixes with learn more link
diff --git a/browser/components/extensions/ExtensionControlledPopup.jsm b/browser/components/extensions/ExtensionControlledPopup.jsm
--- a/browser/components/extensions/ExtensionControlledPopup.jsm
+++ b/browser/components/extensions/ExtensionControlledPopup.jsm
@@ -21,16 +21,24 @@ var EXPORTED_SYMBOLS = ["ExtensionContro
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm");
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-ChromeUtils.defineModuleGetter(this, "ExtensionSettingsStore",
- "resource://gre/modules/ExtensionSettingsStore.jsm");
ChromeUtils.defineModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
+ChromeUtils.defineModuleGetter(this, "BrowserUtils",
+ "resource://gre/modules/BrowserUtils.jsm");
ChromeUtils.defineModuleGetter(this, "CustomizableUI",
"resource:///modules/CustomizableUI.jsm");
+ChromeUtils.defineModuleGetter(this, "ExtensionSettingsStore",
+ "resource://gre/modules/ExtensionSettingsStore.jsm");
let {makeWidgetId} = ExtensionUtils;
+XPCOMUtils.defineLazyGetter(this, "strBundle", function() {
+ return Services.strings.createBundle("chrome://global/locale/extensions.properties");
+});
+
+
class ExtensionControlledPopup {
/* Provide necessary options for the popup.
*
@@ -71,7 +79,10 @@ class ExtensionControlledPopup {
this.popupnotificationId = opts.popupnotificationId;
this.settingType = opts.settingType;
this.settingKey = opts.settingKey;
- this.beforeShow = opts.beforeShow;
+ this.descriptionId = opts.descriptionId;
+ this.descriptionMessageId = opts.descriptionMessageId;
+ this.learnMoreMessageId = opts.learnMoreMessageId;
+ this.learnMoreLink = opts.learnMoreLink;
this.onObserverAdded = opts.onObserverAdded;
this.onObserverRemoved = opts.onObserverRemoved;
this.beforeDisableAddon = opts.beforeDisableAddon;
@@ -151,8 +162,9 @@ class ExtensionControlledPopup {
let panel = doc.getElementById("extension-notification-panel");
let popupnotification = doc.getElementById(this.popupnotificationId);
let urlBarWasFocused = win.gURLBar.focused;
+ let addon = await AddonManager.getAddonByID(item.id);
- await this.beforeShow(item.id, panel, win);
+ this.populateDescription(doc, addon);
if (!popupnotification) {
throw new Error(`No popupnotification found for id "${this.popupnotificationId}"`);
@@ -168,7 +180,6 @@ class ExtensionControlledPopup {
} else {
// Secondary action is to restore settings.
await this.beforeDisableAddon(this, win);
- let addon = await AddonManager.getAddonByID(item.id);
addon.userDisabled = true;
}
@@ -201,4 +212,34 @@ class ExtensionControlledPopup {
popupnotification.hidden = false;
panel.openPopup(anchor);
}
+
+ getAddonDetails(doc, addon) {
+ const defaultIcon = "chrome://mozapps/skin/extensions/extensionGeneric.svg";
+
+ let image = doc.createElement("image");
+ image.setAttribute("src", addon.iconURL || defaultIcon);
+ image.classList.add("extension-controlled-icon");
+
+ let addonDetails = doc.createDocumentFragment();
+ addonDetails.appendChild(image);
+ addonDetails.appendChild(doc.createTextNode(" " + addon.name));
+
+ return addonDetails;
+ }
+
+ populateDescription(doc, addon) {
+ let description = doc.getElementById(this.descriptionId);
+ description.textContent = "";
+
+ let addonDetails = this.getAddonDetails(doc, addon);
+ let message = strBundle.GetStringFromName(this.descriptionMessageId);
+ description.appendChild(
+ BrowserUtils.getLocalizedFragment(doc, message, addonDetails));
+
+ let link = doc.createElement("label");
+ link.setAttribute("class", "learnMore text-link");
+ link.href = Services.urlFormatter.formatURLPref("app.support.baseURL") + this.learnMoreLink;
+ link.textContent = strBundle.GetStringFromName(this.learnMoreMessageId);
+ description.appendChild(link);
+ }
}
diff --git a/browser/components/extensions/ext-browser.js b/browser/components/extensions/ext-browser.js
--- a/browser/components/extensions/ext-browser.js
+++ b/browser/components/extensions/ext-browser.js
@@ -8,7 +8,7 @@
/* global EventEmitter:false, TabContext:false, WindowEventManager:false,
waitForTabLoaded:false, replaceUrlInTab:false, makeWidgetId:false,
- getAddonDetails:false, tabTracker:true, windowTracker:true */
+ tabTracker:true, windowTracker:true */
/* import-globals-from ../../../toolkit/components/extensions/ext-toolkit.js */
/* globals TabBase, WindowBase, TabTrackerBase, WindowTrackerBase, TabManagerBase, WindowManagerBase */
@@ -127,20 +127,6 @@ global.replaceUrlInTab = (gBrowser, tab,
return loaded;
};
-global.getAddonDetails = (doc, addon) => {
- const defaultIcon = "chrome://mozapps/skin/extensions/extensionGeneric.svg";
-
- let image = doc.createElement("image");
- image.setAttribute("src", addon.iconURL || defaultIcon);
- image.classList.add("extension-controlled-icon");
-
- let addonDetails = doc.createDocumentFragment();
- addonDetails.appendChild(image);
- addonDetails.appendChild(doc.createTextNode(" " + addon.name));
-
- return addonDetails;
-};
-
// Manages tab-specific context data, and dispatching tab select events
// across all windows.
global.TabContext = class extends EventEmitter {
diff --git a/browser/components/extensions/ext-chrome-settings-overrides.js b/browser/components/extensions/ext-chrome-settings-overrides.js
--- a/browser/components/extensions/ext-chrome-settings-overrides.js
+++ b/browser/components/extensions/ext-chrome-settings-overrides.js
@@ -58,16 +58,10 @@ XPCOMUtils.defineLazyGetter(this, "homep
popupnotificationId: "extension-homepage-notification",
settingType: HOMEPAGE_SETTING_TYPE,
settingKey: HOMEPAGE_SETTING_NAME,
- async beforeShow(id, popup, win) {
- let doc = win.document;
- let addon = await AddonManager.getAddonByID(id);
- let description = doc.getElementById("extension-homepage-notification-description");
- let message = strBundle.GetStringFromName("homepageControlled.message");
- let addonDetails = getAddonDetails(doc, addon);
- description.textContent = "";
- description.appendChild(
- BrowserUtils.getLocalizedFragment(doc, message, addonDetails));
- },
+ descriptionId: "extension-homepage-notification-description",
+ descriptionMessageId: "homepageControlled.message",
+ learnMoreMessageId: "homepageControlled.learnMore",
+ learnMoreLink: "extension-home",
async beforeDisableAddon(popup, win) {
// Disabling an add-on should remove the tabs that it has open, but we want
// to open the new homepage in this tab (which might get closed).
diff --git a/browser/components/extensions/ext-url-overrides.js b/browser/components/extensions/ext-url-overrides.js
--- a/browser/components/extensions/ext-url-overrides.js
+++ b/browser/components/extensions/ext-url-overrides.js
@@ -7,8 +7,6 @@
ChromeUtils.defineModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
-ChromeUtils.defineModuleGetter(this, "BrowserUtils",
- "resource://gre/modules/BrowserUtils.jsm");
ChromeUtils.defineModuleGetter(this, "CustomizableUI",
"resource:///modules/CustomizableUI.jsm");
ChromeUtils.defineModuleGetter(this, "ExtensionControlledPopup",
@@ -24,10 +22,6 @@ const STORE_TYPE = "url_overrides";
const NEW_TAB_SETTING_NAME = "newTabURL";
const NEW_TAB_CONFIRMED_TYPE = "newTabNotification";
-XPCOMUtils.defineLazyGetter(this, "strBundle", function() {
- return Services.strings.createBundle("chrome://global/locale/extensions.properties");
-});
-
XPCOMUtils.defineLazyGetter(this, "newTabPopup", () => {
return new ExtensionControlledPopup({
confirmedType: NEW_TAB_CONFIRMED_TYPE,
@@ -35,22 +29,16 @@ XPCOMUtils.defineLazyGetter(this, "newTa
popupnotificationId: "extension-new-tab-notification",
settingType: STORE_TYPE,
settingKey: NEW_TAB_SETTING_NAME,
+ descriptionId: "extension-new-tab-notification-description",
+ descriptionMessageId: "newTabControlled.message2",
+ learnMoreMessageId: "newTabControlled.learnMore",
+ learnMoreLink: "extension-home",
onObserverAdded() {
aboutNewTabService.willNotifyUser = true;
},
onObserverRemoved() {
aboutNewTabService.willNotifyUser = false;
},
- async beforeShow(id, popup, win) {
- let doc = win.document;
- let addon = await AddonManager.getAddonByID(id);
- let description = doc.getElementById("extension-new-tab-notification-description");
- let message = strBundle.GetStringFromName("newTabControlled.message2");
- let addonDetails = getAddonDetails(doc, addon);
- description.textContent = "";
- description.appendChild(
- BrowserUtils.getLocalizedFragment(doc, message, addonDetails));
- },
async beforeDisableAddon(popup, win) {
// ExtensionControlledPopup will disable the add-on once this function completes.
// Disabling an add-on should remove the tabs that it has open, but we want
diff --git a/browser/components/extensions/test/browser/browser_ext_ExtensionControlledPopup.js b/browser/components/extensions/test/browser/browser_ext_ExtensionControlledPopup.js
--- a/browser/components/extensions/test/browser/browser_ext_ExtensionControlledPopup.js
+++ b/browser/components/extensions/test/browser/browser_ext_ExtensionControlledPopup.js
@@ -34,13 +34,12 @@ function createMarkup(doc) {
Object.entries(attributes).forEach(([key, value]) => {
popupnotification.setAttribute(key, value);
});
- popupnotification.innerHTML = `
- <popupnotificationcontent orient="vertical">
- <description>
- This is a test.
- </description>
- </popupnotificationcontent>
- `;
+ let content = doc.createElement("popupnotificationcontent");
+ content.setAttribute("orient", "vertical");
+ let description = doc.createElement("description");
+ description.setAttribute("id", "extension-controlled-description");
+ content.appendChild(description);
+ popupnotification.appendChild(content);
panel.appendChild(popupnotification);
registerCleanupFunction(function removePopup() {
@@ -58,7 +57,10 @@ function createMarkup(doc) {
add_task(async function testExtensionControlledPopup() {
let id = "[email protected]";
let extension = ExtensionTestUtils.loadExtension({
- manifest: {applications: {gecko: {id}}},
+ manifest: {
+ applications: {gecko: {id}},
+ name: "Ext Controlled",
+ },
// We need to be able to find the extension using AddonManager.
useAddonManager: "temporary",
});
@@ -74,19 +76,20 @@ add_task(async function testExtensionCon
let confirmedType = "extension-controlled-confirmed";
let onObserverAdded = sinon.spy();
let onObserverRemoved = sinon.spy();
- let beforeShow = sinon.spy();
let observerTopic = "extension-controlled-event";
let beforeDisableAddon = sinon.spy();
let settingType = "extension-controlled";
let settingKey = "some-key";
let popup = new ExtensionControlledPopup({
- beforeShow,
confirmedType,
observerTopic,
popupnotificationId: "extension-controlled-notification",
settingType,
settingKey,
- windowTracker,
+ descriptionId: "extension-controlled-description",
+ descriptionMessageId: "newTabControlled.message2",
+ learnMoreMessageId: "newTabControlled.learnMore",
+ learnMoreLink: "extension-controlled",
onObserverAdded,
onObserverRemoved,
beforeDisableAddon,
@@ -137,7 +140,6 @@ add_task(async function testExtensionCon
is(popupnotification.hidden, true, "The popup is hidden");
is(addon.userDisabled, false, "The extension is enabled");
is(await popup.userHasConfirmed(id), false, "The user is not initially confirmed");
- ok(!beforeShow.called, "beforeShow has not been called");
// The popup should opened based on the observer event.
await openPopupWithEvent();
@@ -149,7 +151,15 @@ add_task(async function testExtensionCon
is(panel.getAttribute("panelopen"), "true", "The panel is open");
is(popupnotification.hidden, false, "The popup content is visible");
is(await popup.userHasConfirmed(id), false, "The user has not confirmed yet");
- ok(beforeShow.calledOnce, "beforeShow was called");
+
+ // Verify the description is populated.
+ let description = doc.getElementById("extension-controlled-description");
+ is(description.textContent,
+ "An extension, Ext Controlled, changed the page you see when you open a new tab.Learn more",
+ "The extension name is in the description");
+ let link = description.querySelector("label");
+ is(link.href, "http://127.0.0.1:8888/support-dummy/extension-controlled",
+ "The link has the href set from learnMoreLink");
// Force close the popup, as if a user clicked away from it.
await closePopupWithAction("ignore");
diff --git a/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js b/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js
--- a/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js
+++ b/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js
@@ -362,12 +362,16 @@ add_task(async function test_doorhanger_
applications: {
gecko: {id: ext1Id},
},
+ name: "Ext1",
},
files: {"ext1.html": "<h1>1</h1>"},
useAddonManager: "temporary",
});
let ext2 = ExtensionTestUtils.loadExtension({
- manifest: {"chrome_settings_overrides": {"homepage": "ext2.html"}},
+ manifest: {
+ chrome_settings_overrides: {homepage: "ext2.html"},
+ name: "Ext2",
+ },
files: {"ext2.html": "<h1>2</h1>"},
useAddonManager: "temporary",
});
@@ -382,10 +386,14 @@ add_task(async function test_doorhanger_
await windowOpenedPromise;
await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
let doc = win.document;
+ let description = doc.getElementById("extension-homepage-notification-description");
let panel = doc.getElementById("extension-notification-panel");
await promisePopupShown(panel);
ok(win.gURLBar.value.endsWith("ext2.html"), "ext2 is in control");
+ is(description.textContent,
+ "An extension, Ext2, changed what you see when you open your homepage and new windows.Learn more",
+ "The extension name is in the popup");
// Click Restore Settings.
let popupHidden = promisePopupHidden(panel);
@@ -399,6 +407,9 @@ add_task(async function test_doorhanger_
await promisePopupShown(panel);
ok(win.gURLBar.value.endsWith("ext1.html"), "ext1 is in control");
+ is(description.textContent,
+ "An extension, Ext1, changed what you see when you open your homepage and new windows.Learn more",
+ "The extension name is in the popup");
// Click Keep Changes.
doc.getAnonymousElementByAttribute(popupnotification, "anonid", "button").click();
diff --git a/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js b/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
--- a/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
+++ b/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
@@ -218,7 +218,7 @@ add_task(async function test_new_tab_kee
is(panel.anchorNode.closest("toolbarbutton").id, "PanelUI-menu-button",
"The doorhanger is anchored to the menu icon");
is(panel.querySelector("description").textContent,
- "An extension, New Tab Add-on, changed the page you see when you open a new tab.",
+ "An extension, New Tab Add-on, changed the page you see when you open a new tab.Learn more",
"The description includes the add-on name");
// Click the Keep Changes button.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment