| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 file_value->SetString("file_name", file_name); | 181 file_value->SetString("file_name", file_name); |
| 182 file_value->SetString("url", download_item->GetURL().spec()); | 182 file_value->SetString("url", download_item->GetURL().spec()); |
| 183 file_value->SetBoolean("otr", incognito); | 183 file_value->SetBoolean("otr", incognito); |
| 184 file_value->SetInteger("total", static_cast<int>( | 184 file_value->SetInteger("total", static_cast<int>( |
| 185 download_item->GetTotalBytes())); | 185 download_item->GetTotalBytes())); |
| 186 file_value->SetBoolean("file_externally_removed", | 186 file_value->SetBoolean("file_externally_removed", |
| 187 download_item->GetFileExternallyRemoved()); | 187 download_item->GetFileExternallyRemoved()); |
| 188 file_value->SetBoolean("retry", false); // Overridden below if needed. | 188 file_value->SetBoolean("retry", false); // Overridden below if needed. |
| 189 file_value->SetBoolean("resume", download_item->CanResume()); | 189 file_value->SetBoolean("resume", download_item->CanResume()); |
| 190 | 190 |
| 191 const char* danger_type = ""; |
| 192 base::string16 last_reason_text; |
| 193 base::string16 progress_status_text; |
| 194 |
| 191 switch (download_item->GetState()) { | 195 switch (download_item->GetState()) { |
| 192 case content::DownloadItem::IN_PROGRESS: { | 196 case content::DownloadItem::IN_PROGRESS: { |
| 193 if (download_item->IsDangerous()) { | 197 if (download_item->IsDangerous()) { |
| 194 file_value->SetString("state", "DANGEROUS"); | 198 file_value->SetString("state", "DANGEROUS"); |
| 195 // These are the only danger states that the UI is equipped to handle. | 199 // These are the only danger states that the UI is equipped to handle. |
| 196 DCHECK(download_item->GetDangerType() == | 200 DCHECK(download_item->GetDangerType() == |
| 197 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || | 201 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || |
| 198 download_item->GetDangerType() == | 202 download_item->GetDangerType() == |
| 199 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || | 203 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || |
| 200 download_item->GetDangerType() == | 204 download_item->GetDangerType() == |
| 201 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || | 205 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || |
| 202 download_item->GetDangerType() == | 206 download_item->GetDangerType() == |
| 203 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || | 207 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || |
| 204 download_item->GetDangerType() == | 208 download_item->GetDangerType() == |
| 205 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || | 209 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || |
| 206 download_item->GetDangerType() == | 210 download_item->GetDangerType() == |
| 207 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED); | 211 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED); |
| 208 const char* danger_type_value = | 212 danger_type = GetDangerTypeString(download_item->GetDangerType()); |
| 209 GetDangerTypeString(download_item->GetDangerType()); | |
| 210 file_value->SetString("danger_type", danger_type_value); | |
| 211 } else if (download_item->IsPaused()) { | 213 } else if (download_item->IsPaused()) { |
| 212 file_value->SetString("state", "PAUSED"); | 214 file_value->SetString("state", "PAUSED"); |
| 213 } else { | 215 } else { |
| 214 file_value->SetString("state", "IN_PROGRESS"); | 216 file_value->SetString("state", "IN_PROGRESS"); |
| 215 } | 217 } |
| 216 file_value->SetString("progress_status_text", | 218 progress_status_text = download_model.GetTabProgressStatusText(); |
| 217 download_model.GetTabProgressStatusText()); | |
| 218 | 219 |
| 219 int percent = download_item->PercentComplete(); | 220 int percent = download_item->PercentComplete(); |
| 220 if (!MdDownloadsEnabled()) | 221 if (!MdDownloadsEnabled()) |
| 221 percent = std::max(0, percent); | 222 percent = std::max(0, percent); |
| 222 file_value->SetInteger("percent", percent); | 223 file_value->SetInteger("percent", percent); |
| 223 | 224 |
| 224 file_value->SetInteger("received", | 225 file_value->SetInteger("received", |
| 225 static_cast<int>(download_item->GetReceivedBytes())); | 226 static_cast<int>(download_item->GetReceivedBytes())); |
| 226 break; | 227 break; |
| 227 } | 228 } |
| 228 | 229 |
| 229 case content::DownloadItem::INTERRUPTED: | 230 case content::DownloadItem::INTERRUPTED: |
| 230 file_value->SetString("state", "INTERRUPTED"); | 231 file_value->SetString("state", "INTERRUPTED"); |
| 231 | 232 progress_status_text = download_model.GetTabProgressStatusText(); |
| 232 file_value->SetString("progress_status_text", | |
| 233 download_model.GetTabProgressStatusText()); | |
| 234 | 233 |
| 235 if (download_item->CanResume()) { | 234 if (download_item->CanResume()) { |
| 236 file_value->SetInteger("percent", | 235 file_value->SetInteger("percent", |
| 237 static_cast<int>(download_item->PercentComplete())); | 236 static_cast<int>(download_item->PercentComplete())); |
| 238 } | 237 } |
| 239 file_value->SetInteger("received", | 238 file_value->SetInteger("received", |
| 240 static_cast<int>(download_item->GetReceivedBytes())); | 239 static_cast<int>(download_item->GetReceivedBytes())); |
| 241 file_value->SetString("last_reason_text", | 240 last_reason_text = download_model.GetInterruptReasonText(); |
| 242 download_model.GetInterruptReasonText()); | |
| 243 if (content::DOWNLOAD_INTERRUPT_REASON_CRASH == | 241 if (content::DOWNLOAD_INTERRUPT_REASON_CRASH == |
| 244 download_item->GetLastReason() && !download_item->CanResume()) | 242 download_item->GetLastReason() && !download_item->CanResume()) |
| 245 file_value->SetBoolean("retry", true); | 243 file_value->SetBoolean("retry", true); |
| 246 break; | 244 break; |
| 247 | 245 |
| 248 case content::DownloadItem::CANCELLED: | 246 case content::DownloadItem::CANCELLED: |
| 249 file_value->SetString("state", "CANCELLED"); | 247 file_value->SetString("state", "CANCELLED"); |
| 250 file_value->SetBoolean("retry", true); | 248 file_value->SetBoolean("retry", true); |
| 251 break; | 249 break; |
| 252 | 250 |
| 253 case content::DownloadItem::COMPLETE: | 251 case content::DownloadItem::COMPLETE: |
| 254 DCHECK(!download_item->IsDangerous()); | 252 DCHECK(!download_item->IsDangerous()); |
| 255 file_value->SetString("state", "COMPLETE"); | 253 file_value->SetString("state", "COMPLETE"); |
| 256 break; | 254 break; |
| 257 | 255 |
| 258 case content::DownloadItem::MAX_DOWNLOAD_STATE: | 256 case content::DownloadItem::MAX_DOWNLOAD_STATE: |
| 259 NOTREACHED(); | 257 NOTREACHED(); |
| 260 } | 258 } |
| 261 | 259 |
| 260 file_value->SetString("danger_type", danger_type); |
| 261 file_value->SetString("last_reason_text", last_reason_text); |
| 262 file_value->SetString("progress_status_text", progress_status_text); |
| 263 |
| 262 return file_value; | 264 return file_value; |
| 263 } | 265 } |
| 264 | 266 |
| 265 // Filters out extension downloads and downloads that don't have a filename yet. | 267 // Filters out extension downloads and downloads that don't have a filename yet. |
| 266 bool IsDownloadDisplayable(const content::DownloadItem& item) { | 268 bool IsDownloadDisplayable(const content::DownloadItem& item) { |
| 267 return !download_crx_util::IsExtensionDownload(item) && | 269 return !download_crx_util::IsExtensionDownload(item) && |
| 268 !item.IsTemporary() && | 270 !item.IsTemporary() && |
| 269 !item.GetFileNameToReportUser().empty() && | 271 !item.GetFileNameToReportUser().empty() && |
| 270 !item.GetTargetFilePath().empty() && | 272 !item.GetTargetFilePath().empty() && |
| 271 DownloadItemModel( | 273 DownloadItemModel( |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 return web_ui()->GetWebContents(); | 719 return web_ui()->GetWebContents(); |
| 718 } | 720 } |
| 719 | 721 |
| 720 void DownloadsDOMHandler::CallUpdateAll(const base::ListValue& list) { | 722 void DownloadsDOMHandler::CallUpdateAll(const base::ListValue& list) { |
| 721 web_ui()->CallJavascriptFunction("downloads.Manager.updateAll", list); | 723 web_ui()->CallJavascriptFunction("downloads.Manager.updateAll", list); |
| 722 } | 724 } |
| 723 | 725 |
| 724 void DownloadsDOMHandler::CallUpdateItem(const base::DictionaryValue& item) { | 726 void DownloadsDOMHandler::CallUpdateItem(const base::DictionaryValue& item) { |
| 725 web_ui()->CallJavascriptFunction("downloads.Manager.updateItem", item); | 727 web_ui()->CallJavascriptFunction("downloads.Manager.updateItem", item); |
| 726 } | 728 } |
| OLD | NEW |