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 ANDROID_WEBVIEW_LIB_RENDERER_HOST_AW_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 6 #define ANDROID_WEBVIEW_LIB_RENDERER_HOST_AW_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 7 8 #include <map> 9 10 #include "base/lazy_instance.h" 11 #include "content/public/browser/resource_dispatcher_host_delegate.h" 12 13 namespace content { 14 class ResourceDispatcherHostLoginDelegate; 15 struct ResourceResponse; 16 } // namespace content 17 18 namespace IPC { 19 class Sender; 20 } // namespace IPC 21 22 namespace android_webview { 23 24 class IoThreadClientThrottle; 25 26 class AwResourceDispatcherHostDelegate 27 : public content::ResourceDispatcherHostDelegate { 28 public: 29 static void ResourceDispatcherHostCreated(); 30 31 // Overriden methods from ResourceDispatcherHostDelegate. 32 virtual void RequestBeginning( 33 net::URLRequest* request, 34 content::ResourceContext* resource_context, 35 appcache::AppCacheService* appcache_service, 36 ResourceType::Type resource_type, 37 int child_id, 38 int route_id, 39 bool is_continuation_of_transferred_request, 40 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE; 41 virtual void DownloadStarting( 42 net::URLRequest* request, 43 content::ResourceContext* resource_context, 44 int child_id, 45 int route_id, 46 int request_id, 47 bool is_content_initiated, 48 bool must_download, 49 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE; 50 virtual bool AcceptAuthRequest(net::URLRequest* request, 51 net::AuthChallengeInfo* auth_info) OVERRIDE; 52 virtual bool AcceptSSLClientCertificateRequest( 53 net::URLRequest* request, 54 net::SSLCertRequestInfo* cert_info) OVERRIDE; 55 56 virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 57 net::AuthChallengeInfo* auth_info, 58 net::URLRequest* request) OVERRIDE; 59 virtual bool HandleExternalProtocol(const GURL& url, 60 int child_id, 61 int route_id) OVERRIDE; 62 virtual void OnResponseStarted( 63 net::URLRequest* request, 64 content::ResourceContext* resource_context, 65 content::ResourceResponse* response, 66 IPC::Sender* sender) OVERRIDE; 67 68 void RemovePendingThrottleOnIoThread(IoThreadClientThrottle* throttle); 69 70 static void OnIoThreadClientReady(int new_child_id, int new_route_id); 71 static void AddPendingThrottle(int child_id, 72 int route_id, 73 IoThreadClientThrottle* pending_throttle); 74 75 private: 76 friend struct base::DefaultLazyInstanceTraits< 77 AwResourceDispatcherHostDelegate>; 78 AwResourceDispatcherHostDelegate(); 79 virtual ~AwResourceDispatcherHostDelegate(); 80 81 // These methods must be called on IO thread. 82 void OnIoThreadClientReadyInternal(int child_id, int route_id); 83 void AddPendingThrottleOnIoThread(int child_id, 84 int route_id, 85 IoThreadClientThrottle* pending_throttle); 86 87 typedef std::pair<int, int> ChildRouteIDPair; 88 typedef std::map<ChildRouteIDPair, IoThreadClientThrottle*> 89 PendingThrottleMap; 90 91 // Only accessed on the IO thread. 92 PendingThrottleMap pending_throttles_; 93 94 DISALLOW_COPY_AND_ASSIGN(AwResourceDispatcherHostDelegate); 95 }; 96 97 } // namespace android_webview 98 99 #endif // ANDROID_WEBVIEW_LIB_RENDERER_HOST_AW_RESOURCE_DISPATCHER_HOST_H_ 100