From 8fffba6f74486890411ab44ef5c900ca87e72b04 Mon Sep 17 00:00:00 2001 From: Felipe Gomes Date: Sat, 14 Jul 2012 01:09:32 -0700 Subject: [PATCH] Bug 771294. Use window id for webapp installation. r=gavin Test by Myk Melez --- browser/modules/webappsUI.jsm | 52 +++++++++--------- dom/tests/mochitest/webapps/Makefile.in | 1 + dom/tests/mochitest/webapps/apps/Makefile.in | 1 + .../mochitest/webapps/apps/bug_765063.xul | 2 +- .../mochitest/webapps/apps/bug_771294.xul | 11 ++++ .../mochitest/webapps/test_bug_765063.xul | 19 ++++--- .../mochitest/webapps/test_bug_771294.xul | 53 +++++++++++++++++++ toolkit/content/PopupNotifications.jsm | 3 ++ 8 files changed, 105 insertions(+), 37 deletions(-) create mode 100644 dom/tests/mochitest/webapps/apps/bug_771294.xul create mode 100644 dom/tests/mochitest/webapps/test_bug_771294.xul diff --git a/browser/modules/webappsUI.jsm b/browser/modules/webappsUI.jsm index b0308692a66..e24ef83dbe7 100644 --- a/browser/modules/webappsUI.jsm +++ b/browser/modules/webappsUI.jsm @@ -29,10 +29,12 @@ let webappsUI = { switch(aTopic) { case "webapps-ask-install": - let [chromeWin, browser] = this._getBrowserForId(data.oid); - if (chromeWin) - this.doInstall(data, browser, chromeWin); + let win = this._getWindowForId(data.oid); + if (win && win.location.href == data.from) { + this.doInstall(data, win); + } break; + case "webapps-launch": DOMApplicationRegistry.getManifestFor(data.origin, (function(aManifest) { if (!aManifest) @@ -83,27 +85,14 @@ let webappsUI = { } }, - _getBrowserForId: function(aId) { - let someWindow = Services.wm.getMostRecentWindow(null); + doInstall: function(aData, aWindow) { + let browser = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShell) + .chromeEventHandler; - if (someWindow) { - let windowUtils = someWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowUtils); - let content = windowUtils.getOuterWindowWithId(aId); - if (content) { - let browser = content.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShell).chromeEventHandler; - let win = browser.ownerDocument.defaultView; - return [win, browser]; - } - } - - return [null, null]; - }, - - doInstall: function(aData, aBrowser, aWindow) { - let bundle = aWindow.gNavigatorBundle; + let chromeWin = browser.ownerDocument.defaultView; + let bundle = chromeWin.gNavigatorBundle; let mainAction = { label: bundle.getString("webapps.install"), @@ -117,14 +106,14 @@ let webappsUI = { } DOMApplicationRegistry.confirmInstall(aData, false, localDir); - installationSuccessNotification(app, aWindow); + installationSuccessNotification(app, chromeWin); } else { DOMApplicationRegistry.denyInstall(aData); } } }; - let requestingURI = aWindow.makeURI(aData.from); + let requestingURI = chromeWin.makeURI(aData.from); let manifest = new DOMApplicationManifest(aData.app.manifest, aData.app.origin); let host; @@ -135,11 +124,18 @@ let webappsUI = { } let message = bundle.getFormattedString("webapps.requestInstall", - [manifest.name, host], 2); + [manifest.name, host]); - aWindow.PopupNotifications.show(aBrowser, "webapps-install", message, - "webapps-notification-icon", mainAction); + chromeWin.PopupNotifications.show(browser, "webapps-install", message, + "webapps-notification-icon", mainAction); + }, + _getWindowForId: function(aId) { + let someWindow = Services.wm.getMostRecentWindow(null); + return someWindow && + someWindow.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils) + .getOuterWindowWithId(aId); } } diff --git a/dom/tests/mochitest/webapps/Makefile.in b/dom/tests/mochitest/webapps/Makefile.in index d2e7e887580..d5679ad6163 100644 --- a/dom/tests/mochitest/webapps/Makefile.in +++ b/dom/tests/mochitest/webapps/Makefile.in @@ -16,6 +16,7 @@ DIRS = \ MOCHITEST_CHROME_FILES = \ test_bug_765063.xul \ + test_bug_771294.xul \ test_install_app.xul \ test_list_api.xul \ test_install_errors.xul \ diff --git a/dom/tests/mochitest/webapps/apps/Makefile.in b/dom/tests/mochitest/webapps/apps/Makefile.in index 53f4500dba4..e297ba2d478 100644 --- a/dom/tests/mochitest/webapps/apps/Makefile.in +++ b/dom/tests/mochitest/webapps/apps/Makefile.in @@ -12,6 +12,7 @@ include $(DEPTH)/config/autoconf.mk MOCHITEST_CHROME_FILES = \ bug_765063.xul \ + bug_771294.xul \ include.html \ wild_crazy.webapp \ wild_crazy.webapp^headers^ \ diff --git a/dom/tests/mochitest/webapps/apps/bug_765063.xul b/dom/tests/mochitest/webapps/apps/bug_765063.xul index 8f8d1c01f66..462f06870cf 100644 --- a/dom/tests/mochitest/webapps/apps/bug_765063.xul +++ b/dom/tests/mochitest/webapps/apps/bug_765063.xul @@ -6,6 +6,6 @@ diff --git a/dom/tests/mochitest/webapps/apps/bug_771294.xul b/dom/tests/mochitest/webapps/apps/bug_771294.xul new file mode 100644 index 00000000000..66d1d6f7a28 --- /dev/null +++ b/dom/tests/mochitest/webapps/apps/bug_771294.xul @@ -0,0 +1,11 @@ + + + + + + + diff --git a/dom/tests/mochitest/webapps/test_bug_765063.xul b/dom/tests/mochitest/webapps/test_bug_765063.xul index 5ac9a6d6647..21f503e68f3 100644 --- a/dom/tests/mochitest/webapps/test_bug_765063.xul +++ b/dom/tests/mochitest/webapps/test_bug_765063.xul @@ -18,19 +18,22 @@ + + + + + + + + +