Bug 638292: InstallTrigger is undefined in new tabs opened from links. r=robstrong
--- a/toolkit/mozapps/extensions/content/extensions-content.js
+++ b/toolkit/mozapps/extensions/content/extensions-content.js
@@ -230,25 +230,16 @@ function InstallTriggerManager() {
self.callbacks = null;
}, false);
}
InstallTriggerManager.prototype = {
handleEvent: function handleEvent(aEvent) {
var window = aEvent.target.defaultView;
- // Need to make sure we are called on what we care about -
- // content windows. DOMWindowCreated is called on *all* HTMLDocuments,
- // some of which belong to chrome windows or other special content.
- //
- var uri = window.document.documentURIObject;
- if (uri.scheme === "chrome" || uri.spec.split(":")[0] == "about") {
- return;
- }
-
window.wrappedJSObject.__defineGetter__("InstallTrigger", function() {
// We do this in a getter, so that we create these objects
// only on demand (this is a potential concern, since
// otherwise we might add one per iframe, and keep them
// alive for as long as the tab is alive).
delete window.wrappedJSObject.InstallTrigger;
var installTrigger = createInstallTrigger(window.wrappedJSObject);
--- a/toolkit/mozapps/extensions/test/xpinstall/Makefile.in
+++ b/toolkit/mozapps/extensions/test/xpinstall/Makefile.in
@@ -91,16 +91,17 @@ include $(topsrcdir)/config/rules.mk
browser_httphash2.js \
browser_httphash3.js \
browser_httphash4.js \
browser_httphash5.js \
browser_httphash6.js \
browser_badargs.js \
browser_badargs2.js \
browser_bug611242.js \
+ browser_bug638292.js \
unsigned.xpi \
signed.xpi \
signed2.xpi \
signed-no-o.xpi \
signed-no-cn.xpi \
signed-untrusted.xpi \
signed-tampered.xpi \
theme.xpi \
@@ -114,13 +115,14 @@ include $(topsrcdir)/config/rules.mk
installtrigger_frame.html \
startsoftwareupdate.html \
installchrome.html \
triggerredirect.html \
authRedirect.sjs \
cookieRedirect.sjs \
hashRedirect.sjs \
bug540558.html \
+ bug638292.html \
redirect.sjs \
$(NULL)
libs:: $(_BROWSER_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_bug638292.js
@@ -0,0 +1,53 @@
+// ----------------------------------------------------------------------------
+// Test whether an InstallTrigger.enabled is working
+function test() {
+ waitForExplicitFinish();
+
+ gBrowser.selectedTab = gBrowser.addTab();
+ gBrowser.selectedBrowser.addEventListener("load", function() {
+ gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+ waitForFocus(page_loaded, gBrowser.contentWindow);
+ }, true);
+ gBrowser.loadURI(TESTROOT + "bug638292.html");
+}
+
+function check_load(aCallback) {
+ gBrowser.addEventListener("load", function(aEvent) {
+ gBrowser.removeEventListener("load", arguments.callee, true);
+
+ // Let the load handler complete
+ executeSoon(function() {
+ var doc = gBrowser.browsers[2].contentDocument;
+ is(doc.getElementById("enabled").textContent, "true", "installTrigger should have been enabled");
+
+ // Focus the old tab
+ gBrowser.selectedTab = gBrowser.tabs[1];
+ waitForFocus(function() {
+ // Close the new tab
+ gBrowser.removeTab(gBrowser.tabs[2]);
+ aCallback();
+ }, gBrowser.contentWindow);
+ });
+ }, true);
+}
+
+function page_loaded() {
+ var doc = gBrowser.contentDocument;
+ info("Clicking link 1");
+ EventUtils.synthesizeMouseAtCenter(doc.getElementById("link1"), { }, gBrowser.contentWindow);
+
+ check_load(function() {
+ info("Clicking link 2");
+ EventUtils.synthesizeMouseAtCenter(doc.getElementById("link2"), { }, gBrowser.contentWindow);
+
+ check_load(function() {
+ info("Clicking link 3");
+ EventUtils.synthesizeMouseAtCenter(doc.getElementById("link3"), { button: 1 }, gBrowser.contentWindow);
+
+ check_load(function() {
+ gBrowser.removeCurrentTab();
+ finish();
+ });
+ });
+ });
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpinstall/bug638292.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+
+<!-- This page tests InstallTrigger is defined in a new window -->
+
+<head>
+<title>InstallTrigger tests</title>
+</head>
+<body>
+<p>InstallTrigger tests</p>
+<p><a id="link1" target="_blank" href="enabled.html">Open window with target</a></p>
+<p><a id="link2" onclick="window.open(this.href); return false" href="enabled.html">Open window with JS</a></p>
+<p><a id="link3" href="enabled.html">Open window with middle-click</a></p>
+</body>
+</html>