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 *****
72 .URI_INHERITS_SECURITY_CONTEXT;
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");
84 var
uri = aCmdLine.resolveURI(aArgument);
91 if (uri.file.exists())
95 Components.utils.reportError(e);
102 var urifixup = Components.classes[
"@mozilla.org/docshell/urifixup;1"]
105 uri = urifixup.createFixupURI(aArgument, 0);
108 Components.utils.reportError(e);
126 var savedmstone =
null;
128 savedmstone = prefb.getCharPref(
"browser.startup.homepage_override.mstone");
131 if (savedmstone ==
"ignore")
134 var mstone = Components.classes[
"@mozilla.org/network/protocol;1?name=http"]
137 if (mstone != savedmstone) {
143 prefb.setBoolPref(
"browser.rights.3.shown",
true);
145 prefb.setCharPref(
"browser.startup.homepage_override.mstone", mstone);
156 var fileLocator = Components.classes[
"@mozilla.org/file/directory_service;1"]
157 .getService(Components.interfaces.nsIProperties);
160 Components.interfaces.nsIFile);
161 if (!prefOverride.exists())
164 const NS_APP_PREFS_OVERRIDE_DIR =
"PrefDOverride";
165 var prefOverridesDir = fileLocator.get(NS_APP_PREFS_OVERRIDE_DIR,
166 Components.interfaces.nsIFile);
169 var existingPrefOverridesFile = prefOverridesDir.clone();
170 existingPrefOverridesFile.append(prefOverride.leafName);
171 if (existingPrefOverridesFile.exists())
172 existingPrefOverridesFile.remove(
false);
174 prefOverride.copyTo(prefOverridesDir,
null);
178 var prefSvcObs = Components.classes[
"@mozilla.org/preferences-service;1"]
179 .getService(Components.interfaces.nsIObserver);
180 prefSvcObs.observe(
null,
"reload-default-prefs",
null);
182 Components.utils.reportError(ex);
190 var wwatch = Components.classes[
"@mozilla.org/embedcomp/window-watcher;1"]
197 argstring = Components.classes[
"@mozilla.org/supports-string;1"]
199 argstring.data =
args;
202 return wwatch.openWindow(parent,
url,
target, features, argstring);
206 var argArray = Components.classes[
"@mozilla.org/supports-array;1"]
207 .createInstance(Components.interfaces.nsISupportsArray);
210 var stringArgs =
null;
218 var uriArray = Components.classes[
"@mozilla.org/supports-array;1"]
219 .createInstance(Components.interfaces.nsISupportsArray);
220 stringArgs.forEach(
function (
uri) {
221 var sstring = Components.classes[
"@mozilla.org/supports-string;1"]
224 uriArray.AppendElement(sstring);
226 argArray.AppendElement(uriArray);
228 argArray.AppendElement(
null);
234 argArray.AppendElement(
null);
235 argArray.AppendElement(
null);
236 argArray.AppendElement(
null);
237 argArray.AppendElement(
null);
239 return wwatch.openWindow(parent,
url,
target, features, argArray);
243 var features =
"chrome,titlebar,toolbar,centerscreen,dialog=no";
244 var
url =
"chrome://browser/content/preferences/preferences.xul";
255 var
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
257 return wm.getMostRecentWindow(aType);
262 var browserGlue = Components.classes[
"@mozilla.org/browser/browserglue;1"]
263 .getService(Components.interfaces.nsIBrowserGlue);
264 return browserGlue.getMostRecentBrowserWindow();
268 var ss = Components.classes[
"@mozilla.org/browser/search-service;1"]
271 var submission = ss.defaultEngine.getSubmission(searchTerm,
null);
274 var sa = Components.classes[
"@mozilla.org/supports-array;1"]
275 .createInstance(Components.interfaces.nsISupportsArray);
277 var wuri = Components.classes[
"@mozilla.org/supports-string;1"]
278 .createInstance(Components.interfaces.nsISupportsString);
279 wuri.data = submission.uri.spec;
281 sa.AppendElement(wuri);
282 sa.AppendElement(
null);
283 sa.AppendElement(
null);
284 sa.AppendElement(submission.postData);
289 var wwatch = Components.classes[
"@mozilla.org/embedcomp/window-watcher;1"]
294 "chrome,dialog=no,all" +
305 if (this.mChromeURL) {
306 return this.mChromeURL;
309 var prefb = Components.classes[
"@mozilla.org/preferences-service;1"]
311 this.mChromeURL = prefb.getCharPref(
"browser.chromeURL");
313 return this.mChromeURL;
324 throw Components.results.NS_ERROR_NO_INTERFACE;
330 handle :
function bch_handle(cmdLine) {
331 if (cmdLine.handleFlag(
"browser",
false)) {
334 "chrome,dialog=no,all" + this.getFeatures(cmdLine),
336 cmdLine.preventDefault =
true;
340 var remoteCommand = cmdLine.handleFlagWithParam(
"remote",
true);
346 if (remoteCommand !=
null) {
348 var a = /^\s*(\w+)\(([^\)]*)\)\s*$/.exec(remoteCommand);
351 remoteVerb = a[1].toLowerCase();
352 var remoteParams = [];
353 var sepIndex = a[2].lastIndexOf(
",");
355 remoteParams[0] = a[2];
357 remoteParams[0] = a[2].substring(0, sepIndex);
358 remoteParams[1] = a[2].substring(sepIndex + 1);
362 switch (remoteVerb) {
371 var
url = remoteParams[0];
373 if (remoteParams[1]) {
374 var targetParam = remoteParams[1].toLowerCase()
375 .replace(/^\s*|\s*$/g,
"");
376 if (targetParam ==
"new-tab")
378 else if (targetParam ==
"new-window")
383 url +=
"," + remoteParams[1];
393 if (remoteParams[0].toLowerCase() !=
"openbrowser")
398 "chrome,dialog=no,all" + this.getFeatures(cmdLine),
405 throw "Unknown remote command.";
408 cmdLine.preventDefault =
true;
411 Components.utils.reportError(e);
421 while ((uriparam = cmdLine.handleFlagWithParam(
"new-window",
false))) {
426 "chrome,dialog=no,all" + this.getFeatures(cmdLine),
428 cmdLine.preventDefault =
true;
432 Components.utils.reportError(e);
436 while ((uriparam = cmdLine.handleFlagWithParam(
"new-tab",
false))) {
439 cmdLine.preventDefault =
true;
443 Components.utils.reportError(e);
446 var chromeParam = cmdLine.handleFlagWithParam(
"chrome",
false);
450 if (chromeParam ==
"chrome://browser/content/pref/pref.xul") {
452 cmdLine.preventDefault =
true;
455 var features =
"chrome,dialog=no,all" + this.getFeatures(cmdLine);
457 var netutil = Components.classes[
"@mozilla.org/network/util;1"]
461 cmdLine.preventDefault =
true;
465 Components.utils.reportError(e);
468 if (cmdLine.handleFlag(
"preferences",
false)) {
470 cmdLine.preventDefault =
true;
472 if (cmdLine.handleFlag(
"silent",
false))
473 cmdLine.preventDefault =
true;
475 var searchParam = cmdLine.handleFlagWithParam(
"search",
false);
478 cmdLine.preventDefault =
true;
481 var fileParam = cmdLine.handleFlagWithParam(
"file",
false);
483 var
file = cmdLine.resolveFile(fileParam);
484 var
ios = Components.classes[
"@mozilla.org/network/io-service;1"]
485 .getService(Components.interfaces.nsIIOService);
486 var
uri = ios.newFileURI(file);
488 "chrome,dialog=no,all" + this.getFeatures(cmdLine),
490 cmdLine.preventDefault =
true;
495 for (var
i = cmdLine.length - 1;
i >= 0; --
i) {
496 var param = cmdLine.getArgument(
i);
497 if (param.match(/^\? /)) {
498 cmdLine.removeArguments(
i,
i);
499 cmdLine.preventDefault =
true;
501 searchParam = param.substr(2);
508 helpInfo :
" -browser Open a browser window.\n",
513 var prefb = Components.classes[
"@mozilla.org/preferences-service;1"]
515 var formatter = Components.classes[
"@mozilla.org/toolkit/URLFormatterService;1"]
516 .getService(Components.interfaces.nsIURLFormatter);
518 var overridePage =
"";
519 var haveUpdateSession =
false;
524 overridePage = formatter.formatURLPref(
"startup.homepage_welcome_url");
532 var ss = Components.classes[
"@mozilla.org/browser/sessionstartup;1"]
533 .getService(Components.interfaces.nsISessionStartup);
534 haveUpdateSession = ss.doRestore();
535 overridePage = formatter.formatURLPref(
"startup.homepage_override_url");
541 if (overridePage ==
"about:blank")
546 var choice = prefb.getIntPref(
"browser.startup.page");
547 if (choice == 1 || choice == 3)
548 startPage = this.startPage;
551 startPage = Components.classes[
"@mozilla.org/browser/global-history;2"]
554 Components.utils.reportError(e);
557 if (startPage ==
"about:blank")
561 if (overridePage && startPage && !haveUpdateSession)
562 return overridePage +
"|" + startPage;
564 return overridePage || startPage ||
"about:blank";
568 var prefb = Components.classes[
"@mozilla.org/preferences-service;1"]
571 var
uri = prefb.getComplexValue(
"browser.startup.homepage",
575 prefb.clearUserPref(
"browser.startup.homepage");
576 uri = prefb.getComplexValue(
"browser.startup.homepage",
582 count = prefb.getIntPref(
"browser.startup.homepage.count");
590 var page = prefb.getComplexValue(
"browser.startup.homepage." +
i,
603 getFeatures :
function bch_features(cmdLine) {
604 if (this.mFeatures ===
null) {
608 var
width = cmdLine.handleFlagWithParam(
"width",
false);
609 var
height = cmdLine.handleFlagWithParam(
"height",
false);
612 this.mFeatures +=
",width=" +
width;
614 this.mFeatures +=
",height=" +
height;
620 return this.mFeatures;
625 handleContent :
function bch_handleContent(contentType, context, request) {
627 var webNavInfo = Components.classes[
"@mozilla.org/webnavigation-info;1"]
629 if (!webNavInfo.isTypeSupported(contentType,
null)) {
643 validate :
function bch_validate(cmdLine) {
646 var osintFlagIdx = cmdLine.findFlag(
"osint",
false);
647 var urlFlagIdx = cmdLine.findFlag(
"url",
false);
648 if (urlFlagIdx > -1 && (osintFlagIdx > -1 ||
650 var urlParam = cmdLine.getArgument(urlFlagIdx + 1);
651 if (cmdLine.length != urlFlagIdx + 2 || /firefoxurl:/.test(urlParam))
653 cmdLine.handleFlag(
"osint",
false)
660 throw Components.results.NS_ERROR_NO_AGGREGATION;
665 lockFactory :
function bch_lock(lock) {
671 const bch_CID = Components.ID(
"{5d0ce354-df01-421a-83fb-7ead0990c24e}");
694 bwin.openURI(
uri,
null, location,
705 throw Components.results.NS_ERROR_NO_INTERFACE;
719 handle :
function dch_handle(cmdLine) {
729 if (!this._haveProfile) {
732 var fl = Components.classes[
"@mozilla.org/file/directory_service;1"]
733 .getService(Components.interfaces.nsIProperties);
734 var
dir = fl.get(
"ProfD", Components.interfaces.nsILocalFile);
735 this._haveProfile =
true;
738 while ((ar = cmdLine.handleFlagWithParam(
"url",
false))) { }
739 cmdLine.preventDefault =
true;
746 while ((ar = cmdLine.handleFlagWithParam(
"url",
false))) {
750 var
count = this._handledURIs.length;
752 if (this._handledURIs[
i].spec == uri.spec) {
753 this._handledURIs.splice(
i, 1);
755 cmdLine.preventDefault =
true;
762 if (cmdLine.handleFlag(
"requestpending",
false) &&
764 this._handledURIs.push(uri)
769 Components.utils.reportError(e);
772 count = cmdLine.length;
775 var curarg = cmdLine.getArgument(
i);
776 if (curarg.match(/^-/)) {
777 Components.utils.reportError(
"Warning: unrecognized command line flag " + curarg +
"\n");
786 Components.utils.reportError(
"Error opening URI '" + curarg +
"' from the command line: " + e +
"\n");
791 if (urilist.length) {
793 urilist.length == 1) {
804 var URLlist = urilist.filter(
shouldLoadURI).map(
function (u) u.spec);
805 if (URLlist.length) {
812 else if (!cmdLine.preventDefault) {
821 helpInfo :
"Usage: firefox [-flags] [<url>]\n",
826 throw Components.results.NS_ERROR_NO_AGGREGATION;
831 lockFactory :
function dch_lock(lock) {
837 const dch_CID = Components.ID(
"{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}");
842 if (iid.equals(Components.interfaces.nsIModule) ||
843 iid.equals(Components.interfaces.nsISupports))
846 throw Components.results.NS_ERROR_NO_INTERFACE;
855 return nsDefaultCommandLineHandler.QueryInterface(iid);
857 throw Components.results.NS_ERROR_NO_INTERFACE;
860 registerSelf:
function mod_regself(compMgr, fileSpec, location, type) {
861 if (Components.classes[
"@mozilla.org/xre/app-info;1"]) {
863 const FIREFOX_UID =
"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
864 var appInfo = Components.classes[
"@mozilla.org/xre/app-info;1"]
865 .getService(Components.interfaces.nsIXULAppInfo);
866 if (appInfo.ID != FIREFOX_UID)
871 compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
873 compReg.registerFactoryLocation(
bch_CID,
874 "nsBrowserContentHandler",
879 compReg.registerFactoryLocation(
dch_CID,
880 "nsDefaultCommandLineHandler",
886 function registerType(contentType) {
887 compReg.registerFactoryLocation(
bch_CID,
888 "Browser Cmdline Handler",
895 registerType(
"text/html");
896 registerType(
"application/vnd.mozilla.xul+xml");
898 registerType(
"image/svg+xml");
900 registerType(
"text/rdf");
901 registerType(
"text/xml");
902 registerType(
"application/xhtml+xml");
903 registerType(
"text/css");
904 registerType(
"text/plain");
905 registerType(
"image/gif");
906 registerType(
"image/jpeg");
907 registerType(
"image/jpg");
908 registerType(
"image/png");
909 registerType(
"image/bmp");
910 registerType(
"image/x-icon");
911 registerType(
"image/vnd.microsoft.icon");
912 registerType(
"application/http-index-format");
914 var catMan = Components.classes[
"@mozilla.org/categorymanager;1"]
917 catMan.addCategoryEntry(
"command-line-handler",
920 catMan.addCategoryEntry(
"command-line-handler",
923 catMan.addCategoryEntry(
"command-line-validator",
928 unregisterSelf :
function mod_unregself(compMgr, location, type) {
929 var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
930 compReg.unregisterFactoryLocation(
bch_CID, location);
931 compReg.unregisterFactoryLocation(
dch_CID, location);
933 var catMan = Components.classes[
"@mozilla.org/categorymanager;1"]
936 catMan.deleteCategoryEntry(
"command-line-handler",
938 catMan.deleteCategoryEntry(
"command-line-handler",
940 catMan.deleteCategoryEntry(
"command-line-validator",
944 canUnload:
function(compMgr) {
var nsDefaultCommandLineHandler
const nsICommandLineValidator
#define NS_APP_EXISTING_PREF_OVERRIDE
var nsBrowserContentHandler
const nsIBrowserDOMWindow
const nsICommandLineHandler
const nsIDocShellTreeItem
SafebrowsingApplicationMod prototype registerSelf
const nsIPrefLocalizedString
function openPreferences()
sbOSDControlService prototype QueryInterface
function handle(request, response)
const nsIHttpProtocolHandler
function handURIToExistingBrowser(uri, location, cmdLine)
function NSGetModule(compMgr, fileSpec)
const NS_ERROR_WONT_HANDLE_CONTENT
const URI_INHERITS_SECURITY_CONTEXT
SafebrowsingApplicationMod prototype getClassObject
function needHomepageOverride(prefb)
function openWindow(parent, url, target, features, args, noExternalArgs)
const nsIWebNavigationInfo
const OVERRIDE_NEW_MSTONE
function resolveURIInternal(aCmdLine, aArgument)
function doSearch(searchTerm, cmdLine)
const nsIBrowserSearchService
const nsIInterfaceRequestor
function getMostRecentWindow(aType)
_getSelectedPageStyle s i
function getMostRecentBrowserWindow()
function copyPrefOverride()
const OVERRIDE_NEW_PROFILE
function shouldLoadURI(aURI)