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> | |
8 #include <cctype> | |
9 #include <iterator> | |
10 #include <set> | 7 #include <set> |
11 #include <string> | 8 #include <string> |
12 | 9 |
13 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
14 #include "base/bind.h" | 11 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
16 #include "base/callback.h" | 13 #include "base/callback.h" |
17 #include "base/file_util.h" | 14 #include "base/file_util.h" |
18 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
19 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
(...skipping 14 matching lines...) Expand all Loading... |
34 #include "chrome/browser/download/download_file_icon_extractor.h" | 31 #include "chrome/browser/download/download_file_icon_extractor.h" |
35 #include "chrome/browser/download/download_prefs.h" | 32 #include "chrome/browser/download/download_prefs.h" |
36 #include "chrome/browser/download/download_query.h" | 33 #include "chrome/browser/download/download_query.h" |
37 #include "chrome/browser/download/download_service.h" | 34 #include "chrome/browser/download/download_service.h" |
38 #include "chrome/browser/download/download_service_factory.h" | 35 #include "chrome/browser/download/download_service_factory.h" |
39 #include "chrome/browser/download/download_shelf.h" | 36 #include "chrome/browser/download/download_shelf.h" |
40 #include "chrome/browser/download/download_stats.h" | 37 #include "chrome/browser/download/download_stats.h" |
41 #include "chrome/browser/download/drag_download_item.h" | 38 #include "chrome/browser/download/drag_download_item.h" |
42 #include "chrome/browser/extensions/extension_service.h" | 39 #include "chrome/browser/extensions/extension_service.h" |
43 #include "chrome/browser/extensions/extension_warning_service.h" | 40 #include "chrome/browser/extensions/extension_warning_service.h" |
44 #include "chrome/browser/extensions/extension_warning_set.h" | |
45 #include "chrome/browser/icon_loader.h" | 41 #include "chrome/browser/icon_loader.h" |
46 #include "chrome/browser/icon_manager.h" | 42 #include "chrome/browser/icon_manager.h" |
47 #include "chrome/browser/platform_util.h" | 43 #include "chrome/browser/platform_util.h" |
48 #include "chrome/browser/profiles/profile.h" | 44 #include "chrome/browser/profiles/profile.h" |
49 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 45 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
50 #include "chrome/browser/ui/browser.h" | 46 #include "chrome/browser/ui/browser.h" |
51 #include "chrome/browser/ui/browser_list.h" | 47 #include "chrome/browser/ui/browser_list.h" |
52 #include "chrome/browser/ui/browser_window.h" | 48 #include "chrome/browser/ui/browser_window.h" |
53 #include "chrome/common/extensions/api/downloads.h" | 49 #include "chrome/common/extensions/api/downloads.h" |
54 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 50 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
55 #include "content/public/browser/download_interrupt_reasons.h" | 51 #include "content/public/browser/download_interrupt_reasons.h" |
56 #include "content/public/browser/download_item.h" | 52 #include "content/public/browser/download_item.h" |
57 #include "content/public/browser/download_save_info.h" | 53 #include "content/public/browser/download_save_info.h" |
58 #include "content/public/browser/download_url_parameters.h" | 54 #include "content/public/browser/download_url_parameters.h" |
59 #include "content/public/browser/notification_details.h" | 55 #include "content/public/browser/notification_details.h" |
60 #include "content/public/browser/notification_service.h" | 56 #include "content/public/browser/notification_service.h" |
61 #include "content/public/browser/notification_source.h" | 57 #include "content/public/browser/notification_source.h" |
62 #include "content/public/browser/render_process_host.h" | 58 #include "content/public/browser/render_process_host.h" |
63 #include "content/public/browser/render_view_host.h" | 59 #include "content/public/browser/render_view_host.h" |
64 #include "content/public/browser/render_widget_host_view.h" | 60 #include "content/public/browser/render_widget_host_view.h" |
65 #include "content/public/browser/resource_context.h" | 61 #include "content/public/browser/resource_context.h" |
66 #include "content/public/browser/resource_dispatcher_host.h" | 62 #include "content/public/browser/resource_dispatcher_host.h" |
67 #include "content/public/browser/web_contents.h" | 63 #include "content/public/browser/web_contents.h" |
68 #include "content/public/browser/web_contents_view.h" | 64 #include "content/public/browser/web_contents_view.h" |
69 #include "extensions/browser/event_router.h" | 65 #include "extensions/browser/event_router.h" |
70 #include "extensions/browser/extension_function_dispatcher.h" | 66 #include "extensions/browser/extension_function_dispatcher.h" |
71 #include "extensions/browser/extension_prefs.h" | 67 #include "extensions/browser/extension_registry.h" |
72 #include "extensions/browser/extension_system.h" | 68 #include "extensions/browser/extension_system.h" |
73 #include "extensions/common/extension.h" | |
74 #include "extensions/common/permissions/permissions_data.h" | |
75 #include "net/base/filename_util.h" | 69 #include "net/base/filename_util.h" |
76 #include "net/base/load_flags.h" | 70 #include "net/base/load_flags.h" |
77 #include "net/http/http_util.h" | 71 #include "net/http/http_util.h" |
78 #include "net/url_request/url_request.h" | |
79 #include "third_party/skia/include/core/SkBitmap.h" | 72 #include "third_party/skia/include/core/SkBitmap.h" |
80 #include "ui/base/webui/web_ui_util.h" | 73 #include "ui/base/webui/web_ui_util.h" |
81 #include "ui/gfx/image/image_skia.h" | 74 #include "ui/gfx/image/image_skia.h" |
82 | 75 |
83 using content::BrowserContext; | 76 using content::BrowserContext; |
84 using content::BrowserThread; | 77 using content::BrowserThread; |
85 using content::DownloadItem; | 78 using content::DownloadItem; |
86 using content::DownloadManager; | 79 using content::DownloadManager; |
87 | 80 |
88 namespace download_extension_errors { | 81 namespace download_extension_errors { |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 if (*query_in.limit.get() < 0) { | 494 if (*query_in.limit.get() < 0) { |
502 *error = errors::kInvalidQueryLimit; | 495 *error = errors::kInvalidQueryLimit; |
503 return; | 496 return; |
504 } | 497 } |
505 limit = *query_in.limit.get(); | 498 limit = *query_in.limit.get(); |
506 } | 499 } |
507 if (limit > 0) { | 500 if (limit > 0) { |
508 query_out.Limit(limit); | 501 query_out.Limit(limit); |
509 } | 502 } |
510 | 503 |
511 std::string state_string = | 504 std::string state_string = downloads::ToString(query_in.state); |
512 downloads::ToString(query_in.state); | |
513 if (!state_string.empty()) { | 505 if (!state_string.empty()) { |
514 DownloadItem::DownloadState state = StateEnumFromString(state_string); | 506 DownloadItem::DownloadState state = StateEnumFromString(state_string); |
515 if (state == DownloadItem::MAX_DOWNLOAD_STATE) { | 507 if (state == DownloadItem::MAX_DOWNLOAD_STATE) { |
516 *error = errors::kInvalidState; | 508 *error = errors::kInvalidState; |
517 return; | 509 return; |
518 } | 510 } |
519 query_out.AddFilter(state); | 511 query_out.AddFilter(state); |
520 } | 512 } |
521 std::string danger_string = | 513 std::string danger_string = |
522 downloads::ToString(query_in.danger); | 514 downloads::ToString(query_in.danger); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 } | 1507 } |
1516 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); | 1508 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); |
1517 SetResult(new base::StringValue(url)); | 1509 SetResult(new base::StringValue(url)); |
1518 SendResponse(true); | 1510 SendResponse(true); |
1519 } | 1511 } |
1520 | 1512 |
1521 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( | 1513 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( |
1522 Profile* profile, | 1514 Profile* profile, |
1523 DownloadManager* manager) | 1515 DownloadManager* manager) |
1524 : profile_(profile), | 1516 : profile_(profile), |
1525 notifier_(manager, this) { | 1517 notifier_(manager, this), |
| 1518 extension_registry_observer_(this) { |
1526 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1519 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1527 DCHECK(profile_); | 1520 DCHECK(profile_); |
1528 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 1521 extension_registry_observer_.Add( |
1529 content::Source<Profile>(profile_)); | 1522 extensions::ExtensionRegistry::Get(profile_)); |
1530 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); | 1523 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); |
1531 if (router) | 1524 if (router) |
1532 router->RegisterObserver(this, | 1525 router->RegisterObserver(this, |
1533 downloads::OnDeterminingFilename::kEventName); | 1526 downloads::OnDeterminingFilename::kEventName); |
1534 } | 1527 } |
1535 | 1528 |
1536 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { | 1529 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { |
1537 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1530 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1538 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); | 1531 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); |
1539 if (router) | 1532 if (router) |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 notification_source.event_name = event_name; | 1883 notification_source.event_name = event_name; |
1891 notification_source.profile = profile_; | 1884 notification_source.profile = profile_; |
1892 content::Source<DownloadsNotificationSource> content_source( | 1885 content::Source<DownloadsNotificationSource> content_source( |
1893 ¬ification_source); | 1886 ¬ification_source); |
1894 content::NotificationService::current()->Notify( | 1887 content::NotificationService::current()->Notify( |
1895 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, | 1888 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, |
1896 content_source, | 1889 content_source, |
1897 content::Details<std::string>(&json_args)); | 1890 content::Details<std::string>(&json_args)); |
1898 } | 1891 } |
1899 | 1892 |
1900 void ExtensionDownloadsEventRouter::Observe( | 1893 void ExtensionDownloadsEventRouter::OnExtensionUnloaded( |
1901 int type, | 1894 content::BrowserContext* browser_context, |
1902 const content::NotificationSource& source, | 1895 const extensions::Extension* extension, |
1903 const content::NotificationDetails& details) { | 1896 extensions::UnloadedExtensionInfo::Reason reason) { |
1904 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1897 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1905 switch (type) { | 1898 std::set<const extensions::Extension*>::iterator iter = |
1906 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 1899 shelf_disabling_extensions_.find(extension); |
1907 extensions::UnloadedExtensionInfo* unloaded = | 1900 if (iter != shelf_disabling_extensions_.end()) |
1908 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 1901 shelf_disabling_extensions_.erase(iter); |
1909 std::set<const extensions::Extension*>::iterator iter = | |
1910 shelf_disabling_extensions_.find(unloaded->extension); | |
1911 if (iter != shelf_disabling_extensions_.end()) | |
1912 shelf_disabling_extensions_.erase(iter); | |
1913 break; | |
1914 } | |
1915 } | |
1916 } | 1902 } |
OLD | NEW |