OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/downloads_dom_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 } | 112 } |
113 | 113 |
114 // A download has started or been deleted. Query our DownloadManager for the | 114 // A download has started or been deleted. Query our DownloadManager for the |
115 // current set of downloads. | 115 // current set of downloads. |
116 void DownloadsDOMHandler::ModelChanged() { | 116 void DownloadsDOMHandler::ModelChanged() { |
117 ClearDownloadItems(); | 117 ClearDownloadItems(); |
118 download_manager_->SearchDownloads(WideToUTF16(search_text_), | 118 download_manager_->SearchDownloads(WideToUTF16(search_text_), |
119 &download_items_); | 119 &download_items_); |
120 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); | 120 sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); |
121 | 121 |
122 // Scan for any in progress downloads and add ourself to them as an observer. | 122 // Add oneself to all download items as an observer. |
123 for (OrderedDownloads::iterator it = download_items_.begin(); | 123 for (OrderedDownloads::iterator it = download_items_.begin(); |
124 it != download_items_.end(); ++it) { | 124 it != download_items_.end(); ++it) { |
125 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) | 125 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) |
126 break; | 126 break; |
127 | 127 (*it)->AddObserver(this); |
128 DownloadItem* download = *it; | |
129 if (download->IsInProgress()) { | |
130 // We want to know what happens as the download progresses. | |
131 download->AddObserver(this); | |
132 } else if (download->safety_state() == DownloadItem::DANGEROUS) { | |
133 // We need to be notified when the user validates the dangerous download. | |
134 download->AddObserver(this); | |
135 } | |
136 } | 128 } |
137 | 129 |
138 SendCurrentDownloads(); | 130 SendCurrentDownloads(); |
139 } | 131 } |
140 | 132 |
141 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { | 133 void DownloadsDOMHandler::HandleGetDownloads(const ListValue* args) { |
142 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); | 134 std::wstring new_search = UTF16ToWideHack(ExtractStringValue(args)); |
143 if (search_text_.compare(new_search) != 0) { | 135 if (search_text_.compare(new_search) != 0) { |
144 search_text_ = new_search; | 136 search_text_ = new_search; |
145 ModelChanged(); | 137 ModelChanged(); |
146 } else { | 138 } else { |
147 SendCurrentDownloads(); | 139 SendCurrentDownloads(); |
148 } | 140 } |
141 | |
142 download_manager_->CheckForFilesRemoval(); | |
Randy Smith (Not in Mondays)
2011/05/13 20:45:32
And I'd also nuke these, as well. I think doing t
haraken1
2011/05/16 11:42:27
I removed it.
| |
149 } | 143 } |
150 | 144 |
151 void DownloadsDOMHandler::HandleOpenFile(const ListValue* args) { | 145 void DownloadsDOMHandler::HandleOpenFile(const ListValue* args) { |
152 DownloadItem* file = GetDownloadByValue(args); | 146 DownloadItem* file = GetDownloadByValue(args); |
153 if (file) | 147 if (file) |
154 file->OpenDownload(); | 148 file->OpenDownload(); |
149 | |
150 download_manager_->CheckForFilesRemoval(); | |
155 } | 151 } |
156 | 152 |
157 void DownloadsDOMHandler::HandleDrag(const ListValue* args) { | 153 void DownloadsDOMHandler::HandleDrag(const ListValue* args) { |
158 DownloadItem* file = GetDownloadByValue(args); | 154 DownloadItem* file = GetDownloadByValue(args); |
159 if (file) { | 155 if (file) { |
160 IconManager* im = g_browser_process->icon_manager(); | 156 IconManager* im = g_browser_process->icon_manager(); |
161 gfx::Image* icon = im->LookupIcon(file->GetUserVerifiedFilePath(), | 157 gfx::Image* icon = im->LookupIcon(file->GetUserVerifiedFilePath(), |
162 IconLoader::NORMAL); | 158 IconLoader::NORMAL); |
163 gfx::NativeView view = web_ui_->tab_contents()->GetNativeView(); | 159 gfx::NativeView view = web_ui_->tab_contents()->GetNativeView(); |
164 download_util::DragDownload(file, icon, view); | 160 download_util::DragDownload(file, icon, view); |
165 } | 161 } |
162 | |
163 download_manager_->CheckForFilesRemoval(); | |
166 } | 164 } |
167 | 165 |
168 void DownloadsDOMHandler::HandleSaveDangerous(const ListValue* args) { | 166 void DownloadsDOMHandler::HandleSaveDangerous(const ListValue* args) { |
169 DownloadItem* file = GetDownloadByValue(args); | 167 DownloadItem* file = GetDownloadByValue(args); |
170 if (file) | 168 if (file) |
171 download_manager_->DangerousDownloadValidated(file); | 169 download_manager_->DangerousDownloadValidated(file); |
170 | |
171 download_manager_->CheckForFilesRemoval(); | |
172 } | 172 } |
173 | 173 |
174 void DownloadsDOMHandler::HandleDiscardDangerous(const ListValue* args) { | 174 void DownloadsDOMHandler::HandleDiscardDangerous(const ListValue* args) { |
175 DownloadItem* file = GetDownloadByValue(args); | 175 DownloadItem* file = GetDownloadByValue(args); |
176 if (file) | 176 if (file) |
177 file->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 177 file->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
178 | |
179 download_manager_->CheckForFilesRemoval(); | |
178 } | 180 } |
179 | 181 |
180 void DownloadsDOMHandler::HandleShow(const ListValue* args) { | 182 void DownloadsDOMHandler::HandleShow(const ListValue* args) { |
181 DownloadItem* file = GetDownloadByValue(args); | 183 DownloadItem* file = GetDownloadByValue(args); |
182 if (file) | 184 if (file) |
183 file->ShowDownloadInShell(); | 185 file->ShowDownloadInShell(); |
186 | |
187 download_manager_->CheckForFilesRemoval(); | |
184 } | 188 } |
185 | 189 |
186 void DownloadsDOMHandler::HandlePause(const ListValue* args) { | 190 void DownloadsDOMHandler::HandlePause(const ListValue* args) { |
187 DownloadItem* file = GetDownloadByValue(args); | 191 DownloadItem* file = GetDownloadByValue(args); |
188 if (file) | 192 if (file) |
189 file->TogglePause(); | 193 file->TogglePause(); |
194 | |
195 download_manager_->CheckForFilesRemoval(); | |
190 } | 196 } |
191 | 197 |
192 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { | 198 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { |
193 DownloadItem* file = GetDownloadByValue(args); | 199 DownloadItem* file = GetDownloadByValue(args); |
194 if (file) | 200 if (file) |
195 file->Remove(); | 201 file->Remove(); |
202 | |
203 download_manager_->CheckForFilesRemoval(); | |
196 } | 204 } |
197 | 205 |
198 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { | 206 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { |
199 DownloadItem* file = GetDownloadByValue(args); | 207 DownloadItem* file = GetDownloadByValue(args); |
200 if (file) | 208 if (file) |
201 file->Cancel(true); | 209 file->Cancel(true); |
210 | |
211 download_manager_->CheckForFilesRemoval(); | |
202 } | 212 } |
203 | 213 |
204 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { | 214 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { |
205 download_manager_->RemoveAllDownloads(); | 215 download_manager_->RemoveAllDownloads(); |
216 | |
217 download_manager_->CheckForFilesRemoval(); | |
206 } | 218 } |
207 | 219 |
208 // DownloadsDOMHandler, private: ---------------------------------------------- | 220 // DownloadsDOMHandler, private: ---------------------------------------------- |
209 | 221 |
210 void DownloadsDOMHandler::SendCurrentDownloads() { | 222 void DownloadsDOMHandler::SendCurrentDownloads() { |
211 ListValue results_value; | 223 ListValue results_value; |
212 for (OrderedDownloads::iterator it = download_items_.begin(); | 224 for (OrderedDownloads::iterator it = download_items_.begin(); |
213 it != download_items_.end(); ++it) { | 225 it != download_items_.end(); ++it) { |
214 int index = static_cast<int>(it - download_items_.begin()); | 226 int index = static_cast<int>(it - download_items_.begin()); |
215 if (index > kMaxDownloads) | 227 if (index > kMaxDownloads) |
(...skipping 24 matching lines...) Expand all Loading... | |
240 return NULL; | 252 return NULL; |
241 } | 253 } |
242 | 254 |
243 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { | 255 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { |
244 int id; | 256 int id; |
245 if (ExtractIntegerValue(args, &id)) { | 257 if (ExtractIntegerValue(args, &id)) { |
246 return GetDownloadById(id); | 258 return GetDownloadById(id); |
247 } | 259 } |
248 return NULL; | 260 return NULL; |
249 } | 261 } |
OLD | NEW |