Bug 732631 - Selecting to a open a new window within an app, then exiting the app does not shut down the application [r=myk]
authorEdward Lee <edilee@mozilla.com>
Thu, 26 Apr 2012 16:55:25 -0700
changeset 92570 c8f67f81e8dfd3fa60b88aae712f69b6af88ed8e
parent 92569 bb2d256dcfacc935c8ab47d4e96f5aec595e5c35
child 92571 0064e5064b4f6856b9b7b1286f10ad50f958f467
push idunknown
push userunknown
push dateunknown
reviewersmyk
bugs732631, 746217
milestone15.0a1
Bug 732631 - Selecting to a open a new window within an app, then exiting the app does not shut down the application [r=myk] Switch browser type to content-primary so the frame loader triggers the right behavior for adding a content shell. Also fixes Bug 746217 - Cannot open windows even from the same domain
webapprt/CommandLineHandler.js
webapprt/content/webapp.js
webapprt/content/webapp.xul
--- a/webapprt/CommandLineHandler.js
+++ b/webapprt/CommandLineHandler.js
@@ -20,20 +20,21 @@ try {
 function CommandLineHandler() {}
 
 CommandLineHandler.prototype = {
   classID: Components.ID("{6d69c782-40a3-469b-8bfd-3ee366105a4a}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
 
   handle: function handle(cmdLine) {
+    // Open the window with arguments to identify it as the main window
     Services.ww.openWindow(null,
                            "chrome://webapprt/content/webapp.xul",
                            "_blank",
                            "chrome,dialog=no,all,resizable",
-                           null);
+                           []);
   },
 
   helpInfo : "",
 };
 
 let components = [CommandLineHandler];
 let NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
--- a/webapprt/content/webapp.js
+++ b/webapprt/content/webapp.js
@@ -7,27 +7,29 @@ const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://webapprt/modules/WebappRT.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 function onLoad() {
   window.removeEventListener("load", onLoad, false);
 
-  let installRecord = WebappRT.config.app;
+  // Set the title of the window to the name of the webapp
   let manifest = WebappRT.config.app.manifest;
-
-  // Set the title of the window to the name of the webapp.
   document.documentElement.setAttribute("title", manifest.name);
 
-  // Load the webapp's launch path.
-  let url = Services.io.newURI(installRecord.origin, null, null);
-  if (manifest.launch_path)
-    url = Services.io.newURI(manifest.launch_path, null, url);
-  document.getElementById("content").setAttribute("src", url.spec);
+  // Only load the webapp on the initially launched main window
+  if ("arguments" in window) {
+    // Load the webapp's launch URL
+    let installRecord = WebappRT.config.app;
+    let url = Services.io.newURI(installRecord.origin, null, null);
+    if (manifest.launch_path)
+      url = Services.io.newURI(manifest.launch_path, null, url);
+    document.getElementById("content").setAttribute("src", url.spec);
+  }
 }
 window.addEventListener("load", onLoad, false);
 
 #ifdef XP_MACOSX
 // On Mac, we dynamically create the label for the Quit menuitem, using
 // a string property to inject the name of the webapp into it.
 window.addEventListener("load", function onLoadUpdateMenuItems() {
   window.removeEventListener("load", onLoadUpdateMenuItems, false);
--- a/webapprt/content/webapp.xul
+++ b/webapprt/content/webapp.xul
@@ -146,11 +146,11 @@
                   label="&selectAllCmd.label;"
                   key="key_selectAll"
                   accesskey="&selectAllCmd.accesskey;"
                   command="cmd_selectAll"/>
       </menupopup>
     </menu>
   </menubar>
 
-  <browser type="content" id="content" flex="1"/>
+  <browser type="content-primary" id="content" flex="1"/>
 
 </window>