Bug 1354109 - update WebExtensions code for Photon, r?kmag
MozReview-Commit-ID: 8nHvyafxwV1
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -18,16 +18,18 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource:///modules/ExtensionPopups.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "DOMUtils",
"@mozilla.org/inspector/dom-utils;1",
"inIDOMUtils");
Cu.import("resource://gre/modules/EventEmitter.jsm");
+XPCOMUtils.defineLazyPreferenceGetter(this, "gPhotonStructure", "browser.photon.structure.enabled");
+
var {
DefaultWeakMap,
} = ExtensionUtils;
Cu.import("resource://gre/modules/ExtensionParent.jsm");
var {
IconDetails,
@@ -47,17 +49,17 @@ function isAncestorOrSelf(target, node)
}
// WeakMap[Extension -> BrowserAction]
const browserActionMap = new WeakMap();
XPCOMUtils.defineLazyGetter(this, "browserAreas", () => {
return {
"navbar": CustomizableUI.AREA_NAVBAR,
- "menupanel": CustomizableUI.AREA_PANEL,
+ "menupanel": gPhotonStructure ? CustomizableUI.AREA_FIXED_OVERFLOW_PANEL : CustomizableUI.AREA_PANEL,
"tabstrip": CustomizableUI.AREA_TABSTRIP,
"personaltoolbar": CustomizableUI.AREA_BOOKMARKS,
};
});
this.browserAction = class extends ExtensionAPI {
static for(extension) {
return browserActionMap.get(extension);
@@ -213,17 +215,21 @@ this.browserAction = class extends Exten
return;
}
// Popups are shown only if a popup URL is defined; otherwise
// a "click" event is dispatched. This is done for compatibility with the
// Google Chrome onClicked extension API.
if (this.getProperty(tab, "popup")) {
if (this.widget.areaType == CustomizableUI.TYPE_MENU_PANEL) {
- await window.PanelUI.show();
+ if (gPhotonStructure) {
+ await window.document.getElementById("nav-bar").overflowable.show();
+ } else {
+ await window.PanelUI.show();
+ }
}
let event = new window.CustomEvent("command", {bubbles: true, cancelable: true});
widget.node.dispatchEvent(event);
} else {
this.emit("click");
}
}
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_area.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_area.js
@@ -1,15 +1,15 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
var browserAreas = {
"navbar": CustomizableUI.AREA_NAVBAR,
- "menupanel": CustomizableUI.AREA_PANEL,
+ "menupanel": getCustomizableUIPanelID(),
"tabstrip": CustomizableUI.AREA_TABSTRIP,
"personaltoolbar": CustomizableUI.AREA_BOOKMARKS,
};
async function testInArea(area) {
let manifest = {
"browser_action": {
"browser_style": true,
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon.js
@@ -290,34 +290,36 @@ add_task(async function testDetailsObjec
await SpecialPowers.popPrefEnv();
}
if (!test.menuResolutions) {
continue;
}
- // Test icon sizes in the menu panel.
- CustomizableUI.addWidgetToArea(browserActionWidget.id,
- CustomizableUI.AREA_PANEL);
+ if (!gPhotonStructure) {
+ // Test icon sizes in the menu panel.
+ CustomizableUI.addWidgetToArea(browserActionWidget.id,
+ CustomizableUI.AREA_PANEL);
- await showBrowserAction(extension);
- browserActionButton = browserActionWidget.forWindow(window).node;
+ await showBrowserAction(extension);
+ browserActionButton = browserActionWidget.forWindow(window).node;
- for (let resolution of Object.keys(test.menuResolutions)) {
- await SpecialPowers.pushPrefEnv({set: [[RESOLUTION_PREF, resolution]]});
+ for (let resolution of Object.keys(test.menuResolutions)) {
+ await SpecialPowers.pushPrefEnv({set: [[RESOLUTION_PREF, resolution]]});
- is(window.devicePixelRatio, +resolution, "window has the required resolution");
+ is(window.devicePixelRatio, +resolution, "window has the required resolution");
- let imageURL = test.menuResolutions[resolution];
- is(getListStyleImage(browserActionButton), imageURL, `browser action has the correct menu image at ${resolution}x resolution`);
+ let imageURL = test.menuResolutions[resolution];
+ is(getListStyleImage(browserActionButton), imageURL, `browser action has the correct menu image at ${resolution}x resolution`);
- await SpecialPowers.popPrefEnv();
- }
+ await SpecialPowers.popPrefEnv();
+ }
- await closeBrowserAction(extension);
+ await closeBrowserAction(extension);
- CustomizableUI.addWidgetToArea(browserActionWidget.id,
- CustomizableUI.AREA_NAVBAR);
+ CustomizableUI.addWidgetToArea(browserActionWidget.id,
+ CustomizableUI.AREA_NAVBAR);
+ }
}
await extension.unload();
});
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
@@ -228,10 +228,10 @@ async function testInArea(area) {
is(view, null, "browserAction view removed from document");
}
add_task(async function testBrowserActionInToolbar() {
await testInArea(CustomizableUI.AREA_NAVBAR);
});
add_task(async function testBrowserActionInPanel() {
- await testInArea(CustomizableUI.AREA_PANEL);
+ await testInArea(getCustomizableUIPanelID());
});
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
@@ -143,21 +143,21 @@ async function testPopupSize(standardsMo
`Window width should return to approximately its original value (${win.innerWidth} ~= ${innerWidth})`);
await closeBrowserAction(extension, browserWin);
}
// Test the PanelUI panel for a menu panel button.
let widget = getBrowserActionWidget(extension);
- CustomizableUI.addWidgetToArea(widget.id, CustomizableUI.AREA_PANEL);
+ CustomizableUI.addWidgetToArea(widget.id, getCustomizableUIPanelID());
let browser = await openPanel(extension, browserWin);
- let {panel} = browserWin.PanelUI;
+ let panel = gPhotonStructure ? browserWin.PanelUI.overflowPanel : browserWin.PanelUI.panel;
let origPanelRect = panel.getBoundingClientRect();
// Check that the panel is still positioned as expected.
let checkPanelPosition = () => {
is(panel.getAttribute("side"), arrowSide, "Panel arrow is positioned as expected");
let panelRect = panel.getBoundingClientRect();
if (arrowSide == "top") {
@@ -271,17 +271,17 @@ add_task(async function testBrowserActio
await testPopupSize(false);
});
// Test that we still make reasonable maximum size calculations when the window
// is close enough to the bottom of the screen that the menu panel opens above,
// rather than below, its button.
add_task(async function testBrowserActionMenuResizeBottomArrow() {
const WIDTH = 800;
- const HEIGHT = 300;
+ const HEIGHT = 80;
let left = screen.availLeft + screen.availWidth - WIDTH;
let top = screen.availTop + screen.availHeight - HEIGHT;
let win = await BrowserTestUtils.openNewBrowserWindow();
win.resizeTo(WIDTH, HEIGHT);
--- a/browser/components/extensions/test/browser/browser_ext_commands_execute_browser_action.js
+++ b/browser/components/extensions/test/browser/browser_ext_commands_execute_browser_action.js
@@ -106,17 +106,17 @@ add_task(async function test_execute_bro
add_task(async function test_execute_browser_action_without_popup() {
await testExecuteBrowserActionWithOptions();
});
add_task(async function test_execute_browser_action_in_hamburger_menu_with_popup() {
await testExecuteBrowserActionWithOptions({
withPopup: true,
- inArea: CustomizableUI.AREA_PANEL,
+ inArea: getCustomizableUIPanelID(),
});
});
add_task(async function test_execute_browser_action_in_hamburger_menu_without_popup() {
await testExecuteBrowserActionWithOptions({
- inArea: CustomizableUI.AREA_PANEL,
+ inArea: getCustomizableUIPanelID(),
});
});
--- a/browser/components/extensions/test/browser/browser_ext_popup_background.js
+++ b/browser/components/extensions/test/browser/browser_ext_popup_background.js
@@ -107,17 +107,17 @@ add_task(async function testPopupBackgro
await testPanel(browser, true);
await closeBrowserAction(extension);
}
{
info("Test menu panel browserAction popup");
let widget = getBrowserActionWidget(extension);
- CustomizableUI.addWidgetToArea(widget.id, CustomizableUI.AREA_PANEL);
+ CustomizableUI.addWidgetToArea(widget.id, getCustomizableUIPanelID());
clickBrowserAction(extension);
let browser = await awaitExtensionPanel(extension);
await testPanel(browser, false);
await closeBrowserAction(extension);
}
{
--- a/browser/components/extensions/test/browser/browser_ext_popup_corners.js
+++ b/browser/components/extensions/test/browser/browser_ext_popup_corners.js
@@ -72,17 +72,17 @@ add_task(async function testPopupBorderR
await testPanel(browser);
await closeBrowserAction(extension);
}
{
info("Test menu panel browserAction popup");
let widget = getBrowserActionWidget(extension);
- CustomizableUI.addWidgetToArea(widget.id, CustomizableUI.AREA_PANEL);
+ CustomizableUI.addWidgetToArea(widget.id, getCustomizableUIPanelID());
clickBrowserAction(extension);
let browser = await awaitExtensionPanel(extension);
await testPanel(browser, false);
await closeBrowserAction(extension);
}
{
--- a/browser/components/extensions/test/browser/browser_ext_popup_shutdown.js
+++ b/browser/components/extensions/test/browser/browser_ext_popup_shutdown.js
@@ -46,17 +46,17 @@ add_task(async function testStandaloneBr
});
add_task(async function testMenuPanelBrowserAction() {
let extension = getExtension();
await extension.startup();
await extension.awaitMessage("pageAction ready");
let widget = getBrowserActionWidget(extension);
- CustomizableUI.addWidgetToArea(widget.id, CustomizableUI.AREA_PANEL);
+ CustomizableUI.addWidgetToArea(widget.id, getCustomizableUIPanelID());
clickBrowserAction(extension);
let browser = await awaitExtensionPanel(extension);
let panel = getPanelForNode(browser);
await extension.unload();
is(panel.state, "closed", "Panel should be closed");
--- a/browser/components/extensions/test/browser/browser_ext_themes_icons.js
+++ b/browser/components/extensions/test/browser/browser_ext_themes_icons.js
@@ -158,27 +158,29 @@ async function runTestWithIcons(icons) {
}
let extension = ExtensionTestUtils.loadExtension({manifest, files});
await extension.startup();
checkButtons(icons, ICON_INFO, "toolbar");
- for (let button of ICON_INFO) {
- if (button[2]) {
- CustomizableUI.addWidgetToArea(button[2], CustomizableUI.AREA_PANEL);
+ if (!gPhotonStructure) {
+ for (let button of ICON_INFO) {
+ if (button[2]) {
+ CustomizableUI.addWidgetToArea(button[2], CustomizableUI.AREA_PANEL);
+ }
}
- }
- await PanelUI.show();
+ await PanelUI.show();
- checkButtons(icons, ICON_INFO, "panel");
+ checkButtons(icons, ICON_INFO, "panel");
- await PanelUI.hide();
+ await PanelUI.hide();
+ }
await extension.unload();
for (let button of ICON_INFO) {
verifyButtonWithoutCustomStyling(button[1],
`The ${button[1]} should not have it's icon customized when the theme is unloaded`);
}
}
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -13,17 +13,17 @@
* openExtensionContextMenu closeExtensionContextMenu
* openActionContextMenu openSubmenu closeActionContextMenu
* openTabContextMenu closeTabContextMenu
* imageBuffer imageBufferFromDataURI
* getListStyleImage getPanelForNode
* awaitExtensionPanel awaitPopupResize
* promiseContentDimensions alterContent
* promisePrefChangeObserved openContextMenuInFrame
- * promiseAnimationFrame
+ * promiseAnimationFrame getCustomizableUIPanelID
*/
const {AppConstants} = Cu.import("resource://gre/modules/AppConstants.jsm", {});
const {CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm", {});
// We run tests under two different configurations, from browser.ini and
// browser-remote.ini. When running from browser-remote.ini, the tests are
// copied to the sub-directory "test-oop-extensions", which we detect here, and
@@ -196,37 +196,49 @@ var awaitExtensionPanel = async function
promisePopupShown(getPanelForNode(browser)),
awaitLoad && awaitBrowserLoaded(browser, awaitLoad),
]);
return browser;
};
+function getCustomizableUIPanelID() {
+ return gPhotonStructure ? CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
+ : CustomizableUI.AREA_PANEL;
+}
+
function getBrowserActionWidget(extension) {
return CustomizableUI.getWidget(makeWidgetId(extension.id) + "-browser-action");
}
function getBrowserActionPopup(extension, win = window) {
let group = getBrowserActionWidget(extension);
if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
return win.document.getElementById("customizationui-widget-panel");
}
- return win.PanelUI.panel;
+ return gPhotonStructure ? win.PanelUI.overflowPanel : win.PanelUI.panel;
}
var showBrowserAction = async function(extension, win = window) {
let group = getBrowserActionWidget(extension);
let widget = group.forWindow(win);
if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
ok(!widget.overflowed, "Expect widget not to be overflowed");
} else if (group.areaType == CustomizableUI.TYPE_MENU_PANEL) {
- await win.PanelUI.show();
+ // Show the right panel. After Photon is turned on permanently, this
+ // can be re-simplified. This is unfortunately easier than getting
+ // and using the panel (area) ID out of CustomizableUI for the widget.
+ if (gPhotonStructure) {
+ await win.document.getElementById("nav-bar").overflowable.show();
+ } else {
+ await win.PanelUI.show();
+ }
}
};
var clickBrowserAction = async function(extension, win = window) {
await promiseAnimationFrame(win);
await showBrowserAction(extension, win);
let widget = getBrowserActionWidget(extension).forWindow(win);