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

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

Issue 160243: Merge 21612 - Implement mimetype sniffing for extensions.... (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 | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/save_package.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
Merged /trunk/src/chrome/browser/download/download_manager.cc:r21612
Merged /branches/chrome_webkit_merge_branch/chrome/browser/download/download_manager.cc:r69-2775
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return (download_path == desktop_dir); 110 return (download_path == desktop_dir);
111 } 111 }
112 112
113 // DownloadItem implementation ------------------------------------------------- 113 // DownloadItem implementation -------------------------------------------------
114 114
115 // Constructor for reading from the history service. 115 // Constructor for reading from the history service.
116 DownloadItem::DownloadItem(const DownloadCreateInfo& info) 116 DownloadItem::DownloadItem(const DownloadCreateInfo& info)
117 : id_(-1), 117 : id_(-1),
118 full_path_(info.path), 118 full_path_(info.path),
119 url_(info.url), 119 url_(info.url),
120 referrer_url_(info.referrer_url),
121 mime_type_(info.mime_type),
120 total_bytes_(info.total_bytes), 122 total_bytes_(info.total_bytes),
121 received_bytes_(info.received_bytes), 123 received_bytes_(info.received_bytes),
122 start_tick_(base::TimeTicks()), 124 start_tick_(base::TimeTicks()),
123 state_(static_cast<DownloadState>(info.state)), 125 state_(static_cast<DownloadState>(info.state)),
124 start_time_(info.start_time), 126 start_time_(info.start_time),
125 db_handle_(info.db_handle), 127 db_handle_(info.db_handle),
126 manager_(NULL), 128 manager_(NULL),
127 is_paused_(false), 129 is_paused_(false),
128 open_when_complete_(false), 130 open_when_complete_(false),
129 safety_state_(SAFE), 131 safety_state_(SAFE),
130 auto_opened_(false), 132 auto_opened_(false),
131 original_name_(info.original_name), 133 original_name_(info.original_name),
132 render_process_id_(-1), 134 render_process_id_(-1),
133 request_id_(-1) { 135 request_id_(-1) {
134 if (state_ == IN_PROGRESS) 136 if (state_ == IN_PROGRESS)
135 state_ = CANCELLED; 137 state_ = CANCELLED;
136 Init(false /* don't start progress timer */); 138 Init(false /* don't start progress timer */);
137 } 139 }
138 140
139 // Constructor for DownloadItem created via user action in the main thread. 141 // Constructor for DownloadItem created via user action in the main thread.
140 DownloadItem::DownloadItem(int32 download_id, 142 DownloadItem::DownloadItem(int32 download_id,
141 const FilePath& path, 143 const FilePath& path,
142 int path_uniquifier, 144 int path_uniquifier,
143 const GURL& url, 145 const GURL& url,
146 const std::string& mime_type,
144 const FilePath& original_name, 147 const FilePath& original_name,
145 const base::Time start_time, 148 const base::Time start_time,
146 int64 download_size, 149 int64 download_size,
147 int render_process_id, 150 int render_process_id,
148 int request_id, 151 int request_id,
149 bool is_dangerous) 152 bool is_dangerous)
150 : id_(download_id), 153 : id_(download_id),
151 full_path_(path), 154 full_path_(path),
152 path_uniquifier_(path_uniquifier), 155 path_uniquifier_(path_uniquifier),
153 url_(url), 156 url_(url),
157 mime_type_(mime_type),
154 total_bytes_(download_size), 158 total_bytes_(download_size),
155 received_bytes_(0), 159 received_bytes_(0),
156 start_tick_(base::TimeTicks::Now()), 160 start_tick_(base::TimeTicks::Now()),
157 state_(IN_PROGRESS), 161 state_(IN_PROGRESS),
158 start_time_(start_time), 162 start_time_(start_time),
159 db_handle_(kUninitializedHandle), 163 db_handle_(kUninitializedHandle),
160 manager_(NULL), 164 manager_(NULL),
161 is_paused_(false), 165 is_paused_(false),
162 open_when_complete_(false), 166 open_when_complete_(false),
163 safety_state_(is_dangerous ? DANGEROUS : SAFE), 167 safety_state_(is_dangerous ? DANGEROUS : SAFE),
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 scoped_ptr<DownloadCreateInfo> infop(info); 671 scoped_ptr<DownloadCreateInfo> infop(info);
668 info->path = target_path; 672 info->path = target_path;
669 673
670 DownloadItem* download = NULL; 674 DownloadItem* download = NULL;
671 DownloadMap::iterator it = in_progress_.find(info->download_id); 675 DownloadMap::iterator it = in_progress_.find(info->download_id);
672 if (it == in_progress_.end()) { 676 if (it == in_progress_.end()) {
673 download = new DownloadItem(info->download_id, 677 download = new DownloadItem(info->download_id,
674 info->path, 678 info->path,
675 info->path_uniquifier, 679 info->path_uniquifier,
676 info->url, 680 info->url,
681 info->mime_type,
677 info->original_name, 682 info->original_name,
678 info->start_time, 683 info->start_time,
679 info->total_bytes, 684 info->total_bytes,
680 info->render_process_id, 685 info->render_process_id,
681 info->request_id, 686 info->request_id,
682 info->is_dangerous); 687 info->is_dangerous);
683 download->set_manager(this); 688 download->set_manager(this);
684 in_progress_[info->download_id] = download; 689 in_progress_[info->download_id] = download;
685 } else { 690 } else {
686 NOTREACHED(); // Should not exist! 691 NOTREACHED(); // Should not exist!
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 if (it != dangerous_finished_.end()) 836 if (it != dangerous_finished_.end())
832 dangerous_finished_.erase(it); 837 dangerous_finished_.erase(it);
833 838
834 // Open the download if the user or user prefs indicate it should be. 839 // Open the download if the user or user prefs indicate it should be.
835 FilePath::StringType extension = download->full_path().Extension(); 840 FilePath::StringType extension = download->full_path().Extension();
836 // Drop the leading period. (The auto-open list is period-less.) 841 // Drop the leading period. (The auto-open list is period-less.)
837 if (extension.size() > 0) 842 if (extension.size() > 0)
838 extension = extension.substr(1); 843 extension = extension.substr(1);
839 844
840 // Handle chrome extensions explicitly and skip the shell execute. 845 // Handle chrome extensions explicitly and skip the shell execute.
841 if (Extension::IsExtension(download->full_path())) { 846 if (download->mime_type() == Extension::kMimeType) {
842 OpenChromeExtension(download->full_path()); 847 OpenChromeExtension(download->full_path());
843 download->set_auto_opened(true); 848 download->set_auto_opened(true);
844 } else if (download->open_when_complete() || 849 } else if (download->open_when_complete() ||
845 ShouldOpenFileExtension(extension)) { 850 ShouldOpenFileExtension(extension)) {
846 OpenDownloadInShell(download, NULL); 851 OpenDownloadInShell(download, NULL);
847 download->set_auto_opened(true); 852 download->set_auto_opened(true);
848 } 853 }
849 854
850 // Notify our observers that we are complete (the call to Finished() set the 855 // Notify our observers that we are complete (the call to Finished() set the
851 // state to complete but did not notify). 856 // state to complete but did not notify).
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 file_loop_->PostTask(FROM_HERE, 1205 file_loop_->PostTask(FROM_HERE,
1201 NewRunnableMethod(file_manager_, 1206 NewRunnableMethod(file_manager_,
1202 &DownloadFileManager::OnShowDownloadInShell, 1207 &DownloadFileManager::OnShowDownloadInShell,
1203 FilePath(download->full_path()))); 1208 FilePath(download->full_path())));
1204 } 1209 }
1205 1210
1206 void DownloadManager::OpenDownload(const DownloadItem* download, 1211 void DownloadManager::OpenDownload(const DownloadItem* download,
1207 gfx::NativeView parent_window) { 1212 gfx::NativeView parent_window) {
1208 // Open Chrome extensions with ExtensionsService. For everything else do shell 1213 // Open Chrome extensions with ExtensionsService. For everything else do shell
1209 // execute. 1214 // execute.
1210 if (Extension::IsExtension(download->full_path())) { 1215 if (download->mime_type() == Extension::kMimeType) {
1211 OpenChromeExtension(download->full_path()); 1216 OpenChromeExtension(download->full_path());
1212 } else { 1217 } else {
1213 OpenDownloadInShell(download, parent_window); 1218 OpenDownloadInShell(download, parent_window);
1214 } 1219 }
1215 } 1220 }
1216 1221
1217 void DownloadManager::OpenChromeExtension(const FilePath& full_path) { 1222 void DownloadManager::OpenChromeExtension(const FilePath& full_path) {
1218 profile_->GetOriginalProfile()->GetExtensionsService()-> 1223 profile_->GetOriginalProfile()->GetExtensionsService()->
1219 InstallExtension(full_path); 1224 InstallExtension(full_path);
1220 } 1225 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 1485
1481 if (contents) 1486 if (contents)
1482 contents->OnStartDownload(download); 1487 contents->OnStartDownload(download);
1483 } 1488 }
1484 1489
1485 // Clears the last download path, used to initialize "save as" dialogs. 1490 // Clears the last download path, used to initialize "save as" dialogs.
1486 void DownloadManager::ClearLastDownloadPath() { 1491 void DownloadManager::ClearLastDownloadPath() {
1487 last_download_path_ = FilePath(); 1492 last_download_path_ = FilePath();
1488 } 1493 }
1489 1494
OLDNEW
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/save_package.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698