Chromium Code Reviews| 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 #if !defined(OS_ANDROID) | 210 #if !defined(OS_ANDROID) |
| 241 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 211 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { |
| 242 // If there is no longer a WebContents, the request may have raced with tab | 212 // If there is no longer a WebContents, the request may have raced with tab |
| 243 // closing. Don't fire the external request. (It may have been a prerender.) | 213 // closing. Don't fire the external request. (It may have been a prerender.) |
| 244 content::WebContents* web_contents = | 214 content::WebContents* web_contents = |
| 245 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 215 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 246 if (!web_contents) | 216 if (!web_contents) |
| 247 return; | 217 return; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 const GURL& url, const std::string& mime_type) { | 559 const GURL& url, const std::string& mime_type) { |
| 590 #if defined(ENABLE_EXTENSIONS) | 560 #if defined(ENABLE_EXTENSIONS) |
| 591 // Special-case user scripts to get downloaded instead of viewed. | 561 // Special-case user scripts to get downloaded instead of viewed. |
| 592 return extensions::UserScript::IsURLUserScript(url, mime_type); | 562 return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 593 #else | 563 #else |
| 594 return false; | 564 return false; |
| 595 #endif | 565 #endif |
| 596 } | 566 } |
| 597 | 567 |
| 598 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 568 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
| 569 const base::FilePath& plugin_path, | |
| 599 net::URLRequest* request, | 570 net::URLRequest* request, |
| 600 const std::string& mime_type, | 571 const std::string& mime_type, |
| 601 GURL* origin, | 572 GURL* origin, |
| 602 std::string* payload) { | 573 std::string* payload) { |
| 603 #if defined(ENABLE_EXTENSIONS) | 574 #if defined(ENABLE_EXTENSIONS) |
| 604 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 575 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 605 ProfileIOData* io_data = | 576 ProfileIOData* io_data = |
| 606 ProfileIOData::FromResourceContext(info->GetContext()); | 577 ProfileIOData::FromResourceContext(info->GetContext()); |
| 607 bool profile_is_off_the_record = io_data->IsOffTheRecord(); | 578 bool profile_is_off_the_record = io_data->IsOffTheRecord(); |
| 608 const scoped_refptr<const extensions::InfoMap> extension_info_map( | 579 const scoped_refptr<const extensions::InfoMap> extension_info_map( |
| 609 io_data->GetExtensionInfoMap()); | 580 io_data->GetExtensionInfoMap()); |
| 610 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 581 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
| 611 // Go through the white-listed extensions and try to use them to intercept | 582 // Go through the white-listed extensions and try to use them to intercept |
| 612 // the URL request. | 583 // the URL request. |
| 613 for (size_t i = 0; i < whitelist.size(); ++i) { | 584 for (size_t i = 0; i < whitelist.size(); ++i) { |
| 614 const char* extension_id = whitelist[i].c_str(); | 585 const char* extension_id = whitelist[i].c_str(); |
| 615 const Extension* extension = | 586 const Extension* extension = |
| 616 extension_info_map->extensions().GetByID(extension_id); | 587 extension_info_map->extensions().GetByID(extension_id); |
| 617 // The white-listed extension may not be installed, so we have to NULL check | 588 // The white-listed extension may not be installed, so we have to NULL check |
| 618 // |extension|. | 589 // |extension|. |
| 619 if (!extension || | 590 if (!extension || |
| 620 (profile_is_off_the_record && | 591 (profile_is_off_the_record && |
| 621 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 592 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
| 622 continue; | 593 continue; |
| 623 } | 594 } |
| 624 | |
| 625 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 595 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 626 if (handler && handler->CanHandleMIMEType(mime_type)) { | 596 // If the MimeHandlerView plugin to be loaded matches the extension, |
| 597 // intercept the stream for that extension. | |
| 598 if (plugin_path == | |
| 599 base::FilePath::FromUTF8Unsafe(extension->url().spec())) { | |
| 627 StreamTargetInfo target_info; | 600 StreamTargetInfo target_info; |
| 628 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | 601 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
| 629 target_info.extension_id = extension_id; | 602 target_info.extension_id = extension_id; |
| 630 if (!handler->handler_url().empty()) { | 603 DCHECK(!handler->handler_url().empty()); |
| 631 // This is reached in the case of MimeHandlerViews. If the | 604 target_info.view_id = base::GenerateGUID(); |
| 632 // MimeHandlerView plugin is disabled, then we shouldn't intercept the | 605 *payload = target_info.view_id; |
| 633 // stream. | |
| 634 if (!IsPluginEnabledForExtension(extension, info, mime_type, | |
| 635 request->url())) { | |
| 636 continue; | |
| 637 } | |
| 638 target_info.view_id = base::GenerateGUID(); | |
| 639 *payload = target_info.view_id; | |
| 640 } | |
| 641 stream_target_info_[request] = target_info; | 606 stream_target_info_[request] = target_info; |
| 642 return true; | 607 return true; |
| 608 } else { | |
| 609 // If no plugin path is provided, then we are trying to intercept the | |
| 610 // stream for the streamsPrivate API. | |
| 611 if (plugin_path.empty() && handler && | |
|
raymes
2015/03/19 00:39:22
Please merge this if-statement into the else above
Deepak
2015/03/19 10:22:22
Done.
| |
| 612 handler->CanHandleMIMEType(mime_type)) { | |
| 613 StreamTargetInfo target_info; | |
| 614 *origin = Extension::GetBaseURLFromExtensionId(extension_id); | |
| 615 target_info.extension_id = extension_id; | |
| 616 DCHECK(handler->handler_url().empty()); | |
| 617 stream_target_info_[request] = target_info; | |
| 618 return true; | |
| 619 } | |
| 643 } | 620 } |
| 644 } | 621 } |
| 645 #endif | 622 #endif |
| 646 return false; | 623 return false; |
| 647 } | 624 } |
| 648 | 625 |
| 649 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 626 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
| 650 net::URLRequest* request, | 627 net::URLRequest* request, |
| 651 scoped_ptr<content::StreamInfo> stream) { | 628 scoped_ptr<content::StreamInfo> stream) { |
| 652 #if defined(ENABLE_EXTENSIONS) | 629 #if defined(ENABLE_EXTENSIONS) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 url_request->GetTotalReceivedBytes())); | 733 url_request->GetTotalReceivedBytes())); |
| 757 } | 734 } |
| 758 } | 735 } |
| 759 | 736 |
| 760 // static | 737 // static |
| 761 void ChromeResourceDispatcherHostDelegate:: | 738 void ChromeResourceDispatcherHostDelegate:: |
| 762 SetExternalProtocolHandlerDelegateForTesting( | 739 SetExternalProtocolHandlerDelegateForTesting( |
| 763 ExternalProtocolHandler::Delegate* delegate) { | 740 ExternalProtocolHandler::Delegate* delegate) { |
| 764 g_external_protocol_handler_delegate = delegate; | 741 g_external_protocol_handler_delegate = delegate; |
| 765 } | 742 } |
| OLD | NEW |