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>
|
2008-11-12 12:45:53 -08:00
|
|
|
# Marco Bonardo <mak77@bonardo.net>
|
2008-12-30 04:44:55 -08:00
|
|
|
# Dietrich Ayala <dietrich@mozilla.com>
|
2009-02-17 11:56:16 -08:00
|
|
|
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2009-07-30 21:57:57 -07:00
|
|
|
# Nils Maier <maierman@web.de>
|
2010-04-06 19:49:23 -07:00
|
|
|
# Robert Strong <robert.bugzilla@gmail.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;
|
|
|
|
|
2009-04-15 14:49:11 -07:00
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2007-09-11 08:52:04 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2007-09-05 20:02:22 -07:00
|
|
|
|
2008-03-07 16:16:38 -08:00
|
|
|
const PREF_EM_NEW_ADDONS_LIST = "extensions.newAddons";
|
2009-10-02 04:26:04 -07:00
|
|
|
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
|
|
|
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
2008-03-07 16:16:38 -08:00
|
|
|
|
2009-09-29 03:44:18 -07:00
|
|
|
// We try to backup bookmarks at idle times, to avoid doing that at shutdown.
|
|
|
|
// Number of idle seconds before trying to backup bookmarks. 15 minutes.
|
|
|
|
const BOOKMARKS_BACKUP_IDLE_TIME = 15 * 60;
|
|
|
|
// Minimum interval in milliseconds between backups.
|
|
|
|
const BOOKMARKS_BACKUP_INTERVAL = 86400 * 1000;
|
|
|
|
// Maximum number of backups to create. Old ones will be purged.
|
|
|
|
const BOOKMARKS_BACKUP_MAX_BACKUPS = 10;
|
2008-03-13 12:25:49 -07:00
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
// Factory object
|
|
|
|
const BrowserGlueServiceFactory = {
|
|
|
|
_instance: null,
|
2009-12-17 13:28:08 -08:00
|
|
|
createInstance: function BGSF_createInstance(outer, iid) {
|
2007-09-05 20:02:22 -07:00
|
|
|
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() {
|
2009-09-29 03:44:18 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_prefs",
|
|
|
|
"@mozilla.org/preferences-service;1",
|
|
|
|
"nsIPrefBranch");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_bundleService",
|
|
|
|
"@mozilla.org/intl/stringbundle;1",
|
|
|
|
"nsIStringBundleService");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_idleService",
|
|
|
|
"@mozilla.org/widget/idleservice;1",
|
|
|
|
"nsIIdleService");
|
|
|
|
|
2009-10-05 03:13:04 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_distributionCustomizer", function() {
|
2010-01-21 15:49:11 -08:00
|
|
|
Cu.import("resource:///modules/distribution.js");
|
2009-10-05 03:13:04 -07:00
|
|
|
return new DistributionCustomizer();
|
|
|
|
});
|
|
|
|
|
2009-10-14 02:53:13 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_sanitizer",
|
|
|
|
function() {
|
|
|
|
let sanitizerScope = {};
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
|
|
getService(Ci.mozIJSSubScriptLoader).
|
|
|
|
loadSubScript("chrome://browser/content/sanitize.js", sanitizerScope);
|
|
|
|
return sanitizerScope.Sanitizer;
|
|
|
|
});
|
|
|
|
|
|
|
|
// The observer service is immediately used in _init(), so there's no reason
|
|
|
|
// to have a getter.
|
|
|
|
this._observerService = Cc["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Ci.nsIObserverService);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2009-07-30 21:57:57 -07:00
|
|
|
#ifndef XP_MACOSX
|
|
|
|
# OS X has the concept of zero-window sessions and therefore ignores the
|
|
|
|
# browser-lastwindow-close-* topics.
|
|
|
|
#define OBSERVE_LASTWINDOW_CLOSE_TOPICS 1
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
BrowserGlue.prototype = {
|
2007-06-15 11:01:25 -07:00
|
|
|
_saveSession: false,
|
2009-09-29 03:44:18 -07:00
|
|
|
_isIdleObserver: false,
|
|
|
|
_isPlacesInitObserver: false,
|
|
|
|
_isPlacesLockedObserver: false,
|
|
|
|
_isPlacesDatabaseLocked: false,
|
2007-06-15 11:01:25 -07:00
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_setPrefToSaveSession: function BG__setPrefToSaveSession(aForce) {
|
2009-10-14 02:53:13 -07:00
|
|
|
if (!this._saveSession && !aForce)
|
|
|
|
return;
|
|
|
|
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
|
2009-06-11 13:17:33 -07:00
|
|
|
|
|
|
|
// This method can be called via [NSApplication terminate:] on Mac, which
|
|
|
|
// ends up causing prefs not to be flushed to disk, so we need to do that
|
|
|
|
// explicitly here. See bug 497652.
|
|
|
|
this._prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
|
2008-02-07 01:28:43 -08:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIObserver implementation
|
2009-12-17 13:28:08 -08:00
|
|
|
observe: function BG_observe(subject, topic, data) {
|
2010-02-06 02:40:06 -08:00
|
|
|
switch (topic) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case "xpcom-shutdown":
|
|
|
|
this._dispose();
|
|
|
|
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;
|
2008-03-07 16:16:38 -08:00
|
|
|
case "sessionstore-windows-restored":
|
|
|
|
this._onBrowserStartup();
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
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":
|
2009-10-14 02:53:13 -07:00
|
|
|
// This pref must be set here because SessionStore will use its value
|
|
|
|
// on quit-application.
|
|
|
|
this._setPrefToSaveSession();
|
2009-01-06 12:41:08 -08:00
|
|
|
this._onProfileShutdown();
|
2007-06-15 11:01:25 -07:00
|
|
|
break;
|
2009-07-30 21:57:57 -07:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
|
|
|
case "browser-lastwindow-close-requested":
|
|
|
|
// The application is not actually quitting, but the last full browser
|
|
|
|
// window is about to be closed.
|
|
|
|
this._onQuitRequest(subject, "lastwindow");
|
|
|
|
break;
|
|
|
|
case "browser-lastwindow-close-granted":
|
2009-10-14 02:53:13 -07:00
|
|
|
this._setPrefToSaveSession();
|
2009-07-30 21:57:57 -07:00
|
|
|
break;
|
|
|
|
#endif
|
2008-02-07 01:28:43 -08:00
|
|
|
case "session-save":
|
2009-10-14 02:53:13 -07:00
|
|
|
this._setPrefToSaveSession(true);
|
2008-02-07 01:28:43 -08:00
|
|
|
subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
subject.data = true;
|
|
|
|
break;
|
2008-11-12 12:45:53 -08:00
|
|
|
case "places-init-complete":
|
|
|
|
this._initPlaces();
|
2008-12-30 04:44:55 -08:00
|
|
|
this._observerService.removeObserver(this, "places-init-complete");
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesInitObserver = false;
|
2008-12-30 04:44:55 -08:00
|
|
|
// no longer needed, since history was initialized completely.
|
|
|
|
this._observerService.removeObserver(this, "places-database-locked");
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesLockedObserver = false;
|
2009-10-05 03:13:04 -07:00
|
|
|
|
|
|
|
// Now apply distribution customized bookmarks.
|
|
|
|
// This should always run after Places initialization.
|
|
|
|
this._distributionCustomizer.applyBookmarks();
|
2008-12-30 04:44:55 -08:00
|
|
|
break;
|
|
|
|
case "places-database-locked":
|
|
|
|
this._isPlacesDatabaseLocked = true;
|
2009-10-14 02:53:13 -07:00
|
|
|
// Stop observing, so further attempts to load history service
|
|
|
|
// will not show the prompt.
|
2008-12-30 04:44:55 -08:00
|
|
|
this._observerService.removeObserver(this, "places-database-locked");
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesLockedObserver = false;
|
2008-11-12 12:45:53 -08:00
|
|
|
break;
|
2008-03-13 12:25:49 -07:00
|
|
|
case "idle":
|
2009-09-29 03:44:18 -07:00
|
|
|
if (this._idleService.idleTime > BOOKMARKS_BACKUP_IDLE_TIME * 1000)
|
|
|
|
this._backupBookmarks();
|
2008-03-13 12:25:49 -07:00
|
|
|
break;
|
2009-10-05 03:13:04 -07:00
|
|
|
case "distribution-customization-complete":
|
2009-10-05 07:43:10 -07:00
|
|
|
this._observerService
|
|
|
|
.removeObserver(this, "distribution-customization-complete");
|
2009-10-05 03:13:04 -07:00
|
|
|
// Customization has finished, we don't need the customizer anymore.
|
|
|
|
delete this._distributionCustomizer;
|
|
|
|
break;
|
2010-03-23 18:17:49 -07:00
|
|
|
case "bookmarks-restore-success":
|
|
|
|
case "bookmarks-restore-failed":
|
|
|
|
this._observerService.removeObserver(this, "bookmarks-restore-success");
|
|
|
|
this._observerService.removeObserver(this, "bookmarks-restore-failed");
|
|
|
|
if (topic == "bookmarks-restore-success" && data == "html-initial")
|
|
|
|
this.ensurePlacesDefaultQueriesInitialized();
|
|
|
|
break;
|
2010-04-06 19:49:23 -07:00
|
|
|
case "browser-glue-test": // used by tests
|
|
|
|
if (data == "post-update-notification") {
|
|
|
|
if (this._prefs.prefHasUserValue("app.update.postupdate"))
|
|
|
|
this._showUpdateNotification();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-03-13 12:25:49 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// initialization (called on application startup)
|
2009-12-17 13:28:08 -08:00
|
|
|
_init: function BG__init() {
|
2007-03-22 10:30:00 -07:00
|
|
|
// observer registration
|
2008-12-30 04:44:55 -08:00
|
|
|
const osvr = this._observerService;
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
2008-03-07 16:16:38 -08:00
|
|
|
osvr.addObserver(this, "sessionstore-windows-restored", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
2009-07-30 21:57:57 -07:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
|
|
|
osvr.addObserver(this, "browser-lastwindow-close-requested", false);
|
|
|
|
osvr.addObserver(this, "browser-lastwindow-close-granted", false);
|
|
|
|
#endif
|
2008-02-07 01:28:43 -08:00
|
|
|
osvr.addObserver(this, "session-save", false);
|
2008-11-12 12:45:53 -08:00
|
|
|
osvr.addObserver(this, "places-init-complete", false);
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesInitObserver = true;
|
2008-12-30 04:44:55 -08:00
|
|
|
osvr.addObserver(this, "places-database-locked", false);
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesLockedObserver = true;
|
2009-10-05 03:13:04 -07:00
|
|
|
osvr.addObserver(this, "distribution-customization-complete", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// cleanup (called on application shutdown)
|
2009-12-17 13:28:08 -08:00
|
|
|
_dispose: function BG__dispose() {
|
2007-03-22 10:30:00 -07:00
|
|
|
// observer removal
|
2008-12-30 04:44:55 -08:00
|
|
|
const osvr = this._observerService;
|
2007-03-22 10:30:00 -07:00
|
|
|
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");
|
2008-03-07 16:16:38 -08:00
|
|
|
osvr.removeObserver(this, "sessionstore-windows-restored");
|
2007-03-22 10:30:00 -07:00
|
|
|
osvr.removeObserver(this, "browser:purge-session-history");
|
2007-06-15 11:01:25 -07:00
|
|
|
osvr.removeObserver(this, "quit-application-requested");
|
2009-09-29 03:44:18 -07:00
|
|
|
osvr.removeObserver(this, "quit-application-granted");
|
2009-07-30 21:57:57 -07:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
|
|
|
osvr.removeObserver(this, "browser-lastwindow-close-requested");
|
|
|
|
osvr.removeObserver(this, "browser-lastwindow-close-granted");
|
|
|
|
#endif
|
2008-02-07 01:28:43 -08:00
|
|
|
osvr.removeObserver(this, "session-save");
|
2009-09-29 03:44:18 -07:00
|
|
|
if (this._isIdleObserver)
|
|
|
|
this._idleService.removeIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
|
|
|
|
if (this._isPlacesInitObserver)
|
|
|
|
osvr.removeObserver(this, "places-init-complete");
|
|
|
|
if (this._isPlacesLockedObserver)
|
|
|
|
osvr.removeObserver(this, "places-database-locked");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_onAppDefaults: function BG__onAppDefaults() {
|
2007-09-11 08:52:04 -07:00
|
|
|
// apply distribution customizations (prefs)
|
|
|
|
// other customizations are applied in _onProfileStartup()
|
2009-10-05 03:13:04 -07:00
|
|
|
this._distributionCustomizer.applyPrefDefaults();
|
2007-09-11 08:52:04 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// profile startup handler (contains profile initialization routines)
|
2009-12-17 13:28:08 -08:00
|
|
|
_onProfileStartup: function BG__onProfileStartup() {
|
2009-10-14 02:53:13 -07:00
|
|
|
this._sanitizer.onStartup();
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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
|
|
|
|
2007-09-11 08:52:04 -07:00
|
|
|
// apply distribution customizations
|
|
|
|
// prefs are applied in _onAppDefaults()
|
2009-10-05 03:13:04 -07:00
|
|
|
this._distributionCustomizer.applyCustomizations();
|
2007-09-11 08:52:04 -07:00
|
|
|
|
2008-02-04 11:37:26 -08:00
|
|
|
// handle any UI migration
|
2008-03-20 11:57:05 -07:00
|
|
|
this._migrateUI();
|
2008-09-30 22:36:21 -07:00
|
|
|
|
2009-08-18 08:39:37 -07:00
|
|
|
var ioService = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService2);
|
|
|
|
|
|
|
|
// if ioService is managing the offline status, then ioservice.offline
|
|
|
|
// is already set correctly. We will continue to allow the ioService
|
|
|
|
// to manage its offline state until the user uses the "Work Offline" UI.
|
|
|
|
if (!ioService.manageOfflineStatus) {
|
|
|
|
// set the initial state
|
|
|
|
try {
|
|
|
|
ioService.offline = this._prefs.getBoolPref("browser.offline");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ioService.offline = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 02:53:13 -07:00
|
|
|
this._observerService
|
|
|
|
.notifyObservers(null, "browser-ui-startup-complete", "");
|
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)
|
2009-12-17 13:28:08 -08:00
|
|
|
_onProfileShutdown: function BG__onProfileShutdown() {
|
2009-12-14 22:28:40 -08:00
|
|
|
#ifdef WINCE
|
|
|
|
// If there's a pending update, clear cache to free up disk space.
|
|
|
|
try {
|
|
|
|
let um = Cc["@mozilla.org/updates/update-manager;1"].
|
|
|
|
getService(Ci.nsIUpdateManager);
|
|
|
|
if (um.activeUpdate && um.activeUpdate.state == "pending") {
|
|
|
|
let cacheService = Cc["@mozilla.org/network/cache-service;1"].
|
|
|
|
getService(Ci.nsICacheService);
|
|
|
|
cacheService.evictEntries(Ci.nsICache.STORE_ANYWHERE);
|
|
|
|
}
|
|
|
|
} catch (e) { }
|
|
|
|
#endif
|
2008-02-22 12:42:24 -08:00
|
|
|
this._shutdownPlaces();
|
2009-09-29 03:44:18 -07:00
|
|
|
this._idleService.removeIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
|
|
|
|
this._isIdleObserver = false;
|
2009-10-14 02:53:13 -07:00
|
|
|
this._sanitizer.onShutdown();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 16:16:38 -08:00
|
|
|
// Browser startup complete. All initial windows have opened.
|
2009-12-17 13:28:08 -08:00
|
|
|
_onBrowserStartup: function BG__onBrowserStartup() {
|
2008-10-30 23:42:02 -07:00
|
|
|
// Show about:rights notification, if needed.
|
|
|
|
if (this._shouldShowRights())
|
|
|
|
this._showRightsNotification();
|
|
|
|
|
2010-04-06 19:49:23 -07:00
|
|
|
// Show update notification, if needed.
|
|
|
|
if (this._prefs.prefHasUserValue("app.update.postupdate"))
|
|
|
|
this._showUpdateNotification();
|
|
|
|
|
2008-03-07 16:16:38 -08:00
|
|
|
// If new add-ons were installed during startup open the add-ons manager.
|
2008-10-17 19:02:07 -07:00
|
|
|
if (this._prefs.prefHasUserValue(PREF_EM_NEW_ADDONS_LIST)) {
|
2008-03-07 16:16:38 -08:00
|
|
|
var args = Cc["@mozilla.org/supports-array;1"].
|
|
|
|
createInstance(Ci.nsISupportsArray);
|
|
|
|
var str = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
str.data = "";
|
|
|
|
args.AppendElement(str);
|
|
|
|
var str = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
2008-10-17 19:02:07 -07:00
|
|
|
str.data = this._prefs.getCharPref(PREF_EM_NEW_ADDONS_LIST);
|
2008-03-07 16:16:38 -08:00
|
|
|
args.AppendElement(str);
|
|
|
|
const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
|
|
|
|
const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable";
|
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
|
|
|
ww.openWindow(null, EMURL, "_blank", EMFEATURES, args);
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.clearUserPref(PREF_EM_NEW_ADDONS_LIST);
|
2008-03-07 16:16:38 -08:00
|
|
|
}
|
2008-12-30 04:44:55 -08:00
|
|
|
|
|
|
|
// Load the "more info" page for a locked places.sqlite
|
|
|
|
// This property is set earlier in the startup process:
|
|
|
|
// nsPlacesDBFlush loads after profile-after-change and initializes
|
|
|
|
// the history service, which sends out places-database-locked
|
|
|
|
// which sets this property.
|
|
|
|
if (this._isPlacesDatabaseLocked) {
|
|
|
|
this._showPlacesLockedNotificationBox();
|
|
|
|
}
|
2009-10-02 04:26:04 -07:00
|
|
|
|
|
|
|
// If there are plugins installed that are outdated, and the user hasn't
|
|
|
|
// been warned about them yet, open the plugins update page.
|
|
|
|
if (this._prefs.getBoolPref(PREF_PLUGINS_NOTIFYUSER))
|
|
|
|
this._showPluginUpdatePage();
|
2009-10-07 02:09:11 -07:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#ifndef WINCE
|
|
|
|
// For windows seven, initialize the jump list module.
|
2009-10-08 13:08:35 -07:00
|
|
|
const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
|
|
|
|
if (WINTASKBAR_CONTRACTID in Cc &&
|
|
|
|
Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available) {
|
|
|
|
let temp = {};
|
|
|
|
Cu.import("resource://gre/modules/WindowsJumpLists.jsm", temp);
|
|
|
|
temp.WinTaskbarJumpList.startup();
|
|
|
|
}
|
2009-10-07 02:09:11 -07:00
|
|
|
#endif
|
|
|
|
#endif
|
2008-03-07 16:16:38 -08:00
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {
|
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);
|
2008-05-10 08:52:32 -07:00
|
|
|
|
2007-06-15 11:01:25 -07:00
|
|
|
var windowcount = 0;
|
2008-05-10 08:52:32 -07:00
|
|
|
var pagecount = 0;
|
2007-06-15 11:01:25 -07:00
|
|
|
var browserEnum = wm.getEnumerator("navigator:browser");
|
2008-05-10 08:52:32 -07:00
|
|
|
while (browserEnum.hasMoreElements()) {
|
|
|
|
windowcount++;
|
|
|
|
|
|
|
|
var browser = browserEnum.getNext();
|
|
|
|
var tabbrowser = browser.document.getElementById("content");
|
|
|
|
if (tabbrowser)
|
|
|
|
pagecount += tabbrowser.browsers.length;
|
|
|
|
}
|
2007-06-15 11:01:25 -07:00
|
|
|
|
|
|
|
this._saveSession = false;
|
2008-05-10 08:52:32 -07:00
|
|
|
if (pagecount < 2)
|
|
|
|
return;
|
2007-06-15 11:01:25 -07:00
|
|
|
|
2007-07-25 14:43:17 -07:00
|
|
|
if (aQuitType != "restart")
|
|
|
|
aQuitType = "quit";
|
|
|
|
|
2007-06-15 11:01:25 -07:00
|
|
|
var showPrompt = true;
|
|
|
|
try {
|
2008-04-10 10:27:20 -07:00
|
|
|
// browser.warnOnQuit is a hidden global boolean to override all quit prompts
|
|
|
|
// browser.warnOnRestart specifically covers app-initiated restarts where we restart the app
|
|
|
|
// browser.tabs.warnOnClose is the global "warn when closing multiple tabs" pref
|
2008-05-08 08:08:40 -07:00
|
|
|
|
2008-10-17 19:02:07 -07:00
|
|
|
var sessionWillBeSaved = this._prefs.getIntPref("browser.startup.page") == 3 ||
|
|
|
|
this._prefs.getBoolPref("browser.sessionstore.resume_session_once");
|
|
|
|
if (sessionWillBeSaved || !this._prefs.getBoolPref("browser.warnOnQuit"))
|
2007-06-15 11:01:25 -07:00
|
|
|
showPrompt = false;
|
2008-04-10 10:27:20 -07:00
|
|
|
else if (aQuitType == "restart")
|
2008-10-17 19:02:07 -07:00
|
|
|
showPrompt = this._prefs.getBoolPref("browser.warnOnRestart");
|
2007-06-15 11:01:25 -07:00
|
|
|
else
|
2008-10-17 19:02:07 -07:00
|
|
|
showPrompt = this._prefs.getBoolPref("browser.tabs.warnOnClose");
|
2007-06-15 11:01:25 -07:00
|
|
|
} catch (ex) {}
|
|
|
|
|
2009-02-17 11:56:16 -08:00
|
|
|
// Never show a prompt inside the private browsing mode
|
|
|
|
var inPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService).
|
|
|
|
privateBrowsingEnabled;
|
|
|
|
if (!showPrompt || inPrivateBrowsing)
|
2008-05-08 08:08:40 -07:00
|
|
|
return false;
|
2007-11-29 12:46:08 -08:00
|
|
|
|
2008-12-30 04:44:55 -08:00
|
|
|
var quitBundle = this._bundleService.createBundle("chrome://browser/locale/quitDialog.properties");
|
|
|
|
var brandBundle = this._bundleService.createBundle("chrome://branding/locale/brand.properties");
|
2008-05-08 08:08:40 -07:00
|
|
|
|
|
|
|
var appName = brandBundle.GetStringFromName("brandShortName");
|
|
|
|
var quitDialogTitle = quitBundle.formatStringFromName(aQuitType + "DialogTitle",
|
2008-12-30 04:44:55 -08:00
|
|
|
[appName], 1);
|
2008-05-08 08:08:40 -07:00
|
|
|
|
|
|
|
var message;
|
|
|
|
if (aQuitType == "restart")
|
|
|
|
message = quitBundle.formatStringFromName("messageRestart",
|
|
|
|
[appName], 1);
|
|
|
|
else if (windowcount == 1)
|
|
|
|
message = quitBundle.formatStringFromName("messageNoWindows",
|
|
|
|
[appName], 1);
|
|
|
|
else
|
|
|
|
message = quitBundle.formatStringFromName("message",
|
|
|
|
[appName], 1);
|
|
|
|
|
|
|
|
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
var neverAsk = {value:false};
|
|
|
|
var button0Title, button2Title;
|
|
|
|
var button1Title = quitBundle.GetStringFromName("cancelTitle");
|
|
|
|
var neverAskText = quitBundle.GetStringFromName("neverAsk");
|
|
|
|
|
|
|
|
if (aQuitType == "restart")
|
|
|
|
button0Title = quitBundle.GetStringFromName("restartTitle");
|
|
|
|
else {
|
|
|
|
flags += promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
|
|
|
|
button0Title = quitBundle.GetStringFromName("saveTitle");
|
|
|
|
button2Title = quitBundle.GetStringFromName("quitTitle");
|
|
|
|
}
|
2007-06-15 11:01:25 -07:00
|
|
|
|
2009-07-30 21:57:57 -07:00
|
|
|
var mostRecentBrowserWindow = wm.getMostRecentWindow("navigator:browser");
|
|
|
|
var buttonChoice =
|
|
|
|
promptService.confirmEx(mostRecentBrowserWindow, quitDialogTitle, message,
|
|
|
|
flags, button0Title, button1Title, button2Title,
|
|
|
|
neverAskText, neverAsk);
|
2008-05-08 08:08:40 -07:00
|
|
|
|
|
|
|
switch (buttonChoice) {
|
|
|
|
case 2: // Quit
|
|
|
|
if (neverAsk.value)
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.setBoolPref("browser.tabs.warnOnClose", false);
|
2008-05-08 08:08:40 -07:00
|
|
|
break;
|
|
|
|
case 1: // Cancel
|
|
|
|
aCancelQuit.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
aCancelQuit.data = true;
|
|
|
|
break;
|
|
|
|
case 0: // Save & Quit
|
|
|
|
this._saveSession = true;
|
|
|
|
if (neverAsk.value) {
|
|
|
|
if (aQuitType == "restart")
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.setBoolPref("browser.warnOnRestart", false);
|
2008-05-08 08:08:40 -07:00
|
|
|
else {
|
|
|
|
// always save state when shutting down
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.setIntPref("browser.startup.page", 3);
|
2008-02-23 01:32:09 -08:00
|
|
|
}
|
2007-06-15 11:01:25 -07:00
|
|
|
}
|
2008-05-08 08:08:40 -07:00
|
|
|
break;
|
2007-06-15 11:01:25 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-10-30 23:42:02 -07:00
|
|
|
/*
|
|
|
|
* _shouldShowRights - Determines if the user should be shown the
|
|
|
|
* about:rights notification. The notification should *not* be shown if
|
|
|
|
* we've already shown the current version, or if the override pref says to
|
|
|
|
* never show it. The notification *should* be shown if it's never been seen
|
|
|
|
* before, if a newer version is available, or if the override pref says to
|
|
|
|
* always show it.
|
|
|
|
*/
|
2009-12-17 13:28:08 -08:00
|
|
|
_shouldShowRights: function BG__shouldShowRights() {
|
2008-10-30 23:42:02 -07:00
|
|
|
// Look for an unconditional override pref. If set, do what it says.
|
|
|
|
// (true --> never show, false --> always show)
|
|
|
|
try {
|
|
|
|
return !this._prefs.getBoolPref("browser.rights.override");
|
|
|
|
} catch (e) { }
|
|
|
|
// Ditto, for the legacy EULA pref.
|
|
|
|
try {
|
|
|
|
return !this._prefs.getBoolPref("browser.EULA.override");
|
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
#ifndef OFFICIAL_BUILD
|
|
|
|
// Non-official builds shouldn't shouldn't show the notification.
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Look to see if the user has seen the current version or not.
|
|
|
|
var currentVersion = this._prefs.getIntPref("browser.rights.version");
|
|
|
|
try {
|
|
|
|
return !this._prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
|
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
// Legacy: If the user accepted a EULA, we won't annoy them with the
|
|
|
|
// equivalent about:rights page until the version changes.
|
|
|
|
try {
|
|
|
|
return !this._prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
|
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
// We haven't shown the notification before, so do so now.
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_showRightsNotification: function BG__showRightsNotification() {
|
2008-10-30 23:42:02 -07:00
|
|
|
// Stick the notification onto the selected tab of the active browser window.
|
|
|
|
var win = this.getMostRecentBrowserWindow();
|
|
|
|
var browser = win.gBrowser; // for closure in notification bar callback
|
|
|
|
var notifyBox = browser.getNotificationBox();
|
|
|
|
|
2008-12-30 04:44:55 -08:00
|
|
|
var brandBundle = this._bundleService.createBundle("chrome://branding/locale/brand.properties");
|
2009-09-04 05:27:14 -07:00
|
|
|
var rightsBundle = this._bundleService.createBundle("chrome://global/locale/aboutRights.properties");
|
2008-10-30 23:42:02 -07:00
|
|
|
|
2009-02-25 11:54:14 -08:00
|
|
|
var buttonLabel = rightsBundle.GetStringFromName("buttonLabel");
|
|
|
|
var buttonAccessKey = rightsBundle.GetStringFromName("buttonAccessKey");
|
|
|
|
var productName = brandBundle.GetStringFromName("brandFullName");
|
|
|
|
var notifyRightsText = rightsBundle.formatStringFromName("notifyRightsText", [productName], 1);
|
2008-10-30 23:42:02 -07:00
|
|
|
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: buttonLabel,
|
|
|
|
accessKey: buttonAccessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
|
|
|
browser.selectedTab = browser.addTab("about:rights");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2008-11-12 12:45:53 -08:00
|
|
|
// Set pref to indicate we've shown the notification.
|
2008-10-30 23:42:02 -07:00
|
|
|
var currentVersion = this._prefs.getIntPref("browser.rights.version");
|
|
|
|
this._prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
|
|
|
|
|
2009-02-25 11:54:14 -08:00
|
|
|
var box = notifyBox.appendNotification(notifyRightsText, "about-rights", null, notifyBox.PRIORITY_INFO_LOW, buttons);
|
2008-11-18 23:09:33 -08:00
|
|
|
box.persistence = 3; // arbitrary number, just so bar sticks around for a bit
|
2008-10-30 23:42:02 -07:00
|
|
|
},
|
2010-04-06 19:49:23 -07:00
|
|
|
|
|
|
|
_showUpdateNotification: function BG__showUpdateNotification() {
|
|
|
|
this._prefs.clearUserPref("app.update.postupdate");
|
|
|
|
|
|
|
|
var um = Cc["@mozilla.org/updates/update-manager;1"].
|
|
|
|
getService(Ci.nsIUpdateManager);
|
|
|
|
try {
|
|
|
|
// If the updates.xml file is deleted then getUpdateAt will throw.
|
|
|
|
var update = um.getUpdateAt(0).QueryInterface(Ci.nsIPropertyBag);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// This should never happen.
|
|
|
|
Cu.reportError("Unable to find update: " + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var actions = update.getProperty("actions");
|
|
|
|
if (!actions || actions.indexOf("silent") != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
|
|
|
|
getService(Ci.nsIURLFormatter);
|
|
|
|
var browserBundle = this._bundleService.
|
|
|
|
createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
var brandBundle = this._bundleService.
|
|
|
|
createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
var appName = brandBundle.GetStringFromName("brandShortName");
|
|
|
|
|
|
|
|
function getNotifyString(aPropData) {
|
|
|
|
var propValue = update.getProperty(aPropData.propName);
|
|
|
|
if (!propValue) {
|
|
|
|
if (aPropData.prefName)
|
|
|
|
propValue = formatter.formatURLPref(aPropData.prefName);
|
|
|
|
else if (aPropData.stringParams)
|
|
|
|
propValue = browserBundle.formatStringFromName(aPropData.stringName,
|
|
|
|
aPropData.stringParams,
|
|
|
|
aPropData.stringParams.length);
|
|
|
|
else
|
|
|
|
propValue = browserBundle.GetStringFromName(aPropData.stringName);
|
|
|
|
}
|
|
|
|
return propValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actions.indexOf("showNotification") != -1) {
|
|
|
|
let text = getNotifyString({propName: "notificationText",
|
|
|
|
stringName: "puNotifyText",
|
|
|
|
stringParams: [appName]});
|
|
|
|
let url = getNotifyString({propName: "notificationURL",
|
|
|
|
prefName: "startup.homepage_override_url"});
|
|
|
|
let label = getNotifyString({propName: "notificationButtonLabel",
|
|
|
|
stringName: "pu.notifyButton.label"});
|
|
|
|
let key = getNotifyString({propName: "notificationButtonAccessKey",
|
|
|
|
stringName: "pu.notifyButton.accesskey"});
|
|
|
|
|
|
|
|
let win = this.getMostRecentBrowserWindow();
|
|
|
|
let browser = win.gBrowser; // for closure in notification bar callback
|
|
|
|
let notifyBox = browser.getNotificationBox();
|
|
|
|
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: label,
|
|
|
|
accessKey: key,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
|
|
|
browser.selectedTab = browser.addTab(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
let box = notifyBox.appendNotification(text, "post-update-notification",
|
|
|
|
null, notifyBox.PRIORITY_INFO_LOW,
|
|
|
|
buttons);
|
|
|
|
box.persistence = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actions.indexOf("showAlert") == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let notifier;
|
|
|
|
try {
|
|
|
|
notifier = Cc["@mozilla.org/alerts-service;1"].
|
|
|
|
getService(Ci.nsIAlertsService);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// nsIAlertsService is not available for this platform
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = getNotifyString({propName: "alertTitle",
|
|
|
|
stringName: "puAlertTitle",
|
|
|
|
stringParams: [appName]});
|
|
|
|
let text = getNotifyString({propName: "alertText",
|
|
|
|
stringName: "puAlertText",
|
|
|
|
stringParams: [appName]});
|
|
|
|
let url = getNotifyString({propName: "alertURL",
|
|
|
|
prefName: "startup.homepage_override_url"});
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
function clickCallback(subject, topic, data) {
|
|
|
|
// This callback will be called twice but only once with this topic
|
|
|
|
if (topic != "alertclickcallback")
|
|
|
|
return;
|
|
|
|
let win = self.getMostRecentBrowserWindow();
|
|
|
|
let browser = win.gBrowser;
|
|
|
|
browser.selectedTab = browser.addTab(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// This will throw NS_ERROR_NOT_AVAILABLE if the notification cannot
|
|
|
|
// be displayed per the idl.
|
|
|
|
notifier.showAlertNotification("post-update-notification", title, text,
|
|
|
|
true, url, clickCallback);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_showPluginUpdatePage: function BG__showPluginUpdatePage() {
|
2009-10-02 04:26:04 -07:00
|
|
|
this._prefs.setBoolPref(PREF_PLUGINS_NOTIFYUSER, false);
|
|
|
|
|
|
|
|
var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
|
|
|
|
getService(Ci.nsIURLFormatter);
|
|
|
|
var updateUrl = formatter.formatURLPref(PREF_PLUGINS_UPDATEURL);
|
|
|
|
|
|
|
|
var win = this.getMostRecentBrowserWindow();
|
|
|
|
var browser = win.gBrowser;
|
|
|
|
browser.selectedTab = browser.addTab(updateUrl);
|
|
|
|
},
|
2008-10-30 23:42:02 -07:00
|
|
|
|
2007-05-03 01:56:41 -07:00
|
|
|
/**
|
|
|
|
* Initialize Places
|
2008-11-12 12:45:53 -08:00
|
|
|
* - imports the bookmarks html file if bookmarks database is empty, try to
|
|
|
|
* restore bookmarks from a JSON backup if the backend indicates that the
|
|
|
|
* database was corrupt.
|
|
|
|
*
|
|
|
|
* These prefs can be set up by the frontend:
|
|
|
|
*
|
|
|
|
* WARNING: setting these preferences to true will overwite existing bookmarks
|
2008-03-28 09:43:17 -07:00
|
|
|
*
|
|
|
|
* - browser.places.importBookmarksHTML
|
2008-11-12 12:45:53 -08:00
|
|
|
* Set to true will import the bookmarks.html file from the profile folder.
|
2008-04-08 11:42:53 -07:00
|
|
|
* - browser.places.smartBookmarksVersion
|
|
|
|
* Set during HTML import to indicate that Smart Bookmarks were created.
|
|
|
|
* Set to -1 to disable Smart Bookmarks creation.
|
|
|
|
* Set to 0 to restore current Smart Bookmarks.
|
2008-04-02 12:33:01 -07:00
|
|
|
* - browser.bookmarks.restore_default_bookmarks
|
|
|
|
* Set to true by safe-mode dialog to indicate we must restore default
|
|
|
|
* bookmarks.
|
2007-05-03 01:56:41 -07:00
|
|
|
*/
|
2009-12-17 13:28:08 -08:00
|
|
|
_initPlaces: function BG__initPlaces() {
|
2008-11-12 12:45:53 -08:00
|
|
|
// We must instantiate the history service since it will tell us if we
|
|
|
|
// need to import or restore bookmarks due to first-run, corruption or
|
|
|
|
// forced migration (due to a major schema change).
|
2007-06-16 14:23:17 -07:00
|
|
|
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
2008-11-12 12:45:53 -08:00
|
|
|
|
|
|
|
// If the database is corrupt or has been newly created we should
|
|
|
|
// import bookmarks.
|
2008-12-30 04:44:55 -08:00
|
|
|
var databaseStatus = histsvc.databaseStatus;
|
|
|
|
var importBookmarks = databaseStatus == histsvc.DATABASE_STATUS_CREATE ||
|
|
|
|
databaseStatus == histsvc.DATABASE_STATUS_CORRUPT;
|
2008-11-12 12:45:53 -08:00
|
|
|
|
2009-02-09 10:16:02 -08:00
|
|
|
if (databaseStatus == histsvc.DATABASE_STATUS_CREATE) {
|
|
|
|
// If the database has just been created, but we already have any
|
|
|
|
// bookmark, this is not the initial import. This can happen after a
|
|
|
|
// migration from a different browser since migrators run before us.
|
|
|
|
// In such a case we should not import, unless some pref has been set.
|
|
|
|
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
|
|
|
if (bmsvc.getIdForItemAt(bmsvc.bookmarksMenuFolder, 0) != -1 ||
|
|
|
|
bmsvc.getIdForItemAt(bmsvc.toolbarFolder, 0) != -1)
|
|
|
|
importBookmarks = false;
|
|
|
|
}
|
|
|
|
|
2008-11-12 12:45:53 -08:00
|
|
|
// Check if user or an extension has required to import bookmarks.html
|
|
|
|
var importBookmarksHTML = false;
|
|
|
|
try {
|
|
|
|
importBookmarksHTML =
|
|
|
|
this._prefs.getBoolPref("browser.places.importBookmarksHTML");
|
|
|
|
if (importBookmarksHTML)
|
|
|
|
importBookmarks = true;
|
|
|
|
} catch(ex) {}
|
2007-12-04 00:08:33 -08:00
|
|
|
|
2008-11-12 12:45:53 -08:00
|
|
|
// Check if Safe Mode or the user has required to restore bookmarks from
|
|
|
|
// default profile's bookmarks.html
|
2008-04-02 12:33:01 -07:00
|
|
|
var restoreDefaultBookmarks = false;
|
2007-05-03 01:56:41 -07:00
|
|
|
try {
|
2008-11-12 12:45:53 -08:00
|
|
|
restoreDefaultBookmarks =
|
|
|
|
this._prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
|
|
|
if (restoreDefaultBookmarks) {
|
2009-09-29 03:44:18 -07:00
|
|
|
// Ensure that we already have a bookmarks backup for today.
|
|
|
|
this._backupBookmarks();
|
2008-11-12 12:45:53 -08:00
|
|
|
importBookmarks = true;
|
|
|
|
}
|
2007-05-03 01:56:41 -07:00
|
|
|
} catch(ex) {}
|
2007-12-04 03:22:14 -08:00
|
|
|
|
2008-11-12 12:45:53 -08:00
|
|
|
// If the user did not require to restore default bookmarks, or import
|
|
|
|
// from bookmarks.html, we will try to restore from JSON
|
|
|
|
if (importBookmarks && !restoreDefaultBookmarks && !importBookmarksHTML) {
|
|
|
|
// get latest JSON backup
|
|
|
|
Cu.import("resource://gre/modules/utils.js");
|
2009-09-29 03:44:18 -07:00
|
|
|
var bookmarksBackupFile = PlacesUtils.backups.getMostRecent("json");
|
|
|
|
if (bookmarksBackupFile) {
|
2008-11-12 12:45:53 -08:00
|
|
|
// restore from JSON backup
|
2009-10-06 06:47:58 -07:00
|
|
|
PlacesUtils.restoreBookmarksFromJSONFile(bookmarksBackupFile);
|
2008-11-12 12:45:53 -08:00
|
|
|
importBookmarks = false;
|
|
|
|
}
|
|
|
|
else {
|
2008-12-09 12:39:32 -08:00
|
|
|
// We have created a new database but we don't have any backup available
|
2008-11-12 12:45:53 -08:00
|
|
|
importBookmarks = true;
|
2008-12-09 12:39:32 -08:00
|
|
|
var dirService = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
|
|
|
var bookmarksHTMLFile = dirService.get("BMarks", Ci.nsILocalFile);
|
|
|
|
if (bookmarksHTMLFile.exists()) {
|
|
|
|
// If bookmarks.html is available in current profile import it...
|
|
|
|
importBookmarksHTML = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// ...otherwise we will restore defaults
|
|
|
|
restoreDefaultBookmarks = true;
|
|
|
|
}
|
2008-11-12 12:45:53 -08:00
|
|
|
}
|
2008-04-02 12:33:01 -07:00
|
|
|
}
|
|
|
|
|
2010-03-23 18:17:49 -07:00
|
|
|
// If bookmarks are not imported, then initialize smart bookmarks. This
|
|
|
|
// happens during a common startup.
|
|
|
|
// Otherwise, if any kind of import runs, smart bookmarks creation should be
|
|
|
|
// delayed till the import operations has finished. Not doing so would
|
|
|
|
// cause them to be overwritten by the newly imported bookmarks.
|
2007-11-26 16:08:50 -08:00
|
|
|
if (!importBookmarks) {
|
|
|
|
this.ensurePlacesDefaultQueriesInitialized();
|
|
|
|
}
|
2008-03-13 12:25:49 -07:00
|
|
|
else {
|
2010-03-23 18:17:49 -07:00
|
|
|
// An import operation is about to run.
|
2009-01-13 02:48:28 -08:00
|
|
|
// Don't try to recreate smart bookmarks if autoExportHTML is true or
|
|
|
|
// smart bookmarks are disabled.
|
|
|
|
var autoExportHTML = false;
|
|
|
|
try {
|
|
|
|
autoExportHTML = this._prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
|
|
|
} catch(ex) {}
|
|
|
|
var smartBookmarksVersion = 0;
|
|
|
|
try {
|
|
|
|
smartBookmarksVersion = this._prefs.getIntPref("browser.places.smartBookmarksVersion");
|
|
|
|
} catch(ex) {}
|
|
|
|
if (!autoExportHTML && smartBookmarksVersion != -1)
|
|
|
|
this._prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
2008-11-12 12:45:53 -08:00
|
|
|
|
2008-11-18 09:25:39 -08:00
|
|
|
// Get bookmarks.html file location
|
2008-11-12 12:45:53 -08:00
|
|
|
var dirService = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
|
|
|
|
2008-11-18 09:25:39 -08:00
|
|
|
var bookmarksFile = null;
|
|
|
|
if (restoreDefaultBookmarks) {
|
|
|
|
// User wants to restore bookmarks.html file from default profile folder
|
2008-12-04 04:40:49 -08:00
|
|
|
bookmarksFile = dirService.get("profDef", Ci.nsILocalFile);
|
|
|
|
bookmarksFile.append("bookmarks.html");
|
2007-05-03 01:56:41 -07:00
|
|
|
}
|
2008-11-18 09:25:39 -08:00
|
|
|
else
|
|
|
|
bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
|
|
|
|
|
|
|
|
if (bookmarksFile.exists()) {
|
2010-03-23 18:17:49 -07:00
|
|
|
// Add an import observer. It will ensure that smart bookmarks are
|
|
|
|
// created once the operation is complete.
|
|
|
|
this._observerService.addObserver(this, "bookmarks-restore-success", false);
|
|
|
|
this._observerService.addObserver(this, "bookmarks-restore-failed", false);
|
|
|
|
|
|
|
|
// Import from bookmarks.html file.
|
2008-11-18 09:25:39 -08:00
|
|
|
try {
|
|
|
|
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
|
|
|
|
getService(Ci.nsIPlacesImportExportService);
|
|
|
|
importer.importHTMLFromFile(bookmarksFile, true /* overwrite existing */);
|
|
|
|
} catch (err) {
|
|
|
|
// Report the error, but ignore it.
|
|
|
|
Cu.reportError("Bookmarks.html file could be corrupt. " + err);
|
2010-03-23 18:17:49 -07:00
|
|
|
this._observerService.removeObserver(this, "bookmarks-restore-success");
|
|
|
|
this._observerService.removeObserver(this, "bookmarks-restore-failed");
|
2008-11-18 09:25:39 -08:00
|
|
|
}
|
2008-11-12 12:45:53 -08:00
|
|
|
}
|
2008-11-18 09:25:39 -08:00
|
|
|
else
|
|
|
|
Cu.reportError("Unable to find bookmarks.html file.");
|
2008-03-13 12:25:49 -07:00
|
|
|
|
2008-11-12 12:45:53 -08:00
|
|
|
// Reset preferences, so we won't try to import again at next run
|
|
|
|
if (importBookmarksHTML)
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.setBoolPref("browser.places.importBookmarksHTML", false);
|
2008-11-12 12:45:53 -08:00
|
|
|
if (restoreDefaultBookmarks)
|
|
|
|
this._prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks",
|
|
|
|
false);
|
2007-05-03 01:56:41 -07:00
|
|
|
}
|
2008-03-13 12:25:49 -07:00
|
|
|
|
|
|
|
// Initialize bookmark archiving on idle.
|
|
|
|
// Once a day, either on idle or shutdown, bookmarks are backed up.
|
2009-09-29 03:44:18 -07:00
|
|
|
if (!this._isIdleObserver) {
|
|
|
|
this._idleService.addIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
|
|
|
|
this._isIdleObserver = true;
|
|
|
|
}
|
2007-05-03 01:56:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Places shut-down tasks
|
2009-09-29 03:44:18 -07:00
|
|
|
* - back up bookmarks if needed.
|
|
|
|
* - export bookmarks as HTML, if so configured.
|
2008-03-13 12:25:49 -07:00
|
|
|
*
|
|
|
|
* Note: quit-application-granted notification is received twice
|
|
|
|
* so replace this method with a no-op when first called.
|
2007-05-03 01:56:41 -07:00
|
|
|
*/
|
2009-12-17 13:28:08 -08:00
|
|
|
_shutdownPlaces: function BG__shutdownPlaces() {
|
2009-09-29 03:44:18 -07:00
|
|
|
this._backupBookmarks();
|
2008-03-13 12:25:49 -07:00
|
|
|
|
|
|
|
// Backup bookmarks to bookmarks.html to support apps that depend
|
|
|
|
// on the legacy format.
|
|
|
|
var autoExportHTML = false;
|
|
|
|
try {
|
2008-10-17 19:02:07 -07:00
|
|
|
autoExportHTML = this._prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
2009-09-29 03:44:18 -07:00
|
|
|
} catch(ex) { /* Don't export */ }
|
2008-03-13 12:25:49 -07:00
|
|
|
|
|
|
|
if (autoExportHTML) {
|
2007-06-16 14:23:17 -07:00
|
|
|
Cc["@mozilla.org/browser/places/import-export-service;1"].
|
2008-03-13 12:25:49 -07:00
|
|
|
getService(Ci.nsIPlacesImportExportService).
|
|
|
|
backupBookmarksFile();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2009-09-29 03:44:18 -07:00
|
|
|
* Backup bookmarks if needed.
|
2008-03-13 12:25:49 -07:00
|
|
|
*/
|
2009-12-17 13:28:08 -08:00
|
|
|
_backupBookmarks: function BG__backupBookmarks() {
|
2008-03-13 12:25:49 -07:00
|
|
|
Cu.import("resource://gre/modules/utils.js");
|
|
|
|
|
2009-09-29 03:44:18 -07:00
|
|
|
let lastBackupFile = PlacesUtils.backups.getMostRecent();
|
2008-03-13 12:25:49 -07:00
|
|
|
|
2009-09-29 03:44:18 -07:00
|
|
|
// Backup bookmarks if there are no backups or the maximum interval between
|
|
|
|
// backups elapsed.
|
|
|
|
if (!lastBackupFile ||
|
|
|
|
new Date() - PlacesUtils.backups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_INTERVAL) {
|
|
|
|
let maxBackups = BOOKMARKS_BACKUP_MAX_BACKUPS;
|
2008-03-13 12:25:49 -07:00
|
|
|
try {
|
2008-10-17 19:02:07 -07:00
|
|
|
maxBackups = this._prefs.getIntPref("browser.bookmarks.max_backups");
|
2009-09-29 03:44:18 -07:00
|
|
|
}
|
|
|
|
catch(ex) { /* Use default. */ }
|
2008-03-13 12:25:49 -07:00
|
|
|
|
2009-09-29 03:44:18 -07:00
|
|
|
PlacesUtils.backups.create(maxBackups); // Don't force creation.
|
2008-03-13 12:25:49 -07:00
|
|
|
}
|
2007-05-03 01:56:41 -07:00
|
|
|
},
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2008-12-30 04:44:55 -08:00
|
|
|
/**
|
|
|
|
* Show the notificationBox for a locked places database.
|
|
|
|
*/
|
2009-12-17 13:28:08 -08:00
|
|
|
_showPlacesLockedNotificationBox: function BG__showPlacesLockedNotificationBox() {
|
2008-12-30 04:44:55 -08:00
|
|
|
var brandBundle = this._bundleService.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
var applicationName = brandBundle.GetStringFromName("brandShortName");
|
|
|
|
var placesBundle = this._bundleService.createBundle("chrome://browser/locale/places/places.properties");
|
|
|
|
var title = placesBundle.GetStringFromName("lockPrompt.title");
|
|
|
|
var text = placesBundle.formatStringFromName("lockPrompt.text", [applicationName], 1);
|
|
|
|
var buttonText = placesBundle.GetStringFromName("lockPromptInfoButton.label");
|
|
|
|
var accessKey = placesBundle.GetStringFromName("lockPromptInfoButton.accessKey");
|
|
|
|
|
|
|
|
var helpTopic = "places-locked";
|
|
|
|
var url = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
|
|
|
|
getService(Components.interfaces.nsIURLFormatter).
|
|
|
|
formatURLPref("app.support.baseURL");
|
|
|
|
url += helpTopic;
|
|
|
|
|
|
|
|
var browser = this.getMostRecentBrowserWindow().gBrowser;
|
|
|
|
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: buttonText,
|
|
|
|
accessKey: accessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
|
|
|
browser.selectedTab = browser.addTab(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var notifyBox = browser.getNotificationBox();
|
|
|
|
var box = notifyBox.appendNotification(text, title, null,
|
|
|
|
notifyBox.PRIORITY_CRITICAL_MEDIUM,
|
|
|
|
buttons);
|
|
|
|
box.persistence = -1; // Until user closes it
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_migrateUI: function BG__migrateUI() {
|
2008-02-04 11:37:26 -08:00
|
|
|
var migration = 0;
|
|
|
|
try {
|
2008-10-17 19:02:07 -07:00
|
|
|
migration = this._prefs.getIntPref("browser.migration.version");
|
2008-02-04 11:37:26 -08:00
|
|
|
} 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);
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource = this._rdf.GetDataSource("rdf:local-store");
|
|
|
|
this._dirty = false;
|
2008-02-04 11:37:26 -08:00
|
|
|
|
2008-07-17 03:22:50 -07:00
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
|
|
|
let toolbars = ["nav-bar", "toolbar-menubar", "PersonalToolbar"];
|
|
|
|
for (let i = 0; i < toolbars.length; i++) {
|
|
|
|
let toolbar = this._rdf.GetResource("chrome://browser/content/browser.xul#" + toolbars[i]);
|
|
|
|
let currentset = this._getPersist(toolbar, currentsetResource);
|
|
|
|
if (!currentset) {
|
|
|
|
// toolbar isn't customized
|
|
|
|
if (i == 0)
|
|
|
|
// new button is in the defaultset, nothing to migrate
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (/(?:^|,)unified-back-forward-button(?:$|,)/.test(currentset))
|
|
|
|
// new button is already there, nothing to migrate
|
|
|
|
break;
|
|
|
|
if (/(?:^|,)back-button(?:$|,)/.test(currentset)) {
|
|
|
|
let newset = currentset.replace(/(^|,)back-button($|,)/,
|
|
|
|
"$1unified-back-forward-button,back-button$2")
|
|
|
|
this._setPersist(toolbar, currentsetResource, newset);
|
|
|
|
// done migrating
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-04 11:37:26 -08:00
|
|
|
|
|
|
|
// force the RDF to be saved
|
2008-02-20 01:56:52 -08:00
|
|
|
if (this._dirty)
|
|
|
|
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
|
2008-02-04 11:37:26 -08:00
|
|
|
|
|
|
|
// free up the RDF service
|
|
|
|
this._rdf = null;
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource = null;
|
2008-02-04 11:37:26 -08:00
|
|
|
|
|
|
|
// update the migration version
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.setIntPref("browser.migration.version", 1);
|
2008-02-04 11:37:26 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_getPersist: function BG__getPersist(aSource, aProperty) {
|
2008-02-20 01:56:52 -08:00
|
|
|
var target = this._dataSource.GetTarget(aSource, aProperty, true);
|
2008-02-04 11:37:26 -08:00
|
|
|
if (target instanceof Ci.nsIRDFLiteral)
|
|
|
|
return target.Value;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_setPersist: function BG__setPersist(aSource, aProperty, aTarget) {
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dirty = true;
|
2008-02-04 11:37:26 -08:00
|
|
|
try {
|
2008-02-20 01:56:52 -08:00
|
|
|
var oldTarget = this._dataSource.GetTarget(aSource, aProperty, true);
|
2008-02-04 11:37:26 -08:00
|
|
|
if (oldTarget) {
|
|
|
|
if (aTarget)
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource.Change(aSource, aProperty, oldTarget, this._rdf.GetLiteral(aTarget));
|
2008-02-04 11:37:26 -08:00
|
|
|
else
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource.Unassert(aSource, aProperty, oldTarget);
|
2008-02-04 11:37:26 -08:00
|
|
|
}
|
|
|
|
else {
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource.Assert(aSource, aProperty, this._rdf.GetLiteral(aTarget), true);
|
2008-02-04 11:37:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// ------------------------------
|
|
|
|
// public nsIBrowserGlue members
|
|
|
|
// ------------------------------
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
sanitize: function BG_sanitize(aParentWindow) {
|
2009-10-14 02:53:13 -07:00
|
|
|
this._sanitizer.sanitize(aParentWindow);
|
2007-09-05 20:02:22 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
ensurePlacesDefaultQueriesInitialized:
|
|
|
|
function BG_ensurePlacesDefaultQueriesInitialized() {
|
2009-03-26 05:58:32 -07:00
|
|
|
// This is actual version of the smart bookmarks, must be increased every
|
|
|
|
// time smart bookmarks change.
|
|
|
|
// When adding a new smart bookmark below, its newInVersion property must
|
|
|
|
// be set to the version it has been added in, we will compare its value
|
|
|
|
// to users' smartBookmarksVersion and add new smart bookmarks without
|
|
|
|
// recreating old deleted ones.
|
2009-03-17 14:00:50 -07:00
|
|
|
const SMART_BOOKMARKS_VERSION = 2;
|
2008-04-08 11:42:53 -07:00
|
|
|
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
|
|
|
const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion";
|
|
|
|
|
2009-10-14 02:53:13 -07:00
|
|
|
// TODO bug 399268: should this be a pref?
|
2008-04-08 11:42:53 -07:00
|
|
|
const MAX_RESULTS = 10;
|
|
|
|
|
|
|
|
// get current smart bookmarks version
|
2008-04-08 17:34:03 -07:00
|
|
|
// By default, if the pref is not set up, we must create Smart Bookmarks
|
|
|
|
var smartBookmarksCurrentVersion = 0;
|
2007-11-26 16:08:50 -08:00
|
|
|
try {
|
2008-10-17 19:02:07 -07:00
|
|
|
smartBookmarksCurrentVersion = this._prefs.getIntPref(SMART_BOOKMARKS_PREF);
|
2009-03-26 05:58:32 -07:00
|
|
|
} catch(ex) { /* no version set, new profile */ }
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2008-04-08 11:42:53 -07:00
|
|
|
// bail out if we don't have to create or update Smart Bookmarks
|
|
|
|
if (smartBookmarksCurrentVersion == -1 ||
|
|
|
|
smartBookmarksCurrentVersion >= SMART_BOOKMARKS_VERSION)
|
2007-11-26 16:08:50 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
2008-04-08 11:42:53 -07:00
|
|
|
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"].
|
|
|
|
getService(Ci.nsIAnnotationService);
|
2007-11-26 16:08:50 -08:00
|
|
|
|
|
|
|
var callback = {
|
2009-12-17 13:28:08 -08:00
|
|
|
_uri: function BG_EPDQI__uri(aSpec) {
|
2007-11-26 16:08:50 -08:00
|
|
|
return Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService).
|
|
|
|
newURI(aSpec, null, null);
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
runBatched: function BG_EPDQI_runBatched() {
|
2008-04-08 11:42:53 -07:00
|
|
|
var smartBookmarks = [];
|
|
|
|
var bookmarksMenuIndex = 0;
|
|
|
|
var bookmarksToolbarIndex = 0;
|
|
|
|
|
2008-12-30 04:44:55 -08:00
|
|
|
var placesBundle = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle("chrome://browser/locale/places/places.properties");
|
|
|
|
|
2008-04-08 11:42:53 -07:00
|
|
|
// MOST VISITED
|
|
|
|
var smart = {queryId: "MostVisited", // don't change this
|
|
|
|
itemId: null,
|
2008-12-30 04:44:55 -08:00
|
|
|
title: placesBundle.GetStringFromName("mostVisitedTitle"),
|
2009-03-17 14:00:50 -07:00
|
|
|
uri: this._uri("place:redirectsMode=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET +
|
2008-04-08 11:42:53 -07:00
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS),
|
|
|
|
parent: bmsvc.toolbarFolder,
|
2009-03-26 05:58:32 -07:00
|
|
|
position: bookmarksToolbarIndex++,
|
|
|
|
newInVersion: 1 };
|
2008-04-08 11:42:53 -07:00
|
|
|
smartBookmarks.push(smart);
|
|
|
|
|
|
|
|
// RECENTLY BOOKMARKED
|
|
|
|
smart = {queryId: "RecentlyBookmarked", // don't change this
|
|
|
|
itemId: null,
|
2008-12-30 04:44:55 -08:00
|
|
|
title: placesBundle.GetStringFromName("recentlyBookmarkedTitle"),
|
2008-04-08 11:42:53 -07:00
|
|
|
uri: this._uri("place:folder=BOOKMARKS_MENU" +
|
|
|
|
"&folder=UNFILED_BOOKMARKS" +
|
|
|
|
"&folder=TOOLBAR" +
|
|
|
|
"&queryType=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
|
|
|
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
|
|
|
"&maxResults=" + MAX_RESULTS +
|
|
|
|
"&excludeQueries=1"),
|
|
|
|
parent: bmsvc.bookmarksMenuFolder,
|
2009-03-26 05:58:32 -07:00
|
|
|
position: bookmarksMenuIndex++,
|
|
|
|
newInVersion: 1 };
|
2008-04-08 11:42:53 -07:00
|
|
|
smartBookmarks.push(smart);
|
|
|
|
|
|
|
|
// RECENT TAGS
|
|
|
|
smart = {queryId: "RecentTags", // don't change this
|
|
|
|
itemId: null,
|
2008-12-30 04:44:55 -08:00
|
|
|
title: placesBundle.GetStringFromName("recentTagsTitle"),
|
2008-04-08 11:42:53 -07:00
|
|
|
uri: this._uri("place:"+
|
|
|
|
"type=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS),
|
|
|
|
parent: bmsvc.bookmarksMenuFolder,
|
2009-03-26 05:58:32 -07:00
|
|
|
position: bookmarksMenuIndex++,
|
|
|
|
newInVersion: 1 };
|
2008-04-08 11:42:53 -07:00
|
|
|
smartBookmarks.push(smart);
|
|
|
|
|
2009-11-02 13:04:15 -08:00
|
|
|
var smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
2009-03-26 05:58:32 -07:00
|
|
|
// Set current itemId, parent and position if Smart Bookmark exists,
|
|
|
|
// we will use these informations to create the new version at the same
|
|
|
|
// position.
|
2008-04-08 11:42:53 -07:00
|
|
|
for each(var itemId in smartBookmarkItemIds) {
|
|
|
|
var queryId = annosvc.getItemAnnotation(itemId, SMART_BOOKMARKS_ANNO);
|
|
|
|
for (var i = 0; i < smartBookmarks.length; i++){
|
|
|
|
if (smartBookmarks[i].queryId == queryId) {
|
2009-03-26 05:58:32 -07:00
|
|
|
smartBookmarks[i].found = true;
|
2008-04-08 11:42:53 -07:00
|
|
|
smartBookmarks[i].itemId = itemId;
|
|
|
|
smartBookmarks[i].parent = bmsvc.getFolderIdForItem(itemId);
|
|
|
|
smartBookmarks[i].position = bmsvc.getItemIndex(itemId);
|
|
|
|
// remove current item, since it will be replaced
|
|
|
|
bmsvc.removeItem(itemId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// We don't remove old Smart Bookmarks because user could still
|
|
|
|
// find them useful, or could have personalized them.
|
|
|
|
// Instead we remove the Smart Bookmark annotation.
|
|
|
|
if (i == smartBookmarks.length - 1)
|
|
|
|
annosvc.removeItemAnnotation(itemId, SMART_BOOKMARKS_ANNO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// create smart bookmarks
|
|
|
|
for each(var smartBookmark in smartBookmarks) {
|
2009-03-26 05:58:32 -07:00
|
|
|
// We update or create only changed or new smart bookmarks.
|
|
|
|
// Also we respect user choices, so we won't try to create a smart
|
|
|
|
// bookmark if it has been removed.
|
|
|
|
if (smartBookmarksCurrentVersion > 0 &&
|
|
|
|
smartBookmark.newInVersion <= smartBookmarksCurrentVersion &&
|
|
|
|
!smartBookmark.found)
|
|
|
|
continue;
|
|
|
|
|
2008-04-08 11:42:53 -07:00
|
|
|
smartBookmark.itemId = bmsvc.insertBookmark(smartBookmark.parent,
|
|
|
|
smartBookmark.uri,
|
|
|
|
smartBookmark.position,
|
|
|
|
smartBookmark.title);
|
|
|
|
annosvc.setItemAnnotation(smartBookmark.itemId,
|
|
|
|
SMART_BOOKMARKS_ANNO, smartBookmark.queryId,
|
|
|
|
0, annosvc.EXPIRE_NEVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are creating all Smart Bookmarks from ground up, add a
|
|
|
|
// separator below them in the bookmarks menu.
|
2009-03-26 05:58:32 -07:00
|
|
|
if (smartBookmarksCurrentVersion == 0 &&
|
|
|
|
smartBookmarkItemIds.length == 0)
|
2008-04-08 11:42:53 -07:00
|
|
|
bmsvc.insertSeparator(bmsvc.bookmarksMenuFolder, bookmarksMenuIndex);
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2008-02-21 20:09:08 -08:00
|
|
|
bmsvc.runInBatchMode(callback, null);
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
|
|
|
finally {
|
2008-10-17 19:02:07 -07:00
|
|
|
this._prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
|
|
|
|
this._prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-01-13 12:18:03 -08:00
|
|
|
#ifndef XP_WIN
|
2008-10-30 23:42:02 -07:00
|
|
|
#define BROKEN_WM_Z_ORDER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// this returns the most recent non-popup browser window
|
2009-12-17 13:28:08 -08:00
|
|
|
getMostRecentBrowserWindow: function BG_getMostRecentBrowserWindow() {
|
2008-10-30 23:42:02 -07:00
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
2010-01-24 02:20:10 -08:00
|
|
|
getService(Ci.nsIWindowMediator);
|
|
|
|
|
|
|
|
function isFullBrowserWindow(win) {
|
|
|
|
return !win.closed &&
|
|
|
|
!win.document.documentElement.getAttribute("chromehidden");
|
|
|
|
}
|
2008-10-30 23:42:02 -07:00
|
|
|
|
|
|
|
#ifdef BROKEN_WM_Z_ORDER
|
2010-01-24 02:20:10 -08:00
|
|
|
var win = wm.getMostRecentWindow("navigator:browser");
|
2008-10-30 23:42:02 -07:00
|
|
|
|
|
|
|
// if we're lucky, this isn't a popup, and we can just return this
|
2010-01-24 02:20:10 -08:00
|
|
|
if (win && !isFullBrowserWindow(win)) {
|
2008-10-30 23:42:02 -07:00
|
|
|
win = null;
|
2010-01-24 02:20:10 -08:00
|
|
|
let windowList = wm.getEnumerator("navigator:browser");
|
2008-10-30 23:42:02 -07:00
|
|
|
// this is oldest to newest, so this gets a bit ugly
|
|
|
|
while (windowList.hasMoreElements()) {
|
2010-01-24 02:20:10 -08:00
|
|
|
let nextWin = windowList.getNext();
|
|
|
|
if (isFullBrowserWindow(nextWin))
|
2008-10-30 23:42:02 -07:00
|
|
|
win = nextWin;
|
|
|
|
}
|
|
|
|
}
|
2010-01-24 02:20:10 -08:00
|
|
|
return win;
|
2008-10-30 23:42:02 -07:00
|
|
|
#else
|
|
|
|
var windowList = wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
|
2010-01-24 02:20:10 -08:00
|
|
|
while (windowList.hasMoreElements()) {
|
|
|
|
let win = windowList.getNext();
|
|
|
|
if (isFullBrowserWindow(win))
|
|
|
|
return win;
|
2008-10-30 23:42:02 -07:00
|
|
|
}
|
2010-01-24 02:20:10 -08:00
|
|
|
return null;
|
2008-10-30 23:42:02 -07:00
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-10-23 11:01:32 -07:00
|
|
|
function GeolocationPrompt() {}
|
|
|
|
|
|
|
|
GeolocationPrompt.prototype = {
|
|
|
|
classDescription: "Geolocation Prompting Component",
|
|
|
|
classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
|
|
|
|
contractID: "@mozilla.org/geolocation/prompt;1",
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationPrompt]),
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
prompt: function GP_prompt(request) {
|
2009-05-06 15:38:50 -07:00
|
|
|
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
|
2008-10-23 11:01:32 -07:00
|
|
|
|
2009-05-06 15:38:50 -07:00
|
|
|
var result = pm.testExactPermission(request.requestingURI, "geo");
|
2009-04-15 14:49:11 -07:00
|
|
|
|
2009-05-06 15:38:50 -07:00
|
|
|
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
|
|
request.allow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == Ci.nsIPermissionManager.DENY_ACTION) {
|
|
|
|
request.cancel();
|
|
|
|
return;
|
2009-04-15 14:49:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function setPagePermission(uri, allow) {
|
2009-05-06 15:38:50 -07:00
|
|
|
if (allow == true)
|
|
|
|
pm.add(uri, "geo", Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
else
|
|
|
|
pm.add(uri, "geo", Ci.nsIPermissionManager.DENY_ACTION);
|
2009-04-15 14:49:11 -07:00
|
|
|
}
|
|
|
|
|
2008-10-23 11:01:32 -07:00
|
|
|
function getChromeWindow(aWindow) {
|
|
|
|
var chromeWin = aWindow
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
|
|
.rootTreeItem
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
|
|
.QueryInterface(Ci.nsIDOMChromeWindow);
|
|
|
|
return chromeWin;
|
|
|
|
}
|
|
|
|
|
|
|
|
var requestingWindow = request.requestingWindow.top;
|
2009-04-15 14:49:11 -07:00
|
|
|
var chromeWindowObject = getChromeWindow(requestingWindow).wrappedJSObject;
|
|
|
|
var tabbrowser = chromeWindowObject.gBrowser;
|
2008-10-23 11:01:32 -07:00
|
|
|
var browser = tabbrowser.getBrowserForDocument(requestingWindow.document);
|
|
|
|
var notificationBox = tabbrowser.getNotificationBox(browser);
|
|
|
|
|
|
|
|
var notification = notificationBox.getNotificationWithValue("geolocation");
|
|
|
|
if (!notification) {
|
|
|
|
var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
|
|
|
|
var browserBundle = bundleService.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
|
|
|
|
var buttons = [{
|
2009-05-06 16:25:31 -07:00
|
|
|
label: browserBundle.GetStringFromName("geolocation.shareLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.shareLocation.accesskey"),
|
2009-08-02 10:53:04 -07:00
|
|
|
callback: function(notification) {
|
|
|
|
var elements = notification.getElementsByClassName("rememberChoice");
|
|
|
|
if (elements.length && elements[0].checked)
|
2009-04-15 14:49:11 -07:00
|
|
|
setPagePermission(request.requestingURI, true);
|
|
|
|
request.allow();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2009-05-06 16:25:31 -07:00
|
|
|
label: browserBundle.GetStringFromName("geolocation.dontShareLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.dontShareLocation.accesskey"),
|
2009-04-15 14:49:11 -07:00
|
|
|
callback: function(notification) {
|
2009-08-02 10:53:04 -07:00
|
|
|
var elements = notification.getElementsByClassName("rememberChoice");
|
|
|
|
if (elements.length && elements[0].checked)
|
2009-04-15 14:49:11 -07:00
|
|
|
setPagePermission(request.requestingURI, false);
|
2009-04-17 09:27:26 -07:00
|
|
|
request.cancel();
|
2009-04-15 14:49:11 -07:00
|
|
|
},
|
|
|
|
}];
|
2008-10-23 11:01:32 -07:00
|
|
|
|
2009-12-12 13:39:26 -08:00
|
|
|
var message;
|
|
|
|
|
|
|
|
// Different message/info if it is a local file
|
|
|
|
if (request.requestingURI.schemeIs("file")) {
|
|
|
|
message = browserBundle.formatStringFromName("geolocation.fileWantsToKnow",
|
|
|
|
[request.requestingURI.path], 1);
|
|
|
|
} else {
|
|
|
|
message = browserBundle.formatStringFromName("geolocation.siteWantsToKnow",
|
|
|
|
[request.requestingURI.host], 1);
|
|
|
|
}
|
2009-04-15 14:49:11 -07:00
|
|
|
|
|
|
|
var newBar = notificationBox.appendNotification(message,
|
|
|
|
"geolocation",
|
|
|
|
"chrome://browser/skin/Geo.png",
|
|
|
|
notificationBox.PRIORITY_INFO_HIGH,
|
|
|
|
buttons);
|
|
|
|
|
|
|
|
// For whatever reason, if we do this immediately
|
|
|
|
// (eg, without the setTimeout), the "link"
|
|
|
|
// element does not show up in the notification
|
|
|
|
// bar.
|
|
|
|
function geolocation_hacks_to_notification () {
|
|
|
|
|
2009-08-02 10:53:04 -07:00
|
|
|
// Never show a remember checkbox inside the private browsing mode
|
|
|
|
var inPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService).
|
|
|
|
privateBrowsingEnabled;
|
2009-12-13 14:38:16 -08:00
|
|
|
|
|
|
|
// don't show "Remember for this site" checkbox for file:
|
|
|
|
var host;
|
|
|
|
try {
|
|
|
|
host = request.requestingURI.host;
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
if (!inPrivateBrowsing && host) {
|
2009-08-02 10:53:04 -07:00
|
|
|
var checkbox = newBar.ownerDocument.createElementNS(XULNS, "checkbox");
|
|
|
|
checkbox.className = "rememberChoice";
|
|
|
|
checkbox.setAttribute("label", browserBundle.GetStringFromName("geolocation.remember"));
|
|
|
|
checkbox.setAttribute("accesskey", browserBundle.GetStringFromName("geolocation.remember.accesskey"));
|
|
|
|
newBar.appendChild(checkbox);
|
|
|
|
}
|
2009-04-15 14:49:11 -07:00
|
|
|
|
|
|
|
var link = newBar.ownerDocument.createElementNS(XULNS, "label");
|
|
|
|
link.className = "text-link";
|
2009-04-20 09:00:53 -07:00
|
|
|
link.setAttribute("value", browserBundle.GetStringFromName("geolocation.learnMore"));
|
2009-04-15 14:49:11 -07:00
|
|
|
|
|
|
|
var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
|
|
|
|
link.href = formatter.formatURLPref("browser.geolocation.warning.infoURL");
|
|
|
|
|
|
|
|
var description = newBar.ownerDocument.getAnonymousElementByAttribute(newBar, "anonid", "messageText");
|
|
|
|
description.appendChild(link);
|
|
|
|
};
|
|
|
|
|
|
|
|
chromeWindowObject.setTimeout(geolocation_hacks_to_notification, 0);
|
|
|
|
|
2008-10-23 11:01:32 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
//module initialization
|
|
|
|
function NSGetModule(aCompMgr, aFileSpec) {
|
2008-10-23 11:01:32 -07:00
|
|
|
return XPCOMUtils.generateModule([BrowserGlue, GeolocationPrompt]);
|
2007-09-05 20:02:22 -07:00
|
|
|
}
|