Bug 1280128: [webext] Use transparent backgrounds and correct border radii for popup browsers. r=bwinton ui-r=maritz

MozReview-Commit-ID: 9jmuxdSLmBM
This commit is contained in:
Kris Maglione
2016-08-09 10:54:53 -07:00
parent 742e1fb7b3
commit c42feb4686
12 changed files with 202 additions and 18 deletions

View File

@@ -4,9 +4,15 @@
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
"resource:///modules/CustomizableUI.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "styleSheetService",
"@mozilla.org/content/style-sheet-service;1",
"nsIStyleSheetService");
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
@@ -42,18 +48,14 @@ function promisePopupShown(popup) {
});
}
XPCOMUtils.defineLazyGetter(global, "stylesheets", () => {
let styleSheetService = Cc["@mozilla.org/content/style-sheet-service;1"]
.getService(Components.interfaces.nsIStyleSheetService);
let styleSheetURI = Services.io.newURI("chrome://browser/content/extension.css",
null, null);
XPCOMUtils.defineLazyGetter(this, "stylesheets", () => {
let styleSheetURI = NetUtil.newURI("chrome://browser/content/extension.css");
let styleSheet = styleSheetService.preloadSheet(styleSheetURI,
styleSheetService.AGENT_SHEET);
let stylesheets = [styleSheet];
if (AppConstants.platform === "macosx") {
styleSheetURI = Services.io.newURI("chrome://browser/content/extension-mac.css",
null, null);
styleSheetURI = NetUtil.newURI("chrome://browser/content/extension-mac.css");
let macStyleSheet = styleSheetService.preloadSheet(styleSheetURI,
styleSheetService.AGENT_SHEET);
stylesheets.push(macStyleSheet);
@@ -61,6 +63,24 @@ XPCOMUtils.defineLazyGetter(global, "stylesheets", () => {
return stylesheets;
});
XPCOMUtils.defineLazyGetter(this, "standaloneStylesheets", () => {
let stylesheets = [];
if (AppConstants.platform === "macosx") {
let styleSheetURI = NetUtil.newURI("chrome://browser/content/extension-mac-panel.css");
let macStyleSheet = styleSheetService.preloadSheet(styleSheetURI,
styleSheetService.AGENT_SHEET);
stylesheets.push(macStyleSheet);
}
if (AppConstants.platform === "win") {
let styleSheetURI = NetUtil.newURI("chrome://browser/content/extension-win-panel.css");
let winStyleSheet = styleSheetService.preloadSheet(styleSheetURI,
styleSheetService.AGENT_SHEET);
stylesheets.push(winStyleSheet);
}
return stylesheets;
});
class BasePopup {
constructor(extension, viewNode, popupURL, browserStyle) {
let popupURI = Services.io.newURI(popupURL, null, extension.baseURI);
@@ -123,11 +143,20 @@ class BasePopup {
break;
case "DOMWindowCreated":
if (this.browserStyle && event.target === this.browser.contentDocument) {
if (event.target === this.browser.contentDocument) {
let winUtils = this.browser.contentWindow
.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
for (let stylesheet of global.stylesheets) {
winUtils.addSheet(stylesheet, winUtils.AGENT_SHEET);
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
if (this.browserStyle) {
for (let stylesheet of stylesheets) {
winUtils.addSheet(stylesheet, winUtils.AGENT_SHEET);
}
}
if (!this.fixedWidth) {
for (let stylesheet of standaloneStylesheets) {
winUtils.addSheet(stylesheet, winUtils.AGENT_SHEET);
}
}
}
break;
@@ -174,6 +203,8 @@ class BasePopup {
this.browser = document.createElementNS(XUL_NS, "browser");
this.browser.setAttribute("type", "content");
this.browser.setAttribute("disableglobalhistory", "true");
this.browser.setAttribute("transparent", "true");
this.browser.setAttribute("class", "webextension-popup-browser");
this.browser.setAttribute("webextension-view-type", "popup");
// We only need flex sizing for the sake of the slide-in sub-views of the