Index: chrome/browser/extensions/api/downloads/downloads_api.h |
diff --git a/chrome/browser/extensions/api/downloads/downloads_api.h b/chrome/browser/extensions/api/downloads/downloads_api.h |
index 6efb8df89116b98e4293721bfe8225ddb628fce8..098fe5d3b76d0ba01989c4cc099870cd90615616 100644 |
--- a/chrome/browser/extensions/api/downloads/downloads_api.h |
+++ b/chrome/browser/extensions/api/downloads/downloads_api.h |
@@ -8,6 +8,7 @@ |
#include <string> |
#include "base/file_path.h" |
+#include "base/hash_tables.h" |
#include "base/memory/singleton.h" |
#include "base/string16.h" |
#include "base/values.h" |
@@ -126,20 +127,6 @@ class DownloadsEraseFunction : public SyncExtensionFunction { |
DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); |
}; |
-class DownloadsSetDestinationFunction : public AsyncExtensionFunction { |
- public: |
- DECLARE_EXTENSION_FUNCTION("downloads.setDestination", |
- DOWNLOADS_SETDESTINATION) |
- DownloadsSetDestinationFunction(); |
- virtual bool RunImpl() OVERRIDE; |
- |
- protected: |
- virtual ~DownloadsSetDestinationFunction(); |
- |
- private: |
- DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction); |
-}; |
- |
class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { |
public: |
DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) |
@@ -212,13 +199,62 @@ class DownloadsGetFileIconFunction : public AsyncExtensionFunction { |
// Observes a single DownloadManager and many DownloadItems and dispatches |
// onCreated and onErased events. |
-class ExtensionDownloadsEventRouter |
- : public AllDownloadItemNotifier::Observer { |
+class ExtensionDownloadsEventRouter : public content::NotificationObserver, |
+ public AllDownloadItemNotifier::Observer { |
public: |
+ typedef base::Callback<void(const base::FilePath& changed_filename, |
+ bool overwrite)> FilenameChangedCallback; |
+ |
+ // An extension has added a listener for downloads.onDeterminingFilename. When |
+ // that event is dispatched, the filename determination process will be |
+ // blocked until all listeners return. Returns true on success, false |
+ // otherwise. |
+ static bool AddFilenameDeterminer( |
+ Profile* profile, |
+ bool include_incognito, |
+ const std::string& ext_id, |
+ int sub_event_id); |
+ |
+ // An extension has removed a listener for downloads.onDeterminingFilename. |
+ // The filename determination process should not wait for this listener, |
+ // because it won't be run. Returns true on success, false otherwise. |
+ static bool RemoveFilenameDeterminer( |
+ Profile* profile, |
+ const std::string& ext_id, |
+ int sub_event_id); |
+ |
+ // A downloads.onDeterminingFilename listener has returned. If the extension |
+ // wishes to override the download's filename, then |filename| will be |
+ // non-empty. |filename| will be interpreted as a relative path, appended to |
+ // the default downloads directory. If the extension wishes to overwrite any |
+ // existing files, then |overwrite| will be true. Returns true on success, |
+ // false otherwise. |
+ static bool DetermineFilename( |
+ Profile* profile, |
+ bool include_incognito, |
+ const std::string& ext_id, |
+ int sub_event_id, |
+ int download_id, |
+ const base::FilePath& filename, |
+ bool overwrite); |
+ |
explicit ExtensionDownloadsEventRouter( |
Profile* profile, content::DownloadManager* manager); |
virtual ~ExtensionDownloadsEventRouter(); |
+ // Called by ChromeDownloadManagerDelegate during the filename determination |
+ // process, allows extensions to change the item's target filename. If no |
+ // extension wants to change the target filename, then |no_change| will be |
+ // called and the filename determination process will continue as normal. If |
+ // an extension wants to change the target filename, then |change| will be |
+ // called with the new filename and a flag indicating whether the new file |
+ // should overwrite any old files of the same name. |
+ void OnDeterminingFilename( |
+ content::DownloadItem* item, |
+ const base::FilePath& suggested_path, |
+ const base::Closure& no_change, |
+ const FilenameChangedCallback& change); |
+ |
// AllDownloadItemNotifier::Observer interface |
virtual void OnDownloadCreated( |
content::DownloadManager* manager, |
@@ -237,11 +273,43 @@ class ExtensionDownloadsEventRouter |
}; |
private: |
- void DispatchEvent(const char* event_name, base::Value* json_arg); |
+ struct DeterminerId { |
+ DeterminerId( |
+ const std::string& ext_id, |
+ int sub_id, |
+ bool incognito, |
+ const base::Time& install); |
+ ~DeterminerId(); |
+ |
+ std::string extension_id; |
+ int sub_event_id; |
+ bool include_incognito; |
+ base::Time installed; |
+ }; |
+ |
+ typedef std::vector<DeterminerId> DeterminerVector; |
+ |
+ void DispatchEvent( |
+ const char* event_name, |
+ bool include_incognito, |
+ base::Value* json_arg); |
+ |
+ virtual void Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) OVERRIDE; |
Profile* profile_; |
+ content::NotificationRegistrar registrar_; |
AllDownloadItemNotifier notifier_; |
+ // AddFilenameDeterminer appends to this; RemoveFilenameDeterminer removes |
+ // from this. When onDeterminingFilename is dispatched for a DownloadItem, |
+ // that item's EDERD UserData is given a copy of this so that it can know when |
+ // all determiners have reported. The last determiner added has the highest |
+ // priority. |
+ DeterminerVector determiners_; |
+ |
DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
}; |