resource_dispatcher_host_delegate.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 "webkit/common/resource_type.h"
14
15class GURL;
16template <class T> class ScopedVector;
17
18namespace appcache {
19class AppCacheService;
20}
21
22namespace content {
23class ResourceContext;
24class ResourceThrottle;
25class StreamHandle;
26struct Referrer;
27struct ResourceResponse;
28}
29
30namespace IPC {
31class Sender;
32}
33
34namespace net {
35class AuthChallengeInfo;
36class URLRequest;
37}
38
39namespace content {
40
41class ResourceDispatcherHostLoginDelegate;
42
43// Interface that the embedder provides to ResourceDispatcherHost to allow
44// observing and modifying requests.
45class CONTENT_EXPORT ResourceDispatcherHostDelegate {
46 public:
47  // Called when a request begins. Return false to abort the request.
48  virtual bool ShouldBeginRequest(
49      int child_id,
50      int route_id,
51      const std::string& method,
52      const GURL& url,
53      ResourceType::Type resource_type,
54      ResourceContext* resource_context);
55
56  // Called after ShouldBeginRequest to allow the embedder to add resource
57  // throttles.
58  virtual void RequestBeginning(
59      net::URLRequest* request,
60      ResourceContext* resource_context,
61      appcache::AppCacheService* appcache_service,
62      ResourceType::Type resource_type,
63      int child_id,
64      int route_id,
65      ScopedVector<ResourceThrottle>* throttles);
66
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,
72      int child_id,
73      int route_id,
74      int request_id,
75      bool is_content_initiated,
76      bool must_download,
77      ScopedVector<ResourceThrottle>* throttles);
78
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);
83
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  virtual bool HandleExternalProtocol(const GURL& url,
88                                      int child_id,
89                                      int route_id);
90
91  // Returns true if we should force the given resource to be downloaded.
92  // Otherwise, the content layer decides.
93  virtual bool ShouldForceDownloadResource(
94      const GURL& url, const std::string& mime_type);
95
96  // Returns true and sets |origin| and |target_id| if a Stream should be
97  // created for the resource.
98  // If true is returned, a new Stream will be created and OnStreamCreated()
99  // will be called with
100  // - the |target_id| returned by this function
101  // - a StreamHandle instance for the Stream. The handle contains the URL for
102  //   reading the Stream etc.
103  // The Stream's origin will be set to |origin|.
104  virtual bool ShouldInterceptResourceAsStream(
105      content::ResourceContext* resource_context,
106      const GURL& url,
107      const std::string& mime_type,
108      GURL* origin,
109      std::string* target_id);
110
111  // Informs the delegate that a Stream was created. |target_id| will be filled
112  // with the parameter returned by ShouldInterceptResourceAsStream(). The
113  // Stream can be read from the blob URL of the Stream, but can only be read
114  // once.
115  virtual void OnStreamCreated(
116      content::ResourceContext* resource_context,
117      int render_process_id,
118      int render_view_id,
119      const std::string& target_id,
120      scoped_ptr<StreamHandle> stream,
121      int64 expected_content_size);
122
123  // Informs the delegate that a response has started.
124  virtual void OnResponseStarted(
125      net::URLRequest* request,
126      ResourceContext* resource_context,
127      ResourceResponse* response,
128      IPC::Sender* sender);
129
130  // Informs the delegate that a request has been redirected.
131  virtual void OnRequestRedirected(
132      const GURL& redirect_url,
133      net::URLRequest* request,
134      ResourceContext* resource_context,
135      ResourceResponse* response);
136
137  // Notification that a request has completed.
138  virtual void RequestComplete(net::URLRequest* url_request);
139
140 protected:
141  ResourceDispatcherHostDelegate();
142  virtual ~ResourceDispatcherHostDelegate();
143};
144
145}  // namespace content
146
147#endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
148