OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/component_updater/component_updater_service.h" | 13 #include "chrome/browser/component_updater/component_updater_service.h" |
14 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" | 14 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map.h" |
16 #include "chrome/browser/download/download_request_limiter.h" | 16 #include "chrome/browser/download/download_request_limiter.h" |
17 #include "chrome/browser/download/download_resource_throttle.h" | 17 #include "chrome/browser/download/download_resource_throttle.h" |
18 #include "chrome/browser/extensions/api/streams_private/streams_private_api.h" | 18 #include "chrome/browser/extensions/api/streams_private/streams_private_api.h" |
19 #include "chrome/browser/extensions/extension_renderer_state.h" | 19 #include "chrome/browser/extensions/extension_renderer_state.h" |
20 #include "chrome/browser/extensions/user_script_listener.h" | 20 #include "chrome/browser/extensions/user_script_listener.h" |
21 #include "chrome/browser/google/google_util.h" | 21 #include "chrome/browser/google/google_util.h" |
22 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 22 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
23 #include "chrome/browser/prefetch/prefetch.h" | 23 #include "chrome/browser/prefetch/prefetch.h" |
24 #include "chrome/browser/prerender/prerender_manager.h" | 24 #include "chrome/browser/prerender/prerender_manager.h" |
| 25 #include "chrome/browser/prerender/prerender_manager_factory.h" |
25 #include "chrome/browser/prerender/prerender_pending_swap_throttle.h" | 26 #include "chrome/browser/prerender/prerender_pending_swap_throttle.h" |
26 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 27 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
27 #include "chrome/browser/prerender/prerender_tracker.h" | 28 #include "chrome/browser/prerender/prerender_tracker.h" |
28 #include "chrome/browser/prerender/prerender_util.h" | 29 #include "chrome/browser/prerender/prerender_util.h" |
29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/profiles/profile_io_data.h" | 31 #include "chrome/browser/profiles/profile_io_data.h" |
31 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" | 32 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" |
32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
33 #include "chrome/browser/signin/signin_header_helper.h" | 34 #include "chrome/browser/signin/signin_header_helper.h" |
34 #include "chrome/browser/ui/auto_login_prompter.h" | 35 #include "chrome/browser/ui/auto_login_prompter.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 render_view_id); | 105 render_view_id); |
105 if (!rvh) | 106 if (!rvh) |
106 return; | 107 return; |
107 | 108 |
108 content::NotificationService::current()->Notify( | 109 content::NotificationService::current()->Notify( |
109 chrome::NOTIFICATION_DOWNLOAD_INITIATED, | 110 chrome::NOTIFICATION_DOWNLOAD_INITIATED, |
110 content::Source<RenderViewHost>(rvh), | 111 content::Source<RenderViewHost>(rvh), |
111 content::NotificationService::NoDetails()); | 112 content::NotificationService::NoDetails()); |
112 } | 113 } |
113 | 114 |
| 115 prerender::PrerenderContents* FindPrerenderContents(int render_process_id, |
| 116 int render_view_id) { |
| 117 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 118 content::RenderViewHost* rvh = |
| 119 content::RenderViewHost::FromID(render_process_id, render_view_id); |
| 120 if (!rvh) |
| 121 return NULL; |
| 122 content::WebContents* web_contents = |
| 123 content::WebContents::FromRenderViewHost(rvh); |
| 124 if (!web_contents) |
| 125 return NULL; |
| 126 |
| 127 return prerender::PrerenderContents::FromWebContents(web_contents); |
| 128 } |
| 129 |
| 130 prerender::PrerenderManager* GetPrerenderManager(int render_process_id, |
| 131 int render_view_id) { |
| 132 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 133 |
| 134 content::RenderViewHost* render_view_host = |
| 135 content::RenderViewHost::FromID(render_process_id, render_view_id); |
| 136 if (!render_view_host) |
| 137 return NULL; |
| 138 |
| 139 content::WebContents* web_contents = |
| 140 content::WebContents::FromRenderViewHost(render_view_host); |
| 141 if (!web_contents) |
| 142 return NULL; |
| 143 |
| 144 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 145 if (!browser_context) |
| 146 return NULL; |
| 147 |
| 148 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 149 if (!profile) |
| 150 return NULL; |
| 151 |
| 152 return prerender::PrerenderManagerFactory::GetForProfile(profile); |
| 153 } |
| 154 |
| 155 void UpdatePrerenderNetworkBytesCallback(int render_process_id, |
| 156 int render_view_id, |
| 157 int64 bytes) { |
| 158 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 159 |
| 160 prerender::PrerenderContents* prerender_contents = |
| 161 FindPrerenderContents(render_process_id, render_view_id); |
| 162 |
| 163 if (prerender_contents) |
| 164 prerender_contents->AddNetworkBytes(bytes); |
| 165 |
| 166 prerender::PrerenderManager* prerender_manager = |
| 167 GetPrerenderManager(render_process_id, render_view_id); |
| 168 if (prerender_manager) |
| 169 prerender_manager->AddProfileNetworkBytesIfEnabled(bytes); |
| 170 } |
| 171 |
114 #if !defined(OS_ANDROID) | 172 #if !defined(OS_ANDROID) |
115 // Goes through the extension's file browser handlers and checks if there is one | 173 // Goes through the extension's file browser handlers and checks if there is one |
116 // that can handle the |mime_type|. | 174 // that can handle the |mime_type|. |
117 // |extension| must not be NULL. | 175 // |extension| must not be NULL. |
118 bool ExtensionCanHandleMimeType(const Extension* extension, | 176 bool ExtensionCanHandleMimeType(const Extension* extension, |
119 const std::string& mime_type) { | 177 const std::string& mime_type) { |
120 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 178 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
121 if (!handler) | 179 if (!handler) |
122 return false; | 180 return false; |
123 | 181 |
(...skipping 28 matching lines...) Expand all Loading... |
152 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 210 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
153 if (!streams_private) | 211 if (!streams_private) |
154 return; | 212 return; |
155 streams_private->ExecuteMimeTypeHandler( | 213 streams_private->ExecuteMimeTypeHandler( |
156 extension_id, web_contents, stream.Pass(), expected_content_size); | 214 extension_id, web_contents, stream.Pass(), expected_content_size); |
157 } | 215 } |
158 | 216 |
159 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 217 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { |
160 // If there is no longer a WebContents, the request may have raced with tab | 218 // If there is no longer a WebContents, the request may have raced with tab |
161 // closing. Don't fire the external request. (It may have been a prerender.) | 219 // closing. Don't fire the external request. (It may have been a prerender.) |
162 content::RenderViewHost* rvh = content::RenderViewHost::FromID( | |
163 render_process_id, render_view_id); | |
164 if (!rvh) | |
165 return; | |
166 content::WebContents* web_contents = | |
167 content::WebContents::FromRenderViewHost(rvh); | |
168 if (!web_contents) | |
169 return; | |
170 | 220 |
171 // If the request was for a prerender, abort the prerender and do not | |
172 // continue. | |
173 prerender::PrerenderContents* prerender_contents = | 221 prerender::PrerenderContents* prerender_contents = |
174 prerender::PrerenderContents::FromWebContents(web_contents); | 222 FindPrerenderContents(render_process_id, render_view_id); |
175 if (prerender_contents) { | 223 if (prerender_contents) { |
176 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); | 224 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
177 prerender::ReportPrerenderExternalURL(); | 225 prerender::ReportPrerenderExternalURL(); |
178 return; | 226 return; |
179 } | 227 } |
180 | 228 |
181 ExternalProtocolHandler::LaunchUrlWithDelegate( | 229 ExternalProtocolHandler::LaunchUrlWithDelegate( |
182 url, render_process_id, render_view_id, | 230 url, render_process_id, render_view_id, |
183 g_external_protocol_handler_delegate); | 231 g_external_protocol_handler_delegate); |
184 } | 232 } |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 662 |
615 // In the Mirror world, Chrome should append a X-Chrome-Connected header to | 663 // In the Mirror world, Chrome should append a X-Chrome-Connected header to |
616 // all Gaia requests from a connected profile so Gaia could return a 204 | 664 // all Gaia requests from a connected profile so Gaia could return a 204 |
617 // response and let Chrome handle the action with native UI. The only | 665 // response and let Chrome handle the action with native UI. The only |
618 // exception is requests from gaia webview, since the native profile | 666 // exception is requests from gaia webview, since the native profile |
619 // management UI is built on top of it. | 667 // management UI is built on top of it. |
620 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, | 668 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, |
621 info->GetChildID(), info->GetRouteID()); | 669 info->GetChildID(), info->GetRouteID()); |
622 } | 670 } |
623 | 671 |
| 672 // Notification that a request has completed. |
| 673 void ChromeResourceDispatcherHostDelegate::RequestComplete( |
| 674 net::URLRequest* url_request) { |
| 675 // Jump on the UI thread and inform the prerender about the bytes. |
| 676 const ResourceRequestInfo* info = |
| 677 ResourceRequestInfo::ForRequest(url_request); |
| 678 if (url_request && !url_request->was_cached()) { |
| 679 BrowserThread::PostTask(BrowserThread::UI, |
| 680 FROM_HERE, |
| 681 base::Bind(&UpdatePrerenderNetworkBytesCallback, |
| 682 info->GetChildID(), |
| 683 info->GetRouteID(), |
| 684 url_request->GetTotalReceivedBytes())); |
| 685 } |
| 686 } |
| 687 |
624 // static | 688 // static |
625 void ChromeResourceDispatcherHostDelegate:: | 689 void ChromeResourceDispatcherHostDelegate:: |
626 SetExternalProtocolHandlerDelegateForTesting( | 690 SetExternalProtocolHandlerDelegateForTesting( |
627 ExternalProtocolHandler::Delegate* delegate) { | 691 ExternalProtocolHandler::Delegate* delegate) { |
628 g_external_protocol_handler_delegate = delegate; | 692 g_external_protocol_handler_delegate = delegate; |
629 } | 693 } |
OLD | NEW |