Bug 1146201 - Initiate check for GMP updates when JS requests CDM and we haven't installed it yet. r=spohl a=sylvestre
authorChris Pearce <cpearce@mozilla.com>
Tue, 31 Mar 2015 20:50:01 +1300
changeset 258237 9383010b69fe
parent 258236 b7e7470e83b3
child 258238 7a04aad0ab5d
push id4625
push usercpearce@mozilla.com
push date2015-04-03 06:37 +0000
treeherdermozilla-beta@c481e8a84a6c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl, sylvestre
bugs1146201
milestone38.0
Bug 1146201 - Initiate check for GMP updates when JS requests CDM and we haven't installed it yet. r=spohl a=sylvestre
toolkit/mozapps/extensions/internal/GMPProvider.jsm
--- a/toolkit/mozapps/extensions/internal/GMPProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/GMPProvider.jsm
@@ -102,16 +102,17 @@ function GMPWrapper(aPluginInfo) {
                                           this._plugin.id),
                       this.onPrefEnabledChanged, this);
   Preferences.observe(GMPPrefs.getPrefKey(GMPPrefs.KEY_PLUGIN_VERSION,
                                           this._plugin.id),
                       this.onPrefVersionChanged, this);
   if (this._plugin.isEME) {
     Preferences.observe(GMPPrefs.KEY_EME_ENABLED,
                         this.onPrefEMEGlobalEnabledChanged, this);
+    Services.obs.addObserver(this, "mediakeys-request", false);
   }
 }
 
 GMPWrapper.prototype = {
   // An active task that checks for plugin updates and installs them.
   _updateTask: null,
   _gmpPath: null,
   _isUpdateCheckPending: false,
@@ -333,37 +334,56 @@ GMPWrapper.prototype = {
                                            ["appDisabled"]);
     if (this.appDisabled) {
       this.uninstallPlugin();
     } else {
       AddonManagerPrivate.callInstallListeners("onExternalInstall", null, this,
                                                null, false);
       AddonManagerPrivate.callAddonListeners("onInstalling", this, false);
       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);
-      }
+      this.checkForUpdates(GMP_CHECK_DELAY);
     }
     if (!this.userDisabled) {
       this._handleEnabledChanged();
     }
   },
 
+  checkForUpdates: function(delay) {
+    if (this._isUpdateCheckPending) {
+      return;
+    }
+    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;
+    }, delay);
+  },
+
+  observe: function(subject, topic, data) {
+    let parsedData;
+    try {
+      parsedData = JSON.parse(data);
+    } catch(ex) {
+      this._log.error("Malformed EME video message with data: " + data);
+      return;
+    }
+    let {status: status, keySystem: keySystem} = parsedData;
+    if (status == "cdm-not-installed" || status == "cdm-insufficient-version") {
+      this.checkForUpdates(0);
+    }
+  },
+
   onPrefEnabledChanged: function() {
     if (!this._plugin.isEME || !this.appDisabled) {
       this._handleEnabledChanged();
     }
   },
 
   onPrefVersionChanged: function() {
     AddonManagerPrivate.callAddonListeners("onUninstalling", this, false);
@@ -408,16 +428,17 @@ GMPWrapper.prototype = {
                                            this._plugin.id),
                        this.onPrefEnabledChanged, this);
     Preferences.ignore(GMPPrefs.getPrefKey(GMPPrefs.KEY_PLUGIN_VERSION,
                                            this._plugin.id),
                        this.onPrefVersionChanged, this);
     if (this._plugin.isEME) {
       Preferences.ignore(GMPPrefs.KEY_EME_ENABLED,
                          this.onPrefEMEGlobalEnabledChanged, this);
+      Services.obs.removeObserver(this, "mediakeys-request", false);
     }
     return this._updateTask;
   },
 };
 
 let GMPProvider = {
   get name() { return "GMPProvider"; },