summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbenjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-15 16:17:12 +0000
committerbenjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-15 16:17:12 +0000
commit21d7a4e30d89fd4e2e334c70125770e5c7836071 (patch)
treef15992601ef9ec3be0a6932dcc2edc782a2571d1
parente7f370383f2b16a25d91e27987edfd3d432ba12b (diff)
downloadchromium_src-21d7a4e30d89fd4e2e334c70125770e5c7836071.zip
chromium_src-21d7a4e30d89fd4e2e334c70125770e5c7836071.tar.gz
chromium_src-21d7a4e30d89fd4e2e334c70125770e5c7836071.tar.bz2
chrome.experimental.downloads stubs
http://goo.gl/6hO1n Future CLs will contain implementations for the functions and events. BUG= TEST= Review URL: http://codereview.chromium.org/7480046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96778 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_downloads_api.cc168
-rw-r--r--chrome/browser/extensions/extension_downloads_api.h162
-rw-r--r--chrome/browser/extensions/extension_downloads_api_constants.cc18
-rw-r--r--chrome/browser/extensions/extension_downloads_api_constants.h22
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc13
-rw-r--r--chrome/chrome_browser.gypi4
-rw-r--r--chrome/common/extensions/api/extension_api.json531
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js3
-rw-r--r--chrome/renderer/resources/renderer_extension_bindings.js1
9 files changed, 922 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_downloads_api.cc b/chrome/browser/extensions/extension_downloads_api.cc
new file mode 100644
index 0000000..ae76bdc
--- /dev/null
+++ b/chrome/browser/extensions/extension_downloads_api.cc
@@ -0,0 +1,168 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/extension_downloads_api.h"
+
+#include <algorithm>
+#include <string>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/stl_util.h"
+#include "base/values.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_file_manager.h"
+#include "chrome/browser/download/download_item.h"
+#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/download/download_util.h"
+#include "chrome/browser/extensions/extension_downloads_api_constants.h"
+#include "chrome/browser/icon_loader.h"
+#include "chrome/browser/icon_manager.h"
+#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "content/browser/renderer_host/render_view_host.h"
+#include "content/browser/renderer_host/resource_dispatcher_host.h"
+
+namespace constants = extension_downloads_api_constants;
+
+DownloadsDownloadFunction::DownloadsDownloadFunction()
+ : save_as_(false),
+ extra_headers_(NULL),
+ rdh_(NULL),
+ resource_context_(NULL),
+ render_process_host_id_(0),
+ render_view_host_routing_id_(0) {
+}
+DownloadsDownloadFunction::~DownloadsDownloadFunction() {}
+
+bool DownloadsDownloadFunction::RunImpl() {
+ base::DictionaryValue* options = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options));
+ EXTENSION_FUNCTION_VALIDATE(options->GetString(constants::kUrlKey, &url_));
+ if (options->HasKey(constants::kFilenameKey))
+ EXTENSION_FUNCTION_VALIDATE(options->GetString(
+ constants::kFilenameKey, &filename_));
+ if (options->HasKey(constants::kSaveAsKey))
+ EXTENSION_FUNCTION_VALIDATE(options->GetBoolean(
+ constants::kSaveAsKey, &save_as_));
+ if (options->HasKey(constants::kMethodKey))
+ EXTENSION_FUNCTION_VALIDATE(options->GetString(
+ constants::kMethodKey, &method_));
+ if (options->HasKey(constants::kHeadersKey))
+ EXTENSION_FUNCTION_VALIDATE(options->GetDictionary(
+ constants::kHeadersKey, &extra_headers_));
+ if (options->HasKey(constants::kBodyKey))
+ EXTENSION_FUNCTION_VALIDATE(options->GetString(
+ constants::kBodyKey, &post_body_));
+ rdh_ = g_browser_process->resource_dispatcher_host();
+ TabContents* tab_contents = BrowserList::GetLastActive()
+ ->GetSelectedTabContentsWrapper()->tab_contents();
+ resource_context_ = &profile()->GetResourceContext();
+ render_process_host_id_ = tab_contents->GetRenderProcessHost()->id();
+ render_view_host_routing_id_ = tab_contents->render_view_host()
+ ->routing_id();
+ VLOG(1) << __FUNCTION__ << " " << url_;
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsSearchFunction::DownloadsSearchFunction() {}
+DownloadsSearchFunction::~DownloadsSearchFunction() {}
+
+bool DownloadsSearchFunction::RunImpl() {
+ DictionaryValue* query_json = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query_json));
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsPauseFunction::DownloadsPauseFunction() {}
+DownloadsPauseFunction::~DownloadsPauseFunction() {}
+
+bool DownloadsPauseFunction::RunImpl() {
+ int dl_id = 0;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id));
+ VLOG(1) << __FUNCTION__ << " " << dl_id;
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsResumeFunction::DownloadsResumeFunction() {}
+DownloadsResumeFunction::~DownloadsResumeFunction() {}
+
+bool DownloadsResumeFunction::RunImpl() {
+ int dl_id = 0;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id));
+ VLOG(1) << __FUNCTION__ << " " << dl_id;
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsCancelFunction::DownloadsCancelFunction() {}
+DownloadsCancelFunction::~DownloadsCancelFunction() {}
+
+bool DownloadsCancelFunction::RunImpl() {
+ int dl_id = 0;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id));
+ VLOG(1) << __FUNCTION__ << " " << dl_id;
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsEraseFunction::DownloadsEraseFunction() {}
+DownloadsEraseFunction::~DownloadsEraseFunction() {}
+
+bool DownloadsEraseFunction::RunImpl() {
+ DictionaryValue* query_json = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query_json));
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsSetDestinationFunction::DownloadsSetDestinationFunction() {}
+DownloadsSetDestinationFunction::~DownloadsSetDestinationFunction() {}
+
+bool DownloadsSetDestinationFunction::RunImpl() {
+ int dl_id = 0;
+ std::string path;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &path));
+ VLOG(1) << __FUNCTION__ << " " << dl_id << " " << &path;
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {}
+DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {}
+
+bool DownloadsAcceptDangerFunction::RunImpl() {
+ int dl_id = 0;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id));
+ VLOG(1) << __FUNCTION__ << " " << dl_id;
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsShowFunction::DownloadsShowFunction() {}
+DownloadsShowFunction::~DownloadsShowFunction() {}
+
+bool DownloadsShowFunction::RunImpl() {
+ int dl_id = 0;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id));
+ VLOG(1) << __FUNCTION__ << " " << dl_id;
+ error_ = constants::kNotImplemented;
+ return false;
+}
+
+DownloadsDragFunction::DownloadsDragFunction() {}
+DownloadsDragFunction::~DownloadsDragFunction() {}
+
+bool DownloadsDragFunction::RunImpl() {
+ int dl_id = 0;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id));
+ VLOG(1) << __FUNCTION__ << " " << dl_id;
+ error_ = constants::kNotImplemented;
+ return false;
+}
diff --git a/chrome/browser/extensions/extension_downloads_api.h b/chrome/browser/extensions/extension_downloads_api.h
new file mode 100644
index 0000000..0865d69
--- /dev/null
+++ b/chrome/browser/extensions/extension_downloads_api.h
@@ -0,0 +1,162 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
+#pragma once
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/download/download_item.h"
+#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/extensions/extension_function.h"
+
+namespace base {
+class DictionaryValue;
+}
+class ResourceDispatcherHost;
+class TabContents;
+namespace content {
+class ResourceContext;
+}
+
+// Functions in the chrome.experimental.downloads namespace facilitate
+// controlling downloads from extensions. See the full API doc at
+// http://goo.gl/6hO1n
+
+class DownloadsDownloadFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsDownloadFunction();
+ virtual ~DownloadsDownloadFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.download");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ std::string url_;
+ std::string filename_;
+ bool save_as_;
+ base::DictionaryValue* extra_headers_;
+ std::string method_;
+ std::string post_body_;
+
+ ResourceDispatcherHost* rdh_;
+ const content::ResourceContext* resource_context_;
+ int render_process_host_id_;
+ int render_view_host_routing_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction);
+};
+
+class DownloadsSearchFunction : public SyncExtensionFunction {
+ public:
+ DownloadsSearchFunction();
+ virtual ~DownloadsSearchFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.search");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsSearchFunction);
+};
+
+class DownloadsPauseFunction : public SyncExtensionFunction {
+ public:
+ DownloadsPauseFunction();
+ virtual ~DownloadsPauseFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.pause");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsPauseFunction);
+};
+
+class DownloadsResumeFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsResumeFunction();
+ virtual ~DownloadsResumeFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.resume");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsResumeFunction);
+};
+
+class DownloadsCancelFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsCancelFunction();
+ virtual ~DownloadsCancelFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.cancel");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsCancelFunction);
+};
+
+class DownloadsEraseFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsEraseFunction();
+ virtual ~DownloadsEraseFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.erase");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction);
+};
+
+class DownloadsSetDestinationFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsSetDestinationFunction();
+ virtual ~DownloadsSetDestinationFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.setDestination");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction);
+};
+
+class DownloadsAcceptDangerFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsAcceptDangerFunction();
+ virtual ~DownloadsAcceptDangerFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.acceptDanger");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction);
+};
+
+class DownloadsShowFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsShowFunction();
+ virtual ~DownloadsShowFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.show");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction);
+};
+
+class DownloadsDragFunction : public AsyncExtensionFunction {
+ public:
+ DownloadsDragFunction();
+ virtual ~DownloadsDragFunction();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.drag");
+
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction);
+};
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
diff --git a/chrome/browser/extensions/extension_downloads_api_constants.cc b/chrome/browser/extensions/extension_downloads_api_constants.cc
new file mode 100644
index 0000000..2836fee
--- /dev/null
+++ b/chrome/browser/extensions/extension_downloads_api_constants.cc
@@ -0,0 +1,18 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/extension_downloads_api_constants.h"
+
+namespace extension_downloads_api_constants {
+
+const char kNotImplemented[] = "NotImplemented";
+const char kGenericError[] = "I'm afraid I can't do that.";
+const char kUrlKey[] = "url";
+const char kFilenameKey[] = "filename";
+const char kSaveAsKey[] = "saveAs";
+const char kMethodKey[] = "method";
+const char kHeadersKey[] = "headers";
+const char kBodyKey[] = "body";
+
+} // namespace extension_downloads_api_constants
diff --git a/chrome/browser/extensions/extension_downloads_api_constants.h b/chrome/browser/extensions/extension_downloads_api_constants.h
new file mode 100644
index 0000000..a676060
--- /dev/null
+++ b/chrome/browser/extensions/extension_downloads_api_constants.h
@@ -0,0 +1,22 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_CONSTANTS_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_CONSTANTS_H_
+#pragma once
+
+namespace extension_downloads_api_constants {
+
+extern const char kNotImplemented[];
+extern const char kGenericError[];
+extern const char kUrlKey[];
+extern const char kFilenameKey[];
+extern const char kSaveAsKey[];
+extern const char kMethodKey[];
+extern const char kHeadersKey[];
+extern const char kBodyKey[];
+
+} // namespace extension_downloads_api_constants
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_CONSTANTS_H_
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index c98fe43..9bba97e4 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/extensions/extension_context_menu_api.h"
#include "chrome/browser/extensions/extension_cookies_api.h"
#include "chrome/browser/extensions/extension_debugger_api.h"
+#include "chrome/browser/extensions/extension_downloads_api.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/extensions/extension_history_api.h"
#include "chrome/browser/extensions/extension_i18n_api.h"
@@ -421,6 +422,18 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<GetAllPermissionsFunction>();
RegisterFunction<RemovePermissionsFunction>();
RegisterFunction<RequestPermissionsFunction>();
+
+ // Downloads
+ RegisterFunction<DownloadsDownloadFunction>();
+ RegisterFunction<DownloadsSearchFunction>();
+ RegisterFunction<DownloadsPauseFunction>();
+ RegisterFunction<DownloadsResumeFunction>();
+ RegisterFunction<DownloadsCancelFunction>();
+ RegisterFunction<DownloadsEraseFunction>();
+ RegisterFunction<DownloadsSetDestinationFunction>();
+ RegisterFunction<DownloadsAcceptDangerFunction>();
+ RegisterFunction<DownloadsShowFunction>();
+ RegisterFunction<DownloadsDragFunction>();
}
void FactoryRegistry::GetAllNames(std::vector<std::string>* names) {
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 076be2e..74c8a4e 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -961,6 +961,10 @@
'browser/extensions/extension_devtools_manager.h',
'browser/extensions/extension_disabled_infobar_delegate.cc',
'browser/extensions/extension_disabled_infobar_delegate.h',
+ 'browser/extensions/extension_downloads_api.cc',
+ 'browser/extensions/extension_downloads_api.h',
+ 'browser/extensions/extension_downloads_api_constants.cc',
+ 'browser/extensions/extension_downloads_api_constants.h',
'browser/extensions/extension_error_reporter.cc',
'browser/extensions/extension_error_reporter.h',
'browser/extensions/extension_event_names.cc',
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index 1dc410d..a32a78c 100644
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -3818,6 +3818,537 @@
]
},
{
+ "namespace": "experimental.downloads",
+ "nodoc": "true",
+ "events": [
+ {
+ "name": "onCreated",
+ "type": "function",
+ "unprivileged": true,
+ "description": "This event fires with the DownloadItem object when a download begins.",
+ "parameters": [
+ {"$ref": "DownloadItem"}
+ ]
+ },
+ {
+ "name": "onChanged",
+ "type": "function",
+ "unprivileged": true,
+ "description": "When any of a DownloadItem's properties except |bytesReceived| changes, this event fires with the download id and an object containing the properties that changed.",
+ "parameters": [
+ {"$ref": "DownloadDelta"}
+ ]
+ },
+ {
+ "name": "onErased",
+ "type": "function",
+ "unprivileged": true,
+ "description": "Fires with the download id when a download is erased from history.",
+ "parameters": [
+ {"type": "integer", "name": "downloadId"}
+ ]
+ }
+ ],
+ "properties": {
+ "STATE_IN_PROGRESS": {
+ "type": "string",
+ "value": "in_progress",
+ "description": "The download is currently receiving data from the server."
+ },
+ "STATE_INTERRUPTED": {
+ "type": "string",
+ "value": "interrupted",
+ "description": "An error broke the connection with the file host."
+ },
+ "STATE_COMPLETE": {
+ "type": "string",
+ "value": "complete",
+ "description": "The download has completed."
+ },
+ "DANGER_SAFE": {
+ "type": "string",
+ "value": "safe",
+ "description": "The file has been determined to present no known danger to the user's computer."
+ },
+ "DANGER_FILE": {
+ "type": "string",
+ "value": "file",
+ "description": "The download's filename is suspicious."
+ },
+ "DANGER_URL": {
+ "type": "string",
+ "value": "url",
+ "description": "The download's URL is suspicious."
+ }
+ },
+ "types": [
+ {
+ "id": "DownloadItem",
+ "type": "object",
+ "description": "The state of a file as it is downloaded from the internet.",
+ "properties": {
+ "id": {
+ "type": "integer",
+ "description": "An identifier that is persistent across browser sessions."
+ },
+ "url": {
+ "type": "string",
+ "description": "absolute URL"
+ },
+ "filename": {
+ "type": "string",
+ "description": "absolute local path"
+ },
+ "danger": {
+ "type": "string",
+ "description": "Indication of whether this download is thought to be safe or known to be suspicious.",
+ "enum": ["safe", "file", "url"],
+ "optional": true
+ },
+ "dangerAccepted": {
+ "type": "boolean",
+ "description": "true if the user has accepted the download's danger."
+ },
+ "mime": {
+ "type": "string",
+ "description": "The file's MIME type."
+ },
+ "startTime": {
+ "type": "integer",
+ "description": "Number of milliseconds between the unix epoch and when this download began."
+ },
+ "endTime": {
+ "type": "integer",
+ "description": "Number of milliseconds between the unix epoch and when this download ended.",
+ "optional": true
+ },
+ "state": {
+ "type": "string",
+ "description": "Indicates whether the download is progressing, interrupted, or complete.",
+ "enum": ["in_progress", "complete", "interrupted"]
+ },
+ "paused": {
+ "type": "boolean",
+ "description": "true if the download has stopped reading data from the host, but kept the connection open."
+ },
+ "error": {
+ "type": "integer",
+ "description": "Number indicating why a download was interrupted.",
+ "optional": true
+ },
+ "bytesReceived": {
+ "type": "integer",
+ "description": "Number of bytes received so far from the host, without considering file compression."
+ },
+ "totalBytes": {
+ "type": "integer",
+ "description": "Number of bytes in the whole file, without considering file compression, or -1 if unknown."
+ },
+ "fileSize": {
+ "type": "integer",
+ "description": "Number of bytes in the whole file post-decompression, or -1 if unknown."
+ }
+ }
+ },
+ {
+ "id": "DownloadOptions",
+ "type": "object",
+ "properties": {
+ "url": {
+ "type": "string",
+ "description": "The URL to download.",
+ "minLength": 1
+ },
+ "filename": {
+ "type": "string",
+ "description": "A file path relative to the Downloads directory to contain the downloaded file.",
+ "optional": true
+ },
+ "saveAs": {
+ "type": "boolean",
+ "optional": true,
+ "description": "Use a file-chooser to allow the user to select a filename."
+ },
+ "method": {
+ "type": "string",
+ "description": "The HTTP method to use if the URL uses the HTTP[S] protocol.",
+ "optional": true,
+ "enum": ["GET", "POST"]
+ },
+ "headers": {
+ "$ref": "HttpHeaders",
+ "description": "Extra HTTP headers to send with the request if the URL uses the HTTP[s] protocol, restricted to those allowed by XMLHttpRequest.",
+ "optional": true
+ },
+ "body": {
+ "type": "string",
+ "description": "post body",
+ "optional": true
+ }
+ }
+ },
+ {
+ "id": "DownloadQuery",
+ "type": "object",
+ "description": "",
+ "properties": {
+ "query": {
+ "type": "string",
+ "description": "This space-separated string of search terms that may be grouped using quotation marks limits results to downloads whose filename or url contain all of the search terms that do not begin with a dash ‘-’ and none of the search terms that do begin with a dash.",
+ "optional": true
+ },
+ "startedBefore": {
+ "type": "integer",
+ "description": "Limits results to downloads that started before the given ms since the epoch.",
+ "optional": true
+ },
+ "startedAfter": {
+ "type": "integer",
+ "description": "Limits results to downloads that started after the given ms since the epoch.",
+ "optional": true
+ },
+ "endedBefore": {
+ "type": "integer",
+ "description": "Limits results to downloads that ended before the given ms since the epoch.",
+ "optional": true
+ },
+ "endedAfter": {
+ "type": "integer",
+ "description": "Limits results to downloads that ended after the given ms since the epoch.",
+ "optional": true
+ },
+ "totalBytesGreater": {
+ "type": "integer",
+ "description": "Limits results to downloads whose totalBytes is greater than the given integer.",
+ "optional": true
+ },
+ "totalBytesLess": {
+ "type": "integer",
+ "description": "Limits results to downloads whose totalBytes is less than the given integer.",
+ "optional": true
+ },
+ "filenameRegex": {
+ "type": "string",
+ "description": "Limits results to downloads whose filename matches the given regular expression.",
+ "optional": true
+ },
+ "urlRegex": {
+ "type": "string",
+ "description": "Limits results to downloads whose url matches the given regular expression.",
+ "optional": true
+ },
+ "limit": {
+ "type": "integer",
+ "optional": true,
+ "description": "Setting this integer limits the number of results. Otherwise, all matching DownloadItems will be returned."
+ },
+ "orderBy": {
+ "type": "string",
+ "optional": true,
+ "description": "Setting this string to a DownloadItem property sorts the DownloadItems prior to applying the above filters. For example, setting |orderBy|=”startTime” sorts the DownloadItems by their start time in ascending order. To specify descending order, prefix |orderBy| with a hyphen: “-startTime”."
+ },
+ "id": {
+ "type": "integer",
+ "optional": true,
+ "description": "An identifier that is persistent across browser sessions."
+ },
+ "url": {
+ "type": "string",
+ "optional": true,
+ "description": "absolute URL"
+ },
+ "filename": {
+ "type": "string",
+ "optional": true,
+ "description": "absolute local path"
+ },
+ "danger": {
+ "type": "string",
+ "description": "Indication of whether this download is thought to be safe or known to be suspicious.",
+ "enum": ["safe", "file", "url"],
+ "optional": true
+ },
+ "dangerAccepted": {
+ "type": "boolean",
+ "optional": true,
+ "description": "true if the user has accepted the download's danger."
+ },
+ "mime": {
+ "type": "string",
+ "optional": true,
+ "description": "The file's MIME type."
+ },
+ "startTime": {
+ "type": "integer",
+ "optional": true,
+ "description": "Number of milliseconds between the unix epoch and when this download began."
+ },
+ "endTime": {
+ "type": "integer",
+ "description": "Number of milliseconds between the unix epoch and when this download ended.",
+ "optional": true
+ },
+ "state": {
+ "type": "string",
+ "optional": true,
+ "description": "Indicates whether the download is progressing, interrupted, or complete.",
+ "enum": ["in_progress", "complete", "interrupted"]
+ },
+ "paused": {
+ "type": "boolean",
+ "optional": true,
+ "description": "true if the download has stopped reading data from the host, but kept the connection open."
+ },
+ "error": {
+ "type": "integer",
+ "description": "Number indicating why a download was interrupted.",
+ "optional": true
+ },
+ "bytesReceived": {
+ "type": "integer",
+ "optional": true,
+ "description": "Number of bytes received so far from the host, without considering file compression."
+ },
+ "totalBytes": {
+ "type": "integer",
+ "optional": true,
+ "description": "Number of bytes in the whole file, without considering file compression, or -1 if unknown."
+ },
+ "fileSize": {
+ "type": "integer",
+ "optional": true,
+ "description": "Number of bytes in the whole file post-decompression, or -1 if unknown."
+ }
+ }
+ },
+ {
+ "id": "DownloadBooleanDiff",
+ "type": "object",
+ "description": "Encapsulates a change in a boolean DownloadItem field.",
+ "properties": {
+ "old": {
+ "type": "boolean",
+ "optional": true
+ },
+ "new": {
+ "type": "boolean",
+ "optional": true
+ }
+ }
+ },
+ {
+ "id": "DownloadIntegerDiff",
+ "type": "object",
+ "description": "Encapsulates a change in an integer DownloadItem field.",
+ "properties": {
+ "old": {
+ "type": "integer",
+ "optional": true
+ },
+ "new": {
+ "type": "integer",
+ "optional": true
+ }
+ }
+ },
+ {
+ "id": "DownloadStringDiff",
+ "type": "object",
+ "description": "Encapsulates a change in a string DownloadItem field.",
+ "properties": {
+ "old": {
+ "type": "string",
+ "optional": true
+ },
+ "new": {
+ "type": "string",
+ "optional": true
+ }
+ }
+ },
+ {
+ "id": "DownloadDelta",
+ "type": "object",
+ "description": "Encapsulates a change in a DownloadItem.",
+ "properties": {
+ "id": {
+ "type": "integer",
+ "description": "An identifier that is persistent across browser sessions."
+ },
+ "url": {
+ "$ref": "DownloadStringDiff",
+ "optional": true
+ },
+ "filename": {
+ "$ref": "DownloadStringDiff",
+ "optional": true
+ },
+ "danger": {
+ "$ref": "DownloadStringDiff",
+ "optional": true
+ },
+ "dangerAccepted": {
+ "$ref": "DownloadBooleanDiff",
+ "optional": true
+ },
+ "mime": {
+ "$ref": "DownloadStringDiff",
+ "optional": true
+ },
+ "startTime": {
+ "$ref": "DownloadIntegerDiff",
+ "optional": true
+ },
+ "endTime": {
+ "$ref": "DownloadIntegerDiff",
+ "optional": true
+ },
+ "state": {
+ "$ref": "DownloadStringDiff",
+ "optional": true
+ },
+ "paused": {
+ "$ref": "DownloadBooleanDiff",
+ "optional": true
+ },
+ "error": {
+ "$ref": "DownloadIntegerDiff",
+ "optional": true
+ },
+ "bytesReceived": {
+ "$ref": "DownloadIntegerDiff",
+ "optional": true
+ },
+ "totalBytes": {
+ "$ref": "DownloadIntegerDiff",
+ "optional": true
+ },
+ "fileSize": {
+ "$ref": "DownloadIntegerDiff",
+ "optional": true
+ }
+ }
+ },
+ {
+ "id": "DownloadResponse",
+ "type": "object",
+ "nodoc": true,
+ "description": "This object is transformed into two callback parameters for the callback to download().",
+ "properties": {
+ "id": {"type": "integer", "optional": true},
+ "error": {"type": "integer", "optional": true}
+ }
+ }
+ ],
+ "functions": [
+ {
+ "name": "download",
+ "type": "function",
+ "description": "Download a URL. If the URL uses the HTTP[S] protocol, then the request will include all cookies currently set for its hostname. If the download started successfully, |callback| will be called with the new DownloadItem’s |id| and |error|=undefined. If there was an error starting the download, then |callback| will be called with |downloadId|=undefined and an |error| code integer. If the URL’s hostname is not specified in the |permissions| section of the extension’s manifest, then the |error| object will indicate that the extension does not have permission to access that hostname.",
+ "parameters": [
+ {"$ref": "DownloadOptions"},
+ {
+ "name": "callback",
+ "type": "function",
+ "optional": true,
+ "parameters": [
+ {"$ref": "DownloadResponse"}
+ ]
+ }
+ ]
+ },
+ {
+ "name": "search",
+ "type": "function",
+ "description": "Find DownloadItems. Set |query| to the empty object to get all DownloadItems. To get a specific DownloadItem, set only the |id| field.",
+ "parameters": [
+ {"$ref": "DownloadQuery"},
+ {
+ "name": "callback",
+ "type": "function",
+ "optional": true,
+ "parameters": [
+ {"name": "items", "type": "array"}
+ ]
+ }
+ ]
+ },
+ {
+ "name": "erase",
+ "type": "function",
+ "description": "Erase matching DownloadItems from history",
+ "parameters": [
+ {"$ref": "DownloadQuery"},
+ {
+ "name": "callback",
+ "type": "function",
+ "optional": true,
+ "parameters": [
+ {"name": "ids", "type": "array"}
+ ]
+ }
+ ]
+ },
+ {
+ "name": "setDestination",
+ "type": "function",
+ "description": "Move the file to Downloads/relativePath instead of the Downloads directory if it has completed and pass true to callback. If |relativePath| specifies a directory that does not exist then it will be created. If it has not completed, store |relativePath| such that the file will be moved there when it completes and pass true to callback without waiting for the download to complete. Does nothing if the download is cancelled or if |downloadId| does not reference an existing DownloadItem, but pass false to callback. If the file could not be moved, then the DownloadItem will transition to STATE_INTERRUPTED, its |error| property will be set accordingly, false will be passed to callback, and the OnChanged event will fire.",
+ "parameters": [
+ {"name": "id", "type": "integer"},
+ {"name": "relativePath", "type": "string"}
+ ]
+ },
+ {
+ "name": "acceptDanger",
+ "type": "function",
+ "description": "Accept a dangerous download. If a download is dangerous, then it will not transition to the completed state until this function is called.",
+ "parameters": [
+ {"name": "id", "type": "integer"}
+ ]
+ },
+ {
+ "name": "show",
+ "type": "function",
+ "description": "Show the downloaded file in its folder.",
+ "parameters": [
+ {"name": "id", "type": "integer"}
+ ]
+ },
+ {
+ "name": "drag",
+ "type": "function",
+ "description": "Drag the file to another application",
+ "parameters": [
+ {"name": "id", "type": "integer"}
+ ]
+ },
+ {
+ "name": "pause",
+ "type": "function",
+ "description": "Pause the download.",
+ "parameters": [
+ {"name": "id", "type": "integer"}
+ ]
+ },
+ {
+ "name": "resume",
+ "type": "function",
+ "description": "Resume a paused download.",
+ "parameters": [
+ {"name": "id", "type": "integer"}
+ ]
+ },
+ {
+ "name": "cancel",
+ "type": "function",
+ "description": "Cancel a download.",
+ "parameters": [
+ {"name": "id", "type": "integer"}
+ ]
+ }
+ ]
+ },
+ {
"namespace": "devtools",
"nodoc": "true",
"types": [],
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js
index d24cd67..9c95f43 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -1052,4 +1052,7 @@ var chrome = chrome || {};
if (!chrome.ttsEngine)
chrome.ttsEngine = {};
+
+ if (!chrome.experimental.downloads)
+ chrome.experimental.downloads = {};
})();
diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js
index 7a53e49..b9811c1 100644
--- a/chrome/renderer/resources/renderer_extension_bindings.js
+++ b/chrome/renderer/resources/renderer_extension_bindings.js
@@ -306,6 +306,7 @@ var chrome = chrome || {};
"experimental.bookmarkManager",
"experimental.contentSettings",
"experimental.debugger",
+ "experimental.downloads",
"experimental.extension",
"experimental.infobars",
"experimental.input",