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 "content/public/common/resource_type.h"
16 template <class T
> class ScopedVector
;
23 class AuthChallengeInfo
;
29 class AppCacheService
;
30 class ResourceContext
;
31 class ResourceDispatcherHostLoginDelegate
;
32 class ResourceThrottle
;
34 struct ResourceResponse
;
37 // Interface that the embedder provides to ResourceDispatcherHost to allow
38 // observing and modifying requests.
39 class CONTENT_EXPORT ResourceDispatcherHostDelegate
{
41 // Called when a request begins. Return false to abort the request.
42 virtual bool ShouldBeginRequest(const std::string
& method
,
44 ResourceType resource_type
,
45 ResourceContext
* resource_context
);
47 // Called after ShouldBeginRequest to allow the embedder to add resource
49 virtual void RequestBeginning(net::URLRequest
* request
,
50 ResourceContext
* resource_context
,
51 AppCacheService
* appcache_service
,
52 ResourceType resource_type
,
53 ScopedVector
<ResourceThrottle
>* throttles
);
55 // Allows an embedder to add additional resource handlers for a download.
56 // |must_download| is set if the request must be handled as a download.
57 virtual void DownloadStarting(net::URLRequest
* request
,
58 ResourceContext
* resource_context
,
62 bool is_content_initiated
,
64 ScopedVector
<ResourceThrottle
>* throttles
);
66 // Creates a ResourceDispatcherHostLoginDelegate that asks the user for a
67 // username and password.
68 virtual ResourceDispatcherHostLoginDelegate
* CreateLoginDelegate(
69 net::AuthChallengeInfo
* auth_info
,
70 net::URLRequest
* request
);
72 // Launches the url for the given tab. Returns true if an attempt to handle
73 // the url was made, e.g. by launching an app. Note that this does not
74 // guarantee that the app successfully handled it.
75 virtual bool HandleExternalProtocol(const GURL
& url
,
79 // Returns true if we should force the given resource to be downloaded.
80 // Otherwise, the content layer decides.
81 virtual bool ShouldForceDownloadResource(const GURL
& url
,
82 const std::string
& mime_type
);
84 // Returns true and sets |origin| if a Stream should be created for the
86 // If true is returned, a new Stream will be created and OnStreamCreated()
87 // will be called with
88 // - a StreamHandle instance for the Stream. The handle contains the URL for
89 // reading the Stream etc.
90 // The Stream's origin will be set to |origin|.
92 // If the stream will be rendered in a BrowserPlugin, |payload| will contain
93 // the data that should be given to the old ResourceHandler to forward to the
95 virtual bool ShouldInterceptResourceAsStream(net::URLRequest
* request
,
96 const std::string
& mime_type
,
98 std::string
* payload
);
100 // Informs the delegate that a Stream was created. The Stream can be read from
101 // the blob URL of the Stream, but can only be read once.
102 virtual void OnStreamCreated(net::URLRequest
* request
,
103 scoped_ptr
<content::StreamInfo
> stream
);
105 // Informs the delegate that a response has started.
106 virtual void OnResponseStarted(net::URLRequest
* request
,
107 ResourceContext
* resource_context
,
108 ResourceResponse
* response
,
109 IPC::Sender
* sender
);
111 // Informs the delegate that a request has been redirected.
112 virtual void OnRequestRedirected(const GURL
& redirect_url
,
113 net::URLRequest
* request
,
114 ResourceContext
* resource_context
,
115 ResourceResponse
* response
);
117 // Notification that a request has completed.
118 virtual void RequestComplete(net::URLRequest
* url_request
);
121 ResourceDispatcherHostDelegate();
122 virtual ~ResourceDispatcherHostDelegate();
125 } // namespace content
127 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_