| 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_id.h" | 20 #include "content/public/browser/download_id.h" |
| 20 #include "content/public/browser/download_item.h" | 21 #include "content/public/browser/download_item.h" |
| 21 #include "content/public/browser/download_manager.h" | 22 #include "content/public/browser/download_manager.h" |
| 22 | 23 |
| 23 class DownloadFileIconExtractor; | 24 class DownloadFileIconExtractor; |
| 24 class DownloadQuery; | 25 class DownloadQuery; |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 class ResourceContext; | 28 class ResourceContext; |
| 28 class ResourceDispatcherHost; | 29 class ResourceDispatcherHost; |
| 29 } | 30 } |
| 30 | 31 |
| 31 // Functions in the chrome.downloads namespace facilitate | 32 // Functions in the chrome.downloads namespace facilitate |
| 32 // controlling downloads from extensions. See the full API doc at | 33 // controlling downloads from extensions. See the full API doc at |
| 33 // http://goo.gl/6hO1n | 34 // http://goo.gl/6hO1n |
| 34 | 35 |
| 35 namespace download_extension_errors { | 36 namespace download_extension_errors { |
| 36 | 37 |
| 37 // Errors that can be returned through chrome.runtime.lastError.message. | 38 // Errors that can be returned through chrome.runtime.lastError.message. |
| 38 extern const char kGenericError[]; | |
| 39 extern const char kIconNotFoundError[]; | 39 extern const char kIconNotFoundError[]; |
| 40 extern const char kInvalidDangerTypeError[]; | 40 extern const char kInvalidDangerTypeError[]; |
| 41 extern const char kInvalidFilenameError[]; | 41 extern const char kInvalidFilenameError[]; |
| 42 extern const char kInvalidFilterError[]; | 42 extern const char kInvalidFilterError[]; |
| 43 extern const char kInvalidHeaderError[]; |
| 43 extern const char kInvalidOperationError[]; | 44 extern const char kInvalidOperationError[]; |
| 44 extern const char kInvalidOrderByError[]; | 45 extern const char kInvalidOrderByError[]; |
| 45 extern const char kInvalidQueryLimit[]; | 46 extern const char kInvalidQueryLimit[]; |
| 46 extern const char kInvalidStateError[]; | 47 extern const char kInvalidStateError[]; |
| 47 extern const char kInvalidURLError[]; | 48 extern const char kInvalidURLError[]; |
| 49 extern const char kNotPermittedURLError[]; |
| 48 extern const char kNotImplementedError[]; | 50 extern const char kNotImplementedError[]; |
| 49 extern const char kTooManyListenersError[]; | 51 extern const char kTooManyListenersError[]; |
| 50 | 52 |
| 51 } // namespace download_extension_errors | 53 } // namespace download_extension_errors |
| 52 | 54 |
| 53 | 55 |
| 54 class DownloadsDownloadFunction : public AsyncExtensionFunction { | 56 class DownloadsDownloadFunction : public AsyncExtensionFunction { |
| 55 public: | 57 public: |
| 56 DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD) | 58 DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD) |
| 57 DownloadsDownloadFunction(); | 59 DownloadsDownloadFunction(); |
| 58 virtual bool RunImpl() OVERRIDE; | 60 virtual bool RunImpl() OVERRIDE; |
| 59 | 61 |
| 60 protected: | 62 protected: |
| 61 virtual ~DownloadsDownloadFunction(); | 63 virtual ~DownloadsDownloadFunction(); |
| 62 | 64 |
| 63 private: | 65 private: |
| 64 void OnStarted(content::DownloadItem* item, net::Error error); | 66 void OnStarted( |
| 67 const base::FilePath& creator_suggested_filename, |
| 68 extensions::api::downloads::FilenameConflictAction |
| 69 creator_conflict_action, |
| 70 content::DownloadItem* item, |
| 71 net::Error error); |
| 65 | 72 |
| 66 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); | 73 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); |
| 67 }; | 74 }; |
| 68 | 75 |
| 69 class DownloadsSearchFunction : public SyncExtensionFunction { | 76 class DownloadsSearchFunction : public SyncExtensionFunction { |
| 70 public: | 77 public: |
| 71 DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH) | 78 DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH) |
| 72 DownloadsSearchFunction(); | 79 DownloadsSearchFunction(); |
| 73 virtual bool RunImpl() OVERRIDE; | 80 virtual bool RunImpl() OVERRIDE; |
| 74 | 81 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 DownloadsEraseFunction(); | 131 DownloadsEraseFunction(); |
| 125 virtual bool RunImpl() OVERRIDE; | 132 virtual bool RunImpl() OVERRIDE; |
| 126 | 133 |
| 127 protected: | 134 protected: |
| 128 virtual ~DownloadsEraseFunction(); | 135 virtual ~DownloadsEraseFunction(); |
| 129 | 136 |
| 130 private: | 137 private: |
| 131 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); | 138 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); |
| 132 }; | 139 }; |
| 133 | 140 |
| 141 class DownloadsDeleteFileFunction : public AsyncExtensionFunction { |
| 142 public: |
| 143 DECLARE_EXTENSION_FUNCTION("downloads.deleteFile", DOWNLOADS_DELETEFILE) |
| 144 DownloadsDeleteFileFunction(); |
| 145 virtual bool RunImpl() OVERRIDE; |
| 146 |
| 147 protected: |
| 148 virtual ~DownloadsDeleteFileFunction(); |
| 149 |
| 150 private: |
| 151 void DeleteOnFileThread(const base::FilePath& path); |
| 152 void RespondOnUIThread(); |
| 153 DISALLOW_COPY_AND_ASSIGN(DownloadsDeleteFileFunction); |
| 154 }; |
| 155 |
| 134 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { | 156 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { |
| 135 public: | 157 public: |
| 136 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) | 158 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) |
| 137 DownloadsAcceptDangerFunction(); | 159 DownloadsAcceptDangerFunction(); |
| 138 virtual bool RunImpl() OVERRIDE; | 160 virtual bool RunImpl() OVERRIDE; |
| 139 | 161 |
| 140 protected: | 162 protected: |
| 141 virtual ~DownloadsAcceptDangerFunction(); | 163 virtual ~DownloadsAcceptDangerFunction(); |
| 142 void DangerPromptCallback(bool accept, int download_id); | 164 void DangerPromptCallback(int download_id, |
| 165 DownloadDangerPrompt::Action action); |
| 143 | 166 |
| 144 private: | 167 private: |
| 145 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); | 168 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); |
| 146 }; | 169 }; |
| 147 | 170 |
| 148 class DownloadsShowFunction : public AsyncExtensionFunction { | 171 class DownloadsShowFunction : public AsyncExtensionFunction { |
| 149 public: | 172 public: |
| 150 DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW) | 173 DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW) |
| 151 DownloadsShowFunction(); | 174 DownloadsShowFunction(); |
| 152 virtual bool RunImpl() OVERRIDE; | 175 virtual bool RunImpl() OVERRIDE; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 177 DownloadsDragFunction(); | 200 DownloadsDragFunction(); |
| 178 virtual bool RunImpl() OVERRIDE; | 201 virtual bool RunImpl() OVERRIDE; |
| 179 | 202 |
| 180 protected: | 203 protected: |
| 181 virtual ~DownloadsDragFunction(); | 204 virtual ~DownloadsDragFunction(); |
| 182 | 205 |
| 183 private: | 206 private: |
| 184 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction); | 207 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction); |
| 185 }; | 208 }; |
| 186 | 209 |
| 210 class DownloadsSetShelfVisibleFunction : public SyncExtensionFunction { |
| 211 public: |
| 212 DECLARE_EXTENSION_FUNCTION("downloads.setShelfVisible", |
| 213 DOWNLOADS_SETSHELFVISIBLE) |
| 214 DownloadsSetShelfVisibleFunction(); |
| 215 virtual bool RunImpl() OVERRIDE; |
| 216 |
| 217 protected: |
| 218 virtual ~DownloadsSetShelfVisibleFunction(); |
| 219 |
| 220 private: |
| 221 DISALLOW_COPY_AND_ASSIGN(DownloadsSetShelfVisibleFunction); |
| 222 }; |
| 223 |
| 187 class DownloadsGetFileIconFunction : public AsyncExtensionFunction { | 224 class DownloadsGetFileIconFunction : public AsyncExtensionFunction { |
| 188 public: | 225 public: |
| 189 DECLARE_EXTENSION_FUNCTION("downloads.getFileIcon", DOWNLOADS_GETFILEICON) | 226 DECLARE_EXTENSION_FUNCTION("downloads.getFileIcon", DOWNLOADS_GETFILEICON) |
| 190 DownloadsGetFileIconFunction(); | 227 DownloadsGetFileIconFunction(); |
| 191 virtual bool RunImpl() OVERRIDE; | 228 virtual bool RunImpl() OVERRIDE; |
| 192 void SetIconExtractorForTesting(DownloadFileIconExtractor* extractor); | 229 void SetIconExtractorForTesting(DownloadFileIconExtractor* extractor); |
| 193 | 230 |
| 194 protected: | 231 protected: |
| 195 virtual ~DownloadsGetFileIconFunction(); | 232 virtual ~DownloadsGetFileIconFunction(); |
| 196 | 233 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 const extensions::Event::WillDispatchCallback& will_dispatch_callback, | 308 const extensions::Event::WillDispatchCallback& will_dispatch_callback, |
| 272 base::Value* json_arg); | 309 base::Value* json_arg); |
| 273 | 310 |
| 274 Profile* profile_; | 311 Profile* profile_; |
| 275 AllDownloadItemNotifier notifier_; | 312 AllDownloadItemNotifier notifier_; |
| 276 | 313 |
| 277 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 314 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| 278 }; | 315 }; |
| 279 | 316 |
| 280 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 317 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| OLD | NEW |