2016-01-22 23:48:20 +03: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/. */
|
2005-08-23 20:38:28 +04:00
|
|
|
|
2007-06-17 01:23:17 +04:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Cr = Components.results;
|
2007-09-11 19:52:04 +04:00
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2009-04-16 01:49:11 +04:00
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-04-12 18:33:10 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2016-01-22 23:48:20 +03:00
|
|
|
Cu.import("resource://gre/modules/AppConstants.jsm");
|
2016-03-13 16:10:16 +03:00
|
|
|
Cu.import("resource://gre/modules/AsyncPrefs.jsm");
|
2007-09-06 07:02:22 +04:00
|
|
|
|
2016-08-09 22:18:13 +03:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils", "@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "AlertsService", "@mozilla.org/alerts-service;1", "nsIAlertsService");
|
|
|
|
|
|
|
|
// lazy module getters
|
2016-12-22 15:14:05 +03:00
|
|
|
|
|
|
|
/* global AboutHome:false, AboutNewTab:false, AddonManager:false, AddonWatcher:false,
|
|
|
|
AsyncShutdown:false, AutoCompletePopup:false, BookmarkHTMLUtils:false,
|
|
|
|
BookmarkJSONUtils:false, BrowserUITelemetry:false, BrowserUsageTelemetry:false,
|
2017-01-14 01:58:50 +03:00
|
|
|
ContentClick:false, ContentPrefServiceParent:false, ContentSearch:false,
|
|
|
|
DateTimePickerHelper:false, DirectoryLinksProvider:false, Feeds:false,
|
|
|
|
FileUtils:false, FormValidationHandler:false, Integration:false,
|
2016-12-22 15:14:05 +03:00
|
|
|
LightweightThemeManager:false, LoginHelper:false, LoginManagerParent:false,
|
|
|
|
NetUtil:false, NewTabMessages:false, NewTabUtils:false, OS:false,
|
|
|
|
PageThumbs:false, PdfJs:false, PermissionUI:false, PlacesBackups:false,
|
|
|
|
PlacesUtils:false, PluralForm:false, PrivateBrowsingUtils:false,
|
|
|
|
ProcessHangMonitor:false, ReaderParent:false, RecentWindow:false,
|
|
|
|
RemotePrompt:false, SelfSupportBackend:false, SessionStore:false,
|
|
|
|
ShellService:false, SimpleServiceDiscovery:false, TabCrashHandler:false,
|
|
|
|
Task:false, UITour:false, URLBarZoom:false, WebChannel:false,
|
|
|
|
WindowsRegistry:false, webrtcUI:false */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IF YOU ADD OR REMOVE FROM THIS LIST, PLEASE UPDATE THE LIST ABOVE AS WELL.
|
|
|
|
* XXX Bug 1325373 is for making eslint detect these automatically.
|
|
|
|
*/
|
|
|
|
|
2016-08-09 22:18:13 +03:00
|
|
|
[
|
|
|
|
["AboutHome", "resource:///modules/AboutHome.jsm"],
|
|
|
|
["AboutNewTab", "resource:///modules/AboutNewTab.jsm"],
|
|
|
|
["AddonManager", "resource://gre/modules/AddonManager.jsm"],
|
|
|
|
["AddonWatcher", "resource://gre/modules/AddonWatcher.jsm"],
|
|
|
|
["AsyncShutdown", "resource://gre/modules/AsyncShutdown.jsm"],
|
2016-08-18 17:50:58 +03:00
|
|
|
["AutoCompletePopup", "resource://gre/modules/AutoCompletePopup.jsm"],
|
2016-08-09 22:18:13 +03:00
|
|
|
["BookmarkHTMLUtils", "resource://gre/modules/BookmarkHTMLUtils.jsm"],
|
|
|
|
["BookmarkJSONUtils", "resource://gre/modules/BookmarkJSONUtils.jsm"],
|
|
|
|
["BrowserUITelemetry", "resource:///modules/BrowserUITelemetry.jsm"],
|
|
|
|
["BrowserUsageTelemetry", "resource:///modules/BrowserUsageTelemetry.jsm"],
|
|
|
|
["ContentClick", "resource:///modules/ContentClick.jsm"],
|
|
|
|
["ContentPrefServiceParent", "resource://gre/modules/ContentPrefServiceParent.jsm"],
|
|
|
|
["ContentSearch", "resource:///modules/ContentSearch.jsm"],
|
2016-10-06 07:17:00 +03:00
|
|
|
["DateTimePickerHelper", "resource://gre/modules/DateTimePickerHelper.jsm"],
|
2016-08-09 22:18:13 +03:00
|
|
|
["DirectoryLinksProvider", "resource:///modules/DirectoryLinksProvider.jsm"],
|
2017-01-03 21:55:25 +03:00
|
|
|
["ExtensionsUI", "resource:///modules/ExtensionsUI.jsm"],
|
2016-08-09 22:18:13 +03:00
|
|
|
["Feeds", "resource:///modules/Feeds.jsm"],
|
|
|
|
["FileUtils", "resource://gre/modules/FileUtils.jsm"],
|
|
|
|
["FormValidationHandler", "resource:///modules/FormValidationHandler.jsm"],
|
2016-08-28 06:11:07 +03:00
|
|
|
["Integration", "resource://gre/modules/Integration.jsm"],
|
2016-08-09 22:18:13 +03:00
|
|
|
["LightweightThemeManager", "resource://gre/modules/LightweightThemeManager.jsm"],
|
|
|
|
["LoginHelper", "resource://gre/modules/LoginHelper.jsm"],
|
|
|
|
["LoginManagerParent", "resource://gre/modules/LoginManagerParent.jsm"],
|
|
|
|
["NetUtil", "resource://gre/modules/NetUtil.jsm"],
|
|
|
|
["NewTabMessages", "resource:///modules/NewTabMessages.jsm"],
|
|
|
|
["NewTabUtils", "resource://gre/modules/NewTabUtils.jsm"],
|
|
|
|
["OS", "resource://gre/modules/osfile.jsm"],
|
|
|
|
["PageThumbs", "resource://gre/modules/PageThumbs.jsm"],
|
|
|
|
["PdfJs", "resource://pdf.js/PdfJs.jsm"],
|
2016-08-28 06:11:07 +03:00
|
|
|
["PermissionUI", "resource:///modules/PermissionUI.jsm"],
|
2016-08-09 22:18:13 +03:00
|
|
|
["PlacesBackups", "resource://gre/modules/PlacesBackups.jsm"],
|
|
|
|
["PlacesUtils", "resource://gre/modules/PlacesUtils.jsm"],
|
|
|
|
["PluralForm", "resource://gre/modules/PluralForm.jsm"],
|
|
|
|
["PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"],
|
|
|
|
["ProcessHangMonitor", "resource:///modules/ProcessHangMonitor.jsm"],
|
|
|
|
["ReaderParent", "resource:///modules/ReaderParent.jsm"],
|
|
|
|
["RecentWindow", "resource:///modules/RecentWindow.jsm"],
|
|
|
|
["RemotePrompt", "resource:///modules/RemotePrompt.jsm"],
|
|
|
|
["SelfSupportBackend", "resource:///modules/SelfSupportBackend.jsm"],
|
|
|
|
["SessionStore", "resource:///modules/sessionstore/SessionStore.jsm"],
|
|
|
|
["ShellService", "resource:///modules/ShellService.jsm"],
|
|
|
|
["SimpleServiceDiscovery", "resource://gre/modules/SimpleServiceDiscovery.jsm"],
|
|
|
|
["TabCrashHandler", "resource:///modules/ContentCrashHandlers.jsm"],
|
|
|
|
["Task", "resource://gre/modules/Task.jsm"],
|
|
|
|
["UITour", "resource:///modules/UITour.jsm"],
|
2016-08-12 20:48:59 +03:00
|
|
|
["URLBarZoom", "resource:///modules/URLBarZoom.jsm"],
|
2016-08-09 22:18:13 +03:00
|
|
|
["WebChannel", "resource://gre/modules/WebChannel.jsm"],
|
|
|
|
["WindowsRegistry", "resource://gre/modules/WindowsRegistry.jsm"],
|
|
|
|
["webrtcUI", "resource:///modules/webrtcUI.jsm"],
|
|
|
|
].forEach(([name, resource]) => XPCOMUtils.defineLazyModuleGetter(this, name, resource));
|
2013-07-06 00:55:00 +04:00
|
|
|
|
2016-01-22 23:48:20 +03:00
|
|
|
if (AppConstants.MOZ_CRASHREPORTER) {
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PluginCrashReporter",
|
|
|
|
"resource:///modules/ContentCrashHandlers.jsm");
|
2016-09-02 20:16:28 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UnsubmittedCrashHandler",
|
|
|
|
"resource:///modules/ContentCrashHandlers.jsm");
|
2016-05-11 09:50:55 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit",
|
|
|
|
"resource://gre/modules/CrashSubmit.jsm");
|
2016-01-22 23:48:20 +03:00
|
|
|
}
|
2015-03-28 06:34:15 +03:00
|
|
|
|
2015-04-01 02:00:45 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function() {
|
2017-01-17 18:48:17 +03:00
|
|
|
return Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
2015-04-01 02:00:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
|
2017-01-17 18:48:17 +03:00
|
|
|
return Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
2015-04-01 02:00:45 +03:00
|
|
|
});
|
|
|
|
|
2014-02-04 17:43:20 +04:00
|
|
|
// Seconds of idle before trying to create a bookmarks backup.
|
2014-05-28 09:10:00 +04:00
|
|
|
const BOOKMARKS_BACKUP_IDLE_TIME_SEC = 8 * 60;
|
2014-02-04 17:43:20 +04:00
|
|
|
// 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.
|
2014-05-28 09:10:00 +04:00
|
|
|
const BOOKMARKS_BACKUP_MAX_INTERVAL_DAYS = 3;
|
2008-03-13 22:25:49 +03:00
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// Factory object
|
|
|
|
const BrowserGlueServiceFactory = {
|
|
|
|
_instance: null,
|
2009-12-18 00:28:08 +03:00
|
|
|
createInstance: function BGSF_createInstance(outer, iid) {
|
2007-09-06 07:02:22 +04:00
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return this._instance == null ?
|
|
|
|
this._instance = new BrowserGlue() : this._instance;
|
|
|
|
}
|
|
|
|
};
|
2005-12-05 00:02:38 +03:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// Constructor
|
|
|
|
|
|
|
|
function BrowserGlue() {
|
2009-09-29 14:44:18 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_idleService",
|
|
|
|
"@mozilla.org/widget/idleservice;1",
|
|
|
|
"nsIIdleService");
|
|
|
|
|
2009-10-05 14:13:04 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_distributionCustomizer", function() {
|
2010-01-22 02:49:11 +03:00
|
|
|
Cu.import("resource:///modules/distribution.js");
|
2009-10-05 14:13:04 +04:00
|
|
|
return new DistributionCustomizer();
|
|
|
|
});
|
|
|
|
|
2009-10-14 13:53:13 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "_sanitizer",
|
|
|
|
function() {
|
|
|
|
let sanitizerScope = {};
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", sanitizerScope);
|
2009-10-14 13:53:13 +04:00
|
|
|
return sanitizerScope.Sanitizer;
|
|
|
|
});
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2016-01-22 23:48:20 +03:00
|
|
|
/*
|
|
|
|
* OS X has the concept of zero-window sessions and therefore ignores the
|
|
|
|
* browser-lastwindow-close-* topics.
|
|
|
|
*/
|
|
|
|
const OBSERVE_LASTWINDOW_CLOSE_TOPICS = AppConstants.platform != "macosx";
|
2009-07-31 08:57:57 +04:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
BrowserGlue.prototype = {
|
2007-06-15 22:01:25 +04:00
|
|
|
_saveSession: false,
|
2009-09-29 14:44:18 +04:00
|
|
|
_isPlacesInitObserver: false,
|
|
|
|
_isPlacesLockedObserver: false,
|
2010-04-22 16:53:54 +04:00
|
|
|
_isPlacesShutdownObserver: false,
|
2009-09-29 14:44:18 +04:00
|
|
|
_isPlacesDatabaseLocked: false,
|
2012-05-28 13:43:59 +04:00
|
|
|
_migrationImportsDefaultBookmarks: false,
|
2007-06-15 22:01:25 +04:00
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_setPrefToSaveSession: function BG__setPrefToSaveSession(aForce) {
|
2009-10-14 13:53:13 +04:00
|
|
|
if (!this._saveSession && !aForce)
|
|
|
|
return;
|
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
|
2009-06-12 00:17:33 +04:00
|
|
|
|
|
|
|
// This method can be called via [NSApplication terminate:] on Mac, which
|
|
|
|
// ends up causing prefs not to be flushed to disk, so we need to do that
|
|
|
|
// explicitly here. See bug 497652.
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.savePrefFile(null);
|
2008-02-07 12:28:43 +03:00
|
|
|
},
|
|
|
|
|
2010-08-12 05:28:27 +04:00
|
|
|
_setSyncAutoconnectDelay: function BG__setSyncAutoconnectDelay() {
|
|
|
|
// Assume that a non-zero value for services.sync.autoconnectDelay should override
|
|
|
|
if (Services.prefs.prefHasUserValue("services.sync.autoconnectDelay")) {
|
|
|
|
let prefDelay = Services.prefs.getIntPref("services.sync.autoconnectDelay");
|
|
|
|
|
|
|
|
if (prefDelay > 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delays are in seconds
|
|
|
|
const MAX_DELAY = 300;
|
|
|
|
let delay = 3;
|
2011-01-23 04:46:22 +03:00
|
|
|
let browserEnum = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (browserEnum.hasMoreElements()) {
|
|
|
|
delay += browserEnum.getNext().gBrowser.tabs.length;
|
2010-08-12 05:28:27 +04:00
|
|
|
}
|
|
|
|
delay = delay <= MAX_DELAY ? delay : MAX_DELAY;
|
|
|
|
|
2011-07-21 23:20:55 +04:00
|
|
|
Cu.import("resource://services-sync/main.js");
|
2012-08-30 01:43:41 +04:00
|
|
|
Weave.Service.scheduler.delayedAutoConnect(delay);
|
2010-08-12 05:28:27 +04:00
|
|
|
},
|
|
|
|
|
2014-11-12 16:16:00 +03:00
|
|
|
// nsIObserver implementation
|
2009-12-18 00:28:08 +03:00
|
|
|
observe: function BG_observe(subject, topic, data) {
|
2010-02-06 13:40:06 +03:00
|
|
|
switch (topic) {
|
2015-09-25 23:18:29 +03:00
|
|
|
case "notifications-open-settings":
|
|
|
|
this._openPreferences("content");
|
|
|
|
break;
|
2007-09-11 19:52:04 +04:00
|
|
|
case "prefservice:after-app-defaults":
|
|
|
|
this._onAppDefaults();
|
|
|
|
break;
|
2005-10-07 19:15:21 +04:00
|
|
|
case "final-ui-startup":
|
2013-05-13 20:25:39 +04:00
|
|
|
this._finalUIStartup();
|
2005-08-23 20:38:28 +04:00
|
|
|
break;
|
2010-10-02 19:53:37 +04:00
|
|
|
case "browser-delayed-startup-finished":
|
2013-07-27 09:40:07 +04:00
|
|
|
this._onFirstWindowLoaded(subject);
|
2010-10-02 19:53:37 +04:00
|
|
|
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
|
|
|
|
break;
|
2008-03-08 03:16:38 +03:00
|
|
|
case "sessionstore-windows-restored":
|
2012-01-19 03:25:05 +04:00
|
|
|
this._onWindowsRestored();
|
2008-03-08 03:16:38 +03:00
|
|
|
break;
|
2006-07-19 16:49:33 +04:00
|
|
|
case "browser:purge-session-history":
|
|
|
|
// reset the console service's error buffer
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.console.logStringMessage(null); // clear the console (in case it's open)
|
|
|
|
Services.console.reset();
|
2006-07-19 16:49:33 +04:00
|
|
|
break;
|
2015-02-20 03:53:00 +03:00
|
|
|
case "restart-in-safe-mode":
|
|
|
|
this._onSafeModeRestart();
|
|
|
|
break;
|
2007-06-15 22:01:25 +04:00
|
|
|
case "quit-application-requested":
|
2007-07-26 01:43:17 +04:00
|
|
|
this._onQuitRequest(subject, data);
|
2007-06-15 22:01:25 +04:00
|
|
|
break;
|
|
|
|
case "quit-application-granted":
|
2014-02-07 21:47:35 +04:00
|
|
|
this._onQuitApplicationGranted();
|
2007-06-15 22:01:25 +04:00
|
|
|
break;
|
2009-07-31 08:57:57 +04:00
|
|
|
case "browser-lastwindow-close-requested":
|
2016-01-22 23:48:20 +03:00
|
|
|
if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
|
|
|
|
// The application is not actually quitting, but the last full browser
|
|
|
|
// window is about to be closed.
|
|
|
|
this._onQuitRequest(subject, "lastwindow");
|
|
|
|
}
|
2009-07-31 08:57:57 +04:00
|
|
|
break;
|
|
|
|
case "browser-lastwindow-close-granted":
|
2016-01-22 23:48:20 +03:00
|
|
|
if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
|
|
|
|
this._setPrefToSaveSession();
|
|
|
|
}
|
2009-07-31 08:57:57 +04:00
|
|
|
break;
|
2010-08-12 05:28:27 +04:00
|
|
|
case "weave:service:ready":
|
|
|
|
this._setSyncAutoconnectDelay();
|
|
|
|
break;
|
2016-06-02 20:36:53 +03:00
|
|
|
case "fxaccounts:onverified":
|
|
|
|
this._showSyncStartedDoorhanger();
|
|
|
|
break;
|
2017-01-05 03:21:36 +03:00
|
|
|
case "fxaccounts:device_connected":
|
|
|
|
this._onDeviceConnected(data);
|
|
|
|
break;
|
2016-06-08 20:40:42 +03:00
|
|
|
case "fxaccounts:device_disconnected":
|
|
|
|
this._onDeviceDisconnected();
|
|
|
|
break;
|
2016-07-07 23:33:29 +03:00
|
|
|
case "weave:engine:clients:display-uris":
|
|
|
|
this._onDisplaySyncURIs(subject);
|
2012-06-30 02:30:45 +04:00
|
|
|
break;
|
2008-02-07 12:28:43 +03:00
|
|
|
case "session-save":
|
2009-10-14 13:53:13 +04:00
|
|
|
this._setPrefToSaveSession(true);
|
2008-02-07 12:28:43 +03:00
|
|
|
subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
subject.data = true;
|
|
|
|
break;
|
2008-11-12 23:45:53 +03:00
|
|
|
case "places-init-complete":
|
2012-05-28 13:43:59 +04:00
|
|
|
if (!this._migrationImportsDefaultBookmarks)
|
|
|
|
this._initPlaces(false);
|
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "places-init-complete");
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesInitObserver = false;
|
2008-12-30 15:44:55 +03:00
|
|
|
// no longer needed, since history was initialized completely.
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "places-database-locked");
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesLockedObserver = false;
|
2008-12-30 15:44:55 +03:00
|
|
|
break;
|
|
|
|
case "places-database-locked":
|
|
|
|
this._isPlacesDatabaseLocked = true;
|
2009-10-14 13:53:13 +04:00
|
|
|
// Stop observing, so further attempts to load history service
|
|
|
|
// will not show the prompt.
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "places-database-locked");
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesLockedObserver = false;
|
2008-11-12 23:45:53 +03:00
|
|
|
break;
|
2008-03-13 22:25:49 +03:00
|
|
|
case "idle":
|
2014-02-04 17:43:20 +04:00
|
|
|
this._backupBookmarks();
|
2008-03-13 22:25:49 +03:00
|
|
|
break;
|
2009-10-05 14:13:04 +04:00
|
|
|
case "distribution-customization-complete":
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.removeObserver(this, "distribution-customization-complete");
|
2009-10-05 14:13:04 +04:00
|
|
|
// Customization has finished, we don't need the customizer anymore.
|
|
|
|
delete this._distributionCustomizer;
|
|
|
|
break;
|
2010-04-07 06:49:23 +04:00
|
|
|
case "browser-glue-test": // used by tests
|
|
|
|
if (data == "post-update-notification") {
|
2010-04-12 18:33:10 +04:00
|
|
|
if (Services.prefs.prefHasUserValue("app.update.postupdate"))
|
2010-04-07 06:49:23 +04:00
|
|
|
this._showUpdateNotification();
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (data == "force-ui-migration") {
|
2010-12-22 21:26:18 +03:00
|
|
|
this._migrateUI();
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (data == "force-distribution-customization") {
|
2011-04-13 05:15:39 +04:00
|
|
|
this._distributionCustomizer.applyPrefDefaults();
|
2011-04-12 18:32:20 +04:00
|
|
|
this._distributionCustomizer.applyCustomizations();
|
2011-04-13 05:15:39 +04:00
|
|
|
// To apply distribution bookmarks use "places-init-complete".
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (data == "force-places-init") {
|
2012-05-28 13:43:59 +04:00
|
|
|
this._initPlaces(false);
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (data == "smart-bookmarks-init") {
|
2015-04-01 20:09:26 +03:00
|
|
|
this.ensurePlacesDefaultQueriesInitialized().then(() => {
|
|
|
|
Services.obs.notifyObservers(null, "test-smart-bookmarks-done", null);
|
|
|
|
});
|
|
|
|
}
|
2010-04-07 06:49:23 +04:00
|
|
|
break;
|
2012-05-28 13:43:59 +04: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 11:15:36 +04:00
|
|
|
break;
|
2012-12-14 04:09:03 +04:00
|
|
|
case "handle-xul-text-link":
|
|
|
|
let linkHandled = subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
if (!linkHandled.data) {
|
2015-05-24 14:05:00 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2012-12-14 04:09:03 +04:00
|
|
|
if (win) {
|
2016-05-13 16:53:00 +03:00
|
|
|
data = JSON.parse(data);
|
|
|
|
let where = win.whereToOpenLink(data);
|
2016-05-20 13:51:20 +03:00
|
|
|
// Preserve legacy behavior of non-modifier left-clicks
|
|
|
|
// opening in a new selected tab.
|
|
|
|
if (where == "current") {
|
|
|
|
where = "tab";
|
|
|
|
}
|
2016-05-13 16:53:00 +03:00
|
|
|
win.openUILinkIn(data.href, where);
|
2012-12-14 04:09:03 +04:00
|
|
|
linkHandled.data = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-01-29 21:06:03 +04:00
|
|
|
case "profile-before-change":
|
2014-02-07 21:47:35 +04: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 21:06:03 +04:00
|
|
|
break;
|
2013-02-15 02:47:49 +04:00
|
|
|
case "keyword-search":
|
2015-12-03 03:26:07 +03:00
|
|
|
// This notification is broadcast by the docshell when it "fixes up" a
|
|
|
|
// URI that it's been asked to load into a keyword search.
|
2014-10-31 23:47:13 +03:00
|
|
|
let engine = null;
|
|
|
|
try {
|
|
|
|
engine = subject.QueryInterface(Ci.nsISearchEngine);
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
2015-12-03 03:26:07 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2016-01-05 08:29:00 +03:00
|
|
|
win.BrowserSearch.recordSearchInTelemetry(engine, "urlbar");
|
2014-07-17 19:37:22 +04:00
|
|
|
break;
|
2013-05-27 19:21:47 +04:00
|
|
|
case "browser-search-engine-modified":
|
2015-02-03 03:50:52 +03:00
|
|
|
// Ensure we cleanup the hiddenOneOffs pref when removing
|
|
|
|
// an engine, and that newly added engines are visible.
|
|
|
|
if (data == "engine-added" || data == "engine-removed") {
|
|
|
|
let engineName = subject.QueryInterface(Ci.nsISearchEngine).name;
|
2015-03-03 01:00:45 +03:00
|
|
|
let Preferences =
|
|
|
|
Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
|
|
|
|
let pref = Preferences.get("browser.search.hiddenOneOffs");
|
|
|
|
let hiddenList = pref ? pref.split(",") : [];
|
|
|
|
hiddenList = hiddenList.filter(x => x !== engineName);
|
|
|
|
Preferences.set("browser.search.hiddenOneOffs",
|
|
|
|
hiddenList.join(","));
|
2015-02-03 03:50:52 +03:00
|
|
|
}
|
2013-07-02 03:46:07 +04:00
|
|
|
break;
|
2015-02-20 01:43:24 +03:00
|
|
|
case "flash-plugin-hang":
|
|
|
|
this._handleFlashHang();
|
|
|
|
break;
|
2015-05-08 20:27:25 +03:00
|
|
|
case "xpi-signature-changed":
|
2015-08-05 23:33:57 +03:00
|
|
|
let disabledAddons = JSON.parse(data).disabled;
|
|
|
|
AddonManager.getAddonsByIDs(disabledAddons, (addons) => {
|
|
|
|
for (let addon of addons) {
|
|
|
|
if (addon.type != "experiment") {
|
|
|
|
this._notifyUnsignedAddonsDisabled();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-05-08 20:27:25 +03:00
|
|
|
break;
|
2015-07-27 20:18:19 +03:00
|
|
|
case "test-initialize-sanitizer":
|
|
|
|
this._sanitizer.onStartup();
|
|
|
|
break;
|
2016-01-27 15:34:58 +03:00
|
|
|
case AddonWatcher.TOPIC_SLOW_ADDON_DETECTED:
|
|
|
|
this._notifySlowAddon(data);
|
|
|
|
break;
|
2015-07-08 22:06:15 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-10-12 08:29:12 +03:00
|
|
|
// initialization (called on application startup)
|
2009-12-18 00:28:08 +03:00
|
|
|
_init: function BG__init() {
|
2010-04-22 18:11:21 +04:00
|
|
|
let os = Services.obs;
|
2015-09-25 23:18:29 +03:00
|
|
|
os.addObserver(this, "notifications-open-settings", false);
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "prefservice:after-app-defaults", false);
|
|
|
|
os.addObserver(this, "final-ui-startup", false);
|
2010-10-02 19:53:37 +04:00
|
|
|
os.addObserver(this, "browser-delayed-startup-finished", false);
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "sessionstore-windows-restored", false);
|
|
|
|
os.addObserver(this, "browser:purge-session-history", false);
|
|
|
|
os.addObserver(this, "quit-application-requested", false);
|
|
|
|
os.addObserver(this, "quit-application-granted", false);
|
2016-01-22 23:48:20 +03:00
|
|
|
if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
|
|
|
|
os.addObserver(this, "browser-lastwindow-close-requested", false);
|
|
|
|
os.addObserver(this, "browser-lastwindow-close-granted", false);
|
|
|
|
}
|
2010-08-12 05:28:27 +04:00
|
|
|
os.addObserver(this, "weave:service:ready", false);
|
2016-06-02 20:36:53 +03:00
|
|
|
os.addObserver(this, "fxaccounts:onverified", false);
|
2017-01-05 03:21:36 +03:00
|
|
|
os.addObserver(this, "fxaccounts:device_connected", false);
|
2016-06-08 20:40:42 +03:00
|
|
|
os.addObserver(this, "fxaccounts:device_disconnected", false);
|
2016-07-07 23:33:29 +03:00
|
|
|
os.addObserver(this, "weave:engine:clients:display-uris", false);
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "session-save", false);
|
|
|
|
os.addObserver(this, "places-init-complete", false);
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesInitObserver = true;
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "places-database-locked", false);
|
2009-09-29 14:44:18 +04:00
|
|
|
this._isPlacesLockedObserver = true;
|
2010-04-22 18:11:21 +04:00
|
|
|
os.addObserver(this, "distribution-customization-complete", false);
|
2012-12-14 04:09:03 +04:00
|
|
|
os.addObserver(this, "handle-xul-text-link", false);
|
2013-01-29 21:06:03 +04:00
|
|
|
os.addObserver(this, "profile-before-change", false);
|
2016-01-21 09:59:00 +03:00
|
|
|
if (AppConstants.MOZ_TELEMETRY_REPORTING) {
|
2016-01-22 23:48:20 +03:00
|
|
|
os.addObserver(this, "keyword-search", false);
|
|
|
|
}
|
2013-05-27 19:21:47 +04:00
|
|
|
os.addObserver(this, "browser-search-engine-modified", false);
|
2015-02-20 03:53:00 +03:00
|
|
|
os.addObserver(this, "restart-in-safe-mode", false);
|
2015-02-20 01:43:24 +03:00
|
|
|
os.addObserver(this, "flash-plugin-hang", false);
|
2015-05-08 20:27:25 +03:00
|
|
|
os.addObserver(this, "xpi-signature-changed", false);
|
2015-02-20 01:43:24 +03:00
|
|
|
|
2016-01-27 15:34:58 +03:00
|
|
|
if (AppConstants.NIGHTLY_BUILD) {
|
|
|
|
os.addObserver(this, AddonWatcher.TOPIC_SLOW_ADDON_DETECTED, false);
|
|
|
|
}
|
|
|
|
|
2015-02-20 01:43:24 +03:00
|
|
|
this._flashHangCount = 0;
|
2015-11-03 01:59:52 +03:00
|
|
|
this._firstWindowReady = new Promise(resolve => this._firstWindowLoaded = resolve);
|
2016-07-27 01:22:00 +03:00
|
|
|
|
2017-01-11 12:54:16 +03:00
|
|
|
if (AppConstants.platform == "macosx") {
|
2016-07-27 01:22:00 +03:00
|
|
|
// Handles prompting to inform about incompatibilites when accessibility
|
|
|
|
// and e10s are active together.
|
|
|
|
E10SAccessibilityCheck.init();
|
|
|
|
}
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// cleanup (called on application shutdown)
|
2009-12-18 00:28:08 +03:00
|
|
|
_dispose: function BG__dispose() {
|
2010-04-22 18:11:21 +04:00
|
|
|
let os = Services.obs;
|
2015-09-25 23:18:29 +03:00
|
|
|
os.removeObserver(this, "notifications-open-settings");
|
2010-04-22 18:11:21 +04:00
|
|
|
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");
|
2015-02-20 03:53:00 +03:00
|
|
|
os.removeObserver(this, "restart-in-safe-mode");
|
2016-01-22 23:48:20 +03:00
|
|
|
if (OBSERVE_LASTWINDOW_CLOSE_TOPICS) {
|
|
|
|
os.removeObserver(this, "browser-lastwindow-close-requested");
|
|
|
|
os.removeObserver(this, "browser-lastwindow-close-granted");
|
|
|
|
}
|
2013-04-06 22:46:35 +04:00
|
|
|
os.removeObserver(this, "weave:service:ready");
|
2016-06-02 20:36:53 +03:00
|
|
|
os.removeObserver(this, "fxaccounts:onverified");
|
2017-01-05 03:21:36 +03:00
|
|
|
os.removeObserver(this, "fxaccounts:device_connected");
|
2016-06-08 20:40:42 +03:00
|
|
|
os.removeObserver(this, "fxaccounts:device_disconnected");
|
2016-07-07 23:33:29 +03:00
|
|
|
os.removeObserver(this, "weave:engine:clients:display-uris");
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "session-save");
|
2014-02-04 17:43:20 +04:00
|
|
|
if (this._bookmarksBackupIdleTime) {
|
|
|
|
this._idleService.removeIdleObserver(this, this._bookmarksBackupIdleTime);
|
|
|
|
delete this._bookmarksBackupIdleTime;
|
|
|
|
}
|
2009-09-29 14:44:18 +04:00
|
|
|
if (this._isPlacesInitObserver)
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "places-init-complete");
|
2009-09-29 14:44:18 +04:00
|
|
|
if (this._isPlacesLockedObserver)
|
2010-04-22 18:11:21 +04:00
|
|
|
os.removeObserver(this, "places-database-locked");
|
2012-12-14 04:09:03 +04:00
|
|
|
os.removeObserver(this, "handle-xul-text-link");
|
2013-01-29 21:06:03 +04:00
|
|
|
os.removeObserver(this, "profile-before-change");
|
2016-01-21 09:59:00 +03:00
|
|
|
if (AppConstants.MOZ_TELEMETRY_REPORTING) {
|
2016-01-22 23:48:20 +03:00
|
|
|
os.removeObserver(this, "keyword-search");
|
|
|
|
}
|
2013-05-27 19:21:47 +04:00
|
|
|
os.removeObserver(this, "browser-search-engine-modified");
|
2015-02-20 01:43:24 +03:00
|
|
|
os.removeObserver(this, "flash-plugin-hang");
|
2015-05-08 20:27:25 +03:00
|
|
|
os.removeObserver(this, "xpi-signature-changed");
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_onAppDefaults: function BG__onAppDefaults() {
|
2007-09-11 19:52:04 +04:00
|
|
|
// apply distribution customizations (prefs)
|
2013-05-13 20:25:39 +04:00
|
|
|
// other customizations are applied in _finalUIStartup()
|
2009-10-05 14:13:04 +04:00
|
|
|
this._distributionCustomizer.applyPrefDefaults();
|
2007-09-11 19:52:04 +04:00
|
|
|
},
|
|
|
|
|
2015-02-23 19:39:05 +03:00
|
|
|
_notifySlowAddon: function BG_notifySlowAddon(addonId) {
|
|
|
|
let addonCallback = function(addon) {
|
|
|
|
if (!addon) {
|
|
|
|
Cu.reportError("couldn't look up addon: " + addonId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let brandBundle = win.document.getElementById("bundle_brand");
|
|
|
|
let brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
let message = win.gNavigatorBundle.getFormattedString("addonwatch.slow", [addon.name, brandShortName]);
|
|
|
|
let notificationBox = win.document.getElementById("global-notificationbox");
|
2017-01-17 18:48:17 +03:00
|
|
|
let notificationId = "addon-slow:" + addonId;
|
2015-02-23 19:39:05 +03:00
|
|
|
let notification = notificationBox.getNotificationWithValue(notificationId);
|
2015-07-31 15:00:10 +03:00
|
|
|
|
|
|
|
// Monitor the response of users
|
|
|
|
const STATE_WARNING_DISPLAYED = 0;
|
|
|
|
const STATE_USER_PICKED_DISABLE = 1;
|
|
|
|
const STATE_USER_PICKED_IGNORE_FOR_NOW = 2;
|
|
|
|
const STATE_USER_PICKED_IGNORE_FOREVER = 3;
|
|
|
|
const STATE_USER_CLOSED_NOTIFICATION = 4;
|
|
|
|
|
|
|
|
let update = function(response) {
|
|
|
|
Services.telemetry.getHistogramById("SLOW_ADDON_WARNING_STATES").add(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
let complete = false;
|
|
|
|
let start = Date.now();
|
|
|
|
let done = function(response) {
|
|
|
|
// Only report the first reason for closing.
|
|
|
|
if (complete) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
complete = true;
|
|
|
|
update(response);
|
|
|
|
Services.telemetry.getHistogramById("SLOW_ADDON_WARNING_RESPONSE_TIME").add(Date.now() - start);
|
|
|
|
};
|
|
|
|
|
|
|
|
update(STATE_WARNING_DISPLAYED);
|
|
|
|
|
|
|
|
if (notification) {
|
2015-02-23 19:39:05 +03:00
|
|
|
notification.label = message;
|
|
|
|
} else {
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getFormattedString("addonwatch.disable.label", [addon.name]),
|
2015-08-10 17:51:00 +03:00
|
|
|
accessKey: "", // workaround for bug 1192901
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-07-31 15:00:10 +03:00
|
|
|
done(STATE_USER_PICKED_DISABLE);
|
2015-02-23 19:39:05 +03:00
|
|
|
addon.userDisabled = true;
|
2015-07-31 15:00:10 +03:00
|
|
|
if (addon.pendingOperations == addon.PENDING_NONE) {
|
|
|
|
return;
|
2015-02-23 19:39:05 +03:00
|
|
|
}
|
2015-07-31 15:00:10 +03:00
|
|
|
let restartMessage = win.gNavigatorBundle.getFormattedString("addonwatch.restart.message", [addon.name, brandShortName]);
|
|
|
|
let restartButton = [
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getFormattedString("addonwatch.restart.label", [brandShortName]),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("addonwatch.restart.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-07-31 15:00:10 +03:00
|
|
|
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
|
|
|
|
.getService(Ci.nsIAppStartup);
|
|
|
|
appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
|
|
|
|
notificationBox.appendNotification(restartMessage, "restart-" + addonId, "",
|
|
|
|
priority, restartButton);
|
2015-02-23 19:39:05 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getString("addonwatch.ignoreSession.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("addonwatch.ignoreSession.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-07-31 15:00:10 +03:00
|
|
|
done(STATE_USER_PICKED_IGNORE_FOR_NOW);
|
2015-02-23 19:39:05 +03:00
|
|
|
AddonWatcher.ignoreAddonForSession(addonId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getString("addonwatch.ignorePerm.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("addonwatch.ignorePerm.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-07-31 15:00:10 +03:00
|
|
|
done(STATE_USER_PICKED_IGNORE_FOREVER);
|
2015-02-23 19:39:05 +03:00
|
|
|
AddonWatcher.ignoreAddonPermanently(addonId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
|
2015-07-31 15:00:10 +03:00
|
|
|
notification = notificationBox.appendNotification(
|
|
|
|
message, notificationId, "",
|
|
|
|
priority, buttons,
|
|
|
|
function(topic) {
|
|
|
|
if (topic == "removed") {
|
|
|
|
// Other callbacks are called before this one and only the first
|
|
|
|
// call to `done` is taken into account, so if this call to `done`
|
|
|
|
// gets through, this means that the user has closed the notification
|
|
|
|
// manually.
|
|
|
|
done(STATE_USER_CLOSED_NOTIFICATION);
|
|
|
|
}
|
|
|
|
});
|
2015-02-23 19:39:05 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
AddonManager.getAddonByID(addonId, addonCallback);
|
|
|
|
},
|
|
|
|
|
2013-05-13 20:25:39 +04: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 13:53:13 +04:00
|
|
|
this._sanitizer.onStartup();
|
2005-10-04 09:02:47 +04:00
|
|
|
// check if we're in safe mode
|
2010-04-12 18:33:10 +04:00
|
|
|
if (Services.appinfo.inSafeMode) {
|
2015-10-12 08:29:12 +03:00
|
|
|
Services.ww.openWindow(null, "chrome://browser/content/safeMode.xul",
|
2010-04-12 18:33:10 +04:00
|
|
|
"_blank", "chrome,centerscreen,modal,resizable=no", null);
|
2005-10-04 09:02:47 +04:00
|
|
|
}
|
2007-05-03 12:56:41 +04:00
|
|
|
|
2007-09-11 19:52:04 +04:00
|
|
|
// apply distribution customizations
|
|
|
|
// prefs are applied in _onAppDefaults()
|
2009-10-05 14:13:04 +04:00
|
|
|
this._distributionCustomizer.applyCustomizations();
|
2007-09-11 19:52:04 +04:00
|
|
|
|
2008-02-04 22:37:26 +03:00
|
|
|
// handle any UI migration
|
2008-03-20 21:57:05 +03:00
|
|
|
this._migrateUI();
|
2008-10-01 09:36:21 +04:00
|
|
|
|
2012-05-03 00:11:19 +04:00
|
|
|
PageThumbs.init();
|
2012-10-05 13:37:00 +04:00
|
|
|
webrtcUI.init();
|
2013-07-06 00:55:00 +04:00
|
|
|
AboutHome.init();
|
2015-10-12 08:29:12 +03:00
|
|
|
|
|
|
|
DirectoryLinksProvider.init();
|
|
|
|
NewTabUtils.init();
|
|
|
|
NewTabUtils.links.addProvider(DirectoryLinksProvider);
|
2015-06-15 22:36:43 +03:00
|
|
|
AboutNewTab.init();
|
2015-10-12 08:29:12 +03:00
|
|
|
|
2016-03-04 06:20:23 +03:00
|
|
|
NewTabMessages.init();
|
2015-10-31 06:00:35 +03:00
|
|
|
|
2013-10-17 22:26:25 +04:00
|
|
|
SessionStore.init();
|
2016-05-12 10:30:00 +03:00
|
|
|
BrowserUsageTelemetry.init();
|
2013-12-10 23:49:02 +04:00
|
|
|
BrowserUITelemetry.init();
|
2014-04-25 06:09:20 +04:00
|
|
|
ContentSearch.init();
|
2014-08-21 19:42:42 +04:00
|
|
|
FormValidationHandler.init();
|
2012-05-03 00:11:19 +04:00
|
|
|
|
2014-08-11 22:13:36 +04:00
|
|
|
ContentClick.init();
|
|
|
|
RemotePrompt.init();
|
2015-08-01 03:03:37 +03:00
|
|
|
Feeds.init();
|
2014-08-11 22:13:36 +04:00
|
|
|
ContentPrefServiceParent.init();
|
2013-08-09 04:16:47 +04:00
|
|
|
|
2014-06-28 22:09:45 +04:00
|
|
|
LoginManagerParent.init();
|
2014-12-30 18:44:34 +03:00
|
|
|
ReaderParent.init();
|
2016-08-12 20:48:59 +03:00
|
|
|
URLBarZoom.init();
|
2014-06-28 22:09:45 +04:00
|
|
|
|
2015-01-27 10:11:00 +03:00
|
|
|
SelfSupportBackend.init();
|
|
|
|
|
2016-07-26 14:48:37 +03:00
|
|
|
// Ensure we keep track of places/pw-mananager undo by init'ing this early.
|
|
|
|
Cu.import("resource:///modules/AutoMigrate.jsm");
|
|
|
|
|
2017-01-13 22:53:58 +03:00
|
|
|
if (AppConstants.INSTALL_COMPACT_THEMES) {
|
2016-01-22 23:48:20 +03:00
|
|
|
let vendorShortName = gBrandBundle.GetStringFromName("vendorShortName");
|
2015-04-01 06:00:32 +03:00
|
|
|
|
2016-01-22 23:48:20 +03:00
|
|
|
LightweightThemeManager.addBuiltInTheme({
|
2017-01-13 22:53:58 +03:00
|
|
|
id: "firefox-compact-light@mozilla.org",
|
|
|
|
name: gBrowserBundle.GetStringFromName("compactLightTheme.name"),
|
|
|
|
description: gBrowserBundle.GetStringFromName("compactLightTheme.description"),
|
|
|
|
headerURL: "resource:///chrome/browser/content/browser/defaultthemes/compact.header.png",
|
|
|
|
iconURL: "resource:///chrome/browser/content/browser/defaultthemes/compactlight.icon.svg",
|
|
|
|
textcolor: "black",
|
|
|
|
accentcolor: "white",
|
|
|
|
author: vendorShortName,
|
|
|
|
});
|
|
|
|
LightweightThemeManager.addBuiltInTheme({
|
|
|
|
id: "firefox-compact-dark@mozilla.org",
|
|
|
|
name: gBrowserBundle.GetStringFromName("compactDarkTheme.name"),
|
|
|
|
description: gBrowserBundle.GetStringFromName("compactDarkTheme.description"),
|
|
|
|
headerURL: "resource:///chrome/browser/content/browser/defaultthemes/compact.header.png",
|
|
|
|
iconURL: "resource:///chrome/browser/content/browser/defaultthemes/compactdark.icon.svg",
|
|
|
|
textcolor: "white",
|
|
|
|
accentcolor: "black",
|
2016-01-22 23:48:20 +03:00
|
|
|
author: vendorShortName,
|
|
|
|
});
|
|
|
|
}
|
2015-04-01 06:00:32 +03:00
|
|
|
|
2015-11-03 04:57:03 +03:00
|
|
|
TabCrashHandler.init();
|
2016-01-22 23:48:20 +03:00
|
|
|
if (AppConstants.MOZ_CRASHREPORTER) {
|
|
|
|
PluginCrashReporter.init();
|
2016-09-02 20:16:28 +03:00
|
|
|
UnsubmittedCrashHandler.init();
|
2016-01-22 23:48:20 +03:00
|
|
|
}
|
2015-03-28 06:34:15 +03:00
|
|
|
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
|
2007-05-11 04:42:22 +04:00
|
|
|
},
|
2007-05-03 12:56:41 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_checkForOldBuildUpdates() {
|
2013-07-31 07:19:58 +04:00
|
|
|
// check for update if our build is old
|
2015-08-18 14:33:24 +03:00
|
|
|
if (AppConstants.MOZ_UPDATER &&
|
|
|
|
Services.prefs.getBoolPref("app.update.enabled") &&
|
2013-07-31 07:19:58 +04:00
|
|
|
Services.prefs.getBoolPref("app.update.checkInstallTime")) {
|
|
|
|
|
|
|
|
let buildID = Services.appinfo.appBuildID;
|
|
|
|
let today = new Date().getTime();
|
2016-08-16 22:44:15 +03:00
|
|
|
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
|
2013-07-31 07:19:58 +04:00
|
|
|
.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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-02-20 03:53:00 +03:00
|
|
|
_onSafeModeRestart: function BG_onSafeModeRestart() {
|
|
|
|
// prompt the user to confirm
|
2015-04-01 02:00:45 +03:00
|
|
|
let strings = gBrowserBundle;
|
2015-02-20 03:53:00 +03:00
|
|
|
let promptTitle = strings.GetStringFromName("safeModeRestartPromptTitle");
|
|
|
|
let promptMessage = strings.GetStringFromName("safeModeRestartPromptMessage");
|
|
|
|
let restartText = strings.GetStringFromName("safeModeRestartButton");
|
|
|
|
let buttonFlags = (Services.prompt.BUTTON_POS_0 *
|
|
|
|
Services.prompt.BUTTON_TITLE_IS_STRING) +
|
|
|
|
(Services.prompt.BUTTON_POS_1 *
|
|
|
|
Services.prompt.BUTTON_TITLE_CANCEL) +
|
|
|
|
Services.prompt.BUTTON_POS_0_DEFAULT;
|
|
|
|
|
|
|
|
let rv = Services.prompt.confirmEx(null, promptTitle, promptMessage,
|
|
|
|
buttonFlags, restartText, null, null,
|
|
|
|
null, {});
|
|
|
|
if (rv != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
|
|
|
|
.createInstance(Ci.nsISupportsPRBool);
|
|
|
|
Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
|
|
|
|
|
|
|
|
if (!cancelQuit.data) {
|
|
|
|
Services.startup.restartInSafeMode(Ci.nsIAppStartup.eAttemptQuit);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_trackSlowStartup() {
|
2013-02-20 03:15:38 +04:00
|
|
|
if (Services.startup.interrupted ||
|
|
|
|
Services.prefs.getBoolPref("browser.slowStartup.notificationDisabled"))
|
2013-02-02 01:47:07 +04: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-13 03:55:05 +04:00
|
|
|
let totalTime = (averageTime * samples) + currentTime;
|
|
|
|
samples++;
|
|
|
|
averageTime = totalTime / samples;
|
2013-02-02 01:47:07 +04:00
|
|
|
|
|
|
|
if (samples >= Services.prefs.getIntPref("browser.slowStartup.maxSamples")) {
|
|
|
|
if (averageTime > Services.prefs.getIntPref("browser.slowStartup.timeThreshold"))
|
2016-09-02 20:40:21 +03:00
|
|
|
this._calculateProfileAgeInDays().then(this._showSlowStartupNotification, null);
|
2013-02-02 01:47:07 +04:00
|
|
|
averageTime = 0;
|
|
|
|
samples = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.prefs.setIntPref("browser.slowStartup.averageTime", averageTime);
|
|
|
|
Services.prefs.setIntPref("browser.slowStartup.samples", samples);
|
|
|
|
},
|
|
|
|
|
2016-09-02 20:40:21 +03:00
|
|
|
_calculateProfileAgeInDays: Task.async(function* () {
|
|
|
|
let ProfileAge = Cu.import("resource://gre/modules/ProfileAge.jsm", {}).ProfileAge;
|
|
|
|
let profileAge = new ProfileAge(null, null);
|
|
|
|
|
|
|
|
let creationDate = yield profileAge.created;
|
|
|
|
let resetDate = yield profileAge.reset;
|
|
|
|
|
|
|
|
// if the profile was reset, consider the
|
|
|
|
// reset date for its age.
|
|
|
|
let profileDate = resetDate || creationDate;
|
|
|
|
|
|
|
|
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
|
|
return (Date.now() - profileDate) / ONE_DAY;
|
|
|
|
}),
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_showSlowStartupNotification(profileAge) {
|
2016-09-02 20:40:21 +03:00
|
|
|
if (profileAge < 90) // 3 months
|
|
|
|
return;
|
|
|
|
|
2015-05-24 14:05:00 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2013-02-02 01:47:07 +04:00
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
|
2015-04-01 02:00:45 +03:00
|
|
|
let productName = gBrandBundle.GetStringFromName("brandFullName");
|
2013-02-02 01:47:07 +04:00
|
|
|
let message = win.gNavigatorBundle.getFormattedString("slowStartup.message", [productName]);
|
|
|
|
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getString("slowStartup.helpButton.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("slowStartup.helpButton.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2013-08-24 05:30:07 +04:00
|
|
|
win.openUILinkIn("https://support.mozilla.org/kb/reset-firefox-easily-fix-most-problems", "tab");
|
2013-02-02 01:47:07 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getString("slowStartup.disableNotificationButton.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("slowStartup.disableNotificationButton.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2013-02-02 01:47:07 +04:00
|
|
|
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-29 07:25:08 +04:00
|
|
|
/**
|
2016-04-27 12:37:00 +03:00
|
|
|
* Show a notification bar offering a reset.
|
|
|
|
*
|
|
|
|
* @param reason
|
|
|
|
* String of either "unused" or "uninstall", specifying the reason
|
|
|
|
* why a profile reset is offered.
|
2013-06-29 07:25:08 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_resetProfileNotification(reason) {
|
2015-05-24 14:05:00 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2013-06-29 07:25:08 +04:00
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/ResetProfile.jsm");
|
|
|
|
if (!ResetProfile.resetSupported())
|
|
|
|
return;
|
|
|
|
|
2015-04-01 02:00:45 +03:00
|
|
|
let productName = gBrandBundle.GetStringFromName("brandShortName");
|
2013-06-29 07:25:08 +04:00
|
|
|
let resetBundle = Services.strings
|
|
|
|
.createBundle("chrome://global/locale/resetProfile.properties");
|
|
|
|
|
2016-04-27 12:37:00 +03:00
|
|
|
let message;
|
|
|
|
if (reason == "unused") {
|
|
|
|
message = resetBundle.formatStringFromName("resetUnusedProfile.message", [productName], 1);
|
|
|
|
} else if (reason == "uninstall") {
|
|
|
|
message = resetBundle.formatStringFromName("resetUninstalled.message", [productName], 1);
|
|
|
|
} else {
|
|
|
|
throw new Error(`Unknown reason (${reason}) given to _resetProfileNotification.`);
|
|
|
|
}
|
2013-06-29 07:25:08 +04:00
|
|
|
let buttons = [
|
|
|
|
{
|
2014-10-11 05:37:16 +04:00
|
|
|
label: resetBundle.formatStringFromName("refreshProfile.resetButton.label", [productName], 1),
|
|
|
|
accessKey: resetBundle.GetStringFromName("refreshProfile.resetButton.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2013-06-29 07:25:08 +04:00
|
|
|
ResetProfile.openConfirmationDialog(win);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
let nb = win.document.getElementById("global-notificationbox");
|
2016-04-27 12:37:00 +03:00
|
|
|
nb.appendNotification(message, "reset-profile-notification",
|
2013-06-29 07:25:08 +04:00
|
|
|
"chrome://global/skin/icons/question-16.png",
|
|
|
|
nb.PRIORITY_INFO_LOW, buttons);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_notifyUnsignedAddonsDisabled() {
|
2015-05-24 14:05:00 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2015-05-08 20:27:25 +03:00
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let message = win.gNavigatorBundle.getString("unsignedAddonsDisabled.message");
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: win.gNavigatorBundle.getString("unsignedAddonsDisabled.learnMore.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("unsignedAddonsDisabled.learnMore.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-05-08 20:27:25 +03:00
|
|
|
win.BrowserOpenAddonsMgr("addons://list/extension?unsigned=true");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
let nb = win.document.getElementById("high-priority-global-notificationbox");
|
|
|
|
nb.appendNotification(message, "unsigned-addons-disabled", "",
|
|
|
|
nb.PRIORITY_WARNING_MEDIUM, buttons);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_firstWindowTelemetry(aWindow) {
|
2014-06-27 22:20:02 +04:00
|
|
|
let SCALING_PROBE_NAME = "";
|
2016-01-22 23:48:20 +03:00
|
|
|
switch (AppConstants.platform) {
|
|
|
|
case "win":
|
|
|
|
SCALING_PROBE_NAME = "DISPLAY_SCALING_MSWIN";
|
|
|
|
break;
|
|
|
|
case "macosx":
|
|
|
|
SCALING_PROBE_NAME = "DISPLAY_SCALING_OSX";
|
|
|
|
break;
|
|
|
|
case "linux":
|
|
|
|
SCALING_PROBE_NAME = "DISPLAY_SCALING_LINUX";
|
|
|
|
break;
|
|
|
|
}
|
2014-06-27 22:20:02 +04:00
|
|
|
if (SCALING_PROBE_NAME) {
|
|
|
|
let scaling = aWindow.devicePixelRatio * 100;
|
2016-09-19 22:40:28 +03:00
|
|
|
try {
|
|
|
|
Services.telemetry.getHistogramById(SCALING_PROBE_NAME).add(scaling);
|
|
|
|
} catch (ex) {}
|
2014-06-27 22:20:02 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-02 19:53:37 +04:00
|
|
|
// the first browser window has finished initializing
|
2013-07-27 09:40:07 +04:00
|
|
|
_onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) {
|
2014-09-22 20:33:29 +04:00
|
|
|
// Initialize PdfJs when running in-process and remote. This only
|
|
|
|
// happens once since PdfJs registers global hooks. If the PdfJs
|
|
|
|
// extension is installed the init method below will be overridden
|
|
|
|
// leaving initialization to the extension.
|
|
|
|
// parent only: configure default prefs, set up pref observers, register
|
|
|
|
// pdf content handler, and initializes parent side message manager
|
|
|
|
// shim for privileged api access.
|
|
|
|
PdfJs.init(true);
|
|
|
|
// child only: similar to the call above for parent - register content
|
|
|
|
// handler and init message manager child shim for privileged api access.
|
|
|
|
// With older versions of the extension installed, this load will fail
|
|
|
|
// passively.
|
2015-08-04 22:55:54 +03:00
|
|
|
Services.ppmm.loadProcessScript("resource://pdf.js/pdfjschildbootstrap.js", true);
|
2015-05-08 20:27:56 +03:00
|
|
|
|
2016-01-22 23:48:20 +03:00
|
|
|
if (AppConstants.platform == "win") {
|
|
|
|
// For Windows 7, initialize the jump list module.
|
|
|
|
const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
|
|
|
|
if (WINTASKBAR_CONTRACTID in Cc &&
|
|
|
|
Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available) {
|
|
|
|
let temp = {};
|
|
|
|
Cu.import("resource:///modules/WindowsJumpLists.jsm", temp);
|
|
|
|
temp.WinTaskbarJumpList.startup();
|
|
|
|
}
|
2010-10-02 19:53:37 +04:00
|
|
|
}
|
2013-02-02 01:47:07 +04:00
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
ProcessHangMonitor.init();
|
|
|
|
|
2014-11-07 10:12:26 +03:00
|
|
|
// A channel for "remote troubleshooting" code...
|
|
|
|
let channel = new WebChannel("remote-troubleshooting", "remote-troubleshooting");
|
|
|
|
channel.listen((id, data, target) => {
|
|
|
|
if (data.command == "request") {
|
|
|
|
let {Troubleshoot} = Cu.import("resource://gre/modules/Troubleshoot.jsm", {});
|
2016-11-16 06:58:30 +03:00
|
|
|
Troubleshoot.snapshot(snapshotData => {
|
2014-11-07 10:12:26 +03:00
|
|
|
// for privacy we remove crash IDs and all preferences (but bug 1091944
|
|
|
|
// exists to expose prefs once we are confident of privacy implications)
|
2016-11-16 06:58:30 +03:00
|
|
|
delete snapshotData.crashes;
|
|
|
|
delete snapshotData.modifiedPreferences;
|
|
|
|
channel.send(snapshotData, target);
|
2014-11-07 10:12:26 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-02 01:47:07 +04:00
|
|
|
this._trackSlowStartup();
|
2013-06-29 07:25:08 +04: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;
|
2014-03-24 04:41:06 +04:00
|
|
|
let disableResetPrompt = false;
|
|
|
|
try {
|
|
|
|
disableResetPrompt = Services.prefs.getBoolPref("browser.disableResetPrompt");
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {}
|
2016-04-27 12:37:00 +03:00
|
|
|
|
2014-03-24 04:41:06 +04:00
|
|
|
if (!disableResetPrompt && lastUse &&
|
2013-07-27 19:22:56 +04:00
|
|
|
Date.now() - lastUse >= OFFER_PROFILE_RESET_INTERVAL_MS) {
|
2016-04-27 12:37:00 +03:00
|
|
|
this._resetProfileNotification("unused");
|
|
|
|
} else if (AppConstants.platform == "win" && !disableResetPrompt) {
|
|
|
|
// Check if we were just re-installed and offer Firefox Reset
|
|
|
|
let updateChannel;
|
|
|
|
try {
|
|
|
|
updateChannel = Cu.import("resource://gre/modules/UpdateUtils.jsm", {}).UpdateUtils.UpdateChannel;
|
|
|
|
} catch (ex) {}
|
|
|
|
if (updateChannel) {
|
|
|
|
let uninstalledValue =
|
|
|
|
WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
"Software\\Mozilla\\Firefox",
|
|
|
|
`Uninstalled-${updateChannel}`);
|
|
|
|
let removalSuccessful =
|
|
|
|
WindowsRegistry.removeRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
"Software\\Mozilla\\Firefox",
|
|
|
|
`Uninstalled-${updateChannel}`);
|
|
|
|
if (removalSuccessful && uninstalledValue == "True") {
|
|
|
|
this._resetProfileNotification("uninstall");
|
|
|
|
}
|
|
|
|
}
|
2013-06-29 07:25:08 +04:00
|
|
|
}
|
2013-07-31 07:19:58 +04:00
|
|
|
|
|
|
|
this._checkForOldBuildUpdates();
|
2014-06-27 22:20:02 +04:00
|
|
|
|
2016-08-18 17:50:58 +03:00
|
|
|
AutoCompletePopup.init();
|
2016-10-06 07:17:00 +03:00
|
|
|
DateTimePickerHelper.init();
|
2016-08-18 17:50:58 +03:00
|
|
|
|
2014-06-27 22:20:02 +04:00
|
|
|
this._firstWindowTelemetry(aWindow);
|
2015-11-03 01:59:52 +03:00
|
|
|
this._firstWindowLoaded();
|
2010-10-02 19:53:37 +04:00
|
|
|
},
|
|
|
|
|
2013-01-29 21:06:03 +04:00
|
|
|
/**
|
2014-02-07 21:47:35 +04:00
|
|
|
* Application shutdown handler.
|
2013-01-29 21:06:03 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_onQuitApplicationGranted() {
|
2014-02-07 21:47:35 +04:00
|
|
|
// This pref must be set here because SessionStore will use its value
|
|
|
|
// on quit-application.
|
|
|
|
this._setPrefToSaveSession();
|
2014-02-09 01:04:31 +04:00
|
|
|
|
|
|
|
// Call trackStartupCrashEnd here in case the delayed call on startup hasn't
|
|
|
|
// yet occurred (see trackStartupCrashEnd caller in browser.js).
|
2014-02-07 21:47:35 +04:00
|
|
|
try {
|
|
|
|
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
|
|
|
|
.getService(Ci.nsIAppStartup);
|
|
|
|
appStartup.trackStartupCrashEnd();
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("Could not end startup crash tracking in quit-application-granted: " + e);
|
|
|
|
}
|
|
|
|
|
2017-01-26 19:54:32 +03:00
|
|
|
if (this._bookmarksBackupIdleTime) {
|
|
|
|
this._idleService.removeIdleObserver(this, this._bookmarksBackupIdleTime);
|
|
|
|
delete this._bookmarksBackupIdleTime;
|
|
|
|
}
|
|
|
|
|
2016-05-12 10:30:00 +03:00
|
|
|
BrowserUsageTelemetry.uninit();
|
2015-01-27 10:11:00 +03:00
|
|
|
SelfSupportBackend.uninit();
|
2017-01-26 19:54:32 +03:00
|
|
|
PageThumbs.uninit();
|
2016-03-04 06:20:23 +03:00
|
|
|
NewTabMessages.uninit();
|
2015-06-15 22:36:43 +03:00
|
|
|
AboutNewTab.uninit();
|
2013-01-29 21:06:03 +04:00
|
|
|
webrtcUI.uninit();
|
2014-08-21 19:42:42 +04:00
|
|
|
FormValidationHandler.uninit();
|
2016-08-18 17:50:58 +03:00
|
|
|
AutoCompletePopup.uninit();
|
2016-10-06 07:17:00 +03:00
|
|
|
DateTimePickerHelper.uninit();
|
2016-01-22 23:48:20 +03:00
|
|
|
if (AppConstants.NIGHTLY_BUILD) {
|
|
|
|
AddonWatcher.uninit();
|
|
|
|
}
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_initServiceDiscovery() {
|
2015-03-09 16:15:55 +03:00
|
|
|
if (!Services.prefs.getBoolPref("browser.casting.enabled")) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-18 02:55:14 +04:00
|
|
|
var rokuDevice = {
|
|
|
|
id: "roku:ecp",
|
|
|
|
target: "roku:ecp",
|
2016-12-30 02:34:54 +03:00
|
|
|
factory(aService) {
|
2014-10-18 02:55:14 +04:00
|
|
|
Cu.import("resource://gre/modules/RokuApp.jsm");
|
|
|
|
return new RokuApp(aService);
|
|
|
|
},
|
|
|
|
types: ["video/mp4"],
|
|
|
|
extensions: ["mp4"]
|
|
|
|
};
|
|
|
|
|
|
|
|
// Register targets
|
|
|
|
SimpleServiceDiscovery.registerDevice(rokuDevice);
|
|
|
|
|
|
|
|
// Search for devices continuously every 120 seconds
|
|
|
|
SimpleServiceDiscovery.search(120 * 1000);
|
|
|
|
},
|
|
|
|
|
2012-01-19 03:25:05 +04:00
|
|
|
// All initial windows have opened.
|
|
|
|
_onWindowsRestored: function BG__onWindowsRestored() {
|
2016-01-22 23:48:20 +03:00
|
|
|
if (AppConstants.MOZ_DEV_EDITION) {
|
|
|
|
this._createExtraDefaultProfile();
|
|
|
|
}
|
2014-11-05 21:21:42 +03:00
|
|
|
|
2014-10-18 02:55:14 +04:00
|
|
|
this._initServiceDiscovery();
|
|
|
|
|
2010-04-07 06:49:23 +04:00
|
|
|
// Show update notification, if needed.
|
2010-04-12 18:33:10 +04:00
|
|
|
if (Services.prefs.prefHasUserValue("app.update.postupdate"))
|
2010-04-07 06:49:23 +04:00
|
|
|
this._showUpdateNotification();
|
|
|
|
|
2008-12-30 15:44:55 +03:00
|
|
|
// Load the "more info" page for a locked places.sqlite
|
2010-08-09 19:59:59 +04:00
|
|
|
// This property is set earlier by places-database-locked topic.
|
2008-12-30 15:44:55 +03:00
|
|
|
if (this._isPlacesDatabaseLocked) {
|
|
|
|
this._showPlacesLockedNotificationBox();
|
|
|
|
}
|
2009-10-02 15:26:04 +04:00
|
|
|
|
2017-01-03 21:55:25 +03:00
|
|
|
ExtensionsUI.init();
|
|
|
|
|
2016-01-22 23:48:20 +03:00
|
|
|
let signingRequired;
|
|
|
|
if (AppConstants.MOZ_REQUIRE_SIGNING) {
|
|
|
|
signingRequired = true;
|
|
|
|
} else {
|
|
|
|
signingRequired = Services.prefs.getBoolPref("xpinstall.signatures.required");
|
|
|
|
}
|
2015-08-21 00:25:22 +03:00
|
|
|
|
|
|
|
if (signingRequired) {
|
|
|
|
let disabledAddons = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_DISABLED);
|
|
|
|
AddonManager.getAddonsByIDs(disabledAddons, (addons) => {
|
|
|
|
for (let addon of addons) {
|
|
|
|
if (addon.type == "experiment")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (addon.signedState <= AddonManager.SIGNEDSTATE_MISSING) {
|
|
|
|
this._notifyUnsignedAddonsDisabled();
|
|
|
|
break;
|
|
|
|
}
|
2015-08-05 21:37:58 +03:00
|
|
|
}
|
2015-08-21 00:25:22 +03:00
|
|
|
});
|
|
|
|
}
|
2015-08-05 21:37:58 +03:00
|
|
|
|
2012-03-07 02:28:53 +04:00
|
|
|
// Perform default browser checking.
|
2014-08-12 11:59:11 +04:00
|
|
|
if (ShellService) {
|
2016-01-22 23:48:20 +03:00
|
|
|
let shouldCheck = AppConstants.DEBUG ? false :
|
|
|
|
ShellService.shouldCheckDefaultBrowser;
|
2016-12-21 22:23:18 +03:00
|
|
|
|
|
|
|
const skipDefaultBrowserCheck =
|
|
|
|
Services.prefs.getBoolPref("browser.shell.skipDefaultBrowserCheckOnFirstRun") &&
|
|
|
|
Services.prefs.getBoolPref("browser.shell.skipDefaultBrowserCheck");
|
|
|
|
|
|
|
|
const usePromptLimit = !AppConstants.RELEASE_OR_BETA;
|
|
|
|
let promptCount =
|
|
|
|
usePromptLimit ? Services.prefs.getIntPref("browser.shell.defaultBrowserCheckCount") : 0;
|
|
|
|
|
2012-03-21 23:05:23 +04:00
|
|
|
let willRecoverSession = false;
|
2012-03-07 02:28:53 +04:00
|
|
|
try {
|
2012-03-21 23:05:23 +04:00
|
|
|
let ss = Cc["@mozilla.org/browser/sessionstartup;1"].
|
2012-03-07 02:28:53 +04:00
|
|
|
getService(Ci.nsISessionStartup);
|
|
|
|
willRecoverSession =
|
|
|
|
(ss.sessionType == Ci.nsISessionStartup.RECOVER_SESSION);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (ex) { /* never mind; suppose SessionStore is broken */ }
|
2013-05-30 21:32:17 +04:00
|
|
|
|
2014-08-12 11:59:11 +04:00
|
|
|
// startup check, check all assoc
|
2015-09-01 22:52:05 +03:00
|
|
|
let isDefault = false;
|
|
|
|
let isDefaultError = false;
|
|
|
|
try {
|
|
|
|
isDefault = ShellService.isDefaultBrowser(true, false);
|
|
|
|
} catch (ex) {
|
|
|
|
isDefaultError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDefault) {
|
|
|
|
let now = (Math.floor(Date.now() / 1000)).toString();
|
|
|
|
Services.prefs.setCharPref("browser.shell.mostRecentDateSetAsDefault", now);
|
|
|
|
}
|
|
|
|
|
|
|
|
let willPrompt = shouldCheck && !isDefault && !willRecoverSession;
|
|
|
|
|
2015-11-18 19:37:29 +03:00
|
|
|
// Skip the "Set Default Browser" check during first-run or after the
|
|
|
|
// browser has been run a few times.
|
|
|
|
if (willPrompt) {
|
|
|
|
if (skipDefaultBrowserCheck) {
|
|
|
|
Services.prefs.setBoolPref("browser.shell.skipDefaultBrowserCheck", false);
|
|
|
|
willPrompt = false;
|
|
|
|
} else {
|
|
|
|
promptCount++;
|
|
|
|
}
|
2016-12-21 22:23:18 +03:00
|
|
|
if (usePromptLimit && promptCount > 3) {
|
2015-11-18 19:37:29 +03:00
|
|
|
willPrompt = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 22:23:18 +03:00
|
|
|
if (usePromptLimit && willPrompt) {
|
|
|
|
Services.prefs.setIntPref("browser.shell.defaultBrowserCheckCount", promptCount);
|
2015-11-18 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
2013-05-30 21:32:17 +04:00
|
|
|
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);
|
2015-09-01 22:52:05 +03:00
|
|
|
Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT_ERROR")
|
|
|
|
.add(isDefaultError);
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_ALWAYS_CHECK")
|
|
|
|
.add(shouldCheck);
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_DIALOG_PROMPT_RAWCOUNT")
|
|
|
|
.add(promptCount);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (ex) { /* Don't break the default prompt if telemetry is broken. */ }
|
2013-05-30 21:32:17 +04:00
|
|
|
|
2015-09-01 22:52:05 +03:00
|
|
|
if (willPrompt) {
|
2012-03-07 02:28:53 +04:00
|
|
|
Services.tm.mainThread.dispatch(function() {
|
2015-05-24 14:05:00 +03:00
|
|
|
DefaultBrowserCheck.prompt(RecentWindow.getMostRecentBrowserWindow());
|
2017-01-06 00:43:29 +03:00
|
|
|
}, Ci.nsIThread.DISPATCH_NORMAL);
|
2012-03-07 02:28:53 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-11 02:06:19 +04:00
|
|
|
|
2016-07-27 20:51:40 +03:00
|
|
|
E10SAccessibilityCheck.onWindowsRestored();
|
2008-03-08 03:16:38 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_createExtraDefaultProfile() {
|
2016-01-22 23:48:20 +03:00
|
|
|
if (!AppConstants.MOZ_DEV_EDITION) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-05 21:21:42 +03:00
|
|
|
// If Developer Edition is the only installed Firefox version and no other
|
|
|
|
// profiles are present, create a second one for use by other versions.
|
|
|
|
// This helps Firefox versions earlier than 35 avoid accidentally using the
|
|
|
|
// unsuitable Developer Edition profile.
|
|
|
|
let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]
|
|
|
|
.getService(Ci.nsIToolkitProfileService);
|
|
|
|
let profileCount = profileService.profileCount;
|
|
|
|
if (profileCount == 1 && profileService.selectedProfile.name != "default") {
|
|
|
|
let newProfile;
|
|
|
|
try {
|
|
|
|
newProfile = profileService.createProfile(null, "default");
|
|
|
|
profileService.defaultProfile = newProfile;
|
|
|
|
profileService.flush();
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("Could not create profile 'default': " + e);
|
|
|
|
}
|
|
|
|
if (newProfile) {
|
|
|
|
// We don't want a default profile with Developer Edition settings, an
|
|
|
|
// empty profile directory will do. The profile service of the other
|
|
|
|
// Firefox will populate it with its own stuff.
|
|
|
|
let newProfilePath = newProfile.rootDir.path;
|
|
|
|
OS.File.removeDir(newProfilePath).then(() => {
|
|
|
|
return OS.File.makeDir(newProfilePath);
|
|
|
|
}).then(null, e => {
|
|
|
|
Cu.reportError("Could not empty profile 'default': " + e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {
|
2008-01-30 00:16:02 +03:00
|
|
|
// If user has already dismissed quit request, then do nothing
|
|
|
|
if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
|
|
|
|
return;
|
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
// There are several cases where we won't show a dialog here:
|
|
|
|
// 1. There is only 1 tab open in 1 window
|
|
|
|
// 2. The session will be restored at startup, indicated by
|
|
|
|
// browser.startup.page == 3 or browser.sessionstore.resume_session_once == true
|
|
|
|
// 3. browser.warnOnQuit == false
|
|
|
|
// 4. The browser is currently in Private Browsing mode
|
2012-12-28 23:41:13 +04:00
|
|
|
// 5. The browser will be restarted.
|
2011-02-08 04:50:37 +03: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 23:41:13 +04:00
|
|
|
// 2. aQuitType == "lastwindow" && browser.tabs.warnOnClose == true
|
2011-02-08 04:50:37 +03: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 23:41:13 +04:00
|
|
|
if (aQuitType == "restart")
|
|
|
|
return;
|
|
|
|
|
2007-06-15 22:01:25 +04:00
|
|
|
var windowcount = 0;
|
2008-05-10 19:52:32 +04:00
|
|
|
var pagecount = 0;
|
2010-04-12 18:33:10 +04:00
|
|
|
var browserEnum = Services.wm.getEnumerator("navigator:browser");
|
2012-06-29 01:22:41 +04:00
|
|
|
let allWindowsPrivate = true;
|
2008-05-10 19:52:32 +04:00
|
|
|
while (browserEnum.hasMoreElements()) {
|
2013-09-14 01:29:51 +04:00
|
|
|
// XXXbz should we skip closed windows here?
|
2008-05-10 19:52:32 +04:00
|
|
|
windowcount++;
|
|
|
|
|
|
|
|
var browser = browserEnum.getNext();
|
2012-10-06 03:25:52 +04:00
|
|
|
if (!PrivateBrowsingUtils.isWindowPrivate(browser))
|
2012-06-29 01:22:41 +04:00
|
|
|
allWindowsPrivate = false;
|
2008-05-10 19:52:32 +04:00
|
|
|
var tabbrowser = browser.document.getElementById("content");
|
|
|
|
if (tabbrowser)
|
2010-08-13 16:40:19 +04:00
|
|
|
pagecount += tabbrowser.browsers.length - tabbrowser._numPinnedTabs;
|
2008-05-10 19:52:32 +04:00
|
|
|
}
|
2007-06-15 22:01:25 +04:00
|
|
|
|
|
|
|
this._saveSession = false;
|
2008-05-10 19:52:32 +04:00
|
|
|
if (pagecount < 2)
|
|
|
|
return;
|
2007-06-15 22:01:25 +04:00
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
if (!aQuitType)
|
2007-07-26 01:43:17 +04:00
|
|
|
aQuitType = "quit";
|
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
// 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;
|
|
|
|
|
2014-08-08 18:04:45 +04:00
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
|
2011-02-08 04:50:37 +03:00
|
|
|
// On last window close or quit && showQuitWarning, we want to show the
|
|
|
|
// quit warning.
|
2012-12-28 23:41:13 +04: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.
|
2014-08-08 18:04:45 +04:00
|
|
|
aCancelQuit.data =
|
|
|
|
!win.gBrowser.warnAboutClosingTabs(win.gBrowser.closingTabsEnum.ALL);
|
2012-12-28 23:41:13 +04:00
|
|
|
}
|
2011-02-08 04:50:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-08 18:04:45 +04:00
|
|
|
let prompt = Services.prompt;
|
2014-08-08 18:04:45 +04:00
|
|
|
let quitBundle = Services.strings.createBundle("chrome://browser/locale/quitDialog.properties");
|
2015-04-01 02:00:45 +03:00
|
|
|
let appName = gBrandBundle.GetStringFromName("brandShortName");
|
2014-08-08 18:04:45 +04:00
|
|
|
let quitDialogTitle = quitBundle.formatStringFromName("quitDialogTitle",
|
|
|
|
[appName], 1);
|
2014-08-08 18:04:45 +04:00
|
|
|
let neverAskText = quitBundle.GetStringFromName("neverAsk2");
|
|
|
|
let neverAsk = {value: false};
|
|
|
|
|
|
|
|
let choice;
|
|
|
|
if (allWindowsPrivate) {
|
|
|
|
let text = quitBundle.formatStringFromName("messagePrivate", [appName], 1);
|
|
|
|
let flags = prompt.BUTTON_TITLE_IS_STRING * prompt.BUTTON_POS_0 +
|
|
|
|
prompt.BUTTON_TITLE_IS_STRING * prompt.BUTTON_POS_1 +
|
|
|
|
prompt.BUTTON_POS_0_DEFAULT;
|
|
|
|
choice = prompt.confirmEx(win, quitDialogTitle, text, flags,
|
|
|
|
quitBundle.GetStringFromName("quitTitle"),
|
|
|
|
quitBundle.GetStringFromName("cancelTitle"),
|
|
|
|
null,
|
|
|
|
neverAskText, neverAsk);
|
|
|
|
|
|
|
|
// The order of the buttons differs between the prompt.confirmEx calls
|
|
|
|
// here so we need to fix this for proper handling below.
|
|
|
|
if (choice == 0) {
|
|
|
|
choice = 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let text = quitBundle.formatStringFromName(
|
|
|
|
windowcount == 1 ? "messageNoWindows" : "message", [appName], 1);
|
|
|
|
let flags = prompt.BUTTON_TITLE_IS_STRING * prompt.BUTTON_POS_0 +
|
|
|
|
prompt.BUTTON_TITLE_IS_STRING * prompt.BUTTON_POS_1 +
|
|
|
|
prompt.BUTTON_TITLE_IS_STRING * prompt.BUTTON_POS_2 +
|
|
|
|
prompt.BUTTON_POS_0_DEFAULT;
|
|
|
|
choice = prompt.confirmEx(win, quitDialogTitle, text, flags,
|
|
|
|
quitBundle.GetStringFromName("saveTitle"),
|
|
|
|
quitBundle.GetStringFromName("cancelTitle"),
|
|
|
|
quitBundle.GetStringFromName("quitTitle"),
|
|
|
|
neverAskText, neverAsk);
|
|
|
|
}
|
2008-05-08 19:08:40 +04:00
|
|
|
|
2014-08-08 18:04:45 +04:00
|
|
|
switch (choice) {
|
2008-05-08 19:08:40 +04:00
|
|
|
case 2: // Quit
|
|
|
|
if (neverAsk.value)
|
2011-02-08 04:50:37 +03:00
|
|
|
Services.prefs.setBoolPref("browser.showQuitWarning", false);
|
2008-05-08 19:08:40 +04:00
|
|
|
break;
|
|
|
|
case 1: // Cancel
|
|
|
|
aCancelQuit.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
aCancelQuit.data = true;
|
|
|
|
break;
|
|
|
|
case 0: // Save & Quit
|
|
|
|
this._saveSession = true;
|
|
|
|
if (neverAsk.value) {
|
2012-12-28 23:41:13 +04:00
|
|
|
// always save state when shutting down
|
|
|
|
Services.prefs.setIntPref("browser.startup.page", 3);
|
2007-06-15 22:01:25 +04:00
|
|
|
}
|
2008-05-08 19:08:40 +04:00
|
|
|
break;
|
2007-06-15 22:01:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-04-07 06:49:23 +04:00
|
|
|
_showUpdateNotification: function BG__showUpdateNotification() {
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.clearUserPref("app.update.postupdate");
|
2010-04-07 06:49:23 +04:00
|
|
|
|
|
|
|
var um = Cc["@mozilla.org/updates/update-manager;1"].
|
|
|
|
getService(Ci.nsIUpdateManager);
|
|
|
|
try {
|
|
|
|
// If the updates.xml file is deleted then getUpdateAt will throw.
|
|
|
|
var update = um.getUpdateAt(0).QueryInterface(Ci.nsIPropertyBag);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2010-04-07 06:49:23 +04:00
|
|
|
// 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);
|
2015-04-01 02:00:45 +03:00
|
|
|
var appName = gBrandBundle.GetStringFromName("brandShortName");
|
2010-04-07 06:49:23 +04:00
|
|
|
|
|
|
|
function getNotifyString(aPropData) {
|
|
|
|
var propValue = update.getProperty(aPropData.propName);
|
|
|
|
if (!propValue) {
|
|
|
|
if (aPropData.prefName)
|
|
|
|
propValue = formatter.formatURLPref(aPropData.prefName);
|
|
|
|
else if (aPropData.stringParams)
|
2015-04-01 02:00:45 +03:00
|
|
|
propValue = gBrowserBundle.formatStringFromName(aPropData.stringName,
|
|
|
|
aPropData.stringParams,
|
|
|
|
aPropData.stringParams.length);
|
2010-04-07 06:49:23 +04:00
|
|
|
else
|
2015-04-01 02:00:45 +03:00
|
|
|
propValue = gBrowserBundle.GetStringFromName(aPropData.stringName);
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
|
|
|
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"});
|
|
|
|
|
2015-05-24 14:05:00 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2015-05-19 13:29:40 +03:00
|
|
|
let notifyBox = win.document.getElementById("high-priority-global-notificationbox");
|
2010-04-07 06:49:23 +04:00
|
|
|
|
|
|
|
let buttons = [
|
|
|
|
{
|
2016-12-30 02:34:54 +03:00
|
|
|
label,
|
2010-04-07 06:49:23 +04:00
|
|
|
accessKey: key,
|
|
|
|
popup: null,
|
2016-12-30 02:34:54 +03:00
|
|
|
callback(aNotificationBar, aButton) {
|
2012-12-01 08:11:44 +04:00
|
|
|
win.openUILinkIn(url, "tab");
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-11-03 14:51:48 +03:00
|
|
|
notifyBox.appendNotification(text, "post-update-notification",
|
|
|
|
null, notifyBox.PRIORITY_INFO_LOW,
|
|
|
|
buttons);
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (actions.indexOf("showAlert") == -1)
|
|
|
|
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"});
|
|
|
|
|
|
|
|
function clickCallback(subject, topic, data) {
|
|
|
|
// This callback will be called twice but only once with this topic
|
|
|
|
if (topic != "alertclickcallback")
|
|
|
|
return;
|
2015-05-24 14:05:00 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2012-12-01 08:11:44 +04:00
|
|
|
win.openUILinkIn(data, "tab");
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// This will throw NS_ERROR_NOT_AVAILABLE if the notification cannot
|
|
|
|
// be displayed per the idl.
|
2015-10-29 18:42:01 +03:00
|
|
|
AlertsService.showAlertNotification(null, title, text,
|
|
|
|
true, url, clickCallback);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2015-10-29 18:42:01 +03:00
|
|
|
Cu.reportError(e);
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-05-03 12:56:41 +04:00
|
|
|
/**
|
|
|
|
* Initialize Places
|
2008-11-12 23:45:53 +03:00
|
|
|
* - imports the bookmarks html file if bookmarks database is empty, try to
|
|
|
|
* restore bookmarks from a JSON backup if the backend indicates that the
|
|
|
|
* database was corrupt.
|
|
|
|
*
|
|
|
|
* These prefs can be set up by the frontend:
|
|
|
|
*
|
|
|
|
* WARNING: setting these preferences to true will overwite existing bookmarks
|
2008-03-28 19:43:17 +03:00
|
|
|
*
|
|
|
|
* - browser.places.importBookmarksHTML
|
2008-11-12 23:45:53 +03:00
|
|
|
* Set to true will import the bookmarks.html file from the profile folder.
|
2008-04-08 22:42:53 +04:00
|
|
|
* - browser.places.smartBookmarksVersion
|
|
|
|
* Set during HTML import to indicate that Smart Bookmarks were created.
|
|
|
|
* Set to -1 to disable Smart Bookmarks creation.
|
|
|
|
* Set to 0 to restore current Smart Bookmarks.
|
2008-04-02 23:33:01 +04:00
|
|
|
* - browser.bookmarks.restore_default_bookmarks
|
|
|
|
* Set to true by safe-mode dialog to indicate we must restore default
|
|
|
|
* bookmarks.
|
2007-05-03 12:56:41 +04:00
|
|
|
*/
|
2012-05-28 13:43:59 +04:00
|
|
|
_initPlaces: function BG__initPlaces(aInitialMigrationPerformed) {
|
2008-11-12 23:45:53 +03:00
|
|
|
// We must instantiate the history service since it will tell us if we
|
|
|
|
// need to import or restore bookmarks due to first-run, corruption or
|
|
|
|
// forced migration (due to a major schema change).
|
|
|
|
// If the database is corrupt or has been newly created we should
|
|
|
|
// import bookmarks.
|
2014-03-03 20:51:42 +04:00
|
|
|
let dbStatus = PlacesUtils.history.databaseStatus;
|
|
|
|
let importBookmarks = !aInitialMigrationPerformed &&
|
2012-03-23 11:15:36 +04:00
|
|
|
(dbStatus == PlacesUtils.history.DATABASE_STATUS_CREATE ||
|
|
|
|
dbStatus == PlacesUtils.history.DATABASE_STATUS_CORRUPT);
|
2009-02-09 21:16:02 +03:00
|
|
|
|
2008-11-12 23:45:53 +03:00
|
|
|
// Check if user or an extension has required to import bookmarks.html
|
2014-03-03 20:51:42 +04:00
|
|
|
let importBookmarksHTML = false;
|
2008-11-12 23:45:53 +03:00
|
|
|
try {
|
|
|
|
importBookmarksHTML =
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.getBoolPref("browser.places.importBookmarksHTML");
|
2008-11-12 23:45:53 +03:00
|
|
|
if (importBookmarksHTML)
|
|
|
|
importBookmarks = true;
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (ex) {}
|
2007-12-04 11:08:33 +03:00
|
|
|
|
2014-03-25 20:25:58 +04:00
|
|
|
// Support legacy bookmarks.html format for apps that depend on that format.
|
|
|
|
let autoExportHTML = false;
|
|
|
|
try {
|
|
|
|
autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
|
|
|
} catch (ex) {} // Do not export.
|
|
|
|
if (autoExportHTML) {
|
|
|
|
// Sqlite.jsm and Places shutdown happen at profile-before-change, thus,
|
|
|
|
// to be on the safe side, this should run earlier.
|
|
|
|
AsyncShutdown.profileChangeTeardown.addBlocker(
|
|
|
|
"Places: export bookmarks.html",
|
|
|
|
() => BookmarkHTMLUtils.exportToFile(BookmarkHTMLUtils.defaultPath));
|
|
|
|
}
|
|
|
|
|
2015-03-20 11:39:25 +03:00
|
|
|
Task.spawn(function* () {
|
2013-04-09 12:23:40 +04:00
|
|
|
// Check if Safe Mode or the user has required to restore bookmarks from
|
|
|
|
// default profile's bookmarks.html
|
2014-03-03 20:51:42 +04:00
|
|
|
let restoreDefaultBookmarks = false;
|
2013-04-09 12:23:40 +04: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-07 10:52:08 +04:00
|
|
|
yield this._backupBookmarks();
|
2013-04-09 12:23:40 +04:00
|
|
|
importBookmarks = true;
|
|
|
|
}
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (ex) {}
|
2013-04-09 12:23:40 +04:00
|
|
|
|
2014-02-04 17:43:20 +04:00
|
|
|
// This may be reused later, check for "=== undefined" to see if it has
|
|
|
|
// been populated already.
|
|
|
|
let lastBackupFile;
|
|
|
|
|
2013-04-09 12:23:40 +04: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-05-21 10:39:00 +04:00
|
|
|
lastBackupFile = yield PlacesBackups.getMostRecentBackup();
|
2014-02-04 17:43:20 +04:00
|
|
|
if (lastBackupFile) {
|
2013-04-09 12:23:40 +04:00
|
|
|
// restore from JSON backup
|
2014-02-04 17:43:20 +04:00
|
|
|
yield BookmarkJSONUtils.importFromFile(lastBackupFile, true);
|
2013-04-09 12:23:40 +04:00
|
|
|
importBookmarks = false;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2013-04-09 12:23:40 +04:00
|
|
|
// We have created a new database but we don't have any backup available
|
|
|
|
importBookmarks = true;
|
2014-03-03 20:51:42 +04:00
|
|
|
if (yield OS.File.exists(BookmarkHTMLUtils.defaultPath)) {
|
2013-04-09 12:23:40 +04:00
|
|
|
// If bookmarks.html is available in current profile import it...
|
|
|
|
importBookmarksHTML = true;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2013-04-09 12:23:40 +04:00
|
|
|
// ...otherwise we will restore defaults
|
|
|
|
restoreDefaultBookmarks = true;
|
|
|
|
}
|
|
|
|
}
|
2008-11-12 23:45:53 +03:00
|
|
|
}
|
2007-12-04 14:22:14 +03:00
|
|
|
|
2013-04-09 12:23:40 +04: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.
|
2016-10-13 19:02:29 +03:00
|
|
|
try {
|
|
|
|
yield this._distributionCustomizer.applyBookmarks();
|
|
|
|
yield this.ensurePlacesDefaultQueriesInitialized();
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2013-04-09 12:23:40 +04: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 20:51:42 +04:00
|
|
|
let smartBookmarksVersion = 0;
|
2013-04-09 12:23:40 +04:00
|
|
|
try {
|
|
|
|
smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion");
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (ex) {}
|
2013-04-09 12:23:40 +04:00
|
|
|
if (!autoExportHTML && smartBookmarksVersion != -1)
|
|
|
|
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
|
|
|
|
2014-03-03 20:51:42 +04:00
|
|
|
let bookmarksUrl = null;
|
2013-04-09 12:23:40 +04:00
|
|
|
if (restoreDefaultBookmarks) {
|
|
|
|
// User wants to restore bookmarks.html file from default profile folder
|
2015-12-25 03:41:44 +03:00
|
|
|
bookmarksUrl = "chrome://browser/locale/bookmarks.html";
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (yield OS.File.exists(BookmarkHTMLUtils.defaultPath)) {
|
2014-03-03 20:51:42 +04:00
|
|
|
bookmarksUrl = OS.Path.toFileURI(BookmarkHTMLUtils.defaultPath);
|
2008-12-09 23:39:32 +03:00
|
|
|
}
|
2008-11-12 23:45:53 +03:00
|
|
|
|
2014-03-03 20:51:42 +04:00
|
|
|
if (bookmarksUrl) {
|
2013-04-09 12:23:40 +04:00
|
|
|
// Import from bookmarks.html file.
|
|
|
|
try {
|
2015-03-20 11:39:25 +03:00
|
|
|
yield BookmarkHTMLUtils.importFromURL(bookmarksUrl, true);
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("Bookmarks.html file could be corrupt. " + e);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// Now apply distribution customized bookmarks.
|
|
|
|
// This should always run after Places initialization.
|
2015-03-16 14:51:02 +03:00
|
|
|
yield this._distributionCustomizer.applyBookmarks();
|
2015-03-20 11:39:25 +03:00
|
|
|
// Ensure that smart bookmarks are created once the operation is
|
|
|
|
// complete.
|
2015-04-01 20:09:26 +03:00
|
|
|
yield this.ensurePlacesDefaultQueriesInitialized();
|
2015-03-20 11:39:25 +03:00
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError(e);
|
2013-04-09 12:23:40 +04:00
|
|
|
}
|
2015-03-20 11:39:25 +03:00
|
|
|
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2016-10-13 19:02:29 +03:00
|
|
|
Cu.reportError(new Error("Unable to find bookmarks.html file."));
|
2013-04-09 12:23:40 +04:00
|
|
|
}
|
2008-11-12 23:45:53 +03:00
|
|
|
|
2013-04-09 12:23:40 +04: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 12:56:41 +04:00
|
|
|
}
|
2008-11-18 20:25:39 +03:00
|
|
|
|
2013-04-09 12:23:40 +04:00
|
|
|
// Initialize bookmark archiving on idle.
|
2014-02-04 17:43:20 +04: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;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2014-02-04 17:43:20 +04:00
|
|
|
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) {
|
2016-10-13 19:02:29 +03:00
|
|
|
Cu.reportError(new Error("Unable to report telemetry."));
|
2014-02-04 17:43:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (backupAge > BOOKMARKS_BACKUP_MAX_INTERVAL_DAYS)
|
|
|
|
this._bookmarksBackupIdleTime /= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._idleService.addIdleObserver(this, this._bookmarksBackupIdleTime);
|
2012-03-23 11:15:36 +04:00
|
|
|
}
|
2013-04-17 09:36:02 +04:00
|
|
|
|
2016-10-13 19:02:29 +03:00
|
|
|
}.bind(this)).catch(ex => {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}).then(() => {
|
|
|
|
// NB: deliberately after the catch so that we always do this, even if
|
|
|
|
// we threw halfway through initializing in the Task above.
|
2013-04-17 09:36:02 +04:00
|
|
|
Services.obs.notifyObservers(null, "places-browser-init-complete", "");
|
2016-10-13 19:02:29 +03:00
|
|
|
});
|
2007-05-03 12:56:41 +04:00
|
|
|
},
|
|
|
|
|
2013-04-09 12:23:40 +04:00
|
|
|
/**
|
2014-02-04 17:43:20 +04:00
|
|
|
* If a backup for today doesn't exist, this creates one.
|
2013-04-09 12:23:40 +04:00
|
|
|
*/
|
|
|
|
_backupBookmarks: function BG__backupBookmarks() {
|
2016-01-22 23:48:20 +03:00
|
|
|
return Task.spawn(function*() {
|
2013-10-07 10:52:08 +04: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 17:43:20 +04: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-07 10:52:08 +04:00
|
|
|
}
|
2013-04-09 12:23:40 +04:00
|
|
|
});
|
2007-05-03 12:56:41 +04:00
|
|
|
},
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2008-12-30 15:44:55 +03:00
|
|
|
/**
|
|
|
|
* Show the notificationBox for a locked places database.
|
|
|
|
*/
|
2009-12-18 00:28:08 +03:00
|
|
|
_showPlacesLockedNotificationBox: function BG__showPlacesLockedNotificationBox() {
|
2015-04-01 02:00:45 +03:00
|
|
|
var applicationName = gBrandBundle.GetStringFromName("brandShortName");
|
2010-04-12 18:33:10 +04:00
|
|
|
var placesBundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");
|
2008-12-30 15:44:55 +03:00
|
|
|
var title = placesBundle.GetStringFromName("lockPrompt.title");
|
|
|
|
var text = placesBundle.formatStringFromName("lockPrompt.text", [applicationName], 1);
|
|
|
|
var buttonText = placesBundle.GetStringFromName("lockPromptInfoButton.label");
|
|
|
|
var accessKey = placesBundle.GetStringFromName("lockPromptInfoButton.accessKey");
|
|
|
|
|
|
|
|
var helpTopic = "places-locked";
|
|
|
|
var url = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
|
|
|
|
getService(Components.interfaces.nsIURLFormatter).
|
|
|
|
formatURLPref("app.support.baseURL");
|
|
|
|
url += helpTopic;
|
|
|
|
|
2015-05-24 14:05:00 +03:00
|
|
|
var win = RecentWindow.getMostRecentBrowserWindow();
|
2008-12-30 15:44:55 +03:00
|
|
|
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: buttonText,
|
2016-12-30 02:34:54 +03:00
|
|
|
accessKey,
|
2008-12-30 15:44:55 +03:00
|
|
|
popup: null,
|
2016-12-30 02:34:54 +03:00
|
|
|
callback(aNotificationBar, aButton) {
|
2012-12-01 08:11:44 +04:00
|
|
|
win.openUILinkIn(url, "tab");
|
2008-12-30 15:44:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2012-12-01 08:11:44 +04:00
|
|
|
var notifyBox = win.gBrowser.getNotificationBox();
|
2011-11-05 01:45:01 +04:00
|
|
|
var notification = notifyBox.appendNotification(text, title, null,
|
|
|
|
notifyBox.PRIORITY_CRITICAL_MEDIUM,
|
|
|
|
buttons);
|
|
|
|
notification.persistence = -1; // Until user closes it
|
2008-12-30 15:44:55 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_showSyncStartedDoorhanger() {
|
2016-06-02 20:36:53 +03:00
|
|
|
let bundle = Services.strings.createBundle("chrome://browser/locale/accounts.properties");
|
2016-07-16 04:40:05 +03:00
|
|
|
let productName = gBrandBundle.GetStringFromName("brandShortName");
|
2016-06-02 20:36:53 +03:00
|
|
|
let title = bundle.GetStringFromName("syncStartNotification.title");
|
2016-07-16 04:40:05 +03:00
|
|
|
let body = bundle.formatStringFromName("syncStartNotification.body2",
|
|
|
|
[productName], 1);
|
2016-06-02 20:36:53 +03:00
|
|
|
|
|
|
|
let clickCallback = (subject, topic, data) => {
|
|
|
|
if (topic != "alertclickcallback")
|
|
|
|
return;
|
|
|
|
this._openPreferences("sync");
|
|
|
|
}
|
|
|
|
AlertsService.showAlertNotification(null, title, body, true, null, clickCallback);
|
|
|
|
},
|
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
_migrateUI: function BG__migrateUI() {
|
2017-01-13 22:53:58 +03:00
|
|
|
const UI_VERSION = 43;
|
2014-08-19 18:31:00 +04:00
|
|
|
const BROWSER_DOCURL = "chrome://browser/content/browser.xul";
|
2016-02-20 16:04:03 +03:00
|
|
|
|
|
|
|
let currentUIVersion;
|
2016-02-20 17:15:01 +03:00
|
|
|
if (Services.prefs.prefHasUserValue("browser.migration.version")) {
|
2013-11-04 18:11:44 +04:00
|
|
|
currentUIVersion = Services.prefs.getIntPref("browser.migration.version");
|
2016-02-20 16:04:03 +03:00
|
|
|
} else {
|
|
|
|
// This is a new profile, nothing to migrate.
|
|
|
|
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-05 13:23:40 +04:00
|
|
|
if (currentUIVersion >= UI_VERSION)
|
2013-11-04 18:11:44 +04:00
|
|
|
return;
|
|
|
|
|
2014-08-19 18:31:00 +04:00
|
|
|
let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
|
2008-02-04 22:37:26 +03:00
|
|
|
|
2013-01-15 19:47:58 +04:00
|
|
|
if (currentUIVersion < 9) {
|
2012-08-25 13:37:55 +04:00
|
|
|
// This code adds the customizable downloads buttons.
|
2014-08-19 18:31:00 +04:00
|
|
|
let currentset = xulStore.getValue(BROWSER_DOCURL, "nav-bar", "currentset");
|
2012-08-25 13:37:55 +04:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2014-08-19 18:31:00 +04:00
|
|
|
xulStore.setValue(BROWSER_DOCURL, "nav-bar", "currentset", currentset);
|
2012-08-25 13:37:55 +04:00
|
|
|
}
|
2012-09-27 16:57:39 +04:00
|
|
|
}
|
|
|
|
|
2016-01-22 23:48:20 +03:00
|
|
|
if (AppConstants.platform == "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);
|
|
|
|
}
|
2013-04-10 01:07:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-08 21:09:51 +04: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-07-04 01:41:25 +04: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-07-05 02:49:58 +04:00
|
|
|
if (currentUIVersion < 16) {
|
2015-08-18 21:27:01 +03:00
|
|
|
xulStore.removeValue(BROWSER_DOCURL, "nav-bar", "collapsed");
|
2013-05-14 20:15:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-07 22:46:53 +04:00
|
|
|
// Insert the bookmarks-menu-button into the nav-bar if it isn't already
|
|
|
|
// there.
|
2013-07-05 02:49:58 +04:00
|
|
|
if (currentUIVersion < 17) {
|
2014-08-19 18:31:00 +04:00
|
|
|
let currentset = xulStore.getValue(BROWSER_DOCURL, "nav-bar", "currentset");
|
2013-06-07 22:46:53 +04:00
|
|
|
// Need to migrate only if toolbar is customized.
|
|
|
|
if (currentset) {
|
2015-04-29 18:32:05 +03:00
|
|
|
if (!currentset.includes("bookmarks-menu-button")) {
|
2013-06-07 22:46:53 +04:00
|
|
|
// The button isn't in the nav-bar, so let's look for an appropriate
|
|
|
|
// place to put it.
|
2016-06-17 12:43:26 +03:00
|
|
|
if (currentset.includes("bookmarks-menu-button-container")) {
|
|
|
|
currentset = currentset.replace(/(^|,)bookmarks-menu-button-container($|,)/,
|
|
|
|
"$1bookmarks-menu-button$2");
|
|
|
|
} else if (currentset.includes("downloads-button")) {
|
2013-06-07 22:46:53 +04:00
|
|
|
currentset = currentset.replace(/(^|,)downloads-button($|,)/,
|
|
|
|
"$1bookmarks-menu-button,downloads-button$2");
|
2015-04-29 18:32:05 +03:00
|
|
|
} else if (currentset.includes("home-button")) {
|
2013-06-07 22:46:53 +04:00
|
|
|
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")
|
|
|
|
}
|
2014-08-19 18:31:00 +04:00
|
|
|
xulStore.setValue(BROWSER_DOCURL, "nav-bar", "currentset", currentset);
|
2013-06-07 22:46:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 23:59:37 +04: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"]) {
|
|
|
|
for (let toolbarId of toolbars) {
|
2014-08-19 18:31:00 +04:00
|
|
|
xulStore.removeValue(BROWSER_DOCURL, toolbarId, resourceName);
|
2013-11-22 23:59:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 20:01:50 +04:00
|
|
|
if (currentUIVersion < 19) {
|
2015-10-12 08:29:12 +03:00
|
|
|
let detector = null;
|
2013-12-19 20:01:50 +04:00
|
|
|
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 15:51:55 +04:00
|
|
|
if (currentUIVersion < 20) {
|
|
|
|
// Remove persisted collapsed state from TabsToolbar.
|
2014-08-19 18:31:00 +04:00
|
|
|
xulStore.removeValue(BROWSER_DOCURL, "TabsToolbar", "collapsed");
|
2014-02-21 15:51:55 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 03:02:19 +04:00
|
|
|
if (currentUIVersion < 23) {
|
|
|
|
const kSelectedEnginePref = "browser.search.selectedEngine";
|
|
|
|
if (Services.prefs.prefHasUserValue(kSelectedEnginePref)) {
|
|
|
|
try {
|
|
|
|
let name = Services.prefs.getComplexValue(kSelectedEnginePref,
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
|
|
|
Services.search.currentEngine = Services.search.getEngineByName(name);
|
|
|
|
} catch (ex) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-18 16:39:34 +04:00
|
|
|
if (currentUIVersion < 24) {
|
|
|
|
// Reset homepage pref for users who have it set to start.mozilla.org
|
|
|
|
// or google.com/firefox.
|
|
|
|
const HOMEPAGE_PREF = "browser.startup.homepage";
|
2014-10-24 14:56:08 +04:00
|
|
|
if (Services.prefs.prefHasUserValue(HOMEPAGE_PREF)) {
|
|
|
|
const DEFAULT =
|
|
|
|
Services.prefs.getDefaultBranch(HOMEPAGE_PREF)
|
|
|
|
.getComplexValue("", Ci.nsIPrefLocalizedString).data;
|
|
|
|
let value =
|
|
|
|
Services.prefs.getComplexValue(HOMEPAGE_PREF, Ci.nsISupportsString);
|
|
|
|
let updated =
|
|
|
|
value.data.replace(/https?:\/\/start\.mozilla\.org[^|]*/i, DEFAULT)
|
|
|
|
.replace(/https?:\/\/(www\.)?google\.[a-z.]+\/firefox[^|]*/i,
|
|
|
|
DEFAULT);
|
|
|
|
if (updated != value.data) {
|
|
|
|
if (updated == DEFAULT) {
|
|
|
|
Services.prefs.clearUserPref(HOMEPAGE_PREF);
|
|
|
|
} else {
|
|
|
|
value.data = updated;
|
|
|
|
Services.prefs.setComplexValue(HOMEPAGE_PREF,
|
|
|
|
Ci.nsISupportsString, value);
|
|
|
|
}
|
|
|
|
}
|
2014-10-18 16:39:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 21:26:16 +04:00
|
|
|
if (currentUIVersion < 25) {
|
|
|
|
// Make sure the doNotTrack value conforms to the conversion from
|
|
|
|
// three-state to two-state. (This reverts a setting of "please track me"
|
|
|
|
// to the default "don't say anything").
|
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("privacy.donottrackheader.enabled") &&
|
|
|
|
Services.prefs.getIntPref("privacy.donottrackheader.value") != 1) {
|
|
|
|
Services.prefs.clearUserPref("privacy.donottrackheader.enabled");
|
|
|
|
Services.prefs.clearUserPref("privacy.donottrackheader.value");
|
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (ex) {}
|
2014-01-28 21:26:16 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 16:16:00 +03:00
|
|
|
if (currentUIVersion < 26) {
|
|
|
|
// Refactor urlbar suggestion preferences to make it extendable and
|
|
|
|
// allow new suggestion types (e.g: search suggestions).
|
|
|
|
let types = ["history", "bookmark", "openpage"];
|
|
|
|
let defaultBehavior = 0;
|
|
|
|
try {
|
|
|
|
defaultBehavior = Services.prefs.getIntPref("browser.urlbar.default.behavior");
|
|
|
|
} catch (ex) {}
|
|
|
|
try {
|
|
|
|
let autocompleteEnabled = Services.prefs.getBoolPref("browser.urlbar.autocomplete.enabled");
|
|
|
|
if (!autocompleteEnabled) {
|
|
|
|
defaultBehavior = -1;
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
// If the default behavior is:
|
|
|
|
// -1 - all new "...suggest.*" preferences will be false
|
|
|
|
// 0 - all new "...suggest.*" preferences will use the default values
|
|
|
|
// > 0 - all new "...suggest.*" preferences will be inherited
|
|
|
|
for (let type of types) {
|
|
|
|
let prefValue = defaultBehavior == 0;
|
|
|
|
if (defaultBehavior > 0) {
|
|
|
|
prefValue = !!(defaultBehavior & Ci.mozIPlacesAutoComplete["BEHAVIOR_" + type.toUpperCase()]);
|
|
|
|
}
|
|
|
|
Services.prefs.setBoolPref("browser.urlbar.suggest." + type, prefValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Typed behavior will be used only for results from history.
|
|
|
|
if (defaultBehavior != -1 &&
|
|
|
|
!!(defaultBehavior & Ci.mozIPlacesAutoComplete["BEHAVIOR_TYPED"])) {
|
|
|
|
Services.prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 02:13:57 +03:00
|
|
|
if (currentUIVersion < 27) {
|
|
|
|
// Fix up document color use:
|
|
|
|
const kOldColorPref = "browser.display.use_document_colors";
|
|
|
|
if (Services.prefs.prefHasUserValue(kOldColorPref) &&
|
|
|
|
!Services.prefs.getBoolPref(kOldColorPref)) {
|
|
|
|
Services.prefs.setIntPref("browser.display.document_color_use", 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 12:29:28 +03:00
|
|
|
if (currentUIVersion < 29) {
|
|
|
|
let group = null;
|
|
|
|
try {
|
|
|
|
group = Services.prefs.getComplexValue("font.language.group",
|
|
|
|
Ci.nsIPrefLocalizedString);
|
|
|
|
} catch (ex) {}
|
|
|
|
if (group &&
|
|
|
|
["tr", "x-baltic", "x-central-euro"].some(g => g == group.data)) {
|
|
|
|
// Latin groups were consolidated.
|
|
|
|
group.data = "x-western";
|
|
|
|
Services.prefs.setComplexValue("font.language.group",
|
|
|
|
Ci.nsIPrefLocalizedString, group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 06:00:32 +03:00
|
|
|
if (currentUIVersion < 30) {
|
|
|
|
// Convert old devedition theme pref to lightweight theme storage
|
|
|
|
let lightweightThemeSelected = false;
|
|
|
|
let selectedThemeID = null;
|
|
|
|
try {
|
|
|
|
lightweightThemeSelected = Services.prefs.prefHasUserValue("lightweightThemes.selectedThemeID");
|
|
|
|
selectedThemeID = Services.prefs.getCharPref("lightweightThemes.selectedThemeID");
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {}
|
2015-04-01 06:00:32 +03:00
|
|
|
|
|
|
|
let defaultThemeSelected = false;
|
|
|
|
try {
|
|
|
|
defaultThemeSelected = Services.prefs.getCharPref("general.skins.selectedSkin") == "classic/1.0";
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {}
|
2015-04-01 06:00:32 +03:00
|
|
|
|
|
|
|
// If we are on the devedition channel, the devedition theme is on by
|
|
|
|
// default. But we need to handle the case where they didn't want it
|
|
|
|
// applied, and unapply the theme.
|
|
|
|
let userChoseToNotUseDeveditionTheme =
|
|
|
|
!defaultThemeSelected ||
|
|
|
|
(lightweightThemeSelected && selectedThemeID != "firefox-devedition@mozilla.org");
|
|
|
|
|
|
|
|
if (userChoseToNotUseDeveditionTheme && selectedThemeID == "firefox-devedition@mozilla.org") {
|
|
|
|
Services.prefs.setCharPref("lightweightThemes.selectedThemeID", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.prefs.clearUserPref("browser.devedition.showCustomizeButton");
|
|
|
|
}
|
2015-10-12 08:29:12 +03:00
|
|
|
|
2015-08-17 16:51:22 +03:00
|
|
|
if (currentUIVersion < 31) {
|
|
|
|
xulStore.removeValue(BROWSER_DOCURL, "bookmarks-menu-button", "class");
|
|
|
|
xulStore.removeValue(BROWSER_DOCURL, "home-button", "class");
|
|
|
|
}
|
2015-04-01 06:00:32 +03:00
|
|
|
|
2015-10-29 18:42:01 +03:00
|
|
|
if (currentUIVersion < 32) {
|
2015-11-03 01:59:52 +03:00
|
|
|
this._notifyNotificationsUpgrade().catch(Cu.reportError);
|
2015-10-29 18:42:01 +03:00
|
|
|
}
|
|
|
|
|
2016-11-01 18:59:11 +03:00
|
|
|
// version 35 migrated tab groups data.
|
2015-11-04 14:53:52 +03:00
|
|
|
|
2016-01-12 22:39:02 +03:00
|
|
|
if (currentUIVersion < 36) {
|
|
|
|
xulStore.removeValue("chrome://passwordmgr/content/passwordManager.xul",
|
|
|
|
"passwordCol",
|
|
|
|
"hidden");
|
|
|
|
}
|
|
|
|
|
2016-04-02 02:30:14 +03:00
|
|
|
if (currentUIVersion < 37) {
|
2016-04-02 00:22:36 +03:00
|
|
|
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
|
|
|
|
}
|
|
|
|
|
2016-04-19 12:28:01 +03:00
|
|
|
if (currentUIVersion < 38) {
|
|
|
|
LoginHelper.removeLegacySignonFiles();
|
|
|
|
}
|
2016-06-11 15:23:35 +03:00
|
|
|
|
|
|
|
if (currentUIVersion < 39) {
|
|
|
|
// Remove the 'defaultset' value for all the toolbars
|
|
|
|
let toolbars = ["nav-bar", "PersonalToolbar",
|
|
|
|
"addon-bar", "TabsToolbar", "toolbar-menubar"];
|
|
|
|
for (let toolbarId of toolbars) {
|
|
|
|
xulStore.removeValue(BROWSER_DOCURL, toolbarId, "defaultset");
|
|
|
|
}
|
|
|
|
}
|
2016-06-23 07:25:32 +03:00
|
|
|
|
|
|
|
if (currentUIVersion < 40) {
|
|
|
|
const kOldSafeBrowsingPref = "browser.safebrowsing.enabled";
|
|
|
|
// Default value is set to true, a user pref means that the pref was
|
|
|
|
// set to false.
|
|
|
|
if (Services.prefs.prefHasUserValue(kOldSafeBrowsingPref) &&
|
|
|
|
!Services.prefs.getBoolPref(kOldSafeBrowsingPref)) {
|
|
|
|
Services.prefs.setBoolPref("browser.safebrowsing.phishing.enabled",
|
|
|
|
false);
|
|
|
|
// Should just remove support for the pref entirely, even if it's
|
|
|
|
// only in about:config
|
|
|
|
Services.prefs.clearUserPref(kOldSafeBrowsingPref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 18:08:55 +03:00
|
|
|
if (currentUIVersion < 41) {
|
|
|
|
const Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
|
|
|
|
Preferences.resetBranch("loop.");
|
|
|
|
}
|
|
|
|
|
2016-11-01 19:12:19 +03:00
|
|
|
if (currentUIVersion < 42) {
|
|
|
|
let backupFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
|
|
|
backupFile.append("tabgroups-session-backup.json");
|
|
|
|
OS.File.remove(backupFile.path, {ignoreAbsent: true}).catch(ex => Cu.reportError(ex));
|
|
|
|
}
|
|
|
|
|
2017-01-13 22:53:58 +03:00
|
|
|
if (currentUIVersion < 43) {
|
|
|
|
let currentTheme = null;
|
|
|
|
try {
|
|
|
|
currentTheme = Services.prefs.getCharPref("lightweightThemes.selectedThemeID");
|
|
|
|
} catch (e) {}
|
|
|
|
if (currentTheme == "firefox-devedition@mozilla.org") {
|
|
|
|
let newTheme = Services.prefs.getCharPref("devtools.theme") == "dark" ?
|
|
|
|
"firefox-compact-dark@mozilla.org" : "firefox-compact-light@mozilla.org";
|
|
|
|
Services.prefs.setCharPref("lightweightThemes.selectedThemeID", newTheme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-09 23:44:01 +04:00
|
|
|
// Update the migration version.
|
|
|
|
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
|
2008-02-04 22:37:26 +03:00
|
|
|
},
|
|
|
|
|
2015-10-29 18:42:01 +03:00
|
|
|
_hasExistingNotificationPermission: function BG__hasExistingNotificationPermission() {
|
|
|
|
let enumerator = Services.perms.enumerator;
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
|
|
|
if (permission.type == "desktop-notification") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-11-03 01:59:52 +03:00
|
|
|
_notifyNotificationsUpgrade: Task.async(function* () {
|
2015-10-29 18:42:01 +03:00
|
|
|
if (!this._hasExistingNotificationPermission()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 01:59:52 +03:00
|
|
|
yield this._firstWindowReady;
|
2015-10-29 18:42:01 +03:00
|
|
|
function clickCallback(subject, topic, data) {
|
|
|
|
if (topic != "alertclickcallback")
|
|
|
|
return;
|
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
|
|
|
win.openUILinkIn(data, "tab");
|
|
|
|
}
|
2015-11-06 21:30:25 +03:00
|
|
|
// Show the application icon for XUL notifications. We assume system-level
|
|
|
|
// notifications will include their own icon.
|
|
|
|
let imageURL = this._hasSystemAlertsService() ? "" :
|
|
|
|
"chrome://branding/content/about-logo.png";
|
2015-10-29 18:42:01 +03:00
|
|
|
let title = gBrowserBundle.GetStringFromName("webNotifications.upgradeTitle");
|
2015-11-03 02:16:15 +03:00
|
|
|
let text = gBrowserBundle.GetStringFromName("webNotifications.upgradeBody");
|
2015-11-10 20:29:47 +03:00
|
|
|
let url = Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
|
|
|
"push#w_upgraded-notifications";
|
2015-10-29 18:42:01 +03:00
|
|
|
|
2015-11-03 01:59:52 +03:00
|
|
|
AlertsService.showAlertNotification(imageURL, title, text,
|
|
|
|
true, url, clickCallback);
|
|
|
|
}),
|
2015-10-29 18:42:01 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_hasSystemAlertsService() {
|
2015-11-06 21:30:25 +03:00
|
|
|
try {
|
|
|
|
return !!Cc["@mozilla.org/system-alerts-service;1"].getService(
|
|
|
|
Ci.nsIAlertsService);
|
|
|
|
} catch (e) {}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// ------------------------------
|
|
|
|
// public nsIBrowserGlue members
|
|
|
|
// ------------------------------
|
2010-09-03 06:20:12 +04:00
|
|
|
|
2009-12-18 00:28:08 +03:00
|
|
|
sanitize: function BG_sanitize(aParentWindow) {
|
2009-10-14 13:53:13 +04:00
|
|
|
this._sanitizer.sanitize(aParentWindow);
|
2007-09-06 07:02:22 +04:00
|
|
|
},
|
2005-08-23 20:38:28 +04:00
|
|
|
|
2015-04-01 20:09:26 +03:00
|
|
|
ensurePlacesDefaultQueriesInitialized: Task.async(function* () {
|
2015-04-01 20:09:32 +03:00
|
|
|
// This is the current smart bookmarks version, it must be increased every
|
|
|
|
// time they change.
|
2009-03-26 15:58:32 +03:00
|
|
|
// When adding a new smart bookmark below, its newInVersion property must
|
2015-04-01 20:09:32 +03:00
|
|
|
// be set to the version it has been added in. We will compare its value
|
2009-03-26 15:58:32 +03:00
|
|
|
// to users' smartBookmarksVersion and add new smart bookmarks without
|
|
|
|
// recreating old deleted ones.
|
2016-04-14 12:58:28 +03:00
|
|
|
const SMART_BOOKMARKS_VERSION = 8;
|
2008-04-08 22:42:53 +04:00
|
|
|
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
|
|
|
const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion";
|
|
|
|
|
2009-10-14 13:53:13 +04:00
|
|
|
// TODO bug 399268: should this be a pref?
|
2008-04-08 22:42:53 +04:00
|
|
|
const MAX_RESULTS = 10;
|
|
|
|
|
2010-11-23 16:04:07 +03:00
|
|
|
// Get current smart bookmarks version. If not set, create them.
|
|
|
|
let smartBookmarksCurrentVersion = 0;
|
2007-11-27 03:08:50 +03:00
|
|
|
try {
|
2010-04-12 18:33:10 +04:00
|
|
|
smartBookmarksCurrentVersion = Services.prefs.getIntPref(SMART_BOOKMARKS_PREF);
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (ex) {}
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2015-04-01 20:09:32 +03:00
|
|
|
// If version is current, or smart bookmarks are disabled, bail out.
|
2008-04-08 22:42:53 +04:00
|
|
|
if (smartBookmarksCurrentVersion == -1 ||
|
2010-11-23 16:04:07 +03:00
|
|
|
smartBookmarksCurrentVersion >= SMART_BOOKMARKS_VERSION) {
|
2007-11-27 03:08:50 +03:00
|
|
|
return;
|
2010-11-23 16:04:07 +03:00
|
|
|
}
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2015-04-01 20:09:32 +03:00
|
|
|
try {
|
|
|
|
let menuIndex = 0;
|
|
|
|
let toolbarIndex = 0;
|
|
|
|
let bundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");
|
|
|
|
let queryOptions = Ci.nsINavHistoryQueryOptions;
|
|
|
|
|
|
|
|
let smartBookmarks = {
|
|
|
|
MostVisited: {
|
|
|
|
title: bundle.GetStringFromName("mostVisitedTitle"),
|
|
|
|
url: "place:sort=" + queryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS,
|
|
|
|
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
|
|
|
newInVersion: 1
|
|
|
|
},
|
|
|
|
RecentTags: {
|
|
|
|
title: bundle.GetStringFromName("recentTagsTitle"),
|
|
|
|
url: "place:type=" + queryOptions.RESULTS_AS_TAG_QUERY +
|
|
|
|
"&sort=" + queryOptions.SORT_BY_LASTMODIFIED_DESCENDING +
|
|
|
|
"&maxResults=" + MAX_RESULTS,
|
|
|
|
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
|
|
|
newInVersion: 1
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set current guid, parentGuid and index of existing Smart Bookmarks.
|
|
|
|
// We will use those to create a new version of the bookmark at the same
|
|
|
|
// position.
|
|
|
|
let smartBookmarkItemIds = PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
|
|
|
for (let itemId of smartBookmarkItemIds) {
|
|
|
|
let queryId = PlacesUtils.annotations.getItemAnnotation(itemId, SMART_BOOKMARKS_ANNO);
|
|
|
|
if (queryId in smartBookmarks) {
|
|
|
|
// Known smart bookmark.
|
2010-11-23 16:04:07 +03:00
|
|
|
let smartBookmark = smartBookmarks[queryId];
|
2015-04-01 20:09:32 +03:00
|
|
|
smartBookmark.guid = yield PlacesUtils.promiseItemGuid(itemId);
|
2008-04-08 22:42:53 +04:00
|
|
|
|
2015-04-01 20:09:32 +03:00
|
|
|
if (!smartBookmark.url) {
|
|
|
|
yield PlacesUtils.bookmarks.remove(smartBookmark.guid);
|
2009-03-26 15:58:32 +03:00
|
|
|
continue;
|
2010-11-23 16:04:07 +03:00
|
|
|
}
|
|
|
|
|
2015-04-01 20:09:32 +03:00
|
|
|
let bm = yield PlacesUtils.bookmarks.fetch(smartBookmark.guid);
|
|
|
|
smartBookmark.parentGuid = bm.parentGuid;
|
|
|
|
smartBookmark.index = bm.index;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2015-04-01 20:09:32 +03: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.
|
|
|
|
PlacesUtils.annotations.removeItemAnnotation(itemId, SMART_BOOKMARKS_ANNO);
|
2008-04-08 22:42:53 +04:00
|
|
|
}
|
2015-04-01 20:09:32 +03:00
|
|
|
}
|
2010-09-03 06:20:12 +04:00
|
|
|
|
2015-04-01 20:09:32 +03:00
|
|
|
for (let queryId of Object.keys(smartBookmarks)) {
|
|
|
|
let smartBookmark = smartBookmarks[queryId];
|
|
|
|
|
|
|
|
// We update or create only changed or new smart bookmarks.
|
|
|
|
// Also we respect user choices, so we won't try to create a smart
|
|
|
|
// bookmark if it has been removed.
|
|
|
|
if (smartBookmarksCurrentVersion > 0 &&
|
|
|
|
smartBookmark.newInVersion <= smartBookmarksCurrentVersion &&
|
|
|
|
!smartBookmark.guid || !smartBookmark.url)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Remove old version of the smart bookmark if it exists, since it
|
|
|
|
// will be replaced in place.
|
|
|
|
if (smartBookmark.guid) {
|
|
|
|
yield PlacesUtils.bookmarks.remove(smartBookmark.guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new smart bookmark and store its updated guid.
|
|
|
|
if (!("index" in smartBookmark)) {
|
|
|
|
if (smartBookmark.parentGuid == PlacesUtils.bookmarks.toolbarGuid)
|
|
|
|
smartBookmark.index = toolbarIndex++;
|
|
|
|
else if (smartBookmark.parentGuid == PlacesUtils.bookmarks.menuGuid)
|
|
|
|
smartBookmark.index = menuIndex++;
|
2010-04-28 11:17:09 +04:00
|
|
|
}
|
2015-04-01 20:09:32 +03:00
|
|
|
smartBookmark = yield PlacesUtils.bookmarks.insert(smartBookmark);
|
|
|
|
let itemId = yield PlacesUtils.promiseItemId(smartBookmark.guid);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(itemId,
|
|
|
|
SMART_BOOKMARKS_ANNO,
|
|
|
|
queryId, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
|
|
|
|
2015-04-01 20:09:32 +03:00
|
|
|
// If we are creating all Smart Bookmarks from ground up, add a
|
|
|
|
// separator below them in the bookmarks menu.
|
|
|
|
if (smartBookmarksCurrentVersion == 0 &&
|
|
|
|
smartBookmarkItemIds.length == 0) {
|
|
|
|
let bm = yield PlacesUtils.bookmarks.fetch({ parentGuid: PlacesUtils.bookmarks.menuGuid,
|
|
|
|
index: menuIndex });
|
|
|
|
// Don't add a separator if the menu was empty or there is one already.
|
|
|
|
if (bm && bm.type != PlacesUtils.bookmarks.TYPE_SEPARATOR) {
|
|
|
|
yield PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
|
|
|
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
|
|
|
index: menuIndex });
|
|
|
|
}
|
|
|
|
}
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (ex) {
|
2015-04-01 20:09:32 +03:00
|
|
|
Cu.reportError(ex);
|
|
|
|
} finally {
|
2010-04-12 18:33:10 +04:00
|
|
|
Services.prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
|
|
|
|
Services.prefs.savePrefFile(null);
|
2007-11-27 03:08:50 +03:00
|
|
|
}
|
2015-04-01 20:09:26 +03:00
|
|
|
}),
|
2007-11-27 03:08:50 +03:00
|
|
|
|
2015-09-25 23:18:29 +03:00
|
|
|
/**
|
|
|
|
* Open preferences even if there are no open windows.
|
|
|
|
*/
|
|
|
|
_openPreferences(...args) {
|
|
|
|
if (Services.appShell.hiddenDOMWindow.openPreferences) {
|
|
|
|
Services.appShell.hiddenDOMWindow.openPreferences(...args);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let chromeWindow = RecentWindow.getMostRecentBrowserWindow();
|
|
|
|
chromeWindow.openPreferences(...args);
|
|
|
|
},
|
|
|
|
|
2012-06-30 02:30:45 +04:00
|
|
|
/**
|
2016-07-07 23:33:29 +03:00
|
|
|
* Called as an observer when Sync's "display URIs" notification is fired.
|
2012-06-30 02:30:45 +04:00
|
|
|
*
|
2016-07-07 23:33:29 +03:00
|
|
|
* We open the received URIs in background tabs.
|
2012-06-30 02:30:45 +04:00
|
|
|
*/
|
2016-07-07 23:33:29 +03:00
|
|
|
_onDisplaySyncURIs: function _onDisplaySyncURIs(data) {
|
2012-06-30 02:30:45 +04:00
|
|
|
try {
|
2016-07-16 02:48:14 +03:00
|
|
|
// The payload is wrapped weirdly because of how Sync does notifications.
|
2016-07-07 23:33:29 +03:00
|
|
|
const URIs = data.wrappedJSObject.object;
|
|
|
|
|
|
|
|
const findWindow = () => RecentWindow.getMostRecentBrowserWindow({private: false});
|
|
|
|
|
|
|
|
// win can be null, but it's ok, we'll assign it later in openTab()
|
|
|
|
let win = findWindow();
|
|
|
|
|
|
|
|
const openTab = URI => {
|
|
|
|
let tab;
|
|
|
|
if (!win) {
|
|
|
|
Services.appShell.hiddenDOMWindow.open(URI.uri);
|
|
|
|
win = findWindow();
|
|
|
|
tab = win.gBrowser.tabs[0];
|
|
|
|
} else {
|
|
|
|
tab = win.gBrowser.addTab(URI.uri);
|
|
|
|
}
|
|
|
|
tab.setAttribute("attention", true);
|
|
|
|
return tab;
|
|
|
|
};
|
|
|
|
|
|
|
|
const firstTab = openTab(URIs[0]);
|
|
|
|
URIs.slice(1).forEach(URI => openTab(URI));
|
|
|
|
|
|
|
|
let title, body;
|
|
|
|
const deviceName = Weave.Service.clientsEngine.getClientName(URIs[0].clientId);
|
|
|
|
const bundle = Services.strings.createBundle("chrome://browser/locale/accounts.properties");
|
|
|
|
if (URIs.length == 1) {
|
2016-10-21 22:00:59 +03:00
|
|
|
// Due to bug 1305895, tabs from iOS may not have device information, so
|
|
|
|
// we have separate strings to handle those cases. (See Also
|
|
|
|
// unnamedTabsArrivingNotificationNoDevice.body below)
|
|
|
|
if (deviceName) {
|
|
|
|
title = bundle.formatStringFromName("tabArrivingNotificationWithDevice.title", [deviceName], 1);
|
|
|
|
} else {
|
|
|
|
title = bundle.GetStringFromName("tabArrivingNotification.title");
|
|
|
|
}
|
|
|
|
// Use the page URL as the body. We strip the fragment and query to
|
|
|
|
// reduce size, and also format it the same way that the url bar would.
|
|
|
|
body = URIs[0].uri.replace(/[?#].*$/, "");
|
|
|
|
if (win.gURLBar) {
|
|
|
|
body = win.gURLBar.trimValue(body);
|
|
|
|
}
|
2016-07-07 23:33:29 +03:00
|
|
|
} else {
|
|
|
|
title = bundle.GetStringFromName("tabsArrivingNotification.title");
|
2016-10-21 22:00:59 +03:00
|
|
|
const allSameDevice = URIs.every(URI => URI.clientId == URIs[0].clientId);
|
|
|
|
const unknownDevice = allSameDevice && !deviceName;
|
|
|
|
let tabArrivingBody;
|
|
|
|
if (unknownDevice) {
|
|
|
|
tabArrivingBody = "unnamedTabsArrivingNotificationNoDevice.body";
|
|
|
|
} else if (allSameDevice) {
|
|
|
|
tabArrivingBody = "unnamedTabsArrivingNotification2.body";
|
|
|
|
} else {
|
|
|
|
tabArrivingBody = "unnamedTabsArrivingNotificationMultiple2.body"
|
|
|
|
}
|
|
|
|
|
2016-07-19 02:30:52 +03:00
|
|
|
body = bundle.GetStringFromName(tabArrivingBody);
|
|
|
|
body = PluralForm.get(URIs.length, body);
|
|
|
|
body = body.replace("#1", URIs.length);
|
|
|
|
body = body.replace("#2", deviceName);
|
2016-07-07 23:33:29 +03:00
|
|
|
}
|
|
|
|
|
2016-11-16 06:58:30 +03:00
|
|
|
const clickCallback = (obsSubject, obsTopic, obsData) => {
|
|
|
|
if (obsTopic == "alertclickcallback") {
|
2016-07-07 23:33:29 +03:00
|
|
|
win.gBrowser.selectedTab = firstTab;
|
|
|
|
}
|
|
|
|
}
|
2016-08-19 05:34:49 +03:00
|
|
|
|
|
|
|
// Specify an icon because on Windows no icon is shown at the moment
|
|
|
|
let imageURL;
|
|
|
|
if (AppConstants.platform == "win") {
|
|
|
|
imageURL = "chrome://branding/content/icon64.png";
|
|
|
|
}
|
|
|
|
AlertsService.showAlertNotification(imageURL, title, body, true, null, clickCallback);
|
2012-06-30 02:30:45 +04:00
|
|
|
} catch (ex) {
|
2016-07-07 23:33:29 +03:00
|
|
|
Cu.reportError("Error displaying tab(s) received by Sync: " + ex);
|
2012-06-30 02:30:45 +04:00
|
|
|
}
|
|
|
|
},
|
2008-10-31 09:42:02 +03:00
|
|
|
|
2017-01-05 03:21:36 +03:00
|
|
|
_onDeviceConnected(deviceName) {
|
|
|
|
let accountsBundle = Services.strings.createBundle(
|
|
|
|
"chrome://browser/locale/accounts.properties"
|
|
|
|
);
|
|
|
|
let title = accountsBundle.GetStringFromName("deviceConnectedTitle");
|
2017-02-02 23:49:03 +03:00
|
|
|
let body = accountsBundle.formatStringFromName("deviceConnectedBody" +
|
|
|
|
(deviceName ? "" : ".noDeviceName"),
|
|
|
|
[deviceName], 1);
|
2017-01-05 03:21:36 +03:00
|
|
|
let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.settings.devices.uri");
|
|
|
|
|
|
|
|
function clickCallback(subject, topic, data) {
|
|
|
|
if (topic != "alertclickcallback")
|
|
|
|
return;
|
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow({private: false});
|
|
|
|
if (!win) {
|
|
|
|
Services.appShell.hiddenDOMWindow.open(url);
|
|
|
|
} else {
|
|
|
|
win.gBrowser.addTab(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
AlertsService.showAlertNotification(null, title, body, true, url, clickCallback);
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("Error notifying of a new Sync device: " + ex);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-08 20:40:42 +03:00
|
|
|
_onDeviceDisconnected() {
|
|
|
|
let bundle = Services.strings.createBundle("chrome://browser/locale/accounts.properties");
|
|
|
|
let title = bundle.GetStringFromName("deviceDisconnectedNotification.title");
|
|
|
|
let body = bundle.GetStringFromName("deviceDisconnectedNotification.body");
|
|
|
|
|
|
|
|
let clickCallback = (subject, topic, data) => {
|
|
|
|
if (topic != "alertclickcallback")
|
|
|
|
return;
|
|
|
|
this._openPreferences("sync");
|
|
|
|
}
|
|
|
|
AlertsService.showAlertNotification(null, title, body, true, null, clickCallback);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_handleFlashHang() {
|
2015-02-20 01:43:24 +03:00
|
|
|
++this._flashHangCount;
|
|
|
|
if (this._flashHangCount < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// protected mode only applies to win32
|
|
|
|
if (Services.appinfo.XPCOMABI != "x86-msvc") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Services.prefs.getBoolPref("dom.ipc.plugins.flash.disable-protected-mode")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Services.prefs.getBoolPref("browser.flash-protected-mode-flip.enable")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Services.prefs.getBoolPref("browser.flash-protected-mode-flip.done")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Services.prefs.setBoolPref("dom.ipc.plugins.flash.disable-protected-mode", true);
|
|
|
|
Services.prefs.setBoolPref("browser.flash-protected-mode-flip.done", true);
|
|
|
|
|
2015-05-24 14:05:00 +03:00
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2015-02-20 01:43:24 +03:00
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-01 02:00:45 +03:00
|
|
|
let productName = gBrandBundle.GetStringFromName("brandShortName");
|
2015-02-20 01:43:24 +03:00
|
|
|
let message = win.gNavigatorBundle.
|
|
|
|
getFormattedString("flashHang.message", [productName]);
|
|
|
|
let buttons = [{
|
|
|
|
label: win.gNavigatorBundle.getString("flashHang.helpButton.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("flashHang.helpButton.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-02-20 01:43:24 +03:00
|
|
|
win.openUILinkIn("https://support.mozilla.org/kb/flash-protected-mode-autodisabled", "tab");
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
let nb = win.document.getElementById("global-notificationbox");
|
|
|
|
nb.appendNotification(message, "flash-hang", null,
|
|
|
|
nb.PRIORITY_INFO_MEDIUM, buttons);
|
|
|
|
},
|
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// for XPCOM
|
|
|
|
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),
|
2005-08-23 20:38:28 +04:00
|
|
|
|
2007-09-27 23:37:47 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIBrowserGlue]),
|
2005-08-23 20:38:28 +04:00
|
|
|
|
2007-09-06 07:02:22 +04:00
|
|
|
// redefine the default factory for XPCOMUtils
|
|
|
|
_xpcom_factory: BrowserGlueServiceFactory,
|
2005-08-23 20:38:28 +04:00
|
|
|
}
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* ContentPermissionIntegration is responsible for showing the user
|
|
|
|
* simple permission prompts when content requests additional
|
|
|
|
* capabilities.
|
|
|
|
*
|
|
|
|
* While there are some built-in permission prompts, createPermissionPrompt
|
|
|
|
* can also be overridden by system add-ons or tests to provide new ones.
|
|
|
|
*
|
|
|
|
* This override ability is provided by Integration.jsm. See
|
|
|
|
* PermissionUI.jsm for an example of how to provide a new prompt
|
|
|
|
* from an add-on.
|
|
|
|
*/
|
|
|
|
const ContentPermissionIntegration = {
|
|
|
|
/**
|
|
|
|
* Creates a PermissionPrompt for a given permission type and
|
|
|
|
* nsIContentPermissionRequest.
|
|
|
|
*
|
|
|
|
* @param {string} type
|
|
|
|
* The type of the permission request from content. This normally
|
|
|
|
* matches the "type" field of an nsIContentPermissionType, but it
|
|
|
|
* can be something else if the permission does not use the
|
|
|
|
* nsIContentPermissionRequest model. Note that this type might also
|
|
|
|
* be different from the permission key used in the permissions
|
|
|
|
* database.
|
|
|
|
* Example: "geolocation"
|
|
|
|
* @param {nsIContentPermissionRequest} request
|
|
|
|
* The request for a permission from content.
|
|
|
|
* @return {PermissionPrompt} (see PermissionUI.jsm),
|
|
|
|
* or undefined if the type cannot be handled.
|
|
|
|
*/
|
|
|
|
createPermissionPrompt(type, request) {
|
|
|
|
switch (type) {
|
|
|
|
case "geolocation": {
|
|
|
|
return new PermissionUI.GeolocationPermissionPrompt(request);
|
|
|
|
}
|
|
|
|
case "desktop-notification": {
|
|
|
|
return new PermissionUI.DesktopNotificationPermissionPrompt(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
function ContentPermissionPrompt() {}
|
2008-10-23 22:01:32 +04:00
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
ContentPermissionPrompt.prototype = {
|
|
|
|
classID: Components.ID("{d8903bf6-68d5-4e97-bcd1-e4d3012f721a}"),
|
2008-10-23 22:01:32 +04:00
|
|
|
|
2010-09-10 08:59:51 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
|
2010-04-09 21:45:25 +04:00
|
|
|
|
2012-07-12 19:45:38 +04:00
|
|
|
/**
|
2016-08-28 06:11:07 +03:00
|
|
|
* This implementation of nsIContentPermissionPrompt.prompt ensures
|
|
|
|
* that there's only one nsIContentPermissionType in the request,
|
|
|
|
* and that it's of type nsIContentPermissionType. Failing to
|
|
|
|
* satisfy either of these conditions will result in this method
|
|
|
|
* throwing NS_ERRORs. If the combined ContentPermissionIntegration
|
|
|
|
* cannot construct a prompt for this particular request, an
|
|
|
|
* NS_ERROR_FAILURE will be thrown.
|
2012-07-12 19:45:38 +04:00
|
|
|
*
|
2016-08-28 06:11:07 +03:00
|
|
|
* Any time an error is thrown, the nsIContentPermissionRequest is
|
|
|
|
* cancelled automatically.
|
|
|
|
*
|
|
|
|
* @param {nsIContentPermissionRequest} request
|
|
|
|
* The request that we're to show a prompt for.
|
2012-07-12 19:45:38 +04:00
|
|
|
*/
|
2016-08-28 06:11:07 +03:00
|
|
|
prompt(request) {
|
|
|
|
try {
|
|
|
|
// Only allow exactly one permission request here.
|
|
|
|
let types = request.types.QueryInterface(Ci.nsIArray);
|
|
|
|
if (types.length != 1) {
|
|
|
|
throw Components.Exception(
|
|
|
|
"Expected an nsIContentPermissionRequest with only 1 type.",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
2012-07-12 19:45:38 +04:00
|
|
|
}
|
2010-04-09 21:45:25 +04:00
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
let type = types.queryElementAt(0, Ci.nsIContentPermissionType).type;
|
|
|
|
let combinedIntegration =
|
|
|
|
Integration.contentPermission.getCombined(ContentPermissionIntegration);
|
2012-07-12 19:45:38 +04:00
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
let permissionPrompt =
|
|
|
|
combinedIntegration.createPermissionPrompt(type, request);
|
|
|
|
if (!permissionPrompt) {
|
|
|
|
throw Components.Exception(
|
|
|
|
`Failed to handle permission of type ${type}`,
|
|
|
|
Cr.NS_ERROR_FAILURE);
|
2016-09-08 21:36:53 +03:00
|
|
|
}
|
2014-02-10 00:34:40 +04:00
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
permissionPrompt.prompt();
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
2012-07-12 19:45:38 +04:00
|
|
|
request.cancel();
|
2016-08-28 06:11:07 +03:00
|
|
|
throw ex;
|
2012-07-12 19:45:38 +04:00
|
|
|
}
|
2013-03-24 14:32:44 +04:00
|
|
|
},
|
2008-10-23 22:01:32 +04:00
|
|
|
};
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var DefaultBrowserCheck = {
|
2014-08-12 11:59:11 +04:00
|
|
|
get OPTIONPOPUP() { return "defaultBrowserNotificationPopup" },
|
2015-09-01 22:52:05 +03:00
|
|
|
_setAsDefaultTimer: null,
|
|
|
|
_setAsDefaultButtonClickStartTime: 0,
|
2014-08-12 11:59:11 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
closePrompt(aNode) {
|
2014-08-12 11:59:11 +04:00
|
|
|
if (this._notification) {
|
|
|
|
this._notification.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
setAsDefault() {
|
2014-08-12 11:59:11 +04:00
|
|
|
let claimAllTypes = true;
|
2015-09-01 22:52:05 +03:00
|
|
|
let setAsDefaultError = false;
|
2016-01-22 23:48:20 +03:00
|
|
|
if (AppConstants.platform == "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 = Services.sysinfo.getProperty("version");
|
|
|
|
claimAllTypes = (parseFloat(version) < 6.2);
|
|
|
|
} catch (ex) { }
|
|
|
|
}
|
2014-09-24 19:18:45 +04:00
|
|
|
try {
|
|
|
|
ShellService.setDefaultBrowser(claimAllTypes, false);
|
2015-09-01 22:52:05 +03:00
|
|
|
|
|
|
|
if (this._setAsDefaultTimer) {
|
|
|
|
this._setAsDefaultTimer.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._setAsDefaultButtonClickStartTime = Math.floor(Date.now() / 1000);
|
|
|
|
this._setAsDefaultTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2015-09-16 22:01:03 +03:00
|
|
|
this._setAsDefaultTimer.init(() => {
|
2015-09-01 22:52:05 +03:00
|
|
|
let isDefault = false;
|
|
|
|
let isDefaultError = false;
|
|
|
|
try {
|
|
|
|
isDefault = ShellService.isDefaultBrowser(true, false);
|
|
|
|
} catch (ex) {
|
|
|
|
isDefaultError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let now = Math.floor(Date.now() / 1000);
|
|
|
|
let runTime = now - this._setAsDefaultButtonClickStartTime;
|
|
|
|
if (isDefault || runTime > 600) {
|
|
|
|
this._setAsDefaultTimer.cancel();
|
|
|
|
this._setAsDefaultTimer = null;
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_TIME_TO_COMPLETION_SECONDS")
|
|
|
|
.add(runTime);
|
|
|
|
}
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT_ERROR")
|
|
|
|
.add(isDefaultError);
|
|
|
|
}, 1000, Ci.nsITimer.TYPE_REPEATING_SLACK);
|
2014-09-24 19:18:45 +04:00
|
|
|
} catch (ex) {
|
2015-09-01 22:52:05 +03:00
|
|
|
setAsDefaultError = true;
|
2014-09-24 19:18:45 +04:00
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
2015-09-01 22:52:05 +03:00
|
|
|
// Here BROWSER_IS_USER_DEFAULT and BROWSER_SET_USER_DEFAULT_ERROR appear
|
|
|
|
// to be inverse of each other, but that is only because this function is
|
|
|
|
// called when the browser is set as the default. During startup we record
|
|
|
|
// the BROWSER_IS_USER_DEFAULT value without recording BROWSER_SET_USER_DEFAULT_ERROR.
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT")
|
|
|
|
.add(!setAsDefaultError);
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_ERROR")
|
|
|
|
.add(setAsDefaultError);
|
2014-08-12 11:59:11 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_createPopup(win, notNowStrings, neverStrings) {
|
2014-08-12 11:59:11 +04:00
|
|
|
let doc = win.document;
|
|
|
|
let popup = doc.createElement("menupopup");
|
|
|
|
popup.id = this.OPTIONPOPUP;
|
|
|
|
|
|
|
|
let notNowItem = doc.createElement("menuitem");
|
|
|
|
notNowItem.id = "defaultBrowserNotNow";
|
2014-11-03 03:08:58 +03:00
|
|
|
notNowItem.setAttribute("label", notNowStrings.label);
|
|
|
|
notNowItem.setAttribute("accesskey", notNowStrings.accesskey);
|
2014-08-12 11:59:11 +04:00
|
|
|
popup.appendChild(notNowItem);
|
|
|
|
|
|
|
|
let neverItem = doc.createElement("menuitem");
|
|
|
|
neverItem.id = "defaultBrowserNever";
|
2014-11-03 03:08:58 +03:00
|
|
|
neverItem.setAttribute("label", neverStrings.label);
|
|
|
|
neverItem.setAttribute("accesskey", neverStrings.accesskey);
|
2014-08-12 11:59:11 +04:00
|
|
|
popup.appendChild(neverItem);
|
|
|
|
|
|
|
|
popup.addEventListener("command", this);
|
|
|
|
|
|
|
|
let popupset = doc.getElementById("mainPopupSet");
|
|
|
|
popupset.appendChild(popup);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
handleEvent(event) {
|
2014-08-12 11:59:11 +04:00
|
|
|
if (event.type == "command") {
|
|
|
|
if (event.target.id == "defaultBrowserNever") {
|
|
|
|
ShellService.shouldCheckDefaultBrowser = false;
|
|
|
|
}
|
|
|
|
this.closePrompt();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
prompt(win) {
|
2015-01-09 16:52:21 +03:00
|
|
|
let useNotificationBar = Services.prefs.getBoolPref("browser.defaultbrowser.notificationbar");
|
2014-08-12 11:59:11 +04:00
|
|
|
|
2015-01-09 16:52:21 +03:00
|
|
|
let brandBundle = win.document.getElementById("bundle_brand");
|
2014-08-12 11:59:11 +04:00
|
|
|
let brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
|
2015-01-09 16:52:21 +03:00
|
|
|
let shellBundle = win.document.getElementById("bundle_shell");
|
|
|
|
let buttonPrefix = "setDefaultBrowser" + (useNotificationBar ? "" : "Alert");
|
|
|
|
let yesButton = shellBundle.getFormattedString(buttonPrefix + "Confirm.label",
|
2014-11-03 03:08:58 +03:00
|
|
|
[brandShortName]);
|
2015-01-09 16:52:21 +03:00
|
|
|
let notNowButton = shellBundle.getString(buttonPrefix + "NotNow.label");
|
2014-08-12 11:59:11 +04:00
|
|
|
|
2014-11-03 03:08:58 +03:00
|
|
|
if (useNotificationBar) {
|
2015-01-09 16:52:21 +03:00
|
|
|
let promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage2",
|
|
|
|
[brandShortName]);
|
2014-11-03 03:08:58 +03:00
|
|
|
let optionsMessage = shellBundle.getString("setDefaultBrowserOptions.label");
|
|
|
|
let optionsKey = shellBundle.getString("setDefaultBrowserOptions.accesskey");
|
2014-08-12 11:59:11 +04:00
|
|
|
|
2015-01-09 16:52:21 +03:00
|
|
|
let neverLabel = shellBundle.getString("setDefaultBrowserNever.label");
|
|
|
|
let neverKey = shellBundle.getString("setDefaultBrowserNever.accesskey");
|
|
|
|
|
2014-11-03 03:08:58 +03:00
|
|
|
let yesButtonKey = shellBundle.getString("setDefaultBrowserConfirm.accesskey");
|
2015-01-09 16:52:21 +03:00
|
|
|
let notNowButtonKey = shellBundle.getString("setDefaultBrowserNotNow.accesskey");
|
2014-11-03 03:08:58 +03:00
|
|
|
|
|
|
|
let notificationBox = win.document.getElementById("high-priority-global-notificationbox");
|
2014-08-12 11:59:11 +04:00
|
|
|
|
2014-11-03 03:08:58 +03:00
|
|
|
this._createPopup(win, {
|
|
|
|
label: notNowButton,
|
|
|
|
accesskey: notNowButtonKey
|
|
|
|
}, {
|
|
|
|
label: neverLabel,
|
|
|
|
accesskey: neverKey
|
|
|
|
});
|
|
|
|
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: yesButton,
|
|
|
|
accessKey: yesButtonKey,
|
|
|
|
callback: () => {
|
|
|
|
this.setAsDefault();
|
|
|
|
this.closePrompt();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: optionsMessage,
|
|
|
|
accessKey: optionsKey,
|
|
|
|
popup: this.OPTIONPOPUP
|
|
|
|
}
|
|
|
|
];
|
2014-08-12 11:59:11 +04:00
|
|
|
|
2014-11-03 03:08:58 +03:00
|
|
|
let iconPixels = win.devicePixelRatio > 1 ? "32" : "16";
|
|
|
|
let iconURL = "chrome://branding/content/icon" + iconPixels + ".png";
|
|
|
|
const priority = notificationBox.PRIORITY_WARNING_HIGH;
|
|
|
|
let callback = this._onNotificationEvent.bind(this);
|
|
|
|
this._notification = notificationBox.appendNotification(promptMessage, "default-browser",
|
|
|
|
iconURL, priority, buttons,
|
|
|
|
callback);
|
|
|
|
} else {
|
|
|
|
// Modal prompt
|
|
|
|
let promptTitle = shellBundle.getString("setDefaultBrowserTitle");
|
2015-01-09 16:52:21 +03:00
|
|
|
let promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage",
|
|
|
|
[brandShortName]);
|
2015-01-12 18:45:01 +03:00
|
|
|
let askLabel = shellBundle.getFormattedString("setDefaultBrowserDontAsk",
|
|
|
|
[brandShortName]);
|
2014-11-03 03:08:58 +03:00
|
|
|
|
|
|
|
let ps = Services.prompt;
|
2015-01-12 18:45:01 +03:00
|
|
|
let shouldAsk = { value: true };
|
2014-11-03 03:08:58 +03:00
|
|
|
let buttonFlags = (ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0) +
|
|
|
|
(ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_1) +
|
|
|
|
ps.BUTTON_POS_0_DEFAULT;
|
|
|
|
let rv = ps.confirmEx(win, promptTitle, promptMessage, buttonFlags,
|
2015-01-12 18:45:01 +03:00
|
|
|
yesButton, notNowButton, null, askLabel, shouldAsk);
|
2014-11-03 03:08:58 +03:00
|
|
|
if (rv == 0) {
|
|
|
|
this.setAsDefault();
|
2015-01-12 18:45:01 +03:00
|
|
|
} else if (!shouldAsk.value) {
|
2014-11-03 03:08:58 +03:00
|
|
|
ShellService.shouldCheckDefaultBrowser = false;
|
|
|
|
}
|
2015-09-01 22:52:05 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
let resultEnum = rv * 2 + shouldAsk.value;
|
|
|
|
Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_RESULT")
|
|
|
|
.add(resultEnum);
|
|
|
|
} catch (ex) { /* Don't break if Telemetry is acting up. */ }
|
2014-11-03 03:08:58 +03:00
|
|
|
}
|
2014-08-12 11:59:11 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_onNotificationEvent(eventType) {
|
2014-08-12 11:59:11 +04:00
|
|
|
if (eventType == "removed") {
|
|
|
|
let doc = this._notification.ownerDocument;
|
|
|
|
let popup = doc.getElementById(this.OPTIONPOPUP);
|
|
|
|
popup.removeEventListener("command", this);
|
|
|
|
popup.remove();
|
|
|
|
delete this._notification;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-11-24 05:00:47 +03:00
|
|
|
var E10SAccessibilityCheck = {
|
2016-07-27 01:22:00 +03:00
|
|
|
// tracks when an a11y init observer fires prior to the
|
|
|
|
// first window being opening.
|
|
|
|
_wantsPrompt: false,
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
init() {
|
2015-11-24 05:00:47 +03:00
|
|
|
Services.obs.addObserver(this, "a11y-init-or-shutdown", true);
|
2015-12-10 22:28:34 +03:00
|
|
|
Services.obs.addObserver(this, "quit-application-granted", true);
|
2015-11-24 05:00:47 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|
|
|
|
2015-12-10 22:28:34 +03:00
|
|
|
get forcedOn() {
|
|
|
|
try {
|
|
|
|
return Services.prefs.getBoolPref("browser.tabs.remote.force-enable");
|
|
|
|
} catch (e) {}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
observe(subject, topic, data) {
|
2015-12-10 22:28:34 +03:00
|
|
|
switch (topic) {
|
|
|
|
case "quit-application-granted":
|
|
|
|
// Tag the profile with a11y load state. We use this in nsAppRunner
|
|
|
|
// checks on the next start.
|
|
|
|
Services.prefs.setBoolPref("accessibility.loadedInLastSession",
|
|
|
|
Services.appinfo.accessibilityEnabled);
|
|
|
|
break;
|
|
|
|
case "a11y-init-or-shutdown":
|
|
|
|
if (data == "1") {
|
|
|
|
// Update this so users can check this while still running
|
|
|
|
Services.prefs.setBoolPref("accessibility.loadedInLastSession", true);
|
|
|
|
this._showE10sAccessibilityWarning();
|
|
|
|
}
|
|
|
|
break;
|
2015-11-24 05:00:47 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onWindowsRestored() {
|
2016-07-27 01:22:00 +03:00
|
|
|
if (this._wantsPrompt) {
|
|
|
|
this._wantsPrompt = false;
|
|
|
|
this._showE10sAccessibilityWarning();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-24 05:00:47 +03:00
|
|
|
_warnedAboutAccessibility: false,
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_showE10sAccessibilityWarning() {
|
2015-12-10 22:28:34 +03:00
|
|
|
// We don't prompt about a11y incompat if e10s is off.
|
|
|
|
if (!Services.appinfo.browserTabsRemoteAutostart) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-24 05:00:47 +03:00
|
|
|
|
2015-12-10 22:28:34 +03:00
|
|
|
// If the user set the forced pref and it's true, ignore a11y init.
|
|
|
|
// If the pref doesn't exist or if it's false, prompt.
|
|
|
|
if (this.forcedOn) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-24 05:00:47 +03:00
|
|
|
|
2015-12-10 22:28:34 +03:00
|
|
|
// Only prompt once per session
|
|
|
|
if (this._warnedAboutAccessibility) {
|
2015-11-24 05:00:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._warnedAboutAccessibility = true;
|
|
|
|
|
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
2016-07-27 01:22:00 +03:00
|
|
|
if (!win || !win.gBrowser || !win.gBrowser.selectedBrowser) {
|
|
|
|
Services.console.logStringMessage(
|
|
|
|
"Accessibility support is partially disabled due to compatibility issues with new features.");
|
|
|
|
this._wantsPrompt = true;
|
|
|
|
this._warnedAboutAccessibility = false;
|
2015-11-24 05:00:47 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-07-27 01:22:00 +03:00
|
|
|
let browser = win.gBrowser.selectedBrowser;
|
2015-11-24 05:00:47 +03:00
|
|
|
|
2015-12-10 22:28:34 +03:00
|
|
|
// We disable a11y for content and prompt on the chrome side letting
|
|
|
|
// a11y users know they need to disable e10s and restart.
|
2015-11-24 05:00:47 +03:00
|
|
|
let promptMessage = win.gNavigatorBundle.getFormattedString(
|
2015-12-10 22:28:34 +03:00
|
|
|
"e10s.accessibilityNotice.mainMessage2",
|
2015-11-24 05:00:47 +03:00
|
|
|
[gBrandBundle.GetStringFromName("brandShortName")]
|
|
|
|
);
|
2015-12-10 22:28:34 +03:00
|
|
|
let notification;
|
|
|
|
let restartCallback = function() {
|
|
|
|
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
|
|
|
Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
|
|
|
|
if (cancelQuit.data) {
|
|
|
|
return; // somebody canceled our quit request
|
|
|
|
}
|
|
|
|
// Restart the browser
|
|
|
|
Services.startup.quit(Services.startup.eAttemptQuit | Services.startup.eRestart);
|
|
|
|
};
|
|
|
|
// main option: an Ok button, keeps running with content accessibility disabled
|
2015-11-24 05:00:47 +03:00
|
|
|
let mainAction = {
|
2015-12-10 22:28:34 +03:00
|
|
|
label: win.gNavigatorBundle.getString("e10s.accessibilityNotice.acceptButton.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("e10s.accessibilityNotice.acceptButton.accesskey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-12-10 22:28:34 +03:00
|
|
|
// If the user invoked the button option remove the notification,
|
|
|
|
// otherwise keep the alert icon around in the address bar.
|
|
|
|
notification.remove();
|
|
|
|
},
|
|
|
|
dismiss: true
|
2015-11-24 05:00:47 +03:00
|
|
|
};
|
2015-12-10 22:28:34 +03:00
|
|
|
// secondary option: a restart now button. When we restart e10s will be disabled due to
|
|
|
|
// accessibility having been loaded in the previous session.
|
|
|
|
let secondaryActions = [{
|
|
|
|
label: win.gNavigatorBundle.getString("e10s.accessibilityNotice.enableAndRestart.label"),
|
|
|
|
accessKey: win.gNavigatorBundle.getString("e10s.accessibilityNotice.enableAndRestart.accesskey"),
|
|
|
|
callback: restartCallback,
|
|
|
|
}];
|
2015-11-24 05:00:47 +03:00
|
|
|
let options = {
|
|
|
|
popupIconURL: "chrome://browser/skin/e10s-64@2x.png",
|
2016-01-27 23:27:15 +03:00
|
|
|
learnMoreURL: Services.urlFormatter.formatURLPref("app.support.e10sAccessibilityUrl"),
|
2016-11-20 20:40:04 +03:00
|
|
|
persistent: true,
|
2015-12-10 22:28:34 +03:00
|
|
|
persistWhileVisible: true,
|
2015-11-24 05:00:47 +03:00
|
|
|
};
|
|
|
|
|
2015-12-10 22:28:34 +03:00
|
|
|
notification =
|
|
|
|
win.PopupNotifications.show(browser, "a11y_enabled_with_e10s",
|
|
|
|
promptMessage, null, mainAction,
|
|
|
|
secondaryActions, options);
|
2015-11-24 05:00:47 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-01-12 04:30:13 +03:00
|
|
|
var components = [BrowserGlue, ContentPermissionPrompt];
|
2012-10-31 20:13:28 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|
2014-10-24 19:19:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Listen for UITour messages.
|
|
|
|
// Do it here instead of the UITour module itself so that the UITour module is lazy loaded
|
|
|
|
// when the first message is received.
|
2015-09-15 21:19:45 +03:00
|
|
|
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
|
2014-10-24 19:19:00 +04:00
|
|
|
globalMM.addMessageListener("UITour:onPageEvent", function(aMessage) {
|
|
|
|
UITour.onPageEvent(aMessage, aMessage.data);
|
|
|
|
});
|