| 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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/download/download_crx_util.h" | 20 #include "chrome/browser/download/download_crx_util.h" |
| 21 #include "chrome/browser/download/download_danger_prompt.h" | 21 #include "chrome/browser/download/download_danger_prompt.h" |
| 22 #include "chrome/browser/download/download_history.h" | 22 #include "chrome/browser/download/download_history.h" |
| 23 #include "chrome/browser/download/download_prefs.h" | 23 #include "chrome/browser/download/download_prefs.h" |
| 24 #include "chrome/browser/download/download_service.h" | 24 #include "chrome/browser/download/download_service.h" |
| 25 #include "chrome/browser/download/download_service_factory.h" | 25 #include "chrome/browser/download/download_service_factory.h" |
| 26 #include "chrome/browser/download/download_util.h" | 26 #include "chrome/browser/download/download_util.h" |
| 27 #include "chrome/browser/platform_util.h" | 27 #include "chrome/browser/platform_util.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 31 #include "chrome/browser/ui/webui/fileicon_source.h" | 31 #include "chrome/browser/ui/webui/fileicon_source.h" |
| 32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "content/public/browser/download_item.h" | 33 #include "content/public/browser/download_item.h" |
| 34 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_ui.h" | 36 #include "content/public/browser/web_ui.h" |
| 37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 38 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
| 39 | 39 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 results_value.Append(download_util::CreateDownloadItemValue(*it, index)); | 357 results_value.Append(download_util::CreateDownloadItemValue(*it, index)); |
| 358 } | 358 } |
| 359 | 359 |
| 360 web_ui()->CallJavascriptFunction("downloadsList", results_value); | 360 web_ui()->CallJavascriptFunction("downloadsList", results_value); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void DownloadsDOMHandler::ShowDangerPrompt( | 363 void DownloadsDOMHandler::ShowDangerPrompt( |
| 364 content::DownloadItem* dangerous_item) { | 364 content::DownloadItem* dangerous_item) { |
| 365 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create( | 365 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create( |
| 366 dangerous_item, | 366 dangerous_item, |
| 367 TabContentsWrapper::GetCurrentWrapperForContents( | 367 TabContents::FromWebContents(web_ui()->GetWebContents()), |
| 368 web_ui()->GetWebContents()), | |
| 369 base::Bind(&DownloadsDOMHandler::DangerPromptAccepted, | 368 base::Bind(&DownloadsDOMHandler::DangerPromptAccepted, |
| 370 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId()), | 369 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId()), |
| 371 base::Closure()); | 370 base::Closure()); |
| 372 // danger_prompt will delete itself. | 371 // danger_prompt will delete itself. |
| 373 DCHECK(danger_prompt); | 372 DCHECK(danger_prompt); |
| 374 } | 373 } |
| 375 | 374 |
| 376 void DownloadsDOMHandler::DangerPromptAccepted(int download_id) { | 375 void DownloadsDOMHandler::DangerPromptAccepted(int download_id) { |
| 377 content::DownloadItem* item = download_manager_->GetActiveDownloadItem( | 376 content::DownloadItem* item = download_manager_->GetActiveDownloadItem( |
| 378 download_id); | 377 download_id); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 405 } | 404 } |
| 406 | 405 |
| 407 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( | 406 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( |
| 408 const ListValue* args) { | 407 const ListValue* args) { |
| 409 int id; | 408 int id; |
| 410 if (ExtractIntegerValue(args, &id)) { | 409 if (ExtractIntegerValue(args, &id)) { |
| 411 return GetDownloadById(id); | 410 return GetDownloadById(id); |
| 412 } | 411 } |
| 413 return NULL; | 412 return NULL; |
| 414 } | 413 } |
| OLD | NEW |