Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc

Issue 953793003: Ensuring interception of stream get determined by plugin path before checking mime type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nits. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 #if defined(ENABLE_EXTENSIONS) 564 #if defined(ENABLE_EXTENSIONS)
595 // Special-case user scripts to get downloaded instead of viewed. 565 // Special-case user scripts to get downloaded instead of viewed.
596 return extensions::UserScript::IsURLUserScript(url, mime_type); 566 return extensions::UserScript::IsURLUserScript(url, mime_type);
597 #else 567 #else
598 return false; 568 return false;
599 #endif 569 #endif
600 } 570 }
601 571
602 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( 572 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
603 net::URLRequest* request, 573 net::URLRequest* request,
574 const base::FilePath& plugin_path,
604 const std::string& mime_type, 575 const std::string& mime_type,
605 GURL* origin, 576 GURL* origin,
606 std::string* payload) { 577 std::string* payload) {
607 #if defined(ENABLE_EXTENSIONS) 578 #if defined(ENABLE_EXTENSIONS)
608 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 579 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
609 ProfileIOData* io_data = 580 ProfileIOData* io_data =
610 ProfileIOData::FromResourceContext(info->GetContext()); 581 ProfileIOData::FromResourceContext(info->GetContext());
611 bool profile_is_off_the_record = io_data->IsOffTheRecord(); 582 bool profile_is_off_the_record = io_data->IsOffTheRecord();
612 const scoped_refptr<const extensions::InfoMap> extension_info_map( 583 const scoped_refptr<const extensions::InfoMap> extension_info_map(
613 io_data->GetExtensionInfoMap()); 584 io_data->GetExtensionInfoMap());
614 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); 585 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist();
615 // Go through the white-listed extensions and try to use them to intercept 586 // Go through the white-listed extensions and try to use them to intercept
616 // the URL request. 587 // the URL request.
617 for (const std::string& extension_id : whitelist) { 588 for (const std::string& extension_id : whitelist) {
618 const Extension* extension = 589 const Extension* extension =
619 extension_info_map->extensions().GetByID(extension_id); 590 extension_info_map->extensions().GetByID(extension_id);
620 // The white-listed extension may not be installed, so we have to NULL check 591 // The white-listed extension may not be installed, so we have to NULL check
621 // |extension|. 592 // |extension|.
622 if (!extension || 593 if (!extension ||
623 (profile_is_off_the_record && 594 (profile_is_off_the_record &&
624 !extension_info_map->IsIncognitoEnabled(extension_id))) { 595 !extension_info_map->IsIncognitoEnabled(extension_id))) {
625 continue; 596 continue;
626 } 597 }
627
628 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); 598 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension);
629 if (handler && handler->CanHandleMIMEType(mime_type)) { 599 // If the MimeHandlerView plugin to be loaded matches the extension,
600 // intercept the stream for that extension.
601 if (plugin_path ==
602 base::FilePath::FromUTF8Unsafe(extension->url().spec())) {
630 StreamTargetInfo target_info; 603 StreamTargetInfo target_info;
631 *origin = Extension::GetBaseURLFromExtensionId(extension_id); 604 *origin = Extension::GetBaseURLFromExtensionId(extension_id);
632 target_info.extension_id = extension_id; 605 target_info.extension_id = extension_id;
633 if (!handler->handler_url().empty()) { 606 DCHECK(!handler->handler_url().empty());
634 // This is reached in the case of MimeHandlerViews. If the 607 target_info.view_id = base::GenerateGUID();
635 // MimeHandlerView plugin is disabled, then we shouldn't intercept the 608 *payload = target_info.view_id;
636 // stream. 609 stream_target_info_[request] = target_info;
637 if (!IsPluginEnabledForExtension(extension, info, mime_type, 610 return true;
638 request->url())) { 611 } else if (plugin_path.empty() && handler &&
639 continue; 612 handler->CanHandleMIMEType(mime_type)) {
640 } 613 // If no plugin path is provided, then we are trying to intercept the
641 target_info.view_id = base::GenerateGUID(); 614 // stream for the streamsPrivate API.
642 *payload = target_info.view_id; 615 StreamTargetInfo target_info;
643 } 616 *origin = Extension::GetBaseURLFromExtensionId(extension_id);
617 target_info.extension_id = extension_id;
618 DCHECK(handler->handler_url().empty());
644 stream_target_info_[request] = target_info; 619 stream_target_info_[request] = target_info;
645 return true; 620 return true;
646 } 621 }
647 } 622 }
648 #endif 623 #endif
649 return false; 624 return false;
650 } 625 }
651 626
652 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( 627 void ChromeResourceDispatcherHostDelegate::OnStreamCreated(
653 net::URLRequest* request, 628 net::URLRequest* request,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 url_request->GetTotalReceivedBytes())); 734 url_request->GetTotalReceivedBytes()));
760 } 735 }
761 } 736 }
762 737
763 // static 738 // static
764 void ChromeResourceDispatcherHostDelegate:: 739 void ChromeResourceDispatcherHostDelegate::
765 SetExternalProtocolHandlerDelegateForTesting( 740 SetExternalProtocolHandlerDelegateForTesting(
766 ExternalProtocolHandler::Delegate* delegate) { 741 ExternalProtocolHandler::Delegate* delegate) {
767 g_external_protocol_handler_delegate = delegate; 742 g_external_protocol_handler_delegate = delegate;
768 } 743 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698