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 } | |
238 #endif // !defined(ENABLE_EXTENSIONS) | 208 #endif // !defined(ENABLE_EXTENSIONS) |
239 | 209 |
240 void LaunchURL( | 210 void LaunchURL( |
241 const GURL& url, | 211 const GURL& url, |
242 int render_process_id, | 212 int render_process_id, |
243 int render_view_id, | 213 int render_view_id, |
244 ui::PageTransition page_transition, | 214 ui::PageTransition page_transition, |
245 bool has_user_gesture) { | 215 bool has_user_gesture) { |
246 // If there is no longer a WebContents, the request may have raced with tab | 216 // If there is no longer a WebContents, the request may have raced with tab |
247 // closing. Don't fire the external request. (It may have been a prerender.) | 217 // closing. Don't fire the external request. (It may have been a prerender.) |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 #if defined(ENABLE_EXTENSIONS) | 569 #if defined(ENABLE_EXTENSIONS) |
600 // Special-case user scripts to get downloaded instead of viewed. | 570 // Special-case user scripts to get downloaded instead of viewed. |
601 return extensions::UserScript::IsURLUserScript(url, mime_type); | 571 return extensions::UserScript::IsURLUserScript(url, mime_type); |
602 #else | 572 #else |
603 return false; | 573 return false; |
604 #endif | 574 #endif |
605 } | 575 } |
606 | 576 |
607 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 577 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
608 net::URLRequest* request, | 578 net::URLRequest* request, |
579 const base::FilePath& plugin_path, | |
609 const std::string& mime_type, | 580 const std::string& mime_type, |
610 GURL* origin, | 581 GURL* origin, |
611 std::string* payload) { | 582 std::string* payload) { |
612 #if defined(ENABLE_EXTENSIONS) | 583 #if defined(ENABLE_EXTENSIONS) |
613 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 584 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
614 ProfileIOData* io_data = | 585 ProfileIOData* io_data = |
615 ProfileIOData::FromResourceContext(info->GetContext()); | 586 ProfileIOData::FromResourceContext(info->GetContext()); |
616 bool profile_is_off_the_record = io_data->IsOffTheRecord(); | 587 bool profile_is_off_the_record = io_data->IsOffTheRecord(); |
617 const scoped_refptr<const extensions::InfoMap> extension_info_map( | 588 const scoped_refptr<const extensions::InfoMap> extension_info_map( |
618 io_data->GetExtensionInfoMap()); | 589 io_data->GetExtensionInfoMap()); |
619 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 590 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
620 // Go through the white-listed extensions and try to use them to intercept | 591 // Go through the white-listed extensions and try to use them to intercept |
621 // the URL request. | 592 // the URL request. |
622 for (const std::string& extension_id : whitelist) { | 593 for (const std::string& extension_id : whitelist) { |
623 const Extension* extension = | 594 const Extension* extension = |
624 extension_info_map->extensions().GetByID(extension_id); | 595 extension_info_map->extensions().GetByID(extension_id); |
625 // The white-listed extension may not be installed, so we have to NULL check | 596 // The white-listed extension may not be installed, so we have to NULL check |
626 // |extension|. | 597 // |extension|. |
627 if (!extension || | 598 if (!extension || |
628 (profile_is_off_the_record && | 599 (profile_is_off_the_record && |
629 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 600 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
630 continue; | 601 continue; |
631 } | 602 } |
603 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | |
604 if (!handler) | |
605 continue; | |
632 | 606 |
633 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 607 // If a plugin path is provided then a stream is being intercepted for the |
634 if (handler && handler->CanHandleMIMEType(mime_type)) { | 608 // mimeHandlerPrivate API. Otherwise a stream is being intercepted for the |
609 // streamsPrivate API. | |
mmenke
2015/07/17 19:47:51
Optional: The behavior is the same, but I think t
raymes
2015/07/20 04:14:18
Done.
| |
610 if (!plugin_path.empty() && handler->HasPlugin() && | |
611 plugin_path == handler->GetPluginPath()) { | |
635 StreamTargetInfo target_info; | 612 StreamTargetInfo target_info; |
636 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 613 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
637 target_info.extension_id = extension_id; | 614 target_info.extension_id = extension_id; |
638 if (!handler->handler_url().empty()) { | 615 target_info.view_id = base::GenerateGUID(); |
639 // This is reached in the case of MimeHandlerViews. If the | 616 *payload = target_info.view_id; |
640 // MimeHandlerView plugin is disabled, then we shouldn't intercept the | |
641 // stream. | |
642 if (!IsPluginEnabledForExtension(extension, info, mime_type, | |
643 request->url())) { | |
644 continue; | |
645 } | |
646 target_info.view_id = base::GenerateGUID(); | |
647 *payload = target_info.view_id; | |
648 } | |
649 stream_target_info_[request] = target_info; | 617 stream_target_info_[request] = target_info; |
650 return true; | 618 return true; |
651 } | 619 } |
620 | |
621 if (plugin_path.empty() && !handler->HasPlugin() && | |
622 handler->CanHandleMIMEType(mime_type)) { | |
623 StreamTargetInfo target_info; | |
624 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | |
625 target_info.extension_id = extension_id; | |
626 stream_target_info_[request] = target_info; | |
627 return true; | |
628 } | |
652 } | 629 } |
653 #endif | 630 #endif |
654 return false; | 631 return false; |
655 } | 632 } |
656 | 633 |
657 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 634 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
658 net::URLRequest* request, | 635 net::URLRequest* request, |
659 scoped_ptr<content::StreamInfo> stream) { | 636 scoped_ptr<content::StreamInfo> stream) { |
660 #if defined(ENABLE_EXTENSIONS) | 637 #if defined(ENABLE_EXTENSIONS) |
661 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 638 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 url_request->GetTotalReceivedBytes())); | 744 url_request->GetTotalReceivedBytes())); |
768 } | 745 } |
769 } | 746 } |
770 | 747 |
771 // static | 748 // static |
772 void ChromeResourceDispatcherHostDelegate:: | 749 void ChromeResourceDispatcherHostDelegate:: |
773 SetExternalProtocolHandlerDelegateForTesting( | 750 SetExternalProtocolHandlerDelegateForTesting( |
774 ExternalProtocolHandler::Delegate* delegate) { | 751 ExternalProtocolHandler::Delegate* delegate) { |
775 g_external_protocol_handler_delegate = delegate; | 752 g_external_protocol_handler_delegate = delegate; |
776 } | 753 } |
OLD | NEW |