gecko/mobile/android/components/BrowserCLH.js
Doug Turner ab4eb501fc Bug 703098 - Removing unneeded file.exist checks. Stats are terrible. r=mfinkle
--HG--
extra : rebase_source : 550711c66d74b1cfa73829d085502c7c7e48da29
2011-11-17 13:03:57 -08:00

85 lines
2.4 KiB
JavaScript

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
function dump(a) {
Cc["@mozilla.org/consoleservice;1"]
.getService(Ci.nsIConsoleService)
.logStringMessage(a);
}
function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
let argString = null;
if (aArgs && !(aArgs instanceof Ci.nsISupportsArray)) {
argString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
argString.data = aArgs;
}
return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argString || aArgs);
}
function resolveURIInternal(aCmdLine, aArgument) {
let uri = aCmdLine.resolveURI(aArgument);
if (uri)
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;
}
function BrowserCLH() {}
BrowserCLH.prototype = {
handle: function fs_handle(aCmdLine) {
let urlParam = "about:home";
try {
urlParam = aCmdLine.handleFlagWithParam("remote", false);
} catch (e) {
// Optional so not a real error
}
dump("fs_handle: " + urlParam);
try {
let uri = resolveURIInternal(aCmdLine, urlParam);
if (!uri)
return;
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
if (browserWin) {
browserWin.browserDOMWindow.openURI(uri,
null,
Ci.nsIBrowserDOMWindow.OPEN_CURRENTWINDOW,
Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
} else {
browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", urlParam);
}
aCmdLine.preventDefault = true;
} catch (x) {
Cc["@mozilla.org/consoleservice;1"]
.getService(Ci.nsIConsoleService)
.logStringMessage("fs_handle exception!: " + x);
}
},
// QI
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
// XPCOMUtils factory
classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}")
};
var components = [ BrowserCLH ];
const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);