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