2007-09-05 20:02:22 -07:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Browser Search Service.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# Giorgio Maone
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Giorgio Maone <g.maone@informaction.com>
|
2007-11-26 16:08:50 -08:00
|
|
|
# Seth Spitzer <sspitzer@mozilla.com>
|
|
|
|
# Asaf Romano <mano@mozilla.com>
|
2007-09-05 20:02:22 -07:00
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-16 14:23:17 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Cr = Components.results;
|
2007-09-11 08:52:04 -07:00
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource:///modules/distribution.js");
|
2007-09-05 20:02:22 -07:00
|
|
|
|
|
|
|
// Factory object
|
|
|
|
const BrowserGlueServiceFactory = {
|
|
|
|
_instance: null,
|
|
|
|
createInstance: function (outer, iid)
|
|
|
|
{
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return this._instance == null ?
|
|
|
|
this._instance = new BrowserGlue() : this._instance;
|
|
|
|
}
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
|
|
|
|
function BrowserGlue() {
|
|
|
|
this._init();
|
2007-05-03 01:56:41 -07:00
|
|
|
this._profileStarted = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserGlue.prototype = {
|
2007-06-15 11:01:25 -07:00
|
|
|
_saveSession: false,
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIObserver implementation
|
|
|
|
observe: function(subject, topic, data)
|
|
|
|
{
|
|
|
|
switch(topic) {
|
|
|
|
case "xpcom-shutdown":
|
|
|
|
this._dispose();
|
|
|
|
break;
|
2007-05-10 17:42:22 -07:00
|
|
|
case "profile-before-change":
|
|
|
|
this._onProfileChange();
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "profile-change-teardown":
|
|
|
|
this._onProfileShutdown();
|
|
|
|
break;
|
2007-09-11 08:52:04 -07:00
|
|
|
case "prefservice:after-app-defaults":
|
|
|
|
this._onAppDefaults();
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "final-ui-startup":
|
|
|
|
this._onProfileStartup();
|
|
|
|
break;
|
|
|
|
case "browser:purge-session-history":
|
|
|
|
// reset the console service's error buffer
|
2007-06-16 14:23:17 -07:00
|
|
|
const cs = Cc["@mozilla.org/consoleservice;1"].
|
|
|
|
getService(Ci.nsIConsoleService);
|
2007-03-22 10:30:00 -07:00
|
|
|
cs.logStringMessage(null); // clear the console (in case it's open)
|
|
|
|
cs.reset();
|
|
|
|
break;
|
2007-06-15 11:01:25 -07:00
|
|
|
case "quit-application-requested":
|
2007-07-25 14:43:17 -07:00
|
|
|
this._onQuitRequest(subject, data);
|
2007-06-15 11:01:25 -07:00
|
|
|
break;
|
|
|
|
case "quit-application-granted":
|
|
|
|
if (this._saveSession) {
|
2007-06-16 14:23:17 -07:00
|
|
|
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
prefBranch.setBoolPref("browser.sessionstore.resume_session_once", true);
|
2007-06-15 11:01:25 -07:00
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
,
|
|
|
|
// initialization (called on application startup)
|
|
|
|
_init: function()
|
|
|
|
{
|
|
|
|
// observer registration
|
2007-06-16 14:23:17 -07:00
|
|
|
const osvr = Cc['@mozilla.org/observer-service;1'].
|
|
|
|
getService(Ci.nsIObserverService);
|
2007-05-10 17:42:22 -07:00
|
|
|
osvr.addObserver(this, "profile-before-change", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
osvr.addObserver(this, "profile-change-teardown", false);
|
|
|
|
osvr.addObserver(this, "xpcom-shutdown", false);
|
2007-09-11 08:52:04 -07:00
|
|
|
osvr.addObserver(this, "prefservice:after-app-defaults", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
osvr.addObserver(this, "final-ui-startup", false);
|
|
|
|
osvr.addObserver(this, "browser:purge-session-history", false);
|
2007-06-15 11:01:25 -07:00
|
|
|
osvr.addObserver(this, "quit-application-requested", false);
|
|
|
|
osvr.addObserver(this, "quit-application-granted", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// cleanup (called on application shutdown)
|
|
|
|
_dispose: function()
|
|
|
|
{
|
|
|
|
// observer removal
|
2007-06-16 14:23:17 -07:00
|
|
|
const osvr = Cc['@mozilla.org/observer-service;1'].
|
|
|
|
getService(Ci.nsIObserverService);
|
2007-05-10 17:42:22 -07:00
|
|
|
osvr.removeObserver(this, "profile-before-change");
|
2007-03-22 10:30:00 -07:00
|
|
|
osvr.removeObserver(this, "profile-change-teardown");
|
|
|
|
osvr.removeObserver(this, "xpcom-shutdown");
|
2007-09-11 08:52:04 -07:00
|
|
|
osvr.removeObserver(this, "prefservice:after-app-defaults");
|
2007-03-22 10:30:00 -07:00
|
|
|
osvr.removeObserver(this, "final-ui-startup");
|
|
|
|
osvr.removeObserver(this, "browser:purge-session-history");
|
2007-06-15 11:01:25 -07:00
|
|
|
osvr.removeObserver(this, "quit-application-requested");
|
|
|
|
osvr.removeObserver(this, "quit-application-granted");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-09-11 08:52:04 -07:00
|
|
|
_onAppDefaults: function()
|
|
|
|
{
|
|
|
|
// apply distribution customizations (prefs)
|
|
|
|
// other customizations are applied in _onProfileStartup()
|
|
|
|
var distro = new DistributionCustomizer();
|
|
|
|
distro.applyPrefDefaults();
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// profile startup handler (contains profile initialization routines)
|
|
|
|
_onProfileStartup: function()
|
|
|
|
{
|
|
|
|
// check to see if the EULA must be shown on startup
|
|
|
|
try {
|
|
|
|
var mustDisplayEULA = true;
|
2007-06-16 14:23:17 -07:00
|
|
|
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
var EULAVersion = prefBranch.getIntPref("browser.EULA.version");
|
|
|
|
mustDisplayEULA = !prefBranch.getBoolPref("browser.EULA." + EULAVersion + ".accepted");
|
2007-03-22 10:30:00 -07:00
|
|
|
} catch(ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mustDisplayEULA) {
|
2007-06-16 14:23:17 -07:00
|
|
|
var ww2 = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
2007-03-22 10:30:00 -07:00
|
|
|
ww2.openWindow(null, "chrome://browser/content/EULA.xul",
|
|
|
|
"_blank", "chrome,centerscreen,modal,resizable=yes", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.Sanitizer.onStartup();
|
|
|
|
// check if we're in safe mode
|
2007-06-16 14:23:17 -07:00
|
|
|
var app = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).
|
|
|
|
QueryInterface(Ci.nsIXULRuntime);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (app.inSafeMode) {
|
2007-06-16 14:23:17 -07:00
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
2007-03-22 10:30:00 -07:00
|
|
|
ww.openWindow(null, "chrome://browser/content/safeMode.xul",
|
|
|
|
"_blank", "chrome,centerscreen,modal,resizable=no", null);
|
|
|
|
}
|
2007-05-03 01:56:41 -07:00
|
|
|
|
|
|
|
// initialize Places
|
|
|
|
this._initPlaces();
|
|
|
|
|
2007-09-11 08:52:04 -07:00
|
|
|
// apply distribution customizations
|
|
|
|
// prefs are applied in _onAppDefaults()
|
|
|
|
var distro = new DistributionCustomizer();
|
|
|
|
distro.applyCustomizations();
|
|
|
|
|
2008-02-04 11:37:26 -08:00
|
|
|
// handle any UI migration
|
|
|
|
this._migrateUI();
|
|
|
|
|
2007-05-03 01:56:41 -07:00
|
|
|
// indicate that the profile was initialized
|
|
|
|
this._profileStarted = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-05-10 17:42:22 -07:00
|
|
|
_onProfileChange: function()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-10 17:42:22 -07:00
|
|
|
// this block is for code that depends on _onProfileStartup() having
|
|
|
|
// been called.
|
2007-05-03 01:56:41 -07:00
|
|
|
if (this._profileStarted) {
|
|
|
|
// final places cleanup
|
|
|
|
this._shutdownPlaces();
|
|
|
|
}
|
2007-05-10 17:42:22 -07:00
|
|
|
},
|
2007-05-03 01:56:41 -07:00
|
|
|
|
2007-05-10 17:42:22 -07:00
|
|
|
// profile shutdown handler (contains profile cleanup routines)
|
|
|
|
_onProfileShutdown: function()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
// here we enter last survival area, in order to avoid multiple
|
|
|
|
// "quit-application" notifications caused by late window closings
|
2007-06-16 14:23:17 -07:00
|
|
|
const appStartup = Cc['@mozilla.org/toolkit/app-startup;1'].
|
|
|
|
getService(Ci.nsIAppStartup);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
appStartup.enterLastWindowClosingSurvivalArea();
|
|
|
|
|
|
|
|
this.Sanitizer.onShutdown();
|
|
|
|
|
|
|
|
} catch(ex) {
|
|
|
|
} finally {
|
|
|
|
appStartup.exitLastWindowClosingSurvivalArea();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-07-25 14:43:17 -07:00
|
|
|
_onQuitRequest: function(aCancelQuit, aQuitType)
|
2007-06-15 11:01:25 -07:00
|
|
|
{
|
2008-01-29 13:16:02 -08:00
|
|
|
// If user has already dismissed quit request, then do nothing
|
|
|
|
if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
|
|
|
|
return;
|
|
|
|
|
2007-06-16 14:23:17 -07:00
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
2007-06-15 11:01:25 -07:00
|
|
|
var windowcount = 0;
|
|
|
|
var pagecount = 0;
|
|
|
|
var browserEnum = wm.getEnumerator("navigator:browser");
|
|
|
|
while (browserEnum.hasMoreElements()) {
|
|
|
|
windowcount++;
|
|
|
|
|
|
|
|
var browser = browserEnum.getNext();
|
|
|
|
var tabbrowser = browser.document.getElementById("content");
|
|
|
|
if (tabbrowser)
|
|
|
|
pagecount += tabbrowser.browsers.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._saveSession = false;
|
|
|
|
if (pagecount < 2)
|
|
|
|
return;
|
|
|
|
|
2007-07-25 14:43:17 -07:00
|
|
|
if (aQuitType != "restart")
|
|
|
|
aQuitType = "quit";
|
|
|
|
|
2007-06-16 14:23:17 -07:00
|
|
|
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
2007-06-15 11:01:25 -07:00
|
|
|
var showPrompt = true;
|
|
|
|
try {
|
2007-06-16 14:23:17 -07:00
|
|
|
if (prefBranch.getIntPref("browser.startup.page") == 3 ||
|
|
|
|
prefBranch.getBoolPref("browser.sessionstore.resume_session_once"))
|
2007-06-15 11:01:25 -07:00
|
|
|
showPrompt = false;
|
|
|
|
else
|
2007-06-16 14:23:17 -07:00
|
|
|
showPrompt = prefBranch.getBoolPref("browser.warnOnQuit");
|
2007-06-15 11:01:25 -07:00
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
var buttonChoice = 0;
|
|
|
|
if (showPrompt) {
|
2007-06-16 14:23:17 -07:00
|
|
|
var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService);
|
2007-06-15 11:01:25 -07:00
|
|
|
var quitBundle = bundleService.createBundle("chrome://browser/locale/quitDialog.properties");
|
|
|
|
var brandBundle = bundleService.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
|
|
|
|
var appName = brandBundle.GetStringFromName("brandShortName");
|
2007-07-25 14:43:17 -07:00
|
|
|
var quitDialogTitle = quitBundle.formatStringFromName(aQuitType + "DialogTitle",
|
|
|
|
[appName], 1);
|
2007-06-15 11:01:25 -07:00
|
|
|
|
2007-07-25 14:43:17 -07:00
|
|
|
var message;
|
|
|
|
if (aQuitType == "restart")
|
|
|
|
message = quitBundle.formatStringFromName("messageRestart",
|
|
|
|
[appName], 1);
|
|
|
|
else if (windowcount == 1)
|
|
|
|
message = quitBundle.formatStringFromName("messageNoWindows",
|
|
|
|
[appName], 1);
|
2007-06-15 11:01:25 -07:00
|
|
|
else
|
2007-07-25 14:43:17 -07:00
|
|
|
message = quitBundle.formatStringFromName("message",
|
|
|
|
[appName], 1);
|
2007-06-15 11:01:25 -07:00
|
|
|
|
2007-06-16 14:23:17 -07:00
|
|
|
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
2007-06-15 11:01:25 -07:00
|
|
|
|
|
|
|
var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
|
|
|
|
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
|
|
|
|
promptService.BUTTON_POS_0_DEFAULT;
|
2007-11-29 12:46:08 -08:00
|
|
|
|
2007-06-15 11:01:25 -07:00
|
|
|
var neverAsk = {value:false};
|
2007-11-29 12:46:08 -08:00
|
|
|
var button0Title, button2Title;
|
|
|
|
var button1Title = quitBundle.GetStringFromName("cancelTitle");
|
|
|
|
var neverAskText = quitBundle.GetStringFromName("neverAsk");
|
|
|
|
|
|
|
|
if (aQuitType == "restart")
|
|
|
|
button0Title = quitBundle.GetStringFromName("restartTitle");
|
|
|
|
else {
|
2007-07-25 14:43:17 -07:00
|
|
|
flags += promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
|
2007-11-29 12:46:08 -08:00
|
|
|
button0Title = quitBundle.GetStringFromName("saveTitle");
|
|
|
|
button2Title = quitBundle.GetStringFromName("quitTitle");
|
|
|
|
}
|
|
|
|
|
2007-06-15 11:01:25 -07:00
|
|
|
buttonChoice = promptService.confirmEx(null, quitDialogTitle, message,
|
2007-11-29 12:46:08 -08:00
|
|
|
flags, button0Title, button1Title, button2Title,
|
2007-06-15 11:01:25 -07:00
|
|
|
neverAskText, neverAsk);
|
|
|
|
|
|
|
|
switch (buttonChoice) {
|
2007-11-29 12:46:08 -08:00
|
|
|
case 2:
|
2007-06-15 11:01:25 -07:00
|
|
|
if (neverAsk.value)
|
2007-06-16 14:23:17 -07:00
|
|
|
prefBranch.setBoolPref("browser.warnOnQuit", false);
|
2007-06-15 11:01:25 -07:00
|
|
|
break;
|
|
|
|
case 1:
|
2007-06-16 14:23:17 -07:00
|
|
|
aCancelQuit.QueryInterface(Ci.nsISupportsPRBool);
|
2007-06-15 11:01:25 -07:00
|
|
|
aCancelQuit.data = true;
|
|
|
|
break;
|
2007-11-29 12:46:08 -08:00
|
|
|
case 0:
|
|
|
|
this._saveSession = true;
|
2007-06-15 11:01:25 -07:00
|
|
|
// could also set browser.warnOnQuit to false here,
|
|
|
|
// but not setting it is a little safer.
|
|
|
|
if (neverAsk.value)
|
2007-06-16 14:23:17 -07:00
|
|
|
prefBranch.setIntPref("browser.startup.page", 3);
|
2007-06-15 11:01:25 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// returns the (cached) Sanitizer constructor
|
|
|
|
get Sanitizer()
|
|
|
|
{
|
|
|
|
if(typeof(Sanitizer) != "function") { // we should dynamically load the script
|
2007-06-16 14:23:17 -07:00
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
|
|
getService(Ci.mozIJSSubScriptLoader).
|
|
|
|
loadSubScript("chrome://browser/content/sanitize.js", null);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return Sanitizer;
|
|
|
|
},
|
2007-05-03 01:56:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize Places
|
2007-05-20 19:13:25 -07:00
|
|
|
* - imports the bookmarks html file if bookmarks datastore is empty
|
2007-05-03 01:56:41 -07:00
|
|
|
*/
|
|
|
|
_initPlaces: function bg__initPlaces() {
|
2007-05-16 23:47:41 -07:00
|
|
|
// we need to instantiate the history service before we check the
|
|
|
|
// the browser.places.importBookmarksHTML pref, as
|
|
|
|
// nsNavHistory::ForceMigrateBookmarksDB() will set that pref
|
|
|
|
// if we need to force a migration (due to a schema change)
|
2007-06-16 14:23:17 -07:00
|
|
|
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
2007-12-04 00:08:33 -08:00
|
|
|
|
2007-12-04 03:22:14 -08:00
|
|
|
var importBookmarks = false;
|
2007-05-03 01:56:41 -07:00
|
|
|
try {
|
2007-06-16 14:23:17 -07:00
|
|
|
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
importBookmarks = prefBranch.getBoolPref("browser.places.importBookmarksHTML");
|
2007-05-03 01:56:41 -07:00
|
|
|
} catch(ex) {}
|
2007-12-04 03:22:14 -08:00
|
|
|
|
2007-11-26 16:08:50 -08:00
|
|
|
if (!importBookmarks) {
|
|
|
|
// Call it here for Fx3 profiles created before the Places folder
|
|
|
|
// has been added, otherwise it's called during import.
|
|
|
|
this.ensurePlacesDefaultQueriesInitialized();
|
2007-05-03 01:56:41 -07:00
|
|
|
return;
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
2007-05-03 01:56:41 -07:00
|
|
|
|
2007-06-16 14:23:17 -07:00
|
|
|
var dirService = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
2007-05-03 01:56:41 -07:00
|
|
|
|
2007-06-16 14:23:17 -07:00
|
|
|
var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
|
2007-12-04 03:22:14 -08:00
|
|
|
|
2007-05-03 01:56:41 -07:00
|
|
|
if (bookmarksFile.exists()) {
|
2007-05-20 19:13:25 -07:00
|
|
|
// import the file
|
2007-05-03 01:56:41 -07:00
|
|
|
try {
|
|
|
|
var importer =
|
2007-06-16 14:23:17 -07:00
|
|
|
Cc["@mozilla.org/browser/places/import-export-service;1"].
|
|
|
|
getService(Ci.nsIPlacesImportExportService);
|
2007-05-16 23:06:48 -07:00
|
|
|
importer.importHTMLFromFile(bookmarksFile, true);
|
2007-05-03 01:56:41 -07:00
|
|
|
} catch(ex) {
|
|
|
|
} finally {
|
2007-06-16 14:23:17 -07:00
|
|
|
prefBranch.setBoolPref("browser.places.importBookmarksHTML", false);
|
2007-05-03 01:56:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-09 12:11:12 -08:00
|
|
|
// only back up pre-places bookmarks.html if we plan on overwriting it
|
2007-12-05 09:14:05 -08:00
|
|
|
if (prefBranch.getBoolPref("browser.bookmarks.overwrite")) {
|
2007-11-09 12:11:12 -08:00
|
|
|
// backup pre-places bookmarks.html
|
|
|
|
// XXXtodo remove this before betas, after import/export is solid
|
|
|
|
var profDir = dirService.get("ProfD", Ci.nsILocalFile);
|
|
|
|
var bookmarksBackup = profDir.clone();
|
|
|
|
bookmarksBackup.append("bookmarks.preplaces.html");
|
|
|
|
if (!bookmarksBackup.exists()) {
|
|
|
|
// save old bookmarks.html file as bookmarks.preplaces.html
|
|
|
|
try {
|
|
|
|
bookmarksFile.copyTo(profDir, "bookmarks.preplaces.html");
|
|
|
|
} catch(ex) {
|
|
|
|
dump("nsBrowserGlue::_initPlaces(): copy of bookmarks.html to bookmarks.preplaces.html failed: " + ex + "\n");
|
|
|
|
}
|
2007-05-03 01:56:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Places shut-down tasks
|
|
|
|
* - back up and archive bookmarks
|
|
|
|
*/
|
|
|
|
_shutdownPlaces: function bg__shutdownPlaces() {
|
|
|
|
// backup bookmarks to bookmarks.html
|
|
|
|
var importer =
|
2007-06-16 14:23:17 -07:00
|
|
|
Cc["@mozilla.org/browser/places/import-export-service;1"].
|
|
|
|
getService(Ci.nsIPlacesImportExportService);
|
2007-05-03 01:56:41 -07:00
|
|
|
importer.backupBookmarksFile();
|
|
|
|
},
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2008-02-04 11:37:26 -08:00
|
|
|
_migrateUI: function bg__migrateUI() {
|
|
|
|
var prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
|
|
|
|
|
|
|
var migration = 0;
|
|
|
|
try {
|
|
|
|
migration = prefBranch.getIntPref("browser.migration.version");
|
|
|
|
} catch(ex) {}
|
|
|
|
|
|
|
|
if (migration == 0) {
|
|
|
|
// this code should always migrate pre-FF3 profiles to the current UI state
|
|
|
|
|
|
|
|
// grab the localstore.rdf and make changes needed for new UI
|
|
|
|
this._rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
|
|
|
|
var localStore = this._rdf.GetDataSource("rdf:local-store");
|
|
|
|
|
|
|
|
// only move the home button if we find it on the nav-bar
|
|
|
|
var foundHome = false;
|
|
|
|
|
|
|
|
var currentSet = this._rdf.GetResource("currentset");
|
|
|
|
var target = null;
|
|
|
|
var dirty = false;
|
|
|
|
|
|
|
|
// get an nsIRDFResource for the nav-bar item
|
|
|
|
var navBar = this._rdf.GetResource("chrome://browser/content/browser.xul#nav-bar");
|
|
|
|
target = this._getPersist(localStore, navBar, currentSet);
|
|
|
|
if (target) {
|
|
|
|
foundHome = (target.indexOf("home-button") != -1);
|
|
|
|
if (foundHome)
|
|
|
|
target = target.replace("home-button", "");
|
|
|
|
target = "unified-back-forward-button," + target;
|
|
|
|
this._setPersist(localStore, navBar, currentSet, target);
|
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get an nsIRDFResource for the PersonalToolbar item
|
|
|
|
if (foundHome) {
|
|
|
|
var personalBar = this._rdf.GetResource("chrome://browser/content/browser.xul#PersonalToolbar");
|
|
|
|
target = this._getPersist(localStore, personalBar, currentSet);
|
|
|
|
if (target && target.indexOf("home-button") == -1) {
|
|
|
|
this._setPersist(localStore, personalBar, currentSet, "home-button," + target);
|
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// force the RDF to be saved
|
|
|
|
if (dirty)
|
|
|
|
localStore.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
|
|
|
|
|
|
|
|
// free up the RDF service
|
|
|
|
this._rdf = null;
|
|
|
|
|
|
|
|
// update the migration version
|
|
|
|
prefBranch.setIntPref("browser.migration.version", 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPersist: function bg__getPersist(aDataSource, aSource, aProperty) {
|
|
|
|
var target = aDataSource.GetTarget(aSource, aProperty, true);
|
|
|
|
if (target instanceof Ci.nsIRDFLiteral)
|
|
|
|
return target.Value;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setPersist: function bg__setPersist(aDataSource, aSource, aProperty, aTarget) {
|
|
|
|
try {
|
|
|
|
var oldTarget = aDataSource.GetTarget(aSource, aProperty, true);
|
|
|
|
if (oldTarget) {
|
|
|
|
if (aTarget)
|
|
|
|
aDataSource.Change(aSource, aProperty, oldTarget, this._rdf.GetLiteral(aTarget));
|
|
|
|
else
|
|
|
|
aDataSource.Unassert(aSource, aProperty, oldTarget);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aDataSource.Assert(aSource, aProperty, this._rdf.GetLiteral(aTarget), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// ------------------------------
|
|
|
|
// public nsIBrowserGlue members
|
|
|
|
// ------------------------------
|
|
|
|
|
|
|
|
sanitize: function(aParentWindow)
|
|
|
|
{
|
|
|
|
this.Sanitizer.sanitize(aParentWindow);
|
2007-09-05 20:02:22 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-26 16:08:50 -08:00
|
|
|
ensurePlacesDefaultQueriesInitialized: function() {
|
|
|
|
// bail out if the folder is already created
|
|
|
|
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
2007-12-04 00:31:07 -08:00
|
|
|
var createdSmartBookmarks = false;
|
2007-11-26 16:08:50 -08:00
|
|
|
try {
|
2007-12-04 00:31:07 -08:00
|
|
|
createdSmartBookmarks = prefBranch.getBoolPref("browser.places.createdSmartBookmarks");
|
2007-11-26 16:08:50 -08:00
|
|
|
} catch(ex) { }
|
|
|
|
|
2007-12-04 00:31:07 -08:00
|
|
|
if (createdSmartBookmarks)
|
2007-11-26 16:08:50 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
|
|
|
|
|
|
|
// XXXmano bug 405497: this should be batched even if we're not called from
|
|
|
|
// the import service. However, calling runInBatchedMode from within a
|
|
|
|
// RunBatched implementation hangs the browser.
|
|
|
|
var callback = {
|
|
|
|
_placesBundle: Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle("chrome://browser/locale/places/places.properties"),
|
|
|
|
|
|
|
|
_uri: function(aSpec) {
|
|
|
|
return Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService).
|
|
|
|
newURI(aSpec, null, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
runBatched: function() {
|
2007-12-04 00:31:07 -08:00
|
|
|
var smartBookmarksFolderTitle =
|
|
|
|
this._placesBundle.GetStringFromName("smartBookmarksFolderTitle");
|
|
|
|
var mostVisitedTitle =
|
|
|
|
this._placesBundle.GetStringFromName("mostVisitedTitle");
|
|
|
|
var recentlyBookmarkedTitle =
|
|
|
|
this._placesBundle.GetStringFromName("recentlyBookmarkedTitle");
|
|
|
|
var recentTagsTitle =
|
|
|
|
this._placesBundle.GetStringFromName("recentTagsTitle");
|
2007-11-26 16:08:50 -08:00
|
|
|
|
|
|
|
var bookmarksMenuFolder = bmsvc.bookmarksMenuFolder;
|
|
|
|
var unfiledBookmarksFolder = bmsvc.unfiledBookmarksFolder;
|
|
|
|
var toolbarFolder = bmsvc.toolbarFolder;
|
|
|
|
var tagsFolder = bmsvc.tagsFolder;
|
|
|
|
var defaultIndex = bmsvc.DEFAULT_INDEX;
|
|
|
|
|
|
|
|
// index = 0, make it the first folder
|
2007-12-04 00:31:07 -08:00
|
|
|
var placesFolder = bmsvc.createFolder(toolbarFolder, smartBookmarksFolderTitle,
|
2007-11-26 16:08:50 -08:00
|
|
|
0);
|
|
|
|
|
|
|
|
// XXX should this be a pref? see bug #399268
|
|
|
|
var maxResults = 10;
|
|
|
|
|
2007-12-04 00:31:07 -08:00
|
|
|
var mostVisitedItem = bmsvc.insertBookmark(placesFolder,
|
|
|
|
this._uri("place:queryType=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
|
|
|
"&maxResults=" + maxResults),
|
|
|
|
defaultIndex, mostVisitedTitle);
|
|
|
|
|
|
|
|
// excludeQueries=1 so that user created "saved searches"
|
2007-11-26 16:08:50 -08:00
|
|
|
// and these queries (added automatically) are excluded
|
2007-12-04 00:31:07 -08:00
|
|
|
var recentlyBookmarkedItem = bmsvc.insertBookmark(placesFolder,
|
2007-11-26 16:08:50 -08:00
|
|
|
this._uri("place:folder=" + bookmarksMenuFolder +
|
|
|
|
"&folder=" + unfiledBookmarksFolder +
|
|
|
|
"&folder=" + toolbarFolder +
|
|
|
|
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
|
|
|
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
|
|
|
"&maxResults=" + maxResults +
|
|
|
|
"&excludeQueries=1"),
|
2007-12-04 00:31:07 -08:00
|
|
|
defaultIndex, recentlyBookmarkedTitle);
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2007-12-04 00:31:07 -08:00
|
|
|
var sep = bmsvc.insertSeparator(placesFolder, defaultIndex);
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2007-12-04 00:31:07 -08:00
|
|
|
var recentTagsItem = bmsvc.insertBookmark(placesFolder,
|
2007-11-26 16:08:50 -08:00
|
|
|
this._uri("place:folder=" + tagsFolder +
|
|
|
|
"&group=" + Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER +
|
|
|
|
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
|
|
|
"&applyOptionsToContainers=1" +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
|
|
|
"&maxResults=" + maxResults),
|
2007-12-04 00:31:07 -08:00
|
|
|
defaultIndex, recentTagsTitle);
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
callback.runBatched();
|
|
|
|
// See XXX note above
|
|
|
|
// bmsvc.runInBatchMode(callback, null);
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
|
|
|
finally {
|
2007-12-04 00:31:07 -08:00
|
|
|
prefBranch.setBoolPref("browser.places.createdSmartBookmarks", true);
|
2008-01-23 13:15:16 -08:00
|
|
|
prefBranch.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
// for XPCOM
|
|
|
|
classDescription: "Firefox Browser Glue Service",
|
|
|
|
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),
|
|
|
|
contractID: "@mozilla.org/browser/browserglue;1",
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-27 12:37:47 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIBrowserGlue]),
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
// redefine the default factory for XPCOMUtils
|
|
|
|
_xpcom_factory: BrowserGlueServiceFactory,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
// get this contractID registered for certain categories via XPCOMUtils
|
|
|
|
_xpcom_categories: [
|
|
|
|
// make BrowserGlue a startup observer
|
|
|
|
{ category: "app-startup", service: true }
|
|
|
|
]
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
//module initialization
|
|
|
|
function NSGetModule(aCompMgr, aFileSpec) {
|
|
|
|
return XPCOMUtils.generateModule([BrowserGlue]);
|
|
|
|
}
|