• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   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       ResourceType::Type resource_type,
47       content::ResourceContext* resource_context) OVERRIDE;
48   virtual void RequestBeginning(
49       net::URLRequest* request,
50       content::ResourceContext* resource_context,
51       appcache::AppCacheService* appcache_service,
52       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) 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   struct StreamTargetInfo {
99     std::string extension_id;
100     std::string view_id;
101   };
102 
103   void AppendStandardResourceThrottles(
104       net::URLRequest* request,
105       content::ResourceContext* resource_context,
106       ResourceType::Type resource_type,
107       ScopedVector<content::ResourceThrottle>* throttles);
108 
109 #if defined(ENABLE_ONE_CLICK_SIGNIN)
110   // Append headers required to tell Gaia whether the sync interstitial
111   // should be shown or not.  This header is only added for valid Gaia URLs.
112   void AppendChromeSyncGaiaHeader(
113       net::URLRequest* request,
114       content::ResourceContext* resource_context);
115 #endif
116 
117   scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
118   scoped_refptr<SafeBrowsingService> safe_browsing_;
119   scoped_refptr<extensions::UserScriptListener> user_script_listener_;
120   prerender::PrerenderTracker* prerender_tracker_;
121   std::map<net::URLRequest*, StreamTargetInfo> stream_target_info_;
122 
123   DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate);
124 };
125 
126 #endif  // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
127