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/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/version.h" | 22 #include "base/version.h" |
22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
23 #include "chrome/browser/component_updater/flash_component_installer.h" | 24 #include "chrome/browser/component_updater/flash_component_installer.h" |
24 #include "chrome/browser/plugins/plugin_prefs.h" | 25 #include "chrome/browser/plugins/plugin_prefs.h" |
25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/component_flash_hint_file.h" |
28 #include "chrome/common/pepper_flash.h" | 30 #include "chrome/common/pepper_flash.h" |
29 #include "chrome/common/ppapi_utils.h" | 31 #include "chrome/common/ppapi_utils.h" |
30 #include "components/component_updater/component_updater_service.h" | 32 #include "components/component_updater/component_updater_service.h" |
31 #include "components/update_client/update_client.h" | 33 #include "components/update_client/update_client.h" |
32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/plugin_service.h" | 35 #include "content/public/browser/plugin_service.h" |
34 #include "content/public/common/content_constants.h" | 36 #include "content/public/common/content_constants.h" |
35 #include "content/public/common/pepper_plugin_info.h" | 37 #include "content/public/common/pepper_plugin_info.h" |
| 38 #include "crypto/sha2.h" |
36 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT | 39 #include "flapper_version.h" // In SHARED_INTERMEDIATE_DIR. NOLINT |
37 #include "ppapi/shared_impl/ppapi_permissions.h" | 40 #include "ppapi/shared_impl/ppapi_permissions.h" |
38 | 41 |
39 using content::BrowserThread; | 42 using content::BrowserThread; |
40 using content::PluginService; | 43 using content::PluginService; |
41 | 44 |
42 namespace component_updater { | 45 namespace component_updater { |
43 | 46 |
44 namespace { | 47 namespace { |
45 | 48 |
46 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) | 49 #if defined(GOOGLE_CHROME_BUILD) |
47 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. | 50 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb. |
48 const uint8_t kSha2Hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, | 51 const uint8_t kSha2Hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20, |
49 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, | 52 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11, |
50 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, | 53 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70, |
51 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; | 54 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c}; |
52 | 55 |
53 // If we don't have a Pepper Flash component, this is the version we claim. | 56 // If we don't have a Pepper Flash component, this is the version we claim. |
54 const char kNullVersion[] = "0.0.0.0"; | 57 const char kNullVersion[] = "0.0.0.0"; |
55 | 58 |
56 #endif // defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) | 59 #endif // defined(GOOGLE_CHROME_BUILD) |
57 | 60 |
58 // The base directory on Windows looks like: | 61 // The base directory on Windows looks like: |
59 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\. | 62 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\. |
60 base::FilePath GetPepperFlashBaseDirectory() { | 63 base::FilePath GetPepperFlashBaseDirectory() { |
61 base::FilePath result; | 64 base::FilePath result; |
62 PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, &result); | 65 PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, &result); |
63 return result; | 66 return result; |
64 } | 67 } |
65 | 68 |
66 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) | 69 #if defined(GOOGLE_CHROME_BUILD) |
67 // Pepper Flash plugins have the version encoded in the path itself | 70 // Pepper Flash plugins have the version encoded in the path itself |
68 // so we need to enumerate the directories to find the full path. | 71 // so we need to enumerate the directories to find the full path. |
69 // On success, |latest_dir| returns something like: | 72 // On success, |latest_dir| returns something like: |
70 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\. | 73 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\. |
71 // |latest_version| returns the corresponding version number. |older_dirs| | 74 // |latest_version| returns the corresponding version number. |older_dirs| |
72 // returns directories of all older versions. | 75 // returns directories of all older versions. |
73 bool GetPepperFlashDirectory(base::FilePath* latest_dir, | 76 bool GetPepperFlashDirectory(base::FilePath* latest_dir, |
74 Version* latest_version, | 77 Version* latest_version, |
75 std::vector<base::FilePath>* older_dirs) { | 78 std::vector<base::FilePath>* older_dirs) { |
76 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 79 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
(...skipping 15 matching lines...) Expand all Loading... |
92 older_dirs->push_back(path); | 95 older_dirs->push_back(path); |
93 } | 96 } |
94 } else { | 97 } else { |
95 *latest_dir = path; | 98 *latest_dir = path; |
96 *latest_version = version; | 99 *latest_version = version; |
97 found = true; | 100 found = true; |
98 } | 101 } |
99 } | 102 } |
100 return found; | 103 return found; |
101 } | 104 } |
102 #endif // defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) | 105 #endif // defined(GOOGLE_CHROME_BUILD) |
103 | 106 |
| 107 #if !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) |
104 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path, | 108 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path, |
105 const Version& flash_version, | 109 const Version& flash_version, |
106 bool out_of_process, | 110 bool out_of_process, |
107 content::PepperPluginInfo* plugin_info) { | 111 content::PepperPluginInfo* plugin_info) { |
108 if (!flash_version.IsValid()) | 112 if (!flash_version.IsValid()) |
109 return false; | 113 return false; |
110 const std::vector<uint32_t> ver_nums = flash_version.components(); | 114 const std::vector<uint32_t> ver_nums = flash_version.components(); |
111 if (ver_nums.size() < 3) | 115 if (ver_nums.size() < 3) |
112 return false; | 116 return false; |
113 | 117 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 174 |
171 // If the version is newer, remove the old one first. | 175 // If the version is newer, remove the old one first. |
172 PluginService::GetInstance()->UnregisterInternalPlugin(it->path); | 176 PluginService::GetInstance()->UnregisterInternalPlugin(it->path); |
173 break; | 177 break; |
174 } | 178 } |
175 | 179 |
176 PluginService::GetInstance()->RegisterInternalPlugin( | 180 PluginService::GetInstance()->RegisterInternalPlugin( |
177 plugin_info.ToWebPluginInfo(), true); | 181 plugin_info.ToWebPluginInfo(), true); |
178 PluginService::GetInstance()->RefreshPlugins(); | 182 PluginService::GetInstance()->RefreshPlugins(); |
179 } | 183 } |
| 184 #endif // !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) |
180 | 185 |
181 } // namespace | 186 } // namespace |
182 | 187 |
183 class PepperFlashComponentInstaller : public update_client::CrxInstaller { | 188 class PepperFlashComponentInstaller : public update_client::CrxInstaller { |
184 public: | 189 public: |
185 explicit PepperFlashComponentInstaller(const Version& version); | 190 explicit PepperFlashComponentInstaller(const Version& version); |
186 | 191 |
187 // ComponentInstaller implementation: | 192 // ComponentInstaller implementation: |
188 void OnUpdateError(int error) override; | 193 void OnUpdateError(int error) override; |
189 | 194 |
(...skipping 22 matching lines...) Expand all Loading... |
212 } | 217 } |
213 | 218 |
214 bool PepperFlashComponentInstaller::Install( | 219 bool PepperFlashComponentInstaller::Install( |
215 const base::DictionaryValue& manifest, | 220 const base::DictionaryValue& manifest, |
216 const base::FilePath& unpack_path) { | 221 const base::FilePath& unpack_path) { |
217 Version version; | 222 Version version; |
218 if (!chrome::CheckPepperFlashManifest(manifest, &version)) | 223 if (!chrome::CheckPepperFlashManifest(manifest, &version)) |
219 return false; | 224 return false; |
220 if (current_version_.CompareTo(version) > 0) | 225 if (current_version_.CompareTo(version) > 0) |
221 return false; | 226 return false; |
222 if (!base::PathExists(unpack_path.Append(chrome::kPepperFlashPluginFilename))) | 227 base::FilePath unpacked_plugin = |
| 228 unpack_path.Append(chrome::kPepperFlashPluginFilename); |
| 229 if (!base::PathExists(unpacked_plugin)) |
223 return false; | 230 return false; |
224 // Passed the basic tests. Time to install it. | 231 // Passed the basic tests. Time to install it. |
225 base::FilePath path = | 232 base::FilePath path = |
226 GetPepperFlashBaseDirectory().AppendASCII(version.GetString()); | 233 GetPepperFlashBaseDirectory().AppendASCII(version.GetString()); |
227 if (base::PathExists(path)) | 234 if (base::PathExists(path)) |
228 return false; | 235 return false; |
| 236 current_version_ = version; |
| 237 |
229 if (!base::Move(unpack_path, path)) | 238 if (!base::Move(unpack_path, path)) |
230 return false; | 239 return false; |
| 240 #if defined(OS_LINUX) |
| 241 base::FilePath flash_path = path.Append(chrome::kPepperFlashPluginFilename); |
| 242 // Populate the component updated flash hint file so that the zygote can |
| 243 // locate and preload the latest version of flash. |
| 244 if (!chrome::ComponentFlashHintFile::RecordFlashUpdate(flash_path, flash_path, |
| 245 version.GetString())) { |
| 246 if (!base::DeleteFile(path, true)) |
| 247 LOG(WARNING) << "Hint file creation failed, but unable to delete " |
| 248 "installed flash plugin."; |
| 249 return false; |
| 250 } |
| 251 #else |
231 // Installation is done. Now tell the rest of chrome. Both the path service | 252 // Installation is done. Now tell the rest of chrome. Both the path service |
232 // and to the plugin service. | 253 // and to the plugin service. On Linux, a restart is required to use the new |
233 current_version_ = version; | 254 // Flash version, so we do not do this. |
234 PathService::Override(chrome::DIR_PEPPER_FLASH_PLUGIN, path); | 255 PathService::Override(chrome::DIR_PEPPER_FLASH_PLUGIN, path); |
235 path = path.Append(chrome::kPepperFlashPluginFilename); | 256 path = path.Append(chrome::kPepperFlashPluginFilename); |
236 BrowserThread::PostTask( | 257 BrowserThread::PostTask( |
237 BrowserThread::UI, | 258 BrowserThread::UI, |
238 FROM_HERE, | 259 FROM_HERE, |
239 base::Bind(&RegisterPepperFlashWithChrome, path, version)); | 260 base::Bind(&RegisterPepperFlashWithChrome, path, version)); |
| 261 #endif // !defined(OS_LINUX) |
240 return true; | 262 return true; |
241 } | 263 } |
242 | 264 |
243 bool PepperFlashComponentInstaller::GetInstalledFile( | 265 bool PepperFlashComponentInstaller::GetInstalledFile( |
244 const std::string& file, | 266 const std::string& file, |
245 base::FilePath* installed_file) { | 267 base::FilePath* installed_file) { |
246 return false; | 268 return false; |
247 } | 269 } |
248 | 270 |
249 bool PepperFlashComponentInstaller::Uninstall() { | 271 bool PepperFlashComponentInstaller::Uninstall() { |
250 return false; | 272 return false; |
251 } | 273 } |
252 | 274 |
253 | 275 |
254 | 276 |
255 namespace { | 277 namespace { |
256 | 278 |
257 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) | 279 #if defined(GOOGLE_CHROME_BUILD) |
258 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus, | 280 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus, |
259 const Version& version) { | 281 const Version& version) { |
260 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 282 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
261 update_client::CrxComponent pepflash; | 283 update_client::CrxComponent pepflash; |
262 pepflash.name = "pepper_flash"; | 284 pepflash.name = "pepper_flash"; |
263 pepflash.installer = new PepperFlashComponentInstaller(version); | 285 pepflash.installer = new PepperFlashComponentInstaller(version); |
264 pepflash.version = version; | 286 pepflash.version = version; |
265 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); | 287 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); |
266 if (!cus->RegisterComponent(pepflash)) | 288 if (!cus->RegisterComponent(pepflash)) |
267 NOTREACHED() << "Pepper Flash component registration failed."; | 289 NOTREACHED() << "Pepper Flash component registration failed."; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 FROM_HERE, | 326 FROM_HERE, |
305 base::Bind(&FinishPepperFlashUpdateRegistration, cus, version)); | 327 base::Bind(&FinishPepperFlashUpdateRegistration, cus, version)); |
306 | 328 |
307 // Remove older versions of Pepper Flash. | 329 // Remove older versions of Pepper Flash. |
308 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); | 330 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); |
309 iter != older_dirs.end(); | 331 iter != older_dirs.end(); |
310 ++iter) { | 332 ++iter) { |
311 base::DeleteFile(*iter, true); | 333 base::DeleteFile(*iter, true); |
312 } | 334 } |
313 } | 335 } |
314 #endif // defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) | 336 #endif // defined(GOOGLE_CHROME_BUILD) |
315 | 337 |
316 } // namespace | 338 } // namespace |
317 | 339 |
318 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { | 340 void RegisterPepperFlashComponent(ComponentUpdateService* cus) { |
319 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) | 341 #if defined(GOOGLE_CHROME_BUILD) |
320 // Component updated flash supersedes bundled flash therefore if that one | 342 // Component updated flash supersedes bundled flash therefore if that one |
321 // is disabled then this one should never install. | 343 // is disabled then this one should never install. |
322 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 344 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
323 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) | 345 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) |
324 return; | 346 return; |
325 BrowserThread::PostTask(BrowserThread::FILE, | 347 BrowserThread::PostTask(BrowserThread::FILE, |
326 FROM_HERE, | 348 FROM_HERE, |
327 base::Bind(&StartPepperFlashUpdateRegistration, cus)); | 349 base::Bind(&StartPepperFlashUpdateRegistration, cus)); |
328 #endif | 350 #endif |
329 } | 351 } |
330 | 352 |
331 } // namespace component_updater | 353 } // namespace component_updater |
OLD | NEW |