Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: content/public/browser/download_url_parameters.h

Issue 148133007: [Downloads] Always call DM::StartDownload() for explicit downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment updates Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // An OnStartedCallback is invoked when a response is available for the
45 // downlaod request. For new downloads, this callback is invoked after the
46 // OnDownloadCreated notification is issued by the DownloadManager. If the
47 // download fails, then the DownloadInterruptReason parameter will indicate
48 // the failure.
49 //
50 // DownloadItem* may be nullptr if no DownloadItem was created. DownloadItems
51 // are not created when a resource throttle or a resource handler blocks the
52 // download request. I.e. the download triggered a warning of some sort and
53 // the user chose to not to proceed with the download as a result.
45 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)> 54 typedef base::Callback<void(DownloadItem*, DownloadInterruptReason)>
46 OnStartedCallback; 55 OnStartedCallback;
47 56
48 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair; 57 typedef std::pair<std::string, std::string> RequestHeadersNameValuePair;
49 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType; 58 typedef std::vector<RequestHeadersNameValuePair> RequestHeadersType;
50 59
60 // Construct DownloadUrlParameters for downloading the resource at |url| and
61 // associating the download with |web_contents|.
51 static scoped_ptr<DownloadUrlParameters> FromWebContents( 62 static scoped_ptr<DownloadUrlParameters> FromWebContents(
52 WebContents* web_contents, 63 WebContents* web_contents,
53 const GURL& url); 64 const GURL& url);
54 65
55 DownloadUrlParameters( 66 // Construct DownloadUrlParameters for downloading the resource at |url| and
56 const GURL& url, 67 // associating the download with the WebContents identified by
57 int render_process_host_id, 68 // |render_process_host_id| and |render_view_host_routing_id|.
58 int render_view_host_routing_id, 69 //
59 int render_frame_host_routing_id, 70 // If the download is not associated with a WebContents, then set the IDs to
60 content::ResourceContext* resource_context); 71 // -1.
72 // NOTE: This is not safe and should only be done in a limited set of cases
Randy Smith (Not in Mondays) 2016/02/12 21:57:19 "This is not safe" strikes me as insufficiently pr
asanka 2016/02/12 23:34:47 For the WebContents associated cases, we don't cre
Randy Smith (Not in Mondays) 2016/02/13 00:16:31 SG, though that only answers my second question.
asanka 2016/02/13 01:27:21 I added a brief explanation. I'm not sure if it's
73 // where the download URL has been previously vetted.
74 DownloadUrlParameters(const GURL& url,
75 int render_process_host_id,
76 int render_view_host_routing_id,
77 int render_frame_host_routing_id,
78 ResourceContext* resource_context);
61 79
62 ~DownloadUrlParameters(); 80 ~DownloadUrlParameters();
63 81
82 // Should be set to true if the download is being initiated by web content.
Randy Smith (Not in Mondays) 2016/02/12 21:57:19 nit, vague suggestion: Maybe wordsmith a little so
asanka 2016/02/12 23:34:48 Done.
83 // Defaults to false.
64 void set_content_initiated(bool content_initiated) { 84 void set_content_initiated(bool content_initiated) {
65 content_initiated_ = content_initiated; 85 content_initiated_ = content_initiated;
66 } 86 }
67 void add_request_header(const std::string& name, const std::string& value) { 87 void add_request_header(const std::string& name, const std::string& value) {
68 request_headers_.push_back(make_pair(name, value)); 88 request_headers_.push_back(make_pair(name, value));
69 } 89 }
90
91 // HTTP Referrer and referrer encoding.
70 void set_referrer(const Referrer& referrer) { referrer_ = referrer; } 92 void set_referrer(const Referrer& referrer) { referrer_ = referrer; }
71 void set_referrer_encoding(const std::string& referrer_encoding) { 93 void set_referrer_encoding(const std::string& referrer_encoding) {
72 referrer_encoding_ = referrer_encoding; 94 referrer_encoding_ = referrer_encoding;
73 } 95 }
96
97 // If this is a request for resuming an HTTP/S download, |last_modified|
98 // should be the value of the last seen Last-Modified response header.
74 void set_last_modified(const std::string& last_modified) { 99 void set_last_modified(const std::string& last_modified) {
75 last_modified_ = last_modified; 100 last_modified_ = last_modified;
76 } 101 }
102
103 // If this is a request for resuming an HTTP/S download, |etag| should be the
104 // last seen Etag response header.
77 void set_etag(const std::string& etag) { 105 void set_etag(const std::string& etag) {
78 etag_ = etag; 106 etag_ = etag;
79 } 107 }
108
109 // HTTP method to use.
80 void set_method(const std::string& method) { 110 void set_method(const std::string& method) {
81 method_ = method; 111 method_ = method;
82 } 112 }
113
114 // Body of the HTTP POST request.
Randy Smith (Not in Mondays) 2016/02/12 21:57:19 nit, suggestion: "Body of the request if method ab
83 void set_post_body(const std::string& post_body) { 115 void set_post_body(const std::string& post_body) {
84 post_body_ = post_body; 116 post_body_ = post_body;
85 } 117 }
118
119 // If |prefer_cache| is true and the response to |url| is in the HTTP cache,
120 // it will be used without validation. If |method| is POST, then |post_id_|
121 // shoud be set via |set_post_id()| below to the identifier of the POST
122 // transaction used to originally retrieve the resource.
86 void set_prefer_cache(bool prefer_cache) { 123 void set_prefer_cache(bool prefer_cache) {
87 prefer_cache_ = prefer_cache; 124 prefer_cache_ = prefer_cache;
88 } 125 }
126
127 // See set_prefer_cache() above.
89 void set_post_id(int64_t post_id) { post_id_ = post_id; } 128 void set_post_id(int64_t post_id) { post_id_ = post_id; }
129
130 // See OnStartedCallback above.
90 void set_callback(const OnStartedCallback& callback) { 131 void set_callback(const OnStartedCallback& callback) {
91 callback_ = callback; 132 callback_ = callback;
92 } 133 }
134
135 // If not empty, specifies the full target path for the download. This value
136 // overrides the filename suggested by a Content-Disposition headers. It
137 // should only be set for programmatic downloads where the caller can verify
138 // the safety of the filename and the resulting download.
93 void set_file_path(const base::FilePath& file_path) { 139 void set_file_path(const base::FilePath& file_path) {
94 save_info_.file_path = file_path; 140 save_info_.file_path = file_path;
95 } 141 }
142
143 // Suggessted filename for the download. The suggestion can be overridden by
144 // either a Content-Disposition response header or a |file_path|.
96 void set_suggested_name(const base::string16& suggested_name) { 145 void set_suggested_name(const base::string16& suggested_name) {
97 save_info_.suggested_name = suggested_name; 146 save_info_.suggested_name = suggested_name;
98 } 147 }
148
149 // If |offset| is non-zero, then a byte range request will be issued to fetch
150 // the range of bytes starting at |offset| through to the end of thedownload.
99 void set_offset(int64_t offset) { save_info_.offset = offset; } 151 void set_offset(int64_t offset) { save_info_.offset = offset; }
100 void set_hash_state(const std::string& hash_state) { 152 void set_hash_state(const std::string& hash_state) {
101 save_info_.hash_state = hash_state; 153 save_info_.hash_state = hash_state;
102 } 154 }
155
156 // If |prompt| is true, then the user will be prompted for a filename. Not
157 // effective if |file_path| is non-empty.
Randy Smith (Not in Mondays) 2016/02/12 21:57:19 Suggestion: "not effective" -> "Ignored"
asanka 2016/02/12 23:34:48 Done.
103 void set_prompt(bool prompt) { save_info_.prompt_for_save_location = prompt; } 158 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); } 159 void set_file(base::File file) { save_info_.file = std::move(file); }
105 void set_do_not_prompt_for_login(bool do_not_prompt) { 160 void set_do_not_prompt_for_login(bool do_not_prompt) {
106 do_not_prompt_for_login_ = do_not_prompt; 161 do_not_prompt_for_login_ = do_not_prompt;
107 } 162 }
108 163
109 const OnStartedCallback& callback() const { return callback_; } 164 const OnStartedCallback& callback() const { return callback_; }
110 bool content_initiated() const { return content_initiated_; } 165 bool content_initiated() const { return content_initiated_; }
111 const std::string& last_modified() const { return last_modified_; } 166 const std::string& last_modified() const { return last_modified_; }
112 const std::string& etag() const { return etag_; } 167 const std::string& etag() const { return etag_; }
113 const std::string& method() const { return method_; } 168 const std::string& method() const { return method_; }
114 const std::string& post_body() const { return post_body_; } 169 const std::string& post_body() const { return post_body_; }
115 int64_t post_id() const { return post_id_; } 170 int64_t post_id() const { return post_id_; }
116 bool prefer_cache() const { return prefer_cache_; } 171 bool prefer_cache() const { return prefer_cache_; }
117 const Referrer& referrer() const { return referrer_; } 172 const Referrer& referrer() const { return referrer_; }
118 const std::string& referrer_encoding() const { return referrer_encoding_; } 173 const std::string& referrer_encoding() const { return referrer_encoding_; }
119 int render_process_host_id() const { return render_process_host_id_; } 174 int render_process_host_id() const { return render_process_host_id_; }
120 int render_view_host_routing_id() const { 175 int render_view_host_routing_id() const {
121 return render_view_host_routing_id_; 176 return render_view_host_routing_id_;
122 } 177 }
123 int render_frame_host_routing_id() const { 178 int render_frame_host_routing_id() const {
124 return render_frame_host_routing_id_; 179 return render_frame_host_routing_id_;
125 } 180 }
126 RequestHeadersType::const_iterator request_headers_begin() const { 181 const RequestHeadersType& request_headers() const { return request_headers_; }
127 return request_headers_.begin(); 182 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; } 183 const base::FilePath& file_path() const { return save_info_.file_path; }
136 const base::string16& suggested_name() const { 184 const base::string16& suggested_name() const {
137 return save_info_.suggested_name; 185 return save_info_.suggested_name;
138 } 186 }
139 int64_t offset() const { return save_info_.offset; } 187 int64_t offset() const { return save_info_.offset; }
140 const std::string& hash_state() const { return save_info_.hash_state; } 188 const std::string& hash_state() const { return save_info_.hash_state; }
141 bool prompt() const { return save_info_.prompt_for_save_location; } 189 bool prompt() const { return save_info_.prompt_for_save_location; }
142 const GURL& url() const { return url_; } 190 const GURL& url() const { return url_; }
143 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; } 191 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; }
144 192
(...skipping 20 matching lines...) Expand all
165 DownloadSaveInfo save_info_; 213 DownloadSaveInfo save_info_;
166 GURL url_; 214 GURL url_;
167 bool do_not_prompt_for_login_; 215 bool do_not_prompt_for_login_;
168 216
169 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); 217 DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters);
170 }; 218 };
171 219
172 } // namespace content 220 } // namespace content
173 221
174 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ 222 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698