Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const Cc = Components.classes; |
michael@0 | 6 | const Ci = Components.interfaces; |
michael@0 | 7 | const Cu = Components.utils; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 10 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 11 | |
michael@0 | 12 | |
michael@0 | 13 | function dump(a) { |
michael@0 | 14 | Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) { |
michael@0 | 18 | let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray); |
michael@0 | 19 | let urlString = null; |
michael@0 | 20 | let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); |
michael@0 | 21 | let guestBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); |
michael@0 | 22 | let widthInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32); |
michael@0 | 23 | let heightInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32); |
michael@0 | 24 | |
michael@0 | 25 | if ("url" in aArgs) { |
michael@0 | 26 | urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); |
michael@0 | 27 | urlString.data = aArgs.url; |
michael@0 | 28 | } |
michael@0 | 29 | widthInt.data = "width" in aArgs ? aArgs.width : 1; |
michael@0 | 30 | heightInt.data = "height" in aArgs ? aArgs.height : 1; |
michael@0 | 31 | pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false; |
michael@0 | 32 | guestBool.data = "guest" in aArgs ? aArgs["guest"] : false; |
michael@0 | 33 | |
michael@0 | 34 | argsArray.AppendElement(urlString, false); |
michael@0 | 35 | argsArray.AppendElement(widthInt, false); |
michael@0 | 36 | argsArray.AppendElement(heightInt, false); |
michael@0 | 37 | argsArray.AppendElement(pinnedBool, false); |
michael@0 | 38 | argsArray.AppendElement(guestBool, false); |
michael@0 | 39 | return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | function resolveURIInternal(aCmdLine, aArgument) { |
michael@0 | 44 | let uri = aCmdLine.resolveURI(aArgument); |
michael@0 | 45 | if (uri) |
michael@0 | 46 | return uri; |
michael@0 | 47 | |
michael@0 | 48 | try { |
michael@0 | 49 | let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup); |
michael@0 | 50 | uri = urifixup.createFixupURI(aArgument, 0); |
michael@0 | 51 | } catch (e) { |
michael@0 | 52 | Cu.reportError(e); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | return uri; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function BrowserCLH() {} |
michael@0 | 59 | |
michael@0 | 60 | BrowserCLH.prototype = { |
michael@0 | 61 | handle: function fs_handle(aCmdLine) { |
michael@0 | 62 | let openURL = "about:home"; |
michael@0 | 63 | let pinned = false; |
michael@0 | 64 | let guest = false; |
michael@0 | 65 | |
michael@0 | 66 | let width = 1; |
michael@0 | 67 | let height = 1; |
michael@0 | 68 | |
michael@0 | 69 | try { |
michael@0 | 70 | openURL = aCmdLine.handleFlagWithParam("url", false); |
michael@0 | 71 | } catch (e) { /* Optional */ } |
michael@0 | 72 | try { |
michael@0 | 73 | pinned = aCmdLine.handleFlag("webapp", false); |
michael@0 | 74 | } catch (e) { /* Optional */ } |
michael@0 | 75 | try { |
michael@0 | 76 | guest = aCmdLine.handleFlag("guest", false); |
michael@0 | 77 | } catch (e) { /* Optional */ } |
michael@0 | 78 | |
michael@0 | 79 | try { |
michael@0 | 80 | width = aCmdLine.handleFlagWithParam("width", false); |
michael@0 | 81 | } catch (e) { /* Optional */ } |
michael@0 | 82 | try { |
michael@0 | 83 | height = aCmdLine.handleFlagWithParam("height", false); |
michael@0 | 84 | } catch (e) { /* Optional */ } |
michael@0 | 85 | |
michael@0 | 86 | try { |
michael@0 | 87 | let uri = resolveURIInternal(aCmdLine, openURL); |
michael@0 | 88 | if (!uri) |
michael@0 | 89 | return; |
michael@0 | 90 | |
michael@0 | 91 | // Let's get a head start on opening the network connection to the URI we are about to load |
michael@0 | 92 | Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null); |
michael@0 | 93 | |
michael@0 | 94 | let browserWin = Services.wm.getMostRecentWindow("navigator:browser"); |
michael@0 | 95 | if (browserWin) { |
michael@0 | 96 | if (!pinned) { |
michael@0 | 97 | browserWin.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL); |
michael@0 | 98 | } |
michael@0 | 99 | } else { |
michael@0 | 100 | let args = { |
michael@0 | 101 | url: openURL, |
michael@0 | 102 | pinned: pinned, |
michael@0 | 103 | width: width, |
michael@0 | 104 | height: height, |
michael@0 | 105 | guest: guest |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | // Make sure webapps do not have: locationbar, personalbar, menubar, statusbar, and toolbar |
michael@0 | 109 | let flags = "chrome,dialog=no"; |
michael@0 | 110 | if (!pinned) |
michael@0 | 111 | flags += ",all"; |
michael@0 | 112 | |
michael@0 | 113 | browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", flags, args); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | aCmdLine.preventDefault = true; |
michael@0 | 117 | } catch (x) { |
michael@0 | 118 | dump("BrowserCLH.handle: " + x); |
michael@0 | 119 | } |
michael@0 | 120 | }, |
michael@0 | 121 | |
michael@0 | 122 | // QI |
michael@0 | 123 | QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]), |
michael@0 | 124 | |
michael@0 | 125 | // XPCOMUtils factory |
michael@0 | 126 | classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}") |
michael@0 | 127 | }; |
michael@0 | 128 | |
michael@0 | 129 | var components = [ BrowserCLH ]; |
michael@0 | 130 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components); |