| 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 kNotImplemented[]; |
| 54 extern const char kNotInProgress[]; |
| 55 extern const char kNotPermittedURL[]; |
| 56 extern const char kNotResumable[]; |
| 57 extern const char kOpenPermission[]; |
| 58 extern const char kTooManyListeners[]; |
| 59 extern const char kUnexpectedDeterminer[]; |
| 49 | 60 |
| 50 } // namespace download_extension_errors | 61 } // namespace download_extension_errors |
| 51 | 62 |
| 52 | 63 |
| 53 class DownloadsDownloadFunction : public AsyncExtensionFunction { | 64 class DownloadsDownloadFunction : public AsyncExtensionFunction { |
| 54 public: | 65 public: |
| 55 DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD) | 66 DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD) |
| 56 DownloadsDownloadFunction(); | 67 DownloadsDownloadFunction(); |
| 57 virtual bool RunImpl() OVERRIDE; | 68 virtual bool RunImpl() OVERRIDE; |
| 58 | 69 |
| 59 protected: | 70 protected: |
| 60 virtual ~DownloadsDownloadFunction(); | 71 virtual ~DownloadsDownloadFunction(); |
| 61 | 72 |
| 62 private: | 73 private: |
| 63 void OnStarted(content::DownloadItem* item, net::Error error); | 74 void OnStarted( |
| 75 const base::FilePath& creator_suggested_filename, |
| 76 extensions::api::downloads::FilenameConflictAction |
| 77 creator_conflict_action, |
| 78 content::DownloadItem* item, |
| 79 net::Error error); |
| 64 | 80 |
| 65 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); | 81 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); |
| 66 }; | 82 }; |
| 67 | 83 |
| 68 class DownloadsSearchFunction : public SyncExtensionFunction { | 84 class DownloadsSearchFunction : public SyncExtensionFunction { |
| 69 public: | 85 public: |
| 70 DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH) | 86 DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH) |
| 71 DownloadsSearchFunction(); | 87 DownloadsSearchFunction(); |
| 72 virtual bool RunImpl() OVERRIDE; | 88 virtual bool RunImpl() OVERRIDE; |
| 73 | 89 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DownloadsEraseFunction(); | 139 DownloadsEraseFunction(); |
| 124 virtual bool RunImpl() OVERRIDE; | 140 virtual bool RunImpl() OVERRIDE; |
| 125 | 141 |
| 126 protected: | 142 protected: |
| 127 virtual ~DownloadsEraseFunction(); | 143 virtual ~DownloadsEraseFunction(); |
| 128 | 144 |
| 129 private: | 145 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); | 146 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); |
| 131 }; | 147 }; |
| 132 | 148 |
| 149 class DownloadsRemoveFileFunction : public AsyncExtensionFunction, |
| 150 public content::DownloadItem::Observer { |
| 151 public: |
| 152 DECLARE_EXTENSION_FUNCTION("downloads.removeFile", DOWNLOADS_REMOVEFILE) |
| 153 DownloadsRemoveFileFunction(); |
| 154 virtual bool RunImpl() OVERRIDE; |
| 155 |
| 156 protected: |
| 157 virtual ~DownloadsRemoveFileFunction(); |
| 158 |
| 159 private: |
| 160 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE; |
| 161 virtual void OnDownloadDestroyed(content::DownloadItem* item) OVERRIDE; |
| 162 |
| 163 content::DownloadItem* item_; |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(DownloadsRemoveFileFunction); |
| 166 }; |
| 167 |
| 133 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { | 168 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { |
| 134 public: | 169 public: |
| 135 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) | 170 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) |
| 136 DownloadsAcceptDangerFunction(); | 171 DownloadsAcceptDangerFunction(); |
| 137 virtual bool RunImpl() OVERRIDE; | 172 virtual bool RunImpl() OVERRIDE; |
| 138 | 173 |
| 139 protected: | 174 protected: |
| 140 virtual ~DownloadsAcceptDangerFunction(); | 175 virtual ~DownloadsAcceptDangerFunction(); |
| 141 void DangerPromptCallback(bool accept, int download_id); | 176 void DangerPromptCallback(int download_id, |
| 177 DownloadDangerPrompt::Action action); |
| 142 | 178 |
| 143 private: | 179 private: |
| 144 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); | 180 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); |
| 145 }; | 181 }; |
| 146 | 182 |
| 147 class DownloadsShowFunction : public AsyncExtensionFunction { | 183 class DownloadsShowFunction : public AsyncExtensionFunction { |
| 148 public: | 184 public: |
| 149 DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW) | 185 DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW) |
| 150 DownloadsShowFunction(); | 186 DownloadsShowFunction(); |
| 151 virtual bool RunImpl() OVERRIDE; | 187 virtual bool RunImpl() OVERRIDE; |
| 152 | 188 |
| 153 protected: | 189 protected: |
| 154 virtual ~DownloadsShowFunction(); | 190 virtual ~DownloadsShowFunction(); |
| 155 | 191 |
| 156 private: | 192 private: |
| 157 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction); | 193 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction); |
| 158 }; | 194 }; |
| 159 | 195 |
| 196 class DownloadsShowDefaultFolderFunction : public AsyncExtensionFunction { |
| 197 public: |
| 198 DECLARE_EXTENSION_FUNCTION( |
| 199 "downloads.showDefaultFolder", DOWNLOADS_SHOWDEFAULTFOLDER) |
| 200 DownloadsShowDefaultFolderFunction(); |
| 201 virtual bool RunImpl() OVERRIDE; |
| 202 |
| 203 protected: |
| 204 virtual ~DownloadsShowDefaultFolderFunction(); |
| 205 |
| 206 private: |
| 207 DISALLOW_COPY_AND_ASSIGN(DownloadsShowDefaultFolderFunction); |
| 208 }; |
| 209 |
| 160 class DownloadsOpenFunction : public SyncExtensionFunction { | 210 class DownloadsOpenFunction : public SyncExtensionFunction { |
| 161 public: | 211 public: |
| 162 DECLARE_EXTENSION_FUNCTION("downloads.open", DOWNLOADS_OPEN) | 212 DECLARE_EXTENSION_FUNCTION("downloads.open", DOWNLOADS_OPEN) |
| 163 DownloadsOpenFunction(); | 213 DownloadsOpenFunction(); |
| 164 virtual bool RunImpl() OVERRIDE; | 214 virtual bool RunImpl() OVERRIDE; |
| 165 | 215 |
| 166 protected: | 216 protected: |
| 167 virtual ~DownloadsOpenFunction(); | 217 virtual ~DownloadsOpenFunction(); |
| 168 | 218 |
| 169 private: | 219 private: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 const extensions::Event::WillDispatchCallback& will_dispatch_callback, | 320 const extensions::Event::WillDispatchCallback& will_dispatch_callback, |
| 271 base::Value* json_arg); | 321 base::Value* json_arg); |
| 272 | 322 |
| 273 Profile* profile_; | 323 Profile* profile_; |
| 274 AllDownloadItemNotifier notifier_; | 324 AllDownloadItemNotifier notifier_; |
| 275 | 325 |
| 276 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 326 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| 277 }; | 327 }; |
| 278 | 328 |
| 279 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 329 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| OLD | NEW |