Commit 4aaa9f29 authored by Andy Paicu's avatar Andy Paicu Committed by Commit Bot

Added cooldown after dimssing the flash warning message

Many users find the fact that the warning message is displayed on every
startup annoying (https://support.google.com/chrome/thread/11549634?hl=en)

This CL adds a 14 day cooldown period for the warning after it is dismissed.

Bug: 918428
Change-Id: I358b1646c797d48e12c1b2718d3f8631483736d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761592Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarAnthony LaForge <laforge@chromium.org>
Commit-Queue: Andy Paicu <andypaicu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689580}
parent 06142604
......@@ -4,33 +4,64 @@
#include "chrome/browser/plugins/flash_deprecation_infobar_delegate.h"
#include <memory>
#include "base/feature_list.h"
#include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/plugins/plugin_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/infobars/core/infobar.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
#include "url/url_constants.h"
namespace {
constexpr base::TimeDelta kMessageCooldown = base::TimeDelta::FromDays(14);
bool IsFlashDeprecationWarningCooldownActive(Profile* profile) {
base::Time last_dismissal =
profile->GetPrefs()->GetTime(prefs::kPluginsDeprecationInfobarLastShown);
// More than |kMessageCooldown| days have passed.
if (base::Time::Now() - last_dismissal > kMessageCooldown) {
return false;
}
return true;
}
void ActivateFlashDeprecationWarningCooldown(Profile* profile) {
profile->GetPrefs()->SetTime(prefs::kPluginsDeprecationInfobarLastShown,
base::Time::Now());
}
} // namespace
// static
void FlashDeprecationInfoBarDelegate::Create(
InfoBarService* infobar_service,
HostContentSettingsMap* host_content_settings_map) {
void FlashDeprecationInfoBarDelegate::Create(InfoBarService* infobar_service,
Profile* profile) {
infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
std::make_unique<FlashDeprecationInfoBarDelegate>(
host_content_settings_map)));
std::make_unique<FlashDeprecationInfoBarDelegate>(profile)));
}
// static
bool FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
HostContentSettingsMap* host_content_settings_map) {
Profile* profile) {
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile);
DCHECK(host_content_settings_map);
if (!base::FeatureList::IsEnabled(features::kFlashDeprecationWarning))
......@@ -41,18 +72,25 @@ bool FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
PluginUtils::UnsafeGetRawDefaultFlashContentSetting(
host_content_settings_map, &is_managed);
// If the user can't do anything about their browser's Flash behavior,
// If the user can't do anything about their browser's Flash behavior
// there's no point to showing a Flash deprecation warning infobar.
if (is_managed)
//
// Also limit showing the infobar to at most once per |kMessageCooldown|.
// Users should be periodically reminded that they need to take action, but
// if they couldn't take action and turn off flash it's unlikely they will
// able to the next time they start a session. The message become more
// annoying than informative in that case.
if (is_managed || IsFlashDeprecationWarningCooldownActive(profile)) {
return false;
}
// Display the infobar if the Flash setting is anything other than BLOCK.
return flash_setting != CONTENT_SETTING_BLOCK;
}
FlashDeprecationInfoBarDelegate::FlashDeprecationInfoBarDelegate(
HostContentSettingsMap* host_content_settings_map)
: host_content_settings_map_(host_content_settings_map) {}
Profile* profile)
: profile_(profile) {}
infobars::InfoBarDelegate::InfoBarIdentifier
FlashDeprecationInfoBarDelegate::GetIdentifier() const {
......@@ -78,11 +116,13 @@ base::string16 FlashDeprecationInfoBarDelegate::GetButtonLabel(
}
bool FlashDeprecationInfoBarDelegate::Accept() {
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
// Can be nullptr in tests.
if (!host_content_settings_map_)
if (!host_content_settings_map)
return true;
host_content_settings_map_->SetDefaultContentSetting(
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DEFAULT);
return true;
}
......@@ -95,3 +135,7 @@ GURL FlashDeprecationInfoBarDelegate::GetLinkURL() const {
return GURL(
"https://www.blog.google/products/chrome/saying-goodbye-flash-chrome/");
}
void FlashDeprecationInfoBarDelegate::InfoBarDismissed() {
ActivateFlashDeprecationWarningCooldown(profile_);
}
......@@ -7,21 +7,18 @@
#include "components/infobars/core/confirm_infobar_delegate.h"
class HostContentSettingsMap;
class Profile;
class InfoBarService;
class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
static void Create(InfoBarService* infobar_service,
HostContentSettingsMap* host_content_settings_map);
static void Create(InfoBarService* infobar_service, Profile* profile);
// Returns true if we should display a deprecation warning for
// |host_content_settings_map|.
static bool ShouldDisplayFlashDeprecation(
HostContentSettingsMap* host_content_settings_map);
static bool ShouldDisplayFlashDeprecation(Profile* profile);
explicit FlashDeprecationInfoBarDelegate(
HostContentSettingsMap* host_content_settings_map);
explicit FlashDeprecationInfoBarDelegate(Profile* profile);
~FlashDeprecationInfoBarDelegate() override = default;
// ConfirmInfobarDelegate:
......@@ -33,9 +30,10 @@ class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate {
bool Accept() override;
base::string16 GetLinkText() const override;
GURL GetLinkURL() const override;
void InfoBarDismissed() override;
private:
HostContentSettingsMap* const host_content_settings_map_;
Profile* const profile_;
};
#endif // CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_
......@@ -5,6 +5,7 @@
#include "chrome/browser/plugins/plugin_prefs_factory.h"
#include "base/path_service.h"
#include "base/time/time.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
......@@ -61,8 +62,11 @@ void PluginPrefsFactory::RegisterProfilePrefs(
registry->RegisterListPref(prefs::kPluginsDisabledPlugins);
registry->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions);
registry->RegisterListPref(prefs::kPluginsEnabledPlugins);
registry->RegisterBooleanPref(prefs::kPluginsAlwaysOpenPdfExternally, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
prefs::kPluginsAlwaysOpenPdfExternally, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterTimePref(prefs::kPluginsDeprecationInfobarLastShown,
base::Time());
}
content::BrowserContext* PluginPrefsFactory::GetBrowserContextToUse(
......
......@@ -868,12 +868,9 @@ void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary(
#endif
#if BUILDFLAG(ENABLE_PLUGINS)
auto* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
if (FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
host_content_settings_map)) {
FlashDeprecationInfoBarDelegate::Create(infobar_service,
host_content_settings_map);
profile_)) {
FlashDeprecationInfoBarDelegate::Create(infobar_service, profile_);
}
#endif
}
......
......@@ -1077,6 +1077,11 @@ const char kPluginsMetadata[] = "plugins.metadata";
const char kPluginsResourceCacheUpdate[] = "plugins.resource_cache_update";
#endif
// Last time the flash deprecation message was dismissed. Used to ensure a
// cooldown period passes before the deprecation message is displayed again.
const char kPluginsDeprecationInfobarLastShown[] =
"plugins.deprecation_infobar_last_shown";
// Int64 containing the internal value of the time at which the default browser
// infobar was last dismissed by the user.
const char kDefaultBrowserLastDeclined[] =
......
......@@ -348,6 +348,7 @@ extern const char kRunAllFlashInAllowMode[];
extern const char kPluginsMetadata[];
extern const char kPluginsResourceCacheUpdate[];
#endif
extern const char kPluginsDeprecationInfobarLastShown[];
extern const char kDefaultBrowserLastDeclined[];
extern const char kResetCheckDefaultBrowser[];
extern const char kDefaultBrowserSettingEnabled[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment