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

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: Resolving Build Errors. Created 5 years, 9 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
599 net::URLRequest* request, 569 net::URLRequest* request,
570 const base::FilePath& plugin_path,
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 (const std::string& extension_id : whitelist) { 584 for (const std::string& extension_id : whitelist) {
614 const Extension* extension = 585 const Extension* extension =
615 extension_info_map->extensions().GetByID(extension_id); 586 extension_info_map->extensions().GetByID(extension_id);
616 // The white-listed extension may not be installed, so we have to NULL check 587 // The white-listed extension may not be installed, so we have to NULL check
617 // |extension|. 588 // |extension|.
618 if (!extension || 589 if (!extension ||
619 (profile_is_off_the_record && 590 (profile_is_off_the_record &&
620 !extension_info_map->IsIncognitoEnabled(extension_id))) { 591 !extension_info_map->IsIncognitoEnabled(extension_id))) {
621 continue; 592 continue;
622 } 593 }
623
624 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); 594 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension);
625 if (handler && handler->CanHandleMIMEType(mime_type)) { 595 // If the MimeHandlerView plugin to be loaded matches the extension,
596 // intercept the stream for that extension.
597 if (plugin_path ==
598 base::FilePath::FromUTF8Unsafe(extension->url().spec())) {
626 StreamTargetInfo target_info; 599 StreamTargetInfo target_info;
627 *origin = Extension::GetBaseURLFromExtensionId(extension_id); 600 *origin = Extension::GetBaseURLFromExtensionId(extension_id);
628 target_info.extension_id = extension_id; 601 target_info.extension_id = extension_id;
629 if (!handler->handler_url().empty()) { 602 DCHECK(!handler->handler_url().empty());
630 // This is reached in the case of MimeHandlerViews. If the 603 target_info.view_id = base::GenerateGUID();
631 // MimeHandlerView plugin is disabled, then we shouldn't intercept the 604 *payload = target_info.view_id;
632 // stream. 605 stream_target_info_[request] = target_info;
633 if (!IsPluginEnabledForExtension(extension, info, mime_type, 606 return true;
634 request->url())) { 607 } else if (plugin_path.empty() && handler &&
635 continue; 608 handler->CanHandleMIMEType(mime_type)) {
636 } 609 // If no plugin path is provided, then we are trying to intercept the
637 target_info.view_id = base::GenerateGUID(); 610 // stream for the streamsPrivate API.
638 *payload = target_info.view_id; 611 StreamTargetInfo target_info;
639 } 612 *origin = Extension::GetBaseURLFromExtensionId(extension_id);
613 target_info.extension_id = extension_id;
614 DCHECK(handler->handler_url().empty());
640 stream_target_info_[request] = target_info; 615 stream_target_info_[request] = target_info;
641 return true; 616 return true;
642 } 617 }
643 } 618 }
644 #endif 619 #endif
645 return false; 620 return false;
646 } 621 }
647 622
648 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( 623 void ChromeResourceDispatcherHostDelegate::OnStreamCreated(
649 net::URLRequest* request, 624 net::URLRequest* request,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 url_request->GetTotalReceivedBytes())); 730 url_request->GetTotalReceivedBytes()));
756 } 731 }
757 } 732 }
758 733
759 // static 734 // static
760 void ChromeResourceDispatcherHostDelegate:: 735 void ChromeResourceDispatcherHostDelegate::
761 SetExternalProtocolHandlerDelegateForTesting( 736 SetExternalProtocolHandlerDelegateForTesting(
762 ExternalProtocolHandler::Delegate* delegate) { 737 ExternalProtocolHandler::Delegate* delegate) {
763 g_external_protocol_handler_delegate = delegate; 738 g_external_protocol_handler_delegate = delegate;
764 } 739 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698