resource_dispatcher_host_delegate.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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/glue/resource_type.h"
14
15class GURL;
16template <class T> class ScopedVector;
17
18namespace appcache {
19class AppCacheService;
20}
21
22namespace content {
23class ResourceContext;
24class ResourceThrottle;
25class StreamHandle;
26struct Referrer;
27struct ResourceResponse;
28}
29
30namespace IPC {
31class Sender;
32}
33
34namespace net {
35class AuthChallengeInfo;
36class SSLCertRequestInfo;
37class URLRequest;
38}
39
40namespace content {
41
42class ResourceDispatcherHostLoginDelegate;
43
44// Interface that the embedder provides to ResourceDispatcherHost to allow
45// observing and modifying requests.
46class 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      bool is_continuation_of_transferred_request,
67      ScopedVector<ResourceThrottle>* throttles);
68
69  // Allows an embedder to add additional resource handlers for a download.
70  // |must_download| is set if the request must be handled as a download.
71  virtual void DownloadStarting(
72      net::URLRequest* request,
73      ResourceContext* resource_context,
74      int child_id,
75      int route_id,
76      int request_id,
77      bool is_content_initiated,
78      bool must_download,
79      ScopedVector<ResourceThrottle>* throttles);
80
81  // Called when an SSL Client Certificate is requested. If false is returned,
82  // the request is canceled. Otherwise, the certificate is chosen.
83  virtual bool AcceptSSLClientCertificateRequest(
84      net::URLRequest* request,
85      net::SSLCertRequestInfo* cert_request_info);
86
87  // Called when authentication is required and credentials are needed. If
88  // false is returned, CancelAuth() is called on the URLRequest and the error
89  // page is shown. If true is returned, the user will be prompted for
90  // authentication credentials.
91  virtual bool AcceptAuthRequest(net::URLRequest* request,
92                                 net::AuthChallengeInfo* auth_info);
93
94  // Creates a ResourceDispatcherHostLoginDelegate that asks the user for a
95  // username and password.
96  virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
97      net::AuthChallengeInfo* auth_info, net::URLRequest* request);
98
99  // Launches the url for the given tab. Returns true if an attempt to handle
100  // the url was made, e.g. by launching an app. Note that this does not
101  // guarantee that the app successfully handled it.
102  virtual bool HandleExternalProtocol(const GURL& url,
103                                      int child_id,
104                                      int route_id);
105
106  // Returns true if we should force the given resource to be downloaded.
107  // Otherwise, the content layer decides.
108  virtual bool ShouldForceDownloadResource(
109      const GURL& url, const std::string& mime_type);
110
111  // Returns true and sets |security_origin| and |target_id| if a Stream should
112  // be created for the resource.
113  // If true is returned, a new Stream will be created and OnStreamCreated will
114  // be called with the |target_id| returned by this function and a URL to read
115  // the Stream which is accessible from the |security_origin| returned by this
116  // function.
117  virtual bool ShouldInterceptResourceAsStream(
118      content::ResourceContext* resource_context,
119      const GURL& url,
120      const std::string& mime_type,
121      GURL* security_origin,
122      std::string* target_id);
123
124  // Informs the delegate that a stream was created. |target_id| will be filled
125  // with the parameter returned by ShouldInterceptResourceAsStream(). The
126  // Stream can be read from the blob URL owned by |stream|, but can only be
127  // read once.
128  virtual void OnStreamCreated(
129      content::ResourceContext* resource_context,
130      int render_process_id,
131      int render_view_id,
132      const std::string& target_id,
133      scoped_ptr<StreamHandle> stream,
134      int64 expected_content_size);
135
136  // Informs the delegate that a response has started.
137  virtual void OnResponseStarted(
138      net::URLRequest* request,
139      ResourceContext* resource_context,
140      ResourceResponse* response,
141      IPC::Sender* sender);
142
143  // Informs the delegate that a request has been redirected.
144  virtual void OnRequestRedirected(
145      const GURL& redirect_url,
146      net::URLRequest* request,
147      ResourceContext* resource_context,
148      ResourceResponse* response);
149
150 protected:
151  ResourceDispatcherHostDelegate();
152  virtual ~ResourceDispatcherHostDelegate();
153};
154
155}  // namespace content
156
157#endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
158