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_
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/external_protocol/external_protocol_handler.h"
14 #include "content/public/browser/resource_dispatcher_host_delegate.h"
16 class DelayedResourceQueue
;
17 class DownloadRequestLimiter
;
18 class SafeBrowsingService
;
20 namespace extensions
{
21 class UserScriptListener
;
25 class PrerenderTracker
;
28 // Implements ResourceDispatcherHostDelegate. Currently used by the Prerender
29 // system to abort requests and add to the load flags when a request begins.
30 class ChromeResourceDispatcherHostDelegate
31 : public content::ResourceDispatcherHostDelegate
{
33 // This class does not take ownership of the tracker but merely holds a
34 // reference to it to avoid accessing g_browser_process.
35 // |prerender_tracker| must outlive |this|.
36 explicit ChromeResourceDispatcherHostDelegate(
37 prerender::PrerenderTracker
* prerender_tracker
);
38 virtual ~ChromeResourceDispatcherHostDelegate();
40 // ResourceDispatcherHostDelegate implementation.
41 virtual bool ShouldBeginRequest(
42 const std::string
& method
,
44 content::ResourceType resource_type
,
45 content::ResourceContext
* resource_context
) override
;
46 virtual void RequestBeginning(
47 net::URLRequest
* request
,
48 content::ResourceContext
* resource_context
,
49 content::AppCacheService
* appcache_service
,
50 content::ResourceType resource_type
,
51 ScopedVector
<content::ResourceThrottle
>* throttles
) override
;
52 virtual void DownloadStarting(
53 net::URLRequest
* request
,
54 content::ResourceContext
* resource_context
,
58 bool is_content_initiated
,
60 ScopedVector
<content::ResourceThrottle
>* throttles
) override
;
61 virtual content::ResourceDispatcherHostLoginDelegate
* CreateLoginDelegate(
62 net::AuthChallengeInfo
* auth_info
, net::URLRequest
* request
) override
;
63 virtual bool HandleExternalProtocol(const GURL
& url
,
65 int route_id
) override
;
66 virtual bool ShouldForceDownloadResource(
67 const GURL
& url
, const std::string
& mime_type
) override
;
68 virtual bool ShouldInterceptResourceAsStream(
69 net::URLRequest
* request
,
70 const std::string
& mime_type
,
72 std::string
* payload
) override
;
73 virtual void OnStreamCreated(
74 net::URLRequest
* request
,
75 scoped_ptr
<content::StreamInfo
> stream
) override
;
76 virtual void OnResponseStarted(
77 net::URLRequest
* request
,
78 content::ResourceContext
* resource_context
,
79 content::ResourceResponse
* response
,
80 IPC::Sender
* sender
) override
;
81 virtual void OnRequestRedirected(
82 const GURL
& redirect_url
,
83 net::URLRequest
* request
,
84 content::ResourceContext
* resource_context
,
85 content::ResourceResponse
* response
) override
;
86 virtual void RequestComplete(net::URLRequest
* url_request
) override
;
88 // Called on the UI thread. Allows switching out the
89 // ExternalProtocolHandler::Delegate for testing code.
90 static void SetExternalProtocolHandlerDelegateForTesting(
91 ExternalProtocolHandler::Delegate
* delegate
);
94 #if defined(ENABLE_EXTENSIONS)
95 struct StreamTargetInfo
{
96 std::string extension_id
;
101 void AppendStandardResourceThrottles(
102 net::URLRequest
* request
,
103 content::ResourceContext
* resource_context
,
104 content::ResourceType resource_type
,
105 ScopedVector
<content::ResourceThrottle
>* throttles
);
107 #if defined(ENABLE_ONE_CLICK_SIGNIN)
108 // Append headers required to tell Gaia whether the sync interstitial
109 // should be shown or not. This header is only added for valid Gaia URLs.
110 void AppendChromeSyncGaiaHeader(
111 net::URLRequest
* request
,
112 content::ResourceContext
* resource_context
);
115 scoped_refptr
<DownloadRequestLimiter
> download_request_limiter_
;
116 scoped_refptr
<SafeBrowsingService
> safe_browsing_
;
117 #if defined(ENABLE_EXTENSIONS)
118 scoped_refptr
<extensions::UserScriptListener
> user_script_listener_
;
119 std::map
<net::URLRequest
*, StreamTargetInfo
> stream_target_info_
;
121 prerender::PrerenderTracker
* prerender_tracker_
;
123 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate
);
126 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_