| 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(url, mime_type, true, &plugins, nullptr); |
| 223 content::PluginServiceFilter* filter = service->GetFilter(); |
| 224 |
| 225 for (auto& plugin : plugins) { |
| 226 // Check that the plugin is running the extension. |
| 227 if (plugin.path != |
| 228 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { |
| 229 continue; |
| 230 } |
| 231 // Check that the plugin is actually enabled. |
| 232 if (!filter || filter->IsPluginAvailable(info->GetChildID(), |
| 233 info->GetRenderFrameID(), |
| 234 info->GetContext(), |
| 235 url, |
| 236 GURL(), |
| 237 &plugin)) { |
| 238 return true; |
| 239 } |
| 240 } |
| 241 return false; |
| 242 } |
| 210 #endif // !defined(ENABLE_EXTENSIONS) | 243 #endif // !defined(ENABLE_EXTENSIONS) |
| 211 | 244 |
| 212 #if !defined(OS_ANDROID) | 245 #if !defined(OS_ANDROID) |
| 213 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 246 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 | 247 // 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.) | 248 // closing. Don't fire the external request. (It may have been a prerender.) |
| 216 content::WebContents* web_contents = | 249 content::WebContents* web_contents = |
| 217 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 250 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 218 if (!web_contents) | 251 if (!web_contents) |
| 219 return; | 252 return; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 653 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
| 621 continue; | 654 continue; |
| 622 } | 655 } |
| 623 | 656 |
| 624 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 657 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 625 if (handler && handler->CanHandleMIMEType(mime_type)) { | 658 if (handler && handler->CanHandleMIMEType(mime_type)) { |
| 626 StreamTargetInfo target_info; | 659 StreamTargetInfo target_info; |
| 627 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 660 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
| 628 target_info.extension_id = extension_id; | 661 target_info.extension_id = extension_id; |
| 629 if (!handler->handler_url().empty()) { | 662 if (!handler->handler_url().empty()) { |
| 663 // This is reached in the case of MimeHandlerViews. If the |
| 664 // MimeHandlerView plugin is disabled, then we shouldn't intercept the |
| 665 // stream. |
| 666 if (!IsPluginEnabledForExtension(extension, info, mime_type, |
| 667 request->url())) { |
| 668 continue; |
| 669 } |
| 630 target_info.view_id = base::GenerateGUID(); | 670 target_info.view_id = base::GenerateGUID(); |
| 631 *payload = target_info.view_id; | 671 *payload = target_info.view_id; |
| 632 } | 672 } |
| 633 stream_target_info_[request] = target_info; | 673 stream_target_info_[request] = target_info; |
| 634 return true; | 674 return true; |
| 635 } | 675 } |
| 636 } | 676 } |
| 637 #endif | 677 #endif |
| 638 return false; | 678 return false; |
| 639 } | 679 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 url_request->GetTotalReceivedBytes())); | 807 url_request->GetTotalReceivedBytes())); |
| 768 } | 808 } |
| 769 } | 809 } |
| 770 | 810 |
| 771 // static | 811 // static |
| 772 void ChromeResourceDispatcherHostDelegate:: | 812 void ChromeResourceDispatcherHostDelegate:: |
| 773 SetExternalProtocolHandlerDelegateForTesting( | 813 SetExternalProtocolHandlerDelegateForTesting( |
| 774 ExternalProtocolHandler::Delegate* delegate) { | 814 ExternalProtocolHandler::Delegate* delegate) { |
| 775 g_external_protocol_handler_delegate = delegate; | 815 g_external_protocol_handler_delegate = delegate; |
| 776 } | 816 } |
| OLD | NEW |