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 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 23 matching lines...) Expand all Loading... | |
34 // resource - it also requires |prefer_cache| to be |true| since re-post'ing is | 34 // resource - it also requires |prefer_cache| to be |true| since re-post'ing is |
35 // not done. |save_info| specifies where the downloaded file should be saved, | 35 // not done. |save_info| specifies where the downloaded file should be saved, |
36 // and whether the user should be prompted about the download. If not null, | 36 // and whether the user should be prompted about the download. If not null, |
37 // |callback| will be called when the download starts, or if an error occurs | 37 // |callback| will be called when the download starts, or if an error occurs |
38 // that prevents a download item from being created. We send a pointer to | 38 // that prevents a download item from being created. We send a pointer to |
39 // content::ResourceContext instead of the usual reference so that a copy of the | 39 // content::ResourceContext instead of the usual reference so that a copy of the |
40 // object isn't made. | 40 // object isn't made. |
41 | 41 |
42 class CONTENT_EXPORT DownloadUrlParameters { | 42 class CONTENT_EXPORT DownloadUrlParameters { |
43 public: | 43 public: |
44 // If there is an error, then |item| will be nullptr. | 44 // Used with set_callback() below. |
45 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)> | 45 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)> |
46 OnStartedCallback; | 46 OnStartedCallback; |
47 | 47 |
48 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair; | 48 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair; |
49 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType; | 49 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType; |
50 | 50 |
51 // Construct DownloadUrlParameters for downloading the resource at |url| and | |
52 // associating the download with |web_contents|. | |
51 static scoped_ptr<DownloadUrlParameters> FromWebContents( | 53 static scoped_ptr<DownloadUrlParameters> FromWebContents( |
52 WebContents* web_contents, | 54 WebContents* web_contents, |
53 const GURL& url); | 55 const GURL& url); |
54 | 56 |
55 DownloadUrlParameters( | 57 // Construct DownloadUrlParameters for downloading the resource at |url| and |
56 const GURL& url, | 58 // associating the download with the WebContents identified by |
57 int render_process_host_id, | 59 // |render_process_host_id| and |render_view_hsot_routing_id|. |
Randy Smith (Not in Mondays)
2016/02/10 21:48:46
Is there a way to give a level-appropriate descrip
asanka
2016/02/11 03:43:07
At the moment FromWebContents() is just a convenie
| |
58 int render_view_host_routing_id, | 60 DownloadUrlParameters(const GURL& url, |
59 int render_frame_host_routing_id, | 61 int render_process_host_id, |
60 content::ResourceContext* resource_context); | 62 int render_view_host_routing_id, |
63 int render_frame_host_routing_id, | |
64 ResourceContext* resource_context); | |
61 | 65 |
62 ~DownloadUrlParameters(); | 66 ~DownloadUrlParameters(); |
63 | 67 |
68 // Should be set to true if the download is being initiated by web content. | |
69 // Defaults to false. | |
64 void set_content_initiated(bool content_initiated) { | 70 void set_content_initiated(bool content_initiated) { |
65 content_initiated_ = content_initiated; | 71 content_initiated_ = content_initiated; |
66 } | 72 } |
67 void add_request_header(const std::string& name, const std::string& value) { | 73 void add_request_header(const std::string& name, const std::string& value) { |
68 request_headers_.push_back(make_pair(name, value)); | 74 request_headers_.push_back(make_pair(name, value)); |
69 } | 75 } |
76 | |
77 // HTTP Referrer and referrer encoding. | |
70 void set_referrer(const Referrer& referrer) { referrer_ = referrer; } | 78 void set_referrer(const Referrer& referrer) { referrer_ = referrer; } |
71 void set_referrer_encoding(const std::string& referrer_encoding) { | 79 void set_referrer_encoding(const std::string& referrer_encoding) { |
72 referrer_encoding_ = referrer_encoding; | 80 referrer_encoding_ = referrer_encoding; |
73 } | 81 } |
82 | |
83 // If this is a request for resuming an HTTP/S download, |last_modified| | |
84 // should be the value of the last seen Last-Modified response header. | |
74 void set_last_modified(const std::string& last_modified) { | 85 void set_last_modified(const std::string& last_modified) { |
75 last_modified_ = last_modified; | 86 last_modified_ = last_modified; |
76 } | 87 } |
88 | |
89 // If this is a request for resuming an HTTP/S download, |etag| should be the | |
90 // last seen Etag response header. | |
77 void set_etag(const std::string& etag) { | 91 void set_etag(const std::string& etag) { |
78 etag_ = etag; | 92 etag_ = etag; |
79 } | 93 } |
94 | |
95 // HTTP method to use. | |
80 void set_method(const std::string& method) { | 96 void set_method(const std::string& method) { |
81 method_ = method; | 97 method_ = method; |
82 } | 98 } |
99 | |
100 // Body of the HTTP POST request. | |
83 void set_post_body(const std::string& post_body) { | 101 void set_post_body(const std::string& post_body) { |
84 post_body_ = post_body; | 102 post_body_ = post_body; |
85 } | 103 } |
104 | |
105 // If |prefer_cache| is true and the response to |url| is in the HTTP cache, | |
106 // it will be used without validation. If |method| is POST, then |post_id_| | |
107 // shoud be set via |set_post_id()| below to the identifier of the POST | |
108 // transaction used to originally retrieve the resource. | |
86 void set_prefer_cache(bool prefer_cache) { | 109 void set_prefer_cache(bool prefer_cache) { |
87 prefer_cache_ = prefer_cache; | 110 prefer_cache_ = prefer_cache; |
88 } | 111 } |
112 | |
113 // See set_prefer_cache() above. | |
89 void set_post_id(int64_t post_id) { post_id_ = post_id; } | 114 void set_post_id(int64_t post_id) { post_id_ = post_id; } |
115 | |
116 // If |callback| is non-null it will be invoked when a response is received | |
117 // for |url|. For new downloads, this callback is invoked after the | |
118 // OnDownloadCreated notification is issued by the DownloadManager. If the | |
119 // download fails, then the DownloadInterruptReason parameter will indicate | |
120 // the failure. DownloadItem is always non-NULL. | |
Randy Smith (Not in Mondays)
2016/02/05 00:51:41
This comment contradicts our offline discussion ar
asanka
2016/02/11 03:43:07
Done.
| |
121 // TODO(asanka): Get rid of this callback since either a OnDownloadCreated or | |
122 // OnDownloadUpdated notification is always issued. | |
90 void set_callback(const OnStartedCallback& callback) { | 123 void set_callback(const OnStartedCallback& callback) { |
91 callback_ = callback; | 124 callback_ = callback; |
92 } | 125 } |
126 | |
127 // If not empty, specifies the full target path for the download. This value | |
128 // overrides the filename suggested by a Content-Disposition headers. It | |
129 // should only be set for programmatic downloads where the caller can verify | |
130 // the safety of the filename and the resulting download. | |
93 void set_file_path(const base::FilePath& file_path) { | 131 void set_file_path(const base::FilePath& file_path) { |
94 save_info_.file_path = file_path; | 132 save_info_.file_path = file_path; |
95 } | 133 } |
134 | |
135 // Suggessted filename for the download. The suggestion can be overridden by | |
136 // either a Content-Disposition response header or a |file_path|. | |
96 void set_suggested_name(const base::string16& suggested_name) { | 137 void set_suggested_name(const base::string16& suggested_name) { |
97 save_info_.suggested_name = suggested_name; | 138 save_info_.suggested_name = suggested_name; |
98 } | 139 } |
140 | |
141 // If |offset| is non-zero, then a byte range request will be issued to fetch | |
142 // the range of bytes starting at |offset| through to the end of thedownload. | |
99 void set_offset(int64_t offset) { save_info_.offset = offset; } | 143 void set_offset(int64_t offset) { save_info_.offset = offset; } |
100 void set_hash_state(const std::string& hash_state) { | 144 void set_hash_state(const std::string& hash_state) { |
101 save_info_.hash_state = hash_state; | 145 save_info_.hash_state = hash_state; |
102 } | 146 } |
147 | |
148 // If |prompt| is true, then the user will be prompted for a filename. Not | |
149 // effective if |file_path| is non-empty. | |
103 void set_prompt(bool prompt) { save_info_.prompt_for_save_location = prompt; } | 150 void set_prompt(bool prompt) { save_info_.prompt_for_save_location = prompt; } |
104 void set_file(base::File file) { save_info_.file = std::move(file); } | 151 void set_file(base::File file) { save_info_.file = std::move(file); } |
105 void set_do_not_prompt_for_login(bool do_not_prompt) { | 152 void set_do_not_prompt_for_login(bool do_not_prompt) { |
106 do_not_prompt_for_login_ = do_not_prompt; | 153 do_not_prompt_for_login_ = do_not_prompt; |
107 } | 154 } |
108 | 155 |
109 const OnStartedCallback& callback() const { return callback_; } | 156 const OnStartedCallback& callback() const { return callback_; } |
110 bool content_initiated() const { return content_initiated_; } | 157 bool content_initiated() const { return content_initiated_; } |
111 const std::string& last_modified() const { return last_modified_; } | 158 const std::string& last_modified() const { return last_modified_; } |
112 const std::string& etag() const { return etag_; } | 159 const std::string& etag() const { return etag_; } |
113 const std::string& method() const { return method_; } | 160 const std::string& method() const { return method_; } |
114 const std::string& post_body() const { return post_body_; } | 161 const std::string& post_body() const { return post_body_; } |
115 int64_t post_id() const { return post_id_; } | 162 int64_t post_id() const { return post_id_; } |
116 bool prefer_cache() const { return prefer_cache_; } | 163 bool prefer_cache() const { return prefer_cache_; } |
117 const Referrer& referrer() const { return referrer_; } | 164 const Referrer& referrer() const { return referrer_; } |
118 const std::string& referrer_encoding() const { return referrer_encoding_; } | 165 const std::string& referrer_encoding() const { return referrer_encoding_; } |
119 int render_process_host_id() const { return render_process_host_id_; } | 166 int render_process_host_id() const { return render_process_host_id_; } |
120 int render_view_host_routing_id() const { | 167 int render_view_host_routing_id() const { |
121 return render_view_host_routing_id_; | 168 return render_view_host_routing_id_; |
122 } | 169 } |
123 int render_frame_host_routing_id() const { | 170 int render_frame_host_routing_id() const { |
124 return render_frame_host_routing_id_; | 171 return render_frame_host_routing_id_; |
125 } | 172 } |
126 RequestHeadersType::const_iterator request_headers_begin() const { | 173 const RequestHeadersType& request_headers() const { return request_headers_; } |
127 return request_headers_.begin(); | 174 ResourceContext* resource_context() const { return resource_context_; } |
128 } | |
129 RequestHeadersType::const_iterator request_headers_end() const { | |
130 return request_headers_.end(); | |
131 } | |
132 content::ResourceContext* resource_context() const { | |
133 return resource_context_; | |
134 } | |
135 const base::FilePath& file_path() const { return save_info_.file_path; } | 175 const base::FilePath& file_path() const { return save_info_.file_path; } |
136 const base::string16& suggested_name() const { | 176 const base::string16& suggested_name() const { |
137 return save_info_.suggested_name; | 177 return save_info_.suggested_name; |
138 } | 178 } |
139 int64_t offset() const { return save_info_.offset; } | 179 int64_t offset() const { return save_info_.offset; } |
140 const std::string& hash_state() const { return save_info_.hash_state; } | 180 const std::string& hash_state() const { return save_info_.hash_state; } |
141 bool prompt() const { return save_info_.prompt_for_save_location; } | 181 bool prompt() const { return save_info_.prompt_for_save_location; } |
142 const GURL& url() const { return url_; } | 182 const GURL& url() const { return url_; } |
143 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; } | 183 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; } |
144 | 184 |
(...skipping 20 matching lines...) Expand all Loading... | |
165 DownloadSaveInfo save_info_; | 205 DownloadSaveInfo save_info_; |
166 GURL url_; | 206 GURL url_; |
167 bool do_not_prompt_for_login_; | 207 bool do_not_prompt_for_login_; |
168 | 208 |
169 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); | 209 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); |
170 }; | 210 }; |
171 | 211 |
172 } // namespace content | 212 } // namespace content |
173 | 213 |
174 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ | 214 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
OLD | NEW |