- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / browser / renderer_host / aw_resource_dispatcher_host_delegate.h
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       ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
40   virtual void DownloadStarting(
41       net::URLRequest* request,
42       content::ResourceContext* resource_context,
43       int child_id,
44       int route_id,
45       int request_id,
46       bool is_content_initiated,
47       bool must_download,
48       ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
49   virtual bool AcceptAuthRequest(net::URLRequest* request,
50                                  net::AuthChallengeInfo* auth_info) OVERRIDE;
51   virtual bool AcceptSSLClientCertificateRequest(
52       net::URLRequest* request,
53       net::SSLCertRequestInfo* cert_info) OVERRIDE;
54
55   virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
56       net::AuthChallengeInfo* auth_info,
57       net::URLRequest* request) OVERRIDE;
58   virtual bool HandleExternalProtocol(const GURL& url,
59                                       int child_id,
60                                       int route_id) OVERRIDE;
61   virtual void OnResponseStarted(
62       net::URLRequest* request,
63       content::ResourceContext* resource_context,
64       content::ResourceResponse* response,
65       IPC::Sender* sender) OVERRIDE;
66
67   void RemovePendingThrottleOnIoThread(IoThreadClientThrottle* throttle);
68
69   static void OnIoThreadClientReady(int new_child_id, int new_route_id);
70   static void AddPendingThrottle(int child_id,
71                                  int route_id,
72                                  IoThreadClientThrottle* pending_throttle);
73
74  private:
75   friend struct base::DefaultLazyInstanceTraits<
76       AwResourceDispatcherHostDelegate>;
77   AwResourceDispatcherHostDelegate();
78   virtual ~AwResourceDispatcherHostDelegate();
79
80   // These methods must be called on IO thread.
81   void OnIoThreadClientReadyInternal(int child_id, int route_id);
82   void AddPendingThrottleOnIoThread(int child_id,
83                                     int route_id,
84                                     IoThreadClientThrottle* pending_throttle);
85
86   typedef std::pair<int, int> ChildRouteIDPair;
87   typedef std::map<ChildRouteIDPair, IoThreadClientThrottle*>
88       PendingThrottleMap;
89
90   // Only accessed on the IO thread.
91   PendingThrottleMap pending_throttles_;
92
93   DISALLOW_COPY_AND_ASSIGN(AwResourceDispatcherHostDelegate);
94 };
95
96 }  // namespace android_webview
97
98 #endif  // ANDROID_WEBVIEW_LIB_RENDERER_HOST_AW_RESOURCE_DISPATCHER_HOST_H_