Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / renderer_host / chrome_resource_dispatcher_host_delegate.h
blob5101ce26be2951843feec2590f625c68550c8d88
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.
5 #ifndef CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
6 #define CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
8 #include <map>
9 #include <set>
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"
16 class DelayedResourceQueue;
17 class DownloadRequestLimiter;
18 class SafeBrowsingService;
20 namespace extensions {
21 class UserScriptListener;
24 // Implements ResourceDispatcherHostDelegate. Currently used by the Prerender
25 // system to abort requests and add to the load flags when a request begins.
26 class ChromeResourceDispatcherHostDelegate
27 : public content::ResourceDispatcherHostDelegate {
28 public:
29 ChromeResourceDispatcherHostDelegate();
30 ~ChromeResourceDispatcherHostDelegate() override;
32 // ResourceDispatcherHostDelegate implementation.
33 bool ShouldBeginRequest(const std::string& method,
34 const GURL& url,
35 content::ResourceType resource_type,
36 content::ResourceContext* resource_context) override;
37 void RequestBeginning(
38 net::URLRequest* request,
39 content::ResourceContext* resource_context,
40 content::AppCacheService* appcache_service,
41 content::ResourceType resource_type,
42 ScopedVector<content::ResourceThrottle>* throttles) override;
43 void DownloadStarting(
44 net::URLRequest* request,
45 content::ResourceContext* resource_context,
46 int child_id,
47 int route_id,
48 int request_id,
49 bool is_content_initiated,
50 bool must_download,
51 ScopedVector<content::ResourceThrottle>* throttles) override;
52 content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
53 net::AuthChallengeInfo* auth_info,
54 net::URLRequest* request) override;
55 bool HandleExternalProtocol(const GURL& url,
56 int child_id,
57 int route_id,
58 bool is_main_frame,
59 ui::PageTransition page_transition,
60 bool has_user_gesture) override;
61 bool ShouldForceDownloadResource(const GURL& url,
62 const std::string& mime_type) override;
63 bool ShouldInterceptResourceAsStream(net::URLRequest* request,
64 const base::FilePath& plugin_path,
65 const std::string& mime_type,
66 GURL* origin,
67 std::string* payload) override;
68 void OnStreamCreated(net::URLRequest* request,
69 scoped_ptr<content::StreamInfo> stream) override;
70 void OnResponseStarted(net::URLRequest* request,
71 content::ResourceContext* resource_context,
72 content::ResourceResponse* response,
73 IPC::Sender* sender) override;
74 void OnRequestRedirected(const GURL& redirect_url,
75 net::URLRequest* request,
76 content::ResourceContext* resource_context,
77 content::ResourceResponse* response) override;
78 void RequestComplete(net::URLRequest* url_request) override;
80 // Called on the UI thread. Allows switching out the
81 // ExternalProtocolHandler::Delegate for testing code.
82 static void SetExternalProtocolHandlerDelegateForTesting(
83 ExternalProtocolHandler::Delegate* delegate);
85 private:
86 #if defined(ENABLE_EXTENSIONS)
87 struct StreamTargetInfo {
88 std::string extension_id;
89 std::string view_id;
91 #endif
93 void AppendStandardResourceThrottles(
94 net::URLRequest* request,
95 content::ResourceContext* resource_context,
96 content::ResourceType resource_type,
97 ScopedVector<content::ResourceThrottle>* throttles);
99 scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
100 scoped_refptr<SafeBrowsingService> safe_browsing_;
101 #if defined(ENABLE_EXTENSIONS)
102 scoped_refptr<extensions::UserScriptListener> user_script_listener_;
103 std::map<net::URLRequest*, StreamTargetInfo> stream_target_info_;
104 #endif
106 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate);
109 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_