summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-26 07:25:32 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-26 07:25:32 +0000
commit4a0380c8f0cd42cc52b15dfb19ae92a076fc99fd (patch)
tree3d5db3e8da921ead9e93f1903df8354e2e47902f /chrome
parent6ef635e4882c4f7af0e17bc525e5922d6d7f82f0 (diff)
downloadchromium_src-4a0380c8f0cd42cc52b15dfb19ae92a076fc99fd.zip
chromium_src-4a0380c8f0cd42cc52b15dfb19ae92a076fc99fd.tar.gz
chromium_src-4a0380c8f0cd42cc52b15dfb19ae92a076fc99fd.tar.bz2
Modify detection of Chrome extensions in download manager. It
turns out many servers send the no-sniff option, including the one we use for our sample extensions. So we can't rely on mime types to detect Chrome extensions, at least until we have some place to put our samples that doesn't have this problem. TBR=erikkay Review URL: http://codereview.chromium.org/159391 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/download/download_manager.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index ad8f16b..04cc6f5 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/platform_util.h"
@@ -110,6 +111,19 @@ static bool DownloadPathIsDangerous(const FilePath& download_path) {
return (download_path == desktop_dir);
}
+// Helper to determine if a download is a Chrome extension. We should be able to
+// just use the mime type, but even our own servers are not setup to serve the
+// right headers yet, so we have a short-term file extension heuristic, too.
+static bool IsChromeExtension(const FilePath& path,
+ const std::string& mime_type) {
+ // If the server says it is an extension, it is definitely an extension.
+ if (mime_type == Extension::kMimeType)
+ return true;
+
+ // Otherwise, it is an extension if it has the right, err, extension.
+ return path.Extension().substr(1) == chrome::kExtensionFileExtension;
+}
+
// DownloadItem implementation -------------------------------------------------
// Constructor for reading from the history service.
@@ -574,7 +588,7 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) {
// 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 &&
+ else if (IsChromeExtension(info->path, info->mime_type) &&
!ExtensionsService::IsDownloadFromGallery(info->url,
info->referrer_url)) {
info->is_dangerous = true;
@@ -854,7 +868,7 @@ void DownloadManager::ContinueDownloadFinished(DownloadItem* download) {
extension = extension.substr(1);
// Handle chrome extensions explicitly and skip the shell execute.
- if (download->mime_type() == Extension::kMimeType) {
+ if (IsChromeExtension(download->full_path(), download->mime_type())) {
OpenChromeExtension(download->full_path(), download->url(),
download->referrer_url());
download->set_auto_opened(true);
@@ -1224,7 +1238,7 @@ void DownloadManager::OpenDownload(const DownloadItem* download,
gfx::NativeView parent_window) {
// Open Chrome extensions with ExtensionsService. For everything else do shell
// execute.
- if (download->mime_type() == Extension::kMimeType) {
+ if (IsChromeExtension(download->full_path(), download->mime_type())) {
OpenChromeExtension(download->full_path(), download->url(),
download->referrer_url());
} else {