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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 Profile* profile = | 203 Profile* profile = |
204 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 204 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
205 | 205 |
206 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 206 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
207 if (!streams_private) | 207 if (!streams_private) |
208 return; | 208 return; |
209 streams_private->ExecuteMimeTypeHandler( | 209 streams_private->ExecuteMimeTypeHandler( |
210 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, | 210 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, |
211 embedded, render_process_id, render_frame_id); | 211 embedded, render_process_id, render_frame_id); |
212 } | 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 } | |
243 #endif // !defined(ENABLE_EXTENSIONS) | 213 #endif // !defined(ENABLE_EXTENSIONS) |
244 | 214 |
245 #if !defined(OS_ANDROID) | 215 #if !defined(OS_ANDROID) |
246 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 216 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { |
247 // If there is no longer a WebContents, the request may have raced with tab | 217 // If there is no longer a WebContents, the request may have raced with tab |
248 // closing. Don't fire the external request. (It may have been a prerender.) | 218 // closing. Don't fire the external request. (It may have been a prerender.) |
249 content::WebContents* web_contents = | 219 content::WebContents* web_contents = |
250 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 220 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
251 if (!web_contents) | 221 if (!web_contents) |
252 return; | 222 return; |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 const GURL& url, const std::string& mime_type) { | 591 const GURL& url, const std::string& mime_type) { |
622 #if defined(ENABLE_EXTENSIONS) | 592 #if defined(ENABLE_EXTENSIONS) |
623 // Special-case user scripts to get downloaded instead of viewed. | 593 // Special-case user scripts to get downloaded instead of viewed. |
624 return extensions::UserScript::IsURLUserScript(url, mime_type); | 594 return extensions::UserScript::IsURLUserScript(url, mime_type); |
625 #else | 595 #else |
626 return false; | 596 return false; |
627 #endif | 597 #endif |
628 } | 598 } |
629 | 599 |
630 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 600 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
601 const base::FilePath& file_path, | |
raymes
2015/03/12 05:21:03
plugin_path
| |
631 net::URLRequest* request, | 602 net::URLRequest* request, |
632 const std::string& mime_type, | 603 const std::string& mime_type, |
633 GURL* origin, | 604 GURL* origin, |
634 std::string* payload) { | 605 std::string* payload) { |
635 #if defined(ENABLE_EXTENSIONS) | 606 #if defined(ENABLE_EXTENSIONS) |
636 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 607 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
637 ProfileIOData* io_data = | 608 ProfileIOData* io_data = |
638 ProfileIOData::FromResourceContext(info->GetContext()); | 609 ProfileIOData::FromResourceContext(info->GetContext()); |
639 bool profile_is_off_the_record = io_data->IsOffTheRecord(); | 610 bool profile_is_off_the_record = io_data->IsOffTheRecord(); |
640 const scoped_refptr<const extensions::InfoMap> extension_info_map( | 611 const scoped_refptr<const extensions::InfoMap> extension_info_map( |
641 io_data->GetExtensionInfoMap()); | 612 io_data->GetExtensionInfoMap()); |
642 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 613 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
614 | |
615 content::PluginService* service = content::PluginService::GetInstance(); | |
616 content::PluginServiceFilter* filter = service->GetFilter(); | |
raymes
2015/03/12 05:21:03
We can remove the above 2 lines (see below)
| |
643 // Go through the white-listed extensions and try to use them to intercept | 617 // Go through the white-listed extensions and try to use them to intercept |
644 // the URL request. | 618 // the URL request. |
645 for (size_t i = 0; i < whitelist.size(); ++i) { | 619 for (size_t i = 0; i < whitelist.size(); ++i) { |
646 const char* extension_id = whitelist[i].c_str(); | 620 const char* extension_id = whitelist[i].c_str(); |
647 const Extension* extension = | 621 const Extension* extension = |
648 extension_info_map->extensions().GetByID(extension_id); | 622 extension_info_map->extensions().GetByID(extension_id); |
649 // The white-listed extension may not be installed, so we have to NULL check | 623 // The white-listed extension may not be installed, so we have to NULL check |
650 // |extension|. | 624 // |extension|. |
651 if (!extension || | 625 if (!extension || |
652 (profile_is_off_the_record && | 626 (profile_is_off_the_record && |
653 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 627 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
654 continue; | 628 continue; |
655 } | 629 } |
656 | 630 |
657 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 631 if (file_path == base::FilePath::FromUTF8Unsafe(extension->url().spec())) { |
658 if (handler && handler->CanHandleMIMEType(mime_type)) { | |
659 StreamTargetInfo target_info; | 632 StreamTargetInfo target_info; |
660 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 633 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
661 target_info.extension_id = extension_id; | 634 target_info.extension_id = extension_id; |
662 if (!handler->handler_url().empty()) { | 635 |
663 // This is reached in the case of MimeHandlerViews. If the | 636 content::WebPluginInfo plugin; |
664 // MimeHandlerView plugin is disabled, then we shouldn't intercept the | 637 bool plugin_info = service->GetPluginInfoByPath(file_path, &plugin); |
665 // stream. | 638 // Check that the plugin is actually enabled. |
raymes
2015/03/12 05:21:03
We don't need to check if it's enabled. This check
| |
666 if (!IsPluginEnabledForExtension(extension, info, mime_type, | 639 // MimeHandlerView plugin is disabled, then we shouldn't intercept the |
667 request->url())) { | 640 // stream. |
641 if (!plugin_info && filter && | |
642 !filter->IsPluginAvailable( | |
643 info->GetChildID(), info->GetRenderFrameID(), info->GetContext(), | |
644 request->url(), GURL(), &plugin)) { | |
668 continue; | 645 continue; |
669 } | |
670 target_info.view_id = base::GenerateGUID(); | |
671 *payload = target_info.view_id; | |
672 } | 646 } |
raymes
2015/03/12 05:21:03
I think we can add a DCHECK in this case:
DCHECK(!
| |
647 target_info.view_id = base::GenerateGUID(); | |
648 *payload = target_info.view_id; | |
673 stream_target_info_[request] = target_info; | 649 stream_target_info_[request] = target_info; |
674 return true; | 650 return true; |
651 } else { | |
652 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | |
653 if (handler && handler->CanHandleMIMEType(mime_type)) { | |
654 StreamTargetInfo target_info; | |
655 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | |
656 target_info.extension_id = extension_id; | |
657 if (!handler->handler_url().empty()) { | |
raymes
2015/03/12 05:21:03
In this case we should be able to remove this if-s
| |
658 target_info.view_id = base::GenerateGUID(); | |
659 *payload = target_info.view_id; | |
raymes
2015/03/12 05:21:03
We can remove the above 2 lines here, they should
| |
660 } | |
661 stream_target_info_[request] = target_info; | |
662 return true; | |
663 } | |
675 } | 664 } |
676 } | 665 } |
677 #endif | 666 #endif |
678 return false; | 667 return false; |
679 } | 668 } |
680 | 669 |
681 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 670 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
682 net::URLRequest* request, | 671 net::URLRequest* request, |
683 scoped_ptr<content::StreamInfo> stream) { | 672 scoped_ptr<content::StreamInfo> stream) { |
684 #if defined(ENABLE_EXTENSIONS) | 673 #if defined(ENABLE_EXTENSIONS) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 url_request->GetTotalReceivedBytes())); | 796 url_request->GetTotalReceivedBytes())); |
808 } | 797 } |
809 } | 798 } |
810 | 799 |
811 // static | 800 // static |
812 void ChromeResourceDispatcherHostDelegate:: | 801 void ChromeResourceDispatcherHostDelegate:: |
813 SetExternalProtocolHandlerDelegateForTesting( | 802 SetExternalProtocolHandlerDelegateForTesting( |
814 ExternalProtocolHandler::Delegate* delegate) { | 803 ExternalProtocolHandler::Delegate* delegate) { |
815 g_external_protocol_handler_delegate = delegate; | 804 g_external_protocol_handler_delegate = delegate; |
816 } | 805 } |
OLD | NEW |