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(base::ASCIIToUTF16("codecs")); |
| 119 additional_param_values->push_back(codecs); |
| 120 } else { |
| 121 DLOG(WARNING) << "Widevine CDM component manifest is missing 'codecs'"; |
| 122 } |
| 123 } |
| 124 |
| 125 void RegisterWidevineCdmWithChrome(const base::Version& version, |
| 126 const base::FilePath& path, |
| 127 scoped_ptr<base::DictionaryValue> manifest) { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 129 std::vector<base::string16> additional_param_names; |
| 130 std::vector<base::string16> additional_param_values; |
| 131 GetAdditionalParams( |
| 132 *manifest, &additional_param_names, &additional_param_values); |
107 content::PepperPluginInfo plugin_info; | 133 content::PepperPluginInfo plugin_info; |
108 if (!MakeWidevineCdmPluginInfo(path, version, &plugin_info)) | 134 if (!MakeWidevineCdmPluginInfo(version, |
| 135 path, |
| 136 additional_param_names, |
| 137 additional_param_values, |
| 138 &plugin_info)) { |
109 return; | 139 return; |
| 140 } |
110 | 141 |
| 142 // true = Add to beginning of list to override any existing registrations. |
111 PluginService::GetInstance()->RegisterInternalPlugin( | 143 PluginService::GetInstance()->RegisterInternalPlugin( |
112 plugin_info.ToWebPluginInfo(), true); | 144 plugin_info.ToWebPluginInfo(), true); |
113 PluginService::GetInstance()->RefreshPlugins(); | 145 PluginService::GetInstance()->RefreshPlugins(); |
114 } | 146 } |
115 | 147 |
116 } // namespace | 148 } // namespace |
117 | 149 |
118 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits { | 150 class WidevineCdmComponentInstallerTraits : public ComponentInstallerTraits { |
119 public: | 151 public: |
120 WidevineCdmComponentInstallerTraits(); | 152 WidevineCdmComponentInstallerTraits(); |
121 virtual ~WidevineCdmComponentInstallerTraits() {} | 153 virtual ~WidevineCdmComponentInstallerTraits() {} |
122 | 154 |
123 private: | 155 private: |
124 // The following methods override ComponentInstallerTraits. | 156 // The following methods override ComponentInstallerTraits. |
125 virtual bool CanAutoUpdate() const OVERRIDE; | 157 virtual bool CanAutoUpdate() const OVERRIDE; |
126 virtual bool OnCustomInstall(const base::DictionaryValue& manifest, | 158 virtual bool OnCustomInstall(const base::DictionaryValue& manifest, |
127 const base::FilePath& install_dir) OVERRIDE; | 159 const base::FilePath& install_dir) OVERRIDE; |
128 virtual bool VerifyInstallation( | 160 virtual bool VerifyInstallation( |
129 const base::FilePath& install_dir) const OVERRIDE; | 161 const base::FilePath& install_dir) const OVERRIDE; |
130 virtual void ComponentReady(const base::Version& version, | 162 virtual void ComponentReady( |
131 const base::FilePath& path) OVERRIDE; | 163 const base::Version& version, |
| 164 const base::FilePath& path, |
| 165 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE; |
132 virtual base::FilePath GetBaseDirectory() const OVERRIDE; | 166 virtual base::FilePath GetBaseDirectory() const OVERRIDE; |
133 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE; | 167 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE; |
134 virtual std::string GetName() const OVERRIDE; | 168 virtual std::string GetName() const OVERRIDE; |
135 DISALLOW_COPY_AND_ASSIGN(WidevineCdmComponentInstallerTraits); | 169 DISALLOW_COPY_AND_ASSIGN(WidevineCdmComponentInstallerTraits); |
136 }; | 170 }; |
137 | 171 |
138 WidevineCdmComponentInstallerTraits::WidevineCdmComponentInstallerTraits() { | 172 WidevineCdmComponentInstallerTraits::WidevineCdmComponentInstallerTraits() { |
139 } | 173 } |
140 | 174 |
141 bool WidevineCdmComponentInstallerTraits::CanAutoUpdate() const { | 175 bool WidevineCdmComponentInstallerTraits::CanAutoUpdate() const { |
142 return true; | 176 return true; |
143 } | 177 } |
144 | 178 |
145 // The adapter is copied into the install directory as part of the installation. | 179 // The adapter is copied into the install directory as part of the installation. |
146 bool WidevineCdmComponentInstallerTraits::OnCustomInstall( | 180 bool WidevineCdmComponentInstallerTraits::OnCustomInstall( |
147 const base::DictionaryValue& manifest, | 181 const base::DictionaryValue& manifest, |
148 const base::FilePath& install_path) { | 182 const base::FilePath& install_path) { |
149 base::FilePath adapter_install_path = GetPlatformDirectory(install_path) | 183 base::FilePath adapter_install_path = GetPlatformDirectory(install_path) |
150 .AppendASCII(kWidevineCdmAdapterFileName); | 184 .AppendASCII(kWidevineCdmAdapterFileName); |
151 base::FilePath adapter_source_path; | 185 base::FilePath adapter_source_path; |
152 PathService::Get(chrome::FILE_WIDEVINE_CDM_ADAPTER, &adapter_source_path); | 186 PathService::Get(chrome::FILE_WIDEVINE_CDM_ADAPTER, &adapter_source_path); |
153 return base::CopyFile(adapter_source_path, adapter_install_path); | 187 return base::CopyFile(adapter_source_path, adapter_install_path); |
154 } | 188 } |
155 | 189 |
156 // Once the component is installed, register the new version with Chrome. | 190 // Once the component is installed, register the new version with Chrome. |
157 void WidevineCdmComponentInstallerTraits::ComponentReady( | 191 void WidevineCdmComponentInstallerTraits::ComponentReady( |
158 const base::Version& version, | 192 const base::Version& version, |
159 const base::FilePath& path) { | 193 const base::FilePath& path, |
| 194 scoped_ptr<base::DictionaryValue> manifest) { |
| 195 // TODO(ddorwin): Check API version compatibility. Return if fails. |
160 base::FilePath adapter_install_path = GetPlatformDirectory(path) | 196 base::FilePath adapter_install_path = GetPlatformDirectory(path) |
161 .AppendASCII(kWidevineCdmAdapterFileName); | 197 .AppendASCII(kWidevineCdmAdapterFileName); |
162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 198 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
163 &RegisterWidevineCdmWithChrome, adapter_install_path, version)); | 199 &RegisterWidevineCdmWithChrome, |
| 200 version, adapter_install_path, base::Passed(&manifest))); |
164 } | 201 } |
165 | 202 |
166 bool WidevineCdmComponentInstallerTraits::VerifyInstallation( | 203 bool WidevineCdmComponentInstallerTraits::VerifyInstallation( |
167 const base::FilePath& install_dir) const { | 204 const base::FilePath& install_dir) const { |
168 return base::PathExists(GetPlatformDirectory(install_dir) | 205 return base::PathExists(GetPlatformDirectory(install_dir) |
169 .AppendASCII(kWidevineCdmFileName)) | 206 .AppendASCII(kWidevineCdmFileName)) |
170 && base::PathExists(GetPlatformDirectory(install_dir) | 207 && base::PathExists(GetPlatformDirectory(install_dir) |
171 .AppendASCII(kWidevineCdmAdapterFileName)); | 208 .AppendASCII(kWidevineCdmAdapterFileName)); |
172 } | 209 } |
173 | 210 |
(...skipping 25 matching lines...) Expand all Loading... |
199 scoped_ptr<ComponentInstallerTraits> traits( | 236 scoped_ptr<ComponentInstallerTraits> traits( |
200 new WidevineCdmComponentInstallerTraits); | 237 new WidevineCdmComponentInstallerTraits); |
201 // |cus| will take ownership of |installer| during installer->Register(cus). | 238 // |cus| will take ownership of |installer| during installer->Register(cus). |
202 DefaultComponentInstaller* installer | 239 DefaultComponentInstaller* installer |
203 = new DefaultComponentInstaller(traits.Pass()); | 240 = new DefaultComponentInstaller(traits.Pass()); |
204 installer->Register(cus); | 241 installer->Register(cus); |
205 #else | 242 #else |
206 return; | 243 return; |
207 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 244 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
208 } | 245 } |
OLD | NEW |