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" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 Profile* profile = | 198 Profile* profile = |
199 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 199 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
200 | 200 |
201 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 201 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
202 if (!streams_private) | 202 if (!streams_private) |
203 return; | 203 return; |
204 streams_private->ExecuteMimeTypeHandler( | 204 streams_private->ExecuteMimeTypeHandler( |
205 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, | 205 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, |
206 embedded, render_process_id, render_frame_id); | 206 embedded, render_process_id, render_frame_id); |
207 } | 207 } |
| 208 |
| 209 // TODO(raymes): This won't return the right result if plugins haven't been |
| 210 // loaded yet. Fixing this properly really requires fixing crbug.com/443466. |
| 211 bool IsPluginEnabledForExtension(const Extension* extension, |
| 212 const ResourceRequestInfo* info, |
| 213 const std::string& mime_type, |
| 214 const GURL& url) { |
| 215 content::PluginService* service = content::PluginService::GetInstance(); |
| 216 std::vector<content::WebPluginInfo> plugins; |
| 217 service->GetPluginInfoArray(url, mime_type, true, &plugins, nullptr); |
| 218 content::PluginServiceFilter* filter = service->GetFilter(); |
| 219 |
| 220 for (auto& plugin : plugins) { |
| 221 // Check that the plugin is running the extension. |
| 222 if (plugin.path != |
| 223 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { |
| 224 continue; |
| 225 } |
| 226 // Check that the plugin is actually enabled. |
| 227 if (!filter || filter->IsPluginAvailable(info->GetChildID(), |
| 228 info->GetRenderFrameID(), |
| 229 info->GetContext(), |
| 230 url, |
| 231 GURL(), |
| 232 &plugin)) { |
| 233 return true; |
| 234 } |
| 235 } |
| 236 return false; |
| 237 } |
208 #endif // !defined(ENABLE_EXTENSIONS) | 238 #endif // !defined(ENABLE_EXTENSIONS) |
209 | 239 |
210 #if !defined(OS_ANDROID) | 240 #if !defined(OS_ANDROID) |
211 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 241 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { |
212 // If there is no longer a WebContents, the request may have raced with tab | 242 // If there is no longer a WebContents, the request may have raced with tab |
213 // closing. Don't fire the external request. (It may have been a prerender.) | 243 // closing. Don't fire the external request. (It may have been a prerender.) |
214 content::WebContents* web_contents = | 244 content::WebContents* web_contents = |
215 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 245 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
216 if (!web_contents) | 246 if (!web_contents) |
217 return; | 247 return; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 #if defined(ENABLE_EXTENSIONS) | 594 #if defined(ENABLE_EXTENSIONS) |
565 // Special-case user scripts to get downloaded instead of viewed. | 595 // Special-case user scripts to get downloaded instead of viewed. |
566 return extensions::UserScript::IsURLUserScript(url, mime_type); | 596 return extensions::UserScript::IsURLUserScript(url, mime_type); |
567 #else | 597 #else |
568 return false; | 598 return false; |
569 #endif | 599 #endif |
570 } | 600 } |
571 | 601 |
572 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 602 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
573 net::URLRequest* request, | 603 net::URLRequest* request, |
574 const base::FilePath& plugin_path, | |
575 const std::string& mime_type, | 604 const std::string& mime_type, |
576 GURL* origin, | 605 GURL* origin, |
577 std::string* payload) { | 606 std::string* payload) { |
578 #if defined(ENABLE_EXTENSIONS) | 607 #if defined(ENABLE_EXTENSIONS) |
579 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 608 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
580 ProfileIOData* io_data = | 609 ProfileIOData* io_data = |
581 ProfileIOData::FromResourceContext(info->GetContext()); | 610 ProfileIOData::FromResourceContext(info->GetContext()); |
582 bool profile_is_off_the_record = io_data->IsOffTheRecord(); | 611 bool profile_is_off_the_record = io_data->IsOffTheRecord(); |
583 const scoped_refptr<const extensions::InfoMap> extension_info_map( | 612 const scoped_refptr<const extensions::InfoMap> extension_info_map( |
584 io_data->GetExtensionInfoMap()); | 613 io_data->GetExtensionInfoMap()); |
585 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 614 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
586 // Go through the white-listed extensions and try to use them to intercept | 615 // Go through the white-listed extensions and try to use them to intercept |
587 // the URL request. | 616 // the URL request. |
588 for (const std::string& extension_id : whitelist) { | 617 for (const std::string& extension_id : whitelist) { |
589 const Extension* extension = | 618 const Extension* extension = |
590 extension_info_map->extensions().GetByID(extension_id); | 619 extension_info_map->extensions().GetByID(extension_id); |
591 // The white-listed extension may not be installed, so we have to NULL check | 620 // The white-listed extension may not be installed, so we have to NULL check |
592 // |extension|. | 621 // |extension|. |
593 if (!extension || | 622 if (!extension || |
594 (profile_is_off_the_record && | 623 (profile_is_off_the_record && |
595 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 624 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
596 continue; | 625 continue; |
597 } | 626 } |
| 627 |
598 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 628 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
599 // If the MimeHandlerView plugin to be loaded matches the extension, | 629 if (handler && handler->CanHandleMIMEType(mime_type)) { |
600 // intercept the stream for that extension. | |
601 if (plugin_path == | |
602 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { | |
603 StreamTargetInfo target_info; | 630 StreamTargetInfo target_info; |
604 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 631 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
605 target_info.extension_id = extension_id; | 632 target_info.extension_id = extension_id; |
606 DCHECK(!handler->handler_url().empty()); | 633 if (!handler->handler_url().empty()) { |
607 target_info.view_id = base::GenerateGUID(); | 634 // This is reached in the case of MimeHandlerViews. If the |
608 *payload = target_info.view_id; | 635 // MimeHandlerView plugin is disabled, then we shouldn't intercept the |
609 stream_target_info_[request] = target_info; | 636 // stream. |
610 return true; | 637 if (!IsPluginEnabledForExtension(extension, info, mime_type, |
611 } else if (plugin_path.empty() && handler && | 638 request->url())) { |
612 handler->CanHandleMIMEType(mime_type)) { | 639 continue; |
613 // If no plugin path is provided, then we are trying to intercept the | 640 } |
614 // stream for the streamsPrivate API. | 641 target_info.view_id = base::GenerateGUID(); |
615 StreamTargetInfo target_info; | 642 *payload = target_info.view_id; |
616 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 643 } |
617 target_info.extension_id = extension_id; | |
618 DCHECK(handler->handler_url().empty()); | |
619 stream_target_info_[request] = target_info; | 644 stream_target_info_[request] = target_info; |
620 return true; | 645 return true; |
621 } | 646 } |
622 } | 647 } |
623 #endif | 648 #endif |
624 return false; | 649 return false; |
625 } | 650 } |
626 | 651 |
627 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 652 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
628 net::URLRequest* request, | 653 net::URLRequest* request, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 url_request->GetTotalReceivedBytes())); | 759 url_request->GetTotalReceivedBytes())); |
735 } | 760 } |
736 } | 761 } |
737 | 762 |
738 // static | 763 // static |
739 void ChromeResourceDispatcherHostDelegate:: | 764 void ChromeResourceDispatcherHostDelegate:: |
740 SetExternalProtocolHandlerDelegateForTesting( | 765 SetExternalProtocolHandlerDelegateForTesting( |
741 ExternalProtocolHandler::Delegate* delegate) { | 766 ExternalProtocolHandler::Delegate* delegate) { |
742 g_external_protocol_handler_delegate = delegate; | 767 g_external_protocol_handler_delegate = delegate; |
743 } | 768 } |
OLD | NEW |