| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // 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. |
| 59 const char kNullVersion[] = "0.0.0.0"; | 59 const char kNullVersion[] = "0.0.0.0"; |
| 60 | 60 |
| 61 // Pepper Flash plugins have the version encoded in the path itself | 61 // Pepper Flash plugins have the version encoded in the path itself |
| 62 // 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. |
| 63 // On success, |latest_dir| returns something like: | 63 // On success, |latest_dir| returns something like: |
| 64 // <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\. |
| 65 // |latest_version| returns the corresponding version number. |older_dirs| | 65 // |latest_version| returns the corresponding version number. |older_dirs| |
| 66 // returns directories of all older versions. | 66 // returns directories of all older versions. |
| 67 bool GetPepperFlashDirectory(base::FilePath* latest_dir, | 67 bool GetPepperFlashDirectory(base::FilePath* latest_dir, |
| 68 base::Version* latest_version, | 68 Version* latest_version, |
| 69 std::vector<base::FilePath>* older_dirs) { | 69 std::vector<base::FilePath>* older_dirs) { |
| 70 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 70 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 71 base::FilePath base_dir; | 71 base::FilePath base_dir; |
| 72 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | 72 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
| 73 &base_dir)) { | 73 &base_dir)) { |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool found = false; | 77 bool found = false; |
| 78 base::FileEnumerator file_enumerator( | 78 base::FileEnumerator file_enumerator( |
| 79 base_dir, false, base::FileEnumerator::DIRECTORIES); | 79 base_dir, false, base::FileEnumerator::DIRECTORIES); |
| 80 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); | 80 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); |
| 81 path = file_enumerator.Next()) { | 81 path = file_enumerator.Next()) { |
| 82 base::Version version(path.BaseName().MaybeAsASCII()); | 82 Version version(path.BaseName().MaybeAsASCII()); |
| 83 if (!version.IsValid()) | 83 if (!version.IsValid()) |
| 84 continue; | 84 continue; |
| 85 if (found) { | 85 if (found) { |
| 86 if (version.CompareTo(*latest_version) > 0) { | 86 if (version.CompareTo(*latest_version) > 0) { |
| 87 older_dirs->push_back(*latest_dir); | 87 older_dirs->push_back(*latest_dir); |
| 88 *latest_dir = path; | 88 *latest_dir = path; |
| 89 *latest_version = version; | 89 *latest_version = version; |
| 90 } else { | 90 } else { |
| 91 older_dirs->push_back(path); | 91 older_dirs->push_back(path); |
| 92 } | 92 } |
| 93 } else { | 93 } else { |
| 94 *latest_dir = path; | 94 *latest_dir = path; |
| 95 *latest_version = version; | 95 *latest_version = version; |
| 96 found = true; | 96 found = true; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 return found; | 99 return found; |
| 100 } | 100 } |
| 101 #endif // defined(GOOGLE_CHROME_BUILD) | 101 #endif // defined(GOOGLE_CHROME_BUILD) |
| 102 | 102 |
| 103 #if !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) | 103 #if !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) |
| 104 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path, | 104 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path, |
| 105 const base::Version& flash_version, | 105 const Version& flash_version, |
| 106 bool out_of_process, | 106 bool out_of_process, |
| 107 content::PepperPluginInfo* plugin_info) { | 107 content::PepperPluginInfo* plugin_info) { |
| 108 if (!flash_version.IsValid()) | 108 if (!flash_version.IsValid()) |
| 109 return false; | 109 return false; |
| 110 const std::vector<uint32_t> ver_nums = flash_version.components(); | 110 const std::vector<uint32_t> ver_nums = flash_version.components(); |
| 111 if (ver_nums.size() < 3) | 111 if (ver_nums.size() < 3) |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 plugin_info->is_internal = false; | 114 plugin_info->is_internal = false; |
| 115 plugin_info->is_out_of_process = out_of_process; | 115 plugin_info->is_out_of_process = out_of_process; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 139 | 139 |
| 140 bool IsPepperFlash(const content::WebPluginInfo& plugin) { | 140 bool IsPepperFlash(const content::WebPluginInfo& plugin) { |
| 141 // We try to recognize Pepper Flash by the following criteria: | 141 // We try to recognize Pepper Flash by the following criteria: |
| 142 // * It is a Pepper plugin. | 142 // * It is a Pepper plugin. |
| 143 // * It has the special Flash permissions. | 143 // * It has the special Flash permissions. |
| 144 return plugin.is_pepper_plugin() && | 144 return plugin.is_pepper_plugin() && |
| 145 (plugin.pepper_permissions & ppapi::PERMISSION_FLASH); | 145 (plugin.pepper_permissions & ppapi::PERMISSION_FLASH); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void RegisterPepperFlashWithChrome(const base::FilePath& path, | 148 void RegisterPepperFlashWithChrome(const base::FilePath& path, |
| 149 const base::Version& version) { | 149 const Version& version) { |
| 150 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 150 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 151 content::PepperPluginInfo plugin_info; | 151 content::PepperPluginInfo plugin_info; |
| 152 if (!MakePepperFlashPluginInfo(path, version, true, &plugin_info)) | 152 if (!MakePepperFlashPluginInfo(path, version, true, &plugin_info)) |
| 153 return; | 153 return; |
| 154 | 154 |
| 155 std::vector<content::WebPluginInfo> plugins; | 155 std::vector<content::WebPluginInfo> plugins; |
| 156 PluginService::GetInstance()->GetInternalPlugins(&plugins); | 156 PluginService::GetInstance()->GetInternalPlugins(&plugins); |
| 157 for (std::vector<content::WebPluginInfo>::const_iterator it = | 157 for (std::vector<content::WebPluginInfo>::const_iterator it = |
| 158 plugins.begin(); | 158 plugins.begin(); |
| 159 it != plugins.end(); | 159 it != plugins.end(); |
| 160 ++it) { | 160 ++it) { |
| 161 if (!IsPepperFlash(*it)) | 161 if (!IsPepperFlash(*it)) |
| 162 continue; | 162 continue; |
| 163 | 163 |
| 164 // Do it only if the version we're trying to register is newer. | 164 // Do it only if the version we're trying to register is newer. |
| 165 base::Version registered_version(base::UTF16ToUTF8(it->version)); | 165 Version registered_version(base::UTF16ToUTF8(it->version)); |
| 166 if (registered_version.IsValid() && | 166 if (registered_version.IsValid() && |
| 167 version.CompareTo(registered_version) <= 0) { | 167 version.CompareTo(registered_version) <= 0) { |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // If the version is newer, remove the old one first. | 171 // If the version is newer, remove the old one first. |
| 172 PluginService::GetInstance()->UnregisterInternalPlugin(it->path); | 172 PluginService::GetInstance()->UnregisterInternalPlugin(it->path); |
| 173 break; | 173 break; |
| 174 } | 174 } |
| 175 | 175 |
| 176 PluginService::GetInstance()->RegisterInternalPlugin( | 176 PluginService::GetInstance()->RegisterInternalPlugin( |
| 177 plugin_info.ToWebPluginInfo(), true); | 177 plugin_info.ToWebPluginInfo(), true); |
| 178 PluginService::GetInstance()->RefreshPlugins(); | 178 PluginService::GetInstance()->RefreshPlugins(); |
| 179 } | 179 } |
| 180 #endif // !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) | 180 #endif // !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD) |
| 181 | 181 |
| 182 } // namespace | 182 } // namespace |
| 183 | 183 |
| 184 class PepperFlashComponentInstaller : public update_client::CrxInstaller { | 184 class PepperFlashComponentInstaller : public update_client::CrxInstaller { |
| 185 public: | 185 public: |
| 186 explicit PepperFlashComponentInstaller(const base::Version& version); | 186 explicit PepperFlashComponentInstaller(const Version& version); |
| 187 | 187 |
| 188 // ComponentInstaller implementation: | 188 // ComponentInstaller implementation: |
| 189 void OnUpdateError(int error) override; | 189 void OnUpdateError(int error) override; |
| 190 | 190 |
| 191 bool Install(const base::DictionaryValue& manifest, | 191 bool Install(const base::DictionaryValue& manifest, |
| 192 const base::FilePath& unpack_path) override; | 192 const base::FilePath& unpack_path) override; |
| 193 | 193 |
| 194 bool GetInstalledFile(const std::string& file, | 194 bool GetInstalledFile(const std::string& file, |
| 195 base::FilePath* installed_file) override; | 195 base::FilePath* installed_file) override; |
| 196 | 196 |
| 197 bool Uninstall() override; | 197 bool Uninstall() override; |
| 198 | 198 |
| 199 private: | 199 private: |
| 200 ~PepperFlashComponentInstaller() override {} | 200 ~PepperFlashComponentInstaller() override {} |
| 201 | 201 |
| 202 base::Version current_version_; | 202 Version current_version_; |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 PepperFlashComponentInstaller::PepperFlashComponentInstaller( | 205 PepperFlashComponentInstaller::PepperFlashComponentInstaller( |
| 206 const base::Version& version) | 206 const Version& version) |
| 207 : current_version_(version) { | 207 : current_version_(version) { |
| 208 DCHECK(version.IsValid()); | 208 DCHECK(version.IsValid()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void PepperFlashComponentInstaller::OnUpdateError(int error) { | 211 void PepperFlashComponentInstaller::OnUpdateError(int error) { |
| 212 NOTREACHED() << "Pepper Flash update error: " << error; | 212 NOTREACHED() << "Pepper Flash update error: " << error; |
| 213 } | 213 } |
| 214 | 214 |
| 215 bool PepperFlashComponentInstaller::Install( | 215 bool PepperFlashComponentInstaller::Install( |
| 216 const base::DictionaryValue& manifest, | 216 const base::DictionaryValue& manifest, |
| 217 const base::FilePath& unpack_path) { | 217 const base::FilePath& unpack_path) { |
| 218 base::Version version; | 218 Version version; |
| 219 if (!chrome::CheckPepperFlashManifest(manifest, &version)) | 219 if (!chrome::CheckPepperFlashManifest(manifest, &version)) |
| 220 return false; | 220 return false; |
| 221 if (current_version_.CompareTo(version) > 0) | 221 if (current_version_.CompareTo(version) > 0) |
| 222 return false; | 222 return false; |
| 223 const base::FilePath unpacked_plugin = | 223 const base::FilePath unpacked_plugin = |
| 224 unpack_path.Append(chrome::kPepperFlashPluginFilename); | 224 unpack_path.Append(chrome::kPepperFlashPluginFilename); |
| 225 if (!base::PathExists(unpacked_plugin)) | 225 if (!base::PathExists(unpacked_plugin)) |
| 226 return false; | 226 return false; |
| 227 // Passed the basic tests. Time to install it. | 227 // Passed the basic tests. Time to install it. |
| 228 base::FilePath path; | 228 base::FilePath path; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 bool PepperFlashComponentInstaller::Uninstall() { | 272 bool PepperFlashComponentInstaller::Uninstall() { |
| 273 return false; | 273 return false; |
| 274 } | 274 } |
| 275 | 275 |
| 276 | 276 |
| 277 | 277 |
| 278 namespace { | 278 namespace { |
| 279 | 279 |
| 280 #if defined(GOOGLE_CHROME_BUILD) | 280 #if defined(GOOGLE_CHROME_BUILD) |
| 281 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus, | 281 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus, |
| 282 const base::Version& version) { | 282 const Version& version) { |
| 283 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 283 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 284 update_client::CrxComponent pepflash; | 284 update_client::CrxComponent pepflash; |
| 285 pepflash.name = "pepper_flash"; | 285 pepflash.name = "pepper_flash"; |
| 286 pepflash.installer = new PepperFlashComponentInstaller(version); | 286 pepflash.installer = new PepperFlashComponentInstaller(version); |
| 287 pepflash.version = version; | 287 pepflash.version = version; |
| 288 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); | 288 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); |
| 289 if (!cus->RegisterComponent(pepflash)) | 289 if (!cus->RegisterComponent(pepflash)) |
| 290 NOTREACHED() << "Pepper Flash component registration failed."; | 290 NOTREACHED() << "Pepper Flash component registration failed."; |
| 291 } | 291 } |
| 292 | 292 |
| 293 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) { | 293 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) { |
| 294 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 294 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 295 base::FilePath path; | 295 base::FilePath path; |
| 296 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | 296 if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
| 297 &path)) { | 297 &path)) { |
| 298 return; | 298 return; |
| 299 } | 299 } |
| 300 | 300 |
| 301 if (!base::PathExists(path)) { | 301 if (!base::PathExists(path)) { |
| 302 if (!base::CreateDirectory(path)) { | 302 if (!base::CreateDirectory(path)) { |
| 303 NOTREACHED() << "Could not create Pepper Flash directory."; | 303 NOTREACHED() << "Could not create Pepper Flash directory."; |
| 304 return; | 304 return; |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 base::Version version(kNullVersion); | 308 Version version(kNullVersion); |
| 309 std::vector<base::FilePath> older_dirs; | 309 std::vector<base::FilePath> older_dirs; |
| 310 if (GetPepperFlashDirectory(&path, &version, &older_dirs)) { | 310 if (GetPepperFlashDirectory(&path, &version, &older_dirs)) { |
| 311 path = path.Append(chrome::kPepperFlashPluginFilename); | 311 path = path.Append(chrome::kPepperFlashPluginFilename); |
| 312 if (base::PathExists(path)) { | 312 if (base::PathExists(path)) { |
| 313 BrowserThread::PostTask( | 313 BrowserThread::PostTask( |
| 314 BrowserThread::UI, | 314 BrowserThread::UI, |
| 315 FROM_HERE, | 315 FROM_HERE, |
| 316 base::Bind(&RegisterPepperFlashWithChrome, path, version)); | 316 base::Bind(&RegisterPepperFlashWithChrome, path, version)); |
| 317 } else { | 317 } else { |
| 318 version = base::Version(kNullVersion); | 318 version = Version(kNullVersion); |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 #if defined(FLAPPER_AVAILABLE) | 322 #if defined(FLAPPER_AVAILABLE) |
| 323 // If a version of Flash is bundled with Chrome, and it's a higher version | 323 // If a version of Flash is bundled with Chrome, and it's a higher version |
| 324 // than the version of the component, or the component has never been updated, | 324 // than the version of the component, or the component has never been updated, |
| 325 // then set the bundled version as the current version. | 325 // then set the bundled version as the current version. |
| 326 if (version.CompareTo(Version(FLAPPER_VERSION_STRING)) < 0) | 326 if (version.CompareTo(Version(FLAPPER_VERSION_STRING)) < 0) |
| 327 version = base::Version(FLAPPER_VERSION_STRING); | 327 version = Version(FLAPPER_VERSION_STRING); |
| 328 #endif | 328 #endif |
| 329 | 329 |
| 330 BrowserThread::PostTask( | 330 BrowserThread::PostTask( |
| 331 BrowserThread::UI, | 331 BrowserThread::UI, |
| 332 FROM_HERE, | 332 FROM_HERE, |
| 333 base::Bind(&FinishPepperFlashUpdateRegistration, cus, version)); | 333 base::Bind(&FinishPepperFlashUpdateRegistration, cus, version)); |
| 334 | 334 |
| 335 // Remove older versions of Pepper Flash. | 335 // Remove older versions of Pepper Flash. |
| 336 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); | 336 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); |
| 337 iter != older_dirs.end(); | 337 iter != older_dirs.end(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 350 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 350 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 351 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) | 351 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) |
| 352 return; | 352 return; |
| 353 BrowserThread::PostTask(BrowserThread::FILE, | 353 BrowserThread::PostTask(BrowserThread::FILE, |
| 354 FROM_HERE, | 354 FROM_HERE, |
| 355 base::Bind(&StartPepperFlashUpdateRegistration, cus)); | 355 base::Bind(&StartPepperFlashUpdateRegistration, cus)); |
| 356 #endif // defined(GOOGLE_CHROME_BUILD) | 356 #endif // defined(GOOGLE_CHROME_BUILD) |
| 357 } | 357 } |
| 358 | 358 |
| 359 } // namespace component_updater | 359 } // namespace component_updater |
| OLD | NEW |