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"
14 #include "ui/base/page_transition_types.h"
17 template <class T
> class ScopedVector
;
24 class AuthChallengeInfo
;
30 class AppCacheService
;
31 class ResourceContext
;
32 class ResourceDispatcherHostLoginDelegate
;
33 class ResourceThrottle
;
35 struct ResourceResponse
;
38 // Interface that the embedder provides to ResourceDispatcherHost to allow
39 // observing and modifying requests.
40 class CONTENT_EXPORT ResourceDispatcherHostDelegate
{
42 // Called when a request begins. Return false to abort the request.
43 virtual bool ShouldBeginRequest(const std::string
& method
,
45 ResourceType resource_type
,
46 ResourceContext
* resource_context
);
48 // Called after ShouldBeginRequest to allow the embedder to add resource
50 virtual void RequestBeginning(net::URLRequest
* request
,
51 ResourceContext
* resource_context
,
52 AppCacheService
* appcache_service
,
53 ResourceType resource_type
,
54 ScopedVector
<ResourceThrottle
>* throttles
);
56 // Allows an embedder to add additional resource handlers for a download.
57 // |must_download| is set if the request must be handled as a download.
58 virtual void DownloadStarting(net::URLRequest
* request
,
59 ResourceContext
* resource_context
,
63 bool is_content_initiated
,
65 ScopedVector
<ResourceThrottle
>* throttles
);
67 // Creates a ResourceDispatcherHostLoginDelegate that asks the user for a
68 // username and password.
69 virtual ResourceDispatcherHostLoginDelegate
* CreateLoginDelegate(
70 net::AuthChallengeInfo
* auth_info
,
71 net::URLRequest
* request
);
73 // Launches the url for the given tab. Returns true if an attempt to handle
74 // the url was made, e.g. by launching an app. Note that this does not
75 // guarantee that the app successfully handled it.
76 virtual bool HandleExternalProtocol(const GURL
& url
,
80 ui::PageTransition page_transition
,
81 bool has_user_gesture
);
83 // Returns true if we should force the given resource to be downloaded.
84 // Otherwise, the content layer decides.
85 virtual bool ShouldForceDownloadResource(const GURL
& url
,
86 const std::string
& mime_type
);
88 // Returns true and sets |origin| if a Stream should be created for the
90 // If true is returned, a new Stream will be created and OnStreamCreated()
91 // will be called with
92 // - a StreamHandle instance for the Stream. The handle contains the URL for
93 // reading the Stream etc.
94 // The Stream's origin will be set to |origin|.
96 // If the stream will be rendered in a BrowserPlugin, |payload| will contain
97 // the data that should be given to the old ResourceHandler to forward to the
99 virtual bool ShouldInterceptResourceAsStream(net::URLRequest
* request
,
100 const std::string
& mime_type
,
102 std::string
* payload
);
104 // Informs the delegate that a Stream was created. The Stream can be read from
105 // the blob URL of the Stream, but can only be read once.
106 virtual void OnStreamCreated(net::URLRequest
* request
,
107 scoped_ptr
<content::StreamInfo
> stream
);
109 // Informs the delegate that a response has started.
110 virtual void OnResponseStarted(net::URLRequest
* request
,
111 ResourceContext
* resource_context
,
112 ResourceResponse
* response
,
113 IPC::Sender
* sender
);
115 // Informs the delegate that a request has been redirected.
116 virtual void OnRequestRedirected(const GURL
& redirect_url
,
117 net::URLRequest
* request
,
118 ResourceContext
* resource_context
,
119 ResourceResponse
* response
);
121 // Notification that a request has completed.
122 virtual void RequestComplete(net::URLRequest
* url_request
);
125 ResourceDispatcherHostDelegate();
126 virtual ~ResourceDispatcherHostDelegate();
129 } // namespace content
131 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_