Bug 1163904 - handle -url command line argument. r=fabrice
authorPaul Rouget <paul@mozilla.com>
Fri, 15 May 2015 06:36:23 +0200
changeset 244036 1d3b19645654ba6bddc7806d1276a0d4b759828e
parent 244035 44eea0b902ec5a6424655493dd7d0d083e761aa2
child 244037 9e20ce726196dd71e60309631074d66e14a3022a
push id59820
push usercbook@mozilla.com
push dateFri, 15 May 2015 15:41:47 +0000
treeherdermozilla-inbound@5943d32f3515 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1163904
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1163904 - handle -url command line argument. r=fabrice
b2g/chrome/content/shell.js
b2g/components/CommandLine.js
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -631,17 +631,35 @@ var shell = {
       Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
 
       SystemAppProxy.setIsReady();
       if ('pendingChromeEvents' in shell) {
         shell.pendingChromeEvents.forEach((shell.sendChromeEvent).bind(shell));
       }
       delete shell.pendingChromeEvents;
     });
-  }
+
+    shell.handleCmdLine();
+  },
+
+  handleCmdLine: function shell_handleCmdLine() {
+    let b2gcmds = Cc["@mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds"]
+                    .getService(Ci.nsISupports);
+    let args = b2gcmds.wrappedJSObject.cmdLine;
+    try {
+      // Returns null if -url is not present
+      let url = args.handleFlagWithParam("url", false);
+      if (url) {
+        this.sendChromeEvent({type: "mozbrowseropenwindow", url});
+        args.preventDefault = true;
+      }
+    } catch(e) {
+      // Throws if -url is present with no params
+    }
+  },
 };
 
 Services.obs.addObserver(function onFullscreenOriginChange(subject, topic, data) {
   shell.sendChromeEvent({ type: "fullscreenoriginchange",
                           fullscreenorigin: data });
 }, "fullscreen-origin-change", false);
 
 DOMApplicationRegistry.registryStarted.then(function () {
--- a/b2g/components/CommandLine.js
+++ b/b2g/components/CommandLine.js
@@ -10,16 +10,20 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 
 function CommandlineHandler() {
   this.wrappedJSObject = this;
 }
 
 CommandlineHandler.prototype = {
     handle: function(cmdLine) {
       this.cmdLine = cmdLine;
+      let win = Services.wm.getMostRecentWindow("navigator:browser");
+      if (win && win.shell) {
+        win.shell.handleCmdLine();
+      }
     },
 
     helpInfo: "",
     classID: Components.ID("{385993fe-8710-4621-9fb1-00a09d8bec37}"),
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandlineHandler]);