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/extensions/api/downloads/downloads_api.h" | 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cctype> | 8 #include <cctype> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <set> | 10 #include <set> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/stringprintf.h" | 25 #include "base/stringprintf.h" |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/download/download_file_icon_extractor.h" | 28 #include "chrome/browser/download/download_file_icon_extractor.h" |
29 #include "chrome/browser/download/download_query.h" | 29 #include "chrome/browser/download/download_query.h" |
30 #include "chrome/browser/download/download_service.h" | 30 #include "chrome/browser/download/download_service.h" |
31 #include "chrome/browser/download/download_service_factory.h" | 31 #include "chrome/browser/download/download_service_factory.h" |
32 #include "chrome/browser/download/download_util.h" | 32 #include "chrome/browser/download/download_util.h" |
33 #include "chrome/browser/extensions/event_names.h" | 33 #include "chrome/browser/extensions/event_names.h" |
34 #include "chrome/browser/extensions/event_router.h" | 34 #include "chrome/browser/extensions/event_router.h" |
| 35 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
35 #include "chrome/browser/extensions/extension_system.h" | 36 #include "chrome/browser/extensions/extension_system.h" |
36 #include "chrome/browser/icon_loader.h" | 37 #include "chrome/browser/icon_loader.h" |
37 #include "chrome/browser/icon_manager.h" | 38 #include "chrome/browser/icon_manager.h" |
38 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 39 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
39 #include "chrome/browser/ui/browser.h" | 40 #include "chrome/browser/ui/browser.h" |
40 #include "chrome/browser/ui/webui/web_ui_util.h" | 41 #include "chrome/browser/ui/webui/web_ui_util.h" |
41 #include "chrome/common/cancelable_task_tracker.h" | 42 #include "chrome/common/cancelable_task_tracker.h" |
42 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
43 #include "chrome/common/extensions/api/downloads.h" | 44 #include "chrome/common/extensions/api/downloads.h" |
44 #include "content/public/browser/download_interrupt_reasons.h" | 45 #include "content/public/browser/download_interrupt_reasons.h" |
45 #include "content/public/browser/download_item.h" | 46 #include "content/public/browser/download_item.h" |
46 #include "content/public/browser/download_save_info.h" | 47 #include "content/public/browser/download_save_info.h" |
47 #include "content/public/browser/download_url_parameters.h" | 48 #include "content/public/browser/download_url_parameters.h" |
48 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
49 #include "content/public/browser/render_process_host.h" | 50 #include "content/public/browser/render_process_host.h" |
50 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
51 #include "content/public/browser/resource_context.h" | 52 #include "content/public/browser/resource_context.h" |
52 #include "content/public/browser/resource_dispatcher_host.h" | 53 #include "content/public/browser/resource_dispatcher_host.h" |
| 54 #include "content/public/browser/web_contents.h" |
53 #include "net/base/load_flags.h" | 55 #include "net/base/load_flags.h" |
54 #include "net/http/http_util.h" | 56 #include "net/http/http_util.h" |
55 #include "net/url_request/url_request.h" | 57 #include "net/url_request/url_request.h" |
56 #include "third_party/skia/include/core/SkBitmap.h" | 58 #include "third_party/skia/include/core/SkBitmap.h" |
57 | 59 |
58 using content::BrowserContext; | 60 using content::BrowserContext; |
59 using content::BrowserThread; | 61 using content::BrowserThread; |
60 using content::DownloadId; | 62 using content::DownloadId; |
61 using content::DownloadItem; | 63 using content::DownloadItem; |
62 using content::DownloadManager; | 64 using content::DownloadManager; |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 return true; | 845 return true; |
844 } | 846 } |
845 | 847 |
846 DownloadsDragFunction::DownloadsDragFunction() {} | 848 DownloadsDragFunction::DownloadsDragFunction() {} |
847 DownloadsDragFunction::~DownloadsDragFunction() {} | 849 DownloadsDragFunction::~DownloadsDragFunction() {} |
848 | 850 |
849 bool DownloadsDragFunction::RunImpl() { | 851 bool DownloadsDragFunction::RunImpl() { |
850 scoped_ptr<extensions::api::downloads::Drag::Params> params( | 852 scoped_ptr<extensions::api::downloads::Drag::Params> params( |
851 extensions::api::downloads::Drag::Params::Create(*args_)); | 853 extensions::api::downloads::Drag::Params::Create(*args_)); |
852 EXTENSION_FUNCTION_VALIDATE(params.get()); | 854 EXTENSION_FUNCTION_VALIDATE(params.get()); |
853 error_ = download_extension_errors::kNotImplementedError; | 855 DownloadItem* download_item = GetDownload( |
854 if (error_.empty()) | 856 profile(), include_incognito(), params->download_id); |
855 RecordApiFunctions(DOWNLOADS_FUNCTION_DRAG); | 857 content::WebContents* web_contents = |
856 return error_.empty(); | 858 dispatcher()->delegate()->GetAssociatedWebContents(); |
| 859 if (!download_item || !web_contents) { |
| 860 error_ = download_extension_errors::kInvalidOperationError; |
| 861 return false; |
| 862 } |
| 863 RecordApiFunctions(DOWNLOADS_FUNCTION_DRAG); |
| 864 gfx::Image* icon = g_browser_process->icon_manager()->LookupIcon( |
| 865 download_item->GetUserVerifiedFilePath(), IconLoader::NORMAL); |
| 866 gfx::NativeView view = web_contents->GetNativeView(); |
| 867 { |
| 868 // Enable nested tasks during DnD, while |DragDownload()| blocks. |
| 869 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 870 download_util::DragDownload(download_item, icon, view); |
| 871 } |
| 872 return true; |
857 } | 873 } |
858 | 874 |
859 DownloadsGetFileIconFunction::DownloadsGetFileIconFunction() | 875 DownloadsGetFileIconFunction::DownloadsGetFileIconFunction() |
860 : icon_extractor_(new DownloadFileIconExtractorImpl()) { | 876 : icon_extractor_(new DownloadFileIconExtractorImpl()) { |
861 } | 877 } |
862 | 878 |
863 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} | 879 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} |
864 | 880 |
865 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( | 881 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( |
866 DownloadFileIconExtractor* extractor) { | 882 DownloadFileIconExtractor* extractor) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 if (profile_->HasOffTheRecordProfile() && | 1038 if (profile_->HasOffTheRecordProfile() && |
1023 !profile_->IsOffTheRecord()) { | 1039 !profile_->IsOffTheRecord()) { |
1024 DispatchEventInternal( | 1040 DispatchEventInternal( |
1025 profile_->GetOffTheRecordProfile(), | 1041 profile_->GetOffTheRecordProfile(), |
1026 event_name, | 1042 event_name, |
1027 json_args, | 1043 json_args, |
1028 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1044 scoped_ptr<base::ListValue>(args->DeepCopy())); |
1029 } | 1045 } |
1030 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1046 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
1031 } | 1047 } |
OLD | NEW |