chrome_resource_dispatcher_host_delegate.h revision 116680a4aac90f2aa7413d9095a592090648e557
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::Type 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::Type 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, 70 bool initiated_by_user_gesture) OVERRIDE; 71 virtual bool ShouldForceDownloadResource( 72 const GURL& url, const std::string& mime_type) OVERRIDE; 73 virtual bool ShouldInterceptResourceAsStream( 74 net::URLRequest* request, 75 const std::string& mime_type, 76 GURL* origin, 77 std::string* payload) OVERRIDE; 78 virtual void OnStreamCreated( 79 net::URLRequest* request, 80 scoped_ptr<content::StreamHandle> stream) OVERRIDE; 81 virtual void OnResponseStarted( 82 net::URLRequest* request, 83 content::ResourceContext* resource_context, 84 content::ResourceResponse* response, 85 IPC::Sender* sender) OVERRIDE; 86 virtual void OnRequestRedirected( 87 const GURL& redirect_url, 88 net::URLRequest* request, 89 content::ResourceContext* resource_context, 90 content::ResourceResponse* response) OVERRIDE; 91 virtual void RequestComplete(net::URLRequest* url_request) OVERRIDE; 92 93 // Called on the UI thread. Allows switching out the 94 // ExternalProtocolHandler::Delegate for testing code. 95 static void SetExternalProtocolHandlerDelegateForTesting( 96 ExternalProtocolHandler::Delegate* delegate); 97 98 private: 99#if defined(ENABLE_EXTENSIONS) 100 struct StreamTargetInfo { 101 std::string extension_id; 102 std::string view_id; 103 }; 104#endif 105 106 void AppendStandardResourceThrottles( 107 net::URLRequest* request, 108 content::ResourceContext* resource_context, 109 content::ResourceType::Type resource_type, 110 ScopedVector<content::ResourceThrottle>* throttles); 111 112#if defined(ENABLE_ONE_CLICK_SIGNIN) 113 // Append headers required to tell Gaia whether the sync interstitial 114 // should be shown or not. This header is only added for valid Gaia URLs. 115 void AppendChromeSyncGaiaHeader( 116 net::URLRequest* request, 117 content::ResourceContext* resource_context); 118#endif 119 120 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; 121 scoped_refptr<SafeBrowsingService> safe_browsing_; 122#if defined(ENABLE_EXTENSIONS) 123 scoped_refptr<extensions::UserScriptListener> user_script_listener_; 124 std::map<net::URLRequest*, StreamTargetInfo> stream_target_info_; 125#endif 126 prerender::PrerenderTracker* prerender_tracker_; 127 128 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate); 129}; 130 131#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 132