| 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 void UpdatePrerenderNetworkBytesCallback(int render_process_id, |
| 131 int render_view_id, |
| 132 int64 bytes) { |
| 133 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 134 |
| 135 prerender::PrerenderContents* prerender_contents = |
| 136 FindPrerenderContents(render_process_id, render_view_id); |
| 137 |
| 138 if (!prerender_contents) |
| 139 return; |
| 140 prerender_contents->AddNetworkBytes(bytes); |
| 141 prerender_contents->prerender_manager()->AddProfileNetworkBytesIfEnabled( |
| 142 bytes); |
| 143 } |
| 144 |
| 114 #if !defined(OS_ANDROID) | 145 #if !defined(OS_ANDROID) |
| 115 // Goes through the extension's file browser handlers and checks if there is one | 146 // Goes through the extension's file browser handlers and checks if there is one |
| 116 // that can handle the |mime_type|. | 147 // that can handle the |mime_type|. |
| 117 // |extension| must not be NULL. | 148 // |extension| must not be NULL. |
| 118 bool ExtensionCanHandleMimeType(const Extension* extension, | 149 bool ExtensionCanHandleMimeType(const Extension* extension, |
| 119 const std::string& mime_type) { | 150 const std::string& mime_type) { |
| 120 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 151 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 121 if (!handler) | 152 if (!handler) |
| 122 return false; | 153 return false; |
| 123 | 154 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 152 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 183 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
| 153 if (!streams_private) | 184 if (!streams_private) |
| 154 return; | 185 return; |
| 155 streams_private->ExecuteMimeTypeHandler( | 186 streams_private->ExecuteMimeTypeHandler( |
| 156 extension_id, web_contents, stream.Pass(), expected_content_size); | 187 extension_id, web_contents, stream.Pass(), expected_content_size); |
| 157 } | 188 } |
| 158 | 189 |
| 159 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 190 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 | 191 // 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.) | 192 // 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 | 193 |
| 171 // If the request was for a prerender, abort the prerender and do not | |
| 172 // continue. | |
| 173 prerender::PrerenderContents* prerender_contents = | 194 prerender::PrerenderContents* prerender_contents = |
| 174 prerender::PrerenderContents::FromWebContents(web_contents); | 195 FindPrerenderContents(render_process_id, render_view_id); |
| 175 if (prerender_contents) { | 196 if (prerender_contents) { |
| 176 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); | 197 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 177 prerender::ReportPrerenderExternalURL(); | 198 prerender::ReportPrerenderExternalURL(); |
| 178 return; | 199 return; |
| 179 } | 200 } |
| 180 | 201 |
| 181 ExternalProtocolHandler::LaunchUrlWithDelegate( | 202 ExternalProtocolHandler::LaunchUrlWithDelegate( |
| 182 url, render_process_id, render_view_id, | 203 url, render_process_id, render_view_id, |
| 183 g_external_protocol_handler_delegate); | 204 g_external_protocol_handler_delegate); |
| 184 } | 205 } |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 635 |
| 615 // In the Mirror world, Chrome should append a X-Chrome-Connected header to | 636 // 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 | 637 // 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 | 638 // response and let Chrome handle the action with native UI. The only |
| 618 // exception is requests from gaia webview, since the native profile | 639 // exception is requests from gaia webview, since the native profile |
| 619 // management UI is built on top of it. | 640 // management UI is built on top of it. |
| 620 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, | 641 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, |
| 621 info->GetChildID(), info->GetRouteID()); | 642 info->GetChildID(), info->GetRouteID()); |
| 622 } | 643 } |
| 623 | 644 |
| 645 // Notification that a request has completed. |
| 646 void ChromeResourceDispatcherHostDelegate::RequestComplete( |
| 647 net::URLRequest* url_request) { |
| 648 // Jump on the UI thread and inform the prerender about the bytes. |
| 649 const ResourceRequestInfo* info = |
| 650 ResourceRequestInfo::ForRequest(url_request); |
| 651 if (url_request && !url_request->was_cached()) { |
| 652 BrowserThread::PostTask(BrowserThread::UI, |
| 653 FROM_HERE, |
| 654 base::Bind(&UpdatePrerenderNetworkBytesCallback, |
| 655 info->GetChildID(), |
| 656 info->GetRouteID(), |
| 657 url_request->GetTotalReceivedBytes())); |
| 658 } |
| 659 } |
| 660 |
| 624 // static | 661 // static |
| 625 void ChromeResourceDispatcherHostDelegate:: | 662 void ChromeResourceDispatcherHostDelegate:: |
| 626 SetExternalProtocolHandlerDelegateForTesting( | 663 SetExternalProtocolHandlerDelegateForTesting( |
| 627 ExternalProtocolHandler::Delegate* delegate) { | 664 ExternalProtocolHandler::Delegate* delegate) { |
| 628 g_external_protocol_handler_delegate = delegate; | 665 g_external_protocol_handler_delegate = delegate; |
| 629 } | 666 } |
| OLD | NEW |