chrome_resource_dispatcher_host_delegate.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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, 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, 52 int child_id, 53 int route_id, 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, 59 int child_id, 60 int route_id, 61 int request_id, 62 bool is_content_initiated, 63 bool must_download, 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, 73 int child_id, 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, 79 const GURL& url, 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, 86 int render_view_id, 87 const std::string& target_id, 88 scoped_ptr<content::StreamHandle> stream, 89 int64 expected_content_size) OVERRIDE; 90 virtual void OnResponseStarted( 91 net::URLRequest* request, 92 content::ResourceContext* resource_context, 93 content::ResourceResponse* response, 94 IPC::Sender* sender) OVERRIDE; 95 virtual void OnRequestRedirected( 96 const GURL& redirect_url, 97 net::URLRequest* request, 98 content::ResourceContext* resource_context, 99 content::ResourceResponse* response) OVERRIDE; 100 101 private: 102 void AppendStandardResourceThrottles( 103 net::URLRequest* request, 104 content::ResourceContext* resource_context, 105 int child_id, 106 int route_id, 107 ResourceType::Type resource_type, 108 ScopedVector<content::ResourceThrottle>* throttles); 109 110 // Adds Chrome experiment and metrics state as custom headers to |request|. 111 // This is a best-effort attempt, and does not interrupt the request if the 112 // headers can not be appended. 113 void AppendChromeMetricsHeaders( 114 net::URLRequest* request, 115 content::ResourceContext* resource_context, 116 ResourceType::Type resource_type); 117 118#if defined(ENABLE_ONE_CLICK_SIGNIN) 119 // Append headers required to tell Gaia whether the sync interstitial 120 // should be shown or not. This header is only added for valid Gaia URLs. 121 void AppendChromeSyncGaiaHeader( 122 net::URLRequest* request, 123 content::ResourceContext* resource_context); 124#endif 125 126 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; 127 scoped_refptr<SafeBrowsingService> safe_browsing_; 128 scoped_refptr<extensions::UserScriptListener> user_script_listener_; 129 prerender::PrerenderTracker* prerender_tracker_; 130 131 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate); 132}; 133 134#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 135