2012-02-23 06:37:04 -08:00
|
|
|
# -*- indent-tabs-mode: nil -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-16 14:23:17 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Cr = Components.results;
|
2007-09-11 08:52:04 -07:00
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2009-04-15 14:49:11 -07:00
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2007-09-11 08:52:04 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-04-12 07:33:10 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-06-12 18:16:00 -07:00
|
|
|
Cu.import("resource:///modules/SignInToWebsite.jsm");
|
2007-09-05 20:02:22 -07:00
|
|
|
|
2013-07-05 13:55:00 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "AboutHome",
|
|
|
|
"resource:///modules/AboutHome.jsm");
|
|
|
|
|
2012-02-15 15:44:29 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
|
|
|
|
"resource://gre/modules/AddonManager.jsm");
|
2010-08-10 15:15:26 -07:00
|
|
|
|
2013-08-08 17:16:47 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "ContentClick",
|
|
|
|
"resource:///modules/ContentClick.jsm");
|
|
|
|
|
2012-02-15 15:44:29 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
|
|
|
|
"resource://gre/modules/NetUtil.jsm");
|
|
|
|
|
2012-12-08 11:50:54 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
|
|
|
"resource://gre/modules/FileUtils.jsm");
|
|
|
|
|
2012-02-15 15:44:29 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
|
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
2010-11-23 05:04:07 -08:00
|
|
|
|
2012-03-23 00:15:36 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
|
|
|
|
"resource://gre/modules/BookmarkHTMLUtils.jsm");
|
|
|
|
|
2013-04-16 22:36:02 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
|
|
|
|
"resource://gre/modules/BookmarkJSONUtils.jsm");
|
|
|
|
|
2012-06-12 18:16:00 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "webappsUI",
|
2012-03-16 09:21:19 -07:00
|
|
|
"resource:///modules/webappsUI.jsm");
|
2012-03-12 17:33:10 -07:00
|
|
|
|
2012-05-02 13:11:19 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PageThumbs",
|
2013-02-16 20:15:41 -08:00
|
|
|
"resource://gre/modules/PageThumbs.jsm");
|
2012-05-02 13:11:19 -07:00
|
|
|
|
2012-08-21 11:17:18 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
|
2013-02-16 20:16:16 -08:00
|
|
|
"resource://gre/modules/NewTabUtils.jsm");
|
2012-08-21 11:17:18 -07:00
|
|
|
|
2012-09-19 07:20:44 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BrowserNewTabPreloader",
|
|
|
|
"resource:///modules/BrowserNewTabPreloader.jsm");
|
|
|
|
|
2014-02-25 09:51:41 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "CustomizationTabPreloader",
|
|
|
|
"resource:///modules/CustomizationTabPreloader.jsm");
|
|
|
|
|
2012-06-02 09:56:24 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PdfJs",
|
|
|
|
"resource://pdf.js/PdfJs.jsm");
|
|
|
|
|
2013-10-21 18:39:43 -07:00
|
|
|
#ifdef NIGHTLY_BUILD
|
2013-09-30 16:23:41 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "ShumwayUtils",
|
|
|
|
"resource://shumway/ShumwayUtils.jsm");
|
2013-10-21 18:39:43 -07:00
|
|
|
#endif
|
2013-09-30 16:23:41 -07:00
|
|
|
|
2012-10-05 02:37:00 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "webrtcUI",
|
|
|
|
"resource:///modules/webrtcUI.jsm");
|
|
|
|
|
2012-10-05 16:25:52 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
|
2012-12-05 17:59:26 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
|
2013-03-18 08:46:17 -07:00
|
|
|
"resource:///modules/RecentWindow.jsm");
|
2012-12-05 17:59:26 -08:00
|
|
|
|
2013-04-09 01:23:40 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
|
|
|
"resource://gre/modules/Task.jsm");
|
|
|
|
|
2013-04-16 23:08:11 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
|
|
|
|
"resource://gre/modules/PlacesBackups.jsm");
|
|
|
|
|
2013-07-03 14:41:25 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "OS",
|
|
|
|
"resource://gre/modules/osfile.jsm");
|
2013-04-16 23:08:11 -07:00
|
|
|
|
2013-07-26 22:40:07 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "SessionStore",
|
|
|
|
"resource:///modules/sessionstore/SessionStore.jsm");
|
|
|
|
|
2013-12-10 11:49:02 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
|
|
|
|
"resource:///modules/BrowserUITelemetry.jsm");
|
|
|
|
|
2014-02-04 05:43:20 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown",
|
2014-02-22 13:37:00 -08:00
|
|
|
"resource://gre/modules/AsyncShutdown.jsm");
|
2014-02-04 05:43:20 -08:00
|
|
|
|
2009-10-02 04:26:04 -07:00
|
|
|
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
|
|
|
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
2008-03-07 16:16:38 -08:00
|
|
|
|
2014-02-04 05:43:20 -08:00
|
|
|
// Seconds of idle before trying to create a bookmarks backup.
|
|
|
|
const BOOKMARKS_BACKUP_IDLE_TIME_SEC = 10 * 60;
|
|
|
|
// Minimum interval between backups. We try to not create more than one backup
|
|
|
|
// per interval.
|
|
|
|
const BOOKMARKS_BACKUP_MIN_INTERVAL_DAYS = 1;
|
|
|
|
// Maximum interval between backups. If the last backup is older than these
|
|
|
|
// days we will try to create a new one more aggressively.
|
|
|
|
const BOOKMARKS_BACKUP_MAX_INTERVAL_DAYS = 5;
|
2008-03-13 12:25:49 -07:00
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
// Factory object
|
|
|
|
const BrowserGlueServiceFactory = {
|
|
|
|
_instance: null,
|
2009-12-17 13:28:08 -08:00
|
|
|
createInstance: function BGSF_createInstance(outer, iid) {
|
2007-09-05 20:02:22 -07:00
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return this._instance == null ?
|
|
|
|
this._instance = new BrowserGlue() : this._instance;
|
|
|
|
}
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
|
|
|
|
function BrowserGlue() {
|
2009-09-29 03:44:18 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_idleService",
|
|
|
|
"@mozilla.org/widget/idleservice;1",
|
|
|
|
"nsIIdleService");
|
|
|
|
|
2009-10-05 03:13:04 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_distributionCustomizer", function() {
|
2010-01-21 15:49:11 -08:00
|
|
|
Cu.import("resource:///modules/distribution.js");
|
2009-10-05 03:13:04 -07:00
|
|
|
return new DistributionCustomizer();
|
|
|
|
});
|
|
|
|
|
2009-10-14 02:53:13 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_sanitizer",
|
|
|
|
function() {
|
|
|
|
let sanitizerScope = {};
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", sanitizerScope);
|
2009-10-14 02:53:13 -07:00
|
|
|
return sanitizerScope.Sanitizer;
|
|
|
|
});
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2009-07-30 21:57:57 -07:00
|
|
|
#ifndef XP_MACOSX
|
|
|
|
# OS X has the concept of zero-window sessions and therefore ignores the
|
|
|
|
# browser-lastwindow-close-* topics.
|
|
|
|
#define OBSERVE_LASTWINDOW_CLOSE_TOPICS 1
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
BrowserGlue.prototype = {
|
2007-06-15 11:01:25 -07:00
|
|
|
_saveSession: false,
|
2009-09-29 03:44:18 -07:00
|
|
|
_isPlacesInitObserver: false,
|
|
|
|
_isPlacesLockedObserver: false,
|
2010-04-22 05:53:54 -07:00
|
|
|
_isPlacesShutdownObserver: false,
|
2009-09-29 03:44:18 -07:00
|
|
|
_isPlacesDatabaseLocked: false,
|
2012-05-28 02:43:59 -07:00
|
|
|
_migrationImportsDefaultBookmarks: false,
|
2007-06-15 11:01:25 -07:00
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_setPrefToSaveSession: function BG__setPrefToSaveSession(aForce) {
|
2009-10-14 02:53:13 -07:00
|
|
|
if (!this._saveSession && !aForce)
|
|
|
|
return;
|
|
|
|
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
|
2009-06-11 13:17:33 -07:00
|
|
|
|
|
|
|
// This method can be called via [NSApplication terminate:] on Mac, which
|
|
|
|
// ends up causing prefs not to be flushed to disk, so we need to do that
|
|
|
|
// explicitly here. See bug 497652.
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.prefs.savePrefFile(null);
|
2008-02-07 01:28:43 -08:00
|
|
|
},
|
|
|
|
|
2010-08-11 18:28:27 -07: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-22 17:46:22 -08:00
|
|
|
let browserEnum = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (browserEnum.hasMoreElements()) {
|
|
|
|
delay += browserEnum.getNext().gBrowser.tabs.length;
|
2010-08-11 18:28:27 -07:00
|
|
|
}
|
|
|
|
delay = delay <= MAX_DELAY ? delay : MAX_DELAY;
|
|
|
|
|
2011-07-21 12:20:55 -07:00
|
|
|
Cu.import("resource://services-sync/main.js");
|
2012-08-29 14:43:41 -07:00
|
|
|
Weave.Service.scheduler.delayedAutoConnect(delay);
|
2010-08-11 18:28:27 -07:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIObserver implementation
|
2009-12-17 13:28:08 -08:00
|
|
|
observe: function BG_observe(subject, topic, data) {
|
2010-02-06 02:40:06 -08:00
|
|
|
switch (topic) {
|
2007-09-11 08:52:04 -07:00
|
|
|
case "prefservice:after-app-defaults":
|
|
|
|
this._onAppDefaults();
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "final-ui-startup":
|
2013-05-13 09:25:39 -07:00
|
|
|
this._finalUIStartup();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-10-02 08:53:37 -07:00
|
|
|
case "browser-delayed-startup-finished":
|
2013-07-26 22:40:07 -07:00
|
|
|
this._onFirstWindowLoaded(subject);
|
2010-10-02 08:53:37 -07:00
|
|
|
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
|
|
|
|
break;
|
2008-03-07 16:16:38 -08:00
|
|
|
case "sessionstore-windows-restored":
|
2012-01-18 15:25:05 -08:00
|
|
|
this._onWindowsRestored();
|
2008-03-07 16:16:38 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "browser:purge-session-history":
|
|
|
|
// reset the console service's error buffer
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.console.logStringMessage(null); // clear the console (in case it's open)
|
|
|
|
Services.console.reset();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2007-06-15 11:01:25 -07:00
|
|
|
case "quit-application-requested":
|
2007-07-25 14:43:17 -07:00
|
|
|
this._onQuitRequest(subject, data);
|
2007-06-15 11:01:25 -07:00
|
|
|
break;
|
|
|
|
case "quit-application-granted":
|
2014-02-07 09:47:35 -08:00
|
|
|
this._onQuitApplicationGranted();
|
2007-06-15 11:01:25 -07:00
|
|
|
break;
|
2009-07-30 21:57:57 -07:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
|
|
|
case "browser-lastwindow-close-requested":
|
|
|
|
// The application is not actually quitting, but the last full browser
|
|
|
|
// window is about to be closed.
|
|
|
|
this._onQuitRequest(subject, "lastwindow");
|
|
|
|
break;
|
|
|
|
case "browser-lastwindow-close-granted":
|
2009-10-14 02:53:13 -07:00
|
|
|
this._setPrefToSaveSession();
|
2009-07-30 21:57:57 -07:00
|
|
|
break;
|
2010-08-11 18:28:27 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
case "weave:service:ready":
|
|
|
|
this._setSyncAutoconnectDelay();
|
|
|
|
break;
|
2012-06-29 15:30:45 -07:00
|
|
|
case "weave:engine:clients:display-uri":
|
|
|
|
this._onDisplaySyncURI(subject);
|
|
|
|
break;
|
2009-07-30 21:57:57 -07:00
|
|
|
#endif
|
2008-02-07 01:28:43 -08:00
|
|
|
case "session-save":
|
2009-10-14 02:53:13 -07:00
|
|
|
this._setPrefToSaveSession(true);
|
2008-02-07 01:28:43 -08:00
|
|
|
subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
subject.data = true;
|
|
|
|
break;
|
2008-11-12 12:45:53 -08:00
|
|
|
case "places-init-complete":
|
2012-05-28 02:43:59 -07:00
|
|
|
if (!this._migrationImportsDefaultBookmarks)
|
|
|
|
this._initPlaces(false);
|
|
|
|
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.obs.removeObserver(this, "places-init-complete");
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesInitObserver = false;
|
2008-12-30 04:44:55 -08:00
|
|
|
// no longer needed, since history was initialized completely.
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.obs.removeObserver(this, "places-database-locked");
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesLockedObserver = false;
|
2008-12-30 04:44:55 -08:00
|
|
|
break;
|
|
|
|
case "places-database-locked":
|
|
|
|
this._isPlacesDatabaseLocked = true;
|
2009-10-14 02:53:13 -07:00
|
|
|
// Stop observing, so further attempts to load history service
|
|
|
|
// will not show the prompt.
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.obs.removeObserver(this, "places-database-locked");
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesLockedObserver = false;
|
2008-11-12 12:45:53 -08:00
|
|
|
break;
|
2010-04-22 05:53:54 -07:00
|
|
|
case "places-shutdown":
|
|
|
|
if (this._isPlacesShutdownObserver) {
|
|
|
|
Services.obs.removeObserver(this, "places-shutdown");
|
|
|
|
this._isPlacesShutdownObserver = false;
|
|
|
|
}
|
2010-08-27 18:24:54 -07:00
|
|
|
// places-shutdown is fired when the profile is about to disappear.
|
2013-01-29 09:06:03 -08:00
|
|
|
this._onPlacesShutdown();
|
2010-04-22 05:53:54 -07:00
|
|
|
break;
|
2008-03-13 12:25:49 -07:00
|
|
|
case "idle":
|
2014-02-04 05:43:20 -08:00
|
|
|
this._backupBookmarks();
|
2008-03-13 12:25:49 -07:00
|
|
|
break;
|
2009-10-05 03:13:04 -07:00
|
|
|
case "distribution-customization-complete":
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.obs.removeObserver(this, "distribution-customization-complete");
|
2009-10-05 03:13:04 -07:00
|
|
|
// Customization has finished, we don't need the customizer anymore.
|
|
|
|
delete this._distributionCustomizer;
|
|
|
|
break;
|
2010-04-06 19:49:23 -07:00
|
|
|
case "browser-glue-test": // used by tests
|
|
|
|
if (data == "post-update-notification") {
|
2010-04-12 07:33:10 -07:00
|
|
|
if (Services.prefs.prefHasUserValue("app.update.postupdate"))
|
2010-04-06 19:49:23 -07:00
|
|
|
this._showUpdateNotification();
|
2010-12-22 10:26:18 -08:00
|
|
|
}
|
|
|
|
else if (data == "force-ui-migration") {
|
|
|
|
this._migrateUI();
|
2010-04-06 19:49:23 -07:00
|
|
|
}
|
2011-04-12 07:32:20 -07:00
|
|
|
else if (data == "force-distribution-customization") {
|
2011-04-12 18:15:39 -07:00
|
|
|
this._distributionCustomizer.applyPrefDefaults();
|
2011-04-12 07:32:20 -07:00
|
|
|
this._distributionCustomizer.applyCustomizations();
|
2011-04-12 18:15:39 -07:00
|
|
|
// To apply distribution bookmarks use "places-init-complete".
|
2011-04-12 07:32:20 -07:00
|
|
|
}
|
2011-04-12 17:43:28 -07:00
|
|
|
else if (data == "force-places-init") {
|
2012-05-28 02:43:59 -07:00
|
|
|
this._initPlaces(false);
|
2011-04-12 17:43:28 -07:00
|
|
|
}
|
2010-04-06 19:49:23 -07:00
|
|
|
break;
|
2012-05-28 02:43:59 -07:00
|
|
|
case "initial-migration-will-import-default-bookmarks":
|
|
|
|
this._migrationImportsDefaultBookmarks = true;
|
|
|
|
break;
|
|
|
|
case "initial-migration-did-import-default-bookmarks":
|
|
|
|
this._initPlaces(true);
|
2012-03-23 00:15:36 -07:00
|
|
|
break;
|
2012-12-13 16:09:03 -08:00
|
|
|
case "handle-xul-text-link":
|
|
|
|
let linkHandled = subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
if (!linkHandled.data) {
|
|
|
|
let win = this.getMostRecentBrowserWindow();
|
|
|
|
if (win) {
|
|
|
|
win.openUILinkIn(data, "tab");
|
|
|
|
linkHandled.data = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-01-29 09:06:03 -08:00
|
|
|
case "profile-before-change":
|
2014-02-07 09:47:35 -08:00
|
|
|
// Any component depending on Places should be finalized in
|
|
|
|
// _onPlacesShutdown. Any component that doesn't need to act after
|
|
|
|
// the UI has gone should be finalized in _onQuitApplicationGranted.
|
|
|
|
this._dispose();
|
2013-01-29 09:06:03 -08:00
|
|
|
break;
|
2013-02-14 14:47:49 -08:00
|
|
|
#ifdef MOZ_SERVICES_HEALTHREPORT
|
|
|
|
case "keyword-search":
|
|
|
|
// This is very similar to code in
|
|
|
|
// browser.js:BrowserSearch.recordSearchInHealthReport(). The code could
|
|
|
|
// be consolidated if there is will. We need the observer in
|
|
|
|
// nsBrowserGlue to prevent double counting.
|
|
|
|
let reporter = Cc["@mozilla.org/datareporting/service;1"]
|
|
|
|
.getService()
|
|
|
|
.wrappedJSObject
|
|
|
|
.healthReporter;
|
|
|
|
|
|
|
|
if (!reporter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reporter.onInit().then(function record() {
|
|
|
|
try {
|
2013-10-18 12:31:39 -07:00
|
|
|
let engine = subject.QueryInterface(Ci.nsISearchEngine);
|
|
|
|
reporter.getProvider("org.mozilla.searches").recordSearch(engine, "urlbar");
|
2013-02-14 14:47:49 -08:00
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
#endif
|
2013-05-27 08:21:47 -07:00
|
|
|
case "browser-search-engine-modified":
|
|
|
|
if (data != "engine-default" && data != "engine-current") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Enforce that the search service's defaultEngine is always equal to
|
|
|
|
// its currentEngine. The search service will notify us any time either
|
|
|
|
// of them are changed (either by directly setting the relevant prefs,
|
|
|
|
// i.e. if add-ons try to change this directly, or if the
|
|
|
|
// nsIBrowserSearchService setters are called).
|
2013-07-01 16:46:07 -07:00
|
|
|
// No need to initialize the search service, since it's guaranteed to be
|
|
|
|
// initialized already when this notification fires.
|
2013-05-27 08:21:47 -07:00
|
|
|
let ss = Services.search;
|
|
|
|
if (ss.currentEngine.name == ss.defaultEngine.name)
|
|
|
|
return;
|
|
|
|
if (data == "engine-current")
|
|
|
|
ss.defaultEngine = ss.currentEngine;
|
|
|
|
else
|
|
|
|
ss.currentEngine = ss.defaultEngine;
|
|
|
|
break;
|
2013-07-01 16:46:07 -07:00
|
|
|
case "browser-search-service":
|
|
|
|
if (data != "init-complete")
|
|
|
|
return;
|
|
|
|
Services.obs.removeObserver(this, "browser-search-service");
|
|
|
|
this._syncSearchEngines();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_syncSearchEngines: function () {
|
|
|
|
// Only do this if the search service is already initialized. This function
|
|
|
|
// gets called in finalUIStartup and from a browser-search-service observer,
|
|
|
|
// to catch both cases (search service initialization occurring before and
|
|
|
|
// after final-ui-startup)
|
|
|
|
if (Services.search.isInitialized) {
|
|
|
|
Services.search.defaultEngine = Services.search.currentEngine;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-02-14 14:47:49 -08:00
|
|
|
},
|
2008-03-13 12:25:49 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// initialization (called on application startup)
|
2009-12-17 13:28:08 -08:00
|
|
|
_init: function BG__init() {
|
2010-04-22 07:11:21 -07:00
|
|
|
let os = Services.obs;
|
|
|
|
os.addObserver(this, "prefservice:after-app-defaults", false);
|
|
|
|
os.addObserver(this, "final-ui-startup", false);
|
2010-10-02 08:53:37 -07:00
|
|
|
os.addObserver(this, "browser-delayed-startup-finished", false);
|
2010-04-22 07:11:21 -07: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-30 21:57:57 -07:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
2010-04-22 07:11:21 -07:00
|
|
|
os.addObserver(this, "browser-lastwindow-close-requested", false);
|
|
|
|
os.addObserver(this, "browser-lastwindow-close-granted", false);
|
2010-08-11 18:28:27 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
os.addObserver(this, "weave:service:ready", false);
|
2012-06-29 15:30:45 -07:00
|
|
|
os.addObserver(this, "weave:engine:clients:display-uri", false);
|
2009-07-30 21:57:57 -07:00
|
|
|
#endif
|
2010-04-22 07:11:21 -07:00
|
|
|
os.addObserver(this, "session-save", false);
|
|
|
|
os.addObserver(this, "places-init-complete", false);
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesInitObserver = true;
|
2010-04-22 07:11:21 -07:00
|
|
|
os.addObserver(this, "places-database-locked", false);
|
2009-09-29 03:44:18 -07:00
|
|
|
this._isPlacesLockedObserver = true;
|
2010-04-22 07:11:21 -07:00
|
|
|
os.addObserver(this, "distribution-customization-complete", false);
|
|
|
|
os.addObserver(this, "places-shutdown", false);
|
2010-04-22 05:53:54 -07:00
|
|
|
this._isPlacesShutdownObserver = true;
|
2012-12-13 16:09:03 -08:00
|
|
|
os.addObserver(this, "handle-xul-text-link", false);
|
2013-01-29 09:06:03 -08:00
|
|
|
os.addObserver(this, "profile-before-change", false);
|
2013-02-14 14:47:49 -08:00
|
|
|
#ifdef MOZ_SERVICES_HEALTHREPORT
|
|
|
|
os.addObserver(this, "keyword-search", false);
|
|
|
|
#endif
|
2013-05-27 08:21:47 -07:00
|
|
|
os.addObserver(this, "browser-search-engine-modified", false);
|
2013-07-01 16:46:07 -07:00
|
|
|
os.addObserver(this, "browser-search-service", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// cleanup (called on application shutdown)
|
2009-12-17 13:28:08 -08:00
|
|
|
_dispose: function BG__dispose() {
|
2010-04-22 07:11:21 -07:00
|
|
|
let os = Services.obs;
|
|
|
|
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-30 21:57:57 -07:00
|
|
|
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
|
2010-04-22 07:11:21 -07:00
|
|
|
os.removeObserver(this, "browser-lastwindow-close-requested");
|
|
|
|
os.removeObserver(this, "browser-lastwindow-close-granted");
|
2010-08-11 18:28:27 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
2013-04-06 11:46:35 -07:00
|
|
|
os.removeObserver(this, "weave:service:ready");
|
|
|
|
os.removeObserver(this, "weave:engine:clients:display-uri");
|
2009-07-30 21:57:57 -07:00
|
|
|
#endif
|
2010-04-22 07:11:21 -07:00
|
|
|
os.removeObserver(this, "session-save");
|
2014-02-04 05:43:20 -08:00
|
|
|
if (this._bookmarksBackupIdleTime) {
|
|
|
|
this._idleService.removeIdleObserver(this, this._bookmarksBackupIdleTime);
|
|
|
|
delete this._bookmarksBackupIdleTime;
|
|
|
|
}
|
2009-09-29 03:44:18 -07:00
|
|
|
if (this._isPlacesInitObserver)
|
2010-04-22 07:11:21 -07:00
|
|
|
os.removeObserver(this, "places-init-complete");
|
2009-09-29 03:44:18 -07:00
|
|
|
if (this._isPlacesLockedObserver)
|
2010-04-22 07:11:21 -07:00
|
|
|
os.removeObserver(this, "places-database-locked");
|
2010-04-22 05:53:54 -07:00
|
|
|
if (this._isPlacesShutdownObserver)
|
2010-04-22 07:11:21 -07:00
|
|
|
os.removeObserver(this, "places-shutdown");
|
2012-12-13 16:09:03 -08:00
|
|
|
os.removeObserver(this, "handle-xul-text-link");
|
2013-01-29 09:06:03 -08:00
|
|
|
os.removeObserver(this, "profile-before-change");
|
2013-02-14 14:47:49 -08:00
|
|
|
#ifdef MOZ_SERVICES_HEALTHREPORT
|
|
|
|
os.removeObserver(this, "keyword-search");
|
|
|
|
#endif
|
2013-05-27 08:21:47 -07:00
|
|
|
os.removeObserver(this, "browser-search-engine-modified");
|
2013-07-01 16:46:07 -07:00
|
|
|
try {
|
|
|
|
os.removeObserver(this, "browser-search-service");
|
|
|
|
// may have already been removed by the observer
|
|
|
|
} catch (ex) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_onAppDefaults: function BG__onAppDefaults() {
|
2007-09-11 08:52:04 -07:00
|
|
|
// apply distribution customizations (prefs)
|
2013-05-13 09:25:39 -07:00
|
|
|
// other customizations are applied in _finalUIStartup()
|
2009-10-05 03:13:04 -07:00
|
|
|
this._distributionCustomizer.applyPrefDefaults();
|
2007-09-11 08:52:04 -07:00
|
|
|
},
|
|
|
|
|
2013-05-13 09:25:39 -07:00
|
|
|
// runs on startup, before the first command line handler is invoked
|
|
|
|
// (i.e. before the first window is opened)
|
|
|
|
_finalUIStartup: function BG__finalUIStartup() {
|
2009-10-14 02:53:13 -07:00
|
|
|
this._sanitizer.onStartup();
|
2007-03-22 10:30:00 -07:00
|
|
|
// check if we're in safe mode
|
2010-04-12 07:33:10 -07:00
|
|
|
if (Services.appinfo.inSafeMode) {
|
|
|
|
Services.ww.openWindow(null, "chrome://browser/content/safeMode.xul",
|
|
|
|
"_blank", "chrome,centerscreen,modal,resizable=no", null);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-05-03 01:56:41 -07:00
|
|
|
|
2007-09-11 08:52:04 -07:00
|
|
|
// apply distribution customizations
|
|
|
|
// prefs are applied in _onAppDefaults()
|
2009-10-05 03:13:04 -07:00
|
|
|
this._distributionCustomizer.applyCustomizations();
|
2007-09-11 08:52:04 -07:00
|
|
|
|
2008-02-04 11:37:26 -08:00
|
|
|
// handle any UI migration
|
2008-03-20 11:57:05 -07:00
|
|
|
this._migrateUI();
|
2008-09-30 22:36:21 -07:00
|
|
|
|
2013-07-01 16:46:07 -07:00
|
|
|
this._syncSearchEngines();
|
|
|
|
|
2012-03-12 17:33:10 -07:00
|
|
|
webappsUI.init();
|
2012-05-02 13:11:19 -07:00
|
|
|
PageThumbs.init();
|
2012-08-21 11:17:18 -07:00
|
|
|
NewTabUtils.init();
|
2012-09-19 07:20:44 -07:00
|
|
|
BrowserNewTabPreloader.init();
|
2012-06-12 18:16:00 -07:00
|
|
|
SignInToWebsiteUX.init();
|
2012-06-02 09:56:24 -07:00
|
|
|
PdfJs.init();
|
2013-10-21 18:39:43 -07:00
|
|
|
#ifdef NIGHTLY_BUILD
|
2013-09-30 16:23:41 -07:00
|
|
|
ShumwayUtils.init();
|
2013-10-21 18:39:43 -07:00
|
|
|
#endif
|
2012-10-05 02:37:00 -07:00
|
|
|
webrtcUI.init();
|
2013-07-05 13:55:00 -07:00
|
|
|
AboutHome.init();
|
2013-10-17 11:26:25 -07:00
|
|
|
SessionStore.init();
|
2013-12-10 11:49:02 -08:00
|
|
|
BrowserUITelemetry.init();
|
2012-05-02 13:11:19 -07:00
|
|
|
|
2013-12-12 14:13:20 -08:00
|
|
|
if (Services.appinfo.browserTabsRemote)
|
2013-08-08 17:16:47 -07:00
|
|
|
ContentClick.init();
|
|
|
|
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
|
2007-05-10 17:42:22 -07:00
|
|
|
},
|
2007-05-03 01:56:41 -07:00
|
|
|
|
2013-07-30 20:19:58 -07:00
|
|
|
_checkForOldBuildUpdates: function () {
|
|
|
|
// check for update if our build is old
|
|
|
|
if (Services.prefs.getBoolPref("app.update.enabled") &&
|
|
|
|
Services.prefs.getBoolPref("app.update.checkInstallTime")) {
|
|
|
|
|
|
|
|
let buildID = Services.appinfo.appBuildID;
|
|
|
|
let today = new Date().getTime();
|
|
|
|
let buildDate = new Date(buildID.slice(0,4), // year
|
|
|
|
buildID.slice(4,6) - 1, // months are zero-based.
|
|
|
|
buildID.slice(6,8), // day
|
|
|
|
buildID.slice(8,10), // hour
|
|
|
|
buildID.slice(10,12), // min
|
|
|
|
buildID.slice(12,14)) // ms
|
|
|
|
.getTime();
|
|
|
|
|
|
|
|
const millisecondsIn24Hours = 86400000;
|
|
|
|
let acceptableAge = Services.prefs.getIntPref("app.update.checkInstallTime.days") * millisecondsIn24Hours;
|
|
|
|
|
|
|
|
if (buildDate + acceptableAge < today) {
|
|
|
|
Cc["@mozilla.org/updates/update-service;1"].getService(Ci.nsIApplicationUpdateService).checkForBackgroundUpdates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-01 13:47:07 -08:00
|
|
|
_trackSlowStartup: function () {
|
2013-02-19 15:15:38 -08:00
|
|
|
if (Services.startup.interrupted ||
|
|
|
|
Services.prefs.getBoolPref("browser.slowStartup.notificationDisabled"))
|
2013-02-01 13:47:07 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
let currentTime = Date.now() - Services.startup.getStartupInfo().process;
|
|
|
|
let averageTime = 0;
|
|
|
|
let samples = 0;
|
|
|
|
try {
|
|
|
|
averageTime = Services.prefs.getIntPref("browser.slowStartup.averageTime");
|
|
|
|
samples = Services.prefs.getIntPref("browser.slowStartup.samples");
|
|
|
|
} catch (e) { }
|
|
|
|
|
2013-08-12 16:55:05 -07:00
|
|
|
let totalTime = (averageTime * samples) + currentTime;
|
|
|
|
samples++;
|
|
|
|
averageTime = totalTime / samples;
|
2013-02-01 13:47:07 -08:00
|
|
|
|
|
|
|
if (samples >= Services.prefs.getIntPref("browser.slowStartup.maxSamples")) {
|
|
|
|
if (averageTime > Services.prefs.getIntPref("browser.slowStartup.timeThreshold"))
|
|
|
|
this._showSlowStartupNotification();
|
|
|
|
averageTime = 0;
|
|
|
|
samples = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.prefs.setIntPref("browser.slowStartup.averageTime", averageTime);
|
|
|
|
Services.prefs.setIntPref("browser.slowStartup.samples", samples);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showSlowStartupNotification: function () {
|
|
|
|
let win = this.getMostRecentBrowserWindow();
|
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let productName = Services.strings
|
|
|
|
.createBundle("chrome://branding/locale/brand.properties")
|
|
|
|
.GetStringFromName("brandFullName");
|
|
|
|
let message = win.gNavigatorBundle.getFormattedString("slowStartup.message", [productName]);
|
|
|
|
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getString("slowStartup.helpButton.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("slowStartup.helpButton.accesskey"),
|
|
|
|
callback: function () {
|
2013-08-23 18:30:07 -07:00
|
|
|
win.openUILinkIn("https://support.mozilla.org/kb/reset-firefox-easily-fix-most-problems", "tab");
|
2013-02-01 13:47:07 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getString("slowStartup.disableNotificationButton.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("slowStartup.disableNotificationButton.accesskey"),
|
|
|
|
callback: function () {
|
|
|
|
Services.prefs.setBoolPref("browser.slowStartup.notificationDisabled", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
let nb = win.document.getElementById("global-notificationbox");
|
|
|
|
nb.appendNotification(message, "slow-startup",
|
|
|
|
"chrome://browser/skin/slowStartup-16.png",
|
|
|
|
nb.PRIORITY_INFO_LOW, buttons);
|
|
|
|
},
|
|
|
|
|
2013-06-28 20:25:08 -07:00
|
|
|
/**
|
|
|
|
* Show a notification bar offering a reset if the profile has been unused for some time.
|
|
|
|
*/
|
|
|
|
_resetUnusedProfileNotification: function () {
|
|
|
|
let win = this.getMostRecentBrowserWindow();
|
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/ResetProfile.jsm");
|
|
|
|
if (!ResetProfile.resetSupported())
|
|
|
|
return;
|
|
|
|
|
|
|
|
let productName = Services.strings
|
|
|
|
.createBundle("chrome://branding/locale/brand.properties")
|
|
|
|
.GetStringFromName("brandShortName");
|
|
|
|
let resetBundle = Services.strings
|
|
|
|
.createBundle("chrome://global/locale/resetProfile.properties");
|
|
|
|
|
|
|
|
let message = resetBundle.formatStringFromName("resetUnusedProfile.message", [productName], 1);
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: resetBundle.formatStringFromName("resetProfile.resetButton.label", [productName], 1),
|
|
|
|
accessKey: resetBundle.GetStringFromName("resetProfile.resetButton.accesskey"),
|
|
|
|
callback: function () {
|
|
|
|
ResetProfile.openConfirmationDialog(win);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
let nb = win.document.getElementById("global-notificationbox");
|
|
|
|
nb.appendNotification(message, "reset-unused-profile",
|
|
|
|
"chrome://global/skin/icons/question-16.png",
|
|
|
|
nb.PRIORITY_INFO_LOW, buttons);
|
|
|
|
},
|
|
|
|
|
2010-10-02 08:53:37 -07:00
|
|
|
// the first browser window has finished initializing
|
2013-07-26 22:40:07 -07:00
|
|
|
_onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) {
|
2010-10-02 08:53:37 -07:00
|
|
|
#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 = {};
|
2013-05-28 19:21:53 -07:00
|
|
|
Cu.import("resource:///modules/WindowsJumpLists.jsm", temp);
|
2010-10-02 08:53:37 -07:00
|
|
|
temp.WinTaskbarJumpList.startup();
|
|
|
|
}
|
|
|
|
#endif
|
2013-02-01 13:47:07 -08:00
|
|
|
|
|
|
|
this._trackSlowStartup();
|
2013-06-28 20:25:08 -07:00
|
|
|
|
|
|
|
// Offer to reset a user's profile if it hasn't been used for 60 days.
|
|
|
|
const OFFER_PROFILE_RESET_INTERVAL_MS = 60 * 24 * 60 * 60 * 1000;
|
|
|
|
let lastUse = Services.appinfo.replacedLockTime;
|
2013-07-27 08:22:56 -07:00
|
|
|
if (lastUse &&
|
|
|
|
Date.now() - lastUse >= OFFER_PROFILE_RESET_INTERVAL_MS) {
|
2013-06-28 20:25:08 -07:00
|
|
|
this._resetUnusedProfileNotification();
|
|
|
|
}
|
2013-07-30 20:19:58 -07:00
|
|
|
|
|
|
|
this._checkForOldBuildUpdates();
|
2010-10-02 08:53:37 -07:00
|
|
|
},
|
|
|
|
|
2013-01-29 09:06:03 -08:00
|
|
|
/**
|
2014-02-07 09:47:35 -08:00
|
|
|
* Application shutdown handler.
|
2013-01-29 09:06:03 -08:00
|
|
|
*/
|
2014-02-07 09:47:35 -08:00
|
|
|
_onQuitApplicationGranted: function () {
|
|
|
|
// This pref must be set here because SessionStore will use its value
|
|
|
|
// on quit-application.
|
|
|
|
this._setPrefToSaveSession();
|
2014-02-08 13:04:31 -08:00
|
|
|
|
|
|
|
// Call trackStartupCrashEnd here in case the delayed call on startup hasn't
|
|
|
|
// yet occurred (see trackStartupCrashEnd caller in browser.js).
|
2014-02-07 09:47:35 -08: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);
|
|
|
|
}
|
|
|
|
|
2012-09-19 07:20:44 -07:00
|
|
|
BrowserNewTabPreloader.uninit();
|
2014-02-25 09:51:41 -08:00
|
|
|
CustomizationTabPreloader.uninit();
|
2013-01-29 09:06:03 -08:00
|
|
|
webappsUI.uninit();
|
|
|
|
SignInToWebsiteUX.uninit();
|
|
|
|
webrtcUI.uninit();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2012-01-18 15:25:05 -08:00
|
|
|
// All initial windows have opened.
|
|
|
|
_onWindowsRestored: function BG__onWindowsRestored() {
|
2010-04-06 19:49:23 -07:00
|
|
|
// Show update notification, if needed.
|
2010-04-12 07:33:10 -07:00
|
|
|
if (Services.prefs.prefHasUserValue("app.update.postupdate"))
|
2010-04-06 19:49:23 -07:00
|
|
|
this._showUpdateNotification();
|
|
|
|
|
2008-12-30 04:44:55 -08:00
|
|
|
// Load the "more info" page for a locked places.sqlite
|
2010-08-09 08:59:59 -07:00
|
|
|
// This property is set earlier by places-database-locked topic.
|
2008-12-30 04:44:55 -08:00
|
|
|
if (this._isPlacesDatabaseLocked) {
|
|
|
|
this._showPlacesLockedNotificationBox();
|
|
|
|
}
|
2009-10-02 04:26:04 -07:00
|
|
|
|
|
|
|
// If there are plugins installed that are outdated, and the user hasn't
|
|
|
|
// been warned about them yet, open the plugins update page.
|
2010-04-12 07:33:10 -07:00
|
|
|
if (Services.prefs.getBoolPref(PREF_PLUGINS_NOTIFYUSER))
|
2009-10-02 04:26:04 -07:00
|
|
|
this._showPluginUpdatePage();
|
2011-08-12 13:50:47 -07:00
|
|
|
|
|
|
|
// For any add-ons that were installed disabled and can be enabled offer
|
2012-02-15 15:44:29 -08:00
|
|
|
// them to the user.
|
|
|
|
let changedIDs = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED);
|
|
|
|
if (changedIDs.length > 0) {
|
2012-11-30 20:11:44 -08:00
|
|
|
let win = this.getMostRecentBrowserWindow();
|
2012-02-15 15:44:29 -08:00
|
|
|
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;
|
|
|
|
|
2012-11-30 20:11:44 -08:00
|
|
|
win.openUILinkIn("about:newaddon?id=" + aAddon.id, "tab");
|
2012-02-15 15:44:29 -08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2012-02-06 17:39:07 -08:00
|
|
|
|
2012-03-06 14:28:53 -08: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 12:05:23 -07:00
|
|
|
let shouldCheck = false;
|
2012-03-06 14:28:53 -08:00
|
|
|
#else
|
2012-03-21 12:05:23 -07:00
|
|
|
let shouldCheck = shell.shouldCheckDefaultBrowser;
|
2012-03-06 14:28:53 -08:00
|
|
|
#endif
|
2012-03-21 12:05:23 -07:00
|
|
|
let willRecoverSession = false;
|
2012-03-06 14:28:53 -08:00
|
|
|
try {
|
2012-03-21 12:05:23 -07:00
|
|
|
let ss = Cc["@mozilla.org/browser/sessionstartup;1"].
|
2012-03-06 14:28:53 -08:00
|
|
|
getService(Ci.nsISessionStartup);
|
|
|
|
willRecoverSession =
|
|
|
|
(ss.sessionType == Ci.nsISessionStartup.RECOVER_SESSION);
|
|
|
|
}
|
|
|
|
catch (ex) { /* never mind; suppose SessionStore is broken */ }
|
2013-05-30 10:32:17 -07:00
|
|
|
|
|
|
|
let isDefault = shell.isDefaultBrowser(true, false); // startup check, check all assoc
|
|
|
|
try {
|
|
|
|
// Report default browser status on startup to telemetry
|
|
|
|
// so we can track whether we are the default.
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT")
|
|
|
|
.add(isDefault);
|
|
|
|
}
|
|
|
|
catch (ex) { /* Don't break the default prompt if telemetry is broken. */ }
|
|
|
|
|
|
|
|
if (shouldCheck && !isDefault && !willRecoverSession) {
|
2012-03-06 14:28:53 -08:00
|
|
|
Services.tm.mainThread.dispatch(function() {
|
2012-03-21 12:05:23 -07:00
|
|
|
var win = this.getMostRecentBrowserWindow();
|
2012-03-06 14:28:53 -08:00
|
|
|
var brandBundle = win.document.getElementById("bundle_brand");
|
|
|
|
var shellBundle = win.document.getElementById("bundle_shell");
|
2013-01-11 19:05:35 -08:00
|
|
|
|
2012-03-06 14:28:53 -08:00
|
|
|
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);
|
2012-09-21 07:05:24 -07:00
|
|
|
if (rv == 0) {
|
|
|
|
var claimAllTypes = true;
|
|
|
|
#ifdef XP_WIN
|
|
|
|
try {
|
|
|
|
// In Windows 8, the UI for selecting default protocol is much
|
|
|
|
// nicer than the UI for setting file type associations. So we
|
|
|
|
// only show the protocol association screen on Windows 8.
|
|
|
|
// Windows 8 is version 6.2.
|
|
|
|
let version = Cc["@mozilla.org/system-info;1"]
|
|
|
|
.getService(Ci.nsIPropertyBag2)
|
|
|
|
.getProperty("version");
|
|
|
|
claimAllTypes = (parseFloat(version) < 6.2);
|
|
|
|
} catch (ex) { }
|
|
|
|
#endif
|
|
|
|
shell.setDefaultBrowser(claimAllTypes, false);
|
|
|
|
}
|
2012-03-06 14:28:53 -08:00
|
|
|
shell.shouldCheckDefaultBrowser = checkEveryTime.value;
|
2012-03-21 12:05:23 -07:00
|
|
|
}.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
|
2012-03-06 14:28:53 -08:00
|
|
|
}
|
|
|
|
}
|
2008-03-07 16:16:38 -08:00
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {
|
2008-01-29 13:16:02 -08:00
|
|
|
// If user has already dismissed quit request, then do nothing
|
|
|
|
if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
|
|
|
|
return;
|
|
|
|
|
2011-02-07 17:50:37 -08: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
|
2012-12-28 11:41:13 -08:00
|
|
|
// 5. The browser will be restarted.
|
2011-02-07 17:50:37 -08:00
|
|
|
//
|
|
|
|
// 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
|
2012-12-28 11:41:13 -08:00
|
|
|
// 2. aQuitType == "lastwindow" && browser.tabs.warnOnClose == true
|
2011-02-07 17:50:37 -08:00
|
|
|
// - 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".
|
|
|
|
|
2012-12-28 11:41:13 -08:00
|
|
|
if (aQuitType == "restart")
|
|
|
|
return;
|
|
|
|
|
2007-06-15 11:01:25 -07:00
|
|
|
var windowcount = 0;
|
2008-05-10 08:52:32 -07:00
|
|
|
var pagecount = 0;
|
2010-04-12 07:33:10 -07:00
|
|
|
var browserEnum = Services.wm.getEnumerator("navigator:browser");
|
2012-06-28 14:22:41 -07:00
|
|
|
let allWindowsPrivate = true;
|
2008-05-10 08:52:32 -07:00
|
|
|
while (browserEnum.hasMoreElements()) {
|
2013-09-13 14:29:51 -07:00
|
|
|
// XXXbz should we skip closed windows here?
|
2008-05-10 08:52:32 -07:00
|
|
|
windowcount++;
|
|
|
|
|
|
|
|
var browser = browserEnum.getNext();
|
2012-10-05 16:25:52 -07:00
|
|
|
if (!PrivateBrowsingUtils.isWindowPrivate(browser))
|
2012-06-28 14:22:41 -07:00
|
|
|
allWindowsPrivate = false;
|
2008-05-10 08:52:32 -07:00
|
|
|
var tabbrowser = browser.document.getElementById("content");
|
|
|
|
if (tabbrowser)
|
2010-08-13 05:40:19 -07:00
|
|
|
pagecount += tabbrowser.browsers.length - tabbrowser._numPinnedTabs;
|
2008-05-10 08:52:32 -07:00
|
|
|
}
|
2007-06-15 11:01:25 -07:00
|
|
|
|
|
|
|
this._saveSession = false;
|
2008-05-10 08:52:32 -07:00
|
|
|
if (pagecount < 2)
|
|
|
|
return;
|
2007-06-15 11:01:25 -07:00
|
|
|
|
2011-02-07 17:50:37 -08:00
|
|
|
if (!aQuitType)
|
2007-07-25 14:43:17 -07:00
|
|
|
aQuitType = "quit";
|
|
|
|
|
2011-02-07 17:50:37 -08:00
|
|
|
var mostRecentBrowserWindow;
|
|
|
|
|
|
|
|
// browser.warnOnQuit is a hidden global boolean to override all quit prompts
|
|
|
|
// browser.showQuitWarning specifically covers quitting
|
|
|
|
// 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.
|
2012-12-28 11:41:13 -08:00
|
|
|
if (!Services.prefs.getBoolPref("browser.showQuitWarning")) {
|
|
|
|
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");
|
2013-05-29 07:07:26 -07:00
|
|
|
let allTabs = mostRecentBrowserWindow.gBrowser.closingTabsEnum.ALL;
|
|
|
|
aCancelQuit.data = !mostRecentBrowserWindow.gBrowser.warnAboutClosingTabs(allTabs)
|
2012-12-28 11:41:13 -08:00
|
|
|
}
|
2011-02-07 17:50:37 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-28 14:22:41 -07:00
|
|
|
// Never show a prompt inside private browsing mode
|
|
|
|
if (allWindowsPrivate)
|
2012-06-27 02:44:45 -07:00
|
|
|
return;
|
|
|
|
|
2010-04-12 07:33:10 -07:00
|
|
|
var quitBundle = Services.strings.createBundle("chrome://browser/locale/quitDialog.properties");
|
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
2008-05-08 08:08:40 -07:00
|
|
|
|
|
|
|
var appName = brandBundle.GetStringFromName("brandShortName");
|
2012-12-28 11:41:13 -08:00
|
|
|
var quitTitleString = "quitDialogTitle";
|
2011-02-08 11:04:13 -08:00
|
|
|
var quitDialogTitle = quitBundle.formatStringFromName(quitTitleString, [appName], 1);
|
2008-05-08 08:08:40 -07:00
|
|
|
|
|
|
|
var message;
|
2012-12-28 11:41:13 -08:00
|
|
|
if (windowcount == 1)
|
2008-05-08 08:08:40 -07:00
|
|
|
message = quitBundle.formatStringFromName("messageNoWindows",
|
|
|
|
[appName], 1);
|
|
|
|
else
|
|
|
|
message = quitBundle.formatStringFromName("message",
|
|
|
|
[appName], 1);
|
|
|
|
|
2010-04-12 07:33:10 -07:00
|
|
|
var promptService = Services.prompt;
|
2008-05-08 08:08:40 -07:00
|
|
|
|
|
|
|
var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
|
|
|
|
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
|
2012-12-28 11:41:13 -08:00
|
|
|
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2 +
|
2008-05-08 08:08:40 -07:00
|
|
|
promptService.BUTTON_POS_0_DEFAULT;
|
|
|
|
|
|
|
|
var neverAsk = {value:false};
|
2012-12-28 11:41:13 -08:00
|
|
|
var button0Title = quitBundle.GetStringFromName("saveTitle");
|
2008-05-08 08:08:40 -07:00
|
|
|
var button1Title = quitBundle.GetStringFromName("cancelTitle");
|
2012-12-28 11:41:13 -08:00
|
|
|
var button2Title = quitBundle.GetStringFromName("quitTitle");
|
2013-04-03 04:59:30 -07:00
|
|
|
var neverAskText = quitBundle.GetStringFromName("neverAsk2");
|
2008-05-08 08:08:40 -07:00
|
|
|
|
2011-02-07 17:50:37 -08: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-30 21:57:57 -07:00
|
|
|
var buttonChoice =
|
|
|
|
promptService.confirmEx(mostRecentBrowserWindow, quitDialogTitle, message,
|
|
|
|
flags, button0Title, button1Title, button2Title,
|
|
|
|
neverAskText, neverAsk);
|
2008-05-08 08:08:40 -07:00
|
|
|
|
|
|
|
switch (buttonChoice) {
|
|
|
|
case 2: // Quit
|
|
|
|
if (neverAsk.value)
|
2011-02-07 17:50:37 -08:00
|
|
|
Services.prefs.setBoolPref("browser.showQuitWarning", false);
|
2008-05-08 08:08:40 -07:00
|
|
|
break;
|
|
|
|
case 1: // Cancel
|
|
|
|
aCancelQuit.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
aCancelQuit.data = true;
|
|
|
|
break;
|
|
|
|
case 0: // Save & Quit
|
|
|
|
this._saveSession = true;
|
|
|
|
if (neverAsk.value) {
|
2012-12-28 11:41:13 -08:00
|
|
|
// always save state when shutting down
|
|
|
|
Services.prefs.setIntPref("browser.startup.page", 3);
|
2007-06-15 11:01:25 -07:00
|
|
|
}
|
2008-05-08 08:08:40 -07:00
|
|
|
break;
|
2007-06-15 11:01:25 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-04-06 19:49:23 -07:00
|
|
|
_showUpdateNotification: function BG__showUpdateNotification() {
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.prefs.clearUserPref("app.update.postupdate");
|
2010-04-06 19:49:23 -07: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 07:33:10 -07:00
|
|
|
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
2010-04-06 19:49:23 -07: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();
|
2012-11-30 20:11:44 -08:00
|
|
|
let notifyBox = win.gBrowser.getNotificationBox();
|
2010-04-06 19:49:23 -07:00
|
|
|
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: label,
|
|
|
|
accessKey: key,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
2012-11-30 20:11:44 -08:00
|
|
|
win.openUILinkIn(url, "tab");
|
2010-04-06 19:49:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2011-11-04 14:45:01 -07:00
|
|
|
let notification = notifyBox.appendNotification(text, "post-update-notification",
|
|
|
|
null, notifyBox.PRIORITY_INFO_LOW,
|
|
|
|
buttons);
|
|
|
|
notification.persistence = -1; // Until user closes it
|
2010-04-06 19:49:23 -07: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();
|
2012-11-30 20:11:44 -08:00
|
|
|
win.openUILinkIn(data, "tab");
|
2010-04-06 19:49:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// This will throw NS_ERROR_NOT_AVAILABLE if the notification cannot
|
|
|
|
// be displayed per the idl.
|
2012-05-04 11:23:55 -07:00
|
|
|
notifier.showAlertNotification(null, title, text,
|
2010-04-06 19:49:23 -07:00
|
|
|
true, url, clickCallback);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_showPluginUpdatePage: function BG__showPluginUpdatePage() {
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.prefs.setBoolPref(PREF_PLUGINS_NOTIFYUSER, false);
|
2009-10-02 04:26:04 -07:00
|
|
|
|
|
|
|
var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
|
|
|
|
getService(Ci.nsIURLFormatter);
|
|
|
|
var updateUrl = formatter.formatURLPref(PREF_PLUGINS_UPDATEURL);
|
|
|
|
|
|
|
|
var win = this.getMostRecentBrowserWindow();
|
2012-11-30 20:11:44 -08:00
|
|
|
win.openUILinkIn(updateUrl, "tab");
|
2009-10-02 04:26:04 -07:00
|
|
|
},
|
2008-10-30 23:42:02 -07:00
|
|
|
|
2007-05-03 01:56:41 -07:00
|
|
|
/**
|
|
|
|
* Initialize Places
|
2008-11-12 12:45:53 -08:00
|
|
|
* - imports the bookmarks html file if bookmarks database is empty, try to
|
|
|
|
* restore bookmarks from a JSON backup if the backend indicates that the
|
|
|
|
* database was corrupt.
|
|
|
|
*
|
|
|
|
* These prefs can be set up by the frontend:
|
|
|
|
*
|
|
|
|
* WARNING: setting these preferences to true will overwite existing bookmarks
|
2008-03-28 09:43:17 -07:00
|
|
|
*
|
|
|
|
* - browser.places.importBookmarksHTML
|
2008-11-12 12:45:53 -08:00
|
|
|
* Set to true will import the bookmarks.html file from the profile folder.
|
2008-04-08 11:42:53 -07:00
|
|
|
* - browser.places.smartBookmarksVersion
|
|
|
|
* Set during HTML import to indicate that Smart Bookmarks were created.
|
|
|
|
* Set to -1 to disable Smart Bookmarks creation.
|
|
|
|
* Set to 0 to restore current Smart Bookmarks.
|
2008-04-02 12:33:01 -07:00
|
|
|
* - browser.bookmarks.restore_default_bookmarks
|
|
|
|
* Set to true by safe-mode dialog to indicate we must restore default
|
|
|
|
* bookmarks.
|
2007-05-03 01:56:41 -07:00
|
|
|
*/
|
2012-05-28 02:43:59 -07:00
|
|
|
_initPlaces: function BG__initPlaces(aInitialMigrationPerformed) {
|
2008-11-12 12:45:53 -08:00
|
|
|
// We must instantiate the history service since it will tell us if we
|
|
|
|
// need to import or restore bookmarks due to first-run, corruption or
|
|
|
|
// forced migration (due to a major schema change).
|
|
|
|
// If the database is corrupt or has been newly created we should
|
|
|
|
// import bookmarks.
|
2014-03-03 08:51:42 -08:00
|
|
|
let dbStatus = PlacesUtils.history.databaseStatus;
|
|
|
|
let importBookmarks = !aInitialMigrationPerformed &&
|
2012-03-23 00:15:36 -07:00
|
|
|
(dbStatus == PlacesUtils.history.DATABASE_STATUS_CREATE ||
|
|
|
|
dbStatus == PlacesUtils.history.DATABASE_STATUS_CORRUPT);
|
2009-02-09 10:16:02 -08:00
|
|
|
|
2008-11-12 12:45:53 -08:00
|
|
|
// Check if user or an extension has required to import bookmarks.html
|
2014-03-03 08:51:42 -08:00
|
|
|
let importBookmarksHTML = false;
|
2008-11-12 12:45:53 -08:00
|
|
|
try {
|
|
|
|
importBookmarksHTML =
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.prefs.getBoolPref("browser.places.importBookmarksHTML");
|
2008-11-12 12:45:53 -08:00
|
|
|
if (importBookmarksHTML)
|
|
|
|
importBookmarks = true;
|
|
|
|
} catch(ex) {}
|
2007-12-04 00:08:33 -08:00
|
|
|
|
2013-04-09 01:23:40 -07:00
|
|
|
Task.spawn(function() {
|
|
|
|
// Check if Safe Mode or the user has required to restore bookmarks from
|
|
|
|
// default profile's bookmarks.html
|
2014-03-03 08:51:42 -08:00
|
|
|
let restoreDefaultBookmarks = false;
|
2013-04-09 01:23:40 -07:00
|
|
|
try {
|
|
|
|
restoreDefaultBookmarks =
|
|
|
|
Services.prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
|
|
|
if (restoreDefaultBookmarks) {
|
|
|
|
// Ensure that we already have a bookmarks backup for today.
|
2013-10-06 23:52:08 -07:00
|
|
|
yield this._backupBookmarks();
|
2013-04-09 01:23:40 -07:00
|
|
|
importBookmarks = true;
|
|
|
|
}
|
|
|
|
} catch(ex) {}
|
|
|
|
|
2014-02-04 05:43:20 -08:00
|
|
|
// This may be reused later, check for "=== undefined" to see if it has
|
|
|
|
// been populated already.
|
|
|
|
let lastBackupFile;
|
|
|
|
|
2013-04-09 01:23:40 -07: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
|
2014-02-04 05:43:20 -08:00
|
|
|
lastBackupFile = yield PlacesBackups.getMostRecentBackup("json");
|
|
|
|
if (lastBackupFile) {
|
2013-04-09 01:23:40 -07:00
|
|
|
// restore from JSON backup
|
2014-02-04 05:43:20 -08:00
|
|
|
yield BookmarkJSONUtils.importFromFile(lastBackupFile, true);
|
2013-04-09 01:23:40 -07:00
|
|
|
importBookmarks = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We have created a new database but we don't have any backup available
|
|
|
|
importBookmarks = true;
|
2014-03-03 08:51:42 -08:00
|
|
|
if (yield OS.File.exists(BookmarkHTMLUtils.defaultPath)) {
|
2013-04-09 01:23:40 -07:00
|
|
|
// If bookmarks.html is available in current profile import it...
|
|
|
|
importBookmarksHTML = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// ...otherwise we will restore defaults
|
|
|
|
restoreDefaultBookmarks = true;
|
|
|
|
}
|
|
|
|
}
|
2008-11-12 12:45:53 -08:00
|
|
|
}
|
2007-12-04 03:22:14 -08:00
|
|
|
|
2013-04-09 01:23:40 -07:00
|
|
|
// If bookmarks are not imported, then initialize smart bookmarks. This
|
|
|
|
// happens during a common startup.
|
|
|
|
// Otherwise, if any kind of import runs, smart bookmarks creation should be
|
|
|
|
// delayed till the import operations has finished. Not doing so would
|
|
|
|
// cause them to be overwritten by the newly imported bookmarks.
|
|
|
|
if (!importBookmarks) {
|
|
|
|
// Now apply distribution customized bookmarks.
|
|
|
|
// This should always run after Places initialization.
|
|
|
|
this._distributionCustomizer.applyBookmarks();
|
|
|
|
this.ensurePlacesDefaultQueriesInitialized();
|
2008-11-12 12:45:53 -08:00
|
|
|
}
|
|
|
|
else {
|
2013-04-09 01:23:40 -07:00
|
|
|
// An import operation is about to run.
|
|
|
|
// Don't try to recreate smart bookmarks if autoExportHTML is true or
|
|
|
|
// smart bookmarks are disabled.
|
2014-03-03 08:51:42 -08:00
|
|
|
let autoExportHTML = false;
|
2013-04-09 01:23:40 -07:00
|
|
|
try {
|
|
|
|
autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
|
|
|
} catch(ex) {}
|
2014-03-03 08:51:42 -08:00
|
|
|
let smartBookmarksVersion = 0;
|
2013-04-09 01:23:40 -07:00
|
|
|
try {
|
|
|
|
smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion");
|
|
|
|
} catch(ex) {}
|
|
|
|
if (!autoExportHTML && smartBookmarksVersion != -1)
|
|
|
|
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
|
|
|
|
2014-03-03 08:51:42 -08:00
|
|
|
let bookmarksUrl = null;
|
2013-04-09 01:23:40 -07:00
|
|
|
if (restoreDefaultBookmarks) {
|
|
|
|
// User wants to restore bookmarks.html file from default profile folder
|
2014-03-03 08:51:42 -08:00
|
|
|
bookmarksUrl = "resource:///defaults/profile/bookmarks.html";
|
2008-12-09 12:39:32 -08:00
|
|
|
}
|
2014-03-03 08:51:42 -08:00
|
|
|
else if (yield OS.File.exists(BookmarkHTMLUtils.defaultPath)) {
|
|
|
|
bookmarksUrl = OS.Path.toFileURI(BookmarkHTMLUtils.defaultPath);
|
2008-12-09 12:39:32 -08:00
|
|
|
}
|
2008-11-12 12:45:53 -08:00
|
|
|
|
2014-03-03 08:51:42 -08:00
|
|
|
if (bookmarksUrl) {
|
2013-04-09 01:23:40 -07:00
|
|
|
// Import from bookmarks.html file.
|
|
|
|
try {
|
2014-03-03 08:51:42 -08:00
|
|
|
BookmarkHTMLUtils.importFromURL(bookmarksUrl, true).then(null,
|
2013-04-09 01:23:40 -07:00
|
|
|
function onFailure() {
|
|
|
|
Cu.reportError("Bookmarks.html file could be corrupt.");
|
|
|
|
}
|
|
|
|
).then(
|
|
|
|
function onComplete() {
|
|
|
|
// 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();
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError("Bookmarks.html file could be corrupt. " + err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Cu.reportError("Unable to find bookmarks.html file.");
|
|
|
|
}
|
2008-11-12 12:45:53 -08:00
|
|
|
|
2013-04-09 01:23:40 -07:00
|
|
|
// Reset preferences, so we won't try to import again at next run
|
|
|
|
if (importBookmarksHTML)
|
|
|
|
Services.prefs.setBoolPref("browser.places.importBookmarksHTML", false);
|
|
|
|
if (restoreDefaultBookmarks)
|
|
|
|
Services.prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks",
|
|
|
|
false);
|
2007-05-03 01:56:41 -07:00
|
|
|
}
|
2008-11-18 09:25:39 -08:00
|
|
|
|
2013-04-09 01:23:40 -07:00
|
|
|
// Initialize bookmark archiving on idle.
|
2014-02-04 05:43:20 -08:00
|
|
|
if (!this._bookmarksBackupIdleTime) {
|
|
|
|
this._bookmarksBackupIdleTime = BOOKMARKS_BACKUP_IDLE_TIME_SEC;
|
|
|
|
|
|
|
|
// If there is no backup, or the last bookmarks backup is too old, use
|
|
|
|
// a more aggressive idle observer.
|
|
|
|
if (lastBackupFile === undefined)
|
|
|
|
lastBackupFile = yield PlacesBackups.getMostRecentBackup();
|
|
|
|
if (!lastBackupFile) {
|
|
|
|
this._bookmarksBackupIdleTime /= 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let lastBackupTime = PlacesBackups.getDateForFile(lastBackupFile);
|
|
|
|
let profileLastUse = Services.appinfo.replacedLockTime || Date.now();
|
|
|
|
|
|
|
|
// If there is a backup after the last profile usage date it's fine,
|
|
|
|
// regardless its age. Otherwise check how old is the last
|
|
|
|
// available backup compared to that session.
|
|
|
|
if (profileLastUse > lastBackupTime) {
|
|
|
|
let backupAge = Math.round((profileLastUse - lastBackupTime) / 86400000);
|
|
|
|
// Report the age of the last available backup.
|
|
|
|
try {
|
|
|
|
Services.telemetry
|
|
|
|
.getHistogramById("PLACES_BACKUPS_DAYSFROMLAST")
|
|
|
|
.add(backupAge);
|
|
|
|
} catch (ex) {
|
|
|
|
Components.utils.reportError("Unable to report telemetry.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backupAge > BOOKMARKS_BACKUP_MAX_INTERVAL_DAYS)
|
|
|
|
this._bookmarksBackupIdleTime /= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._idleService.addIdleObserver(this, this._bookmarksBackupIdleTime);
|
2012-03-23 00:15:36 -07:00
|
|
|
}
|
2013-04-16 22:36:02 -07:00
|
|
|
|
|
|
|
Services.obs.notifyObservers(null, "places-browser-init-complete", "");
|
2013-04-09 01:23:40 -07:00
|
|
|
}.bind(this));
|
2007-05-03 01:56:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Places shut-down tasks
|
2013-01-29 09:06:03 -08:00
|
|
|
* - finalize components depending on Places.
|
2014-02-04 05:43:20 -08:00
|
|
|
* - export bookmarks as HTML, if so configured.
|
2007-05-03 01:56:41 -07:00
|
|
|
*/
|
2013-01-29 09:06:03 -08:00
|
|
|
_onPlacesShutdown: function BG__onPlacesShutdown() {
|
|
|
|
this._sanitizer.onShutdown();
|
|
|
|
PageThumbs.uninit();
|
|
|
|
|
2014-02-04 05:43:20 -08:00
|
|
|
if (this._bookmarksBackupIdleTime) {
|
|
|
|
this._idleService.removeIdleObserver(this, this._bookmarksBackupIdleTime);
|
|
|
|
delete this._bookmarksBackupIdleTime;
|
2010-04-22 05:53:54 -07:00
|
|
|
}
|
2013-01-29 09:06:03 -08:00
|
|
|
|
2014-02-04 05:43:20 -08:00
|
|
|
// Support legacy bookmarks.html format for apps that depend on that format.
|
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML")) {
|
|
|
|
// places-shutdown happens at profile-change-teardown, so here we
|
|
|
|
// can safely add a profile-before-change blocker.
|
|
|
|
AsyncShutdown.profileBeforeChange.addBlocker(
|
|
|
|
"Places: bookmarks.html",
|
2014-03-03 08:51:42 -08:00
|
|
|
() => BookmarkHTMLUtils.exportToFile(BookmarkHTMLUtils.defaultPath)
|
2014-02-04 05:43:20 -08:00
|
|
|
.then(null, Cu.reportError)
|
|
|
|
);
|
2013-10-06 23:52:08 -07:00
|
|
|
}
|
2014-02-04 05:43:20 -08:00
|
|
|
} catch (ex) {} // Do not export.
|
2008-03-13 12:25:49 -07:00
|
|
|
},
|
|
|
|
|
2013-04-09 01:23:40 -07:00
|
|
|
/**
|
2014-02-04 05:43:20 -08:00
|
|
|
* If a backup for today doesn't exist, this creates one.
|
2013-04-09 01:23:40 -07:00
|
|
|
*/
|
|
|
|
_backupBookmarks: function BG__backupBookmarks() {
|
|
|
|
return Task.spawn(function() {
|
2013-10-06 23:52:08 -07:00
|
|
|
let lastBackupFile = yield PlacesBackups.getMostRecentBackup();
|
|
|
|
// Should backup bookmarks if there are no backups or the maximum
|
|
|
|
// interval between backups elapsed.
|
|
|
|
if (!lastBackupFile ||
|
2014-02-04 05:43:20 -08:00
|
|
|
new Date() - PlacesBackups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_MIN_INTERVAL_DAYS * 86400000) {
|
|
|
|
let maxBackups = Services.prefs.getIntPref("browser.bookmarks.max_backups");
|
|
|
|
yield PlacesBackups.create(maxBackups);
|
2013-10-06 23:52:08 -07:00
|
|
|
}
|
2013-04-09 01:23:40 -07:00
|
|
|
});
|
2007-05-03 01:56:41 -07:00
|
|
|
},
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2008-12-30 04:44:55 -08:00
|
|
|
/**
|
|
|
|
* Show the notificationBox for a locked places database.
|
|
|
|
*/
|
2009-12-17 13:28:08 -08:00
|
|
|
_showPlacesLockedNotificationBox: function BG__showPlacesLockedNotificationBox() {
|
2010-04-12 07:33:10 -07:00
|
|
|
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
2008-12-30 04:44:55 -08:00
|
|
|
var applicationName = brandBundle.GetStringFromName("brandShortName");
|
2010-04-12 07:33:10 -07:00
|
|
|
var placesBundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");
|
2008-12-30 04:44:55 -08: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;
|
|
|
|
|
2012-11-30 20:11:44 -08:00
|
|
|
var win = this.getMostRecentBrowserWindow();
|
2008-12-30 04:44:55 -08:00
|
|
|
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: buttonText,
|
|
|
|
accessKey: accessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotificationBar, aButton) {
|
2012-11-30 20:11:44 -08:00
|
|
|
win.openUILinkIn(url, "tab");
|
2008-12-30 04:44:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2012-11-30 20:11:44 -08:00
|
|
|
var notifyBox = win.gBrowser.getNotificationBox();
|
2011-11-04 14:45:01 -07:00
|
|
|
var notification = notifyBox.appendNotification(text, title, null,
|
|
|
|
notifyBox.PRIORITY_CRITICAL_MEDIUM,
|
|
|
|
buttons);
|
|
|
|
notification.persistence = -1; // Until user closes it
|
2008-12-30 04:44:55 -08:00
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_migrateUI: function BG__migrateUI() {
|
2014-03-06 08:29:12 -08:00
|
|
|
const UI_VERSION = 21;
|
2010-12-22 10:26:18 -08:00
|
|
|
const BROWSER_DOCURL = "chrome://browser/content/browser.xul#";
|
2013-11-04 06:11:44 -08:00
|
|
|
let currentUIVersion = 0;
|
|
|
|
try {
|
|
|
|
currentUIVersion = Services.prefs.getIntPref("browser.migration.version");
|
|
|
|
} catch(ex) {}
|
2013-11-05 01:23:40 -08:00
|
|
|
if (currentUIVersion >= UI_VERSION)
|
2013-11-04 06:11:44 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
this._rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
|
|
|
|
this._dataSource = this._rdf.GetDataSource("rdf:local-store");
|
2010-07-09 12:44:01 -07:00
|
|
|
this._dirty = false;
|
2008-02-04 11:37:26 -08:00
|
|
|
|
2010-07-09 12:44:01 -07:00
|
|
|
if (currentUIVersion < 2) {
|
|
|
|
// This code adds the customizable bookmarks button.
|
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
2010-12-22 10:26:18 -08:00
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
2010-07-09 12:44:01 -07: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 01:33:17 -07:00
|
|
|
currentset += ",bookmarks-menu-button-container";
|
2010-07-09 12:44:01 -07:00
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
|
|
|
}
|
|
|
|
}
|
2008-02-04 11:37:26 -08:00
|
|
|
|
2010-09-02 19:20:12 -07: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 10:26:18 -08:00
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
2010-09-02 19:20:12 -07: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-08 21:24:46 -08:00
|
|
|
currentset = currentset.replace(/(^|,)reload-button($|,)/, "$1$2")
|
|
|
|
.replace(/(^|,)stop-button($|,)/, "$1$2")
|
|
|
|
.replace(/(^|,)urlbar-container($|,)/,
|
2010-09-02 19:20:12 -07:00
|
|
|
"$1urlbar-container,reload-button,stop-button$2");
|
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 21:24:46 -08: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 10:26:18 -08:00
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
2010-12-08 21:24:46 -08: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 10:26:18 -08: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 05:19:57 -08: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");
|
|
|
|
}
|
|
|
|
|
2013-01-15 07:47:58 -08:00
|
|
|
// Migration at version 7 only occurred for users who wanted to try the new
|
|
|
|
// Downloads Panel feature before its release. Since migration at version
|
|
|
|
// 9 adds the button by default, this step has been removed.
|
|
|
|
|
|
|
|
if (currentUIVersion < 8) {
|
|
|
|
// Reset homepage pref for users who have it set to google.com/firefox
|
|
|
|
let uri = Services.prefs.getComplexValue("browser.startup.homepage",
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
|
|
|
if (uri && /^https?:\/\/(www\.)?google(\.\w{2,3}){1,2}\/firefox\/?$/.test(uri)) {
|
|
|
|
Services.prefs.clearUserPref("browser.startup.homepage");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentUIVersion < 9) {
|
2012-08-25 02:37:55 -07:00
|
|
|
// This code adds the customizable downloads buttons.
|
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
|
|
|
let currentset = this._getPersist(toolbarResource, currentsetResource);
|
|
|
|
|
|
|
|
// Since the Downloads button is located in the navigation bar by default,
|
|
|
|
// migration needs to happen only if the toolbar was customized using a
|
|
|
|
// previous UI version, and the button was not already placed on the
|
|
|
|
// toolbar manually.
|
|
|
|
if (currentset &&
|
|
|
|
currentset.indexOf("downloads-button") == -1) {
|
|
|
|
// The element is added either after the search bar or before the home
|
|
|
|
// button. As a last resort, the element is added just before the
|
|
|
|
// non-customizable window controls.
|
|
|
|
if (currentset.indexOf("search-container") != -1) {
|
|
|
|
currentset = currentset.replace(/(^|,)search-container($|,)/,
|
|
|
|
"$1search-container,downloads-button$2")
|
|
|
|
} else if (currentset.indexOf("home-button") != -1) {
|
|
|
|
currentset = currentset.replace(/(^|,)home-button($|,)/,
|
|
|
|
"$1downloads-button,home-button$2")
|
|
|
|
} else {
|
|
|
|
currentset = currentset.replace(/(^|,)window-controls($|,)/,
|
|
|
|
"$1downloads-button,window-controls$2")
|
|
|
|
}
|
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
|
|
|
}
|
2012-09-27 05:57:39 -07:00
|
|
|
}
|
|
|
|
|
2013-04-09 14:07:02 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
if (currentUIVersion < 10) {
|
|
|
|
// For Windows systems with display set to > 96dpi (i.e. systemDefaultScale
|
|
|
|
// will return a value > 1.0), we want to discard any saved full-zoom settings,
|
|
|
|
// as we'll now be scaling the content according to the system resolution
|
|
|
|
// scale factor (Windows "logical DPI" setting)
|
|
|
|
let sm = Cc["@mozilla.org/gfx/screenmanager;1"].getService(Ci.nsIScreenManager);
|
|
|
|
if (sm.systemDefaultScale > 1.0) {
|
|
|
|
let cps2 = Cc["@mozilla.org/content-pref/service;1"].
|
|
|
|
getService(Ci.nsIContentPrefService2);
|
|
|
|
cps2.removeByName("browser.content.full-zoom", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-08 10:09:51 -07:00
|
|
|
if (currentUIVersion < 11) {
|
|
|
|
Services.prefs.clearUserPref("dom.disable_window_move_resize");
|
|
|
|
Services.prefs.clearUserPref("dom.disable_window_flip");
|
|
|
|
Services.prefs.clearUserPref("dom.event.contextmenu.enabled");
|
|
|
|
Services.prefs.clearUserPref("javascript.enabled");
|
|
|
|
Services.prefs.clearUserPref("permissions.default.image");
|
|
|
|
}
|
|
|
|
|
2013-04-23 07:06:17 -07:00
|
|
|
if (currentUIVersion < 12) {
|
|
|
|
// Remove bookmarks-menu-button-container, then place
|
|
|
|
// bookmarks-menu-button into its position.
|
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
|
|
|
let currentset = this._getPersist(toolbarResource, currentsetResource);
|
|
|
|
// Need to migrate only if toolbar is customized.
|
|
|
|
if (currentset) {
|
2013-05-10 08:19:48 -07:00
|
|
|
if (currentset.contains("bookmarks-menu-button-container")) {
|
|
|
|
currentset = currentset.replace(/(^|,)bookmarks-menu-button-container($|,)/,
|
|
|
|
"$1bookmarks-menu-button$2");
|
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
2013-04-23 07:06:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-08 17:20:20 -07:00
|
|
|
if (currentUIVersion < 13) {
|
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("plugins.hide_infobar_for_missing_plugin"))
|
|
|
|
Services.prefs.setBoolPref("plugins.notifyMissingFlash", false);
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
}
|
|
|
|
|
2013-07-03 14:41:25 -07:00
|
|
|
if (currentUIVersion < 14) {
|
|
|
|
// DOM Storage doesn't specially handle about: pages anymore.
|
|
|
|
let path = OS.Path.join(OS.Constants.Path.profileDir,
|
|
|
|
"chromeappsstore.sqlite");
|
|
|
|
OS.File.remove(path);
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:59:37 -08:00
|
|
|
// Version 15 was obsoleted in favour of 18.
|
2013-04-24 10:26:01 -07:00
|
|
|
|
2013-07-04 15:49:58 -07:00
|
|
|
if (currentUIVersion < 16) {
|
2013-05-14 09:15:36 -07:00
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
|
|
|
let collapsedResource = this._rdf.GetResource("collapsed");
|
|
|
|
let isCollapsed = this._getPersist(toolbarResource, collapsedResource);
|
|
|
|
if (isCollapsed == "true") {
|
|
|
|
this._setPersist(toolbarResource, collapsedResource, "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:46:53 -07:00
|
|
|
// Insert the bookmarks-menu-button into the nav-bar if it isn't already
|
|
|
|
// there.
|
2013-07-04 15:49:58 -07:00
|
|
|
if (currentUIVersion < 17) {
|
2013-06-07 11:46:53 -07:00
|
|
|
let currentsetResource = this._rdf.GetResource("currentset");
|
|
|
|
let toolbarResource = this._rdf.GetResource(BROWSER_DOCURL + "nav-bar");
|
|
|
|
let currentset = this._getPersist(toolbarResource, currentsetResource);
|
|
|
|
// Need to migrate only if toolbar is customized.
|
|
|
|
if (currentset) {
|
|
|
|
if (!currentset.contains("bookmarks-menu-button")) {
|
|
|
|
// The button isn't in the nav-bar, so let's look for an appropriate
|
|
|
|
// place to put it.
|
|
|
|
if (currentset.contains("downloads-button")) {
|
|
|
|
currentset = currentset.replace(/(^|,)downloads-button($|,)/,
|
|
|
|
"$1bookmarks-menu-button,downloads-button$2");
|
|
|
|
} else if (currentset.contains("home-button")) {
|
|
|
|
currentset = currentset.replace(/(^|,)home-button($|,)/,
|
|
|
|
"$1bookmarks-menu-button,home-button$2");
|
|
|
|
} else {
|
|
|
|
// Just append.
|
|
|
|
currentset = currentset.replace(/(^|,)window-controls($|,)/,
|
|
|
|
"$1bookmarks-menu-button,window-controls$2")
|
|
|
|
}
|
|
|
|
this._setPersist(toolbarResource, currentsetResource, currentset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:59:37 -08:00
|
|
|
if (currentUIVersion < 18) {
|
|
|
|
// Remove iconsize and mode from all the toolbars
|
|
|
|
let toolbars = ["navigator-toolbox", "nav-bar", "PersonalToolbar",
|
|
|
|
"addon-bar", "TabsToolbar", "toolbar-menubar"];
|
|
|
|
for (let resourceName of ["mode", "iconsize"]) {
|
|
|
|
let resource = this._rdf.GetResource(resourceName);
|
|
|
|
for (let toolbarId of toolbars) {
|
|
|
|
let toolbar = this._rdf.GetResource(BROWSER_DOCURL + toolbarId);
|
|
|
|
if (this._getPersist(toolbar, resource)) {
|
|
|
|
this._setPersist(toolbar, resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 08:01:50 -08:00
|
|
|
if (currentUIVersion < 19) {
|
|
|
|
let detector = null;
|
|
|
|
try {
|
|
|
|
detector = Services.prefs.getComplexValue("intl.charset.detector",
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
|
|
|
} catch (ex) {}
|
|
|
|
if (!(detector == "" ||
|
|
|
|
detector == "ja_parallel_state_machine" ||
|
|
|
|
detector == "ruprob" ||
|
|
|
|
detector == "ukprob")) {
|
|
|
|
// If the encoding detector pref value is not reachable from the UI,
|
|
|
|
// reset to default (varies by localization).
|
|
|
|
Services.prefs.clearUserPref("intl.charset.detector");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:51:55 -08:00
|
|
|
if (currentUIVersion < 20) {
|
|
|
|
// Remove persisted collapsed state from TabsToolbar.
|
|
|
|
let resource = this._rdf.GetResource("collapsed");
|
|
|
|
let toolbar = this._rdf.GetResource(BROWSER_DOCURL + "TabsToolbar");
|
|
|
|
if (this._getPersist(toolbar, resource)) {
|
|
|
|
this._setPersist(toolbar, resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 08:29:12 -08:00
|
|
|
if (currentUIVersion < 21) {
|
|
|
|
// Make sure the 'toolbarbutton-1' class will always be present from here
|
|
|
|
// on out.
|
|
|
|
let button = this._rdf.GetResource(BROWSER_DOCURL + "bookmarks-menu-button");
|
|
|
|
let classResource = this._rdf.GetResource("class");
|
|
|
|
if (this._getPersist(button, classResource)) {
|
|
|
|
this._setPersist(button, classResource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:44:01 -07:00
|
|
|
if (this._dirty)
|
|
|
|
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
|
2008-02-04 11:37:26 -08:00
|
|
|
|
2010-07-09 12:44:01 -07:00
|
|
|
delete this._rdf;
|
|
|
|
delete this._dataSource;
|
|
|
|
|
|
|
|
// Update the migration version.
|
|
|
|
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
|
2008-02-04 11:37:26 -08:00
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_getPersist: function BG__getPersist(aSource, aProperty) {
|
2008-02-20 01:56:52 -08:00
|
|
|
var target = this._dataSource.GetTarget(aSource, aProperty, true);
|
2008-02-04 11:37:26 -08:00
|
|
|
if (target instanceof Ci.nsIRDFLiteral)
|
|
|
|
return target.Value;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
_setPersist: function BG__setPersist(aSource, aProperty, aTarget) {
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dirty = true;
|
2008-02-04 11:37:26 -08:00
|
|
|
try {
|
2008-02-20 01:56:52 -08:00
|
|
|
var oldTarget = this._dataSource.GetTarget(aSource, aProperty, true);
|
2008-02-04 11:37:26 -08:00
|
|
|
if (oldTarget) {
|
|
|
|
if (aTarget)
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource.Change(aSource, aProperty, oldTarget, this._rdf.GetLiteral(aTarget));
|
2008-02-04 11:37:26 -08:00
|
|
|
else
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource.Unassert(aSource, aProperty, oldTarget);
|
2008-02-04 11:37:26 -08:00
|
|
|
}
|
|
|
|
else {
|
2008-02-20 01:56:52 -08:00
|
|
|
this._dataSource.Assert(aSource, aProperty, this._rdf.GetLiteral(aTarget), true);
|
2008-02-04 11:37:26 -08:00
|
|
|
}
|
2010-12-22 10:26:18 -08:00
|
|
|
|
|
|
|
// Add the entry to the persisted set for this document if it's not there.
|
2013-03-26 08:31:53 -07:00
|
|
|
// This code is mostly borrowed from XULDocument::Persist.
|
2010-12-22 10:26:18 -08:00
|
|
|
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 11:37:26 -08:00
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// ------------------------------
|
|
|
|
// public nsIBrowserGlue members
|
|
|
|
// ------------------------------
|
2010-09-02 19:20:12 -07:00
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
sanitize: function BG_sanitize(aParentWindow) {
|
2009-10-14 02:53:13 -07:00
|
|
|
this._sanitizer.sanitize(aParentWindow);
|
2007-09-05 20:02:22 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-17 13:28:08 -08:00
|
|
|
ensurePlacesDefaultQueriesInitialized:
|
|
|
|
function BG_ensurePlacesDefaultQueriesInitialized() {
|
2009-03-26 05:58:32 -07:00
|
|
|
// This is actual version of the smart bookmarks, must be increased every
|
|
|
|
// time smart bookmarks change.
|
|
|
|
// When adding a new smart bookmark below, its newInVersion property must
|
|
|
|
// be set to the version it has been added in, we will compare its value
|
|
|
|
// to users' smartBookmarksVersion and add new smart bookmarks without
|
|
|
|
// recreating old deleted ones.
|
2013-12-10 10:42:16 -08:00
|
|
|
const SMART_BOOKMARKS_VERSION = 6;
|
2008-04-08 11:42:53 -07:00
|
|
|
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
|
|
|
const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion";
|
|
|
|
|
2009-10-14 02:53:13 -07:00
|
|
|
// TODO bug 399268: should this be a pref?
|
2008-04-08 11:42:53 -07:00
|
|
|
const MAX_RESULTS = 10;
|
|
|
|
|
2010-11-23 05:04:07 -08:00
|
|
|
// Get current smart bookmarks version. If not set, create them.
|
|
|
|
let smartBookmarksCurrentVersion = 0;
|
2007-11-26 16:08:50 -08:00
|
|
|
try {
|
2010-04-12 07:33:10 -07:00
|
|
|
smartBookmarksCurrentVersion = Services.prefs.getIntPref(SMART_BOOKMARKS_PREF);
|
2010-11-23 05:04:07 -08:00
|
|
|
} catch(ex) {}
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2010-11-23 05:04:07 -08:00
|
|
|
// If version is current or smart bookmarks are disabled, just bail out.
|
2008-04-08 11:42:53 -07:00
|
|
|
if (smartBookmarksCurrentVersion == -1 ||
|
2010-11-23 05:04:07 -08:00
|
|
|
smartBookmarksCurrentVersion >= SMART_BOOKMARKS_VERSION) {
|
2007-11-26 16:08:50 -08:00
|
|
|
return;
|
2010-11-23 05:04:07 -08:00
|
|
|
}
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2010-11-23 05:04:07 -08:00
|
|
|
let batch = {
|
2009-12-17 13:28:08 -08:00
|
|
|
runBatched: function BG_EPDQI_runBatched() {
|
2010-11-23 05:04:07 -08: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-06 16:17:53 -07:00
|
|
|
uri: NetUtil.newURI("place:sort=" +
|
2010-11-23 05:04:07 -08: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 11:42:53 -07: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 05:04:07 -08: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
|
2013-11-23 12:03:34 -08:00
|
|
|
},
|
2013-12-10 10:42:16 -08:00
|
|
|
};
|
|
|
|
|
2014-02-28 05:37:31 -08:00
|
|
|
if (Services.metro && Services.metro.supported) {
|
2013-12-10 10:42:16 -08:00
|
|
|
smartBookmarks.Windows8Touch = {
|
2013-12-03 10:49:55 -08:00
|
|
|
title: bundle.GetStringFromName("windows8TouchTitle"),
|
2013-11-23 12:03:34 -08:00
|
|
|
uri: NetUtil.newURI("place:folder=" +
|
|
|
|
PlacesUtils.annotations.getItemsWithAnnotation('metro/bookmarksRoot', {})[0] +
|
|
|
|
"&queryType=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS +
|
|
|
|
"&excludeQueries=1"),
|
|
|
|
parent: PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
position: menuIndex++,
|
2013-12-10 10:42:16 -08:00
|
|
|
newInVersion: 6
|
|
|
|
};
|
|
|
|
}
|
2010-11-23 05:04:07 -08:00
|
|
|
|
2009-03-26 05:58:32 -07:00
|
|
|
// Set current itemId, parent and position if Smart Bookmark exists,
|
|
|
|
// we will use these informations to create the new version at the same
|
|
|
|
// position.
|
2010-11-23 05:04:07 -08: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 08:15:30 -07:00
|
|
|
smartBookmark.itemId = itemId;
|
|
|
|
smartBookmark.parent = PlacesUtils.bookmarks.getFolderIdForItem(itemId);
|
|
|
|
smartBookmark.position = PlacesUtils.bookmarks.getItemIndex(itemId);
|
2010-11-23 05:04:07 -08:00
|
|
|
}
|
|
|
|
else {
|
2008-04-08 11:42:53 -07: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 05:04:07 -08:00
|
|
|
PlacesUtils.annotations.removeItemAnnotation(itemId, SMART_BOOKMARKS_ANNO);
|
2008-04-08 11:42:53 -07:00
|
|
|
}
|
2010-11-23 05:04:07 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
for (let queryId in smartBookmarks) {
|
|
|
|
let smartBookmark = smartBookmarks[queryId];
|
2008-04-08 11:42:53 -07:00
|
|
|
|
2009-03-26 05:58:32 -07:00
|
|
|
// We update or create only changed or new smart bookmarks.
|
|
|
|
// Also we respect user choices, so we won't try to create a smart
|
|
|
|
// bookmark if it has been removed.
|
|
|
|
if (smartBookmarksCurrentVersion > 0 &&
|
|
|
|
smartBookmark.newInVersion <= smartBookmarksCurrentVersion &&
|
2010-11-23 05:04:07 -08:00
|
|
|
!smartBookmark.itemId)
|
2009-03-26 05:58:32 -07:00
|
|
|
continue;
|
|
|
|
|
2010-11-23 05:04:07 -08: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 11:42:53 -07:00
|
|
|
}
|
2010-09-02 19:20:12 -07:00
|
|
|
|
2008-04-08 11:42:53 -07:00
|
|
|
// If we are creating all Smart Bookmarks from ground up, add a
|
|
|
|
// separator below them in the bookmarks menu.
|
2009-03-26 05:58:32 -07:00
|
|
|
if (smartBookmarksCurrentVersion == 0 &&
|
2010-04-28 00:17:09 -07:00
|
|
|
smartBookmarkItemIds.length == 0) {
|
2010-11-23 05:04:07 -08:00
|
|
|
let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
menuIndex);
|
2010-04-28 00:17:09 -07:00
|
|
|
// Don't add a separator if the menu was empty or there is one already.
|
2010-11-23 05:04:07 -08:00
|
|
|
if (id != -1 &&
|
|
|
|
PlacesUtils.bookmarks.getItemType(id) != PlacesUtils.bookmarks.TYPE_SEPARATOR) {
|
|
|
|
PlacesUtils.bookmarks.insertSeparator(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
menuIndex);
|
|
|
|
}
|
2010-04-28 00:17:09 -07:00
|
|
|
}
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2010-11-23 05:04:07 -08:00
|
|
|
PlacesUtils.bookmarks.runInBatchMode(batch, null);
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
|
|
|
finally {
|
2010-04-12 07:33:10 -07:00
|
|
|
Services.prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
|
|
|
|
Services.prefs.savePrefFile(null);
|
2007-11-26 16:08:50 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-10-30 23:42:02 -07:00
|
|
|
// this returns the most recent non-popup browser window
|
2009-12-17 13:28:08 -08:00
|
|
|
getMostRecentBrowserWindow: function BG_getMostRecentBrowserWindow() {
|
2012-12-05 17:59:26 -08:00
|
|
|
return RecentWindow.getMostRecentBrowserWindow();
|
2008-10-30 23:42:02 -07:00
|
|
|
},
|
|
|
|
|
2012-06-29 15:30:45 -07:00
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
/**
|
|
|
|
* Called as an observer when Sync's "display URI" notification is fired.
|
|
|
|
*
|
|
|
|
* We open the received URI in a background tab.
|
|
|
|
*
|
|
|
|
* Eventually, this will likely be replaced by a more robust tab syncing
|
|
|
|
* feature. This functionality is considered somewhat evil by UX because it
|
|
|
|
* opens a new tab automatically without any prompting. However, it is a
|
|
|
|
* lesser evil than sending a tab to a specific device (from e.g. Fennec)
|
|
|
|
* and having nothing happen on the receiving end.
|
|
|
|
*/
|
|
|
|
_onDisplaySyncURI: function _onDisplaySyncURI(data) {
|
|
|
|
try {
|
2013-03-01 06:14:49 -08:00
|
|
|
let tabbrowser = RecentWindow.getMostRecentBrowserWindow({private: false}).gBrowser;
|
2012-06-29 15:30:45 -07:00
|
|
|
|
|
|
|
// The payload is wrapped weirdly because of how Sync does notifications.
|
|
|
|
tabbrowser.addTab(data.wrappedJSObject.object.uri);
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("Error displaying tab received by Sync: " + ex);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
#endif
|
2008-10-30 23:42:02 -07:00
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
// for XPCOM
|
|
|
|
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-27 12:37:47 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIBrowserGlue]),
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-05 20:02:22 -07:00
|
|
|
// redefine the default factory for XPCOMUtils
|
|
|
|
_xpcom_factory: BrowserGlueServiceFactory,
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 21:59:51 -07:00
|
|
|
function ContentPermissionPrompt() {}
|
2008-10-23 11:01:32 -07:00
|
|
|
|
2010-09-09 21:59:51 -07:00
|
|
|
ContentPermissionPrompt.prototype = {
|
|
|
|
classID: Components.ID("{d8903bf6-68d5-4e97-bcd1-e4d3012f721a}"),
|
2008-10-23 11:01:32 -07:00
|
|
|
|
2010-09-09 21:59:51 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
|
2010-04-09 10:45:25 -07:00
|
|
|
|
2013-08-23 16:04:19 -07:00
|
|
|
_getBrowserForRequest: function (aRequest) {
|
2013-09-04 08:40:16 -07:00
|
|
|
// "element" is only defined in e10s mode.
|
|
|
|
let browser = aRequest.element;
|
2013-08-23 16:04:19 -07:00
|
|
|
if (!browser) {
|
2013-09-04 08:40:16 -07:00
|
|
|
// Find the requesting browser.
|
|
|
|
browser = aRequest.window.QueryInterface(Ci.nsIInterfaceRequestor)
|
2013-08-23 16:04:19 -07:00
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.chromeEventHandler;
|
|
|
|
}
|
|
|
|
return browser;
|
2012-07-12 08:45:38 -07:00
|
|
|
},
|
2010-09-09 21:59:51 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
/**
|
|
|
|
* Show a permission prompt.
|
|
|
|
*
|
|
|
|
* @param aRequest The permission request.
|
|
|
|
* @param aMessage The message to display on the prompt.
|
|
|
|
* @param aPermission The type of permission to prompt.
|
|
|
|
* @param aActions An array of actions of the form:
|
|
|
|
* [main action, secondary actions, ...]
|
|
|
|
* Actions are of the form { stringId, action, expireType, callback }
|
|
|
|
* Permission is granted if action is null or ALLOW_ACTION.
|
|
|
|
* @param aNotificationId The id of the PopupNotification.
|
|
|
|
* @param aAnchorId The id for the PopupNotification anchor.
|
2013-04-01 10:38:36 -07:00
|
|
|
* @param aOptions Options for the PopupNotification
|
2012-07-12 08:45:38 -07:00
|
|
|
*/
|
|
|
|
_showPrompt: function CPP_showPrompt(aRequest, aMessage, aPermission, aActions,
|
2013-04-01 10:38:36 -07:00
|
|
|
aNotificationId, aAnchorId, aOptions) {
|
2013-03-24 03:32:44 -07:00
|
|
|
function onFullScreen() {
|
|
|
|
popup.remove();
|
|
|
|
}
|
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
2010-09-09 21:59:51 -07:00
|
|
|
|
2013-08-23 16:04:19 -07:00
|
|
|
var browser = this._getBrowserForRequest(aRequest);
|
2013-07-22 17:24:11 -07:00
|
|
|
var chromeWin = browser.ownerDocument.defaultView;
|
2012-07-12 08:45:38 -07:00
|
|
|
var requestPrincipal = aRequest.principal;
|
|
|
|
|
|
|
|
// Transform the prompt actions into PopupNotification actions.
|
|
|
|
var popupNotificationActions = [];
|
|
|
|
for (var i = 0; i < aActions.length; i++) {
|
|
|
|
let promptAction = aActions[i];
|
|
|
|
|
|
|
|
// Don't offer action in PB mode if the action remembers permission for more than a session.
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(chromeWin) &&
|
|
|
|
promptAction.expireType != Ci.nsIPermissionManager.EXPIRE_SESSION &&
|
|
|
|
promptAction.action) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-09 10:45:25 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
var action = {
|
|
|
|
label: browserBundle.GetStringFromName(promptAction.stringId),
|
|
|
|
accessKey: browserBundle.GetStringFromName(promptAction.stringId + ".accesskey"),
|
|
|
|
callback: function() {
|
|
|
|
if (promptAction.callback) {
|
|
|
|
promptAction.callback();
|
|
|
|
}
|
2010-04-09 10:45:25 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
// Remember permissions.
|
|
|
|
if (promptAction.action) {
|
|
|
|
Services.perms.addFromPrincipal(requestPrincipal, aPermission,
|
|
|
|
promptAction.action, promptAction.expireType);
|
|
|
|
}
|
2009-04-15 14:49:11 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
// Grant permission if action is null or ALLOW_ACTION.
|
|
|
|
if (!promptAction.action || promptAction.action == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
|
|
aRequest.allow();
|
|
|
|
} else {
|
|
|
|
aRequest.cancel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2010-09-02 19:20:12 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
popupNotificationActions.push(action);
|
2009-04-15 14:49:11 -07:00
|
|
|
}
|
|
|
|
|
2013-03-24 03:32:44 -07:00
|
|
|
var mainAction = popupNotificationActions.length ?
|
|
|
|
popupNotificationActions[0] : null;
|
2012-07-12 08:45:38 -07:00
|
|
|
var secondaryActions = popupNotificationActions.splice(1);
|
2013-03-24 03:32:44 -07:00
|
|
|
|
2014-02-09 12:34:40 -08:00
|
|
|
// Only allow exactly one permission rquest here.
|
|
|
|
let types = aRequest.types.QueryInterface(Ci.nsIArray);
|
|
|
|
if (types.length != 1) {
|
|
|
|
aRequest.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let perm = types.queryElementAt(0, Ci.nsIContentPermissionType);
|
|
|
|
|
|
|
|
if (perm.type == "pointerLock") {
|
2013-03-24 03:32:44 -07:00
|
|
|
// If there's no mainAction, this is the autoAllow warning prompt.
|
|
|
|
let autoAllow = !mainAction;
|
2014-02-18 19:05:34 -08:00
|
|
|
|
|
|
|
if (!aOptions)
|
|
|
|
aOptions = {};
|
|
|
|
|
|
|
|
aOptions.removeOnDismissal = autoAllow;
|
|
|
|
aOptions.eventCallback = type => {
|
|
|
|
if (type == "removed") {
|
|
|
|
browser.removeEventListener("mozfullscreenchange", onFullScreen, true);
|
|
|
|
if (autoAllow) {
|
|
|
|
aRequest.allow();
|
2013-04-01 10:38:36 -07:00
|
|
|
}
|
2014-02-18 19:05:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-24 03:32:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var popup = chromeWin.PopupNotifications.show(browser, aNotificationId, aMessage, aAnchorId,
|
2013-04-01 10:38:36 -07:00
|
|
|
mainAction, secondaryActions, aOptions);
|
2014-02-09 12:34:40 -08:00
|
|
|
if (perm.type == "pointerLock") {
|
2013-03-24 03:32:44 -07:00
|
|
|
// pointerLock is automatically allowed in fullscreen mode (and revoked
|
|
|
|
// upon exit), so if the page enters fullscreen mode after requesting
|
|
|
|
// pointerLock (but before the user has granted permission), we should
|
|
|
|
// remove the now-impotent notification.
|
2013-03-24 05:45:38 -07:00
|
|
|
browser.addEventListener("mozfullscreenchange", onFullScreen, true);
|
2013-03-24 03:32:44 -07:00
|
|
|
}
|
2012-07-12 08:45:38 -07:00
|
|
|
},
|
2008-10-23 11:01:32 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
_promptGeo : function(aRequest) {
|
|
|
|
var secHistogram = Services.telemetry.getHistogramById("SECURITY_UI");
|
2010-04-09 10:45:25 -07:00
|
|
|
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
2012-07-12 08:45:38 -07:00
|
|
|
var requestingURI = aRequest.principal.URI;
|
2009-04-15 14:49:11 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
var message;
|
|
|
|
|
|
|
|
// Share location action.
|
|
|
|
var actions = [{
|
|
|
|
stringId: "geolocation.shareLocation",
|
|
|
|
action: null,
|
|
|
|
expireType: null,
|
2012-06-03 22:25:55 -07:00
|
|
|
callback: function() {
|
2012-09-08 09:20:51 -07:00
|
|
|
secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST_SHARE_LOCATION);
|
2010-04-09 10:45:25 -07:00
|
|
|
},
|
2012-07-12 08:45:38 -07:00
|
|
|
}];
|
2010-04-09 10:45:25 -07:00
|
|
|
|
|
|
|
if (requestingURI.schemeIs("file")) {
|
2011-11-28 13:02:45 -08:00
|
|
|
message = browserBundle.formatStringFromName("geolocation.shareWithFile",
|
2010-09-09 21:59:51 -07:00
|
|
|
[requestingURI.path], 1);
|
2010-04-09 10:45:25 -07:00
|
|
|
} else {
|
2011-11-28 13:02:45 -08:00
|
|
|
message = browserBundle.formatStringFromName("geolocation.shareWithSite",
|
2010-04-09 10:45:25 -07:00
|
|
|
[requestingURI.host], 1);
|
2012-07-12 08:45:38 -07:00
|
|
|
// Always share location action.
|
|
|
|
actions.push({
|
|
|
|
stringId: "geolocation.alwaysShareLocation",
|
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
expireType: null,
|
|
|
|
callback: function() {
|
|
|
|
secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST_ALWAYS_SHARE);
|
|
|
|
},
|
|
|
|
});
|
2010-04-09 10:45:25 -07:00
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
// Never share location action.
|
|
|
|
actions.push({
|
|
|
|
stringId: "geolocation.neverShareLocation",
|
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
expireType: null,
|
|
|
|
callback: function() {
|
|
|
|
secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST_NEVER_SHARE);
|
|
|
|
},
|
|
|
|
});
|
2010-04-09 10:45:25 -07:00
|
|
|
}
|
2009-04-15 14:49:11 -07:00
|
|
|
|
2014-02-18 19:05:34 -08:00
|
|
|
var options = {
|
|
|
|
learnMoreURL: Services.urlFormatter.formatURLPref("browser.geolocation.warning.infoURL"),
|
|
|
|
};
|
2012-12-24 16:08:13 -08:00
|
|
|
|
2012-09-08 09:20:51 -07:00
|
|
|
secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST);
|
2012-07-12 08:45:38 -07:00
|
|
|
|
2013-04-01 10:38:36 -07:00
|
|
|
this._showPrompt(aRequest, message, "geo", actions, "geolocation",
|
2014-02-18 19:05:34 -08:00
|
|
|
"geo-notification-icon", options);
|
2012-07-12 08:45:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_promptWebNotifications : function(aRequest) {
|
|
|
|
var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
var requestingURI = aRequest.principal.URI;
|
|
|
|
|
|
|
|
var message = browserBundle.formatStringFromName("webNotifications.showFromSite",
|
|
|
|
[requestingURI.host], 1);
|
|
|
|
|
|
|
|
var actions = [
|
|
|
|
{
|
|
|
|
stringId: "webNotifications.showForSession",
|
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
expireType: Ci.nsIPermissionManager.EXPIRE_SESSION,
|
|
|
|
callback: function() {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stringId: "webNotifications.alwaysShow",
|
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
expireType: null,
|
|
|
|
callback: function() {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stringId: "webNotifications.neverShow",
|
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
expireType: null,
|
|
|
|
callback: function() {},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
this._showPrompt(aRequest, message, "desktop-notification", actions,
|
|
|
|
"web-notifications",
|
2013-04-01 10:38:36 -07:00
|
|
|
"web-notifications-notification-icon", null);
|
2012-07-12 08:45:38 -07:00
|
|
|
},
|
|
|
|
|
2013-03-24 03:32:44 -07:00
|
|
|
_promptPointerLock: function CPP_promtPointerLock(aRequest, autoAllow) {
|
|
|
|
|
|
|
|
let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
let requestingURI = aRequest.principal.URI;
|
|
|
|
|
|
|
|
let originString = requestingURI.schemeIs("file") ? requestingURI.path : requestingURI.host;
|
|
|
|
let message = browserBundle.formatStringFromName(autoAllow ?
|
2013-04-03 01:22:05 -07:00
|
|
|
"pointerLock.autoLock.title2" : "pointerLock.title2",
|
2013-03-24 03:32:44 -07:00
|
|
|
[originString], 1);
|
|
|
|
// If this is an autoAllow info prompt, offer no actions.
|
|
|
|
// _showPrompt() will allow the request when it's dismissed.
|
|
|
|
let actions = [];
|
|
|
|
if (!autoAllow) {
|
|
|
|
actions = [
|
|
|
|
{
|
2013-04-03 01:22:05 -07:00
|
|
|
stringId: "pointerLock.allow2",
|
2013-03-24 03:32:44 -07:00
|
|
|
action: null,
|
|
|
|
expireType: null,
|
|
|
|
callback: function() {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stringId: "pointerLock.alwaysAllow",
|
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
expireType: null,
|
|
|
|
callback: function() {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stringId: "pointerLock.neverAllow",
|
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
expireType: null,
|
|
|
|
callback: function() {},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2013-04-01 10:38:36 -07:00
|
|
|
this._showPrompt(aRequest, message, "pointerLock", actions, "pointerLock",
|
|
|
|
"pointerLock-notification-icon", null);
|
2013-03-24 03:32:44 -07:00
|
|
|
},
|
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
prompt: function CPP_prompt(request) {
|
2013-03-24 03:32:44 -07:00
|
|
|
|
2014-02-09 12:34:40 -08:00
|
|
|
// Only allow exactly one permission rquest here.
|
|
|
|
let types = request.types.QueryInterface(Ci.nsIArray);
|
|
|
|
if (types.length != 1) {
|
|
|
|
request.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let perm = types.queryElementAt(0, Ci.nsIContentPermissionType);
|
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
const kFeatureKeys = { "geolocation" : "geo",
|
2013-03-24 03:32:44 -07:00
|
|
|
"desktop-notification" : "desktop-notification",
|
|
|
|
"pointerLock" : "pointerLock",
|
|
|
|
};
|
2012-07-12 08:45:38 -07:00
|
|
|
|
|
|
|
// Make sure that we support the request.
|
2014-02-09 12:34:40 -08:00
|
|
|
if (!(perm.type in kFeatureKeys)) {
|
2012-07-12 08:45:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var requestingPrincipal = request.principal;
|
|
|
|
var requestingURI = requestingPrincipal.URI;
|
|
|
|
|
|
|
|
// Ignore requests from non-nsIStandardURLs
|
|
|
|
if (!(requestingURI instanceof Ci.nsIStandardURL))
|
|
|
|
return;
|
|
|
|
|
2013-03-24 03:32:44 -07:00
|
|
|
var autoAllow = false;
|
2014-02-09 12:34:40 -08:00
|
|
|
var permissionKey = kFeatureKeys[perm.type];
|
2012-07-12 08:45:38 -07:00
|
|
|
var result = Services.perms.testExactPermissionFromPrincipal(requestingPrincipal, permissionKey);
|
|
|
|
|
|
|
|
if (result == Ci.nsIPermissionManager.DENY_ACTION) {
|
|
|
|
request.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-24 03:32:44 -07:00
|
|
|
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
|
|
autoAllow = true;
|
|
|
|
// For pointerLock, we still want to show a warning prompt.
|
2014-02-09 12:34:40 -08:00
|
|
|
if (perm.type != "pointerLock") {
|
2013-03-24 03:32:44 -07:00
|
|
|
request.allow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 15:36:54 -08:00
|
|
|
var browser = this._getBrowserForRequest(request);
|
|
|
|
var chromeWin = browser.ownerDocument.defaultView;
|
|
|
|
if (!chromeWin.PopupNotifications)
|
|
|
|
// Ignore requests from browsers hosted in windows that don't support
|
|
|
|
// PopupNotifications.
|
|
|
|
return;
|
|
|
|
|
2012-07-12 08:45:38 -07:00
|
|
|
// Show the prompt.
|
2014-02-09 12:34:40 -08:00
|
|
|
switch (perm.type) {
|
2012-07-12 08:45:38 -07:00
|
|
|
case "geolocation":
|
|
|
|
this._promptGeo(request);
|
|
|
|
break;
|
|
|
|
case "desktop-notification":
|
|
|
|
this._promptWebNotifications(request);
|
|
|
|
break;
|
2013-03-24 03:32:44 -07:00
|
|
|
case "pointerLock":
|
|
|
|
this._promptPointerLock(request, autoAllow);
|
|
|
|
break;
|
2012-07-12 08:45:38 -07:00
|
|
|
}
|
2013-03-24 03:32:44 -07:00
|
|
|
},
|
|
|
|
|
2008-10-23 11:01:32 -07:00
|
|
|
};
|
|
|
|
|
2010-09-09 21:59:51 -07:00
|
|
|
var components = [BrowserGlue, ContentPermissionPrompt];
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|