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-05-14 14:48:04 -07:00
|
|
|
let restoreModeInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
|
2012-04-13 19:45:25 -07:00
|
|
|
let pinnedBool = 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-05-14 14:48:04 -07:00
|
|
|
restoreModeInt.data = "restoreMode" in aArgs ? aArgs.restoreMode : 0;
|
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;
|
2011-10-14 19:58:04 -07:00
|
|
|
|
2012-01-09 11:09:53 -08:00
|
|
|
argsArray.AppendElement(urlString, false);
|
2012-05-14 14:48:04 -07:00
|
|
|
argsArray.AppendElement(restoreModeInt, 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);
|
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;
|
|
|
|
|
2012-05-14 14:48:04 -07:00
|
|
|
let restoreMode = 0;
|
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 */ }
|
|
|
|
|
2011-10-23 21:11:29 -07:00
|
|
|
try {
|
2012-05-14 14:48:04 -07:00
|
|
|
restoreMode = aCmdLine.handleFlagWithParam("restoremode", false);
|
2012-01-06 10:10:16 -08:00
|
|
|
} catch (e) { /* Optional */ }
|
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;
|
|
|
|
|
|
|
|
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
if (browserWin) {
|
2012-04-13 19:45:25 -07:00
|
|
|
let whereFlags = pinned ? Ci.nsIBrowserDOMWindow.OPEN_SWITCHTAB : Ci.nsIBrowserDOMWindow.OPEN_NEWTAB;
|
|
|
|
browserWin.browserDOMWindow.openURI(uri, null, whereFlags, 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,
|
2012-05-14 14:48:04 -07:00
|
|
|
restoreMode: restoreMode,
|
2012-04-13 19:45:25 -07:00
|
|
|
pinned: pinned,
|
2012-01-20 06:36:08 -08:00
|
|
|
width: width,
|
|
|
|
height: height
|
2012-01-09 11:09:53 -08:00
|
|
|
};
|
|
|
|
browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", 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
|
|
|
},
|
|
|
|
|
|
|
|
// QI
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
|
|
|
|
|
|
|
|
// 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 ];
|
2010-06-29 14:02:25 -07:00
|
|
|
const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|