2012-02-23 18:37:04 +04:00
|
|
|
# -*- indent-tabs-mode: nil -*-
|
2007-09-06 07:02:22 +04: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-27 03:08:50 +03:00
|
|
|
# Seth Spitzer <sspitzer@mozilla.com>
|
|
|
|
# Asaf Romano <mano@mozilla.com>
|
2008-11-12 23:45:53 +03:00
|
|
|
# Marco Bonardo <mak77@bonardo.net>
|
2008-12-30 15:44:55 +03:00
|
|
|
# Dietrich Ayala <dietrich@mozilla.com>
|
2009-02-17 22:56:16 +03:00
|
|
|
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2009-07-31 08:57:57 +04:00
|
|
|
# Nils Maier <maierman@web.de>
|
2010-04-07 06:49:23 +04:00
|
|
|
# Robert Strong <robert.bugzilla@gmail.com>
|
2007-09-06 07:02:22 +04: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 *****
|
2005-08-23 20:38:28 +04:00
|
|
|
|
2007-06-17 01:23:17 +04:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Cr = Components.results;
|
2007-09-11 19:52:04 +04:00
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2009-04-16 01:49:11 +04:00
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-04-12 18:33:10 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2007-09-06 07:02:22 +04:00
|
|
|
|
2012-02-16 03:44:29 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
|
|
|
|
"resource://gre/modules/AddonManager.jsm");
|
2010-08-11 02:15:26 +04:00
|
|
|
|
2012-02-16 03:44:29 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
|
|
|
|
"resource://gre/modules/NetUtil.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
|
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
2010-11-23 16:04:07 +03:00
|
|
|
|
2012-03-23 11:15:36 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
|
|
|
|
"resource://gre/modules/BookmarkHTMLUtils.jsm");
|
|
|
|
|
2012-03-13 04:33:10 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "webappsUI",
|
2012-03-16 20:21:19 +04:00
|
|
|
"resource:///modules/webappsUI.jsm");
|
2012-03-13 04:33:10 +04:00
|
|
|
|
2009-10-02 15:26:04 +04:00
|
|
|
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
|
|
|
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
2008-03-08 03:16:38 +03:00
|
|
|
|
2009-09-29 14:44:18 +04: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 22:25:49 +03:00
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// Factory object
|
|
|
|
const BrowserGlueServiceFactory = {
|
|
|
|
_instance: null,
|
2009-12-18 00:28:08 +03:00
|
|
|
createInstance: function BGSF_createInstance(outer, iid) {
|
2007-09-06 07:02:22 +04:00
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return this._instance == null ?
|
|
|
|
this._instance = new BrowserGlue() : this._instance;
|
|
|
|
}
|
|
|
|
};
|
2005-12-05 00:02:38 +03:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// Constructor
|
|
|
|
|
|
|
|
function BrowserGlue() {
|
2009-09-29 14:44:18 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_idleService",
|
|
|
|
"@mozilla.org/widget/idleservice;1",
|
|
|
|
"nsIIdleService");
|
|
|
|
|
2009-10-05 14:13:04 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_distributionCustomizer", function() {
|
2010-01-22 02:49:11 +03:00
|
|
|
Cu.import("resource:///modules/distribution.js");
|
2009-10-05 14:13:04 +04:00
|
|
|
return new DistributionCustomizer();
|
|
|
|
});
|
|
|
|
|
2009-10-14 13:53:13 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_sanitizer",
|
|
|
|
function() {
|
|
|
|
let sanitizerScope = {};
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", sanitizerScope);
|
2009-10-14 13:53:13 +04:00
|
|
|
return sanitizerScope.Sanitizer;
|
|
|
|
});
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2009-07-31 08:57:57 +04: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
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
BrowserGlue.prototype = {
|
2007-06-15 22:01:25 +04:00
|
|
|
_saveSession: false,
|
2009-09-29 14:44:18 +04:00
|
|
|
_isIdleObserver: false,
|
|
|
|
_isPlacesInitObserver: false,
|
|
|
|
_isPlacesLockedObserver: false,
|
2010-04-22 16:53:54 +04:00
|
|
|
_isPlacesShutdownObserver: false,
|
2009-09-29 14:44:18 +04:00
|
|
|
_isPlacesDatabaseLocked: false,
|
2007-06-15 22:01:25 +04:00
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_setPrefToSaveSession: function BG__setPrefToSaveSession(aForce) {
|
2009-10-14 13:53:13 +04:00
|
|
|
if (!this._saveSession && !aForce)
|
|
|
|
return;
|
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
|
2009-06-12 00:17:33 +04: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.
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.savePrefFile(null);
|
2008-02-07 12:28:43 +03:00
|
|
|
},
|
|
|
|
|
2010-08-12 05:28:27 +04:00
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
_setSyncAutoconnectDelay: function BG__setSyncAutoconnectDelay() {
|
|
|
|
// Assume that a non-zero value for services.sync.autoconnectDelay should override
|
|
|
|
if (Services.prefs.prefHasUserValue("services.sync.autoconnectDelay")) {
|
|
|
|
let prefDelay = Services.prefs.getIntPref("services.sync.autoconnectDelay");
|
|
|
|
|
|
|
|
if (prefDelay > 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delays are in seconds
|
|
|
|
const MAX_DELAY = 300;
|
|
|
|
let delay = 3;
|
2011-01-23 04:46:22 +03:00
|
|
|
let browserEnum = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (browserEnum.hasMoreElements()) {
|
|
|
|
delay += browserEnum.getNext().gBrowser.tabs.length;
|
2010-08-12 05:28:27 +04:00
|
|
|
}
|
|
|
|
delay = delay <= MAX_DELAY ? delay : MAX_DELAY;
|
|
|
|
|
2011-07-21 23:20:55 +04:00
|
|
|
Cu.import("resource://services-sync/main.js");
|
|
|
|
Weave.SyncScheduler.delayedAutoConnect(delay);
|
2010-08-12 05:28:27 +04:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// nsIObserver implementation
|
2009-12-18 00:28:08 +03:00
|
|
|
observe: function BG_observe(subject, topic, data) {
|
2010-02-06 13:40:06 +03:00
|
|
|
switch (topic) {
|
2005-08-23 20:38:28 +04:00
|
|
|
case "xpcom-shutdown":
|
|
|
|
this._dispose();
|
|
|
|
break;
|
2007-09-11 19:52:04 +04:00
|
|
|
case "prefservice:after-app-defaults":
|
|
|
|
this._onAppDefaults();
|
|
|
|
break;
|
2005-10-07 19:15:21 +04:00
|
|
|
case "final-ui-startup":
|
2005-08-23 20:38:28 +04:00
|
|
|
this._onProfileStartup();
|
|
|
|
break;
|
2010-10-02 19:53:37 +04:00
|
|
|
case "browser-delayed-startup-finished":
|
|
|
|
this._onFirstWindowLoaded();
|
|
|
|
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
|
|
|
|
break;
|
2008-03-08 03:16:38 +03:00
|
|
|
case "sessionstore-windows-restored":
|
2012-01-19 03:25:05 +04:00
|
|
|
this._onWindowsRestored();
|
2008-03-08 03:16:38 +03:00
|
|
|
break;
|
2006-07-19 16:49:33 +04:00
|
|
|
case "browser:purge-session-history":
|
|
|
|
// reset the console service's error buffer
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.console.logStringMessage(null); // clear the console (in case it's open)
|
|
|
|
Services.console.reset();
|
2006-07-19 16:49:33 +04:00
|
|
|
break;
|
2007-06-15 22:01:25 +04:00
|
|
|
case "quit-application-requested":
|
2007-07-26 01:43:17 +04:00
|
|
|
this._onQuitRequest(subject, data);
|
2007-06-15 22:01:25 +04:00
|
|
|
break;
|
|
|
|
case "quit-application-granted":
|
2009-10-14 13:53:13 +04:00
|
|
|
// This pref must be set here because SessionStore will use its value
|
|
|
|
// on quit-application.
|
|
|
|
this._setPrefToSaveSession();
|
2011-11-08 09:20:42 +04:00
|
|
|
try {
|
|
|
|
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].
|
|
|
|
getService(Ci.nsIAppStartup);
|
|
|
|
appStartup.trackStartupCrashEnd();
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("Could not end startup crash tracking in quit-application-granted: " + e);
|
|
|
|
}
|
2007-06-15 22:01:25 +04:00
|
|
|
break;
|
2009-07-31 08:57:57 +04: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 13:53:13 +04:00
|
|
|
this._setPrefToSaveSession();
|
2009-07-31 08:57:57 +04:00
|
|
|
break;
|
2010-08-12 05:28:27 +04:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
case "weave:service:ready":
|
|
|
|
this._setSyncAutoconnectDelay();
|
|
|
|
break;
|
2009-07-31 08:57:57 +04:00
|
|
|
#endif
|
2008-02-07 12:28:43 +03:00
|
|
|
case "session-save":
|
2009-10-14 13:53:13 +04:00
|
|
|
this._setPrefToSaveSession(true);
|
2008-02-07 12:28:43 +03:00
|
|
|
subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
subject.data = true;
|
|
|
|
break;
|
2008-11-12 23:45:53 +03:00
|
|
|
case "places-init-complete":
|
|
|
|
this._initPlaces();
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "places-init-complete");
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesInitObserver = false;
|
2008-12-30 15:44:55 +03:00
|
|
|
// no longer needed, since history was initialized completely.
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "places-database-locked");
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesLockedObserver = false;
|
2008-12-30 15:44:55 +03:00
|
|
|
break;
|
|
|
|
case "places-database-locked":
|
|
|
|
this._isPlacesDatabaseLocked = true;
|
2009-10-14 13:53:13 +04:00
|
|
|
// Stop observing, so further attempts to load history service
|
|
|
|
// will not show the prompt.
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "places-database-locked");
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesLockedObserver = false;
|
2008-11-12 23:45:53 +03:00
|
|
|
break;
|
2010-04-22 16:53:54 +04:00
|
|
|
case "places-shutdown":
|
|
|
|
if (this._isPlacesShutdownObserver) {
|
|
|
|
Services.obs.removeObserver(this, "places-shutdown");
|
|
|
|
this._isPlacesShutdownObserver = false;
|
|
|
|
}
|
2010-08-28 05:24:54 +04:00
|
|
|
// places-shutdown is fired when the profile is about to disappear.
|
2010-04-22 16:53:54 +04:00
|
|
|
this._onProfileShutdown();
|
|
|
|
break;
|
2008-03-13 22:25:49 +03:00
|
|
|
case "idle":
|
2009-09-29 14:44:18 +04:00
|
|
|
if (this._idleService.idleTime > BOOKMARKS_BACKUP_IDLE_TIME * 1000)
|
|
|
|
this._backupBookmarks();
|
2008-03-13 22:25:49 +03:00
|
|
|
break;
|
2009-10-05 14:13:04 +04:00
|
|
|
case "distribution-customization-complete":
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "distribution-customization-complete");
|
2009-10-05 14:13:04 +04:00
|
|
|
// Customization has finished, we don't need the customizer anymore.
|
|
|
|
delete this._distributionCustomizer;
|
|
|
|
break;
|
2010-04-07 06:49:23 +04:00
|
|
|
case "browser-glue-test": // used by tests
|
|
|
|
if (data == "post-update-notification") {
|
2010-04-12 18:33:10 +04:00
|
|
|
if (Services.prefs.prefHasUserValue("app.update.postupdate"))
|
2010-04-07 06:49:23 +04:00
|
|
|
this._showUpdateNotification();
|
2010-12-22 21:26:18 +03:00
|
|
|
}
|
|
|
|
else if (data == "force-ui-migration") {
|
|
|
|
this._migrateUI();
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
2011-04-12 18:32:20 +04:00
|
|
|
else if (data == "force-distribution-customization") {
|
2011-04-13 05:15:39 +04:00
|
|
|
this._distributionCustomizer.applyPrefDefaults();
|
2011-04-12 18:32:20 +04:00
|
|
|
this._distributionCustomizer.applyCustomizations();
|
2011-04-13 05:15:39 +04:00
|
|
|
// To apply distribution bookmarks use "places-init-complete".
|
2011-04-12 18:32:20 +04:00
|
|
|
}
|
2011-04-13 04:43:28 +04:00
|
|
|
else if (data == "force-places-init") {
|
|
|
|
this._initPlaces();
|
|
|
|
}
|
2010-04-07 06:49:23 +04:00
|
|
|
break;
|
2012-03-23 11:15:36 +04:00
|
|
|
case "initial-migration":
|
|
|
|
this._initialMigrationPerformed = true;
|
|
|
|
break;
|
2005-08-23 20:38:28 +04:00
|
|
|
}
|
2008-03-13 22:25:49 +03:00
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// initialization (called on application startup)
|
2009-12-18 00:28:08 +03:00
|
|
|
_init: function BG__init() {
|
2010-04-22 18:11:21 +04:00
|
|
|
let os = Services.obs;
|
|
|
|
os.addObserver(this, "xpcom-shutdown", false);
|
|
|
|
os.addObserver(this, "prefservice:after-app-defaults", false);
|
|
|
|
os.addObserver(this, "final-ui-startup", false);
|
2010-10-02 19:53:37 +04:00
|
|
|
os.addObserver(this, "browser-delayed-startup-finished", false);
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "sessionstore-windows-restored", false);
|
|
|
|
os.addObserver(this, "browser:purge-session-history", false);
|
|
|
|
os.addObserver(this, "quit-application-requested", false);
|
|
|
|
os.addObserver(this, "quit-application-granted", false);
|
2009-07-31 08:57:57 +04:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "browser-lastwindow-close-requested", false);
|
|
|
|
os.addObserver(this, "browser-lastwindow-close-granted", false);
|
2010-08-12 05:28:27 +04:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
os.addObserver(this, "weave:service:ready", false);
|
2009-07-31 08:57:57 +04:00
|
|
|
#endif
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "session-save", false);
|
|
|
|
os.addObserver(this, "places-init-complete", false);
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesInitObserver = true;
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "places-database-locked", false);
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesLockedObserver = true;
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "distribution-customization-complete", false);
|
|
|
|
os.addObserver(this, "places-shutdown", false);
|
2010-04-22 16:53:54 +04:00
|
|
|
this._isPlacesShutdownObserver = true;
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// cleanup (called on application shutdown)
|
2009-12-18 00:28:08 +03:00
|
|
|
_dispose: function BG__dispose() {
|
2010-04-22 18:11:21 +04:00
|
|
|
let os = Services.obs;
|
|
|
|
os.removeObserver(this, "xpcom-shutdown");
|
|
|
|
os.removeObserver(this, "prefservice:after-app-defaults");
|
|
|
|
os.removeObserver(this, "final-ui-startup");
|
|
|
|
os.removeObserver(this, "sessionstore-windows-restored");
|
|
|
|
os.removeObserver(this, "browser:purge-session-history");
|
|
|
|
os.removeObserver(this, "quit-application-requested");
|
|
|
|
os.removeObserver(this, "quit-application-granted");
|
2009-07-31 08:57:57 +04:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "browser-lastwindow-close-requested");
|
|
|
|
os.removeObserver(this, "browser-lastwindow-close-granted");
|
2010-08-12 05:28:27 +04:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
os.removeObserver(this, "weave:service:ready", false);
|
2009-07-31 08:57:57 +04:00
|
|
|
#endif
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "session-save");
|
2009-09-29 14:44:18 +04:00
|
|
|
if (this._isIdleObserver)
|
|
|
|
this._idleService.removeIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
|
|
|
|
if (this._isPlacesInitObserver)
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "places-init-complete");
|
2009-09-29 14:44:18 +04:00
|
|
|
if (this._isPlacesLockedObserver)
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "places-database-locked");
|
2010-04-22 16:53:54 +04:00
|
|
|
if (this._isPlacesShutdownObserver)
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "places-shutdown");
|
2012-03-13 04:33:10 +04:00
|
|
|
webappsUI.uninit();
|
2007-09-11 19:52:04 +04:00
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_onAppDefaults: function BG__onAppDefaults() {
|
2007-09-11 19:52:04 +04:00
|
|
|
// apply distribution customizations (prefs)
|
|
|
|
// other customizations are applied in _onProfileStartup()
|
2009-10-05 14:13:04 +04:00
|
|
|
this._distributionCustomizer.applyPrefDefaults();
|
2007-09-11 19:52:04 +04:00
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// profile startup handler (contains profile initialization routines)
|
2009-12-18 00:28:08 +03:00
|
|
|
_onProfileStartup: function BG__onProfileStartup() {
|
2009-10-14 13:53:13 +04:00
|
|
|
this._sanitizer.onStartup();
|
2005-10-04 09:02:47 +04:00
|
|
|
// check if we're in safe mode
|
2010-04-12 18:33:10 +04:00
|
|
|
if (Services.appinfo.inSafeMode) {
|
|
|
|
Services.ww.openWindow(null, "chrome://browser/content/safeMode.xul",
|
|
|
|
"_blank", "chrome,centerscreen,modal,resizable=no", null);
|
2005-10-04 09:02:47 +04:00
|
|
|
}
|
2007-05-03 12:56:41 +04:00
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
// apply distribution customizations
|
|
|
|
// prefs are applied in _onAppDefaults()
|
2009-10-05 14:13:04 +04:00
|
|
|
this._distributionCustomizer.applyCustomizations();
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2008-02-04 22:37:26 +03:00
|
|
|
// handle any UI migration
|
2008-03-20 21:57:05 +03:00
|
|
|
this._migrateUI();
|
2008-10-01 09:36:21 +04:00
|
|
|
|
2012-03-13 04:33:10 +04:00
|
|
|
// Initialize webapps UI
|
|
|
|
webappsUI.init();
|
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
|
2007-05-11 04:42:22 +04:00
|
|
|
},
|
2007-05-03 12:56:41 +04:00
|
|
|
|
2010-10-02 19:53:37 +04:00
|
|
|
// the first browser window has finished initializing
|
|
|
|
_onFirstWindowLoaded: function BG__onFirstWindowLoaded() {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// For windows seven, initialize the jump list module.
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
2007-05-11 04:42:22 +04:00
|
|
|
// profile shutdown handler (contains profile cleanup routines)
|
2009-12-18 00:28:08 +03:00
|
|
|
_onProfileShutdown: function BG__onProfileShutdown() {
|
2008-02-22 23:42:24 +03:00
|
|
|
this._shutdownPlaces();
|
2009-10-14 13:53:13 +04:00
|
|
|
this._sanitizer.onShutdown();
|
2007-06-15 22:01:26 +04:00
|
|
|
},
|
|
|
|
|
2012-01-19 03:25:05 +04:00
|
|
|
// All initial windows have opened.
|
|
|
|
_onWindowsRestored: function BG__onWindowsRestored() {
|
2008-10-31 09:42:02 +03:00
|
|
|
// Show about:rights notification, if needed.
|
2011-06-02 12:00:13 +04:00
|
|
|
if (this._shouldShowRights()) {
|
2008-10-31 09:42:02 +03:00
|
|
|
this._showRightsNotification();
|
2011-07-15 20:57:13 +04:00
|
|
|
#ifdef MOZ_TELEMETRY_REPORTING
|
2011-06-02 12:00:13 +04:00
|
|
|
} else {
|
|
|
|
// Only show telemetry notification when about:rights notification is not shown.
|
|
|
|
this._showTelemetryNotification();
|
2011-07-15 20:57:13 +04:00
|
|
|
#endif
|
2011-06-02 12:00:13 +04:00
|
|
|
}
|
|
|
|
|
2010-04-07 06:49:23 +04:00
|
|
|
// Show update notification, if needed.
|
2010-04-12 18:33:10 +04:00
|
|
|
if (Services.prefs.prefHasUserValue("app.update.postupdate"))
|
2010-04-07 06:49:23 +04:00
|
|
|
this._showUpdateNotification();
|
|
|
|
|
2008-12-30 15:44:55 +03:00
|
|
|
// Load the "more info" page for a locked places.sqlite
|
2010-08-09 19:59:59 +04:00
|
|
|
// This property is set earlier by places-database-locked topic.
|
2008-12-30 15:44:55 +03:00
|
|
|
if (this._isPlacesDatabaseLocked) {
|
|
|
|
this._showPlacesLockedNotificationBox();
|
|
|
|
}
|
2009-10-02 15:26:04 +04:00
|
|
|
|
|
|
|
// If there are plugins installed that are outdated, and the user hasn't
|
|
|
|
// been warned about them yet, open the plugins update page.
|
2010-04-12 18:33:10 +04:00
|
|
|
if (Services.prefs.getBoolPref(PREF_PLUGINS_NOTIFYUSER))
|
2009-10-02 15:26:04 +04:00
|
|
|
this._showPluginUpdatePage();
|
2011-08-13 00:50:47 +04:00
|
|
|
|
|
|
|
// For any add-ons that were installed disabled and can be enabled offer
|
2012-02-16 03:44:29 +04:00
|
|
|
// them to the user.
|
|
|
|
let changedIDs = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED);
|
|
|
|
if (changedIDs.length > 0) {
|
|
|
|
let browser = this.getMostRecentBrowserWindow().gBrowser;
|
|
|
|
AddonManager.getAddonsByIDs(changedIDs, function(aAddons) {
|
|
|
|
aAddons.forEach(function(aAddon) {
|
|
|
|
// If the add-on isn't user disabled or can't be enabled then skip it.
|
|
|
|
if (!aAddon.userDisabled || !(aAddon.permissions & AddonManager.PERM_CAN_ENABLE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
browser.selectedTab = browser.addTab("about:newaddon?id=" + aAddon.id);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2012-02-07 05:39:07 +04:00
|
|
|
|
|
|
|
let keywordURLUserSet = Services.prefs.prefHasUserValue("keyword.URL");
|
|
|
|
Services.telemetry.getHistogramById("FX_KEYWORD_URL_USERSET").add(keywordURLUserSet);
|
2012-03-07 02:28:53 +04:00
|
|
|
|
|
|
|
// Perform default browser checking.
|
|
|
|
var shell;
|
|
|
|
try {
|
|
|
|
shell = Components.classes["@mozilla.org/browser/shell-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIShellService);
|
|
|
|
} catch (e) { }
|
|
|
|
if (shell) {
|
|
|
|
#ifdef DEBUG
|
2012-03-21 23:05:23 +04:00
|
|
|
let shouldCheck = false;
|
2012-03-07 02:28:53 +04:00
|
|
|
#else
|
2012-03-21 23:05:23 +04:00
|
|
|
let shouldCheck = shell.shouldCheckDefaultBrowser;
|
2012-03-07 02:28:53 +04:00
|
|
|
#endif
|
2012-03-21 23:05:23 +04:00
|
|
|
let willRecoverSession = false;
|
2012-03-07 02:28:53 +04:00
|
|
|
try {
|
2012-03-21 23:05:23 +04:00
|
|
|
let ss = Cc["@mozilla.org/browser/sessionstartup;1"].
|
2012-03-07 02:28:53 +04:00
|
|
|
getService(Ci.nsISessionStartup);
|
|
|
|
willRecoverSession =
|
|
|
|
(ss.sessionType == Ci.nsISessionStartup.RECOVER_SESSION);
|
|
|
|
}
|
|
|
|
catch (ex) { /* never mind; suppose SessionStore is broken */ }
|
|
|
|
if (shouldCheck && !shell.isDefaultBrowser(true) && !willRecoverSession) {
|
|
|
|
Services.tm.mainThread.dispatch(function() {
|
2012-03-21 23:05:23 +04:00
|
|
|
var win = this.getMostRecentBrowserWindow();
|
2012-03-07 02:28:53 +04:00
|
|
|
var brandBundle = win.document.getElementById("bundle_brand");
|
|
|
|
var shellBundle = win.document.getElementById("bundle_shell");
|
|
|
|
|
|
|
|
var brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
var promptTitle = shellBundle.getString("setDefaultBrowserTitle");
|
|
|
|
var promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage",
|
|
|
|
[brandShortName]);
|
|
|
|
var checkboxLabel = shellBundle.getFormattedString("setDefaultBrowserDontAsk",
|
|
|
|
[brandShortName]);
|
|
|
|
var checkEveryTime = { value: shouldCheck };
|
|
|
|
var ps = Services.prompt;
|
|
|
|
var rv = ps.confirmEx(win, promptTitle, promptMessage,
|
|
|
|
ps.STD_YES_NO_BUTTONS,
|
|
|
|
null, null, null, checkboxLabel, checkEveryTime);
|
|
|
|
if (rv == 0)
|
|
|
|
shell.setDefaultBrowser(true, false);
|
|
|
|
shell.shouldCheckDefaultBrowser = checkEveryTime.value;
|
2012-03-21 23:05:23 +04:00
|
|
|
}.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
|
2012-03-07 02:28:53 +04:00
|
|
|
}
|
|
|
|
}
|
2008-03-08 03:16:38 +03:00
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {
|
2008-01-30 00:16:02 +03:00
|
|
|
// If user has already dismissed quit request, then do nothing
|
|
|
|
if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
|
|
|
|
return;
|
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
// There are several cases where we won't show a dialog here:
|
|
|
|
// 1. There is only 1 tab open in 1 window
|
|
|
|
// 2. The session will be restored at startup, indicated by
|
|
|
|
// browser.startup.page == 3 or browser.sessionstore.resume_session_once == true
|
|
|
|
// 3. browser.warnOnQuit == false
|
|
|
|
// 4. The browser is currently in Private Browsing mode
|
|
|
|
//
|
|
|
|
// Otherwise these are the conditions and the associated dialogs that will be shown:
|
|
|
|
// 1. aQuitType == "lastwindow" or "quit" and browser.showQuitWarning == true
|
|
|
|
// - The quit dialog will be shown
|
|
|
|
// 2. aQuitType == "restart" && browser.warnOnRestart == true
|
|
|
|
// - The restart dialog will be shown
|
|
|
|
// 3. aQuitType == "lastwindow" && browser.tabs.warnOnClose == true
|
|
|
|
// - The "closing multiple tabs" dialog will be shown
|
|
|
|
//
|
|
|
|
// aQuitType == "lastwindow" is overloaded. "lastwindow" is used to indicate
|
|
|
|
// "the last window is closing but we're not quitting (a non-browser window is open)"
|
|
|
|
// and also "we're quitting by closing the last window".
|
|
|
|
|
2007-06-15 22:01:25 +04:00
|
|
|
var windowcount = 0;
|
2008-05-10 19:52:32 +04:00
|
|
|
var pagecount = 0;
|
2010-04-12 18:33:10 +04:00
|
|
|
var browserEnum = Services.wm.getEnumerator("navigator:browser");
|
2008-05-10 19:52:32 +04:00
|
|
|
while (browserEnum.hasMoreElements()) {
|
|
|
|
windowcount++;
|
|
|
|
|
|
|
|
var browser = browserEnum.getNext();
|
|
|
|
var tabbrowser = browser.document.getElementById("content");
|
|
|
|
if (tabbrowser)
|
2010-08-13 16:40:19 +04:00
|
|
|
pagecount += tabbrowser.browsers.length - tabbrowser._numPinnedTabs;
|
2008-05-10 19:52:32 +04:00
|
|
|
}
|
2007-06-15 22:01:25 +04:00
|
|
|
|
|
|
|
this._saveSession = false;
|
2008-05-10 19:52:32 +04:00
|
|
|
if (pagecount < 2)
|
|
|
|
return;
|
2007-06-15 22:01:25 +04:00
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
if (!aQuitType)
|
2007-07-26 01:43:17 +04:00
|
|
|
aQuitType = "quit";
|
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
// Never show a prompt inside private browsing mode
|
2009-02-17 22:56:16 +03:00
|
|
|
var inPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService).
|
|
|
|
privateBrowsingEnabled;
|
2011-02-08 04:50:37 +03:00
|
|
|
if (inPrivateBrowsing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var showPrompt = false;
|
|
|
|
var mostRecentBrowserWindow;
|
|
|
|
|
|
|
|
// browser.warnOnQuit is a hidden global boolean to override all quit prompts
|
|
|
|
// browser.showQuitWarning specifically covers quitting
|
|
|
|
// browser.warnOnRestart specifically covers app-initiated restarts where we restart the app
|
|
|
|
// browser.tabs.warnOnClose is the global "warn when closing multiple tabs" pref
|
|
|
|
|
|
|
|
var sessionWillBeRestored = Services.prefs.getIntPref("browser.startup.page") == 3 ||
|
|
|
|
Services.prefs.getBoolPref("browser.sessionstore.resume_session_once");
|
|
|
|
if (sessionWillBeRestored || !Services.prefs.getBoolPref("browser.warnOnQuit"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// On last window close or quit && showQuitWarning, we want to show the
|
|
|
|
// quit warning.
|
|
|
|
if (aQuitType != "restart" && Services.prefs.getBoolPref("browser.showQuitWarning")) {
|
|
|
|
showPrompt = true;
|
|
|
|
}
|
|
|
|
else if (aQuitType == "restart" && Services.prefs.getBoolPref("browser.warnOnRestart")) {
|
|
|
|
showPrompt = true;
|
|
|
|
}
|
|
|
|
else if (aQuitType == "lastwindow") {
|
|
|
|
// If aQuitType is "lastwindow" and we aren't showing the quit warning,
|
|
|
|
// we should show the window closing warning instead. warnAboutClosing
|
|
|
|
// tabs checks browser.tabs.warnOnClose and returns if it's ok to close
|
|
|
|
// the window. It doesn't actually close the window.
|
|
|
|
mostRecentBrowserWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
aCancelQuit.data = !mostRecentBrowserWindow.gBrowser.warnAboutClosingTabs(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!showPrompt)
|
2010-08-13 16:40:19 +04:00
|
|
|
return;
|
2007-11-29 23:46:08 +03:00
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
var quitBundle = Services.strings.createBundle("chrome://browser/locale/quitDialog.properties");
|
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
2008-05-08 19:08:40 +04:00
|
|
|
|
|
|
|
var appName = brandBundle.GetStringFromName("brandShortName");
|
2011-02-08 22:04:13 +03:00
|
|
|
var quitTitleString = (aQuitType == "restart" ? "restart" : "quit") + "DialogTitle";
|
|
|
|
var quitDialogTitle = quitBundle.formatStringFromName(quitTitleString, [appName], 1);
|
2008-05-08 19:08:40 +04: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);
|
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
var promptService = Services.prompt;
|
2008-05-08 19:08:40 +04: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;
|
|
|
|
|
|
|
|
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 22:01:25 +04:00
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
// This wouldn't have been set above since we shouldn't be here for
|
|
|
|
// aQuitType == "lastwindow"
|
|
|
|
mostRecentBrowserWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
|
2009-07-31 08:57:57 +04:00
|
|
|
var buttonChoice =
|
|
|
|
promptService.confirmEx(mostRecentBrowserWindow, quitDialogTitle, message,
|
|
|
|
flags, button0Title, button1Title, button2Title,
|
|
|
|
neverAskText, neverAsk);
|
2008-05-08 19:08:40 +04:00
|
|
|
|
|
|
|
switch (buttonChoice) {
|
|
|
|
case 2: // Quit
|
|
|
|
if (neverAsk.value)
|
2011-02-08 04:50:37 +03:00
|
|
|
Services.prefs.setBoolPref("browser.showQuitWarning", false);
|
2008-05-08 19:08:40 +04: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")
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setBoolPref("browser.warnOnRestart", false);
|
2008-05-08 19:08:40 +04:00
|
|
|
else {
|
|
|
|
// always save state when shutting down
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setIntPref("browser.startup.page", 3);
|
2008-02-23 12:32:09 +03:00
|
|
|
}
|
2007-06-15 22:01:25 +04:00
|
|
|
}
|
2008-05-08 19:08:40 +04:00
|
|
|
break;
|
2007-06-15 22:01:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-10-31 09:42:02 +03: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-18 00:28:08 +03:00
|
|
|
_shouldShowRights: function BG__shouldShowRights() {
|
2008-10-31 09:42:02 +03:00
|
|
|
// Look for an unconditional override pref. If set, do what it says.
|
|
|
|
// (true --> never show, false --> always show)
|
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
return !Services.prefs.getBoolPref("browser.rights.override");
|
2008-10-31 09:42:02 +03:00
|
|
|
} catch (e) { }
|
|
|
|
// Ditto, for the legacy EULA pref.
|
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
return !Services.prefs.getBoolPref("browser.EULA.override");
|
2008-10-31 09:42:02 +03:00
|
|
|
} 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.
|
2010-04-12 18:33:10 +04:00
|
|
|
var currentVersion = Services.prefs.getIntPref("browser.rights.version");
|
2008-10-31 09:42:02 +03:00
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
|
2008-10-31 09:42:02 +03:00
|
|
|
} 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 {
|
2010-04-12 18:33:10 +04:00
|
|
|
return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
|
2008-10-31 09:42:02 +03:00
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
// We haven't shown the notification before, so do so now.
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_showRightsNotification: function BG__showRightsNotification() {
|
2008-10-31 09:42:02 +03: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();
|
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
var rightsBundle = Services.strings.createBundle("chrome://global/locale/aboutRights.properties");
|
2008-10-31 09:42:02 +03:00
|
|
|
|
2009-02-25 22:54:14 +03:00
|
|
|
var buttonLabel = rightsBundle.GetStringFromName("buttonLabel");
|
|
|
|
var buttonAccessKey = rightsBundle.GetStringFromName("buttonAccessKey");
|
|
|
|
var productName = brandBundle.GetStringFromName("brandFullName");
|
|
|
|
var notifyRightsText = rightsBundle.formatStringFromName("notifyRightsText", [productName], 1);
|
2010-09-03 06:20:12 +04:00
|
|
|
|
2008-10-31 09:42:02 +03:00
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: buttonLabel,
|
|
|
|
accessKey: buttonAccessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
|
|
|
browser.selectedTab = browser.addTab("about:rights");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2008-11-12 23:45:53 +03:00
|
|
|
// Set pref to indicate we've shown the notification.
|
2010-04-12 18:33:10 +04:00
|
|
|
var currentVersion = Services.prefs.getIntPref("browser.rights.version");
|
|
|
|
Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
|
2008-10-31 09:42:02 +03:00
|
|
|
|
2011-11-05 01:45:01 +04:00
|
|
|
var notification = notifyBox.appendNotification(notifyRightsText, "about-rights", null, notifyBox.PRIORITY_INFO_LOW, buttons);
|
|
|
|
notification.persistence = -1; // Until user closes it
|
2008-10-31 09:42:02 +03:00
|
|
|
},
|
2010-04-07 06:49:23 +04:00
|
|
|
|
|
|
|
_showUpdateNotification: function BG__showUpdateNotification() {
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.clearUserPref("app.update.postupdate");
|
2010-04-07 06:49:23 +04:00
|
|
|
|
|
|
|
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);
|
2010-04-12 18:33:10 +04:00
|
|
|
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
2010-04-07 06:49:23 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2011-11-05 01:45:01 +04:00
|
|
|
let notification = notifyBox.appendNotification(text, "post-update-notification",
|
|
|
|
null, notifyBox.PRIORITY_INFO_LOW,
|
|
|
|
buttons);
|
|
|
|
notification.persistence = -1; // Until user closes it
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-15 20:57:13 +04:00
|
|
|
#ifdef MOZ_TELEMETRY_REPORTING
|
2011-06-02 12:00:13 +04:00
|
|
|
_showTelemetryNotification: function BG__showTelemetryNotification() {
|
|
|
|
const PREF_TELEMETRY_PROMPTED = "toolkit.telemetry.prompted";
|
|
|
|
const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
|
2011-11-04 21:07:24 +04:00
|
|
|
const PREF_TELEMETRY_REJECTED = "toolkit.telemetry.rejected";
|
2011-06-02 12:00:13 +04:00
|
|
|
const PREF_TELEMETRY_INFOURL = "toolkit.telemetry.infoURL";
|
|
|
|
const PREF_TELEMETRY_SERVER_OWNER = "toolkit.telemetry.server_owner";
|
2012-02-23 18:37:04 +04:00
|
|
|
const PREF_TELEMETRY_ENABLED_BY_DEFAULT = "toolkit.telemetry.enabledByDefault";
|
|
|
|
const PREF_TELEMETRY_NOTIFIED_OPTOUT = "toolkit.telemetry.notifiedOptOut";
|
2011-10-04 02:05:59 +04:00
|
|
|
// This is used to reprompt users when privacy message changes
|
|
|
|
const TELEMETRY_PROMPT_REV = 2;
|
2011-06-02 12:00:13 +04:00
|
|
|
|
2012-02-23 18:37:04 +04:00
|
|
|
// Stick notifications onto the selected tab of the active browser window.
|
|
|
|
var win = this.getMostRecentBrowserWindow();
|
|
|
|
var tabbrowser = win.gBrowser;
|
|
|
|
var notifyBox = tabbrowser.getNotificationBox();
|
|
|
|
|
|
|
|
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
var productName = brandBundle.GetStringFromName("brandFullName");
|
|
|
|
var serverOwner = Services.prefs.getCharPref(PREF_TELEMETRY_SERVER_OWNER);
|
|
|
|
|
|
|
|
function appendTelemetryNotification(message, buttons, hideclose) {
|
2012-02-25 03:00:02 +04:00
|
|
|
let notification = notifyBox.appendNotification(message, "telemetry", null,
|
2012-02-23 18:37:04 +04:00
|
|
|
notifyBox.PRIORITY_INFO_LOW,
|
|
|
|
buttons);
|
|
|
|
if (hideclose)
|
|
|
|
notification.setAttribute("hideclose", hideclose);
|
2012-02-25 03:00:02 +04:00
|
|
|
notification.persistence = -1; // Until user closes it
|
|
|
|
return notification;
|
|
|
|
}
|
|
|
|
|
2012-02-23 18:37:04 +04:00
|
|
|
function appendLearnMoreLink(notification) {
|
|
|
|
let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
let link = notification.ownerDocument.createElementNS(XULNS, "label");
|
|
|
|
link.className = "text-link telemetry-text-link";
|
|
|
|
link.setAttribute("value", browserBundle.GetStringFromName("telemetryLinkLabel"));
|
|
|
|
let description = notification.ownerDocument.getAnonymousElementByAttribute(notification, "anonid", "messageText");
|
|
|
|
description.appendChild(link);
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
|
|
|
var telemetryEnabledByDefault = false;
|
|
|
|
try {
|
|
|
|
telemetryEnabledByDefault = Services.prefs.getBoolPref(PREF_TELEMETRY_ENABLED_BY_DEFAULT);
|
|
|
|
} catch(e) {}
|
|
|
|
if (telemetryEnabledByDefault) {
|
|
|
|
var telemetryNotifiedOptOut = false;
|
|
|
|
try {
|
|
|
|
telemetryNotifiedOptOut = Services.prefs.getBoolPref(PREF_TELEMETRY_NOTIFIED_OPTOUT);
|
|
|
|
} catch(e) {}
|
|
|
|
if (telemetryNotifiedOptOut)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var telemetryPrompt = browserBundle.formatStringFromName("telemetryOptOutPrompt",
|
|
|
|
[productName, serverOwner, productName], 3);
|
|
|
|
|
|
|
|
Services.prefs.setBoolPref(PREF_TELEMETRY_NOTIFIED_OPTOUT, true);
|
|
|
|
|
|
|
|
let notification = appendTelemetryNotification(telemetryPrompt, null, false);
|
|
|
|
let link = appendLearnMoreLink(notification);
|
|
|
|
link.addEventListener('click', function() {
|
|
|
|
// Open the learn more url in a new tab
|
|
|
|
let url = Services.urlFormatter.formatURLPref("app.support.baseURL");
|
|
|
|
url += "how-can-i-help-submitting-performance-data";
|
|
|
|
tabbrowser.selectedTab = tabbrowser.addTab(url);
|
|
|
|
// Remove the notification on which the user clicked
|
|
|
|
notification.parentNode.removeNotification(notification, true);
|
|
|
|
}, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-04 02:05:59 +04:00
|
|
|
var telemetryPrompted = null;
|
2011-06-02 12:00:13 +04:00
|
|
|
try {
|
2011-10-04 02:05:59 +04:00
|
|
|
telemetryPrompted = Services.prefs.getIntPref(PREF_TELEMETRY_PROMPTED);
|
2011-06-02 12:00:13 +04:00
|
|
|
} catch(e) {}
|
2011-10-04 02:05:59 +04:00
|
|
|
// If the user has seen the latest telemetry prompt, do not prompt again
|
|
|
|
// else clear old prefs and reprompt
|
|
|
|
if (telemetryPrompted === TELEMETRY_PROMPT_REV)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Services.prefs.clearUserPref(PREF_TELEMETRY_PROMPTED);
|
|
|
|
Services.prefs.clearUserPref(PREF_TELEMETRY_ENABLED);
|
|
|
|
|
2012-03-15 01:38:35 +04:00
|
|
|
var telemetryPrompt = browserBundle.formatStringFromName("telemetryOptInPrompt", [productName, serverOwner], 2);
|
2011-06-02 12:00:13 +04:00
|
|
|
|
|
|
|
var buttons = [
|
|
|
|
{
|
2011-11-05 02:19:45 +04:00
|
|
|
label: browserBundle.GetStringFromName("telemetryYesButtonLabel2"),
|
2011-06-02 12:00:13 +04:00
|
|
|
accessKey: browserBundle.GetStringFromName("telemetryYesButtonAccessKey"),
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
|
|
|
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: browserBundle.GetStringFromName("telemetryNoButtonLabel"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("telemetryNoButtonAccessKey"),
|
|
|
|
popup: null,
|
2011-11-04 21:07:24 +04:00
|
|
|
callback: function(aNotificationBar, aButton) {
|
|
|
|
Services.prefs.setBoolPref(PREF_TELEMETRY_REJECTED, true);
|
|
|
|
}
|
2011-06-02 12:00:13 +04:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
// Set pref to indicate we've shown the notification.
|
2011-10-04 02:05:59 +04:00
|
|
|
Services.prefs.setIntPref(PREF_TELEMETRY_PROMPTED, TELEMETRY_PROMPT_REV);
|
2011-06-02 12:00:13 +04:00
|
|
|
|
2012-02-23 18:37:04 +04:00
|
|
|
let notification = appendTelemetryNotification(telemetryPrompt, buttons, true);
|
|
|
|
let link = appendLearnMoreLink(notification);
|
2011-06-02 12:00:13 +04:00
|
|
|
link.addEventListener('click', function() {
|
|
|
|
// Open the learn more url in a new tab
|
2012-02-23 18:37:04 +04:00
|
|
|
tabbrowser.selectedTab = tabbrowser.addTab(Services.prefs.getCharPref(PREF_TELEMETRY_INFOURL));
|
2011-06-02 12:00:13 +04:00
|
|
|
// Remove the notification on which the user clicked
|
|
|
|
notification.parentNode.removeNotification(notification, true);
|
|
|
|
// Add a new notification to that tab, with no "Learn more" link
|
2012-02-23 18:37:04 +04:00
|
|
|
notifyBox = tabbrowser.getNotificationBox();
|
|
|
|
appendTelemetryNotification(telemetryPrompt, buttons, true);
|
2011-06-02 12:00:13 +04:00
|
|
|
}, false);
|
|
|
|
},
|
2011-07-15 20:57:13 +04:00
|
|
|
#endif
|
2011-06-02 12:00:13 +04:00
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_showPluginUpdatePage: function BG__showPluginUpdatePage() {
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setBoolPref(PREF_PLUGINS_NOTIFYUSER, false);
|
2009-10-02 15:26:04 +04:00
|
|
|
|
|
|
|
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-31 09:42:02 +03:00
|
|
|
|
2007-05-03 12:56:41 +04:00
|
|
|
/**
|
|
|
|
* Initialize Places
|
2008-11-12 23:45:53 +03: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 19:43:17 +03:00
|
|
|
*
|
|
|
|
* - browser.places.importBookmarksHTML
|
2008-11-12 23:45:53 +03:00
|
|
|
* Set to true will import the bookmarks.html file from the profile folder.
|
2008-04-08 22:42:53 +04: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 23:33:01 +04:00
|
|
|
* - browser.bookmarks.restore_default_bookmarks
|
|
|
|
* Set to true by safe-mode dialog to indicate we must restore default
|
|
|
|
* bookmarks.
|
2007-05-03 12:56:41 +04:00
|
|
|
*/
|
2009-12-18 00:28:08 +03:00
|
|
|
_initPlaces: function BG__initPlaces() {
|
2008-11-12 23:45:53 +03: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).
|
|
|
|
// If the database is corrupt or has been newly created we should
|
|
|
|
// import bookmarks.
|
2010-11-23 16:04:07 +03:00
|
|
|
var dbStatus = PlacesUtils.history.databaseStatus;
|
2012-03-23 11:15:36 +04:00
|
|
|
var importBookmarks = !this._initialMigrationPerformed &&
|
|
|
|
(dbStatus == PlacesUtils.history.DATABASE_STATUS_CREATE ||
|
|
|
|
dbStatus == PlacesUtils.history.DATABASE_STATUS_CORRUPT);
|
2009-02-09 21:16:02 +03:00
|
|
|
|
2008-11-12 23:45:53 +03:00
|
|
|
// Check if user or an extension has required to import bookmarks.html
|
|
|
|
var importBookmarksHTML = false;
|
|
|
|
try {
|
|
|
|
importBookmarksHTML =
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.getBoolPref("browser.places.importBookmarksHTML");
|
2008-11-12 23:45:53 +03:00
|
|
|
if (importBookmarksHTML)
|
|
|
|
importBookmarks = true;
|
|
|
|
} catch(ex) {}
|
2007-12-04 11:08:33 +03:00
|
|
|
|
2008-11-12 23:45:53 +03:00
|
|
|
// Check if Safe Mode or the user has required to restore bookmarks from
|
|
|
|
// default profile's bookmarks.html
|
2008-04-02 23:33:01 +04:00
|
|
|
var restoreDefaultBookmarks = false;
|
2007-05-03 12:56:41 +04:00
|
|
|
try {
|
2008-11-12 23:45:53 +03:00
|
|
|
restoreDefaultBookmarks =
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
2008-11-12 23:45:53 +03:00
|
|
|
if (restoreDefaultBookmarks) {
|
2009-09-29 14:44:18 +04:00
|
|
|
// Ensure that we already have a bookmarks backup for today.
|
|
|
|
this._backupBookmarks();
|
2008-11-12 23:45:53 +03:00
|
|
|
importBookmarks = true;
|
|
|
|
}
|
2007-05-03 12:56:41 +04:00
|
|
|
} catch(ex) {}
|
2007-12-04 14:22:14 +03:00
|
|
|
|
2008-11-12 23:45:53 +03: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
|
2009-09-29 14:44:18 +04:00
|
|
|
var bookmarksBackupFile = PlacesUtils.backups.getMostRecent("json");
|
|
|
|
if (bookmarksBackupFile) {
|
2008-11-12 23:45:53 +03:00
|
|
|
// restore from JSON backup
|
2009-10-06 17:47:58 +04:00
|
|
|
PlacesUtils.restoreBookmarksFromJSONFile(bookmarksBackupFile);
|
2008-11-12 23:45:53 +03:00
|
|
|
importBookmarks = false;
|
|
|
|
}
|
|
|
|
else {
|
2008-12-09 23:39:32 +03:00
|
|
|
// We have created a new database but we don't have any backup available
|
2008-11-12 23:45:53 +03:00
|
|
|
importBookmarks = true;
|
2008-12-09 23:39:32 +03: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 23:45:53 +03:00
|
|
|
}
|
2008-04-02 23:33:01 +04:00
|
|
|
}
|
|
|
|
|
2010-03-24 04:17:49 +03: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-27 03:08:50 +03:00
|
|
|
if (!importBookmarks) {
|
2012-03-23 11:15:36 +04:00
|
|
|
// Now apply distribution customized bookmarks.
|
|
|
|
// This should always run after Places initialization.
|
|
|
|
this._distributionCustomizer.applyBookmarks();
|
2007-11-27 03:08:50 +03:00
|
|
|
this.ensurePlacesDefaultQueriesInitialized();
|
|
|
|
}
|
2008-03-13 22:25:49 +03:00
|
|
|
else {
|
2010-03-24 04:17:49 +03:00
|
|
|
// An import operation is about to run.
|
2009-01-13 13:48:28 +03:00
|
|
|
// Don't try to recreate smart bookmarks if autoExportHTML is true or
|
|
|
|
// smart bookmarks are disabled.
|
|
|
|
var autoExportHTML = false;
|
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
2009-01-13 13:48:28 +03:00
|
|
|
} catch(ex) {}
|
|
|
|
var smartBookmarksVersion = 0;
|
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion");
|
2009-01-13 13:48:28 +03:00
|
|
|
} catch(ex) {}
|
|
|
|
if (!autoExportHTML && smartBookmarksVersion != -1)
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
2008-11-12 23:45:53 +03:00
|
|
|
|
2008-11-18 20:25:39 +03:00
|
|
|
// Get bookmarks.html file location
|
2008-11-12 23:45:53 +03:00
|
|
|
var dirService = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
|
|
|
|
2010-08-11 02:15:26 +04:00
|
|
|
var bookmarksURI = null;
|
2008-11-18 20:25:39 +03:00
|
|
|
if (restoreDefaultBookmarks) {
|
|
|
|
// User wants to restore bookmarks.html file from default profile folder
|
2010-08-11 02:15:26 +04:00
|
|
|
bookmarksURI = NetUtil.newURI("resource:///defaults/profile/bookmarks.html");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
|
|
|
|
if (bookmarksFile.exists())
|
|
|
|
bookmarksURI = NetUtil.newURI(bookmarksFile);
|
2007-05-03 12:56:41 +04:00
|
|
|
}
|
2008-11-18 20:25:39 +03:00
|
|
|
|
2010-08-11 02:15:26 +04:00
|
|
|
if (bookmarksURI) {
|
2010-03-24 04:17:49 +03:00
|
|
|
// Import from bookmarks.html file.
|
2008-11-18 20:25:39 +03:00
|
|
|
try {
|
2012-03-23 11:15:36 +04:00
|
|
|
BookmarkHTMLUtils.importFromURL(bookmarksURI.spec, true, (function (success) {
|
|
|
|
if (success) {
|
|
|
|
// Now apply distribution customized bookmarks.
|
|
|
|
// This should always run after Places initialization.
|
|
|
|
this._distributionCustomizer.applyBookmarks();
|
|
|
|
// Ensure that smart bookmarks are created once the operation is
|
|
|
|
// complete.
|
|
|
|
this.ensurePlacesDefaultQueriesInitialized();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Cu.reportError("Bookmarks.html file could be corrupt.");
|
|
|
|
}
|
|
|
|
}).bind(this));
|
2008-11-18 20:25:39 +03:00
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError("Bookmarks.html file could be corrupt. " + err);
|
|
|
|
}
|
2008-11-12 23:45:53 +03:00
|
|
|
}
|
2012-03-23 11:15:36 +04:00
|
|
|
else {
|
2008-11-18 20:25:39 +03:00
|
|
|
Cu.reportError("Unable to find bookmarks.html file.");
|
2012-03-23 11:15:36 +04:00
|
|
|
}
|
2008-03-13 22:25:49 +03:00
|
|
|
|
2008-11-12 23:45:53 +03:00
|
|
|
// Reset preferences, so we won't try to import again at next run
|
|
|
|
if (importBookmarksHTML)
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setBoolPref("browser.places.importBookmarksHTML", false);
|
2008-11-12 23:45:53 +03:00
|
|
|
if (restoreDefaultBookmarks)
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks",
|
|
|
|
false);
|
2007-05-03 12:56:41 +04:00
|
|
|
}
|
2008-03-13 22:25:49 +03:00
|
|
|
|
|
|
|
// Initialize bookmark archiving on idle.
|
|
|
|
// Once a day, either on idle or shutdown, bookmarks are backed up.
|
2009-09-29 14:44:18 +04:00
|
|
|
if (!this._isIdleObserver) {
|
|
|
|
this._idleService.addIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
|
|
|
|
this._isIdleObserver = true;
|
|
|
|
}
|
2007-05-03 12:56:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Places shut-down tasks
|
2009-09-29 14:44:18 +04:00
|
|
|
* - back up bookmarks if needed.
|
|
|
|
* - export bookmarks as HTML, if so configured.
|
2008-03-13 22:25:49 +03:00
|
|
|
*
|
|
|
|
* Note: quit-application-granted notification is received twice
|
|
|
|
* so replace this method with a no-op when first called.
|
2007-05-03 12:56:41 +04:00
|
|
|
*/
|
2009-12-18 00:28:08 +03:00
|
|
|
_shutdownPlaces: function BG__shutdownPlaces() {
|
2010-04-22 16:53:54 +04:00
|
|
|
if (this._isIdleObserver) {
|
|
|
|
this._idleService.removeIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
|
|
|
|
this._isIdleObserver = false;
|
|
|
|
}
|
2009-09-29 14:44:18 +04:00
|
|
|
this._backupBookmarks();
|
2008-03-13 22:25:49 +03:00
|
|
|
|
|
|
|
// Backup bookmarks to bookmarks.html to support apps that depend
|
|
|
|
// on the legacy format.
|
|
|
|
var autoExportHTML = false;
|
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
2009-09-29 14:44:18 +04:00
|
|
|
} catch(ex) { /* Don't export */ }
|
2008-03-13 22:25:49 +03:00
|
|
|
|
|
|
|
if (autoExportHTML) {
|
2007-06-17 01:23:17 +04:00
|
|
|
Cc["@mozilla.org/browser/places/import-export-service;1"].
|
2008-03-13 22:25:49 +03:00
|
|
|
getService(Ci.nsIPlacesImportExportService).
|
|
|
|
backupBookmarksFile();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2009-09-29 14:44:18 +04:00
|
|
|
* Backup bookmarks if needed.
|
2008-03-13 22:25:49 +03:00
|
|
|
*/
|
2009-12-18 00:28:08 +03:00
|
|
|
_backupBookmarks: function BG__backupBookmarks() {
|
2009-09-29 14:44:18 +04:00
|
|
|
let lastBackupFile = PlacesUtils.backups.getMostRecent();
|
2008-03-13 22:25:49 +03:00
|
|
|
|
2009-09-29 14:44:18 +04: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 22:25:49 +03:00
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
maxBackups = Services.prefs.getIntPref("browser.bookmarks.max_backups");
|
2009-09-29 14:44:18 +04:00
|
|
|
}
|
|
|
|
catch(ex) { /* Use default. */ }
|
2008-03-13 22:25:49 +03:00
|
|
|
|
2009-09-29 14:44:18 +04:00
|
|
|
PlacesUtils.backups.create(maxBackups); // Don't force creation.
|
2008-03-13 22:25:49 +03:00
|
|
|
}
|
2007-05-03 12:56:41 +04:00
|
|
|
},
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2008-12-30 15:44:55 +03:00
|
|
|
/**
|
|
|
|
* Show the notificationBox for a locked places database.
|
|
|
|
*/
|
2009-12-18 00:28:08 +03:00
|
|
|
_showPlacesLockedNotificationBox: function BG__showPlacesLockedNotificationBox() {
|
2010-04-12 18:33:10 +04:00
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
2008-12-30 15:44:55 +03:00
|
|
|
var applicationName = brandBundle.GetStringFromName("brandShortName");
|
2010-04-12 18:33:10 +04:00
|
|
|
var placesBundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");
|
2008-12-30 15:44:55 +03:00
|
|
|
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();
|
2011-11-05 01:45:01 +04:00
|
|
|
var notification = notifyBox.appendNotification(text, title, null,
|
|
|
|
notifyBox.PRIORITY_CRITICAL_MEDIUM,
|
|
|
|
buttons);
|
|
|
|
notification.persistence = -1; // Until user closes it
|
2008-12-30 15:44:55 +03:00
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_migrateUI: function BG__migrateUI() {
|
2012-01-06 17:19:57 +04:00
|
|
|
const UI_VERSION = 6;
|
2010-12-22 21:26:18 +03:00
|
|
|
const BROWSER_DOCURL = "chrome://browser/content/browser.xul#";
|
2010-07-09 23:44:01 +04:00
|
|
|
let currentUIVersion = 0;
|
2008-02-04 22:37:26 +03:00
|
|
|
try {
|
2010-07-09 23:44:01 +04:00
|
|
|
currentUIVersion = Services.prefs.getIntPref("browser.migration.version");
|
2008-02-04 22:37:26 +03:00
|
|
|
} catch(ex) {}
|
2010-07-09 23:44:01 +04:00
|
|
|
if (currentUIVersion >= UI_VERSION)
|
|
|
|
return;
|
2008-02-04 22:37:26 +03:00
|
|
|
|
2010-07-09 23:44:01 +04:00
|
|
|
this._rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
|
|
|
|
this._dataSource = this._rdf.GetDataSource("rdf:local-store");
|
|
|
|
this._dirty = false;
|
2008-02-04 22:37:26 +03:00
|
|
|
|
2010-07-09 23:44:01 +04:00
|
|
|
if (currentUIVersion < 2) {
|
|
|
|
// This code adds the customizable bookmarks button.
|
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
2010-12-22 21:26:18 +03:00
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
2010-07-09 23:44:01 +04:00
|
|
|
let currentset = this._getPersist(toolbarResource, currentsetResource);
|
|
|
|
// Need to migrate only if toolbar is customized and the element is not found.
|
|
|
|
if (currentset &&
|
|
|
|
currentset.indexOf("bookmarks-menu-button-container") == -1) {
|
2012-03-28 12:33:17 +04:00
|
|
|
currentset += ",bookmarks-menu-button-container";
|
2010-07-09 23:44:01 +04:00
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
|
|
|
}
|
|
|
|
}
|
2008-02-04 22:37:26 +03:00
|
|
|
|
2010-09-03 06:20:12 +04:00
|
|
|
if (currentUIVersion < 3) {
|
|
|
|
// This code merges the reload/stop/go button into the url bar.
|
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
2010-12-22 21:26:18 +03:00
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
2010-09-03 06:20:12 +04:00
|
|
|
let currentset = this._getPersist(toolbarResource, currentsetResource);
|
|
|
|
// Need to migrate only if toolbar is customized and all 3 elements are found.
|
|
|
|
if (currentset &&
|
|
|
|
currentset.indexOf("reload-button") != -1 &&
|
|
|
|
currentset.indexOf("stop-button") != -1 &&
|
|
|
|
currentset.indexOf("urlbar-container") != -1 &&
|
|
|
|
currentset.indexOf("urlbar-container,reload-button,stop-button") == -1) {
|
2010-12-09 08:24:46 +03:00
|
|
|
currentset = currentset.replace(/(^|,)reload-button($|,)/, "$1$2")
|
|
|
|
.replace(/(^|,)stop-button($|,)/, "$1$2")
|
|
|
|
.replace(/(^|,)urlbar-container($|,)/,
|
2010-09-03 06:20:12 +04:00
|
|
|
"$1urlbar-container,reload-button,stop-button$2");
|
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-09 08:24:46 +03:00
|
|
|
if (currentUIVersion < 4) {
|
|
|
|
// This code moves the home button to the immediate left of the bookmarks menu button.
|
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
2010-12-22 21:26:18 +03:00
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
2010-12-09 08:24:46 +03:00
|
|
|
let currentset = this._getPersist(toolbarResource, currentsetResource);
|
|
|
|
// Need to migrate only if toolbar is customized and the elements are found.
|
|
|
|
if (currentset &&
|
|
|
|
currentset.indexOf("home-button") != -1 &&
|
|
|
|
currentset.indexOf("bookmarks-menu-button-container") != -1) {
|
|
|
|
currentset = currentset.replace(/(^|,)home-button($|,)/, "$1$2")
|
|
|
|
.replace(/(^|,)bookmarks-menu-button-container($|,)/,
|
|
|
|
"$1home-button,bookmarks-menu-button-container$2");
|
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-22 21:26:18 +03:00
|
|
|
if (currentUIVersion < 5) {
|
|
|
|
// This code uncollapses PersonalToolbar if its collapsed status is not
|
|
|
|
// persisted, and user customized it or changed default bookmarks.
|
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "PersonalToolbar");
|
|
|
|
let collapsedResource = this._rdf.GetResource("collapsed");
|
|
|
|
let collapsed = this._getPersist(toolbarResource, collapsedResource);
|
|
|
|
// If the user does not have a persisted value for the toolbar's
|
|
|
|
// "collapsed" attribute, try to determine whether it's customized.
|
|
|
|
if (collapsed === null) {
|
|
|
|
// We consider the toolbar customized if it has more than
|
|
|
|
// 3 children, or if it has a persisted currentset value.
|
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
|
|
|
let toolbarIsCustomized = !!this._getPersist(toolbarResource,
|
|
|
|
currentsetResource);
|
|
|
|
function getToolbarFolderCount() {
|
|
|
|
let toolbarFolder =
|
|
|
|
PlacesUtils.getFolderContents(PlacesUtils.toolbarFolderId).root;
|
|
|
|
let toolbarChildCount = toolbarFolder.childCount;
|
|
|
|
toolbarFolder.containerOpen = false;
|
|
|
|
return toolbarChildCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toolbarIsCustomized || getToolbarFolderCount() > 3) {
|
|
|
|
this._setPersist(toolbarResource, collapsedResource, "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-06 17:19:57 +04:00
|
|
|
if (currentUIVersion < 6) {
|
|
|
|
// convert tabsontop attribute to pref
|
|
|
|
let toolboxResource = this._rdf.GetResource(BROWSER_DOCURL + "navigator-toolbox");
|
|
|
|
let tabsOnTopResource = this._rdf.GetResource("tabsontop");
|
|
|
|
let tabsOnTopAttribute = this._getPersist(toolboxResource, tabsOnTopResource);
|
|
|
|
if (tabsOnTopAttribute)
|
|
|
|
Services.prefs.setBoolPref("browser.tabs.onTop", tabsOnTopAttribute == "true");
|
|
|
|
}
|
|
|
|
|
2010-07-09 23:44:01 +04:00
|
|
|
if (this._dirty)
|
|
|
|
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
|
2008-02-04 22:37:26 +03:00
|
|
|
|
2010-07-09 23:44:01 +04:00
|
|
|
delete this._rdf;
|
|
|
|
delete this._dataSource;
|
|
|
|
|
|
|
|
// Update the migration version.
|
|
|
|
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
|
2008-02-04 22:37:26 +03:00
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_getPersist: function BG__getPersist(aSource, aProperty) {
|
2008-02-20 12:56:52 +03:00
|
|
|
var target = this._dataSource.GetTarget(aSource, aProperty, true);
|
2008-02-04 22:37:26 +03:00
|
|
|
if (target instanceof Ci.nsIRDFLiteral)
|
|
|
|
return target.Value;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_setPersist: function BG__setPersist(aSource, aProperty, aTarget) {
|
2008-02-20 12:56:52 +03:00
|
|
|
this._dirty = true;
|
2008-02-04 22:37:26 +03:00
|
|
|
try {
|
2008-02-20 12:56:52 +03:00
|
|
|
var oldTarget = this._dataSource.GetTarget(aSource, aProperty, true);
|
2008-02-04 22:37:26 +03:00
|
|
|
if (oldTarget) {
|
|
|
|
if (aTarget)
|
2008-02-20 12:56:52 +03:00
|
|
|
this._dataSource.Change(aSource, aProperty, oldTarget, this._rdf.GetLiteral(aTarget));
|
2008-02-04 22:37:26 +03:00
|
|
|
else
|
2008-02-20 12:56:52 +03:00
|
|
|
this._dataSource.Unassert(aSource, aProperty, oldTarget);
|
2008-02-04 22:37:26 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-02-20 12:56:52 +03:00
|
|
|
this._dataSource.Assert(aSource, aProperty, this._rdf.GetLiteral(aTarget), true);
|
2008-02-04 22:37:26 +03:00
|
|
|
}
|
2010-12-22 21:26:18 +03:00
|
|
|
|
|
|
|
// Add the entry to the persisted set for this document if it's not there.
|
|
|
|
// This code is mostly borrowed from nsXULDocument::Persist.
|
|
|
|
let docURL = aSource.ValueUTF8.split("#")[0];
|
|
|
|
let docResource = this._rdf.GetResource(docURL);
|
|
|
|
let persistResource = this._rdf.GetResource("http://home.netscape.com/NC-rdf#persist");
|
|
|
|
if (!this._dataSource.HasAssertion(docResource, persistResource, aSource, true)) {
|
|
|
|
this._dataSource.Assert(docResource, persistResource, aSource, true);
|
|
|
|
}
|
2008-02-04 22:37:26 +03:00
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// ------------------------------
|
|
|
|
// public nsIBrowserGlue members
|
|
|
|
// ------------------------------
|
2010-09-03 06:20:12 +04:00
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
sanitize: function BG_sanitize(aParentWindow) {
|
2009-10-14 13:53:13 +04:00
|
|
|
this._sanitizer.sanitize(aParentWindow);
|
2007-09-06 07:02:22 +04:00
|
|
|
},
|
2007-11-27 03:08:51 +03:00
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
ensurePlacesDefaultQueriesInitialized:
|
|
|
|
function BG_ensurePlacesDefaultQueriesInitialized() {
|
2009-03-26 15:58:32 +03: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.
|
2012-04-07 03:17:53 +04:00
|
|
|
const SMART_BOOKMARKS_VERSION = 4;
|
2008-04-08 22:42:53 +04:00
|
|
|
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
|
|
|
const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion";
|
|
|
|
|
2009-10-14 13:53:13 +04:00
|
|
|
// TODO bug 399268: should this be a pref?
|
2008-04-08 22:42:53 +04:00
|
|
|
const MAX_RESULTS = 10;
|
|
|
|
|
2010-11-23 16:04:07 +03:00
|
|
|
// Get current smart bookmarks version. If not set, create them.
|
|
|
|
let smartBookmarksCurrentVersion = 0;
|
2007-11-27 03:08:50 +03:00
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
smartBookmarksCurrentVersion = Services.prefs.getIntPref(SMART_BOOKMARKS_PREF);
|
2010-11-23 16:04:07 +03:00
|
|
|
} catch(ex) {}
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2010-11-23 16:04:07 +03:00
|
|
|
// If version is current or smart bookmarks are disabled, just bail out.
|
2008-04-08 22:42:53 +04:00
|
|
|
if (smartBookmarksCurrentVersion == -1 ||
|
2010-11-23 16:04:07 +03:00
|
|
|
smartBookmarksCurrentVersion >= SMART_BOOKMARKS_VERSION) {
|
2007-11-27 03:08:50 +03:00
|
|
|
return;
|
2010-11-23 16:04:07 +03:00
|
|
|
}
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2010-11-23 16:04:07 +03:00
|
|
|
let batch = {
|
2009-12-18 00:28:08 +03:00
|
|
|
runBatched: function BG_EPDQI_runBatched() {
|
2010-11-23 16:04:07 +03:00
|
|
|
let menuIndex = 0;
|
|
|
|
let toolbarIndex = 0;
|
|
|
|
let bundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");
|
|
|
|
|
|
|
|
let smartBookmarks = {
|
|
|
|
MostVisited: {
|
|
|
|
title: bundle.GetStringFromName("mostVisitedTitle"),
|
2012-04-07 03:17:53 +04:00
|
|
|
uri: NetUtil.newURI("place:sort=" +
|
2010-11-23 16:04:07 +03:00
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS),
|
|
|
|
parent: PlacesUtils.toolbarFolderId,
|
|
|
|
position: toolbarIndex++,
|
|
|
|
newInVersion: 1
|
|
|
|
},
|
|
|
|
RecentlyBookmarked: {
|
|
|
|
title: bundle.GetStringFromName("recentlyBookmarkedTitle"),
|
|
|
|
uri: NetUtil.newURI("place:folder=BOOKMARKS_MENU" +
|
2008-04-08 22:42:53 +04:00
|
|
|
"&folder=UNFILED_BOOKMARKS" +
|
|
|
|
"&folder=TOOLBAR" +
|
|
|
|
"&queryType=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS +
|
|
|
|
"&excludeQueries=1"),
|
2010-11-23 16:04:07 +03:00
|
|
|
parent: PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
position: menuIndex++,
|
|
|
|
newInVersion: 1
|
|
|
|
},
|
|
|
|
RecentTags: {
|
|
|
|
title: bundle.GetStringFromName("recentTagsTitle"),
|
|
|
|
uri: NetUtil.newURI("place:"+
|
|
|
|
"type=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS),
|
|
|
|
parent: PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
position: menuIndex++,
|
|
|
|
newInVersion: 1
|
2012-04-19 19:15:30 +04:00
|
|
|
}
|
2010-11-23 16:04:07 +03:00
|
|
|
};
|
|
|
|
|
2009-03-26 15:58:32 +03: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.
|
2010-11-23 16:04:07 +03:00
|
|
|
let smartBookmarkItemIds = PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
|
|
|
smartBookmarkItemIds.forEach(function (itemId) {
|
|
|
|
let queryId = PlacesUtils.annotations.getItemAnnotation(itemId, SMART_BOOKMARKS_ANNO);
|
|
|
|
if (queryId in smartBookmarks) {
|
|
|
|
let smartBookmark = smartBookmarks[queryId];
|
2012-04-19 19:15:30 +04:00
|
|
|
smartBookmark.itemId = itemId;
|
|
|
|
smartBookmark.parent = PlacesUtils.bookmarks.getFolderIdForItem(itemId);
|
|
|
|
smartBookmark.position = PlacesUtils.bookmarks.getItemIndex(itemId);
|
2010-11-23 16:04:07 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-04-08 22:42:53 +04:00
|
|
|
// 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.
|
2010-11-23 16:04:07 +03:00
|
|
|
PlacesUtils.annotations.removeItemAnnotation(itemId, SMART_BOOKMARKS_ANNO);
|
2008-04-08 22:42:53 +04:00
|
|
|
}
|
2010-11-23 16:04:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
for (let queryId in smartBookmarks) {
|
|
|
|
let smartBookmark = smartBookmarks[queryId];
|
2008-04-08 22:42:53 +04:00
|
|
|
|
2009-03-26 15:58:32 +03: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 &&
|
2010-11-23 16:04:07 +03:00
|
|
|
!smartBookmark.itemId)
|
2009-03-26 15:58:32 +03:00
|
|
|
continue;
|
|
|
|
|
2010-11-23 16:04:07 +03:00
|
|
|
// Remove old version of the smart bookmark if it exists, since it
|
|
|
|
// will be replaced in place.
|
|
|
|
if (smartBookmark.itemId) {
|
|
|
|
PlacesUtils.bookmarks.removeItem(smartBookmark.itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new smart bookmark and store its updated itemId.
|
|
|
|
smartBookmark.itemId =
|
|
|
|
PlacesUtils.bookmarks.insertBookmark(smartBookmark.parent,
|
|
|
|
smartBookmark.uri,
|
|
|
|
smartBookmark.position,
|
|
|
|
smartBookmark.title);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(smartBookmark.itemId,
|
|
|
|
SMART_BOOKMARKS_ANNO,
|
|
|
|
queryId, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2008-04-08 22:42:53 +04:00
|
|
|
}
|
2010-09-03 06:20:12 +04:00
|
|
|
|
2008-04-08 22:42:53 +04:00
|
|
|
// If we are creating all Smart Bookmarks from ground up, add a
|
|
|
|
// separator below them in the bookmarks menu.
|
2009-03-26 15:58:32 +03:00
|
|
|
if (smartBookmarksCurrentVersion == 0 &&
|
2010-04-28 11:17:09 +04:00
|
|
|
smartBookmarkItemIds.length == 0) {
|
2010-11-23 16:04:07 +03:00
|
|
|
let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
menuIndex);
|
2010-04-28 11:17:09 +04:00
|
|
|
// Don't add a separator if the menu was empty or there is one already.
|
2010-11-23 16:04:07 +03:00
|
|
|
if (id != -1 &&
|
|
|
|
PlacesUtils.bookmarks.getItemType(id) != PlacesUtils.bookmarks.TYPE_SEPARATOR) {
|
|
|
|
PlacesUtils.bookmarks.insertSeparator(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
menuIndex);
|
|
|
|
}
|
2010-04-28 11:17:09 +04:00
|
|
|
}
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2010-11-23 16:04:07 +03:00
|
|
|
PlacesUtils.bookmarks.runInBatchMode(batch, null);
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
|
|
|
finally {
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
|
|
|
|
Services.prefs.savePrefFile(null);
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-01-13 23:18:03 +03:00
|
|
|
#ifndef XP_WIN
|
2008-10-31 09:42:02 +03:00
|
|
|
#define BROKEN_WM_Z_ORDER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// this returns the most recent non-popup browser window
|
2009-12-18 00:28:08 +03:00
|
|
|
getMostRecentBrowserWindow: function BG_getMostRecentBrowserWindow() {
|
2010-01-24 13:20:10 +03:00
|
|
|
function isFullBrowserWindow(win) {
|
|
|
|
return !win.closed &&
|
2012-01-24 04:37:54 +04:00
|
|
|
win.toolbar.visible;
|
2010-01-24 13:20:10 +03:00
|
|
|
}
|
2008-10-31 09:42:02 +03:00
|
|
|
|
|
|
|
#ifdef BROKEN_WM_Z_ORDER
|
2010-04-12 18:33:10 +04:00
|
|
|
var win = Services.wm.getMostRecentWindow("navigator:browser");
|
2008-10-31 09:42:02 +03:00
|
|
|
|
|
|
|
// if we're lucky, this isn't a popup, and we can just return this
|
2010-01-24 13:20:10 +03:00
|
|
|
if (win && !isFullBrowserWindow(win)) {
|
2008-10-31 09:42:02 +03:00
|
|
|
win = null;
|
2010-04-12 18:33:10 +04:00
|
|
|
let windowList = Services.wm.getEnumerator("navigator:browser");
|
2008-10-31 09:42:02 +03:00
|
|
|
// this is oldest to newest, so this gets a bit ugly
|
|
|
|
while (windowList.hasMoreElements()) {
|
2010-01-24 13:20:10 +03:00
|
|
|
let nextWin = windowList.getNext();
|
|
|
|
if (isFullBrowserWindow(nextWin))
|
2008-10-31 09:42:02 +03:00
|
|
|
win = nextWin;
|
|
|
|
}
|
|
|
|
}
|
2010-01-24 13:20:10 +03:00
|
|
|
return win;
|
2008-10-31 09:42:02 +03:00
|
|
|
#else
|
2010-04-12 18:33:10 +04:00
|
|
|
var windowList = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
|
2010-01-24 13:20:10 +03:00
|
|
|
while (windowList.hasMoreElements()) {
|
|
|
|
let win = windowList.getNext();
|
|
|
|
if (isFullBrowserWindow(win))
|
|
|
|
return win;
|
2008-10-31 09:42:02 +03:00
|
|
|
}
|
2010-01-24 13:20:10 +03:00
|
|
|
return null;
|
2008-10-31 09:42:02 +03:00
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// for XPCOM
|
|
|
|
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),
|
2008-04-08 22:43:40 +04:00
|
|
|
|
2007-09-27 23:37:47 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIBrowserGlue]),
|
2008-04-08 22:43:40 +04:00
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// redefine the default factory for XPCOMUtils
|
|
|
|
_xpcom_factory: BrowserGlueServiceFactory,
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
2008-04-08 22:43:40 +04:00
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
function ContentPermissionPrompt() {}
|
2008-10-23 22:01:32 +04:00
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
ContentPermissionPrompt.prototype = {
|
|
|
|
classID: Components.ID("{d8903bf6-68d5-4e97-bcd1-e4d3012f721a}"),
|
2008-10-23 22:01:32 +04:00
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
|
2010-04-09 21:45:25 +04:00
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
prompt: function CPP_prompt(request) {
|
|
|
|
|
|
|
|
if (request.type != "geolocation") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var requestingURI = request.uri;
|
2010-04-09 21:45:25 +04:00
|
|
|
|
|
|
|
// Ignore requests from non-nsIStandardURLs
|
|
|
|
if (!(requestingURI instanceof Ci.nsIStandardURL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var result = Services.perms.testExactPermission(requestingURI, "geo");
|
2009-04-16 01:49:11 +04:00
|
|
|
|
2009-05-07 02:38:50 +04:00
|
|
|
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
|
|
request.allow();
|
|
|
|
return;
|
|
|
|
}
|
2010-09-03 06:20:12 +04:00
|
|
|
|
2009-05-07 02:38:50 +04:00
|
|
|
if (result == Ci.nsIPermissionManager.DENY_ACTION) {
|
|
|
|
request.cancel();
|
|
|
|
return;
|
2009-04-16 01:49:11 +04:00
|
|
|
}
|
|
|
|
|
2008-10-23 22:01:32 +04: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;
|
|
|
|
}
|
|
|
|
|
2010-04-09 21:45:25 +04:00
|
|
|
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
2009-04-16 01:49:11 +04:00
|
|
|
|
2010-04-09 21:45:25 +04:00
|
|
|
var mainAction = {
|
|
|
|
label: browserBundle.GetStringFromName("geolocation.shareLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.shareLocation.accesskey"),
|
|
|
|
callback: function(notification) {
|
|
|
|
request.allow();
|
|
|
|
},
|
|
|
|
};
|
2009-04-16 01:49:11 +04:00
|
|
|
|
2010-04-09 21:45:25 +04:00
|
|
|
var message;
|
|
|
|
var secondaryActions = [];
|
|
|
|
|
|
|
|
// Different message/options if it is a local file
|
|
|
|
if (requestingURI.schemeIs("file")) {
|
2011-11-29 01:02:45 +04:00
|
|
|
message = browserBundle.formatStringFromName("geolocation.shareWithFile",
|
2010-09-10 08:59:51 +04:00
|
|
|
[requestingURI.path], 1);
|
2010-04-09 21:45:25 +04:00
|
|
|
} else {
|
2011-11-29 01:02:45 +04:00
|
|
|
message = browserBundle.formatStringFromName("geolocation.shareWithSite",
|
2010-04-09 21:45:25 +04:00
|
|
|
[requestingURI.host], 1);
|
|
|
|
|
|
|
|
// Don't offer to "always/never share" in PB mode
|
|
|
|
var inPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService).
|
|
|
|
privateBrowsingEnabled;
|
|
|
|
|
|
|
|
if (!inPrivateBrowsing) {
|
|
|
|
secondaryActions.push({
|
2011-11-29 01:02:47 +04:00
|
|
|
label: browserBundle.GetStringFromName("geolocation.alwaysShareLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.alwaysShareLocation.accesskey"),
|
2010-04-09 21:45:25 +04:00
|
|
|
callback: function () {
|
|
|
|
Services.perms.add(requestingURI, "geo", Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
request.allow();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
secondaryActions.push({
|
2011-11-29 01:02:47 +04:00
|
|
|
label: browserBundle.GetStringFromName("geolocation.neverShareLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.neverShareLocation.accesskey"),
|
2010-04-09 21:45:25 +04:00
|
|
|
callback: function () {
|
|
|
|
Services.perms.add(requestingURI, "geo", Ci.nsIPermissionManager.DENY_ACTION);
|
|
|
|
request.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2009-04-16 01:49:11 +04:00
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
var requestingWindow = request.window.top;
|
2010-04-09 21:45:25 +04:00
|
|
|
var chromeWin = getChromeWindow(requestingWindow).wrappedJSObject;
|
|
|
|
var browser = chromeWin.gBrowser.getBrowserForDocument(requestingWindow.document);
|
2009-04-16 01:49:11 +04:00
|
|
|
|
2010-04-09 21:45:25 +04:00
|
|
|
chromeWin.PopupNotifications.show(browser, "geolocation", message, "geo-notification-icon",
|
|
|
|
mainAction, secondaryActions);
|
2010-08-12 05:28:27 +04:00
|
|
|
}
|
2008-10-23 22:01:32 +04:00
|
|
|
};
|
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
var components = [BrowserGlue, ContentPermissionPrompt];
|
2010-06-22 20:59:15 +04:00
|
|
|
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|