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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
30 #include "chrome/browser/download/download_danger_prompt.h" | 30 #include "chrome/browser/download/download_danger_prompt.h" |
31 #include "chrome/browser/download/download_file_icon_extractor.h" | 31 #include "chrome/browser/download/download_file_icon_extractor.h" |
32 #include "chrome/browser/download/download_prefs.h" | 32 #include "chrome/browser/download/download_prefs.h" |
33 #include "chrome/browser/download/download_query.h" | 33 #include "chrome/browser/download/download_query.h" |
34 #include "chrome/browser/download/download_service.h" | 34 #include "chrome/browser/download/download_service.h" |
35 #include "chrome/browser/download/download_service_factory.h" | 35 #include "chrome/browser/download/download_service_factory.h" |
36 #include "chrome/browser/download/download_shelf.h" | 36 #include "chrome/browser/download/download_shelf.h" |
37 #include "chrome/browser/download/download_stats.h" | 37 #include "chrome/browser/download/download_stats.h" |
38 #include "chrome/browser/download/drag_download_item.h" | 38 #include "chrome/browser/download/drag_download_item.h" |
39 #include "chrome/browser/extensions/extension_service.h" | |
40 #include "chrome/browser/extensions/extension_warning_service.h" | 39 #include "chrome/browser/extensions/extension_warning_service.h" |
41 #include "chrome/browser/icon_loader.h" | 40 #include "chrome/browser/icon_loader.h" |
42 #include "chrome/browser/icon_manager.h" | 41 #include "chrome/browser/icon_manager.h" |
43 #include "chrome/browser/platform_util.h" | 42 #include "chrome/browser/platform_util.h" |
44 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
45 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 44 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
46 #include "chrome/browser/ui/browser.h" | 45 #include "chrome/browser/ui/browser.h" |
47 #include "chrome/browser/ui/browser_list.h" | 46 #include "chrome/browser/ui/browser_list.h" |
48 #include "chrome/browser/ui/browser_window.h" | 47 #include "chrome/browser/ui/browser_window.h" |
49 #include "chrome/common/extensions/api/downloads.h" | 48 #include "chrome/common/extensions/api/downloads.h" |
50 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 49 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
51 #include "content/public/browser/download_interrupt_reasons.h" | 50 #include "content/public/browser/download_interrupt_reasons.h" |
52 #include "content/public/browser/download_item.h" | 51 #include "content/public/browser/download_item.h" |
53 #include "content/public/browser/download_save_info.h" | 52 #include "content/public/browser/download_save_info.h" |
54 #include "content/public/browser/download_url_parameters.h" | 53 #include "content/public/browser/download_url_parameters.h" |
55 #include "content/public/browser/notification_details.h" | 54 #include "content/public/browser/notification_details.h" |
56 #include "content/public/browser/notification_service.h" | 55 #include "content/public/browser/notification_service.h" |
57 #include "content/public/browser/notification_source.h" | 56 #include "content/public/browser/notification_source.h" |
58 #include "content/public/browser/render_process_host.h" | 57 #include "content/public/browser/render_process_host.h" |
59 #include "content/public/browser/render_view_host.h" | 58 #include "content/public/browser/render_view_host.h" |
60 #include "content/public/browser/render_widget_host_view.h" | 59 #include "content/public/browser/render_widget_host_view.h" |
61 #include "content/public/browser/resource_context.h" | 60 #include "content/public/browser/resource_context.h" |
62 #include "content/public/browser/resource_dispatcher_host.h" | 61 #include "content/public/browser/resource_dispatcher_host.h" |
63 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
64 #include "extensions/browser/event_router.h" | 63 #include "extensions/browser/event_router.h" |
65 #include "extensions/browser/extension_function_dispatcher.h" | 64 #include "extensions/browser/extension_function_dispatcher.h" |
| 65 #include "extensions/browser/extension_prefs.h" |
66 #include "extensions/browser/extension_registry.h" | 66 #include "extensions/browser/extension_registry.h" |
67 #include "extensions/browser/extension_system.h" | |
68 #include "net/base/filename_util.h" | 67 #include "net/base/filename_util.h" |
69 #include "net/base/load_flags.h" | 68 #include "net/base/load_flags.h" |
70 #include "net/http/http_util.h" | 69 #include "net/http/http_util.h" |
71 #include "third_party/skia/include/core/SkBitmap.h" | 70 #include "third_party/skia/include/core/SkBitmap.h" |
72 #include "ui/base/webui/web_ui_util.h" | 71 #include "ui/base/webui/web_ui_util.h" |
73 #include "ui/gfx/image/image_skia.h" | 72 #include "ui/gfx/image/image_skia.h" |
74 | 73 |
75 using content::BrowserContext; | 74 using content::BrowserContext; |
76 using content::BrowserThread; | 75 using content::BrowserThread; |
77 using content::DownloadItem; | 76 using content::DownloadItem; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 const char kUserGesture[] = "User gesture required"; | 108 const char kUserGesture[] = "User gesture required"; |
110 | 109 |
111 } // namespace download_extension_errors | 110 } // namespace download_extension_errors |
112 | 111 |
113 namespace errors = download_extension_errors; | 112 namespace errors = download_extension_errors; |
114 | 113 |
115 namespace extensions { | 114 namespace extensions { |
116 | 115 |
117 namespace { | 116 namespace { |
118 | 117 |
119 namespace downloads = extensions::api::downloads; | 118 namespace downloads = api::downloads; |
120 | 119 |
121 // Default icon size for getFileIcon() in pixels. | 120 // Default icon size for getFileIcon() in pixels. |
122 const int kDefaultIconSize = 32; | 121 const int kDefaultIconSize = 32; |
123 | 122 |
124 // Parameter keys | 123 // Parameter keys |
125 const char kByExtensionIdKey[] = "byExtensionId"; | 124 const char kByExtensionIdKey[] = "byExtensionId"; |
126 const char kByExtensionNameKey[] = "byExtensionName"; | 125 const char kByExtensionNameKey[] = "byExtensionName"; |
127 const char kBytesReceivedKey[] = "bytesReceived"; | 126 const char kBytesReceivedKey[] = "bytesReceived"; |
128 const char kCanResumeKey[] = "canResume"; | 127 const char kCanResumeKey[] = "canResume"; |
129 const char kDangerAccepted[] = "accepted"; | 128 const char kDangerAccepted[] = "accepted"; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 base::Time now = base::Time::Now(); | 272 base::Time now = base::Time::Now(); |
274 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining)); | 273 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining)); |
275 } | 274 } |
276 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item); | 275 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item); |
277 if (by_ext) { | 276 if (by_ext) { |
278 json->SetString(kByExtensionIdKey, by_ext->id()); | 277 json->SetString(kByExtensionIdKey, by_ext->id()); |
279 json->SetString(kByExtensionNameKey, by_ext->name()); | 278 json->SetString(kByExtensionNameKey, by_ext->name()); |
280 // Lookup the extension's current name() in case the user changed their | 279 // Lookup the extension's current name() in case the user changed their |
281 // language. This won't work if the extension was uninstalled, so the name | 280 // language. This won't work if the extension was uninstalled, so the name |
282 // might be the wrong language. | 281 // might be the wrong language. |
283 bool include_disabled = true; | 282 const Extension* extension = |
284 const extensions::Extension* extension = extensions::ExtensionSystem::Get( | 283 ExtensionRegistry::Get(profile) |
285 profile)->extension_service()->GetExtensionById( | 284 ->GetExtensionById(by_ext->id(), ExtensionRegistry::EVERYTHING); |
286 by_ext->id(), include_disabled); | |
287 if (extension) | 285 if (extension) |
288 json->SetString(kByExtensionNameKey, extension->name()); | 286 json->SetString(kByExtensionNameKey, extension->name()); |
289 } | 287 } |
290 // TODO(benjhayden): Implement fileSize. | 288 // TODO(benjhayden): Implement fileSize. |
291 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes()); | 289 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes()); |
292 return scoped_ptr<base::DictionaryValue>(json); | 290 return scoped_ptr<base::DictionaryValue>(json); |
293 } | 291 } |
294 | 292 |
295 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { | 293 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { |
296 public: | 294 public: |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 if (determiners_[index].extension_id == extension_id) { | 728 if (determiners_[index].extension_id == extension_id) { |
731 found_info = true; | 729 found_info = true; |
732 if (determiners_[index].reported) | 730 if (determiners_[index].reported) |
733 return false; | 731 return false; |
734 determiners_[index].reported = true; | 732 determiners_[index].reported = true; |
735 // Do not use filename if another determiner has already overridden the | 733 // Do not use filename if another determiner has already overridden the |
736 // filename and they take precedence. Extensions that were installed | 734 // filename and they take precedence. Extensions that were installed |
737 // later take precedence over previous extensions. | 735 // later take precedence over previous extensions. |
738 if (!filename.empty() || | 736 if (!filename.empty() || |
739 (conflict_action != downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { | 737 (conflict_action != downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { |
740 extensions::ExtensionWarningSet warnings; | 738 ExtensionWarningSet warnings; |
741 std::string winner_extension_id; | 739 std::string winner_extension_id; |
742 ExtensionDownloadsEventRouter::DetermineFilenameInternal( | 740 ExtensionDownloadsEventRouter::DetermineFilenameInternal( |
743 filename, | 741 filename, |
744 conflict_action, | 742 conflict_action, |
745 determiners_[index].extension_id, | 743 determiners_[index].extension_id, |
746 determiners_[index].install_time, | 744 determiners_[index].install_time, |
747 determiner_.extension_id, | 745 determiner_.extension_id, |
748 determiner_.install_time, | 746 determiner_.install_time, |
749 &winner_extension_id, | 747 &winner_extension_id, |
750 &determined_filename_, | 748 &determined_filename_, |
751 &determined_conflict_action_, | 749 &determined_conflict_action_, |
752 &warnings); | 750 &warnings); |
753 if (!warnings.empty()) | 751 if (!warnings.empty()) |
754 extensions::ExtensionWarningService::NotifyWarningsOnUI( | 752 ExtensionWarningService::NotifyWarningsOnUI(profile, warnings); |
755 profile, warnings); | |
756 if (winner_extension_id == determiners_[index].extension_id) | 753 if (winner_extension_id == determiners_[index].extension_id) |
757 determiner_ = determiners_[index]; | 754 determiner_ = determiners_[index]; |
758 } | 755 } |
759 break; | 756 break; |
760 } | 757 } |
761 } | 758 } |
762 if (!found_info) | 759 if (!found_info) |
763 return false; | 760 return false; |
764 CheckAllDeterminersCalled(); | 761 CheckAllDeterminersCalled(); |
765 return true; | 762 return true; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 DISALLOW_COPY_AND_ASSIGN(ManagerDestructionObserver); | 916 DISALLOW_COPY_AND_ASSIGN(ManagerDestructionObserver); |
920 }; | 917 }; |
921 | 918 |
922 std::map<DownloadManager*, ManagerDestructionObserver*>* | 919 std::map<DownloadManager*, ManagerDestructionObserver*>* |
923 ManagerDestructionObserver::manager_file_existence_last_checked_ = NULL; | 920 ManagerDestructionObserver::manager_file_existence_last_checked_ = NULL; |
924 | 921 |
925 void OnDeterminingFilenameWillDispatchCallback( | 922 void OnDeterminingFilenameWillDispatchCallback( |
926 bool* any_determiners, | 923 bool* any_determiners, |
927 ExtensionDownloadsEventRouterData* data, | 924 ExtensionDownloadsEventRouterData* data, |
928 content::BrowserContext* context, | 925 content::BrowserContext* context, |
929 const extensions::Extension* extension, | 926 const Extension* extension, |
930 base::ListValue* event_args) { | 927 base::ListValue* event_args) { |
931 *any_determiners = true; | 928 *any_determiners = true; |
932 base::Time installed = | 929 base::Time installed = |
933 extensions::ExtensionPrefs::Get(context)->GetInstallTime(extension->id()); | 930 ExtensionPrefs::Get(context)->GetInstallTime(extension->id()); |
934 data->AddPendingDeterminer(extension->id(), installed); | 931 data->AddPendingDeterminer(extension->id(), installed); |
935 } | 932 } |
936 | 933 |
937 bool Fault(bool error, | 934 bool Fault(bool error, |
938 const char* message_in, | 935 const char* message_in, |
939 std::string* message_out) { | 936 std::string* message_out) { |
940 if (!error) | 937 if (!error) |
941 return false; | 938 return false; |
942 *message_out = message_in; | 939 *message_out = message_in; |
943 return true; | 940 return true; |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 | 1377 |
1381 bool DownloadsOpenFunction::RunSync() { | 1378 bool DownloadsOpenFunction::RunSync() { |
1382 scoped_ptr<downloads::Open::Params> params( | 1379 scoped_ptr<downloads::Open::Params> params( |
1383 downloads::Open::Params::Create(*args_)); | 1380 downloads::Open::Params::Create(*args_)); |
1384 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1381 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1385 DownloadItem* download_item = | 1382 DownloadItem* download_item = |
1386 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1383 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1387 if (InvalidId(download_item, &error_) || | 1384 if (InvalidId(download_item, &error_) || |
1388 Fault(!user_gesture(), errors::kUserGesture, &error_) || | 1385 Fault(!user_gesture(), errors::kUserGesture, &error_) || |
1389 Fault(download_item->GetState() != DownloadItem::COMPLETE, | 1386 Fault(download_item->GetState() != DownloadItem::COMPLETE, |
1390 errors::kNotComplete, &error_) || | 1387 errors::kNotComplete, |
1391 Fault(!GetExtension()->HasAPIPermission( | 1388 &error_) || |
1392 extensions::APIPermission::kDownloadsOpen), | 1389 Fault(!GetExtension()->HasAPIPermission(APIPermission::kDownloadsOpen), |
1393 errors::kOpenPermission, &error_)) | 1390 errors::kOpenPermission, |
| 1391 &error_)) |
1394 return false; | 1392 return false; |
1395 download_item->OpenDownload(); | 1393 download_item->OpenDownload(); |
1396 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); | 1394 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); |
1397 return true; | 1395 return true; |
1398 } | 1396 } |
1399 | 1397 |
1400 DownloadsDragFunction::DownloadsDragFunction() {} | 1398 DownloadsDragFunction::DownloadsDragFunction() {} |
1401 | 1399 |
1402 DownloadsDragFunction::~DownloadsDragFunction() {} | 1400 DownloadsDragFunction::~DownloadsDragFunction() {} |
1403 | 1401 |
(...skipping 22 matching lines...) Expand all Loading... |
1426 } | 1424 } |
1427 | 1425 |
1428 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} | 1426 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} |
1429 | 1427 |
1430 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} | 1428 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} |
1431 | 1429 |
1432 bool DownloadsSetShelfEnabledFunction::RunSync() { | 1430 bool DownloadsSetShelfEnabledFunction::RunSync() { |
1433 scoped_ptr<downloads::SetShelfEnabled::Params> params( | 1431 scoped_ptr<downloads::SetShelfEnabled::Params> params( |
1434 downloads::SetShelfEnabled::Params::Create(*args_)); | 1432 downloads::SetShelfEnabled::Params::Create(*args_)); |
1435 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1433 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1436 if (!GetExtension()->HasAPIPermission( | 1434 if (!GetExtension()->HasAPIPermission(APIPermission::kDownloadsShelf)) { |
1437 extensions::APIPermission::kDownloadsShelf)) { | |
1438 error_ = download_extension_errors::kShelfPermission; | 1435 error_ = download_extension_errors::kShelfPermission; |
1439 return false; | 1436 return false; |
1440 } | 1437 } |
1441 | 1438 |
1442 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); | 1439 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); |
1443 DownloadManager* manager = NULL; | 1440 DownloadManager* manager = NULL; |
1444 DownloadManager* incognito_manager = NULL; | 1441 DownloadManager* incognito_manager = NULL; |
1445 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1442 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
1446 DownloadService* service = NULL; | 1443 DownloadService* service = NULL; |
1447 DownloadService* incognito_service = NULL; | 1444 DownloadService* incognito_service = NULL; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 } | 1539 } |
1543 | 1540 |
1544 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( | 1541 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( |
1545 Profile* profile, | 1542 Profile* profile, |
1546 DownloadManager* manager) | 1543 DownloadManager* manager) |
1547 : profile_(profile), | 1544 : profile_(profile), |
1548 notifier_(manager, this), | 1545 notifier_(manager, this), |
1549 extension_registry_observer_(this) { | 1546 extension_registry_observer_(this) { |
1550 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1547 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1551 DCHECK(profile_); | 1548 DCHECK(profile_); |
1552 extension_registry_observer_.Add( | 1549 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
1553 extensions::ExtensionRegistry::Get(profile_)); | 1550 EventRouter* router = EventRouter::Get(profile_); |
1554 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); | |
1555 if (router) | 1551 if (router) |
1556 router->RegisterObserver(this, | 1552 router->RegisterObserver(this, |
1557 downloads::OnDeterminingFilename::kEventName); | 1553 downloads::OnDeterminingFilename::kEventName); |
1558 } | 1554 } |
1559 | 1555 |
1560 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { | 1556 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { |
1561 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1557 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1562 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); | 1558 EventRouter* router = EventRouter::Get(profile_); |
1563 if (router) | 1559 if (router) |
1564 router->UnregisterObserver(this); | 1560 router->UnregisterObserver(this); |
1565 } | 1561 } |
1566 | 1562 |
1567 void ExtensionDownloadsEventRouter:: | 1563 void ExtensionDownloadsEventRouter:: |
1568 SetDetermineFilenameTimeoutSecondsForTesting(int s) { | 1564 SetDetermineFilenameTimeoutSecondsForTesting(int s) { |
1569 ExtensionDownloadsEventRouterData:: | 1565 ExtensionDownloadsEventRouterData:: |
1570 SetDetermineFilenameTimeoutSecondsForTesting(s); | 1566 SetDetermineFilenameTimeoutSecondsForTesting(s); |
1571 } | 1567 } |
1572 | 1568 |
1573 void ExtensionDownloadsEventRouter::SetShelfEnabled( | 1569 void ExtensionDownloadsEventRouter::SetShelfEnabled(const Extension* extension, |
1574 const extensions::Extension* extension, bool enabled) { | 1570 bool enabled) { |
1575 std::set<const extensions::Extension*>::iterator iter = | 1571 std::set<const Extension*>::iterator iter = |
1576 shelf_disabling_extensions_.find(extension); | 1572 shelf_disabling_extensions_.find(extension); |
1577 if (iter == shelf_disabling_extensions_.end()) { | 1573 if (iter == shelf_disabling_extensions_.end()) { |
1578 if (!enabled) | 1574 if (!enabled) |
1579 shelf_disabling_extensions_.insert(extension); | 1575 shelf_disabling_extensions_.insert(extension); |
1580 } else if (enabled) { | 1576 } else if (enabled) { |
1581 shelf_disabling_extensions_.erase(extension); | 1577 shelf_disabling_extensions_.erase(extension); |
1582 } | 1578 } |
1583 } | 1579 } |
1584 | 1580 |
1585 bool ExtensionDownloadsEventRouter::IsShelfEnabled() const { | 1581 bool ExtensionDownloadsEventRouter::IsShelfEnabled() const { |
1586 return shelf_disabling_extensions_.empty(); | 1582 return shelf_disabling_extensions_.empty(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 | 1646 |
1651 void ExtensionDownloadsEventRouter::DetermineFilenameInternal( | 1647 void ExtensionDownloadsEventRouter::DetermineFilenameInternal( |
1652 const base::FilePath& filename, | 1648 const base::FilePath& filename, |
1653 downloads::FilenameConflictAction conflict_action, | 1649 downloads::FilenameConflictAction conflict_action, |
1654 const std::string& suggesting_extension_id, | 1650 const std::string& suggesting_extension_id, |
1655 const base::Time& suggesting_install_time, | 1651 const base::Time& suggesting_install_time, |
1656 const std::string& incumbent_extension_id, | 1652 const std::string& incumbent_extension_id, |
1657 const base::Time& incumbent_install_time, | 1653 const base::Time& incumbent_install_time, |
1658 std::string* winner_extension_id, | 1654 std::string* winner_extension_id, |
1659 base::FilePath* determined_filename, | 1655 base::FilePath* determined_filename, |
1660 downloads::FilenameConflictAction* | 1656 downloads::FilenameConflictAction* determined_conflict_action, |
1661 determined_conflict_action, | 1657 ExtensionWarningSet* warnings) { |
1662 extensions::ExtensionWarningSet* warnings) { | |
1663 DCHECK(!filename.empty() || | 1658 DCHECK(!filename.empty() || |
1664 (conflict_action != downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)); | 1659 (conflict_action != downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)); |
1665 DCHECK(!suggesting_extension_id.empty()); | 1660 DCHECK(!suggesting_extension_id.empty()); |
1666 | 1661 |
1667 if (incumbent_extension_id.empty()) { | 1662 if (incumbent_extension_id.empty()) { |
1668 *winner_extension_id = suggesting_extension_id; | 1663 *winner_extension_id = suggesting_extension_id; |
1669 *determined_filename = filename; | 1664 *determined_filename = filename; |
1670 *determined_conflict_action = conflict_action; | 1665 *determined_conflict_action = conflict_action; |
1671 return; | 1666 return; |
1672 } | 1667 } |
1673 | 1668 |
1674 if (suggesting_install_time < incumbent_install_time) { | 1669 if (suggesting_install_time < incumbent_install_time) { |
1675 *winner_extension_id = incumbent_extension_id; | 1670 *winner_extension_id = incumbent_extension_id; |
1676 warnings->insert( | 1671 warnings->insert(ExtensionWarning::CreateDownloadFilenameConflictWarning( |
1677 extensions::ExtensionWarning::CreateDownloadFilenameConflictWarning( | 1672 suggesting_extension_id, |
1678 suggesting_extension_id, | 1673 incumbent_extension_id, |
1679 incumbent_extension_id, | 1674 filename, |
1680 filename, | 1675 *determined_filename)); |
1681 *determined_filename)); | |
1682 return; | 1676 return; |
1683 } | 1677 } |
1684 | 1678 |
1685 *winner_extension_id = suggesting_extension_id; | 1679 *winner_extension_id = suggesting_extension_id; |
1686 warnings->insert( | 1680 warnings->insert(ExtensionWarning::CreateDownloadFilenameConflictWarning( |
1687 extensions::ExtensionWarning::CreateDownloadFilenameConflictWarning( | 1681 incumbent_extension_id, |
1688 incumbent_extension_id, | 1682 suggesting_extension_id, |
1689 suggesting_extension_id, | 1683 *determined_filename, |
1690 *determined_filename, | 1684 filename)); |
1691 filename)); | |
1692 *determined_filename = filename; | 1685 *determined_filename = filename; |
1693 *determined_conflict_action = conflict_action; | 1686 *determined_conflict_action = conflict_action; |
1694 } | 1687 } |
1695 | 1688 |
1696 bool ExtensionDownloadsEventRouter::DetermineFilename( | 1689 bool ExtensionDownloadsEventRouter::DetermineFilename( |
1697 Profile* profile, | 1690 Profile* profile, |
1698 bool include_incognito, | 1691 bool include_incognito, |
1699 const std::string& ext_id, | 1692 const std::string& ext_id, |
1700 int download_id, | 1693 int download_id, |
1701 const base::FilePath& const_filename, | 1694 const base::FilePath& const_filename, |
(...skipping 28 matching lines...) Expand all Loading... |
1730 if (Fault(!data->DeterminerCallback( | 1723 if (Fault(!data->DeterminerCallback( |
1731 profile, ext_id, filename, conflict_action), | 1724 profile, ext_id, filename, conflict_action), |
1732 errors::kUnexpectedDeterminer, error) || | 1725 errors::kUnexpectedDeterminer, error) || |
1733 Fault((!const_filename.empty() && !valid_filename), | 1726 Fault((!const_filename.empty() && !valid_filename), |
1734 errors::kInvalidFilename, error)) | 1727 errors::kInvalidFilename, error)) |
1735 return false; | 1728 return false; |
1736 return true; | 1729 return true; |
1737 } | 1730 } |
1738 | 1731 |
1739 void ExtensionDownloadsEventRouter::OnListenerRemoved( | 1732 void ExtensionDownloadsEventRouter::OnListenerRemoved( |
1740 const extensions::EventListenerInfo& details) { | 1733 const EventListenerInfo& details) { |
1741 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1734 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1742 DownloadManager* manager = notifier_.GetManager(); | 1735 DownloadManager* manager = notifier_.GetManager(); |
1743 if (!manager) | 1736 if (!manager) |
1744 return; | 1737 return; |
1745 bool determiner_removed = ( | 1738 bool determiner_removed = ( |
1746 details.event_name == downloads::OnDeterminingFilename::kEventName); | 1739 details.event_name == downloads::OnDeterminingFilename::kEventName); |
1747 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1740 EventRouter* router = EventRouter::Get(profile_); |
1748 event_router(); | |
1749 bool any_listeners = | 1741 bool any_listeners = |
1750 router->HasEventListener(downloads::OnChanged::kEventName) || | 1742 router->HasEventListener(downloads::OnChanged::kEventName) || |
1751 router->HasEventListener(downloads::OnDeterminingFilename::kEventName); | 1743 router->HasEventListener(downloads::OnDeterminingFilename::kEventName); |
1752 if (!determiner_removed && any_listeners) | 1744 if (!determiner_removed && any_listeners) |
1753 return; | 1745 return; |
1754 DownloadManager::DownloadVector items; | 1746 DownloadManager::DownloadVector items; |
1755 manager->GetAllDownloads(&items); | 1747 manager->GetAllDownloads(&items); |
1756 for (DownloadManager::DownloadVector::const_iterator iter = | 1748 for (DownloadManager::DownloadVector::const_iterator iter = |
1757 items.begin(); | 1749 items.begin(); |
1758 iter != items.end(); ++iter) { | 1750 iter != items.end(); ++iter) { |
(...skipping 18 matching lines...) Expand all Loading... |
1777 | 1769 |
1778 // That's all the methods that have to do with filename determination. The rest | 1770 // That's all the methods that have to do with filename determination. The rest |
1779 // have to do with the other, less special events. | 1771 // have to do with the other, less special events. |
1780 | 1772 |
1781 void ExtensionDownloadsEventRouter::OnDownloadCreated( | 1773 void ExtensionDownloadsEventRouter::OnDownloadCreated( |
1782 DownloadManager* manager, DownloadItem* download_item) { | 1774 DownloadManager* manager, DownloadItem* download_item) { |
1783 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1775 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1784 if (download_item->IsTemporary()) | 1776 if (download_item->IsTemporary()) |
1785 return; | 1777 return; |
1786 | 1778 |
1787 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1779 EventRouter* router = EventRouter::Get(profile_); |
1788 event_router(); | |
1789 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going | 1780 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going |
1790 // to be used. | 1781 // to be used. |
1791 if (!router || | 1782 if (!router || |
1792 (!router->HasEventListener(downloads::OnCreated::kEventName) && | 1783 (!router->HasEventListener(downloads::OnCreated::kEventName) && |
1793 !router->HasEventListener(downloads::OnChanged::kEventName) && | 1784 !router->HasEventListener(downloads::OnChanged::kEventName) && |
1794 !router->HasEventListener( | 1785 !router->HasEventListener( |
1795 downloads::OnDeterminingFilename::kEventName))) { | 1786 downloads::OnDeterminingFilename::kEventName))) { |
1796 return; | 1787 return; |
1797 } | 1788 } |
1798 scoped_ptr<base::DictionaryValue> json_item( | 1789 scoped_ptr<base::DictionaryValue> json_item( |
1799 DownloadItemToJSON(download_item, profile_)); | 1790 DownloadItemToJSON(download_item, profile_)); |
1800 DispatchEvent(downloads::OnCreated::kEventName, | 1791 DispatchEvent(downloads::OnCreated::kEventName, |
1801 true, | 1792 true, |
1802 extensions::Event::WillDispatchCallback(), | 1793 Event::WillDispatchCallback(), |
1803 json_item->DeepCopy()); | 1794 json_item->DeepCopy()); |
1804 if (!ExtensionDownloadsEventRouterData::Get(download_item) && | 1795 if (!ExtensionDownloadsEventRouterData::Get(download_item) && |
1805 (router->HasEventListener(downloads::OnChanged::kEventName) || | 1796 (router->HasEventListener(downloads::OnChanged::kEventName) || |
1806 router->HasEventListener( | 1797 router->HasEventListener( |
1807 downloads::OnDeterminingFilename::kEventName))) { | 1798 downloads::OnDeterminingFilename::kEventName))) { |
1808 new ExtensionDownloadsEventRouterData(download_item, json_item.Pass()); | 1799 new ExtensionDownloadsEventRouterData(download_item, json_item.Pass()); |
1809 } | 1800 } |
1810 } | 1801 } |
1811 | 1802 |
1812 void ExtensionDownloadsEventRouter::OnDownloadUpdated( | 1803 void ExtensionDownloadsEventRouter::OnDownloadUpdated( |
1813 DownloadManager* manager, DownloadItem* download_item) { | 1804 DownloadManager* manager, DownloadItem* download_item) { |
1814 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1805 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1815 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1806 EventRouter* router = EventRouter::Get(profile_); |
1816 event_router(); | |
1817 ExtensionDownloadsEventRouterData* data = | 1807 ExtensionDownloadsEventRouterData* data = |
1818 ExtensionDownloadsEventRouterData::Get(download_item); | 1808 ExtensionDownloadsEventRouterData::Get(download_item); |
1819 if (download_item->IsTemporary() || | 1809 if (download_item->IsTemporary() || |
1820 !router->HasEventListener(downloads::OnChanged::kEventName)) { | 1810 !router->HasEventListener(downloads::OnChanged::kEventName)) { |
1821 return; | 1811 return; |
1822 } | 1812 } |
1823 if (!data) { | 1813 if (!data) { |
1824 // The download_item probably transitioned from temporary to not temporary, | 1814 // The download_item probably transitioned from temporary to not temporary, |
1825 // or else an event listener was added. | 1815 // or else an event listener was added. |
1826 data = new ExtensionDownloadsEventRouterData( | 1816 data = new ExtensionDownloadsEventRouterData( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1865 changed = true; | 1855 changed = true; |
1866 } | 1856 } |
1867 } | 1857 } |
1868 | 1858 |
1869 // Update the OnChangedStat and dispatch the event if something significant | 1859 // Update the OnChangedStat and dispatch the event if something significant |
1870 // changed. Replace the stored json with the new json. | 1860 // changed. Replace the stored json with the new json. |
1871 data->OnItemUpdated(); | 1861 data->OnItemUpdated(); |
1872 if (changed) { | 1862 if (changed) { |
1873 DispatchEvent(downloads::OnChanged::kEventName, | 1863 DispatchEvent(downloads::OnChanged::kEventName, |
1874 true, | 1864 true, |
1875 extensions::Event::WillDispatchCallback(), | 1865 Event::WillDispatchCallback(), |
1876 delta.release()); | 1866 delta.release()); |
1877 data->OnChangedFired(); | 1867 data->OnChangedFired(); |
1878 } | 1868 } |
1879 data->set_json(new_json.Pass()); | 1869 data->set_json(new_json.Pass()); |
1880 } | 1870 } |
1881 | 1871 |
1882 void ExtensionDownloadsEventRouter::OnDownloadRemoved( | 1872 void ExtensionDownloadsEventRouter::OnDownloadRemoved( |
1883 DownloadManager* manager, DownloadItem* download_item) { | 1873 DownloadManager* manager, DownloadItem* download_item) { |
1884 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1874 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1885 if (download_item->IsTemporary()) | 1875 if (download_item->IsTemporary()) |
1886 return; | 1876 return; |
1887 DispatchEvent(downloads::OnErased::kEventName, | 1877 DispatchEvent( |
1888 true, | 1878 downloads::OnErased::kEventName, |
1889 extensions::Event::WillDispatchCallback(), | 1879 true, |
1890 new base::FundamentalValue( | 1880 Event::WillDispatchCallback(), |
1891 static_cast<int>(download_item->GetId()))); | 1881 new base::FundamentalValue(static_cast<int>(download_item->GetId()))); |
1892 } | 1882 } |
1893 | 1883 |
1894 void ExtensionDownloadsEventRouter::DispatchEvent( | 1884 void ExtensionDownloadsEventRouter::DispatchEvent( |
1895 const std::string& event_name, | 1885 const std::string& event_name, |
1896 bool include_incognito, | 1886 bool include_incognito, |
1897 const extensions::Event::WillDispatchCallback& will_dispatch_callback, | 1887 const Event::WillDispatchCallback& will_dispatch_callback, |
1898 base::Value* arg) { | 1888 base::Value* arg) { |
1899 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1889 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1900 if (!extensions::EventRouter::Get(profile_)) | 1890 if (!EventRouter::Get(profile_)) |
1901 return; | 1891 return; |
1902 scoped_ptr<base::ListValue> args(new base::ListValue()); | 1892 scoped_ptr<base::ListValue> args(new base::ListValue()); |
1903 args->Append(arg); | 1893 args->Append(arg); |
1904 std::string json_args; | 1894 std::string json_args; |
1905 base::JSONWriter::Write(args.get(), &json_args); | 1895 base::JSONWriter::Write(args.get(), &json_args); |
1906 scoped_ptr<extensions::Event> event(new extensions::Event( | 1896 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
1907 event_name, args.Pass())); | |
1908 // The downloads system wants to share on-record events with off-record | 1897 // The downloads system wants to share on-record events with off-record |
1909 // extension renderers even in incognito_split_mode because that's how | 1898 // extension renderers even in incognito_split_mode because that's how |
1910 // chrome://downloads works. The "restrict_to_profile" mechanism does not | 1899 // chrome://downloads works. The "restrict_to_profile" mechanism does not |
1911 // anticipate this, so it does not automatically prevent sharing off-record | 1900 // anticipate this, so it does not automatically prevent sharing off-record |
1912 // events with on-record extension renderers. | 1901 // events with on-record extension renderers. |
1913 event->restrict_to_browser_context = | 1902 event->restrict_to_browser_context = |
1914 (include_incognito && !profile_->IsOffTheRecord()) ? NULL : profile_; | 1903 (include_incognito && !profile_->IsOffTheRecord()) ? NULL : profile_; |
1915 event->will_dispatch_callback = will_dispatch_callback; | 1904 event->will_dispatch_callback = will_dispatch_callback; |
1916 extensions::EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 1905 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
1917 DownloadsNotificationSource notification_source; | 1906 DownloadsNotificationSource notification_source; |
1918 notification_source.event_name = event_name; | 1907 notification_source.event_name = event_name; |
1919 notification_source.profile = profile_; | 1908 notification_source.profile = profile_; |
1920 content::Source<DownloadsNotificationSource> content_source( | 1909 content::Source<DownloadsNotificationSource> content_source( |
1921 ¬ification_source); | 1910 ¬ification_source); |
1922 content::NotificationService::current()->Notify( | 1911 content::NotificationService::current()->Notify( |
1923 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, | 1912 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, |
1924 content_source, | 1913 content_source, |
1925 content::Details<std::string>(&json_args)); | 1914 content::Details<std::string>(&json_args)); |
1926 } | 1915 } |
1927 | 1916 |
1928 void ExtensionDownloadsEventRouter::OnExtensionUnloaded( | 1917 void ExtensionDownloadsEventRouter::OnExtensionUnloaded( |
1929 content::BrowserContext* browser_context, | 1918 content::BrowserContext* browser_context, |
1930 const extensions::Extension* extension, | 1919 const Extension* extension, |
1931 extensions::UnloadedExtensionInfo::Reason reason) { | 1920 UnloadedExtensionInfo::Reason reason) { |
1932 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1921 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1933 std::set<const extensions::Extension*>::iterator iter = | 1922 std::set<const Extension*>::iterator iter = |
1934 shelf_disabling_extensions_.find(extension); | 1923 shelf_disabling_extensions_.find(extension); |
1935 if (iter != shelf_disabling_extensions_.end()) | 1924 if (iter != shelf_disabling_extensions_.end()) |
1936 shelf_disabling_extensions_.erase(iter); | 1925 shelf_disabling_extensions_.erase(iter); |
1937 } | 1926 } |
1938 | 1927 |
1939 } // namespace extensions | 1928 } // namespace extensions |
OLD | NEW |