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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/component_updater/component_updater_resource_throttle.h " | 15 #include "chrome/browser/component_updater/component_updater_resource_throttle.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/net/resource_prefetch_predictor_observer.h" | 18 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
| 19 #include "chrome/browser/plugins/plugin_prefs.h" | |
| 19 #include "chrome/browser/prefetch/prefetch.h" | 20 #include "chrome/browser/prefetch/prefetch.h" |
| 20 #include "chrome/browser/prerender/prerender_manager.h" | 21 #include "chrome/browser/prerender/prerender_manager.h" |
| 21 #include "chrome/browser/prerender/prerender_manager_factory.h" | 22 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 22 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 23 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
| 23 #include "chrome/browser/prerender/prerender_tracker.h" | 24 #include "chrome/browser/prerender/prerender_tracker.h" |
| 24 #include "chrome/browser/prerender/prerender_util.h" | 25 #include "chrome/browser/prerender/prerender_util.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_io_data.h" | 27 #include "chrome/browser/profiles/profile_io_data.h" |
| 27 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h " | 28 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h " |
| 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 29 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 29 #include "chrome/browser/signin/signin_header_helper.h" | 30 #include "chrome/browser/signin/signin_header_helper.h" |
| 30 #include "chrome/browser/tab_contents/tab_util.h" | 31 #include "chrome/browser/tab_contents/tab_util.h" |
| 31 #include "chrome/browser/ui/login/login_prompt.h" | 32 #include "chrome/browser/ui/login/login_prompt.h" |
| 32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/render_messages.h" | 34 #include "chrome/common/render_messages.h" |
| 34 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
| 35 #include "components/content_settings/core/browser/host_content_settings_map.h" | 36 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 36 #include "components/google/core/browser/google_util.h" | 37 #include "components/google/core/browser/google_util.h" |
| 37 #include "components/variations/net/variations_http_header_provider.h" | 38 #include "components/variations/net/variations_http_header_provider.h" |
| 38 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 39 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 41 #include "content/public/browser/plugin_service.h" | |
| 42 #include "content/public/browser/plugin_service_filter.h" | |
| 40 #include "content/public/browser/render_process_host.h" | 43 #include "content/public/browser/render_process_host.h" |
| 41 #include "content/public/browser/render_view_host.h" | 44 #include "content/public/browser/render_view_host.h" |
| 42 #include "content/public/browser/resource_context.h" | 45 #include "content/public/browser/resource_context.h" |
| 43 #include "content/public/browser/resource_dispatcher_host.h" | 46 #include "content/public/browser/resource_dispatcher_host.h" |
| 44 #include "content/public/browser/resource_request_info.h" | 47 #include "content/public/browser/resource_request_info.h" |
| 45 #include "content/public/browser/service_worker_context.h" | 48 #include "content/public/browser/service_worker_context.h" |
| 46 #include "content/public/browser/stream_info.h" | 49 #include "content/public/browser/stream_info.h" |
| 47 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
| 48 #include "content/public/common/resource_response.h" | 51 #include "content/public/common/resource_response.h" |
| 49 #include "net/base/load_flags.h" | 52 #include "net/base/load_flags.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 Profile* profile = | 203 Profile* profile = |
| 201 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 204 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 202 | 205 |
| 203 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 206 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
| 204 if (!streams_private) | 207 if (!streams_private) |
| 205 return; | 208 return; |
| 206 streams_private->ExecuteMimeTypeHandler( | 209 streams_private->ExecuteMimeTypeHandler( |
| 207 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, | 210 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, |
| 208 embedded, render_process_id, render_frame_id); | 211 embedded, render_process_id, render_frame_id); |
| 209 } | 212 } |
| 213 | |
| 214 // TODO(raymes): This won't return the right result if plugins haven't been | |
| 215 // loaded yet. Fixing this properly really requires fixing crbug.com/443466. | |
| 216 bool IsPluginEnabledForExtension(const Extension* extension, | |
| 217 const ResourceRequestInfo* info, | |
| 218 const std::string& mime_type, | |
| 219 const GURL& url) { | |
| 220 content::PluginService* service = content::PluginService::GetInstance(); | |
| 221 std::vector<content::WebPluginInfo> plugins; | |
| 222 service->GetPluginInfoArray( | |
| 223 url, mime_type, true, &plugins, nullptr); | |
|
Sam McNally
2015/02/23 00:38:35
This looks like it can fit on the previous line.
raymes
2015/02/23 02:26:13
Done.
| |
| 224 content::PluginServiceFilter* filter = service->GetFilter(); | |
| 225 | |
| 226 for (size_t i = 0; i < plugins.size(); ++i) { | |
|
Sam McNally
2015/02/23 00:38:34
for-each loop?
raymes
2015/02/23 02:26:13
Done.
| |
| 227 // Check that the plugin is running the extension. | |
| 228 if (plugins[i].path != | |
| 229 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { | |
| 230 continue; | |
| 231 } | |
| 232 // Check that the plugin is actually enabled. | |
| 233 if (!filter || filter->IsPluginAvailable(info->GetChildID(), | |
| 234 info->GetRenderFrameID(), | |
| 235 info->GetContext(), | |
| 236 url, | |
| 237 GURL(), | |
| 238 &plugins[i])) { | |
| 239 return true; | |
| 240 } | |
| 241 } | |
| 242 return false; | |
| 243 } | |
| 210 #endif // !defined(ENABLE_EXTENSIONS) | 244 #endif // !defined(ENABLE_EXTENSIONS) |
| 211 | 245 |
| 212 #if !defined(OS_ANDROID) | 246 #if !defined(OS_ANDROID) |
| 213 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 247 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { |
| 214 // If there is no longer a WebContents, the request may have raced with tab | 248 // If there is no longer a WebContents, the request may have raced with tab |
| 215 // closing. Don't fire the external request. (It may have been a prerender.) | 249 // closing. Don't fire the external request. (It may have been a prerender.) |
| 216 content::WebContents* web_contents = | 250 content::WebContents* web_contents = |
| 217 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 251 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 218 if (!web_contents) | 252 if (!web_contents) |
| 219 return; | 253 return; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 654 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
| 621 continue; | 655 continue; |
| 622 } | 656 } |
| 623 | 657 |
| 624 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 658 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 625 if (handler && handler->CanHandleMIMEType(mime_type)) { | 659 if (handler && handler->CanHandleMIMEType(mime_type)) { |
| 626 StreamTargetInfo target_info; | 660 StreamTargetInfo target_info; |
| 627 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 661 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
| 628 target_info.extension_id = extension_id; | 662 target_info.extension_id = extension_id; |
| 629 if (!handler->handler_url().empty()) { | 663 if (!handler->handler_url().empty()) { |
| 664 // This is reached in the case of MimeHandlerViews. If the | |
| 665 // MimeHandlerView plugin is disabled, then we shouldn't intercept the | |
| 666 // stream. | |
| 667 if (!IsPluginEnabledForExtension(extension, info, mime_type, | |
| 668 request->url())) { | |
| 669 continue; | |
| 670 } | |
| 630 target_info.view_id = base::GenerateGUID(); | 671 target_info.view_id = base::GenerateGUID(); |
| 631 *payload = target_info.view_id; | 672 *payload = target_info.view_id; |
| 632 } | 673 } |
| 633 stream_target_info_[request] = target_info; | 674 stream_target_info_[request] = target_info; |
| 634 return true; | 675 return true; |
| 635 } | 676 } |
| 636 } | 677 } |
| 637 #endif | 678 #endif |
| 638 return false; | 679 return false; |
| 639 } | 680 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 url_request->GetTotalReceivedBytes())); | 808 url_request->GetTotalReceivedBytes())); |
| 768 } | 809 } |
| 769 } | 810 } |
| 770 | 811 |
| 771 // static | 812 // static |
| 772 void ChromeResourceDispatcherHostDelegate:: | 813 void ChromeResourceDispatcherHostDelegate:: |
| 773 SetExternalProtocolHandlerDelegateForTesting( | 814 SetExternalProtocolHandlerDelegateForTesting( |
| 774 ExternalProtocolHandler::Delegate* delegate) { | 815 ExternalProtocolHandler::Delegate* delegate) { |
| 775 g_external_protocol_handler_delegate = delegate; | 816 g_external_protocol_handler_delegate = delegate; |
| 776 } | 817 } |
| OLD | NEW |