From 0faecc91b56d4e249b4ae7b210438fbd2ecf01cf Mon Sep 17 00:00:00 2001 From: Emma Malysz Date: Wed, 18 Mar 2020 22:33:01 +0000 Subject: [PATCH] Bug 1522930, delay GMP initialization until after first point to improve perceived performance. r=mconley Differential Revision: https://phabricator.services.mozilla.com/D67165 --HG-- extra : moz-landing-system : lando --- .../extensions/internal/GMPProvider.jsm | 33 +++++++++++++------ .../test/xpcshell/test_gmpProvider.js | 5 +++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/toolkit/mozapps/extensions/internal/GMPProvider.jsm b/toolkit/mozapps/extensions/internal/GMPProvider.jsm index 9973edf04cd7..45cdd33d52c2 100644 --- a/toolkit/mozapps/extensions/internal/GMPProvider.jsm +++ b/toolkit/mozapps/extensions/internal/GMPProvider.jsm @@ -48,6 +48,8 @@ const NS_GRE_DIR = "GreD"; const CLEARKEY_PLUGIN_ID = "gmp-clearkey"; const CLEARKEY_VERSION = "0.1"; +const FIRST_CONTENT_PROCESS_TOPIC = "ipc:first-content-process-created"; + const GMP_LICENSE_INFO = "gmp_license_info"; const GMP_PRIVACY_INFO = "gmp_privacy_info"; const GMP_LEARN_MORE = "learn_more_label"; @@ -880,15 +882,26 @@ var GMPProvider = { } } }, + + observe(subject, topic, data) { + if (topic == FIRST_CONTENT_PROCESS_TOPIC) { + AddonManagerPrivate.registerProvider(GMPProvider, [ + new AddonManagerPrivate.AddonType( + "plugin", + URI_EXTENSION_STRINGS, + "type.plugin.name", + AddonManager.VIEW_TYPE_LIST, + 6000, + AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE + ), + ]); + Services.obs.removeObserver(this, FIRST_CONTENT_PROCESS_TOPIC); + } + }, + + addObserver() { + Services.obs.addObserver(this, FIRST_CONTENT_PROCESS_TOPIC); + }, }; -AddonManagerPrivate.registerProvider(GMPProvider, [ - new AddonManagerPrivate.AddonType( - "plugin", - URI_EXTENSION_STRINGS, - "type.plugin.name", - AddonManager.VIEW_TYPE_LIST, - 6000, - AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE - ), -]); +GMPProvider.addObserver(); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js b/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js index a017a22c1c37..d27cb5f571c1 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js @@ -58,6 +58,11 @@ MockGMPInstallManager.prototype = { add_task(async function setup() { createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); + + // The GMPProvider does not register until the first content process + // is launched, so we simulate that by firing this notification. + Services.obs.notifyObservers(null, "ipc:first-content-process-created"); + await promiseStartupManager(); gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_LOGGING_DUMP, true);