michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: michael@0: function dump(a) { michael@0: Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a); michael@0: } michael@0: michael@0: function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) { michael@0: let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray); michael@0: let urlString = null; michael@0: let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); michael@0: let guestBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); michael@0: let widthInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32); michael@0: let heightInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32); michael@0: michael@0: if ("url" in aArgs) { michael@0: urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); michael@0: urlString.data = aArgs.url; michael@0: } michael@0: widthInt.data = "width" in aArgs ? aArgs.width : 1; michael@0: heightInt.data = "height" in aArgs ? aArgs.height : 1; michael@0: pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false; michael@0: guestBool.data = "guest" in aArgs ? aArgs["guest"] : false; michael@0: michael@0: argsArray.AppendElement(urlString, false); michael@0: argsArray.AppendElement(widthInt, false); michael@0: argsArray.AppendElement(heightInt, false); michael@0: argsArray.AppendElement(pinnedBool, false); michael@0: argsArray.AppendElement(guestBool, false); michael@0: return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray); michael@0: } michael@0: michael@0: michael@0: function resolveURIInternal(aCmdLine, aArgument) { michael@0: let uri = aCmdLine.resolveURI(aArgument); michael@0: if (uri) michael@0: return uri; michael@0: michael@0: try { michael@0: let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup); michael@0: uri = urifixup.createFixupURI(aArgument, 0); michael@0: } catch (e) { michael@0: Cu.reportError(e); michael@0: } michael@0: michael@0: return uri; michael@0: } michael@0: michael@0: function BrowserCLH() {} michael@0: michael@0: BrowserCLH.prototype = { michael@0: handle: function fs_handle(aCmdLine) { michael@0: let openURL = "about:home"; michael@0: let pinned = false; michael@0: let guest = false; michael@0: michael@0: let width = 1; michael@0: let height = 1; michael@0: michael@0: try { michael@0: openURL = aCmdLine.handleFlagWithParam("url", false); michael@0: } catch (e) { /* Optional */ } michael@0: try { michael@0: pinned = aCmdLine.handleFlag("webapp", false); michael@0: } catch (e) { /* Optional */ } michael@0: try { michael@0: guest = aCmdLine.handleFlag("guest", false); michael@0: } catch (e) { /* Optional */ } michael@0: michael@0: try { michael@0: width = aCmdLine.handleFlagWithParam("width", false); michael@0: } catch (e) { /* Optional */ } michael@0: try { michael@0: height = aCmdLine.handleFlagWithParam("height", false); michael@0: } catch (e) { /* Optional */ } michael@0: michael@0: try { michael@0: let uri = resolveURIInternal(aCmdLine, openURL); michael@0: if (!uri) michael@0: return; michael@0: michael@0: // Let's get a head start on opening the network connection to the URI we are about to load michael@0: Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null); michael@0: michael@0: let browserWin = Services.wm.getMostRecentWindow("navigator:browser"); michael@0: if (browserWin) { michael@0: if (!pinned) { michael@0: browserWin.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL); michael@0: } michael@0: } else { michael@0: let args = { michael@0: url: openURL, michael@0: pinned: pinned, michael@0: width: width, michael@0: height: height, michael@0: guest: guest michael@0: }; michael@0: michael@0: // Make sure webapps do not have: locationbar, personalbar, menubar, statusbar, and toolbar michael@0: let flags = "chrome,dialog=no"; michael@0: if (!pinned) michael@0: flags += ",all"; michael@0: michael@0: browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", flags, args); michael@0: } michael@0: michael@0: aCmdLine.preventDefault = true; michael@0: } catch (x) { michael@0: dump("BrowserCLH.handle: " + x); michael@0: } michael@0: }, michael@0: michael@0: // QI michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]), michael@0: michael@0: // XPCOMUtils factory michael@0: classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}") michael@0: }; michael@0: michael@0: var components = [ BrowserCLH ]; michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);