1 # ***** BEGIN LICENSE BLOCK
*****
2 # Version
: MPL
1.1/GPL 2.0/LGPL
2.1
4 # The contents
of this file are subject to the Mozilla Public License Version
5 # 1.1 (the
"License"); you may not
use this file except
in compliance
with
6 # the License
. You may obtain a copy
of the License at
7 # http
://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an
"AS IS" basis
,
10 # WITHOUT WARRANTY OF ANY KIND
, either express or implied
. See the License
11 # for the specific language governing rights and limitations under the
14 # The Original Code is the Mozilla Firefox browser
.
16 # The Initial Developer
of the Original Code is
17 # Benjamin Smedberg
<benjamin
@smedbergs
.us
>
19 # Portions created by the Initial Developer are
Copyright (C
) 2004
20 # the Initial Developer
. All Rights Reserved
.
24 # Alternatively
, the contents
of this file may be used under the terms
of
25 # either the GNU General Public License Version
2 or
later (the
"GPL"), or
26 # the GNU Lesser General Public License Version
2.1 or
later (the
"LGPL"),
27 # in which
case the provisions
of the GPL or the LGPL are applicable instead
28 # of those above
. If you wish to allow
use of your version
of this file only
29 # under the terms
of either the GPL or the LGPL
, and not to allow others to
30 # use your version
of this file under the terms
of the MPL
, indicate your
31 # decision by deleting the provisions above and replace them
with the notice
32 # and other provisions required by the GPL or the LGPL
. If you
do not
delete
33 # the provisions above
, a recipient may
use your version
of this file under
34 # the terms
of any one
of the MPL
, the GPL or the LGPL
.
36 # ***** END LICENSE BLOCK
*****
38 const nsISupports
= Components
.interfaces
.nsISupports
;
40 const nsIBrowserDOMWindow
= Components
.interfaces
.nsIBrowserDOMWindow
;
41 const nsIBrowserHandler
= Components
.interfaces
.nsIBrowserHandler
;
42 const nsIBrowserHistory
= Components
.interfaces
.nsIBrowserHistory
;
43 const nsIChannel
= Components
.interfaces
.nsIChannel
;
44 const nsICommandLine
= Components
.interfaces
.nsICommandLine
;
45 const nsICommandLineHandler
= Components
.interfaces
.nsICommandLineHandler
;
46 const nsIContentHandler
= Components
.interfaces
.nsIContentHandler
;
47 const nsIDocShellTreeItem
= Components
.interfaces
.nsIDocShellTreeItem
;
48 const nsIDOMChromeWindow
= Components
.interfaces
.nsIDOMChromeWindow
;
49 const nsIDOMWindow
= Components
.interfaces
.nsIDOMWindow
;
50 const nsIFactory
= Components
.interfaces
.nsIFactory
;
51 const nsIFileURL
= Components
.interfaces
.nsIFileURL
;
52 const nsIHttpProtocolHandler
= Components
.interfaces
.nsIHttpProtocolHandler
;
53 const nsIInterfaceRequestor
= Components
.interfaces
.nsIInterfaceRequestor
;
54 const nsINetUtil
= Components
.interfaces
.nsINetUtil
;
55 const nsIPrefBranch
= Components
.interfaces
.nsIPrefBranch
;
56 const nsIPrefLocalizedString
= Components
.interfaces
.nsIPrefLocalizedString
;
57 const nsISupportsString
= Components
.interfaces
.nsISupportsString
;
58 const nsIURIFixup
= Components
.interfaces
.nsIURIFixup
;
59 const nsIWebNavigation
= Components
.interfaces
.nsIWebNavigation
;
60 const nsIWindowMediator
= Components
.interfaces
.nsIWindowMediator
;
61 const nsIWindowWatcher
= Components
.interfaces
.nsIWindowWatcher
;
62 const nsICategoryManager
= Components
.interfaces
.nsICategoryManager
;
63 const nsIWebNavigationInfo
= Components
.interfaces
.nsIWebNavigationInfo
;
64 const nsIBrowserSearchService
= Components
.interfaces
.nsIBrowserSearchService
;
65 const nsICommandLineValidator
= Components
.interfaces
.nsICommandLineValidator
;
67 const NS_BINDING_ABORTED
= 0x804b0002;
68 const NS_ERROR_WONT_HANDLE_CONTENT
= 0x805d0001;
69 const NS_ERROR_ABORT
= Components
.results
.NS_ERROR_ABORT
;
71 const URI_INHERITS_SECURITY_CONTEXT
= nsIHttpProtocolHandler
72 .URI_INHERITS_SECURITY_CONTEXT
;
74 function shouldLoadURI(aURI
) {
75 if (aURI
&& !aURI
.schemeIs("chrome"))
78 dump("*** Preventing external load of chrome: URI into browser window\n");
79 dump(" Use -chrome <uri> instead\n");
83 function resolveURIInternal(aCmdLine
, aArgument
) {
84 var uri
= aCmdLine
.resolveURI(aArgument
);
86 if (!(uri
instanceof nsIFileURL
)) {
91 if (uri
.file
.exists())
95 Components
.utils
.reportError(e
);
98 // We have interpreted the argument as a relative file URI, but the file
99 // doesn't exist. Try URI fixup heuristics: see bug 290782.
102 var urifixup
= Components
.classes
["@mozilla.org/docshell/urifixup;1"]
103 .getService(nsIURIFixup
);
105 uri
= urifixup
.createFixupURI(aArgument
, 0);
108 Components
.utils
.reportError(e
);
114 const OVERRIDE_NONE
= 0;
115 const OVERRIDE_NEW_PROFILE
= 1;
116 const OVERRIDE_NEW_MSTONE
= 2;
118 * Determines whether a home page override is needed.
120 * OVERRIDE_NEW_PROFILE if this is the first run with a new profile.
121 * OVERRIDE_NEW_MSTONE if this is the first run with a build with a different
122 * Gecko milestone (i.e. right after an upgrade).
123 * OVERRIDE_NONE otherwise.
125 function needHomepageOverride(prefb
) {
126 var savedmstone
= null;
128 savedmstone
= prefb
.getCharPref("browser.startup.homepage_override.mstone");
131 if (savedmstone
== "ignore")
132 return OVERRIDE_NONE
;
134 var mstone
= Components
.classes
["@mozilla.org/network/protocol;1?name=http"]
135 .getService(nsIHttpProtocolHandler
).misc
;
137 if (mstone
!= savedmstone
) {
138 prefb
.setCharPref("browser.startup.homepage_override.mstone", mstone
);
139 return (savedmstone
? OVERRIDE_NEW_MSTONE
: OVERRIDE_NEW_PROFILE
);
142 return OVERRIDE_NONE
;
145 // Copies a pref override file into the user's profile pref-override folder,
146 // and then tells the pref service to reload it's default prefs.
147 function copyPrefOverride() {
149 var fileLocator
= Components
.classes
["@mozilla.org/file/directory_service;1"]
150 .getService(Components
.interfaces
.nsIProperties
);
151 const NS_APP_EXISTING_PREF_OVERRIDE
= "ExistingPrefOverride";
152 var prefOverride
= fileLocator
.get(NS_APP_EXISTING_PREF_OVERRIDE
,
153 Components
.interfaces
.nsIFile
);
154 if (!prefOverride
.exists())
155 return; // nothing to do
157 const NS_APP_PREFS_OVERRIDE_DIR
= "PrefDOverride";
158 var prefOverridesDir
= fileLocator
.get(NS_APP_PREFS_OVERRIDE_DIR
,
159 Components
.interfaces
.nsIFile
);
161 // Check for any existing pref overrides, and remove them if present
162 var existingPrefOverridesFile
= prefOverridesDir
.clone();
163 existingPrefOverridesFile
.append(prefOverride
.leafName
);
164 if (existingPrefOverridesFile
.exists())
165 existingPrefOverridesFile
.remove(false);
167 prefOverride
.copyTo(prefOverridesDir
, null);
169 // Now that we've installed the new-profile pref override file,
170 // re-read the default prefs.
171 var prefSvcObs
= Components
.classes
["@mozilla.org/preferences-service;1"]
172 .getService(Components
.interfaces
.nsIObserver
);
173 prefSvcObs
.observe(null, "reload-default-prefs", null);
175 Components
.utils
.reportError(ex
);
179 // Flag used to indicate that the arguments to openWindow can be passed directly.
180 const NO_EXTERNAL_URIS
= 1;
182 function openWindow(parent
, url
, target
, features
, args
, noExternalArgs
) {
183 var wwatch
= Components
.classes
["@mozilla.org/embedcomp/window-watcher;1"]
184 .getService(nsIWindowWatcher
);
186 if (noExternalArgs
== NO_EXTERNAL_URIS
) {
187 // Just pass in the defaultArgs directly
190 argstring
= Components
.classes
["@mozilla.org/supports-string;1"]
191 .createInstance(nsISupportsString
);
192 argstring
.data
= args
;
195 return wwatch
.openWindow(parent
, url
, target
, features
, argstring
);
198 // Pass an array to avoid the browser "|"-splitting behavior.
199 var argArray
= Components
.classes
["@mozilla.org/supports-array;1"]
200 .createInstance(Components
.interfaces
.nsISupportsArray
);
202 // add args to the arguments array
203 var stringArgs
= null;
204 if (args
instanceof Array
) // array
206 else if (args
) // string
210 // put the URIs into argArray
211 var uriArray
= Components
.classes
["@mozilla.org/supports-array;1"]
212 .createInstance(Components
.interfaces
.nsISupportsArray
);
213 stringArgs
.forEach(function (uri
) {
214 var sstring
= Components
.classes
["@mozilla.org/supports-string;1"]
215 .createInstance(nsISupportsString
);
217 uriArray
.AppendElement(sstring
);
219 argArray
.AppendElement(uriArray
);
221 argArray
.AppendElement(null);
224 // Pass these as null to ensure that we always trigger the "single URL"
225 // behavior in browser.js's BrowserStartup (which handles the window
227 argArray
.AppendElement(null); // charset
228 argArray
.AppendElement(null); // referer
229 argArray
.AppendElement(null); // postData
230 argArray
.AppendElement(null); // allowThirdPartyFixup
232 return wwatch
.openWindow(parent
, url
, target
, features
, argArray
);
235 function openPreferences() {
236 var features
= "chrome,titlebar,toolbar,centerscreen,dialog=no";
237 var url
= "chrome://browser/content/preferences/preferences.xul";
239 var win
= getMostRecentWindow("Browser:Preferences");
243 openWindow(null, url
, "_blank", features
);
247 function getMostRecentWindow(aType
) {
248 var wm
= Components
.classes
["@mozilla.org/appshell/window-mediator;1"]
249 .getService(nsIWindowMediator
);
250 return wm
.getMostRecentWindow(aType
);
255 #define BROKEN_WM_Z_ORDER
259 #define BROKEN_WM_Z_ORDER
262 // this returns the most recent non-popup browser window
263 function getMostRecentBrowserWindow() {
264 var wm
= Components
.classes
["@mozilla.org/appshell/window-mediator;1"]
265 .getService(Components
.interfaces
.nsIWindowMediator
);
267 #ifdef BROKEN_WM_Z_ORDER
268 var win
= wm
.getMostRecentWindow("navigator:browser", true);
270 // if we're lucky, this isn't a popup, and we can just return this
271 if (win
&& win
.document
.documentElement
.getAttribute("chromehidden")) {
272 var windowList
= wm
.getEnumerator("navigator:browser", true);
273 // this is oldest to newest, so this gets a bit ugly
274 while (windowList
.hasMoreElements()) {
275 var nextWin
= windowList
.getNext();
276 if (!nextWin
.document
.documentElement
.getAttribute("chromehidden"))
281 var windowList
= wm
.getZOrderDOMWindowEnumerator("navigator:browser", true);
282 if (!windowList
.hasMoreElements())
285 var win
= windowList
.getNext();
286 while (win
.document
.documentElement
.getAttribute("chromehidden")) {
287 if (!windowList
.hasMoreElements())
290 win
= windowList
.getNext();
297 function doSearch(searchTerm
, cmdLine
) {
298 var ss
= Components
.classes
["@mozilla.org/browser/search-service;1"]
299 .getService(nsIBrowserSearchService
);
301 var submission
= ss
.defaultEngine
.getSubmission(searchTerm
, null);
303 // fill our nsISupportsArray with uri-as-wstring, null, null, postData
304 var sa
= Components
.classes
["@mozilla.org/supports-array;1"]
305 .createInstance(Components
.interfaces
.nsISupportsArray
);
307 var wuri
= Components
.classes
["@mozilla.org/supports-string;1"]
308 .createInstance(Components
.interfaces
.nsISupportsString
);
309 wuri
.data
= submission
.uri
.spec
;
311 sa
.AppendElement(wuri
);
312 sa
.AppendElement(null);
313 sa
.AppendElement(null);
314 sa
.AppendElement(submission
.postData
);
316 // XXXbsmedberg: use handURIToExistingBrowser to obey tabbed-browsing
317 // preferences, but need nsIBrowserDOMWindow extensions
319 var wwatch
= Components
.classes
["@mozilla.org/embedcomp/window-watcher;1"]
320 .getService(nsIWindowWatcher
);
322 return wwatch
.openWindow(null, nsBrowserContentHandler
.chromeURL
,
324 "chrome,dialog=no,all" +
325 nsBrowserContentHandler
.getFeatures(cmdLine
),
329 var nsBrowserContentHandler
= {
330 /* helper functions */
335 if (this.mChromeURL
) {
336 return this.mChromeURL
;
339 var prefb
= Components
.classes
["@mozilla.org/preferences-service;1"]
340 .getService(nsIPrefBranch
);
341 this.mChromeURL
= prefb
.getCharPref("browser.chromeURL");
343 return this.mChromeURL
;
347 QueryInterface
: function bch_QI(iid
) {
348 if (!iid
.equals(nsISupports
) &&
349 !iid
.equals(nsICommandLineHandler
) &&
350 !iid
.equals(nsIBrowserHandler
) &&
351 !iid
.equals(nsIContentHandler
) &&
352 !iid
.equals(nsICommandLineValidator
) &&
353 !iid
.equals(nsIFactory
))
354 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
359 /* nsICommandLineHandler */
360 handle
: function bch_handle(cmdLine
) {
361 if (cmdLine
.handleFlag("browser", false)) {
362 // Passing defaultArgs, so use NO_EXTERNAL_URIS
363 openWindow(null, this.chromeURL
, "_blank",
364 "chrome,dialog=no,all" + this.getFeatures(cmdLine
),
365 this.defaultArgs
, NO_EXTERNAL_URIS
);
366 cmdLine
.preventDefault
= true;
370 var remoteCommand
= cmdLine
.handleFlagWithParam("remote", true);
373 throw NS_ERROR_ABORT
;
376 if (remoteCommand
!= null) {
378 var a
= /^\s*(\w+)\(([^\)]*)\)\s*$/.exec(remoteCommand
);
381 remoteVerb
= a
[1].toLowerCase();
382 var remoteParams
= [];
383 var sepIndex
= a
[2].lastIndexOf(",");
385 remoteParams
[0] = a
[2];
387 remoteParams
[0] = a
[2].substring(0, sepIndex
);
388 remoteParams
[1] = a
[2].substring(sepIndex
+ 1);
392 switch (remoteVerb
) {
396 // openURL(<url>,new-window)
397 // openURL(<url>,new-tab)
399 // First param is the URL, second param (if present) is the "target"
401 var url
= remoteParams
[0];
402 var target
= nsIBrowserDOMWindow
.OPEN_DEFAULTWINDOW
;
403 if (remoteParams
[1]) {
404 var targetParam
= remoteParams
[1].toLowerCase()
405 .replace(/^\s*|\s*$/g, "");
406 if (targetParam
== "new-tab")
407 target
= nsIBrowserDOMWindow
.OPEN_NEWTAB
;
408 else if (targetParam
== "new-window")
409 target
= nsIBrowserDOMWindow
.OPEN_NEWWINDOW
;
411 // The "target" param isn't one of our supported values, so
412 // assume it's part of a URL that contains commas.
413 url
+= "," + remoteParams
[1];
417 var uri
= resolveURIInternal(cmdLine
, url
);
418 handURIToExistingBrowser(uri
, target
, cmdLine
);
422 // xfeDoCommand(openBrowser)
423 if (remoteParams
[0].toLowerCase() != "openbrowser")
424 throw NS_ERROR_ABORT
;
426 // Passing defaultArgs, so use NO_EXTERNAL_URIS
427 openWindow(null, this.chromeURL
, "_blank",
428 "chrome,dialog=no,all" + this.getFeatures(cmdLine
),
429 this.defaultArgs
, NO_EXTERNAL_URIS
);
433 // Somebody sent us a remote command we don't know how to process:
435 throw "Unknown remote command.";
438 cmdLine
.preventDefault
= true;
441 Components
.utils
.reportError(e
);
442 // If we had a -remote flag but failed to process it, throw
443 // NS_ERROR_ABORT so that the xremote code knows to return a failure
444 // back to the handling code.
445 throw NS_ERROR_ABORT
;
451 while ((uriparam
= cmdLine
.handleFlagWithParam("new-window", false))) {
452 var uri
= resolveURIInternal(cmdLine
, uriparam
);
453 if (!shouldLoadURI(uri
))
455 openWindow(null, this.chromeURL
, "_blank",
456 "chrome,dialog=no,all" + this.getFeatures(cmdLine
),
458 cmdLine
.preventDefault
= true;
462 Components
.utils
.reportError(e
);
466 while ((uriparam
= cmdLine
.handleFlagWithParam("new-tab", false))) {
467 var uri
= resolveURIInternal(cmdLine
, uriparam
);
468 handURIToExistingBrowser(uri
, nsIBrowserDOMWindow
.OPEN_NEWTAB
, cmdLine
);
469 cmdLine
.preventDefault
= true;
473 Components
.utils
.reportError(e
);
476 var chromeParam
= cmdLine
.handleFlagWithParam("chrome", false);
479 // Handle the old preference dialog URL separately (bug 285416)
480 if (chromeParam
== "chrome://browser/content/pref/pref.xul") {
482 cmdLine
.preventDefault
= true;
484 // only load URIs which do not inherit chrome privs
485 var features
= "chrome,dialog=no,all" + this.getFeatures(cmdLine
);
486 var uri
= resolveURIInternal(cmdLine
, chromeParam
);
487 var netutil
= Components
.classes
["@mozilla.org/network/util;1"]
488 .getService(nsINetUtil
);
489 if (!netutil
.URIChainHasFlags(uri
, URI_INHERITS_SECURITY_CONTEXT
)) {
490 openWindow(null, uri
.spec
, "_blank", features
);
491 cmdLine
.preventDefault
= true;
495 Components
.utils
.reportError(e
);
498 if (cmdLine
.handleFlag("preferences", false)) {
500 cmdLine
.preventDefault
= true;
502 if (cmdLine
.handleFlag("silent", false))
503 cmdLine
.preventDefault
= true;
505 var searchParam
= cmdLine
.handleFlagWithParam("search", false);
507 doSearch(searchParam
, cmdLine
);
508 cmdLine
.preventDefault
= true;
512 // Handle "? searchterm" for Windows Vista start menu integration
513 for (var i
= cmdLine
.length
- 1; i
>= 0; --i
) {
514 var param
= cmdLine
.getArgument(i
);
515 if (param
.match(/^\? /)) {
516 cmdLine
.removeArguments(i
, i
);
517 cmdLine
.preventDefault
= true;
519 searchParam
= param
.substr(2);
520 doSearch(searchParam
, cmdLine
);
526 helpInfo
: " -browser Open a browser window.\n",
528 /* nsIBrowserHandler */
531 var prefb
= Components
.classes
["@mozilla.org/preferences-service;1"]
532 .getService(nsIPrefBranch
);
533 var formatter
= Components
.classes
["@mozilla.org/toolkit/URLFormatterService;1"]
534 .getService(Components
.interfaces
.nsIURLFormatter
);
536 var overridePage
= "";
537 var haveUpdateSession
= false;
539 switch (needHomepageOverride(prefb
)) {
540 case OVERRIDE_NEW_PROFILE
:
542 overridePage
= formatter
.formatURLPref("startup.homepage_welcome_url");
544 case OVERRIDE_NEW_MSTONE
:
545 // Existing profile, new build
548 // Check whether we have a session to restore. If we do, we assume
549 // that this is an "update" session.
550 var ss
= Components
.classes
["@mozilla.org/browser/sessionstartup;1"]
551 .getService(Components
.interfaces
.nsISessionStartup
);
552 haveUpdateSession
= ss
.doRestore();
553 overridePage
= formatter
.formatURLPref("startup.homepage_override_url");
558 // formatURLPref might return "about:blank" if getting the pref fails
559 if (overridePage
== "about:blank")
564 var choice
= prefb
.getIntPref("browser.startup.page");
565 if (choice
== 1 || choice
== 3)
566 startPage
= this.startPage
;
569 startPage
= Components
.classes
["@mozilla.org/browser/global-history;2"]
570 .getService(nsIBrowserHistory
).lastPageVisited
;
572 Components
.utils
.reportError(e
);
575 if (startPage
== "about:blank")
578 // Only show the startPage if we're not restoring an update session.
579 if (overridePage
&& startPage
&& !haveUpdateSession
)
580 return overridePage
+ "|" + startPage
;
582 return overridePage
|| startPage
|| "about:blank";
586 var prefb
= Components
.classes
["@mozilla.org/preferences-service;1"]
587 .getService(nsIPrefBranch
);
589 var uri
= prefb
.getComplexValue("browser.startup.homepage",
590 nsIPrefLocalizedString
).data
;
593 prefb
.clearUserPref("browser.startup.homepage");
594 uri
= prefb
.getComplexValue("browser.startup.homepage",
595 nsIPrefLocalizedString
).data
;
600 count
= prefb
.getIntPref("browser.startup.homepage.count");
606 for (var i
= 1; i
< count
; ++i
) {
608 var page
= prefb
.getComplexValue("browser.startup.homepage." + i
,
609 nsIPrefLocalizedString
).data
;
621 getFeatures
: function bch_features(cmdLine
) {
622 if (this.mFeatures
=== null) {
626 var width
= cmdLine
.handleFlagWithParam("width", false);
627 var height
= cmdLine
.handleFlagWithParam("height", false);
630 this.mFeatures
+= ",width=" + width
;
632 this.mFeatures
+= ",height=" + height
;
638 return this.mFeatures
;
641 /* nsIContentHandler */
643 handleContent
: function bch_handleContent(contentType
, context
, request
) {
645 var webNavInfo
= Components
.classes
["@mozilla.org/webnavigation-info;1"]
646 .getService(nsIWebNavigationInfo
);
647 if (!webNavInfo
.isTypeSupported(contentType
, null)) {
648 throw NS_ERROR_WONT_HANDLE_CONTENT
;
651 throw NS_ERROR_WONT_HANDLE_CONTENT
;
654 request
.QueryInterface(nsIChannel
);
655 handURIToExistingBrowser(request
.URI
,
656 nsIBrowserDOMWindow
.OPEN_DEFAULTWINDOW
, null);
657 request
.cancel(NS_BINDING_ABORTED
);
660 /* nsICommandLineValidator */
661 validate
: function bch_validate(cmdLine
) {
662 // Other handlers may use osint so only handle the osint flag if the url
663 // flag is also present and the command line is valid.
664 var osintFlagIdx
= cmdLine
.findFlag("osint", false);
665 var urlFlagIdx
= cmdLine
.findFlag("url", false);
666 if (urlFlagIdx
> -1 && (osintFlagIdx
> -1 ||
667 cmdLine
.state
== nsICommandLine
.STATE_REMOTE_EXPLICIT
)) {
668 var urlParam
= cmdLine
.getArgument(urlFlagIdx
+ 1);
669 if (cmdLine
.length
!= urlFlagIdx
+ 2 || /firefoxurl:/.test(urlParam
))
670 throw NS_ERROR_ABORT
;
671 cmdLine
.handleFlag("osint", false)
676 createInstance
: function bch_CI(outer
, iid
) {
678 throw Components
.results
.NS_ERROR_NO_AGGREGATION
;
680 return this.QueryInterface(iid
);
683 lockFactory
: function bch_lock(lock
) {
688 const bch_contractID
= "@mozilla.org/browser/clh;1";
689 const bch_CID
= Components
.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}");
690 const CONTRACTID_PREFIX
= "@mozilla.org/uriloader/content-handler;1?type=";
692 function handURIToExistingBrowser(uri
, location
, cmdLine
)
694 if (!shouldLoadURI(uri
))
697 var navWin
= getMostRecentBrowserWindow();
699 // if we couldn't load it in an existing window, open a new one
700 openWindow(null, nsBrowserContentHandler
.chromeURL
, "_blank",
701 "chrome,dialog=no,all" + nsBrowserContentHandler
.getFeatures(cmdLine
),
706 var navNav
= navWin
.QueryInterface(nsIInterfaceRequestor
)
707 .getInterface(nsIWebNavigation
);
708 var rootItem
= navNav
.QueryInterface(nsIDocShellTreeItem
).rootTreeItem
;
709 var rootWin
= rootItem
.QueryInterface(nsIInterfaceRequestor
)
710 .getInterface(nsIDOMWindow
);
711 var bwin
= rootWin
.QueryInterface(nsIDOMChromeWindow
).browserDOMWindow
;
712 bwin
.openURI(uri
, null, location
,
713 nsIBrowserDOMWindow
.OPEN_EXTERNAL
);
717 var nsDefaultCommandLineHandler
= {
719 QueryInterface
: function dch_QI(iid
) {
720 if (!iid
.equals(nsISupports
) &&
721 !iid
.equals(nsICommandLineHandler
) &&
722 !iid
.equals(nsIFactory
))
723 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
728 // List of uri's that were passed via the command line without the app
729 // running and have already been handled. This is compared against uri's
730 // opened using DDE on Win32 so we only open one of the requests.
736 /* nsICommandLineHandler */
737 handle
: function dch_handle(cmdLine
) {
741 // If we don't have a profile selected yet (e.g. the Profile Manager is
742 // displayed) we will crash if we open an url and then select a profile. To
743 // prevent this handle all url command line flags and set the command line's
744 // preventDefault to true to prevent the display of the ui. The initial
745 // command line will be retained when nsAppRunner calls LaunchChild though
746 // urls launched after the initial launch will be lost.
747 if (!this._haveProfile
) {
749 // This will throw when a profile has not been selected.
750 var fl
= Components
.classes
["@mozilla.org/file/directory_service;1"]
751 .getService(Components
.interfaces
.nsIProperties
);
752 var dir
= fl
.get("ProfD", Components
.interfaces
.nsILocalFile
);
753 this._haveProfile
= true;
756 while ((ar
= cmdLine
.handleFlagWithParam("url", false))) { }
757 cmdLine
.preventDefault
= true;
764 while ((ar
= cmdLine
.handleFlagWithParam("url", false))) {
766 var uri
= resolveURIInternal(cmdLine
, ar
);
767 // count will never be greater than zero except on Win32.
768 var count
= this._handledURIs
.length
;
769 for (var i
= 0; i
< count
; ++i
) {
770 if (this._handledURIs
[i
].spec
== uri
.spec
) {
771 this._handledURIs
.splice(i
, 1);
773 cmdLine
.preventDefault
= true;
779 // The requestpending command line flag is only used on Win32.
780 if (cmdLine
.handleFlag("requestpending", false) &&
781 cmdLine
.state
== nsICommandLine
.STATE_INITIAL_LAUNCH
)
782 this._handledURIs
.push(uri
)
787 Components
.utils
.reportError(e
);
790 count
= cmdLine
.length
;
792 for (i
= 0; i
< count
; ++i
) {
793 var curarg
= cmdLine
.getArgument(i
);
794 if (curarg
.match(/^-/)) {
795 Components
.utils
.reportError("Warning: unrecognized command line flag " + curarg
+ "\n");
796 // To emulate the pre-nsICommandLine behavior, we ignore
797 // the argument after an unrecognized flag.
801 urilist
.push(resolveURIInternal(cmdLine
, curarg
));
804 Components
.utils
.reportError("Error opening URI '" + curarg
+ "' from the command line: " + e
+ "\n");
809 if (urilist
.length
) {
810 if (cmdLine
.state
!= nsICommandLine
.STATE_INITIAL_LAUNCH
&&
811 urilist
.length
== 1) {
812 // Try to find an existing window and load our URI into the
813 // current tab, new tab, or new window as prefs determine.
815 handURIToExistingBrowser(urilist
[0], nsIBrowserDOMWindow
.OPEN_DEFAULTWINDOW
, cmdLine
);
822 var URLlist
= urilist
.filter(shouldLoadURI
).map(function (u
) u
.spec
);
823 if (URLlist
.length
) {
824 openWindow(null, nsBrowserContentHandler
.chromeURL
, "_blank",
825 "chrome,dialog=no,all" + nsBrowserContentHandler
.getFeatures(cmdLine
),
830 else if (!cmdLine
.preventDefault
) {
831 // Passing defaultArgs, so use NO_EXTERNAL_URIS
832 openWindow(null, nsBrowserContentHandler
.chromeURL
, "_blank",
833 "chrome,dialog=no,all" + nsBrowserContentHandler
.getFeatures(cmdLine
),
834 nsBrowserContentHandler
.defaultArgs
, NO_EXTERNAL_URIS
);
838 // XXX localize me... how?
839 helpInfo
: "Usage: firefox [-flags] [<url>]\n",
842 createInstance
: function dch_CI(outer
, iid
) {
844 throw Components
.results
.NS_ERROR_NO_AGGREGATION
;
846 return this.QueryInterface(iid
);
849 lockFactory
: function dch_lock(lock
) {
854 const dch_contractID
= "@mozilla.org/browser/final-clh;1";
855 const dch_CID
= Components
.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}");
859 QueryInterface
: function mod_QI(iid
) {
860 if (iid
.equals(Components
.interfaces
.nsIModule
) ||
861 iid
.equals(Components
.interfaces
.nsISupports
))
864 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
868 getClassObject
: function mod_getco(compMgr
, cid
, iid
) {
869 if (cid
.equals(bch_CID
))
870 return nsBrowserContentHandler
.QueryInterface(iid
);
872 if (cid
.equals(dch_CID
))
873 return nsDefaultCommandLineHandler
.QueryInterface(iid
);
875 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
878 registerSelf
: function mod_regself(compMgr
, fileSpec
, location
, type
) {
879 if (Components
.classes
["@mozilla.org/xre/app-info;1"]) {
880 // Don't register these if Firefox is launching a XULRunner application
881 const FIREFOX_UID
= "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
882 var appInfo
= Components
.classes
["@mozilla.org/xre/app-info;1"]
883 .getService(Components
.interfaces
.nsIXULAppInfo
);
884 if (appInfo
.ID
!= FIREFOX_UID
)
889 compMgr
.QueryInterface( Components
.interfaces
.nsIComponentRegistrar
);
891 compReg
.registerFactoryLocation( bch_CID
,
892 "nsBrowserContentHandler",
897 compReg
.registerFactoryLocation( dch_CID
,
898 "nsDefaultCommandLineHandler",
904 function registerType(contentType
) {
905 compReg
.registerFactoryLocation( bch_CID
,
906 "Browser Cmdline Handler",
907 CONTRACTID_PREFIX
+ contentType
,
913 registerType("text/html");
914 registerType("application/vnd.mozilla.xul+xml");
916 registerType("image/svg+xml");
918 registerType("text/rdf");
919 registerType("text/xml");
920 registerType("application/xhtml+xml");
921 registerType("text/css");
922 registerType("text/plain");
923 registerType("image/gif");
924 registerType("image/jpeg");
925 registerType("image/jpg");
926 registerType("image/png");
927 registerType("image/bmp");
928 registerType("image/x-icon");
929 registerType("image/vnd.microsoft.icon");
930 registerType("image/x-xbitmap");
931 registerType("application/http-index-format");
933 var catMan
= Components
.classes
["@mozilla.org/categorymanager;1"]
934 .getService(nsICategoryManager
);
936 catMan
.addCategoryEntry("command-line-handler",
938 bch_contractID
, true, true);
939 catMan
.addCategoryEntry("command-line-handler",
941 dch_contractID
, true, true);
942 catMan
.addCategoryEntry("command-line-validator",
944 bch_contractID
, true, true);
947 unregisterSelf
: function mod_unregself(compMgr
, location
, type
) {
948 var compReg
= compMgr
.QueryInterface(nsIComponentRegistrar
);
949 compReg
.unregisterFactoryLocation(bch_CID
, location
);
950 compReg
.unregisterFactoryLocation(dch_CID
, location
);
952 var catMan
= Components
.classes
["@mozilla.org/categorymanager;1"]
953 .getService(nsICategoryManager
);
955 catMan
.deleteCategoryEntry("command-line-handler",
957 catMan
.deleteCategoryEntry("command-line-handler",
959 catMan
.deleteCategoryEntry("command-line-validator",
963 canUnload: function(compMgr
) {
968 // NSGetModule: Return the nsIModule object.
969 function NSGetModule(compMgr
, fileSpec
) {