| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/component_updater/widevine_cdm_component_installer.h" | 5 #include "chrome/browser/component_updater/widevine_cdm_component_installer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/base_paths.h" | 14 #include "base/base_paths.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 22 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 25 #include "base/strings/string_util.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/widevine_cdm_constants.h" | 30 #include "chrome/common/widevine_cdm_constants.h" |
| 30 #include "components/component_updater/component_updater_service.h" | 31 #include "components/component_updater/component_updater_service.h" |
| 31 #include "components/component_updater/default_component_installer.h" | 32 #include "components/component_updater/default_component_installer.h" |
| 32 #include "components/version_info/version_info.h" | 33 #include "components/version_info/version_info.h" |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/plugin_service.h" | 35 #include "content/public/browser/plugin_service.h" |
| 36 #include "content/public/common/key_system_service.h" |
| 35 #include "content/public/common/pepper_plugin_info.h" | 37 #include "content/public/common/pepper_plugin_info.h" |
| 36 #include "media/cdm/supported_cdm_versions.h" | 38 #include "media/cdm/supported_cdm_versions.h" |
| 37 #include "third_party/widevine/cdm/widevine_cdm_common.h" | 39 #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 38 | 40 |
| 39 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT | 41 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT |
| 40 | 42 |
| 41 using content::BrowserThread; | 43 using content::BrowserThread; |
| 44 using content::KeySystemService; |
| 42 using content::PluginService; | 45 using content::PluginService; |
| 43 | 46 |
| 44 namespace component_updater { | 47 namespace component_updater { |
| 45 | 48 |
| 46 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 49 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 47 | 50 |
| 48 namespace { | 51 namespace { |
| 49 | 52 |
| 50 // CRX hash. The extension id is: oimompecagnajdejgnnjijobebaeigek. | 53 // CRX hash. The extension id is: oimompecagnajdejgnnjijobebaeigek. |
| 51 const uint8_t kSha2Hash[] = {0xe8, 0xce, 0xcf, 0x42, 0x06, 0xd0, 0x93, 0x49, | 54 const uint8_t kSha2Hash[] = {0xe8, 0xce, 0xcf, 0x42, 0x06, 0xd0, 0x93, 0x49, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Widevine CDM is packaged as a multi-CRX. Widevine CDM binaries are located in | 105 // Widevine CDM is packaged as a multi-CRX. Widevine CDM binaries are located in |
| 103 // _platform_specific/<platform_arch> folder in the package. This function | 106 // _platform_specific/<platform_arch> folder in the package. This function |
| 104 // returns the platform-specific subdirectory that is part of that multi-CRX. | 107 // returns the platform-specific subdirectory that is part of that multi-CRX. |
| 105 base::FilePath GetPlatformDirectory(const base::FilePath& base_path) { | 108 base::FilePath GetPlatformDirectory(const base::FilePath& base_path) { |
| 106 std::string platform_arch = kWidevineCdmPlatform; | 109 std::string platform_arch = kWidevineCdmPlatform; |
| 107 platform_arch += '_'; | 110 platform_arch += '_'; |
| 108 platform_arch += kWidevineCdmArch; | 111 platform_arch += kWidevineCdmArch; |
| 109 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch); | 112 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch); |
| 110 } | 113 } |
| 111 | 114 |
| 112 bool MakeWidevineCdmPluginInfo( | 115 bool MakeWidevineCdmPluginInfo(const base::Version& version, |
| 113 const base::Version& version, | 116 const base::FilePath& path, |
| 114 const base::FilePath& path, | 117 base::string16 codecs, |
| 115 const std::vector<base::string16>& additional_param_names, | 118 content::PepperPluginInfo* plugin_info) { |
| 116 const std::vector<base::string16>& additional_param_values, | |
| 117 content::PepperPluginInfo* plugin_info) { | |
| 118 if (!version.IsValid() || | 119 if (!version.IsValid() || |
| 119 version.components().size() != | 120 version.components().size() != |
| 120 static_cast<size_t>(kWidevineCdmVersionNumComponents)) { | 121 static_cast<size_t>(kWidevineCdmVersionNumComponents)) { |
| 121 return false; | 122 return false; |
| 122 } | 123 } |
| 123 | 124 |
| 124 plugin_info->is_internal = false; | 125 plugin_info->is_internal = false; |
| 125 // Widevine CDM must run out of process. | 126 // Widevine CDM must run out of process. |
| 126 plugin_info->is_out_of_process = true; | 127 plugin_info->is_out_of_process = true; |
| 127 plugin_info->path = path; | 128 plugin_info->path = path; |
| 128 plugin_info->name = kWidevineCdmDisplayName; | 129 plugin_info->name = kWidevineCdmDisplayName; |
| 129 plugin_info->description = kWidevineCdmDescription + | 130 plugin_info->description = kWidevineCdmDescription + |
| 130 std::string(" (version: ") + version.GetString() + | 131 std::string(" (version: ") + version.GetString() + |
| 131 ")"; | 132 ")"; |
| 132 plugin_info->version = version.GetString(); | 133 plugin_info->version = version.GetString(); |
| 133 content::WebPluginMimeType widevine_cdm_mime_type( | 134 content::WebPluginMimeType widevine_cdm_mime_type( |
| 134 kWidevineCdmPluginMimeType, | 135 kWidevineCdmPluginMimeType, |
| 135 kWidevineCdmPluginExtension, | 136 kWidevineCdmPluginExtension, |
| 136 kWidevineCdmPluginMimeTypeDescription); | 137 kWidevineCdmPluginMimeTypeDescription); |
| 137 widevine_cdm_mime_type.additional_param_names = additional_param_names; | 138 widevine_cdm_mime_type.additional_param_names->push_back( |
| 138 widevine_cdm_mime_type.additional_param_values = additional_param_values; | 139 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)); |
| 140 widevine_cdm_mime_type.additional_param_values->push_back(codecs); |
| 141 |
| 139 plugin_info->mime_types.push_back(widevine_cdm_mime_type); | 142 plugin_info->mime_types.push_back(widevine_cdm_mime_type); |
| 140 plugin_info->permissions = kWidevineCdmPluginPermissions; | 143 plugin_info->permissions = kWidevineCdmPluginPermissions; |
| 141 | 144 |
| 142 return true; | 145 return true; |
| 143 } | 146 } |
| 144 | 147 |
| 145 typedef bool (*VersionCheckFunc)(int version); | 148 typedef bool (*VersionCheckFunc)(int version); |
| 146 | 149 |
| 147 bool CheckForCompatibleVersion(const base::DictionaryValue& manifest, | 150 bool CheckForCompatibleVersion(const base::DictionaryValue& manifest, |
| 148 const std::string version_name, | 151 const std::string version_name, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 179 kCdmModuleVersionsName, | 182 kCdmModuleVersionsName, |
| 180 media::IsSupportedCdmModuleVersion) && | 183 media::IsSupportedCdmModuleVersion) && |
| 181 CheckForCompatibleVersion(manifest, | 184 CheckForCompatibleVersion(manifest, |
| 182 kCdmInterfaceVersionsName, | 185 kCdmInterfaceVersionsName, |
| 183 media::IsSupportedCdmInterfaceVersion) && | 186 media::IsSupportedCdmInterfaceVersion) && |
| 184 CheckForCompatibleVersion(manifest, | 187 CheckForCompatibleVersion(manifest, |
| 185 kCdmHostVersionsName, | 188 kCdmHostVersionsName, |
| 186 media::IsSupportedCdmHostVersion); | 189 media::IsSupportedCdmHostVersion); |
| 187 } | 190 } |
| 188 | 191 |
| 189 void GetAdditionalParams(const base::DictionaryValue& manifest, | 192 void GetCodecs(const base::DictionaryValue& manifest) { |
| 190 std::vector<base::string16>* additional_param_names, | |
| 191 std::vector<base::string16>* additional_param_values) { | |
| 192 base::string16 codecs; | 193 base::string16 codecs; |
| 193 if (manifest.GetString(kCdmCodecsListName, &codecs)) { | 194 if (manifest.GetString(kCdmCodecsListName, &codecs)) { |
| 194 DLOG_IF(WARNING, codecs.empty()) | 195 DLOG_IF(WARNING, codecs.empty()) |
| 195 << "Widevine CDM component manifest has empty codecs list"; | 196 << "Widevine CDM component manifest has empty codecs list"; |
| 196 additional_param_names->push_back( | 197 return codecs; |
| 197 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)); | |
| 198 additional_param_values->push_back(codecs); | |
| 199 } else { | |
| 200 DLOG(WARNING) << "Widevine CDM component manifest is missing codecs"; | |
| 201 } | 198 } |
| 199 |
| 200 DLOG(WARNING) << "Widevine CDM component manifest is missing codecs"; |
| 201 return base::string16(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void RegisterWidevineCdmWithChrome(const base::Version& cdm_version, | 204 void RegisterWidevineCdmWithChrome(const base::Version& cdm_version, |
| 205 const base::FilePath& adapter_install_path, | 205 const base::FilePath& adapter_install_path, |
| 206 scoped_ptr<base::DictionaryValue> manifest) { | 206 scoped_ptr<base::DictionaryValue> manifest) { |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 208 std::vector<base::string16> additional_param_names; | 208 base::string16 codecs = GetCodecs(*manifest); |
| 209 std::vector<base::string16> additional_param_values; | |
| 210 GetAdditionalParams( | |
| 211 *manifest, &additional_param_names, &additional_param_values); | |
| 212 content::PepperPluginInfo plugin_info; | 209 content::PepperPluginInfo plugin_info; |
| 213 if (!MakeWidevineCdmPluginInfo(cdm_version, | 210 if (!MakeWidevineCdmPluginInfo(cdm_version, adapter_install_path, codecs, |
| 214 adapter_install_path, | |
| 215 additional_param_names, | |
| 216 additional_param_values, | |
| 217 &plugin_info)) { | 211 &plugin_info)) { |
| 218 return; | 212 return; |
| 219 } | 213 } |
| 220 | 214 |
| 221 // true = Add to beginning of list to override any existing registrations. | 215 // true = Add to beginning of list to override any existing registrations. |
| 222 PluginService::GetInstance()->RegisterInternalPlugin( | 216 PluginService::GetInstance()->RegisterInternalPlugin( |
| 223 plugin_info.ToWebPluginInfo(), true); | 217 plugin_info.ToWebPluginInfo(), true); |
| 224 // Tell the browser to refresh the plugin list. Then tell all renderers to | 218 // Tell the browser to refresh the plugin list. Then tell all renderers to |
| 225 // update their plugin list caches. | 219 // update their plugin list caches. |
| 226 PluginService::GetInstance()->RefreshPlugins(); | 220 PluginService::GetInstance()->RefreshPlugins(); |
| 227 PluginService::GetInstance()->PurgePluginListCache(NULL, false); | 221 PluginService::GetInstance()->PurgePluginListCache(NULL, false); |
| 222 |
| 223 // Also register Widevine with the KeySystemService. It needs |path| to be |
| 224 // the actual Widevine library, not the adapter, so adjust as necessary. It |
| 225 // will be in the same directory as the installed adapter. |
| 226 KeySystemService::GetInstance()->Register( |
| 227 kWidevineKeySystem, |
| 228 adapter_install_path.DirName().AppendASCII(kWidevineCdmFileName), codecs); |
| 228 } | 229 } |
| 229 | 230 |
| 230 } // namespace | 231 } // namespace |
| 231 | 232 |
| 232 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits { | 233 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits { |
| 233 public: | 234 public: |
| 234 WidevineCdmComponentInstallerTraits(); | 235 WidevineCdmComponentInstallerTraits(); |
| 235 ~WidevineCdmComponentInstallerTraits() override {} | 236 ~WidevineCdmComponentInstallerTraits() override {} |
| 236 | 237 |
| 237 private: | 238 private: |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 scoped_ptr<ComponentInstallerTraits> traits( | 371 scoped_ptr<ComponentInstallerTraits> traits( |
| 371 new WidevineCdmComponentInstallerTraits); | 372 new WidevineCdmComponentInstallerTraits); |
| 372 // |cus| will take ownership of |installer| during installer->Register(cus). | 373 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 373 DefaultComponentInstaller* installer = | 374 DefaultComponentInstaller* installer = |
| 374 new DefaultComponentInstaller(std::move(traits)); | 375 new DefaultComponentInstaller(std::move(traits)); |
| 375 installer->Register(cus, base::Closure()); | 376 installer->Register(cus, base::Closure()); |
| 376 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 377 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 377 } | 378 } |
| 378 | 379 |
| 379 } // namespace component_updater | 380 } // namespace component_updater |
| OLD | NEW |