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

Unified Diff: chrome/browser/plugins/chrome_plugin_service_filter.cc

Issue 2285553002: [HBD] Gate the advertising of Flash on Site Engagement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/plugins/chrome_plugin_service_filter.cc
diff --git a/chrome/browser/plugins/chrome_plugin_service_filter.cc b/chrome/browser/plugins/chrome_plugin_service_filter.cc
index 1c1f506d3ac1bd7d7e5a1bfbc36661e8a2a02d2d..f5a384170dd70cda9731b2d662a5a854f2d2842c 100644
--- a/chrome/browser/plugins/chrome_plugin_service_filter.cc
+++ b/chrome/browser/plugins/chrome_plugin_service_filter.cc
@@ -7,37 +7,28 @@
#include <utility>
#include "base/bind.h"
-#include "base/logging.h"
-#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
-#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
-#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/plugins/plugin_filter_utils.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "chrome/browser/plugins/plugin_metadata.h"
-#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/plugins/plugins_field_trial.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/render_messages.h"
#include "components/content_settings/content/common/content_settings_messages.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
-#include "components/infobars/core/confirm_infobar_delegate.h"
-#include "components/infobars/core/infobar.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_context.h"
-#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_constants.h"
-#include "ui/base/window_open_disposition.h"
+#include "url/gurl.h"
-using base::UserMetricsAction;
using content::BrowserThread;
using content::PluginService;
@@ -68,6 +59,8 @@ void AuthorizeRenderer(content::RenderFrameHost* render_frame_host) {
} // namespace
+// ChromePluginServiceFilter inner struct definitions.
+
struct ChromePluginServiceFilter::ContextInfo {
ContextInfo(
const scoped_refptr<PluginPrefs>& plugin_prefs,
@@ -99,6 +92,20 @@ ChromePluginServiceFilter::ContextInfo::~ContextInfo() {
host_content_settings_map->RemoveObserver(&observer);
}
+ChromePluginServiceFilter::OverriddenPlugin::OverriddenPlugin()
+ : render_frame_id(MSG_ROUTING_NONE) {}
+
+ChromePluginServiceFilter::OverriddenPlugin::~OverriddenPlugin() {}
+
+ChromePluginServiceFilter::ProcessDetails::ProcessDetails() {}
+
+ChromePluginServiceFilter::ProcessDetails::ProcessDetails(
+ const ProcessDetails& other) = default;
+
+ChromePluginServiceFilter::ProcessDetails::~ProcessDetails() {}
+
+// ChromePluginServiceFilter definitions.
+
// static
ChromePluginServiceFilter* ChromePluginServiceFilter::GetInstance() {
return base::Singleton<ChromePluginServiceFilter>::get();
@@ -110,7 +117,8 @@ void ChromePluginServiceFilter::RegisterResourceContext(Profile* profile,
base::AutoLock lock(lock_);
resource_context_map_[context] = base::MakeUnique<ContextInfo>(
PluginPrefs::GetForProfile(profile),
- HostContentSettingsMapFactory::GetForProfile(profile), profile);
+ HostContentSettingsMapFactory::GetForProfile(profile),
+ profile);
}
void ChromePluginServiceFilter::UnregisterResourceContext(
@@ -133,6 +141,26 @@ void ChromePluginServiceFilter::OverridePluginForFrame(
details->overridden_plugins.push_back(overridden_plugin);
}
+void ChromePluginServiceFilter::AuthorizePlugin(
+ int render_process_id,
+ const base::FilePath& plugin_path) {
+ base::AutoLock auto_lock(lock_);
+ ProcessDetails* details = GetOrRegisterProcess(render_process_id);
+ details->authorized_plugins.insert(plugin_path);
+}
+
+void ChromePluginServiceFilter::AuthorizeAllPlugins(
+ content::WebContents* web_contents,
+ bool load_blocked,
+ const std::string& identifier) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ web_contents->ForEachFrame(base::Bind(&AuthorizeRenderer));
+ if (load_blocked) {
+ web_contents->SendToAllFrames(new ChromeViewMsg_LoadBlockedPlugins(
+ MSG_ROUTING_NONE, identifier));
+ }
+}
+
bool ChromePluginServiceFilter::IsPluginAvailable(
int render_process_id,
int render_frame_id,
@@ -164,12 +192,17 @@ bool ChromePluginServiceFilter::IsPluginAvailable(
if (context_info_it == resource_context_map_.end())
return false;
- if (!context_info_it->second->plugin_prefs.get()->IsPluginEnabled(*plugin))
+ const ContextInfo* context_info = context_info_it->second.get();
+ if (!context_info->plugin_prefs.get()->IsPluginEnabled(*plugin))
return false;
- // Check whether PreferHtmlOverPlugins feature is enabled.
+ // If PreferHtmlOverPlugins is enabled and the plugin is Flash, we do
+ // additional checks.
if (plugin->name == base::ASCIIToUTF16(content::kFlashPluginName) &&
base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) {
+
+ // Check the content setting first, and always respect the ALLOW or BLOCK
+ // state.
ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
std::unique_ptr<PluginMetadata> plugin_metadata =
PluginFinder::GetInstance()->GetPluginMetadata(*plugin);
@@ -179,13 +212,22 @@ bool ChromePluginServiceFilter::IsPluginAvailable(
// Flash embed hosted on the same origin as the main frame origin is allowed
// to run.
GetPluginContentSetting(
- context_info_it->second->host_content_settings_map.get(), *plugin,
+ context_info->host_content_settings_map.get(), *plugin,
policy_url, url, plugin_metadata->identifier(), &plugin_setting,
nullptr, nullptr);
plugin_setting = PluginsFieldTrial::EffectiveContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, plugin_setting);
- if (plugin_setting == CONTENT_SETTING_BLOCK ||
- plugin_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) {
+ if (plugin_setting == CONTENT_SETTING_ALLOW)
+ return true;
+ else if (plugin_setting == CONTENT_SETTING_BLOCK)
+ return false;
+
+ // The content setting is neither ALLOW or BLOCK. Check whether the site
+ // meets the site engagement cutoff for making Flash available without a
+ // prompt. This is impossible if |policy_url| is empty.
+ if (policy_url.is_empty() ||
Bernhard Bauer 2016/09/15 09:05:15 When would this be the case again?
dominickn 2016/09/15 12:16:00 Changed to DCHECK.
+ !PluginsFieldTrial::HasSufficientEngagementForFlash(
+ context_info->host_content_settings_map.get(), policy_url)) {
return false;
}
}
@@ -209,26 +251,6 @@ bool ChromePluginServiceFilter::CanLoadPlugin(int render_process_id,
ContainsKey(details->authorized_plugins, base::FilePath()));
}
-void ChromePluginServiceFilter::AuthorizePlugin(
- int render_process_id,
- const base::FilePath& plugin_path) {
- base::AutoLock auto_lock(lock_);
- ProcessDetails* details = GetOrRegisterProcess(render_process_id);
- details->authorized_plugins.insert(plugin_path);
-}
-
-void ChromePluginServiceFilter::AuthorizeAllPlugins(
- content::WebContents* web_contents,
- bool load_blocked,
- const std::string& identifier) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- web_contents->ForEachFrame(base::Bind(&AuthorizeRenderer));
- if (load_blocked) {
- web_contents->SendToAllFrames(new ChromeViewMsg_LoadBlockedPlugins(
- MSG_ROUTING_NONE, identifier));
- }
-}
-
ChromePluginServiceFilter::ChromePluginServiceFilter() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
@@ -237,8 +259,7 @@ ChromePluginServiceFilter::ChromePluginServiceFilter() {
content::NotificationService::AllSources());
}
-ChromePluginServiceFilter::~ChromePluginServiceFilter() {
-}
+ChromePluginServiceFilter::~ChromePluginServiceFilter() {}
void ChromePluginServiceFilter::Observe(
int type,
@@ -284,19 +305,3 @@ ChromePluginServiceFilter::GetProcess(
return NULL;
return &it->second;
}
-
-ChromePluginServiceFilter::OverriddenPlugin::OverriddenPlugin()
- : render_frame_id(MSG_ROUTING_NONE) {
-}
-
-ChromePluginServiceFilter::OverriddenPlugin::~OverriddenPlugin() {
-}
-
-ChromePluginServiceFilter::ProcessDetails::ProcessDetails() {
-}
-
-ChromePluginServiceFilter::ProcessDetails::ProcessDetails(
- const ProcessDetails& other) = default;
-
-ChromePluginServiceFilter::ProcessDetails::~ProcessDetails() {
-}

Powered by Google App Engine
This is Rietveld 408576698