Chromium Code Reviews| Index: content/public/browser/download_url_parameters.h |
| diff --git a/content/public/browser/download_url_parameters.h b/content/public/browser/download_url_parameters.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6c9f34d0633cd58bceaf0cb512517c870b1625a |
| --- /dev/null |
| +++ b/content/public/browser/download_url_parameters.h |
| @@ -0,0 +1,128 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
| +#define CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| +#include "content/public/browser/download_save_info.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "net/base/net_errors.h" |
| + |
| +namespace content { |
| + |
| +class ResourceContext; |
| +class ResourceDispatcherHostImpl; |
| + |
| +// Pass an instance of DownloadUrlParameters to DownloadManager::DownloadUrl in |
| +// order to download the content at |url|. |referrer| and |referrer_encoding| |
| +// are the referrer for the download, and may be empty. If |prefer_cache| is |
| +// true, then if the response to |url| is in the HTTP cache it will be used |
| +// without revalidation. If |post_id| is non-negative, then it identifies the |
| +// post transaction used to originally retrieve the |url| resource - it also |
| +// requires |prefer_cache| to be |true| since re-post'ing is not done. |
| +// |save_info| specifies where the downloaded file should be saved, and whether |
| +// the user should be prompted about the download. |web_contents| is the web |
| +// page that the download is done in context of, and must be non-NULL. |
| +// |callback| will be called when the download starts, or if an error occurs |
|
Randy Smith (Not in Mondays)
2012/04/30 19:44:48
nit: "If not null".
benjhayden
2012/05/02 15:11:54
Done.
|
| +// that prevents a download item from being created. We send a pointer to |
| +// content::ResourceContext instead of the usual reference so that a copy of |
| +// the object isn't made. |
|
Randy Smith (Not in Mondays)
2012/04/30 19:44:48
Could you specify the format of the extra headers?
benjhayden
2012/05/02 15:11:54
PTAL
Randy Smith (Not in Mondays)
2012/05/02 18:36:22
Looks good.
|
| +class CONTENT_EXPORT DownloadUrlParameters { |
| + public: |
| + // NOTE: If there is an error, the DownloadId will be invalid. |
| + typedef base::Callback<void(DownloadId, net::Error)> OnStartedCallback; |
| + |
| + static DownloadUrlParameters* FromWebContents( |
| + content::WebContents* web_contents, |
| + const GURL& url, |
| + const content::DownloadSaveInfo& save_info); |
| + |
| + DownloadUrlParameters( |
| + const GURL& url, |
| + int render_process_host_id, |
| + int render_view_host_routing_id, |
| + content::ResourceContext* resource_context, |
| + const content::DownloadSaveInfo& save_info); |
| + |
| + ~DownloadUrlParameters(); |
| + |
| + void set_extra_headers(scoped_ptr<base::ListValue> extra_headers) { |
| + extra_headers_ = extra_headers.Pass(); |
| + } |
| + void set_referrer(const GURL& referrer) { referrer_ = referrer; } |
| + void set_referrer_encoding(const std::string& referrer_encoding) { |
| + referrer_encoding_ = referrer_encoding; |
| + } |
| + void set_load_flags(int load_flags) { load_flags_ |= load_flags; } |
| + void set_method(const std::string& method) { method_ = method; } |
| + void set_post_body(const std::string& post_body) { |
| + post_body_ = post_body; |
| + } |
| + void set_prefer_cache(bool prefer_cache) { prefer_cache_ = prefer_cache; } |
| + void set_post_id(int64 post_id) { |
| + post_id_ = post_id; |
| + if (post_id_ >= 0) { |
| + set_method("POST"); |
| + set_prefer_cache(true); |
| + } else { |
| + set_method("GET"); |
| + set_prefer_cache(false); |
|
Randy Smith (Not in Mondays)
2012/04/30 19:44:48
I'm a bit concerned about this violating principle
benjhayden
2012/05/02 15:11:54
You're right, this behavior was surprising, and it
|
| + } |
| + } |
| + void set_callback(const OnStartedCallback& callback) { |
| + callback_ = callback; |
| + } |
| + |
| + const OnStartedCallback& callback() const { return callback_; } |
| + base::ListValue* extra_headers() const { return extra_headers_.get(); } |
| + int load_flags() const { return load_flags_; } |
| + const std::string& method() const { return method_; } |
| + const std::string& post_body() const { return post_body_; } |
| + int64 post_id() const { return post_id_; } |
| + bool prefer_cache() const { return prefer_cache_; } |
| + const GURL& referrer() const { return referrer_; } |
| + const std::string& referrer_encoding() const { return referrer_encoding_; } |
| + int render_process_host_id() const { return render_process_host_id_; } |
| + int render_view_host_routing_id() const { |
| + return render_view_host_routing_id_; |
| + } |
| + content::ResourceContext* resource_context() const { |
| + return resource_context_; |
| + } |
| + ResourceDispatcherHostImpl* resource_dispatcher_host() const { |
| + return resource_dispatcher_host_; |
| + } |
| + const content::DownloadSaveInfo& save_info() const { return save_info_; } |
| + const GURL& url() const { return url_; } |
| + |
| + private: |
| + OnStartedCallback callback_; |
| + scoped_ptr<base::ListValue> extra_headers_; |
| + int load_flags_; |
| + std::string method_; |
| + std::string post_body_; |
| + int64 post_id_; |
| + bool prefer_cache_; |
| + GURL referrer_; |
| + std::string referrer_encoding_; |
| + int render_process_host_id_; |
| + int render_view_host_routing_id_; |
| + ResourceContext* resource_context_; |
| + ResourceDispatcherHostImpl* resource_dispatcher_host_; |
| + DownloadSaveInfo save_info_; |
|
Randy Smith (Not in Mondays)
2012/04/30 19:44:48
Given the creation of DownloadUrlParameters, I'd l
benjhayden
2012/05/02 15:11:54
Agreed, that's definitely worth trying, but not fo
Randy Smith (Not in Mondays)
2012/05/02 18:36:22
Awesome; it's yours.
|
| + GURL url_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_URL_PARAMETERS_H_ |