Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / renderer_host / chrome_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 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
16 class DelayedResourceQueue;
17 class DownloadRequestLimiter;
18 class SafeBrowsingService;
19
20 namespace extensions {
21 class UserScriptListener;
22 }
23
24 namespace prerender {
25 class 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.
30 class 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   ~ChromeResourceDispatcherHostDelegate() override;
39
40   // ResourceDispatcherHostDelegate implementation.
41   bool ShouldBeginRequest(const std::string& method,
42                           const GURL& url,
43                           content::ResourceType resource_type,
44                           content::ResourceContext* resource_context) override;
45   void RequestBeginning(
46       net::URLRequest* request,
47       content::ResourceContext* resource_context,
48       content::AppCacheService* appcache_service,
49       content::ResourceType resource_type,
50       ScopedVector<content::ResourceThrottle>* throttles) override;
51   void DownloadStarting(
52       net::URLRequest* request,
53       content::ResourceContext* resource_context,
54       int child_id,
55       int route_id,
56       int request_id,
57       bool is_content_initiated,
58       bool must_download,
59       ScopedVector<content::ResourceThrottle>* throttles) override;
60   content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
61       net::AuthChallengeInfo* auth_info,
62       net::URLRequest* request) override;
63   bool HandleExternalProtocol(const GURL& url,
64                               int child_id,
65                               int route_id) override;
66   bool ShouldForceDownloadResource(const GURL& url,
67                                    const std::string& mime_type) override;
68   bool ShouldInterceptResourceAsStream(net::URLRequest* request,
69                                        const std::string& mime_type,
70                                        GURL* origin,
71                                        std::string* payload) override;
72   void OnStreamCreated(net::URLRequest* request,
73                        scoped_ptr<content::StreamInfo> stream) override;
74   void OnResponseStarted(net::URLRequest* request,
75                          content::ResourceContext* resource_context,
76                          content::ResourceResponse* response,
77                          IPC::Sender* sender) override;
78   void OnRequestRedirected(const GURL& redirect_url,
79                            net::URLRequest* request,
80                            content::ResourceContext* resource_context,
81                            content::ResourceResponse* response) override;
82   void RequestComplete(net::URLRequest* url_request) override;
83
84   // Called on the UI thread. Allows switching out the
85   // ExternalProtocolHandler::Delegate for testing code.
86   static void SetExternalProtocolHandlerDelegateForTesting(
87       ExternalProtocolHandler::Delegate* delegate);
88
89  private:
90 #if defined(ENABLE_EXTENSIONS)
91   struct StreamTargetInfo {
92     std::string extension_id;
93     std::string view_id;
94   };
95 #endif
96
97   void AppendStandardResourceThrottles(
98       net::URLRequest* request,
99       content::ResourceContext* resource_context,
100       content::ResourceType resource_type,
101       ScopedVector<content::ResourceThrottle>* throttles);
102
103 #if defined(ENABLE_ONE_CLICK_SIGNIN)
104   // Append headers required to tell Gaia whether the sync interstitial
105   // should be shown or not.  This header is only added for valid Gaia URLs.
106   void AppendChromeSyncGaiaHeader(
107       net::URLRequest* request,
108       content::ResourceContext* resource_context);
109 #endif
110
111   scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
112   scoped_refptr<SafeBrowsingService> safe_browsing_;
113 #if defined(ENABLE_EXTENSIONS)
114   scoped_refptr<extensions::UserScriptListener> user_script_listener_;
115   std::map<net::URLRequest*, StreamTargetInfo> stream_target_info_;
116 #endif
117   prerender::PrerenderTracker* prerender_tracker_;
118
119   DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate);
120 };
121
122 #endif  // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_