| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 DOWNLOADS_DOM_EVENT_OPEN_FILE = 1, | 66 DOWNLOADS_DOM_EVENT_OPEN_FILE = 1, |
| 67 DOWNLOADS_DOM_EVENT_DRAG = 2, | 67 DOWNLOADS_DOM_EVENT_DRAG = 2, |
| 68 DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS = 3, | 68 DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS = 3, |
| 69 DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS = 4, | 69 DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS = 4, |
| 70 DOWNLOADS_DOM_EVENT_SHOW = 5, | 70 DOWNLOADS_DOM_EVENT_SHOW = 5, |
| 71 DOWNLOADS_DOM_EVENT_PAUSE = 6, | 71 DOWNLOADS_DOM_EVENT_PAUSE = 6, |
| 72 DOWNLOADS_DOM_EVENT_REMOVE = 7, | 72 DOWNLOADS_DOM_EVENT_REMOVE = 7, |
| 73 DOWNLOADS_DOM_EVENT_CANCEL = 8, | 73 DOWNLOADS_DOM_EVENT_CANCEL = 8, |
| 74 DOWNLOADS_DOM_EVENT_CLEAR_ALL = 9, | 74 DOWNLOADS_DOM_EVENT_CLEAR_ALL = 9, |
| 75 DOWNLOADS_DOM_EVENT_OPEN_FOLDER = 10, | 75 DOWNLOADS_DOM_EVENT_OPEN_FOLDER = 10, |
| 76 DOWNLOADS_DOM_EVENT_RESUME = 11, |
| 76 DOWNLOADS_DOM_EVENT_MAX | 77 DOWNLOADS_DOM_EVENT_MAX |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 void CountDownloadsDOMEvents(DownloadsDOMEvent event) { | 80 void CountDownloadsDOMEvents(DownloadsDOMEvent event) { |
| 80 UMA_HISTOGRAM_ENUMERATION("Download.DOMEvent", | 81 UMA_HISTOGRAM_ENUMERATION("Download.DOMEvent", |
| 81 event, | 82 event, |
| 82 DOWNLOADS_DOM_EVENT_MAX); | 83 DOWNLOADS_DOM_EVENT_MAX); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Returns a string constant to be used as the |danger_type| value in | 86 // Returns a string constant to be used as the |danger_type| value in |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 weak_ptr_factory_.GetWeakPtr())); | 247 weak_ptr_factory_.GetWeakPtr())); |
| 247 web_ui()->RegisterMessageCallback("saveDangerous", | 248 web_ui()->RegisterMessageCallback("saveDangerous", |
| 248 base::Bind(&DownloadsDOMHandler::HandleSaveDangerous, | 249 base::Bind(&DownloadsDOMHandler::HandleSaveDangerous, |
| 249 weak_ptr_factory_.GetWeakPtr())); | 250 weak_ptr_factory_.GetWeakPtr())); |
| 250 web_ui()->RegisterMessageCallback("discardDangerous", | 251 web_ui()->RegisterMessageCallback("discardDangerous", |
| 251 base::Bind(&DownloadsDOMHandler::HandleDiscardDangerous, | 252 base::Bind(&DownloadsDOMHandler::HandleDiscardDangerous, |
| 252 weak_ptr_factory_.GetWeakPtr())); | 253 weak_ptr_factory_.GetWeakPtr())); |
| 253 web_ui()->RegisterMessageCallback("show", | 254 web_ui()->RegisterMessageCallback("show", |
| 254 base::Bind(&DownloadsDOMHandler::HandleShow, | 255 base::Bind(&DownloadsDOMHandler::HandleShow, |
| 255 weak_ptr_factory_.GetWeakPtr())); | 256 weak_ptr_factory_.GetWeakPtr())); |
| 256 web_ui()->RegisterMessageCallback("togglepause", | 257 web_ui()->RegisterMessageCallback("pause", |
| 257 base::Bind(&DownloadsDOMHandler::HandlePause, | 258 base::Bind(&DownloadsDOMHandler::HandlePause, |
| 258 weak_ptr_factory_.GetWeakPtr())); | 259 weak_ptr_factory_.GetWeakPtr())); |
| 259 web_ui()->RegisterMessageCallback("resume", | 260 web_ui()->RegisterMessageCallback("resume", |
| 260 base::Bind(&DownloadsDOMHandler::HandlePause, | 261 base::Bind(&DownloadsDOMHandler::HandleResume, |
| 261 weak_ptr_factory_.GetWeakPtr())); | 262 weak_ptr_factory_.GetWeakPtr())); |
| 262 web_ui()->RegisterMessageCallback("remove", | 263 web_ui()->RegisterMessageCallback("remove", |
| 263 base::Bind(&DownloadsDOMHandler::HandleRemove, | 264 base::Bind(&DownloadsDOMHandler::HandleRemove, |
| 264 weak_ptr_factory_.GetWeakPtr())); | 265 weak_ptr_factory_.GetWeakPtr())); |
| 265 web_ui()->RegisterMessageCallback("cancel", | 266 web_ui()->RegisterMessageCallback("cancel", |
| 266 base::Bind(&DownloadsDOMHandler::HandleCancel, | 267 base::Bind(&DownloadsDOMHandler::HandleCancel, |
| 267 weak_ptr_factory_.GetWeakPtr())); | 268 weak_ptr_factory_.GetWeakPtr())); |
| 268 web_ui()->RegisterMessageCallback("clearAll", | 269 web_ui()->RegisterMessageCallback("clearAll", |
| 269 base::Bind(&DownloadsDOMHandler::HandleClearAll, | 270 base::Bind(&DownloadsDOMHandler::HandleClearAll, |
| 270 weak_ptr_factory_.GetWeakPtr())); | 271 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SHOW); | 371 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SHOW); |
| 371 content::DownloadItem* file = GetDownloadByValue(args); | 372 content::DownloadItem* file = GetDownloadByValue(args); |
| 372 if (file) | 373 if (file) |
| 373 file->ShowDownloadInShell(); | 374 file->ShowDownloadInShell(); |
| 374 } | 375 } |
| 375 | 376 |
| 376 void DownloadsDOMHandler::HandlePause(const base::ListValue* args) { | 377 void DownloadsDOMHandler::HandlePause(const base::ListValue* args) { |
| 377 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); | 378 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); |
| 378 content::DownloadItem* file = GetDownloadByValue(args); | 379 content::DownloadItem* file = GetDownloadByValue(args); |
| 379 if (file) | 380 if (file) |
| 380 file->TogglePause(); | 381 file->Pause(); |
| 382 } |
| 383 |
| 384 void DownloadsDOMHandler::HandleResume(const base::ListValue* args) { |
| 385 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_RESUME); |
| 386 content::DownloadItem* file = GetDownloadByValue(args); |
| 387 if (file) |
| 388 file->Resume(); |
| 381 } | 389 } |
| 382 | 390 |
| 383 void DownloadsDOMHandler::HandleRemove(const base::ListValue* args) { | 391 void DownloadsDOMHandler::HandleRemove(const base::ListValue* args) { |
| 384 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); | 392 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); |
| 385 content::DownloadItem* file = GetDownloadByValue(args); | 393 content::DownloadItem* file = GetDownloadByValue(args); |
| 386 if (file) | 394 if (file) |
| 387 file->Remove(); | 395 file->Remove(); |
| 388 } | 396 } |
| 389 | 397 |
| 390 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) { | 398 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 513 } |
| 506 | 514 |
| 507 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { | 515 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { |
| 508 web_ui()->CallJavascriptFunction("downloadsList", downloads); | 516 web_ui()->CallJavascriptFunction("downloadsList", downloads); |
| 509 } | 517 } |
| 510 | 518 |
| 511 void DownloadsDOMHandler::CallDownloadUpdated( | 519 void DownloadsDOMHandler::CallDownloadUpdated( |
| 512 const base::ListValue& download_item) { | 520 const base::ListValue& download_item) { |
| 513 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); | 521 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); |
| 514 } | 522 } |
| OLD | NEW |