Bug 1135261 - return new window from window.open in desktop runtime; r=marco,smaug,junior,wesj

This commit is contained in:
Myk Melez 2015-08-13 19:00:02 -07:00
parent b87496e922
commit 3d8affa2f1
5 changed files with 50 additions and 36 deletions

View File

@ -170,7 +170,9 @@ function checkIsWidgetScript(testMozbrowserEvent) {
request.onerror = onError;
if (testMozbrowserEvent) {
content.window.open("about:blank"); /* test mozbrowseropenwindow */
var win = content.window.open("about:blank"); /* test mozbrowseropenwindow */
/*Close new window to avoid mochitest "unable to restore focus" failures.*/
win.close();
content.window.scrollTo(4000, 4000); /* test mozbrowser(async)scroll */
}
}

View File

@ -117,7 +117,7 @@ DispatchCustomDOMEvent(Element* aFrameElement, const nsAString& aEventName,
}
event->SetTrusted(true);
// Dispatch the event.
*aStatus = nsEventStatus_eConsumeNoDefault;
// We don't initialize aStatus here, as our callers have already done so.
nsresult rv =
EventDispatcher::DispatchDOMEvent(aFrameElement, nullptr,
static_cast<Event*>(event),
@ -177,7 +177,7 @@ BrowserElementParent::DispatchOpenWindowEvent(Element* aOpenerFrameElement,
return BrowserElementParent::OPEN_WINDOW_CANCELLED;
}
nsEventStatus status;
nsEventStatus status = nsEventStatus_eIgnore;
bool dispatchSucceeded =
DispatchCustomDOMEvent(aOpenerFrameElement,
NS_LITERAL_STRING("mozbrowseropenwindow"),

View File

@ -20,11 +20,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "gCrashReporter",
"nsICrashReporter");
#endif
function isSameOrigin(url) {
let origin = Services.io.newURI(url, null, null).prePath;
return (origin == WebappRT.config.app.origin);
}
let progressListener = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference]),
@ -51,15 +46,30 @@ let progressListener = {
}
}
let isSameOrigin = (location.prePath === WebappRT.config.app.origin);
// Set the title of the window to the name of the webapp, adding the origin
// of the page being loaded if it's from a different origin than the app
// (per security bug 741955, which specifies that other-origin pages loaded
// in runtime windows must be identified in chrome).
let title = WebappRT.localeManifest.name;
if (!isSameOrigin(location.spec)) {
if (!isSameOrigin) {
title = location.prePath + " - " + title;
}
document.documentElement.setAttribute("title", title);
#ifndef XP_WIN
#ifndef XP_MACOSX
if (isSameOrigin) {
// On non-Windows platforms, we open new windows in fullscreen mode
// if the opener window is in fullscreen mode, so we hide the menubar;
// but on Mac we don't need to hide the menubar.
if (document.mozFullScreenElement) {
document.getElementById("main-menubar").style.display = "none";
}
}
#endif
#endif
},
onStateChange: function onStateChange(aProgress, aRequest, aFlags, aStatus) {
@ -72,42 +82,38 @@ let progressListener = {
};
function onOpenWindow(event) {
let name = event.detail.name;
if (name == "_blank") {
if (event.detail.name === "_blank") {
let uri = Services.io.newURI(event.detail.url, null, null);
// Prevent the default handler so nsContentTreeOwner.ProvideWindow
// doesn't create the window itself.
event.preventDefault();
// Direct the URL to the browser.
Cc["@mozilla.org/uriloader/external-protocol-service;1"].
getService(Ci.nsIExternalProtocolService).
getProtocolHandlerInfo(uri.scheme).
launchWithURI(uri);
} else {
let win = window.openDialog("chrome://webapprt/content/webapp.xul",
name,
"chrome,dialog=no,resizable," + event.detail.features);
}
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
// Otherwise, don't do anything to make nsContentTreeOwner.ProvideWindow
// create the window itself and return it to the window.open caller.
}
#ifndef XP_WIN
#ifndef XP_MACOSX
if (isSameOrigin(event.detail.url)) {
// On non-Windows platforms, we open new windows in fullscreen mode
// if the opener window is in fullscreen mode, so we hide the menubar;
// but on Mac we don't need to hide the menubar.
if (document.mozFullScreenElement) {
win.document.getElementById("main-menubar").style.display = "none";
}
}
#endif
#endif
win.document.getElementById("content").docShell.setIsApp(WebappRT.appID);
win.document.getElementById("content").setAttribute("src", event.detail.url);
}, false);
function onDOMContentLoaded() {
window.removeEventListener("DOMContentLoaded", onDOMContentLoaded, false);
// The initial window's app ID is set by Startup.jsm before the app
// is loaded, so this code only handles subsequent windows that are opened
// by the app via window.open calls. We do this on DOMContentLoaded
// in order to ensure it gets set before the window's content is loaded.
if (gAppBrowser.docShell.appId === Ci.nsIScriptSecurityManager.NO_APP_ID) {
// Set the principal to the correct app ID. Since this is a subsequent
// window, we know that WebappRT.configPromise has been resolved, so we
// don't have to yield to it before accessing WebappRT.appID.
gAppBrowser.docShell.setIsApp(WebappRT.appID);
}
}
window.addEventListener("DOMContentLoaded", onDOMContentLoaded, false);
function onLoad() {
window.removeEventListener("load", onLoad, false);

View File

@ -27,7 +27,12 @@ function test() {
winAppBrowser.addEventListener("load", function onLoadBrowser() {
winAppBrowser.removeEventListener("load", onLoadBrowser, true);
is(winAppBrowser.getAttribute("src"),
let contentWindow = Cu.waiveXrays(gAppBrowser.contentDocument.defaultView);
is(contentWindow.openedWindow.location.href,
"http://test/webapprtChrome/webapprt/test/chrome/sample.html",
"window.open returns window with correct URL");
is(winAppBrowser.documentURI.spec,
"http://test/webapprtChrome/webapprt/test/chrome/sample.html",
"New window browser has correct src");

View File

@ -4,8 +4,9 @@
<title>Window Open Test App</title>
<meta charset="utf-8">
<script>
var openedWindow;
function onLoad() {
window.open("sample.html");
openedWindow = window.open("sample.html");
}
</script>
</head>