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