| 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> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch); | 112 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch); |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool MakeWidevineCdmPluginInfo(const base::Version& version, | 115 bool MakeWidevineCdmPluginInfo(const base::Version& version, |
| 116 const base::FilePath& cdm_install_dir, | 116 const base::FilePath& cdm_install_dir, |
| 117 const std::string& codecs, | 117 const std::string& codecs, |
| 118 content::PepperPluginInfo* plugin_info) { | 118 content::PepperPluginInfo* plugin_info) { |
| 119 if (!version.IsValid() || | 119 if (!version.IsValid() || |
| 120 version.components().size() != | 120 version.components().size() != |
| 121 static_cast<size_t>(kWidevineCdmVersionNumComponents)) { | 121 static_cast<size_t>(kWidevineCdmVersionNumComponents)) { |
| 122 DVLOG(1) << "Invalid version."; |
| 122 return false; | 123 return false; |
| 123 } | 124 } |
| 124 | 125 |
| 125 plugin_info->is_internal = false; | 126 plugin_info->is_internal = false; |
| 126 // Widevine CDM must run out of process. | 127 // Widevine CDM must run out of process. |
| 127 plugin_info->is_out_of_process = true; | 128 plugin_info->is_out_of_process = true; |
| 128 plugin_info->path = GetPlatformDirectory(cdm_install_dir) | 129 plugin_info->path = GetPlatformDirectory(cdm_install_dir) |
| 129 .AppendASCII(kWidevineCdmAdapterFileName); | 130 .AppendASCII(kWidevineCdmAdapterFileName); |
| 130 plugin_info->name = kWidevineCdmDisplayName; | 131 plugin_info->name = kWidevineCdmDisplayName; |
| 131 plugin_info->description = kWidevineCdmDescription + | 132 plugin_info->description = kWidevineCdmDescription + |
| (...skipping 15 matching lines...) Expand all Loading... |
| 147 return true; | 148 return true; |
| 148 } | 149 } |
| 149 | 150 |
| 150 typedef bool (*VersionCheckFunc)(int version); | 151 typedef bool (*VersionCheckFunc)(int version); |
| 151 | 152 |
| 152 bool CheckForCompatibleVersion(const base::DictionaryValue& manifest, | 153 bool CheckForCompatibleVersion(const base::DictionaryValue& manifest, |
| 153 const std::string version_name, | 154 const std::string version_name, |
| 154 VersionCheckFunc version_check_func) { | 155 VersionCheckFunc version_check_func) { |
| 155 std::string versions_string; | 156 std::string versions_string; |
| 156 if (!manifest.GetString(version_name, &versions_string)) { | 157 if (!manifest.GetString(version_name, &versions_string)) { |
| 157 DLOG(WARNING) << "Widevine CDM component manifest missing " << version_name; | 158 DVLOG(1) << "Widevine CDM component manifest missing " << version_name; |
| 158 return false; | 159 return false; |
| 159 } | 160 } |
| 160 DLOG_IF(WARNING, versions_string.empty()) | 161 DVLOG_IF(1, versions_string.empty()) |
| 161 << "Widevine CDM component manifest has empty " << version_name; | 162 << "Widevine CDM component manifest has empty " << version_name; |
| 162 | 163 |
| 163 for (const base::StringPiece& ver_str : base::SplitStringPiece( | 164 for (const base::StringPiece& ver_str : base::SplitStringPiece( |
| 164 versions_string, std::string(1, kCdmValueDelimiter), | 165 versions_string, std::string(1, kCdmValueDelimiter), |
| 165 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 166 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 166 int version = 0; | 167 int version = 0; |
| 167 if (base::StringToInt(ver_str, &version)) | 168 if (base::StringToInt(ver_str, &version)) |
| 168 if (version_check_func(version)) | 169 if (version_check_func(version)) |
| 169 return true; | 170 return true; |
| 170 } | 171 } |
| 171 | 172 |
| 172 DLOG(WARNING) << "Widevine CDM component manifest has no supported " | 173 DVLOG(1) << "Widevine CDM component manifest has no supported " |
| 173 << version_name << " in '" << versions_string << "'"; | 174 << version_name << " in '" << versions_string << "'"; |
| 174 return false; | 175 return false; |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Returns whether the CDM's API versions, as specified in the manifest, are | 178 // Returns whether the CDM's API versions, as specified in the manifest, are |
| 178 // compatible with this Chrome binary. | 179 // compatible with this Chrome binary. |
| 179 // Checks the module API, CDM interface API, and Host API. | 180 // Checks the module API, CDM interface API, and Host API. |
| 180 // This should never fail except in rare cases where the component has not been | 181 // This should never fail except in rare cases where the component has not been |
| 181 // updated recently or the user downgrades Chrome. | 182 // updated recently or the user downgrades Chrome. |
| 182 bool IsCompatibleWithChrome(const base::DictionaryValue& manifest) { | 183 bool IsCompatibleWithChrome(const base::DictionaryValue& manifest) { |
| 183 return CheckForCompatibleVersion(manifest, | 184 return CheckForCompatibleVersion(manifest, |
| 184 kCdmModuleVersionsName, | 185 kCdmModuleVersionsName, |
| 185 media::IsSupportedCdmModuleVersion) && | 186 media::IsSupportedCdmModuleVersion) && |
| 186 CheckForCompatibleVersion(manifest, | 187 CheckForCompatibleVersion(manifest, |
| 187 kCdmInterfaceVersionsName, | 188 kCdmInterfaceVersionsName, |
| 188 media::IsSupportedCdmInterfaceVersion) && | 189 media::IsSupportedCdmInterfaceVersion) && |
| 189 CheckForCompatibleVersion(manifest, | 190 CheckForCompatibleVersion(manifest, |
| 190 kCdmHostVersionsName, | 191 kCdmHostVersionsName, |
| 191 media::IsSupportedCdmHostVersion); | 192 media::IsSupportedCdmHostVersion); |
| 192 } | 193 } |
| 193 | 194 |
| 194 std::string GetCodecs(const base::DictionaryValue& manifest) { | 195 std::string GetCodecs(const base::DictionaryValue& manifest) { |
| 195 std::string codecs; | 196 std::string codecs; |
| 196 if (manifest.GetStringASCII(kCdmCodecsListName, &codecs)) { | 197 if (manifest.GetStringASCII(kCdmCodecsListName, &codecs)) { |
| 197 DLOG_IF(WARNING, codecs.empty()) | 198 DVLOG_IF(1, codecs.empty()) |
| 198 << "Widevine CDM component manifest has empty codecs list"; | 199 << "Widevine CDM component manifest has empty codecs list"; |
| 199 } else { | 200 } else { |
| 200 DLOG(WARNING) << "Widevine CDM component manifest is missing codecs"; | 201 DVLOG(1) << "Widevine CDM component manifest is missing codecs"; |
| 201 } | 202 } |
| 202 return codecs; | 203 return codecs; |
| 203 } | 204 } |
| 204 | 205 |
| 205 void RegisterWidevineCdmWithChrome( | 206 void RegisterWidevineCdmWithChrome( |
| 206 const base::Version& cdm_version, | 207 const base::Version& cdm_version, |
| 207 const base::FilePath& cdm_install_dir, | 208 const base::FilePath& cdm_install_dir, |
| 208 std::unique_ptr<base::DictionaryValue> manifest) { | 209 std::unique_ptr<base::DictionaryValue> manifest) { |
| 209 LOG(WARNING) << __FUNCTION__; | |
| 210 | |
| 211 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 210 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 212 const std::string codecs = GetCodecs(*manifest); | 211 const std::string codecs = GetCodecs(*manifest); |
| 213 | 212 |
| 214 content::PepperPluginInfo plugin_info; | 213 content::PepperPluginInfo plugin_info; |
| 215 if (!MakeWidevineCdmPluginInfo(cdm_version, cdm_install_dir, codecs, | 214 if (!MakeWidevineCdmPluginInfo(cdm_version, cdm_install_dir, codecs, |
| 216 &plugin_info)) { | 215 &plugin_info)) { |
| 217 return; | 216 return; |
| 218 } | 217 } |
| 219 | 218 |
| 219 VLOG(1) << "Register Widevine CDM with Chrome"; |
| 220 |
| 220 // true = Add to beginning of list to override any existing registrations. | 221 // true = Add to beginning of list to override any existing registrations. |
| 221 PluginService::GetInstance()->RegisterInternalPlugin( | 222 PluginService::GetInstance()->RegisterInternalPlugin( |
| 222 plugin_info.ToWebPluginInfo(), true); | 223 plugin_info.ToWebPluginInfo(), true); |
| 223 // Tell the browser to refresh the plugin list. Then tell all renderers to | 224 // Tell the browser to refresh the plugin list. Then tell all renderers to |
| 224 // update their plugin list caches. | 225 // update their plugin list caches. |
| 225 PluginService::GetInstance()->RefreshPlugins(); | 226 PluginService::GetInstance()->RefreshPlugins(); |
| 226 PluginService::GetInstance()->PurgePluginListCache(NULL, false); | 227 PluginService::GetInstance()->PurgePluginListCache(NULL, false); |
| 227 | 228 |
| 228 // Also register Widevine with the CdmService. | 229 // Also register Widevine with the CdmService. |
| 229 const base::FilePath cdm_path = | 230 const base::FilePath cdm_path = |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 const base::FilePath& install_dir) const { | 313 const base::FilePath& install_dir) const { |
| 313 return IsCompatibleWithChrome(manifest) && | 314 return IsCompatibleWithChrome(manifest) && |
| 314 base::PathExists(GetPlatformDirectory(install_dir) | 315 base::PathExists(GetPlatformDirectory(install_dir) |
| 315 .AppendASCII(kWidevineCdmFileName)); | 316 .AppendASCII(kWidevineCdmFileName)); |
| 316 } | 317 } |
| 317 | 318 |
| 318 // The base directory on Windows looks like: | 319 // The base directory on Windows looks like: |
| 319 // <profile>\AppData\Local\Google\Chrome\User Data\WidevineCdm\. | 320 // <profile>\AppData\Local\Google\Chrome\User Data\WidevineCdm\. |
| 320 base::FilePath WidevineCdmComponentInstallerTraits::GetRelativeInstallDir() | 321 base::FilePath WidevineCdmComponentInstallerTraits::GetRelativeInstallDir() |
| 321 const { | 322 const { |
| 322 // Add LOG(WARNING) here and below to help investigate http://crbug.com/614745 | |
| 323 // TODO(xhwang): Remove LOG(WARNING)s in this file after investigation. | |
| 324 LOG(WARNING) << __FUNCTION__; | |
| 325 return base::FilePath(FILE_PATH_LITERAL("WidevineCdm")); | 323 return base::FilePath(FILE_PATH_LITERAL("WidevineCdm")); |
| 326 } | 324 } |
| 327 | 325 |
| 328 void WidevineCdmComponentInstallerTraits::GetHash( | 326 void WidevineCdmComponentInstallerTraits::GetHash( |
| 329 std::vector<uint8_t>* hash) const { | 327 std::vector<uint8_t>* hash) const { |
| 330 hash->assign(kSha2Hash, kSha2Hash + arraysize(kSha2Hash)); | 328 hash->assign(kSha2Hash, kSha2Hash + arraysize(kSha2Hash)); |
| 331 } | 329 } |
| 332 | 330 |
| 333 std::string WidevineCdmComponentInstallerTraits::GetName() const { | 331 std::string WidevineCdmComponentInstallerTraits::GetName() const { |
| 334 return kWidevineCdmDisplayName; | 332 return kWidevineCdmDisplayName; |
| 335 } | 333 } |
| 336 | 334 |
| 337 std::string WidevineCdmComponentInstallerTraits::GetAp() const { | 335 std::string WidevineCdmComponentInstallerTraits::GetAp() const { |
| 338 return std::string(); | 336 return std::string(); |
| 339 } | 337 } |
| 340 | 338 |
| 341 static bool HasValidAdapter(const base::FilePath& adapter_version_path, | 339 static bool HasValidAdapter(const base::FilePath& adapter_version_path, |
| 342 const base::FilePath& adapter_install_path, | 340 const base::FilePath& adapter_install_path, |
| 343 const std::string& chrome_version) { | 341 const std::string& chrome_version) { |
| 344 std::string adapter_version; | 342 std::string adapter_version; |
| 345 return base::ReadFileToString(adapter_version_path, &adapter_version) && | 343 return base::ReadFileToString(adapter_version_path, &adapter_version) && |
| 346 adapter_version == chrome_version && | 344 adapter_version == chrome_version && |
| 347 base::PathExists(adapter_install_path); | 345 base::PathExists(adapter_install_path); |
| 348 } | 346 } |
| 349 | 347 |
| 350 void WidevineCdmComponentInstallerTraits::UpdateCdmAdapter( | 348 void WidevineCdmComponentInstallerTraits::UpdateCdmAdapter( |
| 351 const base::Version& cdm_version, | 349 const base::Version& cdm_version, |
| 352 const base::FilePath& cdm_install_dir, | 350 const base::FilePath& cdm_install_dir, |
| 353 std::unique_ptr<base::DictionaryValue> manifest) { | 351 std::unique_ptr<base::DictionaryValue> manifest) { |
| 354 LOG(WARNING) << __FUNCTION__; | |
| 355 | |
| 356 const base::FilePath adapter_version_path = | 352 const base::FilePath adapter_version_path = |
| 357 GetPlatformDirectory(cdm_install_dir).AppendASCII(kCdmAdapterVersionName); | 353 GetPlatformDirectory(cdm_install_dir).AppendASCII(kCdmAdapterVersionName); |
| 358 const base::FilePath adapter_install_path = | 354 const base::FilePath adapter_install_path = |
| 359 GetPlatformDirectory(cdm_install_dir) | 355 GetPlatformDirectory(cdm_install_dir) |
| 360 .AppendASCII(kWidevineCdmAdapterFileName); | 356 .AppendASCII(kWidevineCdmAdapterFileName); |
| 361 | 357 |
| 362 VLOG(1) << "UpdateCdmAdapter: version" << cdm_version.GetString() | 358 VLOG(1) << "UpdateCdmAdapter: version" << cdm_version.GetString() |
| 363 << " adapter_install_path=" << adapter_install_path.AsUTF8Unsafe() | 359 << " adapter_install_path=" << adapter_install_path.AsUTF8Unsafe() |
| 364 << " adapter_version_path=" << adapter_version_path.AsUTF8Unsafe(); | 360 << " adapter_version_path=" << adapter_version_path.AsUTF8Unsafe(); |
| 365 | 361 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 std::unique_ptr<ComponentInstallerTraits> traits( | 402 std::unique_ptr<ComponentInstallerTraits> traits( |
| 407 new WidevineCdmComponentInstallerTraits); | 403 new WidevineCdmComponentInstallerTraits); |
| 408 // |cus| will take ownership of |installer| during installer->Register(cus). | 404 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 409 DefaultComponentInstaller* installer = | 405 DefaultComponentInstaller* installer = |
| 410 new DefaultComponentInstaller(std::move(traits)); | 406 new DefaultComponentInstaller(std::move(traits)); |
| 411 installer->Register(cus, base::Closure()); | 407 installer->Register(cus, base::Closure()); |
| 412 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 408 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 413 } | 409 } |
| 414 | 410 |
| 415 } // namespace component_updater | 411 } // namespace component_updater |
| OLD | NEW |