1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const Cu = Components.utils;
9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
10 Cu.import("resource://gre/modules/Services.jsm");
14 Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
17 function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
18 let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
20 let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
21 let guestBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
22 let widthInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
23 let heightInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
26 urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
27 urlString.data = aArgs.url;
29 widthInt.data = "width" in aArgs ? aArgs.width : 1;
30 heightInt.data = "height" in aArgs ? aArgs.height : 1;
31 pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false;
32 guestBool.data = "guest" in aArgs ? aArgs["guest"] : false;
34 argsArray.AppendElement(urlString, false);
35 argsArray.AppendElement(widthInt, false);
36 argsArray.AppendElement(heightInt, false);
37 argsArray.AppendElement(pinnedBool, false);
38 argsArray.AppendElement(guestBool, false);
39 return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray);
43 function resolveURIInternal(aCmdLine, aArgument) {
44 let uri = aCmdLine.resolveURI(aArgument);
49 let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
50 uri = urifixup.createFixupURI(aArgument, 0);
58 function BrowserCLH() {}
60 BrowserCLH.prototype = {
61 handle: function fs_handle(aCmdLine) {
62 let openURL = "about:home";
70 openURL = aCmdLine.handleFlagWithParam("url", false);
71 } catch (e) { /* Optional */ }
73 pinned = aCmdLine.handleFlag("webapp", false);
74 } catch (e) { /* Optional */ }
76 guest = aCmdLine.handleFlag("guest", false);
77 } catch (e) { /* Optional */ }
80 width = aCmdLine.handleFlagWithParam("width", false);
81 } catch (e) { /* Optional */ }
83 height = aCmdLine.handleFlagWithParam("height", false);
84 } catch (e) { /* Optional */ }
87 let uri = resolveURIInternal(aCmdLine, openURL);
91 let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
94 browserWin.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
105 // Make sure webapps do not have: locationbar, personalbar, menubar, statusbar, and toolbar
106 let flags = "chrome,dialog=no";
110 browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", flags, args);
113 aCmdLine.preventDefault = true;
115 dump("BrowserCLH.handle: " + x);
120 QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
122 // XPCOMUtils factory
123 classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}")
126 var components = [ BrowserCLH ];
127 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);