Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/download/download_manager.cc

Issue 165476: Merge 23118 - Remove the temporary hack that considered any file that ended... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/chrome/browser/download/download_manager.cc:r23118
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "chrome/browser/download/download_manager.h" 5 #include "chrome/browser/download/download_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 static bool DownloadPathIsDangerous(const FilePath& download_path) { 106 static bool DownloadPathIsDangerous(const FilePath& download_path) {
107 FilePath desktop_dir; 107 FilePath desktop_dir;
108 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { 108 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) {
109 NOTREACHED(); 109 NOTREACHED();
110 return false; 110 return false;
111 } 111 }
112 return (download_path == desktop_dir); 112 return (download_path == desktop_dir);
113 } 113 }
114 114
115 // Helper to determine if a download is a Chrome extension. We should be able to
116 // just use the mime type, but even our own servers are not setup to serve the
117 // right headers yet, so we have a short-term file extension heuristic, too.
118 static bool IsChromeExtension(const FilePath& path,
119 const std::string& mime_type) {
120 // If the server says it is an extension, it is definitely an extension.
121 if (mime_type == Extension::kMimeType)
122 return true;
123
124 // Otherwise, it is an extension if it has the right, err, extension.
125 return path.Extension().size() > 1 &&
126 path.Extension().substr(1) == chrome::kExtensionFileExtension;
127 }
128
129 // DownloadItem implementation ------------------------------------------------- 115 // DownloadItem implementation -------------------------------------------------
130 116
131 // Constructor for reading from the history service. 117 // Constructor for reading from the history service.
132 DownloadItem::DownloadItem(const DownloadCreateInfo& info) 118 DownloadItem::DownloadItem(const DownloadCreateInfo& info)
133 : id_(-1), 119 : id_(-1),
134 full_path_(info.path), 120 full_path_(info.path),
135 url_(info.url), 121 url_(info.url),
136 referrer_url_(info.referrer_url), 122 referrer_url_(info.referrer_url),
137 mime_type_(info.mime_type), 123 mime_type_(info.mime_type),
138 total_bytes_(info.total_bytes), 124 total_bytes_(info.total_bytes),
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 else 569 else
584 info->suggested_path = download_path(); 570 info->suggested_path = download_path();
585 info->suggested_path = info->suggested_path.Append(generated_name); 571 info->suggested_path = info->suggested_path.Append(generated_name);
586 572
587 if (!info->save_as) { 573 if (!info->save_as) {
588 // Downloads can be marked as dangerous for two reasons: 574 // Downloads can be marked as dangerous for two reasons:
589 // a) They have a dangerous-looking filename 575 // a) They have a dangerous-looking filename
590 // b) They are an extension that is not from the gallery 576 // b) They are an extension that is not from the gallery
591 if (IsDangerous(info->suggested_path.BaseName())) 577 if (IsDangerous(info->suggested_path.BaseName()))
592 info->is_dangerous = true; 578 info->is_dangerous = true;
593 else if (IsChromeExtension(info->path, info->mime_type) && 579 else if (info->mime_type == Extension::kMimeType &&
594 !ExtensionsService::IsDownloadFromGallery(info->url, 580 !ExtensionsService::IsDownloadFromGallery(info->url,
595 info->referrer_url)) { 581 info->referrer_url)) {
596 info->is_dangerous = true; 582 info->is_dangerous = true;
597 } 583 }
598 } 584 }
599 585
600 // We need to move over to the download thread because we don't want to stat 586 // We need to move over to the download thread because we don't want to stat
601 // the suggested path on the UI thread. 587 // the suggested path on the UI thread.
602 file_loop_->PostTask(FROM_HERE, 588 file_loop_->PostTask(FROM_HERE,
603 NewRunnableMethod(this, 589 NewRunnableMethod(this,
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 if (it != dangerous_finished_.end()) 849 if (it != dangerous_finished_.end())
864 dangerous_finished_.erase(it); 850 dangerous_finished_.erase(it);
865 851
866 // Open the download if the user or user prefs indicate it should be. 852 // Open the download if the user or user prefs indicate it should be.
867 FilePath::StringType extension = download->full_path().Extension(); 853 FilePath::StringType extension = download->full_path().Extension();
868 // Drop the leading period. (The auto-open list is period-less.) 854 // Drop the leading period. (The auto-open list is period-less.)
869 if (extension.size() > 0) 855 if (extension.size() > 0)
870 extension = extension.substr(1); 856 extension = extension.substr(1);
871 857
872 // Handle chrome extensions explicitly and skip the shell execute. 858 // Handle chrome extensions explicitly and skip the shell execute.
873 if (IsChromeExtension(download->full_path(), download->mime_type())) { 859 if (download->mime_type() == Extension::kMimeType) {
874 OpenChromeExtension(download->full_path(), download->url(), 860 OpenChromeExtension(download->full_path(), download->url(),
875 download->referrer_url()); 861 download->referrer_url());
876 download->set_auto_opened(true); 862 download->set_auto_opened(true);
877 } else if (download->open_when_complete() || 863 } else if (download->open_when_complete() ||
878 ShouldOpenFileExtension(extension)) { 864 ShouldOpenFileExtension(extension)) {
879 OpenDownloadInShell(download, NULL); 865 OpenDownloadInShell(download, NULL);
880 download->set_auto_opened(true); 866 download->set_auto_opened(true);
881 } 867 }
882 868
883 // Notify our observers that we are complete (the call to Finished() set the 869 // Notify our observers that we are complete (the call to Finished() set the
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 file_loop_->PostTask(FROM_HERE, 1219 file_loop_->PostTask(FROM_HERE,
1234 NewRunnableMethod(file_manager_, 1220 NewRunnableMethod(file_manager_,
1235 &DownloadFileManager::OnShowDownloadInShell, 1221 &DownloadFileManager::OnShowDownloadInShell,
1236 FilePath(download->full_path()))); 1222 FilePath(download->full_path())));
1237 } 1223 }
1238 1224
1239 void DownloadManager::OpenDownload(const DownloadItem* download, 1225 void DownloadManager::OpenDownload(const DownloadItem* download,
1240 gfx::NativeView parent_window) { 1226 gfx::NativeView parent_window) {
1241 // Open Chrome extensions with ExtensionsService. For everything else do shell 1227 // Open Chrome extensions with ExtensionsService. For everything else do shell
1242 // execute. 1228 // execute.
1243 if (IsChromeExtension(download->full_path(), download->mime_type())) { 1229 if (download->mime_type() == Extension::kMimeType) {
1244 OpenChromeExtension(download->full_path(), download->url(), 1230 OpenChromeExtension(download->full_path(), download->url(),
1245 download->referrer_url()); 1231 download->referrer_url());
1246 } else { 1232 } else {
1247 OpenDownloadInShell(download, parent_window); 1233 OpenDownloadInShell(download, parent_window);
1248 } 1234 }
1249 } 1235 }
1250 1236
1251 void DownloadManager::OpenChromeExtension(const FilePath& full_path, 1237 void DownloadManager::OpenChromeExtension(const FilePath& full_path,
1252 const GURL& download_url, 1238 const GURL& download_url,
1253 const GURL& referrer_url) { 1239 const GURL& referrer_url) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 1512
1527 if (contents) 1513 if (contents)
1528 contents->OnStartDownload(download); 1514 contents->OnStartDownload(download);
1529 } 1515 }
1530 1516
1531 // Clears the last download path, used to initialize "save as" dialogs. 1517 // Clears the last download path, used to initialize "save as" dialogs.
1532 void DownloadManager::ClearLastDownloadPath() { 1518 void DownloadManager::ClearLastDownloadPath() {
1533 last_download_path_ = FilePath(); 1519 last_download_path_ = FilePath();
1534 } 1520 }
1535 1521
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698