- add sources.
[platform/framework/web/crosswalk.git] / src / content / public / browser / resource_dispatcher_host_delegate.h
1 // Copyright (c) 2012 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 #ifndef CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
6 #define CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "webkit/common/resource_type.h"
14
15 class GURL;
16 template <class T> class ScopedVector;
17
18 namespace appcache {
19 class AppCacheService;
20 }
21
22 namespace content {
23 class ResourceContext;
24 class ResourceThrottle;
25 class StreamHandle;
26 struct Referrer;
27 struct ResourceResponse;
28 }
29
30 namespace IPC {
31 class Sender;
32 }
33
34 namespace net {
35 class AuthChallengeInfo;
36 class SSLCertRequestInfo;
37 class URLRequest;
38 }
39
40 namespace content {
41
42 class ResourceDispatcherHostLoginDelegate;
43
44 // Interface that the embedder provides to ResourceDispatcherHost to allow
45 // observing and modifying requests.
46 class CONTENT_EXPORT ResourceDispatcherHostDelegate {
47  public:
48   // Called when a request begins. Return false to abort the request.
49   virtual bool ShouldBeginRequest(
50       int child_id,
51       int route_id,
52       const std::string& method,
53       const GURL& url,
54       ResourceType::Type resource_type,
55       ResourceContext* resource_context);
56
57   // Called after ShouldBeginRequest to allow the embedder to add resource
58   // throttles.
59   virtual void RequestBeginning(
60       net::URLRequest* request,
61       ResourceContext* resource_context,
62       appcache::AppCacheService* appcache_service,
63       ResourceType::Type resource_type,
64       int child_id,
65       int route_id,
66       ScopedVector<ResourceThrottle>* throttles);
67
68   // Called if a navigation request is transferred from one process to another.
69   virtual void WillTransferRequestToNewProcess(
70       int old_child_id,
71       int old_route_id,
72       int old_request_id,
73       int new_child_id,
74       int new_route_id,
75       int new_request_id);
76
77   // Allows an embedder to add additional resource handlers for a download.
78   // |must_download| is set if the request must be handled as a download.
79   virtual void DownloadStarting(
80       net::URLRequest* request,
81       ResourceContext* resource_context,
82       int child_id,
83       int route_id,
84       int request_id,
85       bool is_content_initiated,
86       bool must_download,
87       ScopedVector<ResourceThrottle>* throttles);
88
89   // Called when an SSL Client Certificate is requested. If false is returned,
90   // the request is canceled. Otherwise, the certificate is chosen.
91   virtual bool AcceptSSLClientCertificateRequest(
92       net::URLRequest* request,
93       net::SSLCertRequestInfo* cert_request_info);
94
95   // Called when authentication is required and credentials are needed. If
96   // false is returned, CancelAuth() is called on the URLRequest and the error
97   // page is shown. If true is returned, the user will be prompted for
98   // authentication credentials.
99   virtual bool AcceptAuthRequest(net::URLRequest* request,
100                                  net::AuthChallengeInfo* auth_info);
101
102   // Creates a ResourceDispatcherHostLoginDelegate that asks the user for a
103   // username and password.
104   virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
105       net::AuthChallengeInfo* auth_info, net::URLRequest* request);
106
107   // Launches the url for the given tab. Returns true if an attempt to handle
108   // the url was made, e.g. by launching an app. Note that this does not
109   // guarantee that the app successfully handled it.
110   virtual bool HandleExternalProtocol(const GURL& url,
111                                       int child_id,
112                                       int route_id);
113
114   // Returns true if we should force the given resource to be downloaded.
115   // Otherwise, the content layer decides.
116   virtual bool ShouldForceDownloadResource(
117       const GURL& url, const std::string& mime_type);
118
119   // Returns true and sets |origin| and |target_id| if a Stream should be
120   // created for the resource.
121   // If true is returned, a new Stream will be created and OnStreamCreated()
122   // will be called with
123   // - the |target_id| returned by this function
124   // - a StreamHandle instance for the Stream. The handle contains the URL for
125   //   reading the Stream etc.
126   // The Stream's origin will be set to |origin|.
127   virtual bool ShouldInterceptResourceAsStream(
128       content::ResourceContext* resource_context,
129       const GURL& url,
130       const std::string& mime_type,
131       GURL* origin,
132       std::string* target_id);
133
134   // Informs the delegate that a Stream was created. |target_id| will be filled
135   // with the parameter returned by ShouldInterceptResourceAsStream(). The
136   // Stream can be read from the blob URL of the Stream, but can only be read
137   // once.
138   virtual void OnStreamCreated(
139       content::ResourceContext* resource_context,
140       int render_process_id,
141       int render_view_id,
142       const std::string& target_id,
143       scoped_ptr<StreamHandle> stream,
144       int64 expected_content_size);
145
146   // Informs the delegate that a response has started.
147   virtual void OnResponseStarted(
148       net::URLRequest* request,
149       ResourceContext* resource_context,
150       ResourceResponse* response,
151       IPC::Sender* sender);
152
153   // Informs the delegate that a request has been redirected.
154   virtual void OnRequestRedirected(
155       const GURL& redirect_url,
156       net::URLRequest* request,
157       ResourceContext* resource_context,
158       ResourceResponse* response);
159
160  protected:
161   ResourceDispatcherHostDelegate();
162   virtual ~ResourceDispatcherHostDelegate();
163 };
164
165 }  // namespace content
166
167 #endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_