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