2012-05-21 11:12:37 +00: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 15:34:27 +00:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-07-13 14:36:09 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2010-06-30 21:29:22 +00:00
|
|
|
|
2010-12-16 07:00:33 +00:00
|
|
|
|
2011-10-11 00:40:17 +00:00
|
|
|
function dump(a) {
|
2012-01-06 18:10:16 +00:00
|
|
|
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
|
2011-07-12 17:25:35 +00:00
|
|
|
}
|
2011-01-03 21:08:54 +00:00
|
|
|
|
2011-10-15 02:58:04 +00:00
|
|
|
function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
|
2012-01-09 19:09:53 +00:00
|
|
|
let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
|
|
|
|
let urlString = null;
|
2012-04-14 02:45:25 +00:00
|
|
|
let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
2012-01-20 14:36:08 +00: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 19:09:53 +00:00
|
|
|
|
|
|
|
if ("url" in aArgs) {
|
|
|
|
urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
|
|
urlString.data = aArgs.url;
|
2011-10-15 02:58:04 +00:00
|
|
|
}
|
2012-01-20 14:36:08 +00:00
|
|
|
widthInt.data = "width" in aArgs ? aArgs.width : 1;
|
|
|
|
heightInt.data = "height" in aArgs ? aArgs.height : 1;
|
2012-04-14 02:45:25 +00:00
|
|
|
pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false;
|
2011-10-15 02:58:04 +00:00
|
|
|
|
2012-01-09 19:09:53 +00:00
|
|
|
argsArray.AppendElement(urlString, false);
|
2012-01-20 14:36:08 +00:00
|
|
|
argsArray.AppendElement(widthInt, false);
|
|
|
|
argsArray.AppendElement(heightInt, false);
|
2012-04-14 02:45:25 +00:00
|
|
|
argsArray.AppendElement(pinnedBool, false);
|
2012-01-09 19:09:53 +00:00
|
|
|
return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray);
|
2011-10-15 02:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-10 20:46:31 +00:00
|
|
|
function resolveURIInternal(aCmdLine, aArgument) {
|
|
|
|
let uri = aCmdLine.resolveURI(aArgument);
|
2011-11-17 21:03:57 +00:00
|
|
|
if (uri)
|
2011-11-10 20:46:31 +00: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 20:27:03 +00:00
|
|
|
function BrowserCLH() {}
|
2009-12-01 15:34:27 +00:00
|
|
|
|
|
|
|
BrowserCLH.prototype = {
|
2011-10-11 00:40:17 +00:00
|
|
|
handle: function fs_handle(aCmdLine) {
|
2012-04-14 02:45:25 +00:00
|
|
|
let openURL = "about:home";
|
|
|
|
let pinned = false;
|
|
|
|
|
2012-01-20 14:36:08 +00:00
|
|
|
let width = 1;
|
|
|
|
let height = 1;
|
2012-04-14 02:45:25 +00:00
|
|
|
|
2012-01-09 19:09:53 +00:00
|
|
|
try {
|
2012-04-14 02:45:25 +00:00
|
|
|
openURL = aCmdLine.handleFlagWithParam("url", false);
|
2012-01-09 19:09:53 +00:00
|
|
|
} catch (e) { /* Optional */ }
|
2012-04-14 02:45:25 +00:00
|
|
|
try {
|
|
|
|
pinned = aCmdLine.handleFlag("webapp", false);
|
|
|
|
} catch (e) { /* Optional */ }
|
|
|
|
|
2012-01-20 14:36:08 +00:00
|
|
|
try {
|
|
|
|
width = aCmdLine.handleFlagWithParam("width", false);
|
|
|
|
} catch (e) { /* Optional */ }
|
|
|
|
try {
|
|
|
|
height = aCmdLine.handleFlagWithParam("height", false);
|
|
|
|
} catch (e) { /* Optional */ }
|
2011-11-10 20:46:31 +00:00
|
|
|
|
2011-10-15 20:27:03 +00:00
|
|
|
try {
|
2012-04-14 02:45:25 +00:00
|
|
|
let uri = resolveURIInternal(aCmdLine, openURL);
|
2011-10-15 20:27:03 +00:00
|
|
|
if (!uri)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
if (browserWin) {
|
2013-01-10 18:18:58 +00:00
|
|
|
if (!pinned) {
|
|
|
|
browserWin.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
|
|
|
|
}
|
2011-10-15 20:27:03 +00:00
|
|
|
} else {
|
2012-01-09 19:09:53 +00:00
|
|
|
let args = {
|
2012-04-14 02:45:25 +00:00
|
|
|
url: openURL,
|
|
|
|
pinned: pinned,
|
2012-01-20 14:36:08 +00:00
|
|
|
width: width,
|
|
|
|
height: height
|
2012-01-09 19:09:53 +00:00
|
|
|
};
|
2012-10-13 15:18:22 +00: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-11 03:44:37 +00:00
|
|
|
}
|
2011-10-15 20:27:03 +00:00
|
|
|
|
|
|
|
aCmdLine.preventDefault = true;
|
|
|
|
} catch (x) {
|
2012-01-06 18:10:16 +00:00
|
|
|
dump("BrowserCLH.handle: " + x);
|
2011-10-15 20:27:03 +00:00
|
|
|
}
|
2009-12-01 15:34:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// QI
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
|
|
|
|
|
|
|
|
// XPCOMUtils factory
|
2011-10-15 20:27:03 +00:00
|
|
|
classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}")
|
2009-12-01 15:34:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var components = [ BrowserCLH ];
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|