Skip to content

Commit

Permalink
Backed out 12 changesets (bug 1202482, bug 1202483, bug 1202481, bug …
Browse files Browse the repository at this point in the history
…1202486, bug 1202479, bug 1202478, bug 1197475, bug 1203331, bug 1139860, bug 1202501, bug 1199473, bug 1190662) for Mulet mochitest-5 timeouts

CLOSED TREE

Backed out changeset 6503123e95dd (bug 1139860)
Backed out changeset b83bc163064d (bug 1203331)
Backed out changeset 2f501bd57cd2 (bug 1202481)
Backed out changeset 37e6ac7beb42 (bug 1202486)
Backed out changeset f9b6e99e620e (bug 1202483)
Backed out changeset 466af9f9baee (bug 1202482)
Backed out changeset 6be690e265a2 (bug 1202479)
Backed out changeset 57ff88bfccf4 (bug 1197475)
Backed out changeset 7e8c04ff6049 (bug 1202478)
Backed out changeset 525227997274 (bug 1202501)
Backed out changeset da317cdb79d3 (bug 1199473)
Backed out changeset 73b8ddd6dac9 (bug 1190662)

--HG--
rename : browser/components/extensions/test/browser/browser_ext_simple.js => browser/components/extensions/test/browser/browser_extensions_simple.js
rename : toolkit/components/extensions/test/mochitest/file_sample.html => toolkit/components/extensions/test/mochitest/file_contentscript_page1.html
  • Loading branch information
philor committed Sep 23, 2015
1 parent 449e911 commit 5b1ea92
Show file tree
Hide file tree
Showing 38 changed files with 188 additions and 1,415 deletions.
187 changes: 61 additions & 126 deletions browser/components/extensions/ext-browserAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ var {
// WeakMap[Extension -> BrowserAction]
var browserActionMap = new WeakMap();

// WeakMap[Extension -> docshell]
// This map is a cache of the windowless browser that's used to render ImageData
// for the browser_action icon.
let imageRendererMap = new WeakMap();

function browserActionOf(extension)
{
return browserActionMap.get(extension);
Expand Down Expand Up @@ -46,6 +41,9 @@ function BrowserAction(options, extension)
this.icon = new DefaultWeakMap(options.default_icon);
this.popup = new DefaultWeakMap(options.default_popup);

// Make the default something that won't compare equal to anything.
this.prevPopups = new DefaultWeakMap({});

this.context = null;
}

Expand All @@ -65,14 +63,12 @@ BrowserAction.prototype = {
this.updateTab(null, node);

let tabbrowser = document.defaultView.gBrowser;
tabbrowser.tabContainer.addEventListener("TabSelect", this);
tabbrowser.ownerDocument.addEventListener("TabSelect", () => {
this.updateTab(tabbrowser.selectedTab, node);
});

node.addEventListener("command", event => {
let tab = tabbrowser.selectedTab;
let popup = this.getProperty(tab, "popup");
if (popup) {
this.togglePopup(node, popup);
} else {
if (node.getAttribute("type") != "panel") {
this.emit("click");
}
});
Expand All @@ -83,81 +79,6 @@ BrowserAction.prototype = {
this.widget = widget;
},

handleEvent(event) {
if (event.type == "TabSelect") {
let window = event.target.ownerDocument.defaultView;
let tabbrowser = window.gBrowser;
let instance = CustomizableUI.getWidget(this.id).forWindow(window);
if (instance) {
this.updateTab(tabbrowser.selectedTab, instance.node);
}
}
},

togglePopup(node, popupResource) {
let popupURL = this.extension.baseURI.resolve(popupResource);

let document = node.ownerDocument;
let panel = document.createElement("panel");
panel.setAttribute("class", "browser-action-panel");
panel.setAttribute("type", "arrow");
panel.setAttribute("flip", "slide");
node.appendChild(panel);

panel.addEventListener("popuphidden", () => {
this.context.unload();
this.context = null;
panel.remove();
});

const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let browser = document.createElementNS(XUL_NS, "browser");
browser.setAttribute("type", "content");
browser.setAttribute("disableglobalhistory", "true");
panel.appendChild(browser);

let loadListener = () => {
panel.removeEventListener("load", loadListener);

this.context = new ExtensionPage(this.extension, {
type: "popup",
contentWindow: browser.contentWindow,
uri: Services.io.newURI(popupURL, null, null),
docShell: browser.docShell,
});
GlobalManager.injectInDocShell(browser.docShell, this.extension, this.context);
browser.setAttribute("src", popupURL);

let contentLoadListener = () => {
browser.removeEventListener("load", contentLoadListener);

let contentViewer = browser.docShell.contentViewer;
let width = {}, height = {};
try {
contentViewer.getContentSize(width, height);
[width, height] = [width.value, height.value];
} catch (e) {
// getContentSize can throw
[width, height] = [400, 400];
}

let window = document.defaultView;
width /= window.devicePixelRatio;
height /= window.devicePixelRatio;
width = Math.min(width, 800);
height = Math.min(height, 800);

browser.setAttribute("width", width);
browser.setAttribute("height", height);

let anchor = document.getAnonymousElementByAttribute(node, "class", "toolbarbutton-icon");
panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
};
browser.addEventListener("load", contentLoadListener, true);
};
panel.addEventListener("load", loadListener);
},

// Initialize the toolbar icon and popup given that |tab| is the
// current tab and |node| is the CustomizableUI node. Note: |tab|
// will be null if we don't know the current tab yet (during
Expand Down Expand Up @@ -197,6 +118,57 @@ BrowserAction.prototype = {

let iconURL = this.getIcon(tab, node);
node.setAttribute("image", iconURL);

let popup = this.getProperty(tab, "popup");

if (popup != this.prevPopups.get(window)) {
this.prevPopups.set(window, popup);

let panel = node.querySelector("panel");
if (panel) {
panel.remove();
}

if (popup) {
let popupURL = this.extension.baseURI.resolve(popup);
node.setAttribute("type", "panel");

let document = node.ownerDocument;
let panel = document.createElement("panel");
panel.setAttribute("class", "browser-action-panel");
panel.setAttribute("type", "arrow");
panel.setAttribute("flip", "slide");
node.appendChild(panel);

const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let browser = document.createElementNS(XUL_NS, "browser");
browser.setAttribute("type", "content");
browser.setAttribute("disableglobalhistory", "true");
browser.setAttribute("width", "500");
browser.setAttribute("height", "500");
panel.appendChild(browser);

let loadListener = () => {
panel.removeEventListener("load", loadListener);

if (this.context) {
this.context.unload();
}

this.context = new ExtensionPage(this.extension, {
type: "popup",
contentWindow: browser.contentWindow,
uri: Services.io.newURI(popupURL, null, null),
docShell: browser.docShell,
});
GlobalManager.injectInDocShell(browser.docShell, this.extension, this.context);
browser.setAttribute("src", popupURL);
};
panel.addEventListener("load", loadListener);
} else {
node.removeAttribute("type");
}
}
},

// Note: tab is allowed to be null here.
Expand Down Expand Up @@ -264,13 +236,6 @@ BrowserAction.prototype = {
},

shutdown() {
let widget = CustomizableUI.getWidget(this.id);
for (let instance of widget.instances) {
let window = instance.node.ownerDocument.defaultView;
let tabbrowser = window.gBrowser;
tabbrowser.tabContainer.removeEventListener("TabSelect", this);
}

CustomizableUI.destroyWidget(this.id);
},
};
Expand All @@ -288,37 +253,8 @@ extensions.on("shutdown", (type, extension) => {
browserActionMap.get(extension).shutdown();
browserActionMap.delete(extension);
}
imageRendererMap.delete(extension);
});

function convertImageDataToPNG(extension, imageData)
{
let webNav = imageRendererMap.get(extension);
if (!webNav) {
webNav = Services.appShell.createWindowlessBrowser(false);
let principal = Services.scriptSecurityManager.createCodebasePrincipal(extension.baseURI,
{addonId: extension.id});
let interfaceRequestor = webNav.QueryInterface(Ci.nsIInterfaceRequestor);
let docShell = interfaceRequestor.getInterface(Ci.nsIDocShell);

GlobalManager.injectInDocShell(docShell, extension, null);

docShell.createAboutBlankContentViewer(principal);
}

let document = webNav.document;
let canvas = document.createElement("canvas");
canvas.width = imageData.width;
canvas.height = imageData.height;
canvas.getContext("2d").putImageData(imageData, 0, 0);

let url = canvas.toDataURL("image/png");

canvas.remove();

return url;
}

extensions.registerAPI((extension, context) => {
return {
browserAction: {
Expand Down Expand Up @@ -347,11 +283,10 @@ extensions.registerAPI((extension, context) => {
setIcon: function(details, callback) {
let tab = details.tabId ? TabManager.getTab(details.tabId) : null;
if (details.imageData) {
let url = convertImageDataToPNG(extension, details.imageData);
browserActionOf(extension).setProperty(tab, "icon", url);
} else {
browserActionOf(extension).setProperty(tab, "icon", details.path);
// FIXME: Support the imageData attribute.
return;
}
browserActionOf(extension).setProperty(tab, "icon", details.path);
},

setBadgeText: function(details) {
Expand Down
35 changes: 7 additions & 28 deletions browser/components/extensions/ext-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,11 @@ var pageDataMap = new WeakMap();
// in some tab-specific details and keep data around about the
// ExtensionPage.
extensions.on("page-load", (type, page, params, sender, delegate) => {
if (params.type == "tab" || params.type == "popup") {
if (params.type == "tab") {
let browser = params.docShell.chromeEventHandler;

let parentWindow = browser.ownerDocument.defaultView;
page.windowId = WindowManager.getId(parentWindow);

let tab = null;
if (params.type == "tab") {
tab = parentWindow.gBrowser.getTabForBrowser(browser);
sender.tabId = TabManager.getId(tab);
page.tabId = TabManager.getId(tab);
}
let tab = parentWindow.gBrowser.getTabForBrowser(browser);
sender.tabId = TabManager.getId(tab);

pageDataMap.set(page, {tab, parentWindow});
}
Expand All @@ -70,9 +63,7 @@ extensions.on("page-shutdown", (type, page) => {
let {tab, parentWindow} = pageDataMap.get(page);
pageDataMap.delete(page);

if (tab) {
parentWindow.gBrowser.removeTab(tab);
}
parentWindow.gBrowser.removeTab(tab);
}
});

Expand All @@ -86,15 +77,6 @@ extensions.on("fill-browser-data", (type, browser, data, result) => {
data.tabId = tabId;
});

global.currentWindow = function(context)
{
let pageData = pageDataMap.get(context);
if (pageData) {
return pageData.parentWindow;
}
return WindowManager.topWindow;
}

// TODO: activeTab permission

extensions.registerAPI((extension, context) => {
Expand Down Expand Up @@ -275,7 +257,7 @@ extensions.registerAPI((extension, context) => {
}
}

let window = "windowId" in createProperties ?
let window = createProperties.windowId ?
WindowManager.getWindow(createProperties.windowId) :
WindowManager.topWindow;
if (!window.gBrowser) {
Expand Down Expand Up @@ -400,7 +382,7 @@ extensions.registerAPI((extension, context) => {

if ("windowId" in queryInfo) {
if (queryInfo.windowId == WindowManager.WINDOW_ID_CURRENT) {
if (currentWindow(context) != window) {
if (context.contentWindow != window) {
return false;
}
} else {
Expand All @@ -411,7 +393,7 @@ extensions.registerAPI((extension, context) => {
}

if ("currentWindow" in queryInfo) {
let eq = window == currentWindow(context);
let eq = window == context.contentWindow;
if (queryInfo.currentWindow != eq) {
return false;
}
Expand All @@ -424,9 +406,6 @@ extensions.registerAPI((extension, context) => {
let e = Services.wm.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
let window = e.getNext();
if (window.document.readyState != "complete") {
continue;
}
let tabs = TabManager.getTabs(extension, window);
for (let tab of tabs) {
if (matches(window, tab)) {
Expand Down
10 changes: 2 additions & 8 deletions browser/components/extensions/ext-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ extensions.registerAPI((extension, context) => {
},

getCurrent: function(getInfo, callback) {
if (!callback) {
callback = getInfo;
getInfo = {};
}
let window = currentWindow(context);
let window = context.contentWindow;
runSafe(context, callback, WindowManager.convert(extension, window, getInfo));
},

Expand All @@ -69,9 +65,7 @@ extensions.registerAPI((extension, context) => {
let windows = [];
while (e.hasMoreElements()) {
let window = e.getNext();
if (window.document.readyState == "complete") {
windows.push(WindowManager.convert(extension, window, getInfo));
}
windows.push(WindowManager.convert(extension, window, getInfo));
}
runSafe(context, callback, windows);
},
Expand Down
7 changes: 1 addition & 6 deletions browser/components/extensions/test/browser/browser.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
[DEFAULT]
skip-if = os == 'android' || buildapp == 'b2g' || os == 'mac'
support-files =
head.js

[browser_ext_simple.js]
[browser_ext_currentWindow.js]
[browser_extensions_simple.js]
[browser_ext_browserAction_simple.js]
[browser_ext_browserAction_icon.js]
[browser_ext_getViews.js]
[browser_ext_tabs_executeScript.js]
[browser_ext_tabs_query.js]
[browser_ext_tabs_update.js]
Expand Down
Loading

0 comments on commit 5b1ea92

Please sign in to comment.