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 CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
6 #define CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/public/browser/resource_dispatcher_host_delegate.h"
14 class DelayedResourceQueue
;
15 class DownloadRequestLimiter
;
16 class SafeBrowsingService
;
18 namespace extensions
{
19 class UserScriptListener
;
23 class PrerenderTracker
;
26 // Implements ResourceDispatcherHostDelegate. Currently used by the Prerender
27 // system to abort requests and add to the load flags when a request begins.
28 class ChromeResourceDispatcherHostDelegate
29 : public content::ResourceDispatcherHostDelegate
{
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();
38 // ResourceDispatcherHostDelegate implementation.
39 virtual bool ShouldBeginRequest(
42 const std::string
& method
,
44 ResourceType::Type resource_type
,
45 content::ResourceContext
* resource_context
,
46 const content::Referrer
& referrer
) OVERRIDE
;
47 virtual void RequestBeginning(
48 net::URLRequest
* request
,
49 content::ResourceContext
* resource_context
,
50 appcache::AppCacheService
* appcache_service
,
51 ResourceType::Type resource_type
,
54 bool is_continuation_of_transferred_request
,
55 ScopedVector
<content::ResourceThrottle
>* throttles
) OVERRIDE
;
56 virtual void DownloadStarting(
57 net::URLRequest
* request
,
58 content::ResourceContext
* resource_context
,
62 bool is_content_initiated
,
64 ScopedVector
<content::ResourceThrottle
>* throttles
) OVERRIDE
;
65 virtual bool AcceptSSLClientCertificateRequest(
66 net::URLRequest
* request
,
67 net::SSLCertRequestInfo
* cert_request_info
) OVERRIDE
;
68 virtual bool AcceptAuthRequest(net::URLRequest
* request
,
69 net::AuthChallengeInfo
* auth_info
) OVERRIDE
;
70 virtual content::ResourceDispatcherHostLoginDelegate
* CreateLoginDelegate(
71 net::AuthChallengeInfo
* auth_info
, net::URLRequest
* request
) OVERRIDE
;
72 virtual bool HandleExternalProtocol(const GURL
& url
,
74 int route_id
) OVERRIDE
;
75 virtual bool ShouldForceDownloadResource(
76 const GURL
& url
, const std::string
& mime_type
) OVERRIDE
;
77 virtual bool ShouldInterceptResourceAsStream(
78 content::ResourceContext
* resource_context
,
80 const std::string
& mime_type
,
81 GURL
* security_origin
,
82 std::string
* target_id
) OVERRIDE
;
83 virtual void OnStreamCreated(
84 content::ResourceContext
* resource_context
,
85 int render_process_id
,
87 const std::string
& target_id
,
88 scoped_ptr
<content::StreamHandle
> stream
) 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
;
101 void AppendStandardResourceThrottles(
102 net::URLRequest
* request
,
103 content::ResourceContext
* resource_context
,
106 ResourceType::Type resource_type
,
107 ScopedVector
<content::ResourceThrottle
>* throttles
);
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
);
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
);
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_
;
130 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate
);
133 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_