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 <stdint.h> | 5 #include <stdint.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/version.h" | 22 #include "base/version.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "chrome/browser/component_updater/flash_component_installer.h" | 24 #include "chrome/browser/component_updater/flash_component_installer.h" |
25 #include "chrome/browser/plugins/plugin_prefs.h" | 25 #include "chrome/browser/plugins/plugin_prefs.h" |
26 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/component_flash_hint_file_linux.h" | |
30 #include "chrome/common/pepper_flash.h" | 29 #include "chrome/common/pepper_flash.h" |
31 #include "chrome/common/ppapi_utils.h" | 30 #include "chrome/common/ppapi_utils.h" |
32 #include "components/component_updater/component_updater_service.h" | 31 #include "components/component_updater/component_updater_service.h" |
33 #include "components/update_client/update_client.h" | 32 #include "components/update_client/update_client.h" |
34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
36 #include "content/public/common/content_constants.h" | 35 #include "content/public/common/content_constants.h" |
37 #include "content/public/common/pepper_plugin_info.h" | 36 #include "content/public/common/pepper_plugin_info.h" |
38 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT | 37 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT |
39 #include "ppapi/shared_impl/ppapi_permissions.h" | 38 #include "ppapi/shared_impl/ppapi_permissions.h" |
40 | 39 |
| 40 #if defined(OS_LINUX) |
| 41 #include "chrome/common/component_flash_hint_file_linux.h" |
| 42 #endif // defined(OS_LINUX) |
| 43 |
41 using content::BrowserThread; | 44 using content::BrowserThread; |
42 using content::PluginService; | 45 using content::PluginService; |
43 | 46 |
44 namespace component_updater { | 47 namespace component_updater { |
45 | 48 |
46 namespace { | 49 namespace { |
47 | 50 |
48 #if defined(GOOGLE_CHROME_BUILD) | 51 #if defined(GOOGLE_CHROME_BUILD) |
49 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. | 52 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. |
50 const uint8_t kSha2Hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, | 53 const uint8_t kSha2Hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, |
51 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, | 54 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, |
52 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, | 55 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, |
53 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; | 56 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; |
54 | 57 |
55 // If we don't have a Pepper Flash component, this is the version we claim. | 58 // If we don't have a Pepper Flash component, this is the version we claim. |
56 const char kNullVersion[] = "0.0.0.0"; | 59 const char kNullVersion[] = "0.0.0.0"; |
57 | 60 |
58 #endif // defined(GOOGLE_CHROME_BUILD) | |
59 | |
60 // The base directory on Windows looks like: | |
61 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\. | |
62 base::FilePath GetPepperFlashBaseDirectory() { | |
63 base::FilePath result; | |
64 PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, &result); | |
65 return result; | |
66 } | |
67 | |
68 #if defined(GOOGLE_CHROME_BUILD) | |
69 // Pepper Flash plugins have the version encoded in the path itself | 61 // Pepper Flash plugins have the version encoded in the path itself |
70 // so we need to enumerate the directories to find the full path. | 62 // so we need to enumerate the directories to find the full path. |
71 // On success, |latest_dir| returns something like: | 63 // On success, |latest_dir| returns something like: |
72 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\. | 64 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\. |
73 // |latest_version| returns the corresponding version number. |older_dirs| | 65 // |latest_version| returns the corresponding version number. |older_dirs| |
74 // returns directories of all older versions. | 66 // returns directories of all older versions. |
75 bool GetPepperFlashDirectory(base::FilePath* latest_dir, | 67 bool GetPepperFlashDirectory(base::FilePath* latest_dir, |
76 Version* latest_version, | 68 Version* latest_version, |
77 std::vector<base::FilePath>* older_dirs) { | 69 std::vector<base::FilePath>* older_dirs) { |
78 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 70 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
79 base::FilePath base_dir = GetPepperFlashBaseDirectory(); | 71 base::FilePath base_dir; |
| 72 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
| 73 &base_dir)) { |
| 74 return false; |
| 75 } |
| 76 |
80 bool found = false; | 77 bool found = false; |
81 base::FileEnumerator file_enumerator( | 78 base::FileEnumerator file_enumerator( |
82 base_dir, false, base::FileEnumerator::DIRECTORIES); | 79 base_dir, false, base::FileEnumerator::DIRECTORIES); |
83 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); | 80 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); |
84 path = file_enumerator.Next()) { | 81 path = file_enumerator.Next()) { |
85 Version version(path.BaseName().MaybeAsASCII()); | 82 Version version(path.BaseName().MaybeAsASCII()); |
86 if (!version.IsValid()) | 83 if (!version.IsValid()) |
87 continue; | 84 continue; |
88 if (found) { | 85 if (found) { |
89 if (version.CompareTo(*latest_version) > 0) { | 86 if (version.CompareTo(*latest_version) > 0) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 Version version; | 218 Version version; |
222 if (!chrome::CheckPepperFlashManifest(manifest, &version)) | 219 if (!chrome::CheckPepperFlashManifest(manifest, &version)) |
223 return false; | 220 return false; |
224 if (current_version_.CompareTo(version) > 0) | 221 if (current_version_.CompareTo(version) > 0) |
225 return false; | 222 return false; |
226 const base::FilePath unpacked_plugin = | 223 const base::FilePath unpacked_plugin = |
227 unpack_path.Append(chrome::kPepperFlashPluginFilename); | 224 unpack_path.Append(chrome::kPepperFlashPluginFilename); |
228 if (!base::PathExists(unpacked_plugin)) | 225 if (!base::PathExists(unpacked_plugin)) |
229 return false; | 226 return false; |
230 // Passed the basic tests. Time to install it. | 227 // Passed the basic tests. Time to install it. |
231 base::FilePath path = | 228 base::FilePath path; |
232 GetPepperFlashBaseDirectory().AppendASCII(version.GetString()); | 229 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
| 230 &path)) { |
| 231 return false; |
| 232 } |
| 233 path = path.AppendASCII(version.GetString()); |
233 if (base::PathExists(path)) | 234 if (base::PathExists(path)) |
234 return false; | 235 return false; |
235 current_version_ = version; | 236 current_version_ = version; |
236 | 237 |
237 if (!base::Move(unpack_path, path)) | 238 if (!base::Move(unpack_path, path)) |
238 return false; | 239 return false; |
239 #if defined(OS_LINUX) | 240 #if defined(OS_LINUX) |
240 const base::FilePath flash_path = | 241 const base::FilePath flash_path = |
241 path.Append(chrome::kPepperFlashPluginFilename); | 242 path.Append(chrome::kPepperFlashPluginFilename); |
242 // Populate the component updated flash hint file so that the zygote can | 243 // Populate the component updated flash hint file so that the zygote can |
243 // locate and preload the latest version of flash. | 244 // locate and preload the latest version of flash. |
244 if (!chrome::component_flash_hint_file::RecordFlashUpdate( | 245 if (!component_flash_hint_file::RecordFlashUpdate(flash_path, flash_path, |
245 flash_path, flash_path, version.GetString())) { | 246 version.GetString())) { |
246 if (!base::DeleteFile(path, true)) | 247 if (!base::DeleteFile(path, true)) |
247 LOG(ERROR) << "Hint file creation failed, but unable to delete " | 248 LOG(ERROR) << "Hint file creation failed, but unable to delete " |
248 "installed flash plugin."; | 249 "installed flash plugin."; |
249 return false; | 250 return false; |
250 } | 251 } |
251 #else | 252 #else |
252 // Installation is done. Now tell the rest of chrome. Both the path service | 253 // Installation is done. Now tell the rest of chrome. Both the path service |
253 // and to the plugin service. On Linux, a restart is required to use the new | 254 // and to the plugin service. On Linux, a restart is required to use the new |
254 // Flash version, so we do not do this. | 255 // Flash version, so we do not do this. |
255 PathService::Override(chrome::DIR_PEPPER_FLASH_PLUGIN, path); | 256 PathService::Override(chrome::DIR_PEPPER_FLASH_PLUGIN, path); |
(...skipping 28 matching lines...) Expand all Loading... |
284 pepflash.name = "pepper_flash"; | 285 pepflash.name = "pepper_flash"; |
285 pepflash.installer = new PepperFlashComponentInstaller(version); | 286 pepflash.installer = new PepperFlashComponentInstaller(version); |
286 pepflash.version = version; | 287 pepflash.version = version; |
287 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); | 288 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); |
288 if (!cus->RegisterComponent(pepflash)) | 289 if (!cus->RegisterComponent(pepflash)) |
289 NOTREACHED() << "Pepper Flash component registration failed."; | 290 NOTREACHED() << "Pepper Flash component registration failed."; |
290 } | 291 } |
291 | 292 |
292 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) { | 293 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) { |
293 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 294 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
294 base::FilePath path = GetPepperFlashBaseDirectory(); | 295 base::FilePath path; |
| 296 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
| 297 &path)) { |
| 298 return; |
| 299 } |
| 300 |
295 if (!base::PathExists(path)) { | 301 if (!base::PathExists(path)) { |
296 if (!base::CreateDirectory(path)) { | 302 if (!base::CreateDirectory(path)) { |
297 NOTREACHED() << "Could not create Pepper Flash directory."; | 303 NOTREACHED() << "Could not create Pepper Flash directory."; |
298 return; | 304 return; |
299 } | 305 } |
300 } | 306 } |
301 | 307 |
302 Version version(kNullVersion); | 308 Version version(kNullVersion); |
303 std::vector<base::FilePath> older_dirs; | 309 std::vector<base::FilePath> older_dirs; |
304 if (GetPepperFlashDirectory(&path, &version, &older_dirs)) { | 310 if (GetPepperFlashDirectory(&path, &version, &older_dirs)) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 350 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
345 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) | 351 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) |
346 return; | 352 return; |
347 BrowserThread::PostTask(BrowserThread::FILE, | 353 BrowserThread::PostTask(BrowserThread::FILE, |
348 FROM_HERE, | 354 FROM_HERE, |
349 base::Bind(&StartPepperFlashUpdateRegistration, cus)); | 355 base::Bind(&StartPepperFlashUpdateRegistration, cus)); |
350 #endif // defined(GOOGLE_CHROME_BUILD) | 356 #endif // defined(GOOGLE_CHROME_BUILD) |
351 } | 357 } |
352 | 358 |
353 } // namespace component_updater | 359 } // namespace component_updater |
OLD | NEW |