| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_RENDERER_RESOURCE_FETCHER_H_ | 5 #ifndef CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ |
| 6 #define CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ | 6 #define CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 12 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class TimeDelta; | 17 class TimeDelta; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 class WebFrame; | 21 class WebFrame; |
| 22 class WebURLResponse; | 22 class WebURLResponse; |
| 23 enum class WebCachePolicy; | |
| 24 struct WebURLLoaderOptions; | |
| 25 } | 23 } |
| 26 | 24 |
| 27 namespace content { | 25 namespace content { |
| 28 | 26 |
| 29 // Interface to download resources asynchronously. | 27 // Interface to download resources asynchronously. |
| 30 class CONTENT_EXPORT ResourceFetcher { | 28 class CONTENT_EXPORT ResourceFetcher { |
| 31 public: | 29 public: |
| 32 enum LoaderType { | |
| 33 PLATFORM_LOADER, // uses Platform::createURLLoader | |
| 34 FRAME_ASSOCIATED_LOADER, // uses WebFrame::createAssociatedURLLoader | |
| 35 }; | |
| 36 | |
| 37 virtual ~ResourceFetcher() {} | 30 virtual ~ResourceFetcher() {} |
| 38 | 31 |
| 39 // This will be called asynchronously after the URL has been fetched, | 32 // This will be called asynchronously after the URL has been fetched, |
| 40 // successfully or not. If there is a failure, response and data will both be | 33 // successfully or not. If there is a failure, response and data will both be |
| 41 // empty. |response| and |data| are both valid until the URLFetcher instance | 34 // empty. |response| and |data| are both valid until the URLFetcher instance |
| 42 // is destroyed. | 35 // is destroyed. |
| 43 typedef base::Callback<void(const blink::WebURLResponse& response, | 36 typedef base::Callback<void(const blink::WebURLResponse& response, |
| 44 const std::string& data)> Callback; | 37 const std::string& data)> Callback; |
| 45 | 38 |
| 46 // Creates a ResourceFetcher for the specified resource. Caller takes | 39 // Creates a ResourceFetcher for the specified resource. Caller takes |
| 47 // ownership of the returned object. Deleting the ResourceFetcher will cancel | 40 // ownership of the returned object. Deleting the ResourceFetcher will cancel |
| 48 // the request, and the callback will never be run. | 41 // the request, and the callback will never be run. |
| 49 static ResourceFetcher* Create(const GURL& url); | 42 static ResourceFetcher* Create(const GURL& url); |
| 50 | 43 |
| 51 // Set the corresponding parameters of the request. Must be called before | 44 // Set the corresponding parameters of the request. Must be called before |
| 52 // Start. By default, requests are GETs with no body and respect the default | 45 // Start. By default, requests are GETs with no body and respect the default |
| 53 // cache policy. | 46 // cache policy. |
| 54 virtual void SetMethod(const std::string& method) = 0; | 47 virtual void SetMethod(const std::string& method) = 0; |
| 55 virtual void SetBody(const std::string& body) = 0; | 48 virtual void SetBody(const std::string& body) = 0; |
| 56 virtual void SetHeader(const std::string& header, | 49 virtual void SetHeader(const std::string& header, |
| 57 const std::string& value) = 0; | 50 const std::string& value) = 0; |
| 58 virtual void SetSkipServiceWorker( | |
| 59 blink::WebURLRequest::SkipServiceWorker skip_service_worker) = 0; | |
| 60 virtual void SetCachePolicy(blink::WebCachePolicy policy) = 0; | |
| 61 | |
| 62 // Associate the corresponding WebURLLoaderOptions to the loader. Must be | |
| 63 // called before Start. Used if the LoaderType is FRAME_ASSOCIATED_LOADER. | |
| 64 virtual void SetLoaderOptions(const blink::WebURLLoaderOptions& options) = 0; | |
| 65 | 51 |
| 66 // Starts the request using the specified frame. Calls |callback| when | 52 // Starts the request using the specified frame. Calls |callback| when |
| 67 // done. | 53 // done. |
| 68 virtual void Start(blink::WebFrame* frame, | 54 virtual void Start(blink::WebFrame* frame, |
| 69 blink::WebURLRequest::RequestContext request_context, | 55 blink::WebURLRequest::RequestContext request_context, |
| 70 blink::WebURLRequest::FrameType frame_type, | 56 blink::WebURLRequest::FrameType frame_type, |
| 71 LoaderType loader_type, | |
| 72 const Callback& callback) = 0; | 57 const Callback& callback) = 0; |
| 73 | 58 |
| 74 // Sets how long to wait for the server to reply. By default, there is no | 59 // Sets how long to wait for the server to reply. By default, there is no |
| 75 // timeout. Must be called after a request is started. | 60 // timeout. Must be called after a request is started. |
| 76 virtual void SetTimeout(const base::TimeDelta& timeout) = 0; | 61 virtual void SetTimeout(const base::TimeDelta& timeout) = 0; |
| 77 | 62 |
| 78 // Manually cancel the request. | 63 // Manually cancel the request. |
| 79 virtual void Cancel() = 0; | 64 virtual void Cancel() = 0; |
| 80 }; | 65 }; |
| 81 | 66 |
| 82 } // namespace content | 67 } // namespace content |
| 83 | 68 |
| 84 #endif // CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ | 69 #endif // CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ |
| OLD | NEW |