1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/components/BrowserCLH.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const Cc = Components.classes; 1.9 +const Ci = Components.interfaces; 1.10 +const Cu = Components.utils; 1.11 + 1.12 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.13 +Cu.import("resource://gre/modules/Services.jsm"); 1.14 + 1.15 + 1.16 +function dump(a) { 1.17 + Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a); 1.18 +} 1.19 + 1.20 +function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) { 1.21 + let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray); 1.22 + let urlString = null; 1.23 + let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); 1.24 + let guestBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); 1.25 + let widthInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32); 1.26 + let heightInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32); 1.27 + 1.28 + if ("url" in aArgs) { 1.29 + urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); 1.30 + urlString.data = aArgs.url; 1.31 + } 1.32 + widthInt.data = "width" in aArgs ? aArgs.width : 1; 1.33 + heightInt.data = "height" in aArgs ? aArgs.height : 1; 1.34 + pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false; 1.35 + guestBool.data = "guest" in aArgs ? aArgs["guest"] : false; 1.36 + 1.37 + argsArray.AppendElement(urlString, false); 1.38 + argsArray.AppendElement(widthInt, false); 1.39 + argsArray.AppendElement(heightInt, false); 1.40 + argsArray.AppendElement(pinnedBool, false); 1.41 + argsArray.AppendElement(guestBool, false); 1.42 + return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray); 1.43 +} 1.44 + 1.45 + 1.46 +function resolveURIInternal(aCmdLine, aArgument) { 1.47 + let uri = aCmdLine.resolveURI(aArgument); 1.48 + if (uri) 1.49 + return uri; 1.50 + 1.51 + try { 1.52 + let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup); 1.53 + uri = urifixup.createFixupURI(aArgument, 0); 1.54 + } catch (e) { 1.55 + Cu.reportError(e); 1.56 + } 1.57 + 1.58 + return uri; 1.59 +} 1.60 + 1.61 +function BrowserCLH() {} 1.62 + 1.63 +BrowserCLH.prototype = { 1.64 + handle: function fs_handle(aCmdLine) { 1.65 + let openURL = "about:home"; 1.66 + let pinned = false; 1.67 + let guest = false; 1.68 + 1.69 + let width = 1; 1.70 + let height = 1; 1.71 + 1.72 + try { 1.73 + openURL = aCmdLine.handleFlagWithParam("url", false); 1.74 + } catch (e) { /* Optional */ } 1.75 + try { 1.76 + pinned = aCmdLine.handleFlag("webapp", false); 1.77 + } catch (e) { /* Optional */ } 1.78 + try { 1.79 + guest = aCmdLine.handleFlag("guest", false); 1.80 + } catch (e) { /* Optional */ } 1.81 + 1.82 + try { 1.83 + width = aCmdLine.handleFlagWithParam("width", false); 1.84 + } catch (e) { /* Optional */ } 1.85 + try { 1.86 + height = aCmdLine.handleFlagWithParam("height", false); 1.87 + } catch (e) { /* Optional */ } 1.88 + 1.89 + try { 1.90 + let uri = resolveURIInternal(aCmdLine, openURL); 1.91 + if (!uri) 1.92 + return; 1.93 + 1.94 + // Let's get a head start on opening the network connection to the URI we are about to load 1.95 + Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null); 1.96 + 1.97 + let browserWin = Services.wm.getMostRecentWindow("navigator:browser"); 1.98 + if (browserWin) { 1.99 + if (!pinned) { 1.100 + browserWin.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL); 1.101 + } 1.102 + } else { 1.103 + let args = { 1.104 + url: openURL, 1.105 + pinned: pinned, 1.106 + width: width, 1.107 + height: height, 1.108 + guest: guest 1.109 + }; 1.110 + 1.111 + // Make sure webapps do not have: locationbar, personalbar, menubar, statusbar, and toolbar 1.112 + let flags = "chrome,dialog=no"; 1.113 + if (!pinned) 1.114 + flags += ",all"; 1.115 + 1.116 + browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", flags, args); 1.117 + } 1.118 + 1.119 + aCmdLine.preventDefault = true; 1.120 + } catch (x) { 1.121 + dump("BrowserCLH.handle: " + x); 1.122 + } 1.123 + }, 1.124 + 1.125 + // QI 1.126 + QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]), 1.127 + 1.128 + // XPCOMUtils factory 1.129 + classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}") 1.130 +}; 1.131 + 1.132 +var components = [ BrowserCLH ]; 1.133 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);