38
38
const Cc = Components.classes;
39
39
const Ci = Components.interfaces;
40
const Cr = Components.results;
41
40
const Cu = Components.utils;
44
42
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
43
Cu.import("resource://gre/modules/Services.jsm");
45
function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
48
argString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
49
argString.data = aArgs;
52
return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argString);
55
function resolveURIInternal(aCmdLine, aArgument) {
56
let uri = aCmdLine.resolveURI(aArgument);
58
if (!(uri instanceof Ci.nsIFileURL))
62
if (uri.file.exists())
70
let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
71
uri = urifixup.createFixupURI(aArgument, 0);
81
* Determines whether a home page override is needed.
83
* "new profile" if this is the first run with a new profile.
84
* "new version" if this is the first run with a build with a different
85
* Gecko milestone (i.e. right after an upgrade).
88
function needHomepageOverride() {
89
let savedmstone = null;
91
savedmstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone");
94
if (savedmstone == "ignore")
97
#expand let ourmstone = "__MOZ_APP_VERSION__";
99
if (ourmstone != savedmstone) {
100
Services.prefs.setCharPref("browser.startup.homepage_override.mstone", ourmstone);
102
return (savedmstone ? "new version" : "new profile");
108
function getHomePage() {
109
let url = "about:home";
111
url = Services.prefs.getComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString).data;
46
118
function BrowserCLH() { }
50
122
// nsICommandLineHandler
52
handle: function fs_handle(cmdLine) {
124
handle: function fs_handle(aCmdLine) {
53
125
// Instantiate the search service so the search engine cache is created now
54
126
// instead when the application is running. The install process will register
55
127
// this component by using the -silent command line flag, thereby creating
56
128
// the cache during install, not runtime.
57
129
// NOTE: This code assumes this CLH is run before the nsDefaultCLH, which
58
130
// consumes the "-silent" flag.
59
if (cmdLine.findFlag("silent", false) > -1) {
60
let searchService = Cc["@mozilla.org/browser/search-service;1"].
61
getService(Ci.nsIBrowserSearchService);
131
if (aCmdLine.findFlag("silent", false) > -1) {
132
let searchService = Services.search;
62
133
let autoComplete = Cc["@mozilla.org/autocomplete/search;1?name=history"].
63
134
getService(Ci.nsIAutoCompleteSearch);
138
// Handle chrome windows loaded via commandline
139
let chromeParam = aCmdLine.handleFlagWithParam("chrome", false);
142
// Only load URIs which do not inherit chrome privs
143
let features = "chrome,dialog=no,all";
144
let uri = resolveURIInternal(aCmdLine, chromeParam);
145
let netutil = Cc["@mozilla.org/network/util;1"].getService(Ci.nsINetUtil);
146
if (!netutil.URIChainHasFlags(uri, Ci.nsIHttpProtocolHandler.URI_INHERITS_SECURITY_CONTEXT)) {
147
openWindow(null, uri.spec, "_blank", features, null);
149
// Stop the normal commandline processing from continuing
150
aCmdLine.preventDefault = true;
159
// Keep an array of possible URL arguments
162
// Check for the "url" flag
163
let uriFlag = aCmdLine.handleFlagWithParam("url", false);
165
let uri = resolveURIInternal(aCmdLine, uriFlag);
170
for (let i = 0; i < aCmdLine.length; i++) {
171
let arg = aCmdLine.getArgument(i);
172
if (!arg || arg[0] == '-')
175
let uri = resolveURIInternal(aCmdLine, arg);
180
// Open the main browser window, if we don't already have one
69
Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
183
win = Services.wm.getMostRecentWindow("navigator:browser");
185
// Default to the saved homepage
186
let defaultURL = getHomePage();
188
// Override the default if we have a new profile
189
if (needHomepageOverride() == "new profile")
190
defaultURL = "about:firstrun";
192
// Override the default if we have a URL passed on command line
193
if (uris.length > 0) {
194
defaultURL = uris[0].spec;
195
uris = uris.slice(1);
71
win = windowMediator.getMostRecentWindow("navigator:browser");
198
win = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", defaultURL);
76
cmdLine.preventDefault = true;
203
// Stop the normal commandline processing from continuing. We just opened the main browser window
204
aCmdLine.preventDefault = true;
79
// Assumption: All CLH arguments we've received have been sent remotely,
80
// or we wouldn't already have a window. Therefore: open 'em all!
81
for (let i = 0; i < cmdLine.length; i++) {
82
let arg = cmdLine.getArgument(i);
83
if (!arg || arg[0] == '-')
86
let uri = cmdLine.resolveURI(arg);
88
win.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, null);
207
// Assumption: All remaining command line arguments have been sent remotely (browser is already running)
208
// Action: Open any URLs we find into an existing browser window
210
// First, get a browserDOMWindow object
211
while (!win.browserDOMWindow)
212
Services.tm.currentThread.processNextEvent(true);
214
// Open any URIs into new tabs
215
for (let i = 0; i < uris.length; i++)
216
win.browserDOMWindow.openURI(uris[i], null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
217
Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
93
221
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
95
223
// XPCOMUtils factory
96
classDescription: "Command Line Handler",
97
contractID: "@mozilla.org/mobile/browser-clh;1",
98
224
classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}"),
99
_xpcom_categories: [{ category: "command-line-handler", entry: "m-browser" }],
102
227
var components = [ BrowserCLH ];
104
function NSGetModule(compMgr, fileSpec) {
105
return XPCOMUtils.generateModule(components);
228
const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);