OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // The intent of this file is to provide a type-neutral abstraction between | 5 // The intent of this file is to provide a type-neutral abstraction between |
6 // Chrome and WebKit for resource loading. This pure-virtual interface is | 6 // Chrome and WebKit for resource loading. This pure-virtual interface is |
7 // implemented by the embedder. | 7 // implemented by the embedder. |
8 // | 8 // |
9 // One of these objects will be created by WebKit for each request. WebKit | 9 // One of these objects will be created by WebKit for each request. WebKit |
10 // will own the pointer to the bridge, and will delete it when the request is | 10 // will own the pointer to the bridge, and will delete it when the request is |
11 // no longer needed. | 11 // no longer needed. |
12 // | 12 // |
13 // In turn, the bridge's owner on the WebKit end will implement the | 13 // In turn, the bridge's owner on the WebKit end will implement the |
14 // RequestPeer interface, which we will use to communicate notifications | 14 // RequestPeer interface, which we will use to communicate notifications |
15 // back. | 15 // back. |
16 | 16 |
17 #ifndef WEBKIT_CHILD_RESOURCE_LOADER_BRIDGE_H_ | 17 #ifndef CONTENT_CHILD_RESOURCE_LOADER_BRIDGE_H_ |
18 #define WEBKIT_CHILD_RESOURCE_LOADER_BRIDGE_H_ | 18 #define CONTENT_CHILD_RESOURCE_LOADER_BRIDGE_H_ |
19 | 19 |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "content/common/content_export.h" |
21 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
22 #include "webkit/child/webkit_child_export.h" | |
23 | 23 |
24 namespace blink { | 24 namespace blink { |
25 class WebThreadedDataReceiver; | 25 class WebThreadedDataReceiver; |
26 } | 26 } |
27 | 27 |
28 // TODO(pilgrim) remove this once resource loader is moved to content | |
29 // http://crbug.com/338338 | |
30 namespace content { | 28 namespace content { |
| 29 |
31 class RequestPeer; | 30 class RequestPeer; |
32 class ResourceRequestBody; | 31 class ResourceRequestBody; |
33 struct SyncLoadResponse; | 32 struct SyncLoadResponse; |
34 } | |
35 | 33 |
36 namespace webkit_glue { | 34 // TODO(tfarina): Refactor code that uses this class. This shouldn't be needed |
37 | 35 // now that it lives in content/. |
38 class ResourceLoaderBridge { | 36 class CONTENT_EXPORT ResourceLoaderBridge { |
39 public: | 37 public: |
40 // use WebKitPlatformSupportImpl::CreateResourceLoader() for construction, but | 38 // use WebKitPlatformSupportImpl::CreateResourceLoader() for construction, but |
41 // anybody can delete at any time, INCLUDING during processing of callbacks. | 39 // anybody can delete at any time, INCLUDING during processing of callbacks. |
42 WEBKIT_CHILD_EXPORT virtual ~ResourceLoaderBridge(); | 40 virtual ~ResourceLoaderBridge(); |
43 | 41 |
44 // Call this method before calling Start() to set the request body. | 42 // Call this method before calling Start() to set the request body. |
45 // May only be used with HTTP(S) POST requests. | 43 // May only be used with HTTP(S) POST requests. |
46 virtual void SetRequestBody(content::ResourceRequestBody* request_body) = 0; | 44 virtual void SetRequestBody(ResourceRequestBody* request_body) = 0; |
47 | 45 |
48 // Call this method to initiate the request. If this method succeeds, then | 46 // Call this method to initiate the request. If this method succeeds, then |
49 // the peer's methods will be called asynchronously to report various events. | 47 // the peer's methods will be called asynchronously to report various events. |
50 virtual bool Start(content::RequestPeer* peer) = 0; | 48 virtual bool Start(RequestPeer* peer) = 0; |
51 | 49 |
52 // Call this method to cancel a request that is in progress. This method | 50 // Call this method to cancel a request that is in progress. This method |
53 // causes the request to immediately transition into the 'done' state. The | 51 // causes the request to immediately transition into the 'done' state. The |
54 // OnCompletedRequest method will be called asynchronously; this assumes | 52 // OnCompletedRequest method will be called asynchronously; this assumes |
55 // the peer is still valid. | 53 // the peer is still valid. |
56 virtual void Cancel() = 0; | 54 virtual void Cancel() = 0; |
57 | 55 |
58 // Call this method to suspend or resume a load that is in progress. This | 56 // Call this method to suspend or resume a load that is in progress. This |
59 // method may only be called after a successful call to the Start method. | 57 // method may only be called after a successful call to the Start method. |
60 virtual void SetDefersLoading(bool value) = 0; | 58 virtual void SetDefersLoading(bool value) = 0; |
61 | 59 |
62 // Call this method when the priority of the requested resource changes after | 60 // Call this method when the priority of the requested resource changes after |
63 // Start() has been called. This method may only be called after a successful | 61 // Start() has been called. This method may only be called after a successful |
64 // call to the Start method. | 62 // call to the Start method. |
65 virtual void DidChangePriority(net::RequestPriority new_priority, | 63 virtual void DidChangePriority(net::RequestPriority new_priority, |
66 int intra_priority_value) = 0; | 64 int intra_priority_value) = 0; |
67 | 65 |
68 // Call this method to attach a data receiver which will receive resource data | 66 // Call this method to attach a data receiver which will receive resource data |
69 // on its own thread. | 67 // on its own thread. |
70 virtual bool AttachThreadedDataReceiver( | 68 virtual bool AttachThreadedDataReceiver( |
71 blink::WebThreadedDataReceiver* threaded_data_receiver) = 0; | 69 blink::WebThreadedDataReceiver* threaded_data_receiver) = 0; |
72 | 70 |
73 // Call this method to load the resource synchronously (i.e., in one shot). | 71 // Call this method to load the resource synchronously (i.e., in one shot). |
74 // This is an alternative to the Start method. Be warned that this method | 72 // This is an alternative to the Start method. Be warned that this method |
75 // will block the calling thread until the resource is fully downloaded or an | 73 // will block the calling thread until the resource is fully downloaded or an |
76 // error occurs. It could block the calling thread for a long time, so only | 74 // error occurs. It could block the calling thread for a long time, so only |
77 // use this if you really need it! There is also no way for the caller to | 75 // use this if you really need it! There is also no way for the caller to |
78 // interrupt this method. Errors are reported via the status field of the | 76 // interrupt this method. Errors are reported via the status field of the |
79 // response parameter. | 77 // response parameter. |
80 virtual void SyncLoad(content::SyncLoadResponse* response) = 0; | 78 virtual void SyncLoad(SyncLoadResponse* response) = 0; |
81 | 79 |
82 protected: | 80 protected: |
83 // Construction must go through | 81 // Construction must go through |
84 // WebKitPlatformSupportImpl::CreateResourceLoader() | 82 // WebKitPlatformSupportImpl::CreateResourceLoader() |
85 // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload | 83 // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload |
86 // methods may be called to construct the body of the request. | 84 // methods may be called to construct the body of the request. |
87 WEBKIT_CHILD_EXPORT ResourceLoaderBridge(); | 85 ResourceLoaderBridge(); |
88 | 86 |
89 private: | 87 private: |
90 DISALLOW_COPY_AND_ASSIGN(ResourceLoaderBridge); | 88 DISALLOW_COPY_AND_ASSIGN(ResourceLoaderBridge); |
91 }; | 89 }; |
92 | 90 |
93 } // namespace webkit_glue | 91 } // namespace content |
94 | 92 |
95 #endif // WEBKIT_CHILD_RESOURCE_LOADER_BRIDGE_H_ | 93 #endif // CONTENT_CHILD_RESOURCE_LOADER_BRIDGE_H_ |
OLD | NEW |