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