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

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

Issue 1164073006: Make the logic for stream interception by MimeHandlerViews consistent with starting the plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 Profile* profile = 199 Profile* profile =
200 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 200 Profile::FromBrowserContext(web_contents->GetBrowserContext());
201 201
202 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); 202 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile);
203 if (!streams_private) 203 if (!streams_private)
204 return; 204 return;
205 streams_private->ExecuteMimeTypeHandler( 205 streams_private->ExecuteMimeTypeHandler(
206 extension_id, web_contents, stream.Pass(), view_id, expected_content_size, 206 extension_id, web_contents, stream.Pass(), view_id, expected_content_size,
207 embedded, render_process_id, render_frame_id); 207 embedded, render_process_id, render_frame_id);
208 } 208 }
209
210 // TODO(raymes): This won't return the right result if plugins haven't been
211 // loaded yet. Fixing this properly really requires fixing crbug.com/443466.
212 bool IsPluginEnabledForExtension(const Extension* extension,
213 const ResourceRequestInfo* info,
214 const std::string& mime_type,
215 const GURL& url) {
216 content::PluginService* service = content::PluginService::GetInstance();
217 std::vector<content::WebPluginInfo> plugins;
218 service->GetPluginInfoArray(url, mime_type, true, &plugins, nullptr);
219 content::PluginServiceFilter* filter = service->GetFilter();
220
221 for (auto& plugin : plugins) {
222 // Check that the plugin is running the extension.
223 if (plugin.path !=
224 base::FilePath::FromUTF8Unsafe(extension->url().spec())) {
225 continue;
226 }
227 // Check that the plugin is actually enabled.
228 if (!filter || filter->IsPluginAvailable(info->GetChildID(),
229 info->GetRenderFrameID(),
230 info->GetContext(),
231 url,
232 GURL(),
233 &plugin)) {
234 return true;
235 }
236 }
237 return false;
238 }
239 #endif // !defined(ENABLE_EXTENSIONS) 209 #endif // !defined(ENABLE_EXTENSIONS)
240 210
241 void LaunchURL( 211 void LaunchURL(
242 const GURL& url, 212 const GURL& url,
243 int render_process_id, 213 int render_process_id,
244 int render_view_id, 214 int render_view_id,
245 ui::PageTransition page_transition, 215 ui::PageTransition page_transition,
246 bool has_user_gesture) { 216 bool has_user_gesture) {
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.)
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 #if defined(ENABLE_EXTENSIONS) 574 #if defined(ENABLE_EXTENSIONS)
605 // Special-case user scripts to get downloaded instead of viewed. 575 // Special-case user scripts to get downloaded instead of viewed.
606 return extensions::UserScript::IsURLUserScript(url, mime_type); 576 return extensions::UserScript::IsURLUserScript(url, mime_type);
607 #else 577 #else
608 return false; 578 return false;
609 #endif 579 #endif
610 } 580 }
611 581
612 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( 582 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
613 net::URLRequest* request, 583 net::URLRequest* request,
584 const base::FilePath& plugin_path,
614 const std::string& mime_type, 585 const std::string& mime_type,
615 GURL* origin, 586 GURL* origin,
616 std::string* payload) { 587 std::string* payload) {
617 #if defined(ENABLE_EXTENSIONS) 588 #if defined(ENABLE_EXTENSIONS)
618 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 589 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
619 ProfileIOData* io_data = 590 ProfileIOData* io_data =
620 ProfileIOData::FromResourceContext(info->GetContext()); 591 ProfileIOData::FromResourceContext(info->GetContext());
621 bool profile_is_off_the_record = io_data->IsOffTheRecord(); 592 bool profile_is_off_the_record = io_data->IsOffTheRecord();
622 const scoped_refptr<const extensions::InfoMap> extension_info_map( 593 const scoped_refptr<const extensions::InfoMap> extension_info_map(
623 io_data->GetExtensionInfoMap()); 594 io_data->GetExtensionInfoMap());
624 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); 595 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist();
625 // Go through the white-listed extensions and try to use them to intercept 596 // Go through the white-listed extensions and try to use them to intercept
626 // the URL request. 597 // the URL request.
627 for (const std::string& extension_id : whitelist) { 598 for (const std::string& extension_id : whitelist) {
628 const Extension* extension = 599 const Extension* extension =
629 extension_info_map->extensions().GetByID(extension_id); 600 extension_info_map->extensions().GetByID(extension_id);
630 // The white-listed extension may not be installed, so we have to NULL check 601 // The white-listed extension may not be installed, so we have to NULL check
631 // |extension|. 602 // |extension|.
632 if (!extension || 603 if (!extension ||
633 (profile_is_off_the_record && 604 (profile_is_off_the_record &&
634 !extension_info_map->IsIncognitoEnabled(extension_id))) { 605 !extension_info_map->IsIncognitoEnabled(extension_id))) {
635 continue; 606 continue;
636 } 607 }
637
638 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); 608 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension);
639 if (handler && handler->CanHandleMIMEType(mime_type)) { 609 // If the MimeHandlerView plugin to be loaded matches the extension,
610 // intercept the stream for that extension. Note that MimeHandlerView
611 // plugins have a path that is the extension URL which backs them.
612 GURL mime_handler_extension_url(plugin_path.AsUTF8Unsafe());
mmenke 2015/06/11 19:38:04 I'm not following this...We have a path, we get it
raymes 2015/07/01 05:13:18 You're right, it doesn't make much sense, especial
613 if (mime_handler_extension_url == extension->url()) {
640 StreamTargetInfo target_info; 614 StreamTargetInfo target_info;
641 *origin = Extension::GetBaseURLFromExtensionId(extension_id); 615 *origin = Extension::GetBaseURLFromExtensionId(extension_id);
642 target_info.extension_id = extension_id; 616 target_info.extension_id = extension_id;
643 if (!handler->handler_url().empty()) { 617 DCHECK(!handler->handler_url().empty());
644 // This is reached in the case of MimeHandlerViews. If the 618 target_info.view_id = base::GenerateGUID();
645 // MimeHandlerView plugin is disabled, then we shouldn't intercept the 619 *payload = target_info.view_id;
646 // stream. 620 stream_target_info_[request] = target_info;
647 if (!IsPluginEnabledForExtension(extension, info, mime_type, 621 return true;
648 request->url())) { 622 } else if (mime_handler_extension_url.is_empty() && handler &&
649 continue; 623 handler->CanHandleMIMEType(mime_type) &&
650 } 624 handler->handler_url().empty()) {
651 target_info.view_id = base::GenerateGUID(); 625 // If no plugin path is provided, then we are trying to intercept the
652 *payload = target_info.view_id; 626 // stream for the streamsPrivate API.
653 } 627 StreamTargetInfo target_info;
628 *origin = Extension::GetBaseURLFromExtensionId(extension_id);
629 target_info.extension_id = extension_id;
mmenke 2015/06/11 19:38:04 I can't verify the correctness of this code.
raymes 2015/07/01 05:13:18 That's ok, I'll get sammc@ to review this. He's fa
654 stream_target_info_[request] = target_info; 630 stream_target_info_[request] = target_info;
655 return true; 631 return true;
656 } 632 }
657 } 633 }
658 #endif 634 #endif
659 return false; 635 return false;
660 } 636 }
661 637
662 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( 638 void ChromeResourceDispatcherHostDelegate::OnStreamCreated(
663 net::URLRequest* request, 639 net::URLRequest* request,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 url_request->GetTotalReceivedBytes())); 746 url_request->GetTotalReceivedBytes()));
771 } 747 }
772 } 748 }
773 749
774 // static 750 // static
775 void ChromeResourceDispatcherHostDelegate:: 751 void ChromeResourceDispatcherHostDelegate::
776 SetExternalProtocolHandlerDelegateForTesting( 752 SetExternalProtocolHandlerDelegateForTesting(
777 ExternalProtocolHandler::Delegate* delegate) { 753 ExternalProtocolHandler::Delegate* delegate) {
778 g_external_protocol_handler_delegate = delegate; 754 g_external_protocol_handler_delegate = delegate;
779 } 755 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698