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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { | 349 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { |
350 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); | 350 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); |
351 content::DownloadItem* file = GetDownloadByValue(args); | 351 content::DownloadItem* file = GetDownloadByValue(args); |
352 if (file) | 352 if (file) |
353 file->OpenDownload(); | 353 file->OpenDownload(); |
354 } | 354 } |
355 | 355 |
356 void DownloadsDOMHandler::HandleDrag(const base::ListValue* args) { | 356 void DownloadsDOMHandler::HandleDrag(const base::ListValue* args) { |
357 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_DRAG); | 357 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_DRAG); |
358 content::DownloadItem* file = GetDownloadByValue(args); | 358 content::DownloadItem* file = GetDownloadByValue(args); |
| 359 if (!file) |
| 360 return; |
| 361 |
359 content::WebContents* web_contents = GetWebUIWebContents(); | 362 content::WebContents* web_contents = GetWebUIWebContents(); |
360 // |web_contents| is only NULL in the test. | 363 // |web_contents| is only NULL in the test. |
361 if (!file || !web_contents || !file->IsComplete()) | 364 if (!web_contents) |
362 return; | 365 return; |
| 366 |
| 367 if (file->GetState() != content::DownloadItem::COMPLETE) |
| 368 return; |
| 369 |
363 gfx::Image* icon = g_browser_process->icon_manager()->LookupIconFromFilepath( | 370 gfx::Image* icon = g_browser_process->icon_manager()->LookupIconFromFilepath( |
364 file->GetTargetFilePath(), IconLoader::NORMAL); | 371 file->GetTargetFilePath(), IconLoader::NORMAL); |
365 gfx::NativeView view = web_contents->GetView()->GetNativeView(); | 372 gfx::NativeView view = web_contents->GetView()->GetNativeView(); |
366 { | 373 { |
367 // Enable nested tasks during DnD, while |DragDownload()| blocks. | 374 // Enable nested tasks during DnD, while |DragDownload()| blocks. |
368 base::MessageLoop::ScopedNestableTaskAllower allow( | 375 base::MessageLoop::ScopedNestableTaskAllower allow( |
369 base::MessageLoop::current()); | 376 base::MessageLoop::current()); |
370 download_util::DragDownload(file, icon, view); | 377 download_util::DragDownload(file, icon, view); |
371 } | 378 } |
372 } | 379 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 } | 558 } |
552 | 559 |
553 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { | 560 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { |
554 web_ui()->CallJavascriptFunction("downloadsList", downloads); | 561 web_ui()->CallJavascriptFunction("downloadsList", downloads); |
555 } | 562 } |
556 | 563 |
557 void DownloadsDOMHandler::CallDownloadUpdated( | 564 void DownloadsDOMHandler::CallDownloadUpdated( |
558 const base::ListValue& download_item) { | 565 const base::ListValue& download_item) { |
559 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); | 566 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); |
560 } | 567 } |
OLD | NEW |