Bug 1145694: Uninstall Adobe EME when media.eme.enabled is set to false. r=mossop
authorStephen Pohl <spohl.mozilla.bugs@gmail.com>
Sun, 22 Mar 2015 23:12:16 -0400
changeset 265324 017d9b8dc6330863b42e15a1f2fe588d56493593
parent 265323 181e52c05fe0e8b1f057a999a367d9db36803036
child 265325 f99eb0b983d611b136dc168fc0049ae57e6773b7
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1145694
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1145694: Uninstall Adobe EME when media.eme.enabled is set to false. r=mossop
toolkit/modules/GMPUtils.jsm
toolkit/mozapps/extensions/internal/GMPProvider.jsm
toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js
toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
--- a/toolkit/modules/GMPUtils.jsm
+++ b/toolkit/modules/GMPUtils.jsm
@@ -79,17 +79,16 @@ this.GMPPrefs = {
   KEY_CERT_REQUIREBUILTIN:      "media.gmp-manager.cert.requireBuiltIn",
   KEY_UPDATE_LAST_CHECK:        "media.gmp-manager.lastCheck",
   KEY_SECONDS_BETWEEN_CHECKS:   "media.gmp-manager.secondsBetweenChecks",
   KEY_APP_DISTRIBUTION:         "distribution.id",
   KEY_APP_DISTRIBUTION_VERSION: "distribution.version",
   KEY_BUILDID:                  "media.gmp-manager.buildID",
   KEY_CERTS_BRANCH:             "media.gmp-manager.certs.",
   KEY_PROVIDER_ENABLED:         "media.gmp-provider.enabled",
-  KEY_PROVIDER_LASTCHECK:       "media.gmp-manager.lastCheck",
   KEY_LOG_BASE:                 "media.gmp.log.",
   KEY_LOGGING_LEVEL:            this.KEY_LOG_BASE + "level",
   KEY_LOGGING_DUMP:             this.KEY_LOG_BASE + "dump",
 
   /**
    * Obtains the specified preference in relation to the specified plugin.
    * @param aKey The preference key value to use.
    * @param aDefaultValue The default value if no preference exists.
--- a/toolkit/mozapps/extensions/internal/GMPProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/GMPProvider.jsm
@@ -16,21 +16,25 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/GMPUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(
   this, "GMPInstallManager", "resource://gre/modules/GMPInstallManager.jsm");
+XPCOMUtils.defineLazyModuleGetter(
+  this, "setTimeout", "resource://gre/modules/Timer.jsm");
 
 const URI_EXTENSION_STRINGS  = "chrome://mozapps/locale/extensions/extensions.properties";
 const STRING_TYPE_NAME       = "type.%ID%.name";
 
 const SEC_IN_A_DAY           = 24 * 60 * 60;
+// How long to wait after a user enabled EME before attempting to download CDMs.
+const GMP_CHECK_DELAY        = 10 * 1000; // milliseconds
 
 const NS_GRE_DIR             = "GreD";
 const CLEARKEY_PLUGIN_ID     = "gmp-clearkey";
 const CLEARKEY_VERSION       = "0.1";
 
 const GMP_LICENSE_INFO       = "gmp_license_info";
 const GMP_LEARN_MORE         = "learn_more_label";
 
@@ -111,16 +115,17 @@ function GMPWrapper(aPluginInfo) {
                         this.onPrefEMEGlobalEnabledChanged, this);
   }
 }
 
 GMPWrapper.prototype = {
   // An active task that checks for plugin updates and installs them.
   _updateTask: null,
   _gmpPath: null,
+  _isUpdateCheckPending: false,
 
   optionsType: AddonManager.OPTIONS_TYPE_INLINE,
   get optionsURL() { return this._plugin.optionsURL; },
 
   set gmpPath(aPath) { this._gmpPath = aPath; },
   get gmpPath() {
     if (!this._gmpPath && this.isInstalled) {
       this._gmpPath = OS.Path.join(OS.Constants.Path.profileDir,
@@ -234,17 +239,17 @@ GMPWrapper.prototype = {
     if (aReason === AddonManager.UPDATE_WHEN_PERIODIC_UPDATE) {
       if (!AddonManager.shouldAutoUpdate(this)) {
         this._log.trace("findUpdates() - " + this._plugin.id +
                         " - no autoupdate");
         return Promise.resolve(false);
       }
 
       let secSinceLastCheck =
-        Date.now() / 1000 - Preferences.get(GMPPrefs.KEY_PROVIDER_LASTCHECK, 0);
+        Date.now() / 1000 - Preferences.get(GMPPrefs.KEY_UPDATE_LAST_CHECK, 0);
       if (secSinceLastCheck <= SEC_IN_A_DAY) {
         this._log.trace("findUpdates() - " + this._plugin.id +
                         " - last check was less then a day ago");
         return Promise.resolve(false);
       }
     } else if (aReason !== AddonManager.UPDATE_WHEN_USER_REQUESTED) {
       this._log.trace("findUpdates() - " + this._plugin.id +
                       " - the given reason to update is not supported");
@@ -332,29 +337,40 @@ GMPWrapper.prototype = {
   onPrefEMEGlobalEnabledChanged: function() {
     AddonManagerPrivate.callAddonListeners("onPropertyChanged", this,
                                            ["appDisabled"]);
     if (this.appDisabled) {
       AddonManagerPrivate.callAddonListeners("onUninstalling", this, false);
       if (this._gmpPath) {
         this._log.info("onPrefEMEGlobalEnabledChanged() - unregistering gmp " +
                        "directory " + this._gmpPath);
-        gmpService.removePluginDirectory(this._gmpPath);
+        gmpService.removeAndDeletePluginDirectory(this._gmpPath);
       }
+      GMPPrefs.reset(GMPPrefs.KEY_PLUGIN_VERSION, this.id);
       AddonManagerPrivate.callAddonListeners("onUninstalled", this);
     } else {
       AddonManagerPrivate.callInstallListeners("onExternalInstall", null, this,
                                                null, false);
       AddonManagerPrivate.callAddonListeners("onInstalling", this, false);
-      if (this._gmpPath && this.isActive) {
-        this._log.info("onPrefEMEGlobalEnabledChanged() - registering gmp " +
-                       "directory " + this._gmpPath);
-        gmpService.addPluginDirectory(this._gmpPath);
+      AddonManagerPrivate.callAddonListeners("onInstalled", this);
+      if (!this._isUpdateCheckPending) {
+        this._isUpdateCheckPending = true;
+        GMPPrefs.reset(GMPPrefs.KEY_UPDATE_LAST_CHECK, null);
+        // Delay this in case the user changes his mind and doesn't want to
+        // enable EME after all.
+        setTimeout(() => {
+          if (!this.appDisabled) {
+            let gmpInstallManager = new GMPInstallManager();
+            // We don't really care about the results, if someone is interested
+            // they can check the log.
+            gmpInstallManager.simpleCheckAndInstall().then(null, () => {});
+          }
+          this._isUpdateCheckPending = false;
+        }, GMP_CHECK_DELAY);
       }
-      AddonManagerPrivate.callAddonListeners("onInstalled", this);
     }
     if (!this.userDisabled) {
       this._handleEnabledChanged();
     }
   },
 
   onPrefEnabledChanged: function() {
     if (!this._plugin.isEME || !this.appDisabled) {
--- a/toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js
@@ -95,17 +95,17 @@ add_task(function* initializeState() {
       gPrefs.clearUserPref(getKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id));
       gPrefs.clearUserPref(getKey(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, addon.id));
       gPrefs.clearUserPref(getKey(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id));
       gPrefs.clearUserPref(getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id));
       gPrefs.clearUserPref(getKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCEVISIBLE, addon.id));
     }
     gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_LOGGING_DUMP);
     gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_LOGGING_LEVEL);
-    gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_PROVIDER_LASTCHECK);
+    gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK);
     gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_EME_ENABLED);
     yield GMPScope.GMPProvider.shutdown();
     GMPScope.GMPProvider.startup();
   }));
 
   let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
   gIsEnUsLocale = chrome.getSelectedLocale("global") == "en-US";
 
@@ -319,17 +319,17 @@ add_task(function* testPreferencesButton
       yield deferred.promise;
 
       is(gOptionsObserver.lastDisplayed, addon.id);
     }
   }
 });
 
 add_task(function* testUpdateButton() {
-  gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_PROVIDER_LASTCHECK);
+  gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK);
 
   let originalInstallManager = GMPScope.GMPInstallManager;
   Object.defineProperty(GMPScope, "GMPInstallManager", {
     value: MockGMPInstallManager,
     writable: true,
     enumerable: true,
     configurable: true
   });
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
@@ -303,28 +303,28 @@ add_task(function* test_periodicUpdate()
 
   let addons = yield promiseAddonsByIDs([...gMockAddons.keys()]);
   Assert.equal(addons.length, gMockAddons.size);
 
   for (let addon of addons) {
     gPrefs.clearUserPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id));
 
     addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE;
-    gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_PROVIDER_LASTCHECK, 0);
+    gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK, 0);
     let result =
       yield addon.findUpdates({}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
     Assert.strictEqual(result, false);
 
     addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
-    gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_PROVIDER_LASTCHECK, Date.now() / 1000 - 60);
+    gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK, Date.now() / 1000 - 60);
     result =
       yield addon.findUpdates({}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
     Assert.strictEqual(result, false);
 
-    gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_PROVIDER_LASTCHECK,
+    gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK,
                      Date.now() / 1000 - 2 * GMPScope.SEC_IN_A_DAY);
     gInstalledAddonId = "";
     result =
       yield addon.findUpdates({}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
     Assert.strictEqual(result, true);
     Assert.equal(gInstalledAddonId, addon.id);
   }