From 506e1ad07abd78925b6305f566985e4ca343ce86 Mon Sep 17 00:00:00 2001 From: Qeole Date: Mon, 25 Aug 2014 17:23:34 +0200 Subject: [PATCH] Bug 1045209 - Remove media.gmp-gmpopenh264.path pref and set install path for OpenH264 plugin to //. r=unfocused,jesup Certain usage scenarios, like enterprise roaming profile setups, lead to the installed OpenH264 plugin not being found anymore. We install the plugin into the profile directory, so the fix here is to just store the install path relative the profile and not an absolute path. We also now store the plugin in a version-specific subdirectory, which avoids further issues like e.g. Windows preventing updates due to locking loaded DLLs. --- content/media/gmp/GMPChild.cpp | 14 +++-- content/media/gmp/GMPParent.cpp | 17 +++++-- toolkit/modules/GMPInstallManager.jsm | 11 ++-- .../extensions/internal/OpenH264Provider.jsm | 51 +++++++++++-------- 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/content/media/gmp/GMPChild.cpp b/content/media/gmp/GMPChild.cpp index 1dde3ac7c8d..12c88cf614d 100644 --- a/content/media/gmp/GMPChild.cpp +++ b/content/media/gmp/GMPChild.cpp @@ -69,11 +69,19 @@ GetPluginFile(const std::string& aPluginPath, } #endif - nsAutoString leafName; - if (NS_FAILED(aLibFile->GetLeafName(leafName))) { + nsCOMPtr parent; + rv = aLibFile->GetParent(getter_AddRefs(parent)); + if (NS_FAILED(rv)) { return false; } - nsAutoString baseName(Substring(leafName, 4, leafName.Length() - 1)); + + nsAutoString parentLeafName; + rv = parent->GetLeafName(parentLeafName); + if (NS_FAILED(rv)) { + return false; + } + + nsAutoString baseName(Substring(parentLeafName, 4, parentLeafName.Length() - 1)); #if defined(XP_MACOSX) nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".dylib"); diff --git a/content/media/gmp/GMPParent.cpp b/content/media/gmp/GMPParent.cpp index aa60acfa221..90878ca14f5 100644 --- a/content/media/gmp/GMPParent.cpp +++ b/content/media/gmp/GMPParent.cpp @@ -90,16 +90,23 @@ GMPParent::Init(GeckoMediaPluginService *aService, nsIFile* aPluginDir) mService = aService; mDirectory = aPluginDir; - nsAutoString leafname; - nsresult rv = aPluginDir->GetLeafName(leafname); + // aPluginDir is // + // where should be gmp-gmpopenh264 + nsCOMPtr parent; + nsresult rv = aPluginDir->GetParent(getter_AddRefs(parent)); + if (NS_FAILED(rv)) { + return rv; + } + nsAutoString parentLeafName; + rv = parent->GetLeafName(parentLeafName); if (NS_FAILED(rv)) { return rv; } LOGD(("%s::%s: %p for %s", __CLASS__, __FUNCTION__, this, - NS_LossyConvertUTF16toASCII(leafname).get())); + NS_LossyConvertUTF16toASCII(parentLeafName).get())); - MOZ_ASSERT(leafname.Length() > 4); - mName = Substring(leafname, 4); + MOZ_ASSERT(parentLeafName.Length() > 4); + mName = Substring(parentLeafName, 4); return ReadGMPMetaData(); } diff --git a/toolkit/modules/GMPInstallManager.jsm b/toolkit/modules/GMPInstallManager.jsm index 95934923def..470384b5ba3 100644 --- a/toolkit/modules/GMPInstallManager.jsm +++ b/toolkit/modules/GMPInstallManager.jsm @@ -107,7 +107,6 @@ let GMPPrefs = { */ KEY_LOG_ENABLED: "media.gmp-manager.log", KEY_ADDON_LAST_UPDATE: "media.{0}.lastUpdate", - KEY_ADDON_PATH: "media.{0}.path", KEY_ADDON_VERSION: "media.{0}.version", KEY_ADDON_AUTOUPDATE: "media.{0}.autoupdate", KEY_URL: "media.gmp-manager.url", @@ -889,7 +888,9 @@ GMPDownloader.prototype = { let gmpAddon = this._gmpAddon; let installToDirPath = Cc["@mozilla.org/file/local;1"]. createInstance(Ci.nsIFile); - let path = OS.Path.join(OS.Constants.Path.profileDir, gmpAddon.id); + let path = OS.Path.join(OS.Constants.Path.profileDir, + gmpAddon.id, + gmpAddon.version); installToDirPath.initWithPath(path); log.info("install to directory path: " + installToDirPath.path); let gmpInstaller = new GMPExtractor(zipPath, installToDirPath.path); @@ -898,12 +899,10 @@ GMPDownloader.prototype = { // Success, set the prefs let now = Math.round(Date.now() / 1000); GMPPrefs.set(GMPPrefs.KEY_ADDON_LAST_UPDATE, now, gmpAddon.id); - // Setting the path pref signals installation completion to consumers, - // so set the version and potential other information they use first. + // Setting the version pref signals installation completion to consumers, + // if you need to set other prefs etc. do it before this. GMPPrefs.set(GMPPrefs.KEY_ADDON_VERSION, gmpAddon.version, gmpAddon.id); - GMPPrefs.set(GMPPrefs.KEY_ADDON_PATH, - installToDirPath.path, gmpAddon.id); this._deferred.resolve(extractedPaths); }, err => { this._deferred.reject(err); diff --git a/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm b/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm index 1f3a0b1eb47..93517bec8da 100644 --- a/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm +++ b/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm @@ -29,7 +29,6 @@ const SEC_IN_A_DAY = 24 * 60 * 60; const OPENH264_PLUGIN_ID = "gmp-gmpopenh264"; const OPENH264_PREF_BRANCH = "media." + OPENH264_PLUGIN_ID + "."; const OPENH264_PREF_ENABLED = "enabled"; -const OPENH264_PREF_PATH = "path"; const OPENH264_PREF_VERSION = "version"; const OPENH264_PREF_LASTUPDATE = "lastUpdate"; const OPENH264_PREF_AUTOUPDATE = "autoupdate"; @@ -94,12 +93,7 @@ let OpenH264Wrapper = { get description() { return pluginsBundle.GetStringFromName("openH264_description"); }, - get version() { - if (this.isInstalled) { - return prefs.get(OPENH264_PREF_VERSION, ""); - } - return ""; - }, + get version() { return prefs.get(OPENH264_PREF_VERSION, ""); }, get isActive() { return !this.userDisabled; }, get appDisabled() { return false; }, @@ -223,17 +217,24 @@ let OpenH264Wrapper = { get pluginMimeTypes() { return []; }, get pluginLibraries() { - let path = prefs.get(OPENH264_PREF_PATH, null); - return path && path.length ? [OS.Path.basename(path)] : []; + if (this.isInstalled) { + let path = this.version; + return [path]; + } + return []; }, get pluginFullpath() { - let path = prefs.get(OPENH264_PREF_PATH, null); - return path && path.length ? [path] : []; + if (this.isInstalled) { + let path = OS.Path.join(OS.Constants.Path.profileDir, + OPENH264_PLUGIN_ID, + this.version); + return [path]; + } + return []; }, get isInstalled() { - let path = prefs.get(OPENH264_PREF_PATH, ""); - return path.length > 0; + return this.version.length > 0; }, }; @@ -244,14 +245,19 @@ let OpenH264Provider = { "OpenH264Provider" + "::"); OpenH264Wrapper._log = Log.repository.getLoggerWithMessagePrefix("Toolkit.OpenH264Provider", "OpenH264Wrapper" + "::"); - this.gmpPath = prefs.get(OPENH264_PREF_PATH, null); + this.gmpPath = null; + if (OpenH264Wrapper.isInstalled) { + this.gmpPath = OS.Path.join(OS.Constants.Path.profileDir, + OPENH264_PLUGIN_ID, + prefs.get(OPENH264_PREF_VERSION, null)); + } let enabled = prefs.get(OPENH264_PREF_ENABLED, true); this._log.trace("startup() - enabled=" + enabled + ", gmpPath="+this.gmpPath); Services.obs.addObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, false); prefs.observe(OPENH264_PREF_ENABLED, this.onPrefEnabledChanged, this); - prefs.observe(OPENH264_PREF_PATH, this.onPrefPathChanged, this); + prefs.observe(OPENH264_PREF_VERSION, this.onPrefVersionChanged, this); prefs.observe(OPENH264_PREF_LOGGING, configureLogging); if (this.gmpPath && enabled) { @@ -264,7 +270,7 @@ let OpenH264Provider = { this._log.trace("shutdown()"); Services.obs.removeObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED); prefs.ignore(OPENH264_PREF_ENABLED, this.onPrefEnabledChanged, this); - prefs.ignore(OPENH264_PREF_PATH, this.onPrefPathChanged, this); + prefs.ignore(OPENH264_PREF_VERSION, this.onPrefVersionChanged, this); prefs.ignore(OPENH264_PREF_LOGGING, configureLogging); return OpenH264Wrapper._updateTask; @@ -290,20 +296,25 @@ let OpenH264Provider = { wrapper); }, - onPrefPathChanged: function() { + onPrefVersionChanged: function() { let wrapper = OpenH264Wrapper; AddonManagerPrivate.callAddonListeners("onUninstalling", wrapper, false); if (this.gmpPath) { - this._log.info("onPrefPathChanged() - removing gmp directory " + this.gmpPath); + this._log.info("onPrefVersionChanged() - unregistering gmp directory " + this.gmpPath); gmpService.removePluginDirectory(this.gmpPath); } AddonManagerPrivate.callAddonListeners("onUninstalled", wrapper); AddonManagerPrivate.callInstallListeners("onExternalInstall", null, wrapper, null, false); - this.gmpPath = prefs.get(OPENH264_PREF_PATH, null); + this.gmpPath = null; + if (OpenH264Wrapper.isInstalled) { + this.gmpPath = OS.Path.join(OS.Constants.Path.profileDir, + OPENH264_PLUGIN_ID, + prefs.get(OPENH264_PREF_VERSION, null)); + } if (this.gmpPath && wrapper.isActive) { - this._log.info("onPrefPathChanged() - adding gmp directory " + this.gmpPath); + this._log.info("onPrefVersionChanged() - registering gmp directory " + this.gmpPath); gmpService.addPluginDirectory(this.gmpPath); } AddonManagerPrivate.callAddonListeners("onInstalled", wrapper);