diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 21:17:34 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 21:17:34 +0000 |
commit | 4289d9b66a1453aad1115f6ede0007faab22d6d4 (patch) | |
tree | a9fc79dd283f3561bd24cea14342f39552ed05c4 | |
parent | 811f3431f0066d9c4d94deb8af113df65dd67d6a (diff) | |
download | chromium_src-4289d9b66a1453aad1115f6ede0007faab22d6d4.zip chromium_src-4289d9b66a1453aad1115f6ede0007faab22d6d4.tar.gz chromium_src-4289d9b66a1453aad1115f6ede0007faab22d6d4.tar.bz2 |
Make the download manager display a scary file warning if an
extensions is not from the gallery.
Review URL: http://codereview.chromium.org/159379
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21620 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/download_manager.cc | 12 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 19 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 49 |
3 files changed, 51 insertions, 29 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 1a3fb53..d8e3237 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -569,8 +569,16 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) { info->suggested_path = info->suggested_path.Append(generated_name); if (!info->save_as) { - // Let's check if this download is dangerous, based on its name. - info->is_dangerous = IsDangerous(info->suggested_path.BaseName()); + // Downloads can be marked as dangerous for two reasons: + // a) They have a dangerous-looking filename + // b) They are an extension that is not from the gallery + if (IsDangerous(info->suggested_path.BaseName())) + info->is_dangerous = true; + else if (info->mime_type == Extension::kMimeType && + !ExtensionsService::IsDownloadFromGallery(info->url, + info->referrer_url)) { + info->is_dangerous = true; + } } // We need to move over to the download thread because we don't want to stat diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 0ef074c..ee5fc8c 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -87,6 +87,17 @@ const char* kSignatureVerificationInitFailed = "caused by a public key in the wrong format (should encode algorithm)."; } +// static +bool ExtensionsService::IsDownloadFromGallery(const GURL& download_url, + const GURL& referrer_url) { + if (StartsWithASCII(download_url.spec(), kGalleryDownloadURLPrefix, false) && + StartsWithASCII(referrer_url.spec(), kGalleryURLPrefix, false)) { + return true; + } else { + return false; + } +} + // This class coordinates an extension unpack task which is run in a separate // process. Results are sent back to this class, which we route to the // ExtensionServiceBackend. @@ -302,13 +313,11 @@ void ExtensionsService::InstallExtension(const FilePath& extension_path) { void ExtensionsService::InstallExtension(const FilePath& extension_path, const GURL& download_url, const GURL& referrer_url) { - bool from_gallery = - StartsWithASCII(download_url.spec(), kGalleryDownloadURLPrefix, false) && - StartsWithASCII(referrer_url.spec(), kGalleryURLPrefix, false); - backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), - &ExtensionsServiceBackend::InstallExtension, extension_path, from_gallery, + &ExtensionsServiceBackend::InstallExtension, extension_path, + IsDownloadFromGallery(download_url, referrer_url), scoped_refptr<ExtensionsService>(this))); + } void ExtensionsService::UpdateExtension(const std::string& id, diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 29cf798..8e0305f 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -67,18 +67,6 @@ class ExtensionsService // file, in bytes. This should be a multiple of 4. static const size_t kExtensionHeaderMagicSize = 4; - // The maximum size the crx parser will tolerate for a public key. - static const size_t kMaxPublicKeySize = 1 << 16; - - // The maximum size the crx parser will tolerate for a signature. - static const size_t kMaxSignatureSize = 1 << 16; - - // The magic character sequence at the beginning of each crx file. - static const char kExtensionHeaderMagic[]; - - // The current version of the crx format. - static const uint32 kCurrentVersion = 2; - // This header is the first data at the beginning of an extension. Its // contents are purposely 32-bit aligned so that it can just be slurped into // a struct without manual parsing. @@ -91,6 +79,18 @@ class ExtensionsService // The signature follows. }; + // The maximum size the crx parser will tolerate for a public key. + static const size_t kMaxPublicKeySize = 1 << 16; + + // The maximum size the crx parser will tolerate for a signature. + static const size_t kMaxSignatureSize = 1 << 16; + + // The magic character sequence at the beginning of each crx file. + static const char kExtensionHeaderMagic[]; + + // The current version of the crx format. + static const uint32 kCurrentVersion = 2; + // The name of the directory inside the profile where extensions are // installed to. static const char* kInstallDirectoryName; @@ -98,6 +98,21 @@ class ExtensionsService // If auto-updates are turned on, default to running every 5 hours. static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5; + // The name of the file that the current active version number is stored in. + static const char* kCurrentVersionFileName; + + // Hack: + // Extensions downloaded from kGalleryDownloadURLPrefix initiated from pages + // with kGalleryURLPrefix will not require --enable-extensions and will be + // prompt-free. + static const char* kGalleryDownloadURLPrefix; + static const char* kGalleryURLPrefix; + + // Determine if a given extension download should be treated as if it came + // from the gallery. + static bool IsDownloadFromGallery(const GURL& download_url, + const GURL& referrer_url); + ExtensionsService(Profile* profile, const CommandLine* command_line, PrefService* prefs, @@ -182,16 +197,6 @@ class ExtensionsService void SetProviderForTesting(Extension::Location location, ExternalExtensionProvider* test_provider); - // The name of the file that the current active version number is stored in. - static const char* kCurrentVersionFileName; - - // Hack: - // Extensions downloaded from kGalleryDownloadURLPrefix initiated from pages - // with kGalleryURLPrefix will not require --enable-extensions and will be - // prompt-free. - static const char* kGalleryDownloadURLPrefix; - static const char* kGalleryURLPrefix; - void SetExtensionsEnabled(bool enabled); bool extensions_enabled() { return extensions_enabled_; } |