| Index: chrome/browser/component_updater/pepper_flash_component_installer.cc
|
| diff --git a/chrome/browser/component_updater/pepper_flash_component_installer.cc b/chrome/browser/component_updater/pepper_flash_component_installer.cc
|
| index cae975d5861e0411d1d0fe2877943522e0f8f803..472e25c771a484231ef6cebc5811b37c436fd85c 100644
|
| --- a/chrome/browser/component_updater/pepper_flash_component_installer.cc
|
| +++ b/chrome/browser/component_updater/pepper_flash_component_installer.cc
|
| @@ -32,6 +32,7 @@
|
| #include "chrome/common/pepper_flash.h"
|
| #include "chrome/common/ppapi_utils.h"
|
| #include "components/component_updater/component_updater_service.h"
|
| +#include "components/component_updater/default_component_installer.h"
|
| #include "components/update_client/update_client.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/plugin_service.h"
|
| @@ -57,53 +58,9 @@ const uint8_t kSha2Hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20,
|
| 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11,
|
| 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70,
|
| 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c};
|
| -
|
| -// If we don't have a Pepper Flash component, this is the version we claim.
|
| -const char kNullVersion[] = "0.0.0.0";
|
| -
|
| -// Pepper Flash plugins have the version encoded in the path itself
|
| -// so we need to enumerate the directories to find the full path.
|
| -// On success, |latest_dir| returns something like:
|
| -// <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\.
|
| -// |latest_version| returns the corresponding version number. |older_dirs|
|
| -// returns directories of all older versions.
|
| -bool GetPepperFlashDirectory(base::FilePath* latest_dir,
|
| - Version* latest_version,
|
| - std::vector<base::FilePath>* older_dirs) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| - base::FilePath base_dir;
|
| - if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN,
|
| - &base_dir)) {
|
| - return false;
|
| - }
|
| -
|
| - bool found = false;
|
| - base::FileEnumerator file_enumerator(
|
| - base_dir, false, base::FileEnumerator::DIRECTORIES);
|
| - for (base::FilePath path = file_enumerator.Next(); !path.value().empty();
|
| - path = file_enumerator.Next()) {
|
| - Version version(path.BaseName().MaybeAsASCII());
|
| - if (!version.IsValid())
|
| - continue;
|
| - if (found) {
|
| - if (version.CompareTo(*latest_version) > 0) {
|
| - older_dirs->push_back(*latest_dir);
|
| - *latest_dir = path;
|
| - *latest_version = version;
|
| - } else {
|
| - older_dirs->push_back(path);
|
| - }
|
| - } else {
|
| - *latest_dir = path;
|
| - *latest_version = version;
|
| - found = true;
|
| - }
|
| - }
|
| - return found;
|
| -}
|
| #endif // defined(GOOGLE_CHROME_BUILD)
|
|
|
| -#if !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD)
|
| +#if !defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD)
|
| bool MakePepperFlashPluginInfo(const base::FilePath& flash_path,
|
| const Version& flash_version,
|
| bool out_of_process,
|
| @@ -205,193 +162,99 @@ void RegisterPepperFlashWithChrome(const base::FilePath& path,
|
| plugin_info.ToWebPluginInfo(), true);
|
| PluginService::GetInstance()->RefreshPlugins();
|
| }
|
| -#endif // !defined(OS_LINUX) || defined(GOOGLE_CHROME_BUILD)
|
| +#endif // !defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD)
|
|
|
| -} // namespace
|
| -
|
| -class PepperFlashComponentInstaller : public update_client::CrxInstaller {
|
| +#if defined(GOOGLE_CHROME_BUILD)
|
| +class FlashComponentInstallerTraits : public ComponentInstallerTraits {
|
| public:
|
| - explicit PepperFlashComponentInstaller(const Version& version);
|
| -
|
| - // ComponentInstaller implementation:
|
| - void OnUpdateError(int error) override;
|
| -
|
| - bool Install(const base::DictionaryValue& manifest,
|
| - const base::FilePath& unpack_path) override;
|
| -
|
| - bool GetInstalledFile(const std::string& file,
|
| - base::FilePath* installed_file) override;
|
| -
|
| - bool Uninstall() override;
|
| + FlashComponentInstallerTraits();
|
| + ~FlashComponentInstallerTraits() override {}
|
|
|
| private:
|
| - ~PepperFlashComponentInstaller() override {}
|
| -
|
| - Version current_version_;
|
| + // The following methods override ComponentInstallerTraits.
|
| + bool CanAutoUpdate() const override;
|
| + bool RequiresNetworkEncryption() const override;
|
| + bool OnCustomInstall(const base::DictionaryValue& manifest,
|
| + const base::FilePath& install_dir) override;
|
| + bool VerifyInstallation(const base::DictionaryValue& manifest,
|
| + const base::FilePath& install_dir) const override;
|
| + void ComponentReady(const base::Version& version,
|
| + const base::FilePath& path,
|
| + std::unique_ptr<base::DictionaryValue> manifest) override;
|
| + base::FilePath GetRelativeInstallDir() const override;
|
| + void GetHash(std::vector<uint8_t>* hash) const override;
|
| + std::string GetName() const override;
|
| + std::string GetAp() const override;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FlashComponentInstallerTraits);
|
| };
|
|
|
| -PepperFlashComponentInstaller::PepperFlashComponentInstaller(
|
| - const Version& version)
|
| - : current_version_(version) {
|
| - DCHECK(version.IsValid());
|
| +FlashComponentInstallerTraits::FlashComponentInstallerTraits() {}
|
| +
|
| +bool FlashComponentInstallerTraits::CanAutoUpdate() const {
|
| + return true;
|
| }
|
|
|
| -void PepperFlashComponentInstaller::OnUpdateError(int error) {
|
| - NOTREACHED() << "Pepper Flash update error: " << error;
|
| +bool FlashComponentInstallerTraits::RequiresNetworkEncryption() const {
|
| + return false;
|
| }
|
|
|
| -bool PepperFlashComponentInstaller::Install(
|
| +bool FlashComponentInstallerTraits::OnCustomInstall(
|
| const base::DictionaryValue& manifest,
|
| - const base::FilePath& unpack_path) {
|
| - Version version;
|
| - if (!chrome::CheckPepperFlashManifest(manifest, &version))
|
| - return false;
|
| - if (current_version_.CompareTo(version) > 0)
|
| - return false;
|
| - const base::FilePath unpacked_plugin =
|
| - unpack_path.Append(chrome::kPepperFlashPluginFilename);
|
| - if (!base::PathExists(unpacked_plugin))
|
| - return false;
|
| - // Passed the basic tests. Time to install it.
|
| - base::FilePath path;
|
| - if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN,
|
| - &path)) {
|
| - return false;
|
| - }
|
| - path = path.AppendASCII(version.GetString());
|
| - if (base::PathExists(path))
|
| - return false;
|
| - current_version_ = version;
|
| -
|
| - if (!base::Move(unpack_path, path))
|
| - return false;
|
| + const base::FilePath& install_dir) {
|
| #if defined(OS_LINUX)
|
| const base::FilePath flash_path =
|
| - path.Append(chrome::kPepperFlashPluginFilename);
|
| + install_dir.Append(chrome::kPepperFlashPluginFilename);
|
| // Populate the component updated flash hint file so that the zygote can
|
| // locate and preload the latest version of flash.
|
| + std::string version;
|
| + if (!manifest.GetString("version", &version))
|
| + return false;
|
| if (!component_flash_hint_file::RecordFlashUpdate(flash_path, flash_path,
|
| - version.GetString())) {
|
| - if (!base::DeleteFile(path, true))
|
| - LOG(ERROR) << "Hint file creation failed, but unable to delete "
|
| - "installed flash plugin.";
|
| + version)) {
|
| return false;
|
| }
|
| -#else
|
| +#endif // defined(OS_LINUX)
|
| + return true;
|
| +}
|
| +
|
| +void FlashComponentInstallerTraits::ComponentReady(
|
| + const base::Version& version,
|
| + const base::FilePath& path,
|
| + std::unique_ptr<base::DictionaryValue> manifest) {
|
| +#if !defined(OS_LINUX)
|
| // Installation is done. Now tell the rest of chrome. Both the path service
|
| // and to the plugin service. On Linux, a restart is required to use the new
|
| // Flash version, so we do not do this.
|
| PathService::Override(chrome::DIR_PEPPER_FLASH_PLUGIN, path);
|
| - path = path.Append(chrome::kPepperFlashPluginFilename);
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&RegisterPepperFlashWithChrome, path, version));
|
| + RegisterPepperFlashWithChrome(path.Append(chrome::kPepperFlashPluginFilename),
|
| + version);
|
| #endif // !defined(OS_LINUX)
|
| - return true;
|
| }
|
|
|
| -bool PepperFlashComponentInstaller::GetInstalledFile(
|
| - const std::string& file,
|
| - base::FilePath* installed_file) {
|
| - return false;
|
| +bool FlashComponentInstallerTraits::VerifyInstallation(
|
| + const base::DictionaryValue& manifest,
|
| + const base::FilePath& install_dir) const {
|
| + Version unused;
|
| + return chrome::CheckPepperFlashManifest(manifest, &unused);
|
| }
|
|
|
| -bool PepperFlashComponentInstaller::Uninstall() {
|
| - return false;
|
| +// The base directory on Windows looks like:
|
| +// <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\.
|
| +base::FilePath FlashComponentInstallerTraits::GetRelativeInstallDir() const {
|
| + return base::FilePath(FILE_PATH_LITERAL("PepperFlash"));
|
| }
|
|
|
| -
|
| -
|
| -namespace {
|
| -
|
| -#if defined(GOOGLE_CHROME_BUILD)
|
| -void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus,
|
| - const Version& version) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - update_client::CrxComponent pepflash;
|
| - pepflash.name = "pepper_flash";
|
| - pepflash.installer = new PepperFlashComponentInstaller(version);
|
| - pepflash.version = version;
|
| - pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]);
|
| - if (!cus->RegisterComponent(pepflash))
|
| - NOTREACHED() << "Pepper Flash component registration failed.";
|
| +void FlashComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const {
|
| + hash->assign(kSha2Hash, kSha2Hash + arraysize(kSha2Hash));
|
| }
|
|
|
| -bool ValidatePepperFlashManifest(const base::FilePath& path) {
|
| - base::FilePath manifest_path(path.DirName().AppendASCII("manifest.json"));
|
| -
|
| - std::string manifest_data;
|
| - if (!base::ReadFileToString(manifest_path, &manifest_data))
|
| - return false;
|
| - std::unique_ptr<base::Value> manifest_value(
|
| - base::JSONReader::Read(manifest_data, base::JSON_ALLOW_TRAILING_COMMAS));
|
| - if (!manifest_value.get())
|
| - return false;
|
| - base::DictionaryValue* manifest = NULL;
|
| - if (!manifest_value->GetAsDictionary(&manifest))
|
| - return false;
|
| - Version version;
|
| - if (!chrome::CheckPepperFlashManifest(*manifest, &version))
|
| - return false;
|
| - return true;
|
| +std::string FlashComponentInstallerTraits::GetName() const {
|
| + return "pepper_flash";
|
| }
|
|
|
| -void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| - base::FilePath path;
|
| - if (!PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN,
|
| - &path)) {
|
| - return;
|
| - }
|
| -
|
| - if (!base::PathExists(path)) {
|
| - if (!base::CreateDirectory(path)) {
|
| - NOTREACHED() << "Could not create Pepper Flash directory.";
|
| - return;
|
| - }
|
| - }
|
| -
|
| - Version version(kNullVersion);
|
| - std::vector<base::FilePath> older_dirs;
|
| - if (GetPepperFlashDirectory(&path, &version, &older_dirs)) {
|
| - path = path.Append(chrome::kPepperFlashPluginFilename);
|
| - if (base::PathExists(path)) {
|
| - // Only register component pepper flash if it validates manifest check.
|
| - if (ValidatePepperFlashManifest(path)) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&RegisterPepperFlashWithChrome, path, version));
|
| - } else {
|
| - // Queue this version to be deleted.
|
| - older_dirs.push_back(path.DirName());
|
| - version = Version(kNullVersion);
|
| - }
|
| - } else {
|
| - version = Version(kNullVersion);
|
| - }
|
| - }
|
| -
|
| -#if defined(FLAPPER_AVAILABLE)
|
| - // If a version of Flash is bundled with Chrome, and it's a higher version
|
| - // than the version of the component, or the component has never been updated,
|
| - // then set the bundled version as the current version.
|
| - if (version.CompareTo(Version(FLAPPER_VERSION_STRING)) < 0)
|
| - version = Version(FLAPPER_VERSION_STRING);
|
| -#endif
|
| -
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&FinishPepperFlashUpdateRegistration, cus, version));
|
| -
|
| - // Remove older versions of Pepper Flash.
|
| - for (std::vector<base::FilePath>::iterator iter = older_dirs.begin();
|
| - iter != older_dirs.end();
|
| - ++iter) {
|
| - base::DeleteFile(*iter, true);
|
| - }
|
| +std::string FlashComponentInstallerTraits::GetAp() const {
|
| + return std::string();
|
| }
|
| #endif // defined(GOOGLE_CHROME_BUILD)
|
|
|
| @@ -404,9 +267,12 @@ void RegisterPepperFlashComponent(ComponentUpdateService* cus) {
|
| base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
|
| if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash))
|
| return;
|
| - BrowserThread::PostTask(BrowserThread::FILE,
|
| - FROM_HERE,
|
| - base::Bind(&StartPepperFlashUpdateRegistration, cus));
|
| + std::unique_ptr<ComponentInstallerTraits> traits(
|
| + new FlashComponentInstallerTraits);
|
| + // |cus| will take ownership of |installer| during installer->Register(cus).
|
| + DefaultComponentInstaller* installer =
|
| + new DefaultComponentInstaller(std::move(traits));
|
| + installer->Register(cus, base::Closure());
|
| #endif // defined(GOOGLE_CHROME_BUILD)
|
| }
|
|
|
|
|