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/pepper_flash_component_installer.h" | 5 #include "chrome/browser/component_updater/pepper_flash_component_installer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
26 #include "base/version.h" | 26 #include "base/version.h" |
27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
28 #include "chrome/browser/plugins/plugin_prefs.h" | 28 #include "chrome/browser/plugins/plugin_prefs.h" |
29 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pepper_flash.h" | 32 #include "chrome/common/pepper_flash.h" |
33 #include "chrome/common/ppapi_utils.h" | 33 #include "chrome/common/ppapi_utils.h" |
34 #include "components/component_updater/component_updater_service.h" | 34 #include "components/component_updater/component_updater_service.h" |
| 35 #include "components/component_updater/default_component_installer.h" |
35 #include "components/update_client/update_client.h" | 36 #include "components/update_client/update_client.h" |
36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/plugin_service.h" | 38 #include "content/public/browser/plugin_service.h" |
38 #include "content/public/common/content_constants.h" | 39 #include "content/public/common/content_constants.h" |
39 #include "content/public/common/pepper_plugin_info.h" | 40 #include "content/public/common/pepper_plugin_info.h" |
40 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT | 41 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT |
41 #include "ppapi/shared_impl/ppapi_permissions.h" | 42 #include "ppapi/shared_impl/ppapi_permissions.h" |
42 | 43 |
43 #if defined(OS_LINUX) | 44 #if defined(OS_LINUX) |
44 #include "chrome/common/component_flash_hint_file_linux.h" | 45 #include "chrome/common/component_flash_hint_file_linux.h" |
45 #endif // defined(OS_LINUX) | 46 #endif // defined(OS_LINUX) |
46 | 47 |
47 using content::BrowserThread; | 48 using content::BrowserThread; |
48 using content::PluginService; | 49 using content::PluginService; |
49 | 50 |
50 namespace component_updater { | 51 namespace component_updater { |
51 | 52 |
52 namespace { | 53 namespace { |
53 | 54 |
54 #if defined(GOOGLE_CHROME_BUILD) | 55 #if defined(GOOGLE_CHROME_BUILD) |
55 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. | 56 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. |
56 const uint8_t kSha2Hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, | 57 const uint8_t kSha2Hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, |
57 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, | 58 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, |
58 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, | 59 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, |
59 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; | 60 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; |
60 | |
61 // If we don't have a Pepper Flash component, this is the version we claim. | |
62 const char kNullVersion[] = "0.0.0.0"; | |
63 | |
64 // Pepper Flash plugins have the version encoded in the path itself | |
65 // so we need to enumerate the directories to find the full path. | |
66 // On success, |latest_dir| returns something like: | |
67 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\. | |
68 // |latest_version| returns the corresponding version number. |older_dirs| | |
69 // returns directories of all older versions. | |
70 bool GetPepperFlashDirectory(base::FilePath* latest_dir, | |
71 Version* latest_version, | |
72 std::vector<base::FilePath>* older_dirs) { | |
73 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
74 base::FilePath base_dir; | |
75 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | |
76 &base_dir)) { | |
77 return false; | |
78 } | |
79 | |
80 bool found = false; | |
81 base::FileEnumerator file_enumerator( | |
82 base_dir, false, base::FileEnumerator::DIRECTORIES); | |
83 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); | |
84 path = file_enumerator.Next()) { | |
85 Version version(path.BaseName().MaybeAsASCII()); | |
86 if (!version.IsValid()) | |
87 continue; | |
88 if (found) { | |
89 if (version.CompareTo(*latest_version) > 0) { | |
90 older_dirs->push_back(*latest_dir); | |
91 *latest_dir = path; | |
92 *latest_version = version; | |
93 } else { | |
94 older_dirs->push_back(path); | |
95 } | |
96 } else { | |
97 *latest_dir = path; | |
98 *latest_version = version; | |
99 found = true; | |
100 } | |
101 } | |
102 return found; | |
103 } | |
104 #endif // defined(GOOGLE_CHROME_BUILD) | 61 #endif // defined(GOOGLE_CHROME_BUILD) |
105 | 62 |
106 #if !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) | 63 #if !defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD) |
107 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path, | 64 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path, |
108 const Version& flash_version, | 65 const Version& flash_version, |
109 bool out_of_process, | 66 bool out_of_process, |
110 content::PepperPluginInfo* plugin_info) { | 67 content::PepperPluginInfo* plugin_info) { |
111 if (!flash_version.IsValid()) | 68 if (!flash_version.IsValid()) |
112 return false; | 69 return false; |
113 const std::vector<uint32_t> ver_nums = flash_version.components(); | 70 const std::vector<uint32_t> ver_nums = flash_version.components(); |
114 if (ver_nums.size() < 3) | 71 if (ver_nums.size() < 3) |
115 return false; | 72 return false; |
116 | 73 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 155 |
199 // If the version is newer, remove the old one first. | 156 // If the version is newer, remove the old one first. |
200 PluginService::GetInstance()->UnregisterInternalPlugin(plugin.path); | 157 PluginService::GetInstance()->UnregisterInternalPlugin(plugin.path); |
201 break; | 158 break; |
202 } | 159 } |
203 | 160 |
204 PluginService::GetInstance()->RegisterInternalPlugin( | 161 PluginService::GetInstance()->RegisterInternalPlugin( |
205 plugin_info.ToWebPluginInfo(), true); | 162 plugin_info.ToWebPluginInfo(), true); |
206 PluginService::GetInstance()->RefreshPlugins(); | 163 PluginService::GetInstance()->RefreshPlugins(); |
207 } | 164 } |
208 #endif // !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) | 165 #endif // !defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD) |
209 | 166 |
210 } // namespace | 167 #if defined(GOOGLE_CHROME_BUILD) |
211 | 168 class FlashComponentInstallerTraits : public ComponentInstallerTraits { |
212 class PepperFlashComponentInstaller : public update_client::CrxInstaller { | |
213 public: | 169 public: |
214 explicit PepperFlashComponentInstaller(const Version& version); | 170 FlashComponentInstallerTraits(); |
215 | 171 ~FlashComponentInstallerTraits() override {} |
216 // ComponentInstaller implementation: | |
217 void OnUpdateError(int error) override; | |
218 | |
219 bool Install(const base::DictionaryValue& manifest, | |
220 const base::FilePath& unpack_path) override; | |
221 | |
222 bool GetInstalledFile(const std::string& file, | |
223 base::FilePath* installed_file) override; | |
224 | |
225 bool Uninstall() override; | |
226 | 172 |
227 private: | 173 private: |
228 ~PepperFlashComponentInstaller() override {} | 174 // The following methods override ComponentInstallerTraits. |
| 175 bool CanAutoUpdate() const override; |
| 176 bool RequiresNetworkEncryption() const override; |
| 177 bool OnCustomInstall(const base::DictionaryValue& manifest, |
| 178 const base::FilePath& install_dir) override; |
| 179 bool VerifyInstallation(const base::DictionaryValue& manifest, |
| 180 const base::FilePath& install_dir) const override; |
| 181 void ComponentReady(const base::Version& version, |
| 182 const base::FilePath& path, |
| 183 std::unique_ptr<base::DictionaryValue> manifest) override; |
| 184 base::FilePath GetRelativeInstallDir() const override; |
| 185 void GetHash(std::vector<uint8_t>* hash) const override; |
| 186 std::string GetName() const override; |
| 187 std::string GetAp() const override; |
229 | 188 |
230 Version current_version_; | 189 DISALLOW_COPY_AND_ASSIGN(FlashComponentInstallerTraits); |
231 }; | 190 }; |
232 | 191 |
233 PepperFlashComponentInstaller::PepperFlashComponentInstaller( | 192 FlashComponentInstallerTraits::FlashComponentInstallerTraits() {} |
234 const Version& version) | 193 |
235 : current_version_(version) { | 194 bool FlashComponentInstallerTraits::CanAutoUpdate() const { |
236 DCHECK(version.IsValid()); | 195 return true; |
237 } | 196 } |
238 | 197 |
239 void PepperFlashComponentInstaller::OnUpdateError(int error) { | 198 bool FlashComponentInstallerTraits::RequiresNetworkEncryption() const { |
240 NOTREACHED() << "Pepper Flash update error: " << error; | 199 return false; |
241 } | 200 } |
242 | 201 |
243 bool PepperFlashComponentInstaller::Install( | 202 bool FlashComponentInstallerTraits::OnCustomInstall( |
244 const base::DictionaryValue& manifest, | 203 const base::DictionaryValue& manifest, |
245 const base::FilePath& unpack_path) { | 204 const base::FilePath& install_dir) { |
246 Version version; | 205 #if defined(OS_LINUX) |
247 if (!chrome::CheckPepperFlashManifest(manifest, &version)) | 206 const base::FilePath flash_path = |
| 207 install_dir.Append(chrome::kPepperFlashPluginFilename); |
| 208 // Populate the component updated flash hint file so that the zygote can |
| 209 // locate and preload the latest version of flash. |
| 210 std::string version; |
| 211 if (!manifest.GetString("version", &version)) |
248 return false; | 212 return false; |
249 if (current_version_.CompareTo(version) > 0) | 213 if (!component_flash_hint_file::RecordFlashUpdate(flash_path, flash_path, |
250 return false; | 214 version)) { |
251 const base::FilePath unpacked_plugin = | |
252 unpack_path.Append(chrome::kPepperFlashPluginFilename); | |
253 if (!base::PathExists(unpacked_plugin)) | |
254 return false; | |
255 // Passed the basic tests. Time to install it. | |
256 base::FilePath path; | |
257 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | |
258 &path)) { | |
259 return false; | 215 return false; |
260 } | 216 } |
261 path = path.AppendASCII(version.GetString()); | 217 #endif // defined(OS_LINUX) |
262 if (base::PathExists(path)) | 218 return true; |
263 return false; | 219 } |
264 current_version_ = version; | |
265 | 220 |
266 if (!base::Move(unpack_path, path)) | 221 void FlashComponentInstallerTraits::ComponentReady( |
267 return false; | 222 const base::Version& version, |
268 #if defined(OS_LINUX) | 223 const base::FilePath& path, |
269 const base::FilePath flash_path = | 224 std::unique_ptr<base::DictionaryValue> manifest) { |
270 path.Append(chrome::kPepperFlashPluginFilename); | 225 #if !defined(OS_LINUX) |
271 // Populate the component updated flash hint file so that the zygote can | |
272 // locate and preload the latest version of flash. | |
273 if (!component_flash_hint_file::RecordFlashUpdate(flash_path, flash_path, | |
274 version.GetString())) { | |
275 if (!base::DeleteFile(path, true)) | |
276 LOG(ERROR) << "Hint file creation failed, but unable to delete " | |
277 "installed flash plugin."; | |
278 return false; | |
279 } | |
280 #else | |
281 // Installation is done. Now tell the rest of chrome. Both the path service | 226 // Installation is done. Now tell the rest of chrome. Both the path service |
282 // and to the plugin service. On Linux, a restart is required to use the new | 227 // and to the plugin service. On Linux, a restart is required to use the new |
283 // Flash version, so we do not do this. | 228 // Flash version, so we do not do this. |
284 PathService::Override(chrome::DIR_PEPPER_FLASH_PLUGIN, path); | 229 PathService::Override(chrome::DIR_PEPPER_FLASH_PLUGIN, path); |
285 path = path.Append(chrome::kPepperFlashPluginFilename); | 230 RegisterPepperFlashWithChrome(path.Append(chrome::kPepperFlashPluginFilename), |
286 BrowserThread::PostTask( | 231 version); |
287 BrowserThread::UI, | |
288 FROM_HERE, | |
289 base::Bind(&RegisterPepperFlashWithChrome, path, version)); | |
290 #endif // !defined(OS_LINUX) | 232 #endif // !defined(OS_LINUX) |
291 return true; | |
292 } | 233 } |
293 | 234 |
294 bool PepperFlashComponentInstaller::GetInstalledFile( | 235 bool FlashComponentInstallerTraits::VerifyInstallation( |
295 const std::string& file, | 236 const base::DictionaryValue& manifest, |
296 base::FilePath* installed_file) { | 237 const base::FilePath& install_dir) const { |
297 return false; | 238 Version unused; |
| 239 return chrome::CheckPepperFlashManifest(manifest, &unused); |
298 } | 240 } |
299 | 241 |
300 bool PepperFlashComponentInstaller::Uninstall() { | 242 // The base directory on Windows looks like: |
301 return false; | 243 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\. |
| 244 base::FilePath FlashComponentInstallerTraits::GetRelativeInstallDir() const { |
| 245 return base::FilePath(FILE_PATH_LITERAL("PepperFlash")); |
302 } | 246 } |
303 | 247 |
304 | 248 void FlashComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const { |
305 | 249 hash->assign(kSha2Hash, kSha2Hash + arraysize(kSha2Hash)); |
306 namespace { | |
307 | |
308 #if defined(GOOGLE_CHROME_BUILD) | |
309 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus, | |
310 const Version& version) { | |
311 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
312 update_client::CrxComponent pepflash; | |
313 pepflash.name = "pepper_flash"; | |
314 pepflash.installer = new PepperFlashComponentInstaller(version); | |
315 pepflash.version = version; | |
316 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); | |
317 if (!cus->RegisterComponent(pepflash)) | |
318 NOTREACHED() << "Pepper Flash component registration failed."; | |
319 } | 250 } |
320 | 251 |
321 bool ValidatePepperFlashManifest(const base::FilePath& path) { | 252 std::string FlashComponentInstallerTraits::GetName() const { |
322 base::FilePath manifest_path(path.DirName().AppendASCII("manifest.json")); | 253 return "pepper_flash"; |
323 | |
324 std::string manifest_data; | |
325 if (!base::ReadFileToString(manifest_path, &manifest_data)) | |
326 return false; | |
327 std::unique_ptr<base::Value> manifest_value( | |
328 base::JSONReader::Read(manifest_data, base::JSON_ALLOW_TRAILING_COMMAS)); | |
329 if (!manifest_value.get()) | |
330 return false; | |
331 base::DictionaryValue* manifest = NULL; | |
332 if (!manifest_value->GetAsDictionary(&manifest)) | |
333 return false; | |
334 Version version; | |
335 if (!chrome::CheckPepperFlashManifest(*manifest, &version)) | |
336 return false; | |
337 return true; | |
338 } | 254 } |
339 | 255 |
340 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) { | 256 std::string FlashComponentInstallerTraits::GetAp() const { |
341 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 257 return std::string(); |
342 base::FilePath path; | |
343 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | |
344 &path)) { | |
345 return; | |
346 } | |
347 | |
348 if (!base::PathExists(path)) { | |
349 if (!base::CreateDirectory(path)) { | |
350 NOTREACHED() << "Could not create Pepper Flash directory."; | |
351 return; | |
352 } | |
353 } | |
354 | |
355 Version version(kNullVersion); | |
356 std::vector<base::FilePath> older_dirs; | |
357 if (GetPepperFlashDirectory(&path, &version, &older_dirs)) { | |
358 path = path.Append(chrome::kPepperFlashPluginFilename); | |
359 if (base::PathExists(path)) { | |
360 // Only register component pepper flash if it validates manifest check. | |
361 if (ValidatePepperFlashManifest(path)) { | |
362 BrowserThread::PostTask( | |
363 BrowserThread::UI, | |
364 FROM_HERE, | |
365 base::Bind(&RegisterPepperFlashWithChrome, path, version)); | |
366 } else { | |
367 // Queue this version to be deleted. | |
368 older_dirs.push_back(path.DirName()); | |
369 version = Version(kNullVersion); | |
370 } | |
371 } else { | |
372 version = Version(kNullVersion); | |
373 } | |
374 } | |
375 | |
376 #if defined(FLAPPER_AVAILABLE) | |
377 // If a version of Flash is bundled with Chrome, and it's a higher version | |
378 // than the version of the component, or the component has never been updated, | |
379 // then set the bundled version as the current version. | |
380 if (version.CompareTo(Version(FLAPPER_VERSION_STRING)) < 0) | |
381 version = Version(FLAPPER_VERSION_STRING); | |
382 #endif | |
383 | |
384 BrowserThread::PostTask( | |
385 BrowserThread::UI, | |
386 FROM_HERE, | |
387 base::Bind(&FinishPepperFlashUpdateRegistration, cus, version)); | |
388 | |
389 // Remove older versions of Pepper Flash. | |
390 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); | |
391 iter != older_dirs.end(); | |
392 ++iter) { | |
393 base::DeleteFile(*iter, true); | |
394 } | |
395 } | 258 } |
396 #endif // defined(GOOGLE_CHROME_BUILD) | 259 #endif // defined(GOOGLE_CHROME_BUILD) |
397 | 260 |
398 } // namespace | 261 } // namespace |
399 | 262 |
400 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { | 263 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { |
401 #if defined(GOOGLE_CHROME_BUILD) | 264 #if defined(GOOGLE_CHROME_BUILD) |
402 // Component updated flash supersedes bundled flash therefore if that one | 265 // Component updated flash supersedes bundled flash therefore if that one |
403 // is disabled then this one should never install. | 266 // is disabled then this one should never install. |
404 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 267 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
405 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) | 268 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) |
406 return; | 269 return; |
407 BrowserThread::PostTask(BrowserThread::FILE, | 270 std::unique_ptr<ComponentInstallerTraits> traits( |
408 FROM_HERE, | 271 new FlashComponentInstallerTraits); |
409 base::Bind(&StartPepperFlashUpdateRegistration, cus)); | 272 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 273 DefaultComponentInstaller* installer = |
| 274 new DefaultComponentInstaller(std::move(traits)); |
| 275 installer->Register(cus, base::Closure()); |
410 #endif // defined(GOOGLE_CHROME_BUILD) | 276 #endif // defined(GOOGLE_CHROME_BUILD) |
411 } | 277 } |
412 | 278 |
413 } // namespace component_updater | 279 } // namespace component_updater |
OLD | NEW |