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>
|
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;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource:///modules/distribution.js");
|
2007-09-06 07:02:22 +04:00
|
|
|
|
2008-03-08 03:16:38 +03:00
|
|
|
const PREF_EM_NEW_ADDONS_LIST = "extensions.newAddons";
|
|
|
|
|
2008-03-13 22:25:49 +03:00
|
|
|
// Check to see if bookmarks need backing up once per
|
|
|
|
// day on 1 hour idle.
|
|
|
|
const BOOKMARKS_ARCHIVE_IDLE_TIME = 60 * 60;
|
|
|
|
|
|
|
|
// Backup bookmarks once every 24 hours.
|
|
|
|
const BOOKMARKS_ARCHIVE_INTERVAL = 86400 * 1000;
|
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// Factory object
|
|
|
|
const BrowserGlueServiceFactory = {
|
|
|
|
_instance: null,
|
|
|
|
createInstance: function (outer, iid)
|
|
|
|
{
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return this._instance == null ?
|
|
|
|
this._instance = new BrowserGlue() : this._instance;
|
|
|
|
}
|
|
|
|
};
|
2005-12-05 00:02:38 +03:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// Constructor
|
|
|
|
|
|
|
|
function BrowserGlue() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserGlue.prototype = {
|
2008-10-18 06:02:07 +04:00
|
|
|
__prefs: null,
|
|
|
|
get _prefs() {
|
|
|
|
if (!this.__prefs)
|
|
|
|
this.__prefs = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
return this.__prefs;
|
|
|
|
},
|
|
|
|
|
2007-06-15 22:01:25 +04:00
|
|
|
_saveSession: false,
|
|
|
|
|
2008-02-07 12:28:43 +03:00
|
|
|
_setPrefToSaveSession: function()
|
|
|
|
{
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
|
2008-02-07 12:28:43 +03:00
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// nsIObserver implementation
|
2005-12-05 00:02:38 +03:00
|
|
|
observe: function(subject, topic, data)
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
switch(topic) {
|
|
|
|
case "xpcom-shutdown":
|
|
|
|
this._dispose();
|
|
|
|
break;
|
2008-02-22 23:42:24 +03:00
|
|
|
case "quit-application":
|
2005-08-23 20:38:28 +04:00
|
|
|
this._onProfileShutdown();
|
|
|
|
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;
|
2008-03-08 03:16:38 +03:00
|
|
|
case "sessionstore-windows-restored":
|
|
|
|
this._onBrowserStartup();
|
|
|
|
break;
|
2006-07-19 16:49:33 +04:00
|
|
|
case "browser:purge-session-history":
|
|
|
|
// reset the console service's error buffer
|
2007-06-17 01:23:17 +04:00
|
|
|
const cs = Cc["@mozilla.org/consoleservice;1"].
|
|
|
|
getService(Ci.nsIConsoleService);
|
2006-07-19 16:49:33 +04:00
|
|
|
cs.logStringMessage(null); // clear the console (in case it's open)
|
|
|
|
cs.reset();
|
|
|
|
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":
|
|
|
|
if (this._saveSession) {
|
2008-02-07 12:28:43 +03:00
|
|
|
this._setPrefToSaveSession();
|
2007-06-15 22:01:25 +04:00
|
|
|
}
|
|
|
|
break;
|
2008-02-07 12:28:43 +03:00
|
|
|
case "session-save":
|
|
|
|
this._setPrefToSaveSession();
|
|
|
|
subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
subject.data = true;
|
|
|
|
break;
|
2008-03-13 22:25:49 +03:00
|
|
|
case "idle":
|
|
|
|
if (this.idleService.idleTime > BOOKMARKS_ARCHIVE_IDLE_TIME * 1000) {
|
|
|
|
// Back up bookmarks.
|
|
|
|
this._archiveBookmarks();
|
|
|
|
}
|
|
|
|
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)
|
2005-12-05 00:02:38 +03:00
|
|
|
_init: function()
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
// observer registration
|
2007-06-17 01:23:17 +04:00
|
|
|
const osvr = Cc['@mozilla.org/observer-service;1'].
|
|
|
|
getService(Ci.nsIObserverService);
|
2008-02-22 23:42:24 +03:00
|
|
|
osvr.addObserver(this, "quit-application", false);
|
2005-08-23 20:38:28 +04:00
|
|
|
osvr.addObserver(this, "xpcom-shutdown", false);
|
2007-09-11 19:52:04 +04:00
|
|
|
osvr.addObserver(this, "prefservice:after-app-defaults", false);
|
2005-10-07 19:15:21 +04:00
|
|
|
osvr.addObserver(this, "final-ui-startup", false);
|
2008-03-08 03:16:38 +03:00
|
|
|
osvr.addObserver(this, "sessionstore-windows-restored", false);
|
2006-07-19 16:49:33 +04:00
|
|
|
osvr.addObserver(this, "browser:purge-session-history", false);
|
2007-06-15 22:01:25 +04:00
|
|
|
osvr.addObserver(this, "quit-application-requested", false);
|
|
|
|
osvr.addObserver(this, "quit-application-granted", false);
|
2008-02-07 12:28:43 +03:00
|
|
|
osvr.addObserver(this, "session-save", false);
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// cleanup (called on application shutdown)
|
2005-12-05 00:02:38 +03:00
|
|
|
_dispose: function()
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
// observer removal
|
2007-06-17 01:23:17 +04:00
|
|
|
const osvr = Cc['@mozilla.org/observer-service;1'].
|
|
|
|
getService(Ci.nsIObserverService);
|
2008-02-22 23:42:24 +03:00
|
|
|
osvr.removeObserver(this, "quit-application");
|
2005-08-23 20:38:28 +04:00
|
|
|
osvr.removeObserver(this, "xpcom-shutdown");
|
2007-09-11 19:52:04 +04:00
|
|
|
osvr.removeObserver(this, "prefservice:after-app-defaults");
|
2005-10-07 19:15:21 +04:00
|
|
|
osvr.removeObserver(this, "final-ui-startup");
|
2008-03-08 03:16:38 +03:00
|
|
|
osvr.removeObserver(this, "sessionstore-windows-restored");
|
2006-07-19 16:49:33 +04:00
|
|
|
osvr.removeObserver(this, "browser:purge-session-history");
|
2007-06-15 22:01:25 +04:00
|
|
|
osvr.removeObserver(this, "quit-application-requested");
|
|
|
|
osvr.removeObserver(this, "quit-application-granted");
|
2008-02-07 12:28:43 +03:00
|
|
|
osvr.removeObserver(this, "session-save");
|
2007-09-11 19:52:04 +04:00
|
|
|
},
|
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
_onAppDefaults: function()
|
|
|
|
{
|
|
|
|
// apply distribution customizations (prefs)
|
|
|
|
// other customizations are applied in _onProfileStartup()
|
|
|
|
var distro = new DistributionCustomizer();
|
|
|
|
distro.applyPrefDefaults();
|
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// profile startup handler (contains profile initialization routines)
|
2005-12-05 00:02:38 +03:00
|
|
|
_onProfileStartup: function()
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
this.Sanitizer.onStartup();
|
2005-10-04 09:02:47 +04:00
|
|
|
// check if we're in safe mode
|
2007-06-17 01:23:17 +04:00
|
|
|
var app = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).
|
|
|
|
QueryInterface(Ci.nsIXULRuntime);
|
2005-10-04 09:02:47 +04:00
|
|
|
if (app.inSafeMode) {
|
2007-06-17 01:23:17 +04:00
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
2005-10-04 09:02:47 +04:00
|
|
|
ww.openWindow(null, "chrome://browser/content/safeMode.xul",
|
|
|
|
"_blank", "chrome,centerscreen,modal,resizable=no", null);
|
|
|
|
}
|
2007-05-03 12:56:41 +04:00
|
|
|
|
|
|
|
// initialize Places
|
|
|
|
this._initPlaces();
|
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
// apply distribution customizations
|
|
|
|
// prefs are applied in _onAppDefaults()
|
|
|
|
var distro = new DistributionCustomizer();
|
|
|
|
distro.applyCustomizations();
|
|
|
|
|
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
|
|
|
|
|
|
|
const osvr = Cc['@mozilla.org/observer-service;1'].
|
|
|
|
getService(Ci.nsIObserverService);
|
|
|
|
osvr.notifyObservers(null, "browser-ui-startup-complete", "");
|
2007-05-11 04:42:22 +04:00
|
|
|
},
|
2007-05-03 12:56:41 +04:00
|
|
|
|
2007-05-11 04:42:22 +04:00
|
|
|
// profile shutdown handler (contains profile cleanup routines)
|
|
|
|
_onProfileShutdown: function()
|
|
|
|
{
|
2008-02-22 23:42:24 +03:00
|
|
|
this._shutdownPlaces();
|
2008-04-08 22:59:03 +04:00
|
|
|
this.idleService.removeIdleObserver(this, BOOKMARKS_ARCHIVE_IDLE_TIME);
|
2008-02-22 23:42:24 +03:00
|
|
|
this.Sanitizer.onShutdown();
|
2007-06-15 22:01:26 +04:00
|
|
|
},
|
|
|
|
|
2008-03-08 03:16:38 +03:00
|
|
|
// Browser startup complete. All initial windows have opened.
|
|
|
|
_onBrowserStartup: function()
|
|
|
|
{
|
2008-10-31 09:42:02 +03:00
|
|
|
// Show about:rights notification, if needed.
|
|
|
|
if (this._shouldShowRights())
|
|
|
|
this._showRightsNotification();
|
|
|
|
|
2008-03-08 03:16:38 +03:00
|
|
|
// If new add-ons were installed during startup open the add-ons manager.
|
2008-10-18 06:02:07 +04:00
|
|
|
if (this._prefs.prefHasUserValue(PREF_EM_NEW_ADDONS_LIST)) {
|
2008-03-08 03:16:38 +03: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-18 06:02:07 +04:00
|
|
|
str.data = this._prefs.getCharPref(PREF_EM_NEW_ADDONS_LIST);
|
2008-03-08 03:16:38 +03: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-18 06:02:07 +04:00
|
|
|
this._prefs.clearUserPref(PREF_EM_NEW_ADDONS_LIST);
|
2008-03-08 03:16:38 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-07-26 01:43:17 +04:00
|
|
|
_onQuitRequest: function(aCancelQuit, aQuitType)
|
2007-06-15 22:01:25 +04:00
|
|
|
{
|
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;
|
|
|
|
|
2007-06-17 01:23:17 +04:00
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
2008-05-10 19:52:32 +04:00
|
|
|
|
2007-06-15 22:01:25 +04:00
|
|
|
var windowcount = 0;
|
2008-05-10 19:52:32 +04:00
|
|
|
var pagecount = 0;
|
2007-06-15 22:01:25 +04:00
|
|
|
var browserEnum = 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)
|
|
|
|
pagecount += tabbrowser.browsers.length;
|
|
|
|
}
|
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
|
|
|
|
2007-07-26 01:43:17 +04:00
|
|
|
if (aQuitType != "restart")
|
|
|
|
aQuitType = "quit";
|
|
|
|
|
2007-06-15 22:01:25 +04:00
|
|
|
var showPrompt = true;
|
|
|
|
try {
|
2008-04-10 21:27:20 +04: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 19:08:40 +04:00
|
|
|
|
2008-10-18 06:02:07 +04: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 22:01:25 +04:00
|
|
|
showPrompt = false;
|
2008-04-10 21:27:20 +04:00
|
|
|
else if (aQuitType == "restart")
|
2008-10-18 06:02:07 +04:00
|
|
|
showPrompt = this._prefs.getBoolPref("browser.warnOnRestart");
|
2007-06-15 22:01:25 +04:00
|
|
|
else
|
2008-10-18 06:02:07 +04:00
|
|
|
showPrompt = this._prefs.getBoolPref("browser.tabs.warnOnClose");
|
2007-06-15 22:01:25 +04:00
|
|
|
} catch (ex) {}
|
|
|
|
|
2008-05-08 19:08:40 +04:00
|
|
|
if (!showPrompt)
|
|
|
|
return false;
|
2007-11-29 23:46:08 +03:00
|
|
|
|
2008-05-08 19:08:40 +04:00
|
|
|
var buttonChoice = 0;
|
|
|
|
var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService);
|
|
|
|
var quitBundle = bundleService.createBundle("chrome://browser/locale/quitDialog.properties");
|
|
|
|
var brandBundle = bundleService.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
|
|
|
|
var appName = brandBundle.GetStringFromName("brandShortName");
|
|
|
|
var quitDialogTitle = quitBundle.formatStringFromName(aQuitType + "DialogTitle",
|
|
|
|
[appName], 1);
|
|
|
|
|
|
|
|
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 22:01:25 +04:00
|
|
|
|
2008-05-08 19:08:40 +04:00
|
|
|
buttonChoice = promptService.confirmEx(null, quitDialogTitle, message,
|
|
|
|
flags, button0Title, button1Title, button2Title,
|
|
|
|
neverAskText, neverAsk);
|
|
|
|
|
|
|
|
switch (buttonChoice) {
|
|
|
|
case 2: // Quit
|
|
|
|
if (neverAsk.value)
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setBoolPref("browser.tabs.warnOnClose", 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")
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setBoolPref("browser.warnOnRestart", false);
|
2008-05-08 19:08:40 +04:00
|
|
|
else {
|
|
|
|
// always save state when shutting down
|
2008-10-18 06:02:07 +04:00
|
|
|
this._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.
|
|
|
|
*/
|
|
|
|
_shouldShowRights : function () {
|
|
|
|
// 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;
|
|
|
|
},
|
|
|
|
|
|
|
|
_showRightsNotification : function () {
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService);
|
|
|
|
var brandBundle = bundleService.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
var rightsBundle = bundleService.createBundle("chrome://browser/locale/aboutRights.properties");
|
|
|
|
|
|
|
|
var buttonLabel = rightsBundle.GetStringFromName("buttonLabel");
|
|
|
|
var buttonAccessKey = rightsBundle.GetStringFromName("buttonAccessKey");
|
|
|
|
var productName = brandBundle.GetStringFromName("brandFullName");
|
|
|
|
var notifyText = rightsBundle.formatStringFromName("notifyText", [productName], 1);
|
|
|
|
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: buttonLabel,
|
|
|
|
accessKey: buttonAccessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
|
|
|
browser.selectedTab = browser.addTab("about:rights");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
// Set pref to indicate we've shown the notficiation.
|
|
|
|
var currentVersion = this._prefs.getIntPref("browser.rights.version");
|
|
|
|
this._prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
|
|
|
|
|
|
|
|
notifyBox.appendNotification(notifyText, "about-rights", null, notifyBox.PRIORITY_INFO_LOW, buttons);
|
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// returns the (cached) Sanitizer constructor
|
|
|
|
get Sanitizer()
|
|
|
|
{
|
|
|
|
if(typeof(Sanitizer) != "function") { // we should dynamically load the script
|
2007-06-17 01:23:17 +04:00
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
|
|
getService(Ci.mozIJSSubScriptLoader).
|
|
|
|
loadSubScript("chrome://browser/content/sanitize.js", null);
|
2005-08-23 20:38:28 +04:00
|
|
|
}
|
|
|
|
return Sanitizer;
|
|
|
|
},
|
2007-05-03 12:56:41 +04:00
|
|
|
|
2008-03-13 22:25:49 +03:00
|
|
|
_idleService: null,
|
|
|
|
get idleService() {
|
|
|
|
if (!this._idleService)
|
|
|
|
this._idleService = Cc["@mozilla.org/widget/idleservice;1"].
|
|
|
|
getService(Ci.nsIIdleService);
|
|
|
|
return this._idleService;
|
|
|
|
},
|
|
|
|
|
2007-05-03 12:56:41 +04:00
|
|
|
/**
|
|
|
|
* Initialize Places
|
2007-05-21 06:13:25 +04:00
|
|
|
* - imports the bookmarks html file if bookmarks datastore is empty
|
2008-03-28 19:43:17 +03:00
|
|
|
*
|
|
|
|
* These prefs are set by the backend services upon creation (or recreation)
|
|
|
|
* of the Places db:
|
|
|
|
* - browser.places.importBookmarksHTML
|
|
|
|
* Set to false by the history service to indicate we need to re-import.
|
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
|
|
|
*
|
|
|
|
* These prefs are set up by the frontend:
|
|
|
|
* - 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
|
|
|
*/
|
|
|
|
_initPlaces: function bg__initPlaces() {
|
2008-04-02 23:33:01 +04:00
|
|
|
// we need to instantiate the history service before checking
|
|
|
|
// the browser.places.importBookmarksHTML pref, as
|
2007-05-17 10:47:41 +04:00
|
|
|
// nsNavHistory::ForceMigrateBookmarksDB() will set that pref
|
|
|
|
// if we need to force a migration (due to a schema change)
|
2007-06-17 01:23:17 +04:00
|
|
|
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
2007-12-04 11:08:33 +03:00
|
|
|
|
2007-12-04 14:22:14 +03:00
|
|
|
var importBookmarks = false;
|
2008-04-02 23:33:01 +04:00
|
|
|
var restoreDefaultBookmarks = false;
|
2007-05-03 12:56:41 +04:00
|
|
|
try {
|
2008-10-18 06:02:07 +04:00
|
|
|
restoreDefaultBookmarks = this._prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
2007-05-03 12:56:41 +04:00
|
|
|
} catch(ex) {}
|
2007-12-04 14:22:14 +03:00
|
|
|
|
2008-04-02 23:33:01 +04:00
|
|
|
if (restoreDefaultBookmarks) {
|
|
|
|
// Ensure that we already have a bookmarks backup for today
|
|
|
|
this._archiveBookmarks();
|
|
|
|
// we will restore bookmarks from html
|
|
|
|
importBookmarks = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
2008-10-18 06:02:07 +04:00
|
|
|
importBookmarks = this._prefs.getBoolPref("browser.places.importBookmarksHTML");
|
2008-04-02 23:33:01 +04:00
|
|
|
} catch(ex) {}
|
|
|
|
}
|
|
|
|
|
2007-11-27 03:08:50 +03:00
|
|
|
if (!importBookmarks) {
|
|
|
|
// Call it here for Fx3 profiles created before the Places folder
|
|
|
|
// has been added, otherwise it's called during import.
|
|
|
|
this.ensurePlacesDefaultQueriesInitialized();
|
|
|
|
}
|
2008-03-13 22:25:49 +03:00
|
|
|
else {
|
|
|
|
// get latest backup
|
|
|
|
Cu.import("resource://gre/modules/utils.js");
|
|
|
|
var bookmarksFile = PlacesUtils.getMostRecentBackup();
|
|
|
|
|
2008-04-02 23:33:01 +04:00
|
|
|
if (!restoreDefaultBookmarks &&
|
|
|
|
bookmarksFile && bookmarksFile.leafName.match("\.json$")) {
|
2008-03-13 22:25:49 +03:00
|
|
|
// restore a JSON backup
|
|
|
|
PlacesUtils.restoreBookmarksFromJSONFile(bookmarksFile);
|
2007-05-03 12:56:41 +04:00
|
|
|
}
|
2008-03-13 22:25:49 +03:00
|
|
|
else {
|
2008-04-02 23:33:01 +04:00
|
|
|
// if there's no JSON backup or we are restoring default bookmarks
|
2008-03-13 22:25:49 +03:00
|
|
|
|
2008-03-27 08:00:47 +03:00
|
|
|
// ensurePlacesDefaultQueriesInitialized() is called by import.
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
2008-03-27 08:00:47 +03:00
|
|
|
|
2008-03-13 22:25:49 +03:00
|
|
|
var dirService = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
2008-04-02 23:33:01 +04:00
|
|
|
|
2008-05-02 02:02:53 +04:00
|
|
|
var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
|
|
|
|
if (restoreDefaultBookmarks || !bookmarksFile.exists()) {
|
2008-04-02 23:33:01 +04:00
|
|
|
// get bookmarks.html file from default profile folder
|
2008-05-02 02:02:53 +04:00
|
|
|
bookmarksFile = dirService.get("profDef", Ci.nsILocalFile);
|
|
|
|
bookmarksFile.append("bookmarks.html");
|
2008-04-02 23:33:01 +04:00
|
|
|
}
|
2008-03-13 22:25:49 +03:00
|
|
|
|
|
|
|
// import the file
|
|
|
|
try {
|
|
|
|
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
|
|
|
|
getService(Ci.nsIPlacesImportExportService);
|
|
|
|
importer.importHTMLFromFile(bookmarksFile, true /* overwrite existing */);
|
2008-04-18 06:11:23 +04:00
|
|
|
} catch (err) {
|
|
|
|
// Report the error, but ignore it.
|
|
|
|
Cu.reportError(err);
|
2007-05-03 12:56:41 +04:00
|
|
|
}
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setBoolPref("browser.places.importBookmarksHTML", false);
|
2008-04-18 06:11:23 +04:00
|
|
|
if (restoreDefaultBookmarks)
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks",
|
2008-04-18 06:11:23 +04:00
|
|
|
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.
|
|
|
|
this.idleService.addIdleObserver(this, BOOKMARKS_ARCHIVE_IDLE_TIME);
|
2007-05-03 12:56:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Places shut-down tasks
|
|
|
|
* - back up and archive bookmarks
|
2008-03-13 22:25:49 +03:00
|
|
|
* - export bookmarks as HTML, if so configured
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
_shutdownPlaces: function bg__shutdownPlaces() {
|
2008-03-13 22:25:49 +03:00
|
|
|
// Backup and archive Places bookmarks.
|
|
|
|
this._archiveBookmarks();
|
|
|
|
|
|
|
|
// Backup bookmarks to bookmarks.html to support apps that depend
|
|
|
|
// on the legacy format.
|
|
|
|
var autoExportHTML = false;
|
|
|
|
try {
|
2008-10-18 06:02:07 +04:00
|
|
|
autoExportHTML = this._prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
2008-04-08 22:59:03 +04:00
|
|
|
} catch(ex) {
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Back up and archive bookmarks
|
|
|
|
*/
|
|
|
|
_archiveBookmarks: function nsBrowserGlue__archiveBookmarks() {
|
|
|
|
Cu.import("resource://gre/modules/utils.js");
|
|
|
|
|
|
|
|
var lastBackup = PlacesUtils.getMostRecentBackup();
|
|
|
|
|
|
|
|
// Backup bookmarks if there aren't any backups or
|
|
|
|
// they haven't been backed up in the last 24 hrs.
|
|
|
|
if (!lastBackup ||
|
|
|
|
Date.now() - lastBackup.lastModifiedTime > BOOKMARKS_ARCHIVE_INTERVAL) {
|
|
|
|
var maxBackups = 5;
|
|
|
|
try {
|
2008-10-18 06:02:07 +04:00
|
|
|
maxBackups = this._prefs.getIntPref("browser.bookmarks.max_backups");
|
2008-03-13 22:25:49 +03:00
|
|
|
} catch(ex) {}
|
|
|
|
|
|
|
|
PlacesUtils.archiveBookmarksFile(maxBackups, false /* don't force */);
|
|
|
|
}
|
2007-05-03 12:56:41 +04:00
|
|
|
},
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2008-02-04 22:37:26 +03:00
|
|
|
_migrateUI: function bg__migrateUI() {
|
|
|
|
var migration = 0;
|
|
|
|
try {
|
2008-10-18 06:02:07 +04:00
|
|
|
migration = this._prefs.getIntPref("browser.migration.version");
|
2008-02-04 22:37:26 +03: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 12:56:52 +03:00
|
|
|
this._dataSource = this._rdf.GetDataSource("rdf:local-store");
|
|
|
|
this._dirty = false;
|
2008-02-04 22:37:26 +03:00
|
|
|
|
2008-07-17 14:22:50 +04: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 22:37:26 +03:00
|
|
|
|
|
|
|
// force the RDF to be saved
|
2008-02-20 12:56:52 +03:00
|
|
|
if (this._dirty)
|
|
|
|
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
|
2008-02-04 22:37:26 +03:00
|
|
|
|
|
|
|
// free up the RDF service
|
|
|
|
this._rdf = null;
|
2008-02-20 12:56:52 +03:00
|
|
|
this._dataSource = null;
|
2008-02-04 22:37:26 +03:00
|
|
|
|
|
|
|
// update the migration version
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setIntPref("browser.migration.version", 1);
|
2008-02-04 22:37:26 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-02-20 12:56:52 +03:00
|
|
|
_getPersist: function bg__getPersist(aSource, aProperty) {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2008-02-20 12:56:52 +03:00
|
|
|
_setPersist: function bg__setPersist(aSource, aProperty, aTarget) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// ------------------------------
|
|
|
|
// public nsIBrowserGlue members
|
|
|
|
// ------------------------------
|
2005-12-05 00:02:38 +03:00
|
|
|
|
|
|
|
sanitize: function(aParentWindow)
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
this.Sanitizer.sanitize(aParentWindow);
|
2007-09-06 07:02:22 +04:00
|
|
|
},
|
2007-11-27 03:08:51 +03:00
|
|
|
|
2007-11-27 03:08:50 +03:00
|
|
|
ensurePlacesDefaultQueriesInitialized: function() {
|
2008-04-08 22:42:53 +04:00
|
|
|
const SMART_BOOKMARKS_VERSION = 1;
|
|
|
|
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
|
|
|
const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion";
|
|
|
|
|
|
|
|
// XXX should this be a pref? see bug #399268
|
|
|
|
const MAX_RESULTS = 10;
|
|
|
|
|
|
|
|
// get current smart bookmarks version
|
2008-04-09 04:34:03 +04:00
|
|
|
// By default, if the pref is not set up, we must create Smart Bookmarks
|
|
|
|
var smartBookmarksCurrentVersion = 0;
|
2007-11-27 03:08:50 +03:00
|
|
|
try {
|
2008-10-18 06:02:07 +04:00
|
|
|
smartBookmarksCurrentVersion = this._prefs.getIntPref(SMART_BOOKMARKS_PREF);
|
2008-04-08 22:42:53 +04:00
|
|
|
} catch(ex) {}
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2008-04-08 22:42:53 +04:00
|
|
|
// bail out if we don't have to create or update Smart Bookmarks
|
|
|
|
if (smartBookmarksCurrentVersion == -1 ||
|
|
|
|
smartBookmarksCurrentVersion >= SMART_BOOKMARKS_VERSION)
|
2007-11-27 03:08:50 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
2008-04-08 22:42:53 +04:00
|
|
|
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"].
|
|
|
|
getService(Ci.nsIAnnotationService);
|
2007-11-27 03:08:50 +03:00
|
|
|
|
|
|
|
var callback = {
|
|
|
|
_placesBundle: Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle("chrome://browser/locale/places/places.properties"),
|
|
|
|
|
|
|
|
_uri: function(aSpec) {
|
|
|
|
return Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService).
|
|
|
|
newURI(aSpec, null, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
runBatched: function() {
|
2008-04-08 22:42:53 +04:00
|
|
|
var smartBookmarks = [];
|
|
|
|
var bookmarksMenuIndex = 0;
|
|
|
|
var bookmarksToolbarIndex = 0;
|
|
|
|
|
|
|
|
// MOST VISITED
|
|
|
|
var smart = {queryId: "MostVisited", // don't change this
|
|
|
|
itemId: null,
|
|
|
|
title: this._placesBundle.GetStringFromName("mostVisitedTitle"),
|
|
|
|
uri: this._uri("place:queryType=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS),
|
|
|
|
parent: bmsvc.toolbarFolder,
|
|
|
|
position: bookmarksToolbarIndex++};
|
|
|
|
smartBookmarks.push(smart);
|
|
|
|
|
|
|
|
// RECENTLY BOOKMARKED
|
|
|
|
smart = {queryId: "RecentlyBookmarked", // don't change this
|
|
|
|
itemId: null,
|
|
|
|
title: this._placesBundle.GetStringFromName("recentlyBookmarkedTitle"),
|
|
|
|
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,
|
|
|
|
position: bookmarksMenuIndex++};
|
|
|
|
smartBookmarks.push(smart);
|
|
|
|
|
|
|
|
// RECENT TAGS
|
|
|
|
smart = {queryId: "RecentTags", // don't change this
|
|
|
|
itemId: null,
|
|
|
|
title: this._placesBundle.GetStringFromName("recentTagsTitle"),
|
|
|
|
uri: this._uri("place:"+
|
|
|
|
"type=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS),
|
|
|
|
parent: bmsvc.bookmarksMenuFolder,
|
|
|
|
position: bookmarksMenuIndex++};
|
|
|
|
smartBookmarks.push(smart);
|
|
|
|
|
|
|
|
var smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO, {});
|
|
|
|
// set current itemId, parent and position if Smart Bookmark exists
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
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.
|
|
|
|
if (smartBookmarkItemIds.length == 0)
|
|
|
|
bmsvc.insertSeparator(bmsvc.bookmarksMenuFolder, bookmarksMenuIndex);
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2008-02-22 07:09:08 +03:00
|
|
|
bmsvc.runInBatchMode(callback, null);
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
|
|
|
finally {
|
2008-10-18 06:02:07 +04:00
|
|
|
this._prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
|
|
|
|
this._prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-10-31 09:42:02 +03:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
#define BROKEN_WM_Z_ORDER
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef XP_OS2
|
|
|
|
#define BROKEN_WM_Z_ORDER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// this returns the most recent non-popup browser window
|
|
|
|
getMostRecentBrowserWindow : function ()
|
|
|
|
{
|
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
|
|
|
|
#ifdef BROKEN_WM_Z_ORDER
|
|
|
|
var win = wm.getMostRecentWindow("navigator:browser", true);
|
|
|
|
|
|
|
|
// if we're lucky, this isn't a popup, and we can just return this
|
|
|
|
if (win && win.document.documentElement.getAttribute("chromehidden")) {
|
|
|
|
win = null;
|
|
|
|
var windowList = wm.getEnumerator("navigator:browser", true);
|
|
|
|
// this is oldest to newest, so this gets a bit ugly
|
|
|
|
while (windowList.hasMoreElements()) {
|
|
|
|
var nextWin = windowList.getNext();
|
|
|
|
if (!nextWin.document.documentElement.getAttribute("chromehidden"))
|
|
|
|
win = nextWin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
var windowList = wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
|
|
|
|
if (!windowList.hasMoreElements())
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var win = windowList.getNext();
|
|
|
|
while (win.document.documentElement.getAttribute("chromehidden")) {
|
|
|
|
if (!windowList.hasMoreElements())
|
|
|
|
return null;
|
|
|
|
|
|
|
|
win = windowList.getNext();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return win;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// for XPCOM
|
|
|
|
classDescription: "Firefox Browser Glue Service",
|
|
|
|
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),
|
|
|
|
contractID: "@mozilla.org/browser/browserglue;1",
|
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,
|
2008-04-08 22:43:40 +04:00
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// get this contractID registered for certain categories via XPCOMUtils
|
|
|
|
_xpcom_categories: [
|
|
|
|
// make BrowserGlue a startup observer
|
|
|
|
{ category: "app-startup", service: true }
|
|
|
|
]
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
2008-04-08 22:43:40 +04:00
|
|
|
|
2008-10-23 22:01:32 +04: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]),
|
|
|
|
|
|
|
|
prompt: function(request) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
var tabbrowser = getChromeWindow(requestingWindow).wrappedJSObject.gBrowser;
|
|
|
|
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 = [{
|
|
|
|
label: browserBundle.GetStringFromName("geolocation.exactLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.exactLocationKey"),
|
|
|
|
callback: function() request.allow() ,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: browserBundle.GetStringFromName("geolocation.neighborhoodLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.neighborhoodLocationKey"),
|
|
|
|
callback: function() request.allowButFuzz() ,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: browserBundle.GetStringFromName("geolocation.nothingLocation"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("geolocation.nothingLocationKey"),
|
|
|
|
callback: function() request.cancel() ,
|
|
|
|
}];
|
|
|
|
|
|
|
|
var message = browserBundle.formatStringFromName("geolocation.requestMessage",
|
|
|
|
[request.requestingURI.spec], 1);
|
|
|
|
notificationBox.appendNotification(message,
|
|
|
|
"geolocation",
|
|
|
|
"chrome://browser/skin/Info.png",
|
|
|
|
notificationBox.PRIORITY_INFO_HIGH,
|
|
|
|
buttons);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
//module initialization
|
|
|
|
function NSGetModule(aCompMgr, aFileSpec) {
|
2008-10-23 22:01:32 +04:00
|
|
|
return XPCOMUtils.generateModule([BrowserGlue, GeolocationPrompt]);
|
2007-09-06 07:02:22 +04:00
|
|
|
}
|