Chromium Code Reviews| 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 | |
|
tburkard
2014/02/12 19:54:56
Couldnt you this be done more easily by using Find
jkarlin
2014/02/13 13:24:49
Yes! Done.
| |
| 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); | |
|
tburkard
2014/02/12 19:54:56
You could remove GetPrerenderManager() entirely, a
jkarlin
2014/02/13 13:24:49
Done.
| |
| 168 if (prerender_manager) { | |
| 169 prerender_manager->AddProfileNetworkBytesIfEnabled(bytes); | |
| 170 } | |
| 171 } | |
| 172 | |
| 114 #if !defined(OS_ANDROID) | 173 #if !defined(OS_ANDROID) |
| 115 // Goes through the extension's file browser handlers and checks if there is one | 174 // Goes through the extension's file browser handlers and checks if there is one |
| 116 // that can handle the |mime_type|. | 175 // that can handle the |mime_type|. |
| 117 // |extension| must not be NULL. | 176 // |extension| must not be NULL. |
| 118 bool ExtensionCanHandleMimeType(const Extension* extension, | 177 bool ExtensionCanHandleMimeType(const Extension* extension, |
| 119 const std::string& mime_type) { | 178 const std::string& mime_type) { |
| 120 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 179 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 121 if (!handler) | 180 if (!handler) |
| 122 return false; | 181 return false; |
| 123 | 182 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 152 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 211 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
| 153 if (!streams_private) | 212 if (!streams_private) |
| 154 return; | 213 return; |
| 155 streams_private->ExecuteMimeTypeHandler( | 214 streams_private->ExecuteMimeTypeHandler( |
| 156 extension_id, web_contents, stream.Pass(), expected_content_size); | 215 extension_id, web_contents, stream.Pass(), expected_content_size); |
| 157 } | 216 } |
| 158 | 217 |
| 159 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 218 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 | 219 // 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.) | 220 // 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 | 221 |
| 171 // If the request was for a prerender, abort the prerender and do not | |
| 172 // continue. | |
| 173 prerender::PrerenderContents* prerender_contents = | 222 prerender::PrerenderContents* prerender_contents = |
| 174 prerender::PrerenderContents::FromWebContents(web_contents); | 223 FindPrerenderContents(render_process_id, render_view_id); |
| 175 if (prerender_contents) { | 224 if (prerender_contents) { |
| 176 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); | 225 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 177 prerender::ReportPrerenderExternalURL(); | 226 prerender::ReportPrerenderExternalURL(); |
| 178 return; | 227 return; |
| 179 } | 228 } |
| 180 | 229 |
| 181 ExternalProtocolHandler::LaunchUrlWithDelegate( | 230 ExternalProtocolHandler::LaunchUrlWithDelegate( |
| 182 url, render_process_id, render_view_id, | 231 url, render_process_id, render_view_id, |
| 183 g_external_protocol_handler_delegate); | 232 g_external_protocol_handler_delegate); |
| 184 } | 233 } |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 | 663 |
| 615 // In the Mirror world, Chrome should append a X-Chrome-Connected header to | 664 // 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 | 665 // 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 | 666 // response and let Chrome handle the action with native UI. The only |
| 618 // exception is requests from gaia webview, since the native profile | 667 // exception is requests from gaia webview, since the native profile |
| 619 // management UI is built on top of it. | 668 // management UI is built on top of it. |
| 620 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, | 669 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, |
| 621 info->GetChildID(), info->GetRouteID()); | 670 info->GetChildID(), info->GetRouteID()); |
| 622 } | 671 } |
| 623 | 672 |
| 673 // Notification that a request has completed. | |
| 674 void ChromeResourceDispatcherHostDelegate::RequestComplete( | |
| 675 net::URLRequest* url_request, | |
| 676 int render_process_id, | |
| 677 int render_view_id) { | |
| 678 // Jump on the UI thread and inform the prerender about the bytes. | |
| 679 if (url_request && !url_request->was_cached()) { | |
| 680 BrowserThread::PostTask(BrowserThread::UI, | |
| 681 FROM_HERE, | |
| 682 base::Bind(&UpdatePrerenderNetworkBytesCallback, | |
| 683 render_process_id, | |
| 684 render_view_id, | |
| 685 url_request->GetTotalReceivedBytes())); | |
| 686 } | |
| 687 } | |
| 688 | |
| 624 // static | 689 // static |
| 625 void ChromeResourceDispatcherHostDelegate:: | 690 void ChromeResourceDispatcherHostDelegate:: |
| 626 SetExternalProtocolHandlerDelegateForTesting( | 691 SetExternalProtocolHandlerDelegateForTesting( |
| 627 ExternalProtocolHandler::Delegate* delegate) { | 692 ExternalProtocolHandler::Delegate* delegate) { |
| 628 g_external_protocol_handler_delegate = delegate; | 693 g_external_protocol_handler_delegate = delegate; |
| 629 } | 694 } |
| OLD | NEW |