2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
|
|
|
|
2009-12-01 07:34:27 -08:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-07-13 07:36:09 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2010-06-30 14:29:22 -07:00
|
|
|
|
2010-12-15 23:00:33 -08:00
|
|
|
|
2011-10-10 17:40:17 -07:00
|
|
|
function dump(a) {
|
2012-01-06 10:10:16 -08:00
|
|
|
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
|
2011-07-12 10:25:35 -07:00
|
|
|
}
|
2011-01-03 13:08:54 -08:00
|
|
|
|
2011-10-14 19:58:04 -07:00
|
|
|
function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
|
2012-01-09 11:09:53 -08:00
|
|
|
let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
|
|
|
|
let urlString = null;
|
2012-04-13 19:45:25 -07:00
|
|
|
let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
2013-08-26 16:41:13 -07:00
|
|
|
let guestBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
2012-01-20 06:36:08 -08:00
|
|
|
let widthInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
|
|
|
|
let heightInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
|
2012-01-09 11:09:53 -08:00
|
|
|
|
|
|
|
if ("url" in aArgs) {
|
|
|
|
urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
|
|
urlString.data = aArgs.url;
|
2011-10-14 19:58:04 -07:00
|
|
|
}
|
2012-01-20 06:36:08 -08:00
|
|
|
widthInt.data = "width" in aArgs ? aArgs.width : 1;
|
|
|
|
heightInt.data = "height" in aArgs ? aArgs.height : 1;
|
2012-04-13 19:45:25 -07:00
|
|
|
pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false;
|
2013-08-26 16:41:13 -07:00
|
|
|
guestBool.data = "guest" in aArgs ? aArgs["guest"] : false;
|
2011-10-14 19:58:04 -07:00
|
|
|
|
2012-01-09 11:09:53 -08:00
|
|
|
argsArray.AppendElement(urlString, false);
|
2012-01-20 06:36:08 -08:00
|
|
|
argsArray.AppendElement(widthInt, false);
|
|
|
|
argsArray.AppendElement(heightInt, false);
|
2012-04-13 19:45:25 -07:00
|
|
|
argsArray.AppendElement(pinnedBool, false);
|
2013-08-26 16:41:13 -07:00
|
|
|
argsArray.AppendElement(guestBool, false);
|
2012-01-09 11:09:53 -08:00
|
|
|
return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray);
|
2011-10-14 19:58:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-10 12:46:31 -08:00
|
|
|
function resolveURIInternal(aCmdLine, aArgument) {
|
|
|
|
let uri = aCmdLine.resolveURI(aArgument);
|
2011-11-17 13:03:57 -08:00
|
|
|
if (uri)
|
2011-11-10 12:46:31 -08:00
|
|
|
return uri;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
|
|
|
|
uri = urifixup.createFixupURI(aArgument, 0);
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2011-10-15 13:27:03 -07:00
|
|
|
function BrowserCLH() {}
|
2009-12-01 07:34:27 -08:00
|
|
|
|
|
|
|
BrowserCLH.prototype = {
|
2011-10-10 17:40:17 -07:00
|
|
|
handle: function fs_handle(aCmdLine) {
|
2012-04-13 19:45:25 -07:00
|
|
|
let openURL = "about:home";
|
|
|
|
let pinned = false;
|
2013-08-26 16:41:13 -07:00
|
|
|
let guest = false;
|
2012-04-13 19:45:25 -07:00
|
|
|
|
2012-01-20 06:36:08 -08:00
|
|
|
let width = 1;
|
|
|
|
let height = 1;
|
2012-04-13 19:45:25 -07:00
|
|
|
|
2012-01-09 11:09:53 -08:00
|
|
|
try {
|
2012-04-13 19:45:25 -07:00
|
|
|
openURL = aCmdLine.handleFlagWithParam("url", false);
|
2012-01-09 11:09:53 -08:00
|
|
|
} catch (e) { /* Optional */ }
|
2012-04-13 19:45:25 -07:00
|
|
|
try {
|
|
|
|
pinned = aCmdLine.handleFlag("webapp", false);
|
|
|
|
} catch (e) { /* Optional */ }
|
2013-08-26 16:41:13 -07:00
|
|
|
try {
|
|
|
|
guest = aCmdLine.handleFlag("guest", false);
|
|
|
|
} catch (e) { /* Optional */ }
|
2012-04-13 19:45:25 -07:00
|
|
|
|
2012-01-20 06:36:08 -08:00
|
|
|
try {
|
|
|
|
width = aCmdLine.handleFlagWithParam("width", false);
|
|
|
|
} catch (e) { /* Optional */ }
|
|
|
|
try {
|
|
|
|
height = aCmdLine.handleFlagWithParam("height", false);
|
|
|
|
} catch (e) { /* Optional */ }
|
2011-11-10 12:46:31 -08:00
|
|
|
|
2011-10-15 13:27:03 -07:00
|
|
|
try {
|
2012-04-13 19:45:25 -07:00
|
|
|
let uri = resolveURIInternal(aCmdLine, openURL);
|
2011-10-15 13:27:03 -07:00
|
|
|
if (!uri)
|
|
|
|
return;
|
|
|
|
|
2014-02-12 08:27:25 -08:00
|
|
|
// Let's get a head start on opening the network connection to the URI we are about to load
|
|
|
|
Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null);
|
|
|
|
|
2011-10-15 13:27:03 -07:00
|
|
|
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
if (browserWin) {
|
2013-01-10 10:18:58 -08:00
|
|
|
if (!pinned) {
|
|
|
|
browserWin.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
|
|
|
|
}
|
2011-10-15 13:27:03 -07:00
|
|
|
} else {
|
2012-01-09 11:09:53 -08:00
|
|
|
let args = {
|
2012-04-13 19:45:25 -07:00
|
|
|
url: openURL,
|
|
|
|
pinned: pinned,
|
2012-01-20 06:36:08 -08:00
|
|
|
width: width,
|
2013-08-26 16:41:13 -07:00
|
|
|
height: height,
|
|
|
|
guest: guest
|
2012-01-09 11:09:53 -08:00
|
|
|
};
|
2012-10-13 08:18:22 -07:00
|
|
|
|
|
|
|
// Make sure webapps do not have: locationbar, personalbar, menubar, statusbar, and toolbar
|
|
|
|
let flags = "chrome,dialog=no";
|
|
|
|
if (!pinned)
|
|
|
|
flags += ",all";
|
|
|
|
|
|
|
|
browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", flags, args);
|
2010-12-10 19:44:37 -08:00
|
|
|
}
|
2011-10-15 13:27:03 -07:00
|
|
|
|
|
|
|
aCmdLine.preventDefault = true;
|
|
|
|
} catch (x) {
|
2012-01-06 10:10:16 -08:00
|
|
|
dump("BrowserCLH.handle: " + x);
|
2011-10-15 13:27:03 -07:00
|
|
|
}
|
2009-12-01 07:34:27 -08:00
|
|
|
},
|
|
|
|
|
2014-07-22 21:41:53 -07:00
|
|
|
/**
|
|
|
|
* Register resource://android as the APK root.
|
|
|
|
*
|
|
|
|
* Consumers can access Android assets using resource://android/assets/FILENAME.
|
|
|
|
*/
|
|
|
|
setResourceSubstitutions: function () {
|
|
|
|
let registry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci["nsIChromeRegistry"]);
|
|
|
|
// Like jar:jar:file:///data/app/org.mozilla.fennec-2.apk!/assets/omni.ja!/chrome/chrome/content/aboutHome.xhtml
|
|
|
|
let url = registry.convertChromeURL(Services.io.newURI("chrome://browser/content/aboutHome.xhtml", null, null)).spec;
|
|
|
|
// Like jar:file:///data/app/org.mozilla.fennec-2.apk!/
|
|
|
|
url = url.substring(4, url.indexOf("!/") + 2);
|
|
|
|
|
|
|
|
let protocolHandler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
|
|
|
|
protocolHandler.setSubstitution("android", Services.io.newURI(url, null, null));
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function (subject, topic, data) {
|
|
|
|
switch (topic) {
|
|
|
|
case "app-startup":
|
|
|
|
this.setResourceSubstitutions();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-01 07:34:27 -08:00
|
|
|
// QI
|
2014-07-22 21:41:53 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler,
|
|
|
|
Ci.nsIObserver]),
|
2009-12-01 07:34:27 -08:00
|
|
|
|
|
|
|
// XPCOMUtils factory
|
2011-10-15 13:27:03 -07:00
|
|
|
classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}")
|
2009-12-01 07:34:27 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
var components = [ BrowserCLH ];
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|