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