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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 Profile* profile = | 200 Profile* profile = |
201 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 201 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
202 | 202 |
203 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 203 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
204 if (!streams_private) | 204 if (!streams_private) |
205 return; | 205 return; |
206 streams_private->ExecuteMimeTypeHandler( | 206 streams_private->ExecuteMimeTypeHandler( |
207 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, | 207 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, |
208 embedded, render_process_id, render_frame_id); | 208 embedded, render_process_id, render_frame_id); |
209 } | 209 } |
210 | |
211 // TODO(raymes): This won't return the right result if plugins haven't been | |
212 // loaded yet. Fixing this properly really requires fixing crbug.com/443466. | |
213 bool IsPluginEnabledForExtension(const Extension* extension, | |
214 const ResourceRequestInfo* info, | |
215 const std::string& mime_type, | |
216 const GURL& url) { | |
217 content::PluginService* service = content::PluginService::GetInstance(); | |
218 std::vector<content::WebPluginInfo> plugins; | |
219 service->GetPluginInfoArray(url, mime_type, true, &plugins, nullptr); | |
220 content::PluginServiceFilter* filter = service->GetFilter(); | |
221 | |
222 for (auto& plugin : plugins) { | |
223 // Check that the plugin is running the extension. | |
224 if (plugin.path != | |
225 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { | |
226 continue; | |
227 } | |
228 // Check that the plugin is actually enabled. | |
229 if (!filter || filter->IsPluginAvailable(info->GetChildID(), | |
230 info->GetRenderFrameID(), | |
231 info->GetContext(), | |
232 url, | |
233 GURL(), | |
234 &plugin)) { | |
235 return true; | |
236 } | |
237 } | |
238 return false; | |
239 } | |
240 #endif // !defined(ENABLE_EXTENSIONS) | 210 #endif // !defined(ENABLE_EXTENSIONS) |
241 | 211 |
242 void LaunchURL( | 212 void LaunchURL( |
243 const GURL& url, | 213 const GURL& url, |
244 int render_process_id, | 214 int render_process_id, |
245 int render_view_id, | 215 int render_view_id, |
246 ui::PageTransition page_transition, | 216 ui::PageTransition page_transition, |
247 bool has_user_gesture) { | 217 bool has_user_gesture) { |
248 // If there is no longer a WebContents, the request may have raced with tab | 218 // If there is no longer a WebContents, the request may have raced with tab |
249 // closing. Don't fire the external request. (It may have been a prerender.) | 219 // closing. Don't fire the external request. (It may have been a prerender.) |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 #if defined(ENABLE_EXTENSIONS) | 584 #if defined(ENABLE_EXTENSIONS) |
615 // Special-case user scripts to get downloaded instead of viewed. | 585 // Special-case user scripts to get downloaded instead of viewed. |
616 return extensions::UserScript::IsURLUserScript(url, mime_type); | 586 return extensions::UserScript::IsURLUserScript(url, mime_type); |
617 #else | 587 #else |
618 return false; | 588 return false; |
619 #endif | 589 #endif |
620 } | 590 } |
621 | 591 |
622 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 592 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
623 net::URLRequest* request, | 593 net::URLRequest* request, |
594 const base::FilePath& plugin_path, | |
624 const std::string& mime_type, | 595 const std::string& mime_type, |
625 GURL* origin, | 596 GURL* origin, |
626 std::string* payload) { | 597 std::string* payload) { |
627 #if defined(ENABLE_EXTENSIONS) | 598 #if defined(ENABLE_EXTENSIONS) |
628 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 599 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
629 ProfileIOData* io_data = | 600 ProfileIOData* io_data = |
630 ProfileIOData::FromResourceContext(info->GetContext()); | 601 ProfileIOData::FromResourceContext(info->GetContext()); |
631 bool profile_is_off_the_record = io_data->IsOffTheRecord(); | 602 bool profile_is_off_the_record = io_data->IsOffTheRecord(); |
632 const scoped_refptr<const extensions::InfoMap> extension_info_map( | 603 const scoped_refptr<const extensions::InfoMap> extension_info_map( |
633 io_data->GetExtensionInfoMap()); | 604 io_data->GetExtensionInfoMap()); |
634 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 605 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
635 // Go through the white-listed extensions and try to use them to intercept | 606 // Go through the white-listed extensions and try to use them to intercept |
636 // the URL request. | 607 // the URL request. |
637 for (const std::string& extension_id : whitelist) { | 608 for (const std::string& extension_id : whitelist) { |
638 const Extension* extension = | 609 const Extension* extension = |
639 extension_info_map->extensions().GetByID(extension_id); | 610 extension_info_map->extensions().GetByID(extension_id); |
640 // The white-listed extension may not be installed, so we have to NULL check | 611 // The white-listed extension may not be installed, so we have to NULL check |
641 // |extension|. | 612 // |extension|. |
642 if (!extension || | 613 if (!extension || |
643 (profile_is_off_the_record && | 614 (profile_is_off_the_record && |
644 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 615 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
645 continue; | 616 continue; |
646 } | 617 } |
618 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | |
619 if (!handler) | |
620 continue; | |
647 | 621 |
648 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 622 // If a plugin path is provided then we are trying to intercept the stream |
649 if (handler && handler->CanHandleMIMEType(mime_type)) { | 623 // for the mimeHandlerPrivate API. Otherwise we are trying to intercept the |
650 StreamTargetInfo target_info; | 624 // stream for the streamsPrivate API. |
651 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 625 if (!plugin_path.empty()) { |
Sam McNally
2015/07/03 06:21:31
How about looking up the extension using |plugin_p
raymes
2015/07/06 02:30:04
I think I would rather keep that as an implementat
| |
652 target_info.extension_id = extension_id; | 626 // Check that the plugin path matches the handlers plugin path. |
653 if (!handler->handler_url().empty()) { | 627 if (handler->HasPlugin() && plugin_path == handler->GetPluginPath()) { |
654 // This is reached in the case of MimeHandlerViews. If the | 628 StreamTargetInfo target_info; |
655 // MimeHandlerView plugin is disabled, then we shouldn't intercept the | 629 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
656 // stream. | 630 target_info.extension_id = extension_id; |
657 if (!IsPluginEnabledForExtension(extension, info, mime_type, | |
658 request->url())) { | |
659 continue; | |
660 } | |
661 target_info.view_id = base::GenerateGUID(); | 631 target_info.view_id = base::GenerateGUID(); |
662 *payload = target_info.view_id; | 632 *payload = target_info.view_id; |
633 stream_target_info_[request] = target_info; | |
634 return true; | |
663 } | 635 } |
664 stream_target_info_[request] = target_info; | 636 } else { |
665 return true; | 637 if (!handler->HasPlugin() && handler->CanHandleMIMEType(mime_type)) { |
638 StreamTargetInfo target_info; | |
639 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | |
640 target_info.extension_id = extension_id; | |
641 stream_target_info_[request] = target_info; | |
642 return true; | |
643 } | |
666 } | 644 } |
667 } | 645 } |
668 #endif | 646 #endif |
669 return false; | 647 return false; |
670 } | 648 } |
671 | 649 |
672 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 650 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
673 net::URLRequest* request, | 651 net::URLRequest* request, |
674 scoped_ptr<content::StreamInfo> stream) { | 652 scoped_ptr<content::StreamInfo> stream) { |
675 #if defined(ENABLE_EXTENSIONS) | 653 #if defined(ENABLE_EXTENSIONS) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 url_request->GetTotalReceivedBytes())); | 758 url_request->GetTotalReceivedBytes())); |
781 } | 759 } |
782 } | 760 } |
783 | 761 |
784 // static | 762 // static |
785 void ChromeResourceDispatcherHostDelegate:: | 763 void ChromeResourceDispatcherHostDelegate:: |
786 SetExternalProtocolHandlerDelegateForTesting( | 764 SetExternalProtocolHandlerDelegateForTesting( |
787 ExternalProtocolHandler::Delegate* delegate) { | 765 ExternalProtocolHandler::Delegate* delegate) { |
788 g_external_protocol_handler_delegate = delegate; | 766 g_external_protocol_handler_delegate = delegate; |
789 } | 767 } |
OLD | NEW |