| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/scoped_observer.h" |
| 13 #include "base/strings/string16.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/download/all_download_item_notifier.h" | 13 #include "chrome/browser/download/all_download_item_notifier.h" |
| 16 #include "chrome/browser/download/download_danger_prompt.h" | 14 #include "chrome/browser/download/download_danger_prompt.h" |
| 17 #include "chrome/browser/download/download_path_reservation_tracker.h" | 15 #include "chrome/browser/download/download_path_reservation_tracker.h" |
| 18 #include "chrome/browser/extensions/chrome_extension_function.h" | 16 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 19 #include "chrome/browser/extensions/extension_warning_set.h" | 17 #include "chrome/browser/extensions/extension_warning_set.h" |
| 20 #include "chrome/common/extensions/api/downloads.h" | 18 #include "chrome/common/extensions/api/downloads.h" |
| 21 #include "content/public/browser/download_item.h" | |
| 22 #include "content/public/browser/download_manager.h" | 19 #include "content/public/browser/download_manager.h" |
| 23 #include "content/public/browser/notification_observer.h" | |
| 24 #include "content/public/browser/notification_registrar.h" | |
| 25 #include "extensions/browser/event_router.h" | 20 #include "extensions/browser/event_router.h" |
| 21 #include "extensions/browser/extension_registry_observer.h" |
| 26 | 22 |
| 27 class DownloadFileIconExtractor; | 23 class DownloadFileIconExtractor; |
| 28 class DownloadQuery; | 24 class DownloadQuery; |
| 29 | 25 |
| 30 namespace content { | 26 namespace content { |
| 31 class ResourceContext; | 27 class ResourceContext; |
| 32 class ResourceDispatcherHost; | 28 class ResourceDispatcherHost; |
| 33 } | 29 } |
| 34 | 30 |
| 31 namespace extensions { |
| 32 class ExtensionRegistry; |
| 33 } |
| 34 |
| 35 // Functions in the chrome.downloads namespace facilitate | 35 // Functions in the chrome.downloads namespace facilitate |
| 36 // controlling downloads from extensions. See the full API doc at | 36 // controlling downloads from extensions. See the full API doc at |
| 37 // http://goo.gl/6hO1n | 37 // http://goo.gl/6hO1n |
| 38 | 38 |
| 39 namespace download_extension_errors { | 39 namespace download_extension_errors { |
| 40 | 40 |
| 41 // Errors that can be returned through chrome.runtime.lastError.message. | 41 // Errors that can be returned through chrome.runtime.lastError.message. |
| 42 extern const char kEmptyFile[]; | 42 extern const char kEmptyFile[]; |
| 43 extern const char kFileAlreadyDeleted[]; | 43 extern const char kFileAlreadyDeleted[]; |
| 44 extern const char kFileNotRemoved[]; | 44 extern const char kFileNotRemoved[]; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 private: | 290 private: |
| 291 void OnIconURLExtracted(const std::string& url); | 291 void OnIconURLExtracted(const std::string& url); |
| 292 base::FilePath path_; | 292 base::FilePath path_; |
| 293 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; | 293 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; |
| 294 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); | 294 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); |
| 295 }; | 295 }; |
| 296 | 296 |
| 297 // Observes a single DownloadManager and many DownloadItems and dispatches | 297 // Observes a single DownloadManager and many DownloadItems and dispatches |
| 298 // onCreated and onErased events. | 298 // onCreated and onErased events. |
| 299 class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer, | 299 class ExtensionDownloadsEventRouter |
| 300 public content::NotificationObserver, | 300 : public extensions::EventRouter::Observer, |
| 301 public AllDownloadItemNotifier::Observer { | 301 public extensions::ExtensionRegistryObserver, |
| 302 public AllDownloadItemNotifier::Observer { |
| 302 public: | 303 public: |
| 303 typedef base::Callback<void( | 304 typedef base::Callback<void( |
| 304 const base::FilePath& changed_filename, | 305 const base::FilePath& changed_filename, |
| 305 DownloadPathReservationTracker::FilenameConflictAction)> | 306 DownloadPathReservationTracker::FilenameConflictAction)> |
| 306 FilenameChangedCallback; | 307 FilenameChangedCallback; |
| 307 | 308 |
| 308 // The logic for how to handle conflicting filename suggestions from multiple | 309 // The logic for how to handle conflicting filename suggestions from multiple |
| 309 // extensions is split out here for testing. | 310 // extensions is split out here for testing. |
| 310 static void DetermineFilenameInternal( | 311 static void DetermineFilenameInternal( |
| 311 const base::FilePath& filename, | 312 const base::FilePath& filename, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 // called and the filename determination process will continue as normal. If | 349 // called and the filename determination process will continue as normal. If |
| 349 // an extension wants to change the target filename, then |change| will be | 350 // an extension wants to change the target filename, then |change| will be |
| 350 // called with the new filename and a flag indicating whether the new file | 351 // called with the new filename and a flag indicating whether the new file |
| 351 // should overwrite any old files of the same name. | 352 // should overwrite any old files of the same name. |
| 352 void OnDeterminingFilename( | 353 void OnDeterminingFilename( |
| 353 content::DownloadItem* item, | 354 content::DownloadItem* item, |
| 354 const base::FilePath& suggested_path, | 355 const base::FilePath& suggested_path, |
| 355 const base::Closure& no_change, | 356 const base::Closure& no_change, |
| 356 const FilenameChangedCallback& change); | 357 const FilenameChangedCallback& change); |
| 357 | 358 |
| 358 // AllDownloadItemNotifier::Observer | 359 // AllDownloadItemNotifier::Observer. |
| 359 virtual void OnDownloadCreated( | 360 virtual void OnDownloadCreated( |
| 360 content::DownloadManager* manager, | 361 content::DownloadManager* manager, |
| 361 content::DownloadItem* download_item) OVERRIDE; | 362 content::DownloadItem* download_item) OVERRIDE; |
| 362 virtual void OnDownloadUpdated( | 363 virtual void OnDownloadUpdated( |
| 363 content::DownloadManager* manager, | 364 content::DownloadManager* manager, |
| 364 content::DownloadItem* download_item) OVERRIDE; | 365 content::DownloadItem* download_item) OVERRIDE; |
| 365 virtual void OnDownloadRemoved( | 366 virtual void OnDownloadRemoved( |
| 366 content::DownloadManager* manager, | 367 content::DownloadManager* manager, |
| 367 content::DownloadItem* download_item) OVERRIDE; | 368 content::DownloadItem* download_item) OVERRIDE; |
| 368 | 369 |
| 369 // extensions::EventRouter::Observer | 370 // extensions::EventRouter::Observer. |
| 370 virtual void OnListenerRemoved( | 371 virtual void OnListenerRemoved( |
| 371 const extensions::EventListenerInfo& details) OVERRIDE; | 372 const extensions::EventListenerInfo& details) OVERRIDE; |
| 372 | 373 |
| 373 // Used for testing. | 374 // Used for testing. |
| 374 struct DownloadsNotificationSource { | 375 struct DownloadsNotificationSource { |
| 375 std::string event_name; | 376 std::string event_name; |
| 376 Profile* profile; | 377 Profile* profile; |
| 377 }; | 378 }; |
| 378 | 379 |
| 379 private: | 380 private: |
| 380 void DispatchEvent( | 381 void DispatchEvent( |
| 381 const std::string& event_name, | 382 const std::string& event_name, |
| 382 bool include_incognito, | 383 bool include_incognito, |
| 383 const extensions::Event::WillDispatchCallback& will_dispatch_callback, | 384 const extensions::Event::WillDispatchCallback& will_dispatch_callback, |
| 384 base::Value* json_arg); | 385 base::Value* json_arg); |
| 385 | 386 |
| 386 // content::NotificationObserver | 387 // extensions::ExtensionRegistryObserver. |
| 387 virtual void Observe(int type, | 388 virtual void OnExtensionUnloaded( |
| 388 const content::NotificationSource& source, | 389 content::BrowserContext* browser_context, |
| 389 const content::NotificationDetails& details) OVERRIDE; | 390 const extensions::Extension* extension, |
| 391 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 390 | 392 |
| 391 Profile* profile_; | 393 Profile* profile_; |
| 392 AllDownloadItemNotifier notifier_; | 394 AllDownloadItemNotifier notifier_; |
| 393 std::set<const extensions::Extension*> shelf_disabling_extensions_; | 395 std::set<const extensions::Extension*> shelf_disabling_extensions_; |
| 394 content::NotificationRegistrar registrar_; | 396 |
| 397 // Listen to extension unloaded notifications. |
| 398 ScopedObserver<extensions::ExtensionRegistry, |
| 399 extensions::ExtensionRegistryObserver> |
| 400 extension_registry_observer_; |
| 395 | 401 |
| 396 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 402 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| 397 }; | 403 }; |
| 398 | 404 |
| 399 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 405 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| OLD | NEW |