Bug 771294. Use window id for webapp installation. r=gavin

Test by Myk Melez
This commit is contained in:
Felipe Gomes 2012-07-14 01:09:32 -07:00
parent 8e975b670f
commit 8fffba6f74
8 changed files with 105 additions and 37 deletions

View File

@ -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);
}
}

View File

@ -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 \

View File

@ -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^ \

View File

@ -6,6 +6,6 @@
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
navigator.mozApps.install("http://www.example.com:80/chrome/dom/tests/mochitest/webapps/apps/super_crazy.webapp", null);
document.location = "about:blank";
history.pushState({}, "", "modified-url");
</script>
</window>

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
navigator.mozApps.install("http://www.example.com:80/chrome/dom/tests/mochitest/webapps/apps/super_crazy.webapp", null);
window.location = "about:blank";
</script>
</window>

View File

@ -18,19 +18,22 @@
<script>
SimpleTest.waitForExplicitFinish();
// Observe app installation and confirm that the install origin didn't change.
var observer = {
observe: function observe(subject, topic, data) {
Services.obs.removeObserver(observer, "webapps-sync-install");
ok(JSON.parse(data).installOrigin == "http://www.example.com",
"the install origin didn't change");
var mmListener = {
receiveMessage: function(aMessage) {
ppmm.removeMessageListener("Webapps:Install", mmListener);
var msg = aMessage.json;
is(msg.from.indexOf("modified-url"), -1, "the install origin didn't change");
tearDown();
SimpleTest.finish();
}
};
Components.utils.import("resource://gre/modules/Services.jsm");
Services.obs.addObserver(observer, "webapps-sync-install", false);
var ppmm = Components.classes["@mozilla.org/parentprocessmessagemanager;1"]
.getService(Components.interfaces.nsIFrameMessageManager);
ppmm.addMessageListener("Webapps:Install", mmListener);
</script>
<!-- Load a page that initiates an app installation and then immediately

View File

@ -0,0 +1,53 @@
<?xml version="1.0"?>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Mozilla Bug 771294">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript" src="apphelper.js"/>
<script type="application/javascript" src="jshelper.js"/>
<script>
SimpleTest.waitForExplicitFinish();
Components.utils.import('resource://gre/modules/Services.jsm');
var blocked = true;
Services.obs.addObserver(
function observeShowing() {
Services.obs.removeObserver(observeShowing, "PopupNotifications-showing");
blocked = false;
},
"PopupNotifications-showing",
false
);
Services.obs.addObserver(
function observeInstalling() {
Services.obs.removeObserver(observeInstalling, "webapps-ask-install");
// Spin the event loop before running the test to give the registry time
// to process the install request and (hopefully not) show the doorhanger.
setTimeout(function verify() {
ok(blocked, "Install panel was blocked after immediate redirect");
tearDown();
SimpleTest.finish();
}, 0);
},
"webapps-ask-install",
false
);
</script>
<!-- Load a page that initiates an app installation and then immediately
- redirects to a page at a different origin. We can't do this directly
- inside this test page, because that would cause the test to hang. -->
<iframe src="http://www.example.com:80/chrome/dom/tests/mochitest/webapps/apps/bug_771294.xul"/>
</window>

View File

@ -241,6 +241,9 @@ PopupNotifications.prototype = {
let notifications = this._getNotificationsForBrowser(browser);
notifications.push(notification);
// Notify observers that we're showing the popup (useful for testing)
this._notify("showing");
let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
if (browser == this.tabbrowser.selectedBrowser && fm.activeWindow == this.window) {
// show panel now