Index: chrome/browser/extensions/extension_downloads_api.cc |
diff --git a/chrome/browser/extensions/extension_downloads_api.cc b/chrome/browser/extensions/extension_downloads_api.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6e0adf04426bcabb6f1ee31232dccd58947c9c92 |
--- /dev/null |
+++ b/chrome/browser/extensions/extension_downloads_api.cc |
@@ -0,0 +1,111 @@ |
+// 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 "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/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" |
+ |
+bool DownloadsDownloadFunction::RunImpl() { |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options_)); |
+ EXTENSION_FUNCTION_VALIDATE(options_->GetString("url", &url_)); |
Mihai Parparita -not on Chrome
2011/07/28 23:18:29
Key names should be in constants (see extension_tt
benjhayden
2011/08/01 21:43:51
Done.
|
+ if (url_.empty()) { |
Mihai Parparita -not on Chrome
2011/07/28 23:18:29
You can use minLength in the schema file to enforc
benjhayden
2011/08/01 21:43:51
Done.
|
+ error_ = "'url' cannot be empty."; |
+ return false; |
+ } |
+ rdh_ = g_browser_process->resource_dispatcher_host(); |
+ if (rdh_ == NULL) { |
+ error_ = "I'm afraid I can't do that."; |
Mihai Parparita -not on Chrome
2011/07/28 23:18:29
Error names should be in constants. Also, is there
benjhayden
2011/08/01 21:43:51
Punted to a future CL that will use rdh_.
|
+ return false; |
+ } |
+ VLOG(1) << __FUNCTION__ << " " << url_; |
+ products_ = new DictionaryValue(); |
+ result_.reset(products_); |
+ options_->GetString("filename", &filename_); |
Mihai Parparita -not on Chrome
2011/07/28 23:18:29
The pattern for optional keys is to use if (option
benjhayden
2011/08/01 21:43:51
Done.
|
+ options_->GetBoolean("save_as", &save_as_); |
+ options_->GetString("method", &method_); |
+ options_->GetDictionary("headers", &extra_headers_); |
+ options_->GetString("body", &post_body_); |
+ // TODO sanity check method_, extra_headers_, filename_ |
+ dl_man_ = profile()->GetDownloadManager(); |
+ 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_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsSearchFunction::RunImpl() { |
+ DictionaryValue* query_json = NULL; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query_json)); |
+ CHECK(query_json); |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsPauseFunction::RunImpl() { |
+ int dl_id = 0; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id)); |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsResumeFunction::RunImpl() { |
+ int dl_id = 0; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id)); |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsCancelFunction::RunImpl() { |
+ int dl_id = 0; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id)); |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsEraseFunction::RunImpl() { |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsSetDestinationFunction::RunImpl() { |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsAcceptDangerFunction::RunImpl() { |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsShowFunction::RunImpl() { |
+ error_ = "NotImplemented"; |
+ return false; |
+} |
+ |
+bool DownloadsDragFunction::RunImpl() { |
+ error_ = "NotImplemented"; |
+ return false; |
+} |