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 CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ | 6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" |
17 #include "content/public/browser/download_interrupt_reasons.h" | 18 #include "content/public/browser/download_interrupt_reasons.h" |
18 #include "content/public/browser/download_save_info.h" | 19 #include "content/public/browser/download_save_info.h" |
19 #include "content/public/common/referrer.h" | 20 #include "content/public/common/referrer.h" |
| 21 #include "net/url_request/url_request_context_getter.h" |
20 #include "storage/browser/blob/blob_data_handle.h" | 22 #include "storage/browser/blob/blob_data_handle.h" |
21 #include "url/gurl.h" | 23 #include "url/gurl.h" |
22 | 24 |
23 namespace content { | 25 namespace content { |
24 | 26 |
25 class DownloadItem; | 27 class DownloadItem; |
26 class ResourceContext; | |
27 class ResourceDispatcherHost; | 28 class ResourceDispatcherHost; |
28 class WebContents; | 29 class WebContents; |
29 | 30 |
30 // Pass an instance of DownloadUrlParameters to DownloadManager::DownloadUrl() | 31 // Pass an instance of DownloadUrlParameters to DownloadManager::DownloadUrl() |
31 // to download the content at |url|. All parameters with setters are optional. | 32 // to download the content at |url|. All parameters with setters are optional. |
32 // |referrer| and |referrer_encoding| are the referrer for the download. If | 33 // |referrer| and |referrer_encoding| are the referrer for the download. If |
33 // |prefer_cache| is true, then if the response to |url| is in the HTTP cache it | 34 // |prefer_cache| is true, then if the response to |url| is in the HTTP cache it |
34 // will be used without revalidation. If |post_id| is non-negative, then it | 35 // will be used without revalidation. If |post_id| is non-negative, then it |
35 // identifies the post transaction used to originally retrieve the |url| | 36 // identifies the post transaction used to originally retrieve the |url| |
36 // resource - it also requires |prefer_cache| to be |true| since re-post'ing is | 37 // resource - it also requires |prefer_cache| to be |true| since re-post'ing is |
(...skipping 17 matching lines...) Expand all Loading... |
54 // download request. I.e. the download triggered a warning of some sort and | 55 // download request. I.e. the download triggered a warning of some sort and |
55 // the user chose to not to proceed with the download as a result. | 56 // the user chose to not to proceed with the download as a result. |
56 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)> | 57 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)> |
57 OnStartedCallback; | 58 OnStartedCallback; |
58 | 59 |
59 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair; | 60 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair; |
60 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType; | 61 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType; |
61 | 62 |
62 // Construct DownloadUrlParameters for downloading the resource at |url| and | 63 // Construct DownloadUrlParameters for downloading the resource at |url| and |
63 // associating the download with |web_contents|. | 64 // associating the download with |web_contents|. |
| 65 // |
| 66 // DEPRECATED: Using this method can cause the request to be associated with |
| 67 // the wrong site instance where multiple iframes are involved. Use the |
| 68 // DownloadUrlParameters constructor below and specify the process and frame |
| 69 // IDs explicitly. |
64 static std::unique_ptr<DownloadUrlParameters> FromWebContents( | 70 static std::unique_ptr<DownloadUrlParameters> FromWebContents( |
65 WebContents* web_contents, | 71 WebContents* web_contents, |
66 const GURL& url); | 72 const GURL& url); |
67 | 73 |
68 // Construct DownloadUrlParameters for downloading the resource at |url| and | 74 // Construct DownloadUrlParameters for downloading the resource at |url| and |
69 // associating the download with the WebContents identified by | 75 // associating the download with the WebContents identified by |
70 // |render_process_host_id| and |render_view_host_routing_id|. | 76 // |render_process_host_id| and |render_view_host_routing_id|. |
71 // | 77 // |
72 // If the download is not associated with a WebContents, then set the IDs to | 78 // If the download is not associated with a WebContents, then set the IDs to |
73 // -1. | 79 // -1. |
74 // NOTE: This is not safe and should only be done in a limited set of cases | 80 // |
75 // where the download URL has been previously vetted. A download that's | 81 // NOTE: Initiating downloads that are not associated with a WebContents is |
76 // initiated without associating it with a WebContents don't receive the same | 82 // not safe and should only be done in a limited set of cases where the |
77 // security checks as a request that's associated with one. Hence, downloads | 83 // download URL has been previously vetted. A download that's initiated |
78 // that are not associated with a WebContents should only be made for URLs | 84 // without associating it with a WebContents don't receive the same security |
79 // that are either trusted or URLs that have previously been successfully | 85 // checks as a request that's associated with one. Hence, downloads that are |
80 // issued using a non-privileged WebContents. | 86 // not associated with a WebContents should only be made for URLs that are |
81 DownloadUrlParameters(const GURL& url, | 87 // either trusted or URLs that have previously been successfully issued using |
82 int render_process_host_id, | 88 // a non-privileged WebContents. |
83 int render_view_host_routing_id, | 89 DownloadUrlParameters( |
84 int render_frame_host_routing_id, | 90 const GURL& url, |
85 ResourceContext* resource_context); | 91 int render_process_host_id, |
| 92 int render_view_host_routing_id, |
| 93 int render_frame_host_routing_id, |
| 94 net::URLRequestContextGetter* url_request_context_getter); |
86 | 95 |
87 ~DownloadUrlParameters(); | 96 ~DownloadUrlParameters(); |
88 | 97 |
89 // Should be set to true if the download was initiated by a script or a web | 98 // Should be set to true if the download was initiated by a script or a web |
90 // page. I.e. if the download request cannot be attributed to an explicit user | 99 // page. I.e. if the download request cannot be attributed to an explicit user |
91 // request for a download, then set this value to true. | 100 // request for a download, then set this value to true. |
92 void set_content_initiated(bool content_initiated) { | 101 void set_content_initiated(bool content_initiated) { |
93 content_initiated_ = content_initiated; | 102 content_initiated_ = content_initiated; |
94 } | 103 } |
95 void add_request_header(const std::string& name, const std::string& value) { | 104 void add_request_header(const std::string& name, const std::string& value) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 const Referrer& referrer() const { return referrer_; } | 215 const Referrer& referrer() const { return referrer_; } |
207 const std::string& referrer_encoding() const { return referrer_encoding_; } | 216 const std::string& referrer_encoding() const { return referrer_encoding_; } |
208 int render_process_host_id() const { return render_process_host_id_; } | 217 int render_process_host_id() const { return render_process_host_id_; } |
209 int render_view_host_routing_id() const { | 218 int render_view_host_routing_id() const { |
210 return render_view_host_routing_id_; | 219 return render_view_host_routing_id_; |
211 } | 220 } |
212 int render_frame_host_routing_id() const { | 221 int render_frame_host_routing_id() const { |
213 return render_frame_host_routing_id_; | 222 return render_frame_host_routing_id_; |
214 } | 223 } |
215 const RequestHeadersType& request_headers() const { return request_headers_; } | 224 const RequestHeadersType& request_headers() const { return request_headers_; } |
216 ResourceContext* resource_context() const { return resource_context_; } | 225 net::URLRequestContextGetter* url_request_context_getter() { |
| 226 return url_request_context_getter_.get(); |
| 227 } |
217 const base::FilePath& file_path() const { return save_info_.file_path; } | 228 const base::FilePath& file_path() const { return save_info_.file_path; } |
218 const base::string16& suggested_name() const { | 229 const base::string16& suggested_name() const { |
219 return save_info_.suggested_name; | 230 return save_info_.suggested_name; |
220 } | 231 } |
221 int64_t offset() const { return save_info_.offset; } | 232 int64_t offset() const { return save_info_.offset; } |
222 const std::string& hash_of_partial_file() const { | 233 const std::string& hash_of_partial_file() const { |
223 return save_info_.hash_of_partial_file; | 234 return save_info_.hash_of_partial_file; |
224 } | 235 } |
225 bool prompt() const { return save_info_.prompt_for_save_location; } | 236 bool prompt() const { return save_info_.prompt_for_save_location; } |
226 const GURL& url() const { return url_; } | 237 const GURL& url() const { return url_; } |
(...skipping 16 matching lines...) Expand all Loading... |
243 std::string etag_; | 254 std::string etag_; |
244 std::string method_; | 255 std::string method_; |
245 std::string post_body_; | 256 std::string post_body_; |
246 int64_t post_id_; | 257 int64_t post_id_; |
247 bool prefer_cache_; | 258 bool prefer_cache_; |
248 Referrer referrer_; | 259 Referrer referrer_; |
249 std::string referrer_encoding_; | 260 std::string referrer_encoding_; |
250 int render_process_host_id_; | 261 int render_process_host_id_; |
251 int render_view_host_routing_id_; | 262 int render_view_host_routing_id_; |
252 int render_frame_host_routing_id_; | 263 int render_frame_host_routing_id_; |
253 ResourceContext* resource_context_; | 264 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
254 DownloadSaveInfo save_info_; | 265 DownloadSaveInfo save_info_; |
255 GURL url_; | 266 GURL url_; |
256 bool do_not_prompt_for_login_; | 267 bool do_not_prompt_for_login_; |
257 std::unique_ptr<storage::BlobDataHandle> blob_data_handle_; | 268 std::unique_ptr<storage::BlobDataHandle> blob_data_handle_; |
258 | 269 |
259 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); | 270 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); |
260 }; | 271 }; |
261 | 272 |
262 } // namespace content | 273 } // namespace content |
263 | 274 |
264 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ | 275 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
OLD | NEW |