chrome_resource_dispatcher_host_delegate.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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 <map> 9#include <set> 10 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" 15 16class DelayedResourceQueue; 17class DownloadRequestLimiter; 18class SafeBrowsingService; 19 20namespace extensions { 21class UserScriptListener; 22} 23 24namespace prerender { 25class PrerenderTracker; 26} 27 28// Implements ResourceDispatcherHostDelegate. Currently used by the Prerender 29// system to abort requests and add to the load flags when a request begins. 30class ChromeResourceDispatcherHostDelegate 31 : public content::ResourceDispatcherHostDelegate { 32 public: 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(); 39 40 // ResourceDispatcherHostDelegate implementation. 41 virtual bool ShouldBeginRequest( 42 int child_id, 43 int route_id, 44 const std::string& method, 45 const GURL& url, 46 content::ResourceType resource_type, 47 content::ResourceContext* resource_context) OVERRIDE; 48 virtual void RequestBeginning( 49 net::URLRequest* request, 50 content::ResourceContext* resource_context, 51 content::AppCacheService* appcache_service, 52 content::ResourceType resource_type, 53 int child_id, 54 int route_id, 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 content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 66 net::AuthChallengeInfo* auth_info, net::URLRequest* request) OVERRIDE; 67 virtual bool HandleExternalProtocol(const GURL& url, 68 int child_id, 69 int route_id) OVERRIDE; 70 virtual bool ShouldForceDownloadResource( 71 const GURL& url, const std::string& mime_type) OVERRIDE; 72 virtual bool ShouldInterceptResourceAsStream( 73 net::URLRequest* request, 74 const std::string& mime_type, 75 GURL* origin, 76 std::string* payload) OVERRIDE; 77 virtual void OnStreamCreated( 78 net::URLRequest* request, 79 scoped_ptr<content::StreamHandle> stream) OVERRIDE; 80 virtual void OnResponseStarted( 81 net::URLRequest* request, 82 content::ResourceContext* resource_context, 83 content::ResourceResponse* response, 84 IPC::Sender* sender) OVERRIDE; 85 virtual void OnRequestRedirected( 86 const GURL& redirect_url, 87 net::URLRequest* request, 88 content::ResourceContext* resource_context, 89 content::ResourceResponse* response) OVERRIDE; 90 virtual void RequestComplete(net::URLRequest* url_request) OVERRIDE; 91 92 // Called on the UI thread. Allows switching out the 93 // ExternalProtocolHandler::Delegate for testing code. 94 static void SetExternalProtocolHandlerDelegateForTesting( 95 ExternalProtocolHandler::Delegate* delegate); 96 97 private: 98#if defined(ENABLE_EXTENSIONS) 99 struct StreamTargetInfo { 100 std::string extension_id; 101 std::string view_id; 102 }; 103#endif 104 105 void AppendStandardResourceThrottles( 106 net::URLRequest* request, 107 content::ResourceContext* resource_context, 108 content::ResourceType resource_type, 109 ScopedVector<content::ResourceThrottle>* throttles); 110 111#if defined(ENABLE_ONE_CLICK_SIGNIN) 112 // Append headers required to tell Gaia whether the sync interstitial 113 // should be shown or not. This header is only added for valid Gaia URLs. 114 void AppendChromeSyncGaiaHeader( 115 net::URLRequest* request, 116 content::ResourceContext* resource_context); 117#endif 118 119 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; 120 scoped_refptr<SafeBrowsingService> safe_browsing_; 121#if defined(ENABLE_EXTENSIONS) 122 scoped_refptr<extensions::UserScriptListener> user_script_listener_; 123 std::map<net::URLRequest*, StreamTargetInfo> stream_target_info_; 124#endif 125 prerender::PrerenderTracker* prerender_tracker_; 126 127 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate); 128}; 129 130#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 131