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;
41 class ResourceDispatcherHostLoginDelegate;
43 // Interface that the embedder provides to ResourceDispatcherHost to allow
44 // observing and modifying requests.
45 class CONTENT_EXPORT ResourceDispatcherHostDelegate {
47 // Called when a request begins. Return false to abort the request.
48 virtual bool ShouldBeginRequest(
51 const std::string& method,
53 ResourceType::Type resource_type,
54 ResourceContext* resource_context);
56 // Called after ShouldBeginRequest to allow the embedder to add resource
58 virtual void RequestBeginning(
59 net::URLRequest* request,
60 ResourceContext* resource_context,
61 appcache::AppCacheService* appcache_service,
62 ResourceType::Type resource_type,
65 ScopedVector<ResourceThrottle>* throttles);
67 // Allows an embedder to add additional resource handlers for a download.
68 // |must_download| is set if the request must be handled as a download.
69 virtual void DownloadStarting(
70 net::URLRequest* request,
71 ResourceContext* resource_context,
75 bool is_content_initiated,
77 ScopedVector<ResourceThrottle>* throttles);
79 // Creates a ResourceDispatcherHostLoginDelegate that asks the user for a
80 // username and password.
81 virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
82 net::AuthChallengeInfo* auth_info, net::URLRequest* request);
84 // Launches the url for the given tab. Returns true if an attempt to handle
85 // the url was made, e.g. by launching an app. Note that this does not
86 // guarantee that the app successfully handled it.
87 // Some external protocol handlers only run in the context of a user gesture,
88 // so initiated_by_user_gesture should be passed accordingly.
89 virtual bool HandleExternalProtocol(const GURL& url,
92 bool initiated_by_user_gesture);
94 // Returns true if we should force the given resource to be downloaded.
95 // Otherwise, the content layer decides.
96 virtual bool ShouldForceDownloadResource(
97 const GURL& url, const std::string& mime_type);
99 // Returns true and sets |origin| and |target_id| if a Stream should be
100 // created for the resource.
101 // If true is returned, a new Stream will be created and OnStreamCreated()
102 // will be called with
103 // - the |target_id| returned by this function
104 // - a StreamHandle instance for the Stream. The handle contains the URL for
105 // reading the Stream etc.
106 // The Stream's origin will be set to |origin|.
107 virtual bool ShouldInterceptResourceAsStream(
108 content::ResourceContext* resource_context,
110 const std::string& mime_type,
112 std::string* target_id);
114 // Informs the delegate that a Stream was created. |target_id| will be filled
115 // with the parameter returned by ShouldInterceptResourceAsStream(). The
116 // Stream can be read from the blob URL of the Stream, but can only be read
118 virtual void OnStreamCreated(
119 content::ResourceContext* resource_context,
120 int render_process_id,
122 const std::string& target_id,
123 scoped_ptr<StreamHandle> stream,
124 int64 expected_content_size);
126 // Informs the delegate that a response has started.
127 virtual void OnResponseStarted(
128 net::URLRequest* request,
129 ResourceContext* resource_context,
130 ResourceResponse* response,
131 IPC::Sender* sender);
133 // Informs the delegate that a request has been redirected.
134 virtual void OnRequestRedirected(
135 const GURL& redirect_url,
136 net::URLRequest* request,
137 ResourceContext* resource_context,
138 ResourceResponse* response);
140 // Notification that a request has completed.
141 virtual void RequestComplete(net::URLRequest* url_request);
144 ResourceDispatcherHostDelegate();
145 virtual ~ResourceDispatcherHostDelegate();
148 } // namespace content
150 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_