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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 Profile* profile = | 202 Profile* profile = |
203 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 203 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
204 | 204 |
205 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 205 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
206 if (!streams_private) | 206 if (!streams_private) |
207 return; | 207 return; |
208 streams_private->ExecuteMimeTypeHandler( | 208 streams_private->ExecuteMimeTypeHandler( |
209 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, | 209 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, |
210 embedded, render_process_id, render_frame_id); | 210 embedded, render_process_id, render_frame_id); |
211 } | 211 } |
212 | |
213 // TODO(raymes): This won't return the right result if plugins haven't been | |
214 // loaded yet. Fixing this properly really requires fixing crbug.com/443466. | |
215 bool IsPluginEnabledForExtension(const Extension* extension, | |
216 const ResourceRequestInfo* info, | |
217 const std::string& mime_type, | |
218 const GURL& url) { | |
219 content::PluginService* service = content::PluginService::GetInstance(); | |
220 std::vector<content::WebPluginInfo> plugins; | |
221 service->GetPluginInfoArray(url, mime_type, true, &plugins, nullptr); | |
222 content::PluginServiceFilter* filter = service->GetFilter(); | |
223 | |
224 for (auto& plugin : plugins) { | |
225 // Check that the plugin is running the extension. | |
226 if (plugin.path != | |
227 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { | |
228 continue; | |
229 } | |
230 // Check that the plugin is actually enabled. | |
231 if (!filter || filter->IsPluginAvailable(info->GetChildID(), | |
232 info->GetRenderFrameID(), | |
233 info->GetContext(), | |
234 url, | |
235 GURL(), | |
236 &plugin)) { | |
237 return true; | |
238 } | |
239 } | |
240 return false; | |
241 } | |
242 #endif // !defined(ENABLE_EXTENSIONS) | 212 #endif // !defined(ENABLE_EXTENSIONS) |
243 | 213 |
244 #if !defined(OS_ANDROID) | 214 #if !defined(OS_ANDROID) |
245 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 215 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { |
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.) |
248 content::WebContents* web_contents = | 218 content::WebContents* web_contents = |
249 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 219 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
250 if (!web_contents) | 220 if (!web_contents) |
251 return; | 221 return; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 const GURL& url, const std::string& mime_type) { | 589 const GURL& url, const std::string& mime_type) { |
620 #if defined(ENABLE_EXTENSIONS) | 590 #if defined(ENABLE_EXTENSIONS) |
621 // Special-case user scripts to get downloaded instead of viewed. | 591 // Special-case user scripts to get downloaded instead of viewed. |
622 return extensions::UserScript::IsURLUserScript(url, mime_type); | 592 return extensions::UserScript::IsURLUserScript(url, mime_type); |
623 #else | 593 #else |
624 return false; | 594 return false; |
625 #endif | 595 #endif |
626 } | 596 } |
627 | 597 |
628 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 598 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
599 const base::FilePath& plugin_path, | |
629 net::URLRequest* request, | 600 net::URLRequest* request, |
630 const std::string& mime_type, | 601 const std::string& mime_type, |
631 GURL* origin, | 602 GURL* origin, |
632 std::string* payload) { | 603 std::string* payload) { |
633 #if defined(ENABLE_EXTENSIONS) | 604 #if defined(ENABLE_EXTENSIONS) |
634 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 605 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
635 ProfileIOData* io_data = | 606 ProfileIOData* io_data = |
636 ProfileIOData::FromResourceContext(info->GetContext()); | 607 ProfileIOData::FromResourceContext(info->GetContext()); |
637 bool profile_is_off_the_record = io_data->IsOffTheRecord(); | 608 bool profile_is_off_the_record = io_data->IsOffTheRecord(); |
638 const scoped_refptr<const extensions::InfoMap> extension_info_map( | 609 const scoped_refptr<const extensions::InfoMap> extension_info_map( |
639 io_data->GetExtensionInfoMap()); | 610 io_data->GetExtensionInfoMap()); |
640 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 611 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
612 | |
raymes
2015/03/16 05:36:50
nit: don't need a newline
Deepak
2015/03/16 10:17:32
Done.
| |
641 // Go through the white-listed extensions and try to use them to intercept | 613 // Go through the white-listed extensions and try to use them to intercept |
642 // the URL request. | 614 // the URL request. |
643 for (size_t i = 0; i < whitelist.size(); ++i) { | 615 for (size_t i = 0; i < whitelist.size(); ++i) { |
644 const char* extension_id = whitelist[i].c_str(); | 616 const char* extension_id = whitelist[i].c_str(); |
645 const Extension* extension = | 617 const Extension* extension = |
646 extension_info_map->extensions().GetByID(extension_id); | 618 extension_info_map->extensions().GetByID(extension_id); |
647 // The white-listed extension may not be installed, so we have to NULL check | 619 // The white-listed extension may not be installed, so we have to NULL check |
648 // |extension|. | 620 // |extension|. |
649 if (!extension || | 621 if (!extension || |
650 (profile_is_off_the_record && | 622 (profile_is_off_the_record && |
651 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 623 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
652 continue; | 624 continue; |
653 } | 625 } |
654 | |
655 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 626 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
656 if (handler && handler->CanHandleMIMEType(mime_type)) { | 627 if (plugin_path == |
raymes
2015/03/16 05:36:50
We should add a comment above this line:
// If the
Deepak
2015/03/16 10:17:33
Done.
| |
628 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { | |
657 StreamTargetInfo target_info; | 629 StreamTargetInfo target_info; |
658 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 630 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
659 target_info.extension_id = extension_id; | 631 target_info.extension_id = extension_id; |
660 if (!handler->handler_url().empty()) { | 632 DCHECK(!handler->handler_url().empty()); |
661 // This is reached in the case of MimeHandlerViews. If the | 633 target_info.view_id = base::GenerateGUID(); |
662 // MimeHandlerView plugin is disabled, then we shouldn't intercept the | 634 *payload = target_info.view_id; |
663 // stream. | |
664 if (!IsPluginEnabledForExtension(extension, info, mime_type, | |
665 request->url())) { | |
666 continue; | |
667 } | |
668 target_info.view_id = base::GenerateGUID(); | |
669 *payload = target_info.view_id; | |
670 } | |
671 stream_target_info_[request] = target_info; | 635 stream_target_info_[request] = target_info; |
672 return true; | 636 return true; |
637 } else { | |
raymes
2015/03/16 05:36:49
Actually we should do this only if the plugin path
Deepak
2015/03/16 10:17:32
Done.
| |
638 if (handler && handler->CanHandleMIMEType(mime_type)) { | |
639 StreamTargetInfo target_info; | |
640 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | |
641 target_info.extension_id = extension_id; | |
642 DCHECK(handler->handler_url().empty()); | |
643 stream_target_info_[request] = target_info; | |
644 return true; | |
645 } | |
673 } | 646 } |
674 } | 647 } |
675 #endif | 648 #endif |
676 return false; | 649 return false; |
677 } | 650 } |
678 | 651 |
679 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 652 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
680 net::URLRequest* request, | 653 net::URLRequest* request, |
681 scoped_ptr<content::StreamInfo> stream) { | 654 scoped_ptr<content::StreamInfo> stream) { |
682 #if defined(ENABLE_EXTENSIONS) | 655 #if defined(ENABLE_EXTENSIONS) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 url_request->GetTotalReceivedBytes())); | 778 url_request->GetTotalReceivedBytes())); |
806 } | 779 } |
807 } | 780 } |
808 | 781 |
809 // static | 782 // static |
810 void ChromeResourceDispatcherHostDelegate:: | 783 void ChromeResourceDispatcherHostDelegate:: |
811 SetExternalProtocolHandlerDelegateForTesting( | 784 SetExternalProtocolHandlerDelegateForTesting( |
812 ExternalProtocolHandler::Delegate* delegate) { | 785 ExternalProtocolHandler::Delegate* delegate) { |
813 g_external_protocol_handler_delegate = delegate; | 786 g_external_protocol_handler_delegate = delegate; |
814 } | 787 } |
OLD | NEW |