chrome_resource_dispatcher_host_delegate.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
6#define CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
7
8#include <set>
9
10#include "base/compiler_specific.h"
11#include "base/memory/ref_counted.h"
12#include "content/public/browser/resource_dispatcher_host_delegate.h"
13
14class DelayedResourceQueue;
15class DownloadRequestLimiter;
16class SafeBrowsingService;
17
18namespace extensions {
19class UserScriptListener;
20}
21
22namespace prerender {
23class PrerenderTracker;
24}
25
26// Implements ResourceDispatcherHostDelegate. Currently used by the Prerender
27// system to abort requests and add to the load flags when a request begins.
28class ChromeResourceDispatcherHostDelegate
29    : public content::ResourceDispatcherHostDelegate {
30 public:
31  // This class does not take ownership of the tracker but merely holds a
32  // reference to it to avoid accessing g_browser_process.
33  // |prerender_tracker| must outlive |this|.
34  explicit ChromeResourceDispatcherHostDelegate(
35      prerender::PrerenderTracker* prerender_tracker);
36  virtual ~ChromeResourceDispatcherHostDelegate();
37
38  // ResourceDispatcherHostDelegate implementation.
39  virtual bool ShouldBeginRequest(
40      int child_id,
41      int route_id,
42      const std::string& method,
43      const GURL& url,
44      ResourceType::Type resource_type,
45      content::ResourceContext* resource_context) OVERRIDE;
46  virtual void RequestBeginning(
47      net::URLRequest* request,
48      content::ResourceContext* resource_context,
49      appcache::AppCacheService* appcache_service,
50      ResourceType::Type resource_type,
51      int child_id,
52      int route_id,
53      bool is_continuation_of_transferred_request,
54      ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
55  virtual void DownloadStarting(
56      net::URLRequest* request,
57      content::ResourceContext* resource_context,
58      int child_id,
59      int route_id,
60      int request_id,
61      bool is_content_initiated,
62      bool must_download,
63      ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
64  virtual bool AcceptSSLClientCertificateRequest(
65        net::URLRequest* request,
66        net::SSLCertRequestInfo* cert_request_info) OVERRIDE;
67  virtual bool AcceptAuthRequest(net::URLRequest* request,
68                                 net::AuthChallengeInfo* auth_info) OVERRIDE;
69  virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
70      net::AuthChallengeInfo* auth_info, net::URLRequest* request) OVERRIDE;
71  virtual bool HandleExternalProtocol(const GURL& url,
72                                      int child_id,
73                                      int route_id) OVERRIDE;
74  virtual bool ShouldForceDownloadResource(
75      const GURL& url, const std::string& mime_type) OVERRIDE;
76  virtual bool ShouldInterceptResourceAsStream(
77      content::ResourceContext* resource_context,
78      const GURL& url,
79      const std::string& mime_type,
80      GURL* security_origin,
81      std::string* target_id) OVERRIDE;
82  virtual void OnStreamCreated(
83      content::ResourceContext* resource_context,
84      int render_process_id,
85      int render_view_id,
86      const std::string& target_id,
87      scoped_ptr<content::StreamHandle> stream,
88      int64 expected_content_size) OVERRIDE;
89  virtual void OnResponseStarted(
90      net::URLRequest* request,
91      content::ResourceContext* resource_context,
92      content::ResourceResponse* response,
93      IPC::Sender* sender) OVERRIDE;
94  virtual void OnRequestRedirected(
95      const GURL& redirect_url,
96      net::URLRequest* request,
97      content::ResourceContext* resource_context,
98      content::ResourceResponse* response) OVERRIDE;
99
100 private:
101  void AppendStandardResourceThrottles(
102      net::URLRequest* request,
103      content::ResourceContext* resource_context,
104      int child_id,
105      int route_id,
106      ResourceType::Type resource_type,
107      ScopedVector<content::ResourceThrottle>* throttles);
108
109  // Adds Chrome experiment and metrics state as custom headers to |request|.
110  // This is a best-effort attempt, and does not interrupt the request if the
111  // headers can not be appended.
112  void AppendChromeMetricsHeaders(
113      net::URLRequest* request,
114      content::ResourceContext* resource_context,
115      ResourceType::Type resource_type);
116
117#if defined(ENABLE_ONE_CLICK_SIGNIN)
118  // Append headers required to tell Gaia whether the sync interstitial
119  // should be shown or not.  This header is only added for valid Gaia URLs.
120  void AppendChromeSyncGaiaHeader(
121      net::URLRequest* request,
122      content::ResourceContext* resource_context);
123#endif
124
125  scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
126  scoped_refptr<SafeBrowsingService> safe_browsing_;
127  scoped_refptr<extensions::UserScriptListener> user_script_listener_;
128  prerender::PrerenderTracker* prerender_tracker_;
129
130  DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate);
131};
132
133#endif  // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
134