Bug 1369436 - Listen for push messages once all windows have been restored. r?florian
MozReview-Commit-ID: Cy8z01fKZGK
--- a/browser/base/content/test/performance/browser_startup.js
+++ b/browser/base/content/test/performance/browser_startup.js
@@ -25,17 +25,16 @@ const startupPhases = {
"before profile selection": {whitelist: {
components: new Set([
"nsBrowserGlue.js",
"MainProcessSingleton.js",
// Bugs to fix: The following components shouldn't be initialized that early.
"WebContentConverter.js", // bug 1369443
"nsSessionStartup.js", // bug 1369456
- "PushComponents.js", // bug 1369436
]),
modules: new Set([
"resource://gre/modules/AppConstants.jsm",
"resource://gre/modules/XPCOMUtils.jsm",
"resource://gre/modules/Services.jsm",
// Bugs to fix: Probably loaded too early, needs investigation.
"resource://gre/modules/AsyncPrefs.jsm", // bug 1369460
@@ -86,16 +85,19 @@ const startupPhases = {
"@mozilla.org/browser/search-service;1",
])
}},
// We are at this phase once we are ready to handle user events.
// Anything loaded at this phase or before gets in the way of the user
// interacting with the first browser window.
"before handling user events": {blacklist: {
+ components: new Set([
+ "PushComponents.js",
+ ]),
modules: new Set([
"resource://gre/modules/LoginManagerContextMenu.jsm",
"resource://gre/modules/Task.jsm",
]),
}},
};
function test() {
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -13,16 +13,19 @@ Cu.import("resource://gre/modules/XPCOMU
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/AsyncPrefs.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils", "@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
XPCOMUtils.defineLazyGetter(this, "WeaveService", () =>
Cc["@mozilla.org/weave/service;1"].getService().wrappedJSObject
);
+XPCOMUtils.defineLazyGetter(this, "PushService", () =>
+ Cc["@mozilla.org/push/Service;1"].getService().wrappedJSObject
+);
XPCOMUtils.defineLazyModuleGetter(this, "ContextualIdentityService",
"resource://gre/modules/ContextualIdentityService.jsm");
// lazy module getters
/* global AboutHome:false, AboutNewTab:false, AddonManager:false, AppMenuNotifications:false,
AsyncShutdown:false, AutoCompletePopup:false, BookmarkHTMLUtils:false,
BookmarkJSONUtils:false, BrowserUITelemetry:false, BrowserUsageTelemetry:false,
@@ -1191,16 +1194,21 @@ BrowserGlue.prototype = {
// Let's load the contextual identities.
Services.tm.idleDispatchToMainThread(() => {
ContextualIdentityService.load();
});
this._sanitizer.onStartup();
E10SAccessibilityCheck.onWindowsRestored();
+
+ // Start listening for incoming push messages.
+ Services.tm.idleDispatchToMainThread(() => {
+ PushService.ensureReady();
+ });
},
_createExtraDefaultProfile() {
if (!AppConstants.MOZ_DEV_EDITION) {
return;
}
// If Developer Edition is the only installed Firefox version and no other
// profiles are present, create a second one for use by other versions.
--- a/dom/push/Push.manifest
+++ b/dom/push/Push.manifest
@@ -1,11 +1,10 @@
# DOM API
component {cde1d019-fad8-4044-b141-65fb4fb7a245} Push.js
contract @mozilla.org/push/PushManager;1 {cde1d019-fad8-4044-b141-65fb4fb7a245}
# XPCOM components.
component {daaa8d73-677e-4233-8acd-2c404bd01658} PushComponents.js
contract @mozilla.org/push/Service;1 {daaa8d73-677e-4233-8acd-2c404bd01658}
-category app-startup PushServiceParent @mozilla.org/push/Service;1 process=main
# For immediate loading of PushService instead of delayed loading.
category android-push-service PushServiceParent @mozilla.org/push/Service;1 process=main
--- a/dom/push/PushComponents.js
+++ b/dom/push/PushComponents.js
@@ -58,41 +58,32 @@ PushServiceBase.prototype = {
Ci.nsIPushQuotaManager,
Ci.nsIPushErrorReporter,
]),
pushTopic: OBSERVER_TOPIC_PUSH,
subscriptionChangeTopic: OBSERVER_TOPIC_SUBSCRIPTION_CHANGE,
subscriptionModifiedTopic: OBSERVER_TOPIC_SUBSCRIPTION_MODIFIED,
- _handleReady() {},
+ ensureReady() {},
_addListeners() {
for (let message of this._messages) {
this._mm.addMessageListener(message, this);
}
},
_isValidMessage(message) {
return this._messages.includes(message.name);
},
observe(subject, topic, data) {
- if (topic === "app-startup") {
- Services.obs.addObserver(this, "sessionstore-windows-restored", true);
- return;
- }
- if (topic === "sessionstore-windows-restored") {
- Services.obs.removeObserver(this, "sessionstore-windows-restored");
- this._handleReady();
- return;
- }
if (topic === "android-push-service") {
// Load PushService immediately.
- this._handleReady();
+ this.ensureReady();
return;
}
},
_deliverSubscription(request, props) {
if (!props) {
request.onPushSubscription(Cr.NS_OK, null);
return;
@@ -223,17 +214,17 @@ Object.assign(PushServiceParent.prototyp
}, error => {
sender.sendAsyncMessage(this._getResponseName(name, "KO"), {
requestID: data.requestID,
result: error.result,
});
}).catch(Cu.reportError);
},
- _handleReady() {
+ ensureReady() {
this.service.init();
},
_toPageRecord(principal, data) {
if (!data.scope) {
throw new Error("Invalid page record: missing scope");
}
if (!principal) {