OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_downloads_api.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" |
| 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/download/download_file_manager.h" |
| 15 #include "chrome/browser/download/download_item.h" |
| 16 #include "chrome/browser/download/download_manager.h" |
| 17 #include "chrome/browser/download/download_util.h" |
| 18 #include "chrome/browser/icon_loader.h" |
| 19 #include "chrome/browser/icon_manager.h" |
| 20 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 21 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 23 #include "content/browser/renderer_host/render_view_host.h" |
| 24 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 25 |
| 26 bool DownloadsDownloadFunction::RunImpl() { |
| 27 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options_)); |
| 28 EXTENSION_FUNCTION_VALIDATE(options_->GetString("url", &url_)); |
| 29 if (url_.empty()) { |
| 30 error_ = "'url' cannot be empty."; |
| 31 return false; |
| 32 } |
| 33 rdh_ = g_browser_process->resource_dispatcher_host(); |
| 34 if (rdh_ == NULL) { |
| 35 error_ = "I'm afraid I can't do that."; |
| 36 return false; |
| 37 } |
| 38 VLOG(1) << __FUNCTION__ << " " << url_; |
| 39 products_ = new DictionaryValue(); |
| 40 result_.reset(products_); |
| 41 options_->GetString("filename", &filename_); |
| 42 options_->GetBoolean("save_as", &save_as_); |
| 43 options_->GetString("method", &method_); |
| 44 options_->GetDictionary("headers", &extra_headers_); |
| 45 options_->GetString("body", &post_body_); |
| 46 // TODO sanity check method_, extra_headers_, filename_ |
| 47 dl_man_ = profile()->GetDownloadManager(); |
| 48 tab_contents_ = BrowserList::GetLastActive()->GetSelectedTabContentsWrapper() |
| 49 ->tab_contents(); |
| 50 resource_context_ = &profile()->GetResourceContext(); |
| 51 render_process_host_id_ = tab_contents_->GetRenderProcessHost()->id(); |
| 52 render_view_host_routing_id_ = tab_contents_->render_view_host() |
| 53 ->routing_id(); |
| 54 VLOG(1) << __FUNCTION__ << " " << url_; |
| 55 error_ = "NotImplemented"; |
| 56 return false; |
| 57 } |
| 58 |
| 59 bool DownloadsSearchFunction::RunImpl() { |
| 60 DictionaryValue* query_json = NULL; |
| 61 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query_json)); |
| 62 CHECK(query_json); |
| 63 error_ = "NotImplemented"; |
| 64 return false; |
| 65 } |
| 66 |
| 67 bool DownloadsPauseFunction::RunImpl() { |
| 68 int dl_id = 0; |
| 69 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id)); |
| 70 error_ = "NotImplemented"; |
| 71 return false; |
| 72 } |
| 73 |
| 74 bool DownloadsResumeFunction::RunImpl() { |
| 75 int dl_id = 0; |
| 76 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id)); |
| 77 error_ = "NotImplemented"; |
| 78 return false; |
| 79 } |
| 80 |
| 81 bool DownloadsCancelFunction::RunImpl() { |
| 82 int dl_id = 0; |
| 83 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &dl_id)); |
| 84 error_ = "NotImplemented"; |
| 85 return false; |
| 86 } |
| 87 |
| 88 bool DownloadsEraseFunction::RunImpl() { |
| 89 error_ = "NotImplemented"; |
| 90 return false; |
| 91 } |
| 92 |
| 93 bool DownloadsSetDestinationFunction::RunImpl() { |
| 94 error_ = "NotImplemented"; |
| 95 return false; |
| 96 } |
| 97 |
| 98 bool DownloadsAcceptDangerFunction::RunImpl() { |
| 99 error_ = "NotImplemented"; |
| 100 return false; |
| 101 } |
| 102 |
| 103 bool DownloadsShowFunction::RunImpl() { |
| 104 error_ = "NotImplemented"; |
| 105 return false; |
| 106 } |
| 107 |
| 108 bool DownloadsDragFunction::RunImpl() { |
| 109 error_ = "NotImplemented"; |
| 110 return false; |
| 111 } |
OLD | NEW |