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

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

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