resource_dispatcher_host_delegate.h revision 116680a4aac90f2aa7413d9095a592090648e557
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 "content/public/common/resource_type.h"
14
15class GURL;
16template <class T> class ScopedVector;
17
18namespace IPC {
19class Sender;
20}
21
22namespace net {
23class AuthChallengeInfo;
24class URLRequest;
25}
26
27namespace content {
28
29class AppCacheService;
30class ResourceContext;
31class ResourceDispatcherHostLoginDelegate;
32class ResourceThrottle;
33class StreamHandle;
34struct Referrer;
35struct ResourceResponse;
36
37// Interface that the embedder provides to ResourceDispatcherHost to allow
38// observing and modifying requests.
39class CONTENT_EXPORT ResourceDispatcherHostDelegate {
40 public:
41  // Called when a request begins. Return false to abort the request.
42  virtual bool ShouldBeginRequest(
43      int child_id,
44      int route_id,
45      const std::string& method,
46      const GURL& url,
47      ResourceType::Type resource_type,
48      ResourceContext* resource_context);
49
50  // Called after ShouldBeginRequest to allow the embedder to add resource
51  // throttles.
52  virtual void RequestBeginning(
53      net::URLRequest* request,
54      ResourceContext* resource_context,
55      AppCacheService* appcache_service,
56      ResourceType::Type resource_type,
57      int child_id,
58      int route_id,
59      ScopedVector<ResourceThrottle>* throttles);
60
61  // Allows an embedder to add additional resource handlers for a download.
62  // |must_download| is set if the request must be handled as a download.
63  virtual void DownloadStarting(
64      net::URLRequest* request,
65      ResourceContext* resource_context,
66      int child_id,
67      int route_id,
68      int request_id,
69      bool is_content_initiated,
70      bool must_download,
71      ScopedVector<ResourceThrottle>* throttles);
72
73  // Creates a ResourceDispatcherHostLoginDelegate that asks the user for a
74  // username and password.
75  virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
76      net::AuthChallengeInfo* auth_info, net::URLRequest* request);
77
78  // Launches the url for the given tab. Returns true if an attempt to handle
79  // the url was made, e.g. by launching an app. Note that this does not
80  // guarantee that the app successfully handled it.
81  // Some external protocol handlers only run in the context of a user gesture,
82  // so initiated_by_user_gesture should be passed accordingly.
83  virtual bool HandleExternalProtocol(const GURL& url,
84                                      int child_id,
85                                      int route_id,
86                                      bool initiated_by_user_gesture);
87
88  // Returns true if we should force the given resource to be downloaded.
89  // Otherwise, the content layer decides.
90  virtual bool ShouldForceDownloadResource(
91      const GURL& url, const std::string& mime_type);
92
93  // Returns true and sets |origin| if a Stream should be created for the
94  // resource.
95  // If true is returned, a new Stream will be created and OnStreamCreated()
96  // will be called with
97  // - a StreamHandle instance for the Stream. The handle contains the URL for
98  //   reading the Stream etc.
99  // The Stream's origin will be set to |origin|.
100  //
101  // If the stream will be rendered in a BrowserPlugin, |payload| will contain
102  // the data that should be given to the old ResourceHandler to forward to the
103  // renderer process.
104  virtual bool ShouldInterceptResourceAsStream(
105      net::URLRequest* request,
106      const std::string& mime_type,
107      GURL* origin,
108      std::string* payload);
109
110  // Informs the delegate that a Stream was created. The Stream can be read from
111  // the blob URL of the Stream, but can only be read once.
112  virtual void OnStreamCreated(
113      net::URLRequest* request,
114      scoped_ptr<content::StreamHandle> stream);
115
116  // Informs the delegate that a response has started.
117  virtual void OnResponseStarted(
118      net::URLRequest* request,
119      ResourceContext* resource_context,
120      ResourceResponse* response,
121      IPC::Sender* sender);
122
123  // Informs the delegate that a request has been redirected.
124  virtual void OnRequestRedirected(
125      const GURL& redirect_url,
126      net::URLRequest* request,
127      ResourceContext* resource_context,
128      ResourceResponse* response);
129
130  // Notification that a request has completed.
131  virtual void RequestComplete(net::URLRequest* url_request);
132
133 protected:
134  ResourceDispatcherHostDelegate();
135  virtual ~ResourceDispatcherHostDelegate();
136};
137
138}  // namespace content
139
140#endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
141