Bug 1043699 - Fix command line arguments handling on desktop. r=fabrice
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 28 Aug 2014 10:10:00 +0200
changeset 203039 4d991522bbe3
parent 203038 dc77ebda2445
child 203040 99934eed086c
push id27418
push userryanvm@gmail.com
push dateTue, 02 Sep 2014 18:33:17 +0000
treeherdermozilla-central@7753c52d5976 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1043699
milestone34.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 1043699 - Fix command line arguments handling on desktop. r=fabrice
b2g/chrome/content/desktop.js
b2g/chrome/content/runapp.js
b2g/chrome/content/screen.js
b2g/components/B2GComponents.manifest
b2g/components/CommandLine.js
b2g/components/moz.build
b2g/installer/package-manifest.in
--- a/b2g/chrome/content/desktop.js
+++ b/b2g/chrome/content/desktop.js
@@ -50,23 +50,27 @@ function setupButtons() {
 }
 
 function checkDebuggerPort() {
   // XXX: To be removed once bug 942756 lands.
   // We are hacking 'unix-domain-socket' pref by setting a tcp port (number).
   // DebuggerServer.openListener detects that it isn't a file path (string),
   // and starts listening on the tcp port given here as command line argument.
 
-  if (!window.arguments) {
+  // Get the command line arguments that were passed to the b2g client
+  let args;
+  try {
+    let service = Cc["@mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds"].getService(Ci.nsISupports);
+    args = service.wrappedJSObject.cmdLine;
+  } catch(e) {}
+
+  if (!args) {
     return;
   }
 
-  // Get the command line arguments that were passed to the b2g client
-  let args = window.arguments[0].QueryInterface(Ci.nsICommandLine);
-
   let dbgport;
   try {
     dbgport = args.handleFlagWithParam('start-debugger-server', false);
   } catch(e) {}
 
   if (dbgport) {
     dump('Opening debugger server on ' + dbgport + '\n');
     Services.prefs.setCharPref('devtools.debugger.unix-domain-socket', dbgport);
--- a/b2g/chrome/content/runapp.js
+++ b/b2g/chrome/content/runapp.js
@@ -1,21 +1,26 @@
 "use strict";
 
 // runapp.js:
 // Provide a --runapp APPNAME command-line option.
 
 let runAppObj;
 window.addEventListener('load', function() {
-  if (!window.arguments) {
+  // Get the command line arguments that were passed to the b2g client
+  let args;
+  try {
+    let service = Cc["@mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds"].getService(Ci.nsISupports);
+    args = service.wrappedJSObject.cmdLine;
+  } catch(e) {}
+
+  if (!args) {
     return;
   }
 
-  // Get the command line arguments that were passed to the b2g client
-  let args = window.arguments[0].QueryInterface(Ci.nsICommandLine);
   let appname;
 
   // - Check if the argument is present before doing any work.
   try {
     // Returns null if the argument was not specified.  Throws
     // NS_ERROR_INVALID_ARG if there is no parameter specified (because
     // it was the last argument or the next argument starts with '-').
     // However, someone could still explicitly pass an empty argument!
--- a/b2g/chrome/content/screen.js
+++ b/b2g/chrome/content/screen.js
@@ -57,18 +57,18 @@ window.addEventListener('ContentStart', 
     chacha: {
       name: 'HTC ChaCha', width:320, height:480, dpi:222
     },
   };
 
   // Get the command line arguments that were passed to the b2g client
   let args;
   try {
-    // On Firefox Mulet, we don't always have a command line argument
-    args = window.arguments[0].QueryInterface(Ci.nsICommandLine);
+    let service = Cc["@mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds"].getService(Ci.nsISupports);
+    args = service.wrappedJSObject.cmdLine;
   } catch(e) {}
 
   let screenarg = null;
 
   // Get the --screen argument from the command line
   try {
     if (args) {
       screenarg = args.handleFlagWithParam('screen', false);
--- a/b2g/components/B2GComponents.manifest
+++ b/b2g/components/B2GComponents.manifest
@@ -91,18 +91,22 @@ contract @mozilla.org/helperapplauncherd
 #ifndef MOZ_WIDGET_GONK
 component {c83c02c0-5d43-4e3e-987f-9173b313e880} SimulatorScreen.js
 contract @mozilla.org/simulator-screen;1 {c83c02c0-5d43-4e3e-987f-9173b313e880}
 category profile-after-change SimulatorScreen @mozilla.org/simulator-screen;1
 
 component {e30b0e13-2d12-4cb0-bc4c-4e617a1bf76e} OopCommandLine.js
 contract @mozilla.org/commandlinehandler/general-startup;1?type=b2goop {e30b0e13-2d12-4cb0-bc4c-4e617a1bf76e}
 category command-line-handler m-b2goop @mozilla.org/commandlinehandler/general-startup;1?type=b2goop
+
+component {385993fe-8710-4621-9fb1-00a09d8bec37} CommandLine.js
+contract @mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds {385993fe-8710-4621-9fb1-00a09d8bec37}
+category command-line-handler m-b2gcmds @mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds
 #endif
 
 # MobileIdentityUIGlue.js
 component {83dbe26a-81f3-4a75-9541-3d0b7ca496b5} MobileIdentityUIGlue.js
 contract @mozilla.org/services/mobileid-ui-glue;1 {83dbe26a-81f3-4a75-9541-3d0b7ca496b5}
 
 # B2GAppMigrator.js
 component {7211ece0-b458-4635-9afc-f8d7f376ee95} B2GAppMigrator.js
 contract @mozilla.org/b2g-app-migrator;1 {7211ece0-b458-4635-9afc-f8d7f376ee95}
-category profile-after-change B2GAppMigrator @mozilla.org/b2g-app-migrator;1
\ No newline at end of file
+category profile-after-change B2GAppMigrator @mozilla.org/b2g-app-migrator;1
new file mode 100644
--- /dev/null
+++ b/b2g/components/CommandLine.js
@@ -0,0 +1,25 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
+
+// Small helper to expose nsICommandLine object to chrome code
+
+function CommandlineHandler() {
+  this.wrappedJSObject = this;
+}
+
+CommandlineHandler.prototype = {
+    handle: function(cmdLine) {
+      this.cmdLine = cmdLine;
+    },
+
+    helpInfo: "",
+    classID: Components.ID("{385993fe-8710-4621-9fb1-00a09d8bec37}"),
+    QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandlineHandler]);
--- a/b2g/components/moz.build
+++ b/b2g/components/moz.build
@@ -25,16 +25,17 @@ EXTRA_COMPONENTS += [
     'SystemMessageGlue.js',
     'TelProtocolHandler.js',
     'WebappsUpdateTimer.js',
     'YoutubeProtocolHandler.js',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
     EXTRA_COMPONENTS += [
+      'CommandLine.js',
       'OopCommandLine.js',
       'SimulatorScreen.js'
     ]
 
 EXTRA_PP_COMPONENTS += [
     'B2GComponents.manifest',
     'DirectoryProvider.js',
     'RecoveryService.js',
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -446,16 +446,17 @@
 #ifndef MOZ_WIDGET_GONK
 @BINPATH@/components/extensions.manifest
 @BINPATH@/components/addonManager.js
 @BINPATH@/components/amContentHandler.js
 @BINPATH@/components/amInstallTrigger.js
 @BINPATH@/components/amWebInstallListener.js
 @BINPATH@/components/nsBlocklistService.js
 @BINPATH@/components/OopCommandLine.js
+@BINPATH@/components/CommandLine.js
 #endif
 
 #ifdef MOZ_UPDATER
 @BINPATH@/components/nsUpdateService.manifest
 @BINPATH@/components/nsUpdateService.js
 @BINPATH@/components/nsUpdateServiceStub.js
 #endif
 @BINPATH@/components/nsUpdateTimerManager.manifest