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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 2855123003: Remove rendundant WebLocalFrame parameter in various plugin code. (Closed)
Patch Set: Fix Android Created 3 years, 7 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/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 GetImageNamed(IDR_SAD_PLUGIN).ToSkBitmap()); 618 GetImageNamed(IDR_SAD_PLUGIN).ToSkBitmap());
619 } 619 }
620 620
621 SkBitmap* ChromeContentRendererClient::GetSadWebViewBitmap() { 621 SkBitmap* ChromeContentRendererClient::GetSadWebViewBitmap() {
622 return const_cast<SkBitmap*>(ResourceBundle::GetSharedInstance(). 622 return const_cast<SkBitmap*>(ResourceBundle::GetSharedInstance().
623 GetImageNamed(IDR_SAD_WEBVIEW).ToSkBitmap()); 623 GetImageNamed(IDR_SAD_WEBVIEW).ToSkBitmap());
624 } 624 }
625 625
626 bool ChromeContentRendererClient::OverrideCreatePlugin( 626 bool ChromeContentRendererClient::OverrideCreatePlugin(
627 content::RenderFrame* render_frame, 627 content::RenderFrame* render_frame,
628 WebLocalFrame* frame,
629 const WebPluginParams& params, 628 const WebPluginParams& params,
630 WebPlugin** plugin) { 629 WebPlugin** plugin) {
631 std::string orig_mime_type = params.mime_type.Utf8(); 630 std::string orig_mime_type = params.mime_type.Utf8();
632 #if BUILDFLAG(ENABLE_EXTENSIONS) 631 #if BUILDFLAG(ENABLE_EXTENSIONS)
633 if (!ChromeExtensionsRendererClient::GetInstance()->OverrideCreatePlugin( 632 if (!ChromeExtensionsRendererClient::GetInstance()->OverrideCreatePlugin(
634 render_frame, params)) { 633 render_frame, params)) {
635 return false; 634 return false;
636 } 635 }
637 #endif 636 #endif
638 637
639 GURL url(params.url); 638 GURL url(params.url);
640 #if BUILDFLAG(ENABLE_PLUGINS) 639 #if BUILDFLAG(ENABLE_PLUGINS)
641 ChromeViewHostMsg_GetPluginInfo_Output output; 640 ChromeViewHostMsg_GetPluginInfo_Output output;
642 render_frame->Send(new ChromeViewHostMsg_GetPluginInfo( 641 render_frame->Send(new ChromeViewHostMsg_GetPluginInfo(
643 render_frame->GetRoutingID(), url, frame->Top()->GetSecurityOrigin(), 642 render_frame->GetRoutingID(), url,
644 orig_mime_type, &output)); 643 render_frame->GetWebFrame()->Top()->GetSecurityOrigin(), orig_mime_type,
645 *plugin = CreatePlugin(render_frame, frame, params, output); 644 &output));
645 *plugin = CreatePlugin(render_frame, params, output);
646 #else // !BUILDFLAG(ENABLE_PLUGINS) 646 #else // !BUILDFLAG(ENABLE_PLUGINS)
647 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url); 647 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url);
648 *plugin = NonLoadablePluginPlaceholder::CreateNotSupportedPlugin( 648 auto* placeholder = NonLoadablePluginPlaceholder::CreateNotSupportedPlugin(
649 render_frame, frame, params)->plugin(); 649 render_frame, params);
650 *plugin = placeholder->plugin();
650 651
651 #endif // BUILDFLAG(ENABLE_PLUGINS) 652 #endif // BUILDFLAG(ENABLE_PLUGINS)
652 return true; 653 return true;
653 } 654 }
654 655
655 WebPlugin* ChromeContentRendererClient::CreatePluginReplacement( 656 WebPlugin* ChromeContentRendererClient::CreatePluginReplacement(
656 content::RenderFrame* render_frame, 657 content::RenderFrame* render_frame,
657 const base::FilePath& plugin_path) { 658 const base::FilePath& plugin_path) {
658 return NonLoadablePluginPlaceholder::CreateErrorPlugin(render_frame, 659 auto* placeholder = NonLoadablePluginPlaceholder::CreateErrorPlugin(
659 plugin_path)->plugin(); 660 render_frame, plugin_path);
661 return placeholder->plugin();
660 } 662 }
661 663
662 void ChromeContentRendererClient::DeferMediaLoad( 664 void ChromeContentRendererClient::DeferMediaLoad(
663 content::RenderFrame* render_frame, 665 content::RenderFrame* render_frame,
664 bool has_played_media_before, 666 bool has_played_media_before,
665 const base::Closure& closure) { 667 const base::Closure& closure) {
666 // Don't allow autoplay/autoload of media resources in a RenderFrame that is 668 // Don't allow autoplay/autoload of media resources in a RenderFrame that is
667 // hidden and has never played any media before. We want to allow future 669 // hidden and has never played any media before. We want to allow future
668 // loads even when hidden to allow playlist-like functionality. 670 // loads even when hidden to allow playlist-like functionality.
669 // 671 //
670 // NOTE: This is also used to defer media loading for prerender. 672 // NOTE: This is also used to defer media loading for prerender.
671 // NOTE: Switch can be used to allow autoplay, unless frame is prerendered. 673 // NOTE: Switch can be used to allow autoplay, unless frame is prerendered.
672 // 674 //
673 // TODO(dalecurtis): Include an idle check too. http://crbug.com/509135 675 // TODO(dalecurtis): Include an idle check too. http://crbug.com/509135
674 if ((render_frame->IsHidden() && !has_played_media_before && 676 if ((render_frame->IsHidden() && !has_played_media_before &&
675 !base::CommandLine::ForCurrentProcess()->HasSwitch( 677 !base::CommandLine::ForCurrentProcess()->HasSwitch(
676 switches::kIgnoreAutoplayRestrictionsForTests)) || 678 switches::kIgnoreAutoplayRestrictionsForTests)) ||
677 prerender::PrerenderHelper::IsPrerendering(render_frame)) { 679 prerender::PrerenderHelper::IsPrerendering(render_frame)) {
678 new MediaLoadDeferrer(render_frame, closure); 680 new MediaLoadDeferrer(render_frame, closure);
679 return; 681 return;
680 } 682 }
681 683
682 closure.Run(); 684 closure.Run();
683 } 685 }
684 686
685 #if BUILDFLAG(ENABLE_PLUGINS) 687 #if BUILDFLAG(ENABLE_PLUGINS)
688 // static
686 WebPlugin* ChromeContentRendererClient::CreatePlugin( 689 WebPlugin* ChromeContentRendererClient::CreatePlugin(
687 content::RenderFrame* render_frame, 690 content::RenderFrame* render_frame,
688 WebLocalFrame* frame,
689 const WebPluginParams& original_params, 691 const WebPluginParams& original_params,
690 const ChromeViewHostMsg_GetPluginInfo_Output& output) { 692 const ChromeViewHostMsg_GetPluginInfo_Output& output) {
691 const WebPluginInfo& info = output.plugin; 693 const WebPluginInfo& info = output.plugin;
692 const std::string& actual_mime_type = output.actual_mime_type; 694 const std::string& actual_mime_type = output.actual_mime_type;
693 const base::string16& group_name = output.group_name; 695 const base::string16& group_name = output.group_name;
694 const std::string& identifier = output.group_identifier; 696 const std::string& identifier = output.group_identifier;
695 ChromeViewHostMsg_GetPluginInfo_Status status = output.status; 697 ChromeViewHostMsg_GetPluginInfo_Status status = output.status;
696 GURL url(original_params.url); 698 GURL url(original_params.url);
697 std::string orig_mime_type = original_params.mime_type.Utf8(); 699 std::string orig_mime_type = original_params.mime_type.Utf8();
698 ChromePluginPlaceholder* placeholder = NULL; 700 ChromePluginPlaceholder* placeholder = NULL;
699 701
700 // If the browser plugin is to be enabled, this should be handled by the 702 // If the browser plugin is to be enabled, this should be handled by the
701 // renderer, so the code won't reach here due to the early exit in 703 // renderer, so the code won't reach here due to the early exit in
702 // OverrideCreatePlugin. 704 // OverrideCreatePlugin.
703 if (status == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound || 705 if (status == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound ||
704 orig_mime_type == content::kBrowserPluginMimeType) { 706 orig_mime_type == content::kBrowserPluginMimeType) {
705 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url); 707 PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url);
706 placeholder = ChromePluginPlaceholder::CreateLoadableMissingPlugin( 708 placeholder = ChromePluginPlaceholder::CreateLoadableMissingPlugin(
707 render_frame, frame, original_params); 709 render_frame, original_params);
708 } else { 710 } else {
709 // TODO(bauerb): This should be in content/. 711 // TODO(bauerb): This should be in content/.
710 WebPluginParams params(original_params); 712 WebPluginParams params(original_params);
711 for (size_t i = 0; i < info.mime_types.size(); ++i) { 713 for (const auto& mime_type : info.mime_types) {
712 if (info.mime_types[i].mime_type == actual_mime_type) { 714 if (mime_type.mime_type == actual_mime_type) {
713 AppendParams(info.mime_types[i].additional_param_names, 715 AppendParams(mime_type.additional_param_names,
714 info.mime_types[i].additional_param_values, 716 mime_type.additional_param_values, &params.attribute_names,
715 &params.attribute_names, &params.attribute_values); 717 &params.attribute_values);
716 break; 718 break;
717 } 719 }
718 } 720 }
719 if (params.mime_type.IsNull() && (actual_mime_type.size() > 0)) { 721 if (params.mime_type.IsNull() && (actual_mime_type.size() > 0)) {
720 // Webkit might say that mime type is null while we already know the 722 // Webkit might say that mime type is null while we already know the
721 // actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case 723 // actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case
722 // we should use what we know since WebpluginDelegateProxy does some 724 // we should use what we know since WebpluginDelegateProxy does some
723 // specific initializations based on this information. 725 // specific initializations based on this information.
724 params.mime_type = WebString::FromUTF8(actual_mime_type); 726 params.mime_type = WebString::FromUTF8(actual_mime_type);
725 } 727 }
726 728
727 ContentSettingsObserver* observer = 729 ContentSettingsObserver* observer =
728 ContentSettingsObserver::Get(render_frame); 730 ContentSettingsObserver::Get(render_frame);
729 731
730 const ContentSettingsType content_type = 732 const ContentSettingsType content_type =
731 ShouldUseJavaScriptSettingForPlugin(info) 733 ShouldUseJavaScriptSettingForPlugin(info)
732 ? CONTENT_SETTINGS_TYPE_JAVASCRIPT 734 ? CONTENT_SETTINGS_TYPE_JAVASCRIPT
733 : CONTENT_SETTINGS_TYPE_PLUGINS; 735 : CONTENT_SETTINGS_TYPE_PLUGINS;
734 736
735 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized || 737 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized ||
736 status == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked) && 738 status == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked) &&
737 observer->IsPluginTemporarilyAllowed(identifier)) { 739 observer->IsPluginTemporarilyAllowed(identifier)) {
738 status = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed; 740 status = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed;
739 } 741 }
740 742
741 auto create_blocked_plugin = [&render_frame, &frame, &params, &info, 743 auto create_blocked_plugin = [&render_frame, &params, &info, &identifier,
742 &identifier, &group_name]( 744 &group_name](int template_id,
743 int template_id, const base::string16& message) { 745 const base::string16& message) {
744 return ChromePluginPlaceholder::CreateBlockedPlugin( 746 return ChromePluginPlaceholder::CreateBlockedPlugin(
745 render_frame, frame, params, info, identifier, group_name, 747 render_frame, params, info, identifier, group_name, template_id,
746 template_id, message, PowerSaverInfo()); 748 message, PowerSaverInfo());
747 }; 749 };
750 WebLocalFrame* frame = render_frame->GetWebFrame();
748 switch (status) { 751 switch (status) {
749 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: { 752 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: {
750 NOTREACHED(); 753 NOTREACHED();
751 break; 754 break;
752 } 755 }
753 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed: 756 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed:
754 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: { 757 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: {
755 #if !defined(DISABLE_NACL) && BUILDFLAG(ENABLE_EXTENSIONS) 758 #if !defined(DISABLE_NACL) && BUILDFLAG(ENABLE_EXTENSIONS)
756 const bool is_nacl_plugin = 759 const bool is_nacl_plugin =
757 info.name == ASCIIToUTF16(nacl::kNaClPluginName); 760 info.name == ASCIIToUTF16(nacl::kNaClPluginName);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 bool power_saver_setting_on = 825 bool power_saver_setting_on =
823 status == 826 status ==
824 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent; 827 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
825 PowerSaverInfo power_saver_info = 828 PowerSaverInfo power_saver_info =
826 PowerSaverInfo::Get(render_frame, power_saver_setting_on, params, 829 PowerSaverInfo::Get(render_frame, power_saver_setting_on, params,
827 info, frame->GetDocument().Url()); 830 info, frame->GetDocument().Url());
828 if (power_saver_info.blocked_for_background_tab || is_prerendering || 831 if (power_saver_info.blocked_for_background_tab || is_prerendering ||
829 !power_saver_info.poster_attribute.empty() || 832 !power_saver_info.poster_attribute.empty() ||
830 power_saver_info.power_saver_enabled) { 833 power_saver_info.power_saver_enabled) {
831 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( 834 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin(
832 render_frame, frame, params, info, identifier, group_name, 835 render_frame, params, info, identifier, group_name,
833 power_saver_info.poster_attribute.empty() 836 power_saver_info.poster_attribute.empty()
834 ? IDR_BLOCKED_PLUGIN_HTML 837 ? IDR_BLOCKED_PLUGIN_HTML
835 : IDR_PLUGIN_POSTER_HTML, 838 : IDR_PLUGIN_POSTER_HTML,
836 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 839 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
837 power_saver_info); 840 power_saver_info);
838 placeholder->set_blocked_for_prerendering(is_prerendering); 841 placeholder->set_blocked_for_prerendering(is_prerendering);
839 842
840 // Because we can't determine the size of a plugin until it loads, 843 // Because we can't determine the size of a plugin until it loads,
841 // all plugins are treated as tiny until proven otherwise. 844 // all plugins are treated as tiny until proven otherwise.
842 placeholder->set_blocked_for_tinyness( 845 placeholder->set_blocked_for_tinyness(
843 power_saver_info.power_saver_enabled); 846 power_saver_info.power_saver_enabled);
844 847
845 placeholder->AllowLoading(); 848 placeholder->AllowLoading();
846 break; 849 break;
847 } 850 }
848 851
849 // Same-origin and whitelisted-origin plugins skip the placeholder. 852 // Same-origin and whitelisted-origin plugins skip the placeholder.
850 return render_frame->CreatePlugin(frame, info, params, nullptr); 853 return render_frame->CreatePlugin(info, params, nullptr);
851 } 854 }
852 case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled: { 855 case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled: {
853 PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type, 856 PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type,
854 url); 857 url);
855 placeholder = create_blocked_plugin( 858 placeholder = create_blocked_plugin(
856 IDR_DISABLED_PLUGIN_HTML, 859 IDR_DISABLED_PLUGIN_HTML,
857 l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED, group_name)); 860 l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED, group_name));
858 break; 861 break;
859 } 862 }
860 case ChromeViewHostMsg_GetPluginInfo_Status::kFlashHiddenPreferHtml: { 863 case ChromeViewHostMsg_GetPluginInfo_Status::kFlashHiddenPreferHtml: {
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 1555
1553 RecordYouTubeRewriteUMA(result); 1556 RecordYouTubeRewriteUMA(result);
1554 return corrected_url.ReplaceComponents(r); 1557 return corrected_url.ReplaceComponents(r);
1555 } 1558 }
1556 1559
1557 std::unique_ptr<base::TaskScheduler::InitParams> 1560 std::unique_ptr<base::TaskScheduler::InitParams>
1558 ChromeContentRendererClient::GetTaskSchedulerInitParams() { 1561 ChromeContentRendererClient::GetTaskSchedulerInitParams() {
1559 return task_scheduler_util:: 1562 return task_scheduler_util::
1560 GetRendererTaskSchedulerInitParamsFromCommandLine(); 1563 GetRendererTaskSchedulerInitParamsFromCommandLine();
1561 } 1564 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698