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