Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / public / browser / download_url_parameters.h
blob275088d07f735e65c768b3eb416a5f759a00ca3c
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_
6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "content/public/browser/download_interrupt_reasons.h"
15 #include "content/public/browser/download_save_info.h"
16 #include "content/public/common/referrer.h"
17 #include "url/gurl.h"
19 namespace content {
21 class DownloadItem;
22 class ResourceContext;
23 class ResourceDispatcherHost;
24 class WebContents;
26 // Pass an instance of DownloadUrlParameters to DownloadManager::DownloadUrl()
27 // to download the content at |url|. All parameters with setters are optional.
28 // |referrer| and |referrer_encoding| are the referrer for the download. If
29 // |prefer_cache| is true, then if the response to |url| is in the HTTP cache it
30 // will be used without revalidation. If |post_id| is non-negative, then it
31 // identifies the post transaction used to originally retrieve the |url|
32 // resource - it also requires |prefer_cache| to be |true| since re-post'ing is
33 // not done. |save_info| specifies where the downloaded file should be saved,
34 // and whether the user should be prompted about the download. If not null,
35 // |callback| will be called when the download starts, or if an error occurs
36 // that prevents a download item from being created. We send a pointer to
37 // content::ResourceContext instead of the usual reference so that a copy of the
38 // object isn't made.
40 class CONTENT_EXPORT DownloadUrlParameters {
41 public:
42 // If there is an error, then |item| will be nullptr.
43 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)>
44 OnStartedCallback;
46 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair;
47 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType;
49 static scoped_ptr<DownloadUrlParameters> FromWebContents(
50 WebContents* web_contents,
51 const GURL& url);
53 DownloadUrlParameters(
54 const GURL& url,
55 int render_process_host_id,
56 int render_view_host_routing_id,
57 int render_frame_host_routing_id,
58 content::ResourceContext* resource_context);
60 ~DownloadUrlParameters();
62 void set_content_initiated(bool content_initiated) {
63 content_initiated_ = content_initiated;
65 void add_request_header(const std::string& name, const std::string& value) {
66 request_headers_.push_back(make_pair(name, value));
68 void set_referrer(const Referrer& referrer) { referrer_ = referrer; }
69 void set_referrer_encoding(const std::string& referrer_encoding) {
70 referrer_encoding_ = referrer_encoding;
72 void set_last_modified(const std::string& last_modified) {
73 last_modified_ = last_modified;
75 void set_etag(const std::string& etag) {
76 etag_ = etag;
78 void set_method(const std::string& method) {
79 method_ = method;
81 void set_post_body(const std::string& post_body) {
82 post_body_ = post_body;
84 void set_prefer_cache(bool prefer_cache) {
85 prefer_cache_ = prefer_cache;
87 void set_post_id(int64 post_id) { post_id_ = post_id; }
88 void set_callback(const OnStartedCallback& callback) {
89 callback_ = callback;
91 void set_file_path(const base::FilePath& file_path) {
92 save_info_.file_path = file_path;
94 void set_suggested_name(const base::string16& suggested_name) {
95 save_info_.suggested_name = suggested_name;
97 void set_offset(int64 offset) { save_info_.offset = offset; }
98 void set_hash_state(std::string hash_state) {
99 save_info_.hash_state = hash_state;
101 void set_prompt(bool prompt) { save_info_.prompt_for_save_location = prompt; }
102 void set_file(base::File file) {
103 save_info_.file = file.Pass();
105 void set_do_not_prompt_for_login(bool do_not_prompt) {
106 do_not_prompt_for_login_ = do_not_prompt;
109 const OnStartedCallback& callback() const { return callback_; }
110 bool content_initiated() const { return content_initiated_; }
111 const std::string& last_modified() const { return last_modified_; }
112 const std::string& etag() const { return etag_; }
113 const std::string& method() const { return method_; }
114 const std::string& post_body() const { return post_body_; }
115 int64 post_id() const { return post_id_; }
116 bool prefer_cache() const { return prefer_cache_; }
117 const Referrer& referrer() const { return referrer_; }
118 const std::string& referrer_encoding() const { return referrer_encoding_; }
119 int render_process_host_id() const { return render_process_host_id_; }
120 int render_view_host_routing_id() const {
121 return render_view_host_routing_id_;
123 int render_frame_host_routing_id() const {
124 return render_frame_host_routing_id_;
126 RequestHeadersType::const_iterator request_headers_begin() const {
127 return request_headers_.begin();
129 RequestHeadersType::const_iterator request_headers_end() const {
130 return request_headers_.end();
132 content::ResourceContext* resource_context() const {
133 return resource_context_;
135 const base::FilePath& file_path() const { return save_info_.file_path; }
136 const base::string16& suggested_name() const {
137 return save_info_.suggested_name;
139 int64 offset() const { return save_info_.offset; }
140 const std::string& hash_state() const { return save_info_.hash_state; }
141 bool prompt() const { return save_info_.prompt_for_save_location; }
142 const GURL& url() const { return url_; }
143 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; }
145 // Note that this is state changing--the DownloadUrlParameters object
146 // will not have a file attached to it after this call.
147 base::File GetFile() { return save_info_.file.Pass(); }
149 private:
150 OnStartedCallback callback_;
151 bool content_initiated_;
152 RequestHeadersType request_headers_;
153 std::string last_modified_;
154 std::string etag_;
155 std::string method_;
156 std::string post_body_;
157 int64 post_id_;
158 bool prefer_cache_;
159 Referrer referrer_;
160 std::string referrer_encoding_;
161 int render_process_host_id_;
162 int render_view_host_routing_id_;
163 int render_frame_host_routing_id_;
164 ResourceContext* resource_context_;
165 DownloadSaveInfo save_info_;
166 GURL url_;
167 bool do_not_prompt_for_login_;
169 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters);
172 } // namespace content
174 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_