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.
5 #ifndef CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
6 #define CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
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"
16 template <class T
> class ScopedVector
;
19 class AppCacheService
;
23 class ResourceContext
;
24 class ResourceThrottle
;
27 struct ResourceResponse
;
35 class AuthChallengeInfo
;
36 class SSLCertRequestInfo
;
42 class ResourceDispatcherHostLoginDelegate
;
44 // Interface that the embedder provides to ResourceDispatcherHost to allow
45 // observing and modifying requests.
46 class CONTENT_EXPORT ResourceDispatcherHostDelegate
{
48 // Called when a request begins. Return false to abort the request.
49 virtual bool ShouldBeginRequest(
52 const std::string
& method
,
54 ResourceType::Type resource_type
,
55 ResourceContext
* resource_context
);
57 // Called after ShouldBeginRequest to allow the embedder to add resource
59 virtual void RequestBeginning(
60 net::URLRequest
* request
,
61 ResourceContext
* resource_context
,
62 appcache::AppCacheService
* appcache_service
,
63 ResourceType::Type resource_type
,
66 ScopedVector
<ResourceThrottle
>* throttles
);
68 // Called if a navigation request is transferred from one process to another.
69 virtual void WillTransferRequestToNewProcess(
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
,
85 bool is_content_initiated
,
87 ScopedVector
<ResourceThrottle
>* throttles
);
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
);
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
);
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
);
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
,
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
);
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
,
130 const std::string
& mime_type
,
132 std::string
* target_id
);
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
138 virtual void OnStreamCreated(
139 content::ResourceContext
* resource_context
,
140 int render_process_id
,
142 const std::string
& target_id
,
143 scoped_ptr
<StreamHandle
> stream
,
144 int64 expected_content_size
);
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
);
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
);
161 ResourceDispatcherHostDelegate();
162 virtual ~ResourceDispatcherHostDelegate();
165 } // namespace content
167 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_