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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" |
16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/utf_string_conversions.h" |
17 #include "base/values.h" | 20 #include "base/values.h" |
18 #include "build/build_config.h" | 21 #include "build/build_config.h" |
19 #include "chrome/browser/component_updater/component_updater_service.h" | 22 #include "chrome/browser/component_updater/component_updater_service.h" |
20 #include "chrome/browser/component_updater/default_component_installer.h" | 23 #include "chrome/browser/component_updater/default_component_installer.h" |
21 #include "chrome/browser/plugins/plugin_prefs.h" | 24 #include "chrome/browser/plugins/plugin_prefs.h" |
22 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/widevine_cdm_constants.h" | 27 #include "chrome/common/widevine_cdm_constants.h" |
25 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/plugin_service.h" | 29 #include "content/public/browser/plugin_service.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // Widevine CDM is packaged as a multi-CRX. Widevine CDM binaries are located in | 71 // Widevine CDM is packaged as a multi-CRX. Widevine CDM binaries are located in |
69 // _platform_specific/<platform_arch> folder in the package. This function | 72 // _platform_specific/<platform_arch> folder in the package. This function |
70 // returns the platform-specific subdirectory that is part of that multi-CRX. | 73 // returns the platform-specific subdirectory that is part of that multi-CRX. |
71 base::FilePath GetPlatformDirectory(const base::FilePath& base_path) { | 74 base::FilePath GetPlatformDirectory(const base::FilePath& base_path) { |
72 std::string platform_arch = kWidevineCdmPlatform; | 75 std::string platform_arch = kWidevineCdmPlatform; |
73 platform_arch += '_'; | 76 platform_arch += '_'; |
74 platform_arch += kWidevineCdmArch; | 77 platform_arch += kWidevineCdmArch; |
75 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch); | 78 return base_path.AppendASCII("_platform_specific").AppendASCII(platform_arch); |
76 } | 79 } |
77 | 80 |
78 bool MakeWidevineCdmPluginInfo(const base::FilePath& path, | 81 bool MakeWidevineCdmPluginInfo( |
79 const base::Version& version, | 82 const base::Version& version, |
80 content::PepperPluginInfo* plugin_info) { | 83 const base::FilePath& path, |
| 84 const std::vector<base::string16>& additional_param_names, |
| 85 const std::vector<base::string16>& additional_param_values, |
| 86 content::PepperPluginInfo* plugin_info) { |
81 if (!version.IsValid() || | 87 if (!version.IsValid() || |
82 version.components().size() != | 88 version.components().size() != |
83 static_cast<size_t>(kWidevineCdmVersionNumComponents)) { | 89 static_cast<size_t>(kWidevineCdmVersionNumComponents)) { |
84 return false; | 90 return false; |
85 } | 91 } |
86 | 92 |
87 plugin_info->is_internal = false; | 93 plugin_info->is_internal = false; |
88 // Widevine CDM must run out of process. | 94 // Widevine CDM must run out of process. |
89 plugin_info->is_out_of_process = true; | 95 plugin_info->is_out_of_process = true; |
90 plugin_info->path = path; | 96 plugin_info->path = path; |
91 plugin_info->name = kWidevineCdmDisplayName; | 97 plugin_info->name = kWidevineCdmDisplayName; |
92 plugin_info->description = kWidevineCdmDescription; | 98 plugin_info->description = kWidevineCdmDescription; |
93 plugin_info->version = version.GetString(); | 99 plugin_info->version = version.GetString(); |
94 content::WebPluginMimeType widevine_cdm_mime_type( | 100 content::WebPluginMimeType widevine_cdm_mime_type( |
95 kWidevineCdmPluginMimeType, | 101 kWidevineCdmPluginMimeType, |
96 kWidevineCdmPluginExtension, | 102 kWidevineCdmPluginExtension, |
97 kWidevineCdmPluginMimeTypeDescription); | 103 kWidevineCdmPluginMimeTypeDescription); |
| 104 widevine_cdm_mime_type.additional_param_names = additional_param_names; |
| 105 widevine_cdm_mime_type.additional_param_values = additional_param_values; |
98 plugin_info->mime_types.push_back(widevine_cdm_mime_type); | 106 plugin_info->mime_types.push_back(widevine_cdm_mime_type); |
99 plugin_info->permissions = kWidevineCdmPluginPermissions; | 107 plugin_info->permissions = kWidevineCdmPluginPermissions; |
100 | 108 |
101 return true; | 109 return true; |
102 } | 110 } |
103 | 111 |
104 void RegisterWidevineCdmWithChrome(const base::FilePath& path, | 112 void GetAdditionalParams(const base::DictionaryValue& manifest, |
105 const base::Version& version) { | 113 std::vector<base::string16>* additional_param_names, |
| 114 std::vector<base::string16>* additional_param_values) { |
| 115 base::string16 codecs; |
| 116 if (manifest.GetString("x-cdm-codecs", &codecs)) { |
| 117 DLOG_IF(WARNING, codecs.empty()) |
| 118 << "Widevine CDM component manifest has empty codecs list"; |
| 119 additional_param_names->push_back( |
| 120 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)); |
| 121 additional_param_values->push_back(codecs); |
| 122 } else { |
| 123 DLOG(WARNING) << "Widevine CDM component manifest is missing codecs"; |
| 124 // TODO(ddorwin): Remove this once all users have been updated. |
| 125 // The original manifests did not include this string, so add the base set. |
| 126 additional_param_names->push_back( |
| 127 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)); |
| 128 additional_param_values->push_back(base::ASCIIToUTF16("vp8,vorbis")); |
| 129 } |
| 130 } |
| 131 |
| 132 void RegisterWidevineCdmWithChrome(const base::Version& version, |
| 133 const base::FilePath& path, |
| 134 scoped_ptr<base::DictionaryValue> manifest) { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 136 std::vector<base::string16> additional_param_names; |
| 137 std::vector<base::string16> additional_param_values; |
| 138 GetAdditionalParams( |
| 139 *manifest, &additional_param_names, &additional_param_values); |
107 content::PepperPluginInfo plugin_info; | 140 content::PepperPluginInfo plugin_info; |
108 if (!MakeWidevineCdmPluginInfo(path, version, &plugin_info)) | 141 if (!MakeWidevineCdmPluginInfo(version, |
| 142 path, |
| 143 additional_param_names, |
| 144 additional_param_values, |
| 145 &plugin_info)) { |
109 return; | 146 return; |
| 147 } |
110 | 148 |
| 149 // true = Add to beginning of list to override any existing registrations. |
111 PluginService::GetInstance()->RegisterInternalPlugin( | 150 PluginService::GetInstance()->RegisterInternalPlugin( |
112 plugin_info.ToWebPluginInfo(), true); | 151 plugin_info.ToWebPluginInfo(), true); |
113 PluginService::GetInstance()->RefreshPlugins(); | 152 PluginService::GetInstance()->RefreshPlugins(); |
114 } | 153 } |
115 | 154 |
116 } // namespace | 155 } // namespace |
117 | 156 |
118 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits { | 157 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits { |
119 public: | 158 public: |
120 WidevineCdmComponentInstallerTraits(); | 159 WidevineCdmComponentInstallerTraits(); |
121 virtual ~WidevineCdmComponentInstallerTraits() {} | 160 virtual ~WidevineCdmComponentInstallerTraits() {} |
122 | 161 |
123 private: | 162 private: |
124 // The following methods override ComponentInstallerTraits. | 163 // The following methods override ComponentInstallerTraits. |
125 virtual bool CanAutoUpdate() const OVERRIDE; | 164 virtual bool CanAutoUpdate() const OVERRIDE; |
126 virtual bool OnCustomInstall(const base::DictionaryValue& manifest, | 165 virtual bool OnCustomInstall(const base::DictionaryValue& manifest, |
127 const base::FilePath& install_dir) OVERRIDE; | 166 const base::FilePath& install_dir) OVERRIDE; |
128 virtual bool VerifyInstallation( | 167 virtual bool VerifyInstallation( |
129 const base::FilePath& install_dir) const OVERRIDE; | 168 const base::FilePath& install_dir) const OVERRIDE; |
130 virtual void ComponentReady(const base::Version& version, | 169 virtual void ComponentReady( |
131 const base::FilePath& path) OVERRIDE; | 170 const base::Version& version, |
| 171 const base::FilePath& path, |
| 172 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE; |
132 virtual base::FilePath GetBaseDirectory() const OVERRIDE; | 173 virtual base::FilePath GetBaseDirectory() const OVERRIDE; |
133 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE; | 174 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE; |
134 virtual std::string GetName() const OVERRIDE; | 175 virtual std::string GetName() const OVERRIDE; |
135 DISALLOW_COPY_AND_ASSIGN(WidevineCdmComponentInstallerTraits); | 176 DISALLOW_COPY_AND_ASSIGN(WidevineCdmComponentInstallerTraits); |
136 }; | 177 }; |
137 | 178 |
138 WidevineCdmComponentInstallerTraits::WidevineCdmComponentInstallerTraits() { | 179 WidevineCdmComponentInstallerTraits::WidevineCdmComponentInstallerTraits() { |
139 } | 180 } |
140 | 181 |
141 bool WidevineCdmComponentInstallerTraits::CanAutoUpdate() const { | 182 bool WidevineCdmComponentInstallerTraits::CanAutoUpdate() const { |
142 return true; | 183 return true; |
143 } | 184 } |
144 | 185 |
145 // The adapter is copied into the install directory as part of the installation. | 186 // The adapter is copied into the install directory as part of the installation. |
146 bool WidevineCdmComponentInstallerTraits::OnCustomInstall( | 187 bool WidevineCdmComponentInstallerTraits::OnCustomInstall( |
147 const base::DictionaryValue& manifest, | 188 const base::DictionaryValue& manifest, |
148 const base::FilePath& install_path) { | 189 const base::FilePath& install_path) { |
149 base::FilePath adapter_install_path = GetPlatformDirectory(install_path) | 190 base::FilePath adapter_install_path = GetPlatformDirectory(install_path) |
150 .AppendASCII(kWidevineCdmAdapterFileName); | 191 .AppendASCII(kWidevineCdmAdapterFileName); |
151 base::FilePath adapter_source_path; | 192 base::FilePath adapter_source_path; |
152 PathService::Get(chrome::FILE_WIDEVINE_CDM_ADAPTER, &adapter_source_path); | 193 PathService::Get(chrome::FILE_WIDEVINE_CDM_ADAPTER, &adapter_source_path); |
153 return base::CopyFile(adapter_source_path, adapter_install_path); | 194 return base::CopyFile(adapter_source_path, adapter_install_path); |
154 } | 195 } |
155 | 196 |
156 // Once the component is installed, register the new version with Chrome. | 197 // Once the component is installed, register the new version with Chrome. |
157 void WidevineCdmComponentInstallerTraits::ComponentReady( | 198 void WidevineCdmComponentInstallerTraits::ComponentReady( |
158 const base::Version& version, | 199 const base::Version& version, |
159 const base::FilePath& path) { | 200 const base::FilePath& path, |
| 201 scoped_ptr<base::DictionaryValue> manifest) { |
| 202 // TODO(ddorwin): Check API version compatibility. Return if fails. |
160 base::FilePath adapter_install_path = GetPlatformDirectory(path) | 203 base::FilePath adapter_install_path = GetPlatformDirectory(path) |
161 .AppendASCII(kWidevineCdmAdapterFileName); | 204 .AppendASCII(kWidevineCdmAdapterFileName); |
162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 205 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
163 &RegisterWidevineCdmWithChrome, adapter_install_path, version)); | 206 &RegisterWidevineCdmWithChrome, |
| 207 version, adapter_install_path, base::Passed(&manifest))); |
164 } | 208 } |
165 | 209 |
166 bool WidevineCdmComponentInstallerTraits::VerifyInstallation( | 210 bool WidevineCdmComponentInstallerTraits::VerifyInstallation( |
167 const base::FilePath& install_dir) const { | 211 const base::FilePath& install_dir) const { |
168 return base::PathExists(GetPlatformDirectory(install_dir) | 212 return base::PathExists(GetPlatformDirectory(install_dir) |
169 .AppendASCII(kWidevineCdmFileName)) | 213 .AppendASCII(kWidevineCdmFileName)) |
170 && base::PathExists(GetPlatformDirectory(install_dir) | 214 && base::PathExists(GetPlatformDirectory(install_dir) |
171 .AppendASCII(kWidevineCdmAdapterFileName)); | 215 .AppendASCII(kWidevineCdmAdapterFileName)); |
172 } | 216 } |
173 | 217 |
(...skipping 25 matching lines...) Expand all Loading... |
199 scoped_ptr<ComponentInstallerTraits> traits( | 243 scoped_ptr<ComponentInstallerTraits> traits( |
200 new WidevineCdmComponentInstallerTraits); | 244 new WidevineCdmComponentInstallerTraits); |
201 // |cus| will take ownership of |installer| during installer->Register(cus). | 245 // |cus| will take ownership of |installer| during installer->Register(cus). |
202 DefaultComponentInstaller* installer | 246 DefaultComponentInstaller* installer |
203 = new DefaultComponentInstaller(traits.Pass()); | 247 = new DefaultComponentInstaller(traits.Pass()); |
204 installer->Register(cus); | 248 installer->Register(cus); |
205 #else | 249 #else |
206 return; | 250 return; |
207 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 251 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
208 } | 252 } |
OLD | NEW |