| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/download/all_download_item_notifier.h" | 14 #include "chrome/browser/download/all_download_item_notifier.h" |
| 15 #include "chrome/browser/download/download_danger_prompt.h" |
| 15 #include "chrome/browser/download/download_path_reservation_tracker.h" | 16 #include "chrome/browser/download/download_path_reservation_tracker.h" |
| 16 #include "chrome/browser/extensions/event_router.h" | 17 #include "chrome/browser/extensions/event_router.h" |
| 17 #include "chrome/browser/extensions/extension_function.h" | 18 #include "chrome/browser/extensions/extension_function.h" |
| 18 #include "chrome/common/extensions/api/downloads.h" | 19 #include "chrome/common/extensions/api/downloads.h" |
| 19 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
| 20 #include "content/public/browser/download_manager.h" | 21 #include "content/public/browser/download_manager.h" |
| 21 | 22 |
| 22 class DownloadFileIconExtractor; | 23 class DownloadFileIconExtractor; |
| 23 class DownloadQuery; | 24 class DownloadQuery; |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 class ResourceContext; | 27 class ResourceContext; |
| 27 class ResourceDispatcherHost; | 28 class ResourceDispatcherHost; |
| 28 } | 29 } |
| 29 | 30 |
| 30 // Functions in the chrome.downloads namespace facilitate | 31 // Functions in the chrome.downloads namespace facilitate |
| 31 // controlling downloads from extensions. See the full API doc at | 32 // controlling downloads from extensions. See the full API doc at |
| 32 // http://goo.gl/6hO1n | 33 // http://goo.gl/6hO1n |
| 33 | 34 |
| 34 namespace download_extension_errors { | 35 namespace download_extension_errors { |
| 35 | 36 |
| 36 // Errors that can be returned through chrome.runtime.lastError.message. | 37 // Errors that can be returned through chrome.runtime.lastError.message. |
| 37 extern const char kGenericError[]; | 38 extern const char kEmptyFile[]; |
| 38 extern const char kIconNotFoundError[]; | 39 extern const char kFileAlreadyDeleted[]; |
| 39 extern const char kInvalidDangerTypeError[]; | 40 extern const char kIconNotFound[]; |
| 40 extern const char kInvalidFilenameError[]; | 41 extern const char kInvalidDangerType[]; |
| 41 extern const char kInvalidFilterError[]; | 42 extern const char kInvalidFilename[]; |
| 42 extern const char kInvalidOperationError[]; | 43 extern const char kInvalidFilter[]; |
| 43 extern const char kInvalidOrderByError[]; | 44 extern const char kInvalidHeader[]; |
| 45 extern const char kInvalidId[]; |
| 46 extern const char kInvalidOrderBy[]; |
| 44 extern const char kInvalidQueryLimit[]; | 47 extern const char kInvalidQueryLimit[]; |
| 45 extern const char kInvalidStateError[]; | 48 extern const char kInvalidState[]; |
| 46 extern const char kInvalidURLError[]; | 49 extern const char kInvalidURL[]; |
| 47 extern const char kNotImplementedError[]; | 50 extern const char kInvisibleContext[]; |
| 48 extern const char kTooManyListenersError[]; | 51 extern const char kNotComplete[]; |
| 52 extern const char kNotDangerous[]; |
| 53 extern const char kNotInProgress[]; |
| 54 extern const char kNotResumable[]; |
| 55 extern const char kOpenPermission[]; |
| 56 extern const char kTooManyListeners[]; |
| 57 extern const char kUnexpectedDeterminer[]; |
| 49 | 58 |
| 50 } // namespace download_extension_errors | 59 } // namespace download_extension_errors |
| 51 | 60 |
| 52 | 61 |
| 53 class DownloadsDownloadFunction : public AsyncExtensionFunction { | 62 class DownloadsDownloadFunction : public AsyncExtensionFunction { |
| 54 public: | 63 public: |
| 55 DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD) | 64 DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD) |
| 56 DownloadsDownloadFunction(); | 65 DownloadsDownloadFunction(); |
| 57 virtual bool RunImpl() OVERRIDE; | 66 virtual bool RunImpl() OVERRIDE; |
| 58 | 67 |
| 59 protected: | 68 protected: |
| 60 virtual ~DownloadsDownloadFunction(); | 69 virtual ~DownloadsDownloadFunction(); |
| 61 | 70 |
| 62 private: | 71 private: |
| 63 void OnStarted(content::DownloadItem* item, net::Error error); | 72 void OnStarted( |
| 73 const base::FilePath& creator_suggested_filename, |
| 74 extensions::api::downloads::FilenameConflictAction |
| 75 creator_conflict_action, |
| 76 content::DownloadItem* item, |
| 77 net::Error error); |
| 64 | 78 |
| 65 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); | 79 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); |
| 66 }; | 80 }; |
| 67 | 81 |
| 68 class DownloadsSearchFunction : public SyncExtensionFunction { | 82 class DownloadsSearchFunction : public SyncExtensionFunction { |
| 69 public: | 83 public: |
| 70 DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH) | 84 DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH) |
| 71 DownloadsSearchFunction(); | 85 DownloadsSearchFunction(); |
| 72 virtual bool RunImpl() OVERRIDE; | 86 virtual bool RunImpl() OVERRIDE; |
| 73 | 87 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DownloadsEraseFunction(); | 137 DownloadsEraseFunction(); |
| 124 virtual bool RunImpl() OVERRIDE; | 138 virtual bool RunImpl() OVERRIDE; |
| 125 | 139 |
| 126 protected: | 140 protected: |
| 127 virtual ~DownloadsEraseFunction(); | 141 virtual ~DownloadsEraseFunction(); |
| 128 | 142 |
| 129 private: | 143 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); | 144 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); |
| 131 }; | 145 }; |
| 132 | 146 |
| 147 class DownloadsRemoveFileFunction : public AsyncExtensionFunction, |
| 148 public content::DownloadItem::Observer { |
| 149 public: |
| 150 DECLARE_EXTENSION_FUNCTION("downloads.removeFile", DOWNLOADS_REMOVEFILE) |
| 151 DownloadsRemoveFileFunction(); |
| 152 virtual bool RunImpl() OVERRIDE; |
| 153 |
| 154 protected: |
| 155 virtual ~DownloadsRemoveFileFunction(); |
| 156 |
| 157 private: |
| 158 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE; |
| 159 virtual void OnDownloadDestroyed(content::DownloadItem* item) OVERRIDE; |
| 160 |
| 161 content::DownloadItem* item_; |
| 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(DownloadsRemoveFileFunction); |
| 164 }; |
| 165 |
| 133 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { | 166 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { |
| 134 public: | 167 public: |
| 135 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) | 168 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) |
| 136 DownloadsAcceptDangerFunction(); | 169 DownloadsAcceptDangerFunction(); |
| 137 virtual bool RunImpl() OVERRIDE; | 170 virtual bool RunImpl() OVERRIDE; |
| 138 | 171 |
| 139 protected: | 172 protected: |
| 140 virtual ~DownloadsAcceptDangerFunction(); | 173 virtual ~DownloadsAcceptDangerFunction(); |
| 141 void DangerPromptCallback(bool accept, int download_id); | 174 void DangerPromptCallback(int download_id, |
| 175 DownloadDangerPrompt::Action action); |
| 142 | 176 |
| 143 private: | 177 private: |
| 144 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); | 178 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); |
| 145 }; | 179 }; |
| 146 | 180 |
| 147 class DownloadsShowFunction : public AsyncExtensionFunction { | 181 class DownloadsShowFunction : public AsyncExtensionFunction { |
| 148 public: | 182 public: |
| 149 DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW) | 183 DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW) |
| 150 DownloadsShowFunction(); | 184 DownloadsShowFunction(); |
| 151 virtual bool RunImpl() OVERRIDE; | 185 virtual bool RunImpl() OVERRIDE; |
| 152 | 186 |
| 153 protected: | 187 protected: |
| 154 virtual ~DownloadsShowFunction(); | 188 virtual ~DownloadsShowFunction(); |
| 155 | 189 |
| 156 private: | 190 private: |
| 157 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction); | 191 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction); |
| 158 }; | 192 }; |
| 159 | 193 |
| 194 class DownloadsShowDefaultFolderFunction : public AsyncExtensionFunction { |
| 195 public: |
| 196 DECLARE_EXTENSION_FUNCTION( |
| 197 "downloads.showDefaultFolder", DOWNLOADS_SHOWDEFAULTFOLDER) |
| 198 DownloadsShowDefaultFolderFunction(); |
| 199 virtual bool RunImpl() OVERRIDE; |
| 200 |
| 201 protected: |
| 202 virtual ~DownloadsShowDefaultFolderFunction(); |
| 203 |
| 204 private: |
| 205 DISALLOW_COPY_AND_ASSIGN(DownloadsShowDefaultFolderFunction); |
| 206 }; |
| 207 |
| 160 class DownloadsOpenFunction : public SyncExtensionFunction { | 208 class DownloadsOpenFunction : public SyncExtensionFunction { |
| 161 public: | 209 public: |
| 162 DECLARE_EXTENSION_FUNCTION("downloads.open", DOWNLOADS_OPEN) | 210 DECLARE_EXTENSION_FUNCTION("downloads.open", DOWNLOADS_OPEN) |
| 163 DownloadsOpenFunction(); | 211 DownloadsOpenFunction(); |
| 164 virtual bool RunImpl() OVERRIDE; | 212 virtual bool RunImpl() OVERRIDE; |
| 165 | 213 |
| 166 protected: | 214 protected: |
| 167 virtual ~DownloadsOpenFunction(); | 215 virtual ~DownloadsOpenFunction(); |
| 168 | 216 |
| 169 private: | 217 private: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 const extensions::Event::WillDispatchCallback& will_dispatch_callback, | 318 const extensions::Event::WillDispatchCallback& will_dispatch_callback, |
| 271 base::Value* json_arg); | 319 base::Value* json_arg); |
| 272 | 320 |
| 273 Profile* profile_; | 321 Profile* profile_; |
| 274 AllDownloadItemNotifier notifier_; | 322 AllDownloadItemNotifier notifier_; |
| 275 | 323 |
| 276 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 324 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| 277 }; | 325 }; |
| 278 | 326 |
| 279 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 327 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| OLD | NEW |