Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1202)

Side by Side Diff: chrome/browser/component_updater/widevine_cdm_component_installer.cc

Issue 1637083002: Add CdmService to keep track of CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes + file move Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h"
24 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
25 #include "base/values.h" 26 #include "base/values.h"
26 #include "build/build_config.h" 27 #include "build/build_config.h"
27 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/widevine_cdm_constants.h" 29 #include "chrome/common/widevine_cdm_constants.h"
29 #include "components/component_updater/component_updater_service.h" 30 #include "components/component_updater/component_updater_service.h"
30 #include "components/component_updater/default_component_installer.h" 31 #include "components/component_updater/default_component_installer.h"
31 #include "components/version_info/version_info.h" 32 #include "components/version_info/version_info.h"
32 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/cdm_service.h"
33 #include "content/public/browser/plugin_service.h" 35 #include "content/public/browser/plugin_service.h"
34 #include "content/public/common/pepper_plugin_info.h" 36 #include "content/public/common/pepper_plugin_info.h"
35 #include "media/cdm/supported_cdm_versions.h" 37 #include "media/cdm/supported_cdm_versions.h"
36 #include "third_party/widevine/cdm/widevine_cdm_common.h" 38 #include "third_party/widevine/cdm/widevine_cdm_common.h"
37 39
38 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT 40 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT
39 41
40 using content::BrowserThread; 42 using content::BrowserThread;
43 using content::CdmService;
41 using content::PluginService; 44 using content::PluginService;
42 45
43 namespace component_updater { 46 namespace component_updater {
44 47
45 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 48 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
46 49
47 namespace { 50 namespace {
48 51
49 // CRX hash. The extension id is: oimompecagnajdejgnnjijobebaeigek. 52 // CRX hash. The extension id is: oimompecagnajdejgnnjijobebaeigek.
50 const uint8_t kSha2Hash[] = {0xe8, 0xce, 0xcf, 0x42, 0x06, 0xd0, 0x93, 0x49, 53 const uint8_t kSha2Hash[] = {0xe8, 0xce, 0xcf, 0x42, 0x06, 0xd0, 0x93, 0x49,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Widevine CDM is packaged as a multi-CRX. Widevine CDM binaries are located in 104 // Widevine CDM is packaged as a multi-CRX. Widevine CDM binaries are located in
102 // _platform_specific/<platform_arch> folder in the package. This function 105 // _platform_specific/<platform_arch> folder in the package. This function
103 // returns the platform-specific subdirectory that is part of that multi-CRX. 106 // returns the platform-specific subdirectory that is part of that multi-CRX.
104 base::FilePath GetPlatformDirectory(const base::FilePath& base_path) { 107 base::FilePath GetPlatformDirectory(const base::FilePath& base_path) {
105 std::string platform_arch = kWidevineCdmPlatform; 108 std::string platform_arch = kWidevineCdmPlatform;
106 platform_arch += '_'; 109 platform_arch += '_';
107 platform_arch += kWidevineCdmArch; 110 platform_arch += kWidevineCdmArch;
108 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch); 111 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch);
109 } 112 }
110 113
111 bool MakeWidevineCdmPluginInfo( 114 bool MakeWidevineCdmPluginInfo(const base::Version& version,
112 const base::Version& version, 115 const base::FilePath& path,
113 const base::FilePath& path, 116 base::string16 codecs,
114 const std::vector<base::string16>& additional_param_names, 117 content::PepperPluginInfo* plugin_info) {
115 const std::vector<base::string16>& additional_param_values,
116 content::PepperPluginInfo* plugin_info) {
117 if (!version.IsValid() || 118 if (!version.IsValid() ||
118 version.components().size() != 119 version.components().size() !=
119 static_cast<size_t>(kWidevineCdmVersionNumComponents)) { 120 static_cast<size_t>(kWidevineCdmVersionNumComponents)) {
120 return false; 121 return false;
121 } 122 }
122 123
123 plugin_info->is_internal = false; 124 plugin_info->is_internal = false;
124 // Widevine CDM must run out of process. 125 // Widevine CDM must run out of process.
125 plugin_info->is_out_of_process = true; 126 plugin_info->is_out_of_process = true;
126 plugin_info->path = path; 127 plugin_info->path = path;
127 plugin_info->name = kWidevineCdmDisplayName; 128 plugin_info->name = kWidevineCdmDisplayName;
128 plugin_info->description = kWidevineCdmDescription + 129 plugin_info->description = kWidevineCdmDescription +
129 std::string(" (version: ") + version.GetString() + 130 std::string(" (version: ") + version.GetString() +
130 ")"; 131 ")";
131 plugin_info->version = version.GetString(); 132 plugin_info->version = version.GetString();
132 content::WebPluginMimeType widevine_cdm_mime_type( 133 content::WebPluginMimeType widevine_cdm_mime_type(
133 kWidevineCdmPluginMimeType, 134 kWidevineCdmPluginMimeType,
134 kWidevineCdmPluginExtension, 135 kWidevineCdmPluginExtension,
135 kWidevineCdmPluginMimeTypeDescription); 136 kWidevineCdmPluginMimeTypeDescription);
136 widevine_cdm_mime_type.additional_param_names = additional_param_names; 137 widevine_cdm_mime_type.additional_param_names.push_back(
137 widevine_cdm_mime_type.additional_param_values = additional_param_values; 138 base::ASCIIToUTF16(kCdmSupportedCodecsParamName));
139 widevine_cdm_mime_type.additional_param_values.push_back(codecs);
140
138 plugin_info->mime_types.push_back(widevine_cdm_mime_type); 141 plugin_info->mime_types.push_back(widevine_cdm_mime_type);
139 plugin_info->permissions = kWidevineCdmPluginPermissions; 142 plugin_info->permissions = kWidevineCdmPluginPermissions;
140 143
141 return true; 144 return true;
142 } 145 }
143 146
144 typedef bool (*VersionCheckFunc)(int version); 147 typedef bool (*VersionCheckFunc)(int version);
145 148
146 bool CheckForCompatibleVersion(const base::DictionaryValue& manifest, 149 bool CheckForCompatibleVersion(const base::DictionaryValue& manifest,
147 const std::string version_name, 150 const std::string version_name,
(...skipping 30 matching lines...) Expand all
178 kCdmModuleVersionsName, 181 kCdmModuleVersionsName,
179 media::IsSupportedCdmModuleVersion) && 182 media::IsSupportedCdmModuleVersion) &&
180 CheckForCompatibleVersion(manifest, 183 CheckForCompatibleVersion(manifest,
181 kCdmInterfaceVersionsName, 184 kCdmInterfaceVersionsName,
182 media::IsSupportedCdmInterfaceVersion) && 185 media::IsSupportedCdmInterfaceVersion) &&
183 CheckForCompatibleVersion(manifest, 186 CheckForCompatibleVersion(manifest,
184 kCdmHostVersionsName, 187 kCdmHostVersionsName,
185 media::IsSupportedCdmHostVersion); 188 media::IsSupportedCdmHostVersion);
186 } 189 }
187 190
188 void GetAdditionalParams(const base::DictionaryValue& manifest, 191 base::string16 GetCodecs(const base::DictionaryValue& manifest) {
189 std::vector<base::string16>* additional_param_names,
190 std::vector<base::string16>* additional_param_values) {
191 base::string16 codecs; 192 base::string16 codecs;
192 if (manifest.GetString(kCdmCodecsListName, &codecs)) { 193 if (manifest.GetString(kCdmCodecsListName, &codecs)) {
193 DLOG_IF(WARNING, codecs.empty()) 194 DLOG_IF(WARNING, codecs.empty())
194 << "Widevine CDM component manifest has empty codecs list"; 195 << "Widevine CDM component manifest has empty codecs list";
195 additional_param_names->push_back(
196 base::ASCIIToUTF16(kCdmSupportedCodecsParamName));
197 additional_param_values->push_back(codecs);
198 } else { 196 } else {
199 DLOG(WARNING) << "Widevine CDM component manifest is missing codecs"; 197 DLOG(WARNING) << "Widevine CDM component manifest is missing codecs";
200 } 198 }
199 return codecs;
201 } 200 }
202 201
203 void RegisterWidevineCdmWithChrome(const base::Version& cdm_version, 202 void RegisterWidevineCdmWithChrome(const base::Version& cdm_version,
204 const base::FilePath& adapter_install_path, 203 const base::FilePath& adapter_install_path,
205 scoped_ptr<base::DictionaryValue> manifest) { 204 scoped_ptr<base::DictionaryValue> manifest) {
206 DCHECK_CURRENTLY_ON(BrowserThread::UI); 205 DCHECK_CURRENTLY_ON(BrowserThread::UI);
207 std::vector<base::string16> additional_param_names; 206 base::string16 codecs = GetCodecs(*manifest);
208 std::vector<base::string16> additional_param_values; 207
209 GetAdditionalParams(
210 *manifest, &additional_param_names, &additional_param_values);
211 content::PepperPluginInfo plugin_info; 208 content::PepperPluginInfo plugin_info;
212 if (!MakeWidevineCdmPluginInfo(cdm_version, 209 if (!MakeWidevineCdmPluginInfo(cdm_version, adapter_install_path, codecs,
213 adapter_install_path,
214 additional_param_names,
215 additional_param_values,
216 &plugin_info)) { 210 &plugin_info)) {
217 return; 211 return;
218 } 212 }
219 213
220 // true = Add to beginning of list to override any existing registrations. 214 // true = Add to beginning of list to override any existing registrations.
221 PluginService::GetInstance()->RegisterInternalPlugin( 215 PluginService::GetInstance()->RegisterInternalPlugin(
222 plugin_info.ToWebPluginInfo(), true); 216 plugin_info.ToWebPluginInfo(), true);
223 // Tell the browser to refresh the plugin list. Then tell all renderers to 217 // Tell the browser to refresh the plugin list. Then tell all renderers to
224 // update their plugin list caches. 218 // update their plugin list caches.
225 PluginService::GetInstance()->RefreshPlugins(); 219 PluginService::GetInstance()->RefreshPlugins();
226 PluginService::GetInstance()->PurgePluginListCache(NULL, false); 220 PluginService::GetInstance()->PurgePluginListCache(NULL, false);
221
222 // Also register Widevine with the CdmService. It needs |path| to be the
223 // actual Widevine library, not the adapter, so adjust as necessary.
224 // It will be in the same directory as the installed adapter.
225 base::FilePath cdm_install_path =
226 adapter_install_path.DirName().AppendASCII(kWidevineCdmFileName);
227 std::vector<std::string> supported_codecs =
228 base::SplitString(base::UTF16ToASCII(codecs),
229 std::string(1, kCdmSupportedCodecsValueDelimiter),
230 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
231 CdmService::GetInstance()->RegisterCdm(
232 content::CdmInfo(kWidevineCdmName, cdm_version, cdm_install_path,
233 supported_codecs),
234 true);
227 } 235 }
228 236
229 } // namespace 237 } // namespace
230 238
231 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits { 239 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits {
232 public: 240 public:
233 WidevineCdmComponentInstallerTraits(); 241 WidevineCdmComponentInstallerTraits();
234 ~WidevineCdmComponentInstallerTraits() override {} 242 ~WidevineCdmComponentInstallerTraits() override {}
235 243
236 private: 244 private:
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 scoped_ptr<ComponentInstallerTraits> traits( 377 scoped_ptr<ComponentInstallerTraits> traits(
370 new WidevineCdmComponentInstallerTraits); 378 new WidevineCdmComponentInstallerTraits);
371 // |cus| will take ownership of |installer| during installer->Register(cus). 379 // |cus| will take ownership of |installer| during installer->Register(cus).
372 DefaultComponentInstaller* installer = 380 DefaultComponentInstaller* installer =
373 new DefaultComponentInstaller(std::move(traits)); 381 new DefaultComponentInstaller(std::move(traits));
374 installer->Register(cus, base::Closure()); 382 installer->Register(cus, base::Closure());
375 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 383 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
376 } 384 }
377 385
378 } // namespace component_updater 386 } // namespace component_updater
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_content_client.h » ('j') | content/public/browser/cdm_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698