| 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_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/stl_util.h" | |
| 16 #include "base/string16.h" | 15 #include "base/string16.h" |
| 17 #include "base/values.h" | 16 #include "base/values.h" |
| 18 #include "chrome/browser/extensions/extension_function.h" | 17 #include "chrome/browser/extensions/extension_function.h" |
| 19 #include "content/public/browser/download_id.h" | 18 #include "content/public/browser/download_id.h" |
| 20 #include "content/public/browser/download_item.h" | 19 #include "content/public/browser/download_item.h" |
| 21 #include "content/public/browser/download_manager.h" | 20 #include "content/public/browser/download_manager.h" |
| 22 | 21 |
| 23 class DownloadFileIconExtractor; | 22 class DownloadFileIconExtractor; |
| 24 class DownloadQuery; | 23 class DownloadQuery; |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 class ResourceContext; | 26 class ResourceContext; |
| 28 class ResourceDispatcherHost; | 27 class ResourceDispatcherHost; |
| 29 } | 28 } |
| 30 | 29 |
| 31 // Functions in the chrome.experimental.downloads namespace facilitate | 30 // Functions in the chrome.downloads namespace facilitate |
| 32 // controlling downloads from extensions. See the full API doc at | 31 // controlling downloads from extensions. See the full API doc at |
| 33 // http://goo.gl/6hO1n | 32 // http://goo.gl/6hO1n |
| 34 | 33 |
| 35 namespace download_extension_errors { | 34 namespace download_extension_errors { |
| 36 | 35 |
| 37 // Errors that can be returned through chrome.extension.lastError.message. | 36 // Errors that can be returned through chrome.extension.lastError.message. |
| 38 extern const char kGenericError[]; | 37 extern const char kGenericError[]; |
| 39 extern const char kIconNotFoundError[]; | 38 extern const char kIconNotFoundError[]; |
| 40 extern const char kInvalidDangerTypeError[]; | 39 extern const char kInvalidDangerTypeError[]; |
| 41 extern const char kInvalidFilterError[]; | 40 extern const char kInvalidFilterError[]; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 content::DownloadItem* GetActiveItem(int download_id); | 115 content::DownloadItem* GetActiveItem(int download_id); |
| 117 | 116 |
| 118 private: | 117 private: |
| 119 DownloadsFunctionName function_; | 118 DownloadsFunctionName function_; |
| 120 | 119 |
| 121 DISALLOW_COPY_AND_ASSIGN(AsyncDownloadsFunction); | 120 DISALLOW_COPY_AND_ASSIGN(AsyncDownloadsFunction); |
| 122 }; | 121 }; |
| 123 | 122 |
| 124 class DownloadsDownloadFunction : public AsyncDownloadsFunction { | 123 class DownloadsDownloadFunction : public AsyncDownloadsFunction { |
| 125 public: | 124 public: |
| 126 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.download"); | 125 DECLARE_EXTENSION_FUNCTION_NAME("downloads.download"); |
| 127 | 126 |
| 128 DownloadsDownloadFunction(); | 127 DownloadsDownloadFunction(); |
| 129 | 128 |
| 130 protected: | 129 protected: |
| 131 virtual ~DownloadsDownloadFunction(); | 130 virtual ~DownloadsDownloadFunction(); |
| 132 | 131 |
| 133 // DownloadsFunctionInterface: | 132 // DownloadsFunctionInterface: |
| 134 virtual bool ParseArgs() OVERRIDE; | 133 virtual bool ParseArgs() OVERRIDE; |
| 135 virtual bool RunInternal() OVERRIDE; | 134 virtual bool RunInternal() OVERRIDE; |
| 136 | 135 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 155 void BeginDownloadOnIOThread(); | 154 void BeginDownloadOnIOThread(); |
| 156 void OnStarted(content::DownloadId dl_id, net::Error error); | 155 void OnStarted(content::DownloadId dl_id, net::Error error); |
| 157 | 156 |
| 158 scoped_ptr<IOData> iodata_; | 157 scoped_ptr<IOData> iodata_; |
| 159 | 158 |
| 160 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); | 159 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); |
| 161 }; | 160 }; |
| 162 | 161 |
| 163 class DownloadsSearchFunction : public SyncDownloadsFunction { | 162 class DownloadsSearchFunction : public SyncDownloadsFunction { |
| 164 public: | 163 public: |
| 165 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.search"); | 164 DECLARE_EXTENSION_FUNCTION_NAME("downloads.search"); |
| 166 | 165 |
| 167 DownloadsSearchFunction(); | 166 DownloadsSearchFunction(); |
| 168 | 167 |
| 169 protected: | 168 protected: |
| 170 virtual ~DownloadsSearchFunction(); | 169 virtual ~DownloadsSearchFunction(); |
| 171 | 170 |
| 172 // DownloadsFunctionInterface: | 171 // DownloadsFunctionInterface: |
| 173 virtual bool ParseArgs() OVERRIDE; | 172 virtual bool ParseArgs() OVERRIDE; |
| 174 virtual bool RunInternal() OVERRIDE; | 173 virtual bool RunInternal() OVERRIDE; |
| 175 | 174 |
| 176 private: | 175 private: |
| 177 bool ParseOrderBy(const base::Value& order_by_value); | 176 bool ParseOrderBy(const base::Value& order_by_value); |
| 178 | 177 |
| 179 scoped_ptr<DownloadQuery> query_; | 178 scoped_ptr<DownloadQuery> query_; |
| 180 int get_id_; | 179 int get_id_; |
| 181 bool has_get_id_; | 180 bool has_get_id_; |
| 182 | 181 |
| 183 DISALLOW_COPY_AND_ASSIGN(DownloadsSearchFunction); | 182 DISALLOW_COPY_AND_ASSIGN(DownloadsSearchFunction); |
| 184 }; | 183 }; |
| 185 | 184 |
| 186 class DownloadsPauseFunction : public SyncDownloadsFunction { | 185 class DownloadsPauseFunction : public SyncDownloadsFunction { |
| 187 public: | 186 public: |
| 188 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.pause"); | 187 DECLARE_EXTENSION_FUNCTION_NAME("downloads.pause"); |
| 189 | 188 |
| 190 DownloadsPauseFunction(); | 189 DownloadsPauseFunction(); |
| 191 | 190 |
| 192 protected: | 191 protected: |
| 193 virtual ~DownloadsPauseFunction(); | 192 virtual ~DownloadsPauseFunction(); |
| 194 | 193 |
| 195 // DownloadsFunctionInterface: | 194 // DownloadsFunctionInterface: |
| 196 virtual bool ParseArgs() OVERRIDE; | 195 virtual bool ParseArgs() OVERRIDE; |
| 197 virtual bool RunInternal() OVERRIDE; | 196 virtual bool RunInternal() OVERRIDE; |
| 198 | 197 |
| 199 private: | 198 private: |
| 200 int download_id_; | 199 int download_id_; |
| 201 DISALLOW_COPY_AND_ASSIGN(DownloadsPauseFunction); | 200 DISALLOW_COPY_AND_ASSIGN(DownloadsPauseFunction); |
| 202 }; | 201 }; |
| 203 | 202 |
| 204 class DownloadsResumeFunction : public SyncDownloadsFunction { | 203 class DownloadsResumeFunction : public SyncDownloadsFunction { |
| 205 public: | 204 public: |
| 206 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.resume"); | 205 DECLARE_EXTENSION_FUNCTION_NAME("downloads.resume"); |
| 207 | 206 |
| 208 DownloadsResumeFunction(); | 207 DownloadsResumeFunction(); |
| 209 | 208 |
| 210 protected: | 209 protected: |
| 211 virtual ~DownloadsResumeFunction(); | 210 virtual ~DownloadsResumeFunction(); |
| 212 | 211 |
| 213 // DownloadsFunctionInterface: | 212 // DownloadsFunctionInterface: |
| 214 virtual bool ParseArgs() OVERRIDE; | 213 virtual bool ParseArgs() OVERRIDE; |
| 215 virtual bool RunInternal() OVERRIDE; | 214 virtual bool RunInternal() OVERRIDE; |
| 216 | 215 |
| 217 private: | 216 private: |
| 218 int download_id_; | 217 int download_id_; |
| 219 DISALLOW_COPY_AND_ASSIGN(DownloadsResumeFunction); | 218 DISALLOW_COPY_AND_ASSIGN(DownloadsResumeFunction); |
| 220 }; | 219 }; |
| 221 | 220 |
| 222 class DownloadsCancelFunction : public SyncDownloadsFunction { | 221 class DownloadsCancelFunction : public SyncDownloadsFunction { |
| 223 public: | 222 public: |
| 224 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.cancel"); | 223 DECLARE_EXTENSION_FUNCTION_NAME("downloads.cancel"); |
| 225 | 224 |
| 226 DownloadsCancelFunction(); | 225 DownloadsCancelFunction(); |
| 227 | 226 |
| 228 protected: | 227 protected: |
| 229 virtual ~DownloadsCancelFunction(); | 228 virtual ~DownloadsCancelFunction(); |
| 230 | 229 |
| 231 // DownloadsFunctionInterface: | 230 // DownloadsFunctionInterface: |
| 232 virtual bool ParseArgs() OVERRIDE; | 231 virtual bool ParseArgs() OVERRIDE; |
| 233 virtual bool RunInternal() OVERRIDE; | 232 virtual bool RunInternal() OVERRIDE; |
| 234 | 233 |
| 235 private: | 234 private: |
| 236 int download_id_; | 235 int download_id_; |
| 237 DISALLOW_COPY_AND_ASSIGN(DownloadsCancelFunction); | 236 DISALLOW_COPY_AND_ASSIGN(DownloadsCancelFunction); |
| 238 }; | 237 }; |
| 239 | 238 |
| 240 class DownloadsEraseFunction : public AsyncDownloadsFunction { | 239 class DownloadsEraseFunction : public AsyncDownloadsFunction { |
| 241 public: | 240 public: |
| 242 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.erase"); | 241 DECLARE_EXTENSION_FUNCTION_NAME("downloads.erase"); |
| 243 | 242 |
| 244 DownloadsEraseFunction(); | 243 DownloadsEraseFunction(); |
| 245 | 244 |
| 246 protected: | 245 protected: |
| 247 virtual ~DownloadsEraseFunction(); | 246 virtual ~DownloadsEraseFunction(); |
| 248 | 247 |
| 249 // DownloadsFunctionInterface: | 248 // DownloadsFunctionInterface: |
| 250 virtual bool ParseArgs() OVERRIDE; | 249 virtual bool ParseArgs() OVERRIDE; |
| 251 virtual bool RunInternal() OVERRIDE; | 250 virtual bool RunInternal() OVERRIDE; |
| 252 | 251 |
| 253 private: | 252 private: |
| 254 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); | 253 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); |
| 255 }; | 254 }; |
| 256 | 255 |
| 257 class DownloadsSetDestinationFunction : public AsyncDownloadsFunction { | 256 class DownloadsSetDestinationFunction : public AsyncDownloadsFunction { |
| 258 public: | 257 public: |
| 259 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.setDestination"); | 258 DECLARE_EXTENSION_FUNCTION_NAME("downloads.setDestination"); |
| 260 | 259 |
| 261 DownloadsSetDestinationFunction(); | 260 DownloadsSetDestinationFunction(); |
| 262 | 261 |
| 263 protected: | 262 protected: |
| 264 virtual ~DownloadsSetDestinationFunction(); | 263 virtual ~DownloadsSetDestinationFunction(); |
| 265 | 264 |
| 266 // DownloadsFunctionInterface: | 265 // DownloadsFunctionInterface: |
| 267 virtual bool ParseArgs() OVERRIDE; | 266 virtual bool ParseArgs() OVERRIDE; |
| 268 virtual bool RunInternal() OVERRIDE; | 267 virtual bool RunInternal() OVERRIDE; |
| 269 | 268 |
| 270 private: | 269 private: |
| 271 DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction); | 270 DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction); |
| 272 }; | 271 }; |
| 273 | 272 |
| 274 class DownloadsAcceptDangerFunction : public AsyncDownloadsFunction { | 273 class DownloadsAcceptDangerFunction : public AsyncDownloadsFunction { |
| 275 public: | 274 public: |
| 276 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.acceptDanger"); | 275 DECLARE_EXTENSION_FUNCTION_NAME("downloads.acceptDanger"); |
| 277 | 276 |
| 278 DownloadsAcceptDangerFunction(); | 277 DownloadsAcceptDangerFunction(); |
| 279 | 278 |
| 280 protected: | 279 protected: |
| 281 virtual ~DownloadsAcceptDangerFunction(); | 280 virtual ~DownloadsAcceptDangerFunction(); |
| 282 | 281 |
| 283 // DownloadsFunctionInterface: | 282 // DownloadsFunctionInterface: |
| 284 virtual bool ParseArgs() OVERRIDE; | 283 virtual bool ParseArgs() OVERRIDE; |
| 285 virtual bool RunInternal() OVERRIDE; | 284 virtual bool RunInternal() OVERRIDE; |
| 286 | 285 |
| 287 private: | 286 private: |
| 288 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); | 287 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); |
| 289 }; | 288 }; |
| 290 | 289 |
| 291 class DownloadsShowFunction : public AsyncDownloadsFunction { | 290 class DownloadsShowFunction : public AsyncDownloadsFunction { |
| 292 public: | 291 public: |
| 293 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.show"); | 292 DECLARE_EXTENSION_FUNCTION_NAME("downloads.show"); |
| 294 | 293 |
| 295 DownloadsShowFunction(); | 294 DownloadsShowFunction(); |
| 296 | 295 |
| 297 protected: | 296 protected: |
| 298 virtual ~DownloadsShowFunction(); | 297 virtual ~DownloadsShowFunction(); |
| 299 | 298 |
| 300 // DownloadsFunctionInterface: | 299 // DownloadsFunctionInterface: |
| 301 virtual bool ParseArgs() OVERRIDE; | 300 virtual bool ParseArgs() OVERRIDE; |
| 302 virtual bool RunInternal() OVERRIDE; | 301 virtual bool RunInternal() OVERRIDE; |
| 303 | 302 |
| 304 private: | 303 private: |
| 305 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction); | 304 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction); |
| 306 }; | 305 }; |
| 307 | 306 |
| 308 class DownloadsDragFunction : public AsyncDownloadsFunction { | 307 class DownloadsDragFunction : public AsyncDownloadsFunction { |
| 309 public: | 308 public: |
| 310 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.drag"); | 309 DECLARE_EXTENSION_FUNCTION_NAME("downloads.drag"); |
| 311 | 310 |
| 312 DownloadsDragFunction(); | 311 DownloadsDragFunction(); |
| 313 | 312 |
| 314 protected: | 313 protected: |
| 315 virtual ~DownloadsDragFunction(); | 314 virtual ~DownloadsDragFunction(); |
| 316 | 315 |
| 317 // DownloadsFunctionInterface: | 316 // DownloadsFunctionInterface: |
| 318 virtual bool ParseArgs() OVERRIDE; | 317 virtual bool ParseArgs() OVERRIDE; |
| 319 virtual bool RunInternal() OVERRIDE; | 318 virtual bool RunInternal() OVERRIDE; |
| 320 | 319 |
| 321 private: | 320 private: |
| 322 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction); | 321 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction); |
| 323 }; | 322 }; |
| 324 | 323 |
| 325 class DownloadsGetFileIconFunction : public AsyncDownloadsFunction { | 324 class DownloadsGetFileIconFunction : public AsyncDownloadsFunction { |
| 326 public: | 325 public: |
| 327 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.getFileIcon"); | 326 DECLARE_EXTENSION_FUNCTION_NAME("downloads.getFileIcon"); |
| 328 | 327 |
| 329 DownloadsGetFileIconFunction(); | 328 DownloadsGetFileIconFunction(); |
| 330 void SetIconExtractorForTesting(DownloadFileIconExtractor* extractor); | 329 void SetIconExtractorForTesting(DownloadFileIconExtractor* extractor); |
| 331 | 330 |
| 332 protected: | 331 protected: |
| 333 virtual ~DownloadsGetFileIconFunction(); | 332 virtual ~DownloadsGetFileIconFunction(); |
| 334 | 333 |
| 335 // DownloadsFunctionInterface: | 334 // DownloadsFunctionInterface: |
| 336 virtual bool ParseArgs() OVERRIDE; | 335 virtual bool ParseArgs() OVERRIDE; |
| 337 virtual bool RunInternal() OVERRIDE; | 336 virtual bool RunInternal() OVERRIDE; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; | 368 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; |
| 370 typedef std::map<int, OnChangedStat*> OnChangedStatMap; | 369 typedef std::map<int, OnChangedStat*> OnChangedStatMap; |
| 371 | 370 |
| 372 void Init(content::DownloadManager* manager); | 371 void Init(content::DownloadManager* manager); |
| 373 void DispatchEvent(const char* event_name, base::Value* json_arg); | 372 void DispatchEvent(const char* event_name, base::Value* json_arg); |
| 374 | 373 |
| 375 Profile* profile_; | 374 Profile* profile_; |
| 376 content::DownloadManager* manager_; | 375 content::DownloadManager* manager_; |
| 377 ItemMap downloads_; | 376 ItemMap downloads_; |
| 378 ItemJsonMap item_jsons_; | 377 ItemJsonMap item_jsons_; |
| 379 STLValueDeleter<ItemJsonMap> delete_item_jsons_; | |
| 380 OnChangedStatMap on_changed_stats_; | 378 OnChangedStatMap on_changed_stats_; |
| 381 STLValueDeleter<OnChangedStatMap> delete_on_changed_stats_; | |
| 382 | 379 |
| 383 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 380 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| 384 }; | 381 }; |
| 385 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ | 382 |
| 383 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| OLD | NEW |