chrome_resource_dispatcher_host_delegate.h revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE; 54 virtual void WillTransferRequestToNewProcess( 55 int old_child_id, 56 int old_route_id, 57 int old_request_id, 58 int new_child_id, 59 int new_route_id, 60 int new_request_id) OVERRIDE; 61 virtual void DownloadStarting( 62 net::URLRequest* request, 63 content::ResourceContext* resource_context, 64 int child_id, 65 int route_id, 66 int request_id, 67 bool is_content_initiated, 68 bool must_download, 69 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE; 70 virtual bool AcceptSSLClientCertificateRequest( 71 net::URLRequest* request, 72 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; 73 virtual bool AcceptAuthRequest(net::URLRequest* request, 74 net::AuthChallengeInfo* auth_info) OVERRIDE; 75 virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 76 net::AuthChallengeInfo* auth_info, net::URLRequest* request) OVERRIDE; 77 virtual bool HandleExternalProtocol(const GURL& url, 78 int child_id, 79 int route_id) OVERRIDE; 80 virtual bool ShouldForceDownloadResource( 81 const GURL& url, const std::string& mime_type) OVERRIDE; 82 virtual bool ShouldInterceptResourceAsStream( 83 content::ResourceContext* resource_context, 84 const GURL& url, 85 const std::string& mime_type, 86 GURL* origin, 87 std::string* target_id) OVERRIDE; 88 virtual void OnStreamCreated( 89 content::ResourceContext* resource_context, 90 int render_process_id, 91 int render_view_id, 92 const std::string& target_id, 93 scoped_ptr<content::StreamHandle> stream, 94 int64 expected_content_size) OVERRIDE; 95 virtual void OnResponseStarted( 96 net::URLRequest* request, 97 content::ResourceContext* resource_context, 98 content::ResourceResponse* response, 99 IPC::Sender* sender) OVERRIDE; 100 virtual void OnRequestRedirected( 101 const GURL& redirect_url, 102 net::URLRequest* request, 103 content::ResourceContext* resource_context, 104 content::ResourceResponse* response) OVERRIDE; 105 106 private: 107 void AppendStandardResourceThrottles( 108 net::URLRequest* request, 109 content::ResourceContext* resource_context, 110 ResourceType::Type resource_type, 111 ScopedVector<content::ResourceThrottle>* throttles); 112 113 // Adds Chrome experiment and metrics state as custom headers to |request|. 114 // This is a best-effort attempt, and does not interrupt the request if the 115 // headers can not be appended. 116 void AppendChromeMetricsHeaders( 117 net::URLRequest* request, 118 content::ResourceContext* resource_context, 119 ResourceType::Type resource_type); 120 121#if defined(ENABLE_ONE_CLICK_SIGNIN) 122 // Append headers required to tell Gaia whether the sync interstitial 123 // should be shown or not. This header is only added for valid Gaia URLs. 124 void AppendChromeSyncGaiaHeader( 125 net::URLRequest* request, 126 content::ResourceContext* resource_context); 127#endif 128 129 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; 130 scoped_refptr<SafeBrowsingService> safe_browsing_; 131 scoped_refptr<extensions::UserScriptListener> user_script_listener_; 132 prerender::PrerenderTracker* prerender_tracker_; 133 134 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate); 135}; 136 137#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 138