Commit 6e38836f authored by Ravjit Singh Uppal's avatar Ravjit Singh Uppal Committed by Commit Bot

Revert "Added cooldown after dimssing the flash warning message"

This reverts commit 4aaa9f29.

As Flash's deprecation is near, we are resuming per session prompting about the deprecation.

Bug: 995969
Change-Id: I76632c2ace65d95fafaaea9224f02586f53c6841
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2390656
Commit-Queue: Ravjit Singh Uppal <ravjit@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805443}
parent 60018458
......@@ -4,21 +4,15 @@
#include "chrome/browser/plugins/flash_deprecation_infobar_delegate.h"
#include <memory>
#include "base/feature_list.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 "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -26,48 +20,39 @@
#include "url/url_constants.h"
// static
void FlashDeprecationInfoBarDelegate::Create(InfoBarService* infobar_service,
Profile* profile) {
void FlashDeprecationInfoBarDelegate::Create(
InfoBarService* infobar_service,
HostContentSettingsMap* host_content_settings_map) {
infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
std::make_unique<FlashDeprecationInfoBarDelegate>(profile)));
std::make_unique<FlashDeprecationInfoBarDelegate>(
host_content_settings_map)));
}
// static
bool FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
Profile* profile) {
HostContentSettingsMap* host_content_settings_map) {
DCHECK(host_content_settings_map);
if (!base::FeatureList::IsEnabled(features::kFlashDeprecationWarning))
return false;
// Generally, display the infobar if the Flash setting is anything other than
// BLOCK.
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile);
DCHECK(host_content_settings_map);
bool is_managed = false;
ContentSetting flash_setting =
PluginUtils::UnsafeGetRawDefaultFlashContentSetting(
host_content_settings_map, &is_managed);
if (flash_setting == CONTENT_SETTING_BLOCK)
return false;
// However, 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 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)
return false;
// Also limit how frequently the infobar is shown. 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 becomes more annoying than
// informative in that case.
const base::Time last_dismissal =
profile->GetPrefs()->GetTime(prefs::kPluginsDeprecationInfobarLastShown);
return (base::Time::Now() - last_dismissal) > base::TimeDelta::FromDays(3);
// Display the infobar if the Flash setting is anything other than BLOCK.
return flash_setting != CONTENT_SETTING_BLOCK;
}
FlashDeprecationInfoBarDelegate::FlashDeprecationInfoBarDelegate(
Profile* profile)
: profile_(profile) {}
HostContentSettingsMap* host_content_settings_map)
: host_content_settings_map_(host_content_settings_map) {}
infobars::InfoBarDelegate::InfoBarIdentifier
FlashDeprecationInfoBarDelegate::GetIdentifier() const {
......@@ -87,20 +72,6 @@ GURL FlashDeprecationInfoBarDelegate::GetLinkURL() const {
"https://www.blog.google/products/chrome/saying-goodbye-flash-chrome/");
}
bool FlashDeprecationInfoBarDelegate::ShouldExpire(
const NavigationDetails& details) const {
// This duration is the same as the "default browser" banner's duration.
const bool minimum_duration_elapsed =
(base::Time::Now() - display_start_) > base::TimeDelta::FromSeconds(8);
return minimum_duration_elapsed &&
ConfirmInfoBarDelegate::ShouldExpire(details);
}
void FlashDeprecationInfoBarDelegate::InfoBarDismissed() {
profile_->GetPrefs()->SetTime(prefs::kPluginsDeprecationInfobarLastShown,
base::Time::Now());
}
base::string16 FlashDeprecationInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringUTF16(IDS_PLUGIN_FLASH_DEPRECATION_PROMPT);
}
......@@ -115,12 +86,11 @@ base::string16 FlashDeprecationInfoBarDelegate::GetButtonLabel(
}
bool FlashDeprecationInfoBarDelegate::Accept() {
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
// Can be null in tests.
if (host_content_settings_map) {
host_content_settings_map->SetDefaultContentSetting(
ContentSettingsType::PLUGINS, CONTENT_SETTING_DEFAULT);
}
// Can be nullptr in tests.
if (!host_content_settings_map_)
return true;
host_content_settings_map_->SetDefaultContentSetting(
ContentSettingsType::PLUGINS, CONTENT_SETTING_DEFAULT);
return true;
}
......@@ -8,39 +8,35 @@
#include "base/time/time.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
class Profile;
class HostContentSettingsMap;
class InfoBarService;
class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
static void Create(InfoBarService* infobar_service, Profile* profile);
static void Create(InfoBarService* infobar_service,
HostContentSettingsMap* host_content_settings_map);
// Returns true if we should display a deprecation warning for
// |host_content_settings_map|.
static bool ShouldDisplayFlashDeprecation(Profile* profile);
static bool ShouldDisplayFlashDeprecation(
HostContentSettingsMap* host_content_settings_map);
explicit FlashDeprecationInfoBarDelegate(Profile* profile);
explicit FlashDeprecationInfoBarDelegate(
HostContentSettingsMap* host_content_settings_map);
~FlashDeprecationInfoBarDelegate() override = default;
// ConfirmInfobarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
const gfx::VectorIcon& GetVectorIcon() const override;
base::string16 GetLinkText() const override;
GURL GetLinkURL() const override;
bool ShouldExpire(const NavigationDetails& details) const override;
void InfoBarDismissed() override;
base::string16 GetMessageText() const override;
int GetButtons() const override;
base::string16 GetButtonLabel(InfoBarButton button) const override;
bool Accept() override;
private:
// The profile associated with this infobar.
Profile* const profile_;
// The time at which the banner has started to be displayed. Used to determine
// if the banner should expire on navigation, based on how long it has been
// visible.
base::Time display_start_ = base::Time::Now();
HostContentSettingsMap* const host_content_settings_map_;
};
#endif // CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_
......@@ -5,7 +5,6 @@
#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"
......@@ -65,8 +64,6 @@ void PluginPrefsFactory::RegisterProfilePrefs(
registry->RegisterBooleanPref(
prefs::kPluginsAlwaysOpenPdfExternally, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterTimePref(prefs::kPluginsDeprecationInfobarLastShown,
base::Time());
}
content::BrowserContext* PluginPrefsFactory::GetBrowserContextToUse(
......
......@@ -472,6 +472,10 @@ const char kObservedSessionTime[] = "profile.observed_session_time";
// Deprecated 9/2020
const char kBlockThirdPartyCookies[] = "profile.block_third_party_cookies";
// Deprecated 9/2020
const char kPluginsDeprecationInfobarLastShown[] =
"plugins.deprecation_infobar_last_shown";
// Register local state used only for migration (clearing or moving to a new
// key).
void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
......@@ -530,6 +534,8 @@ void RegisterProfilePrefsForMigration(
registry->RegisterDictionaryPref(kObservedSessionTime);
registry->RegisterBooleanPref(kBlockThirdPartyCookies, false);
registry->RegisterTimePref(kPluginsDeprecationInfobarLastShown, base::Time());
}
} // namespace
......@@ -1108,4 +1114,7 @@ void MigrateObsoleteProfilePrefs(Profile* profile) {
// Added 9/2020
profile_prefs->ClearPref(kBlockThirdPartyCookies);
// Added 9/2020
profile_prefs->ClearPref(kPluginsDeprecationInfobarLastShown);
}
......@@ -928,9 +928,12 @@ void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary(
#endif
#if BUILDFLAG(ENABLE_PLUGINS)
auto* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
if (FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
profile_)) {
FlashDeprecationInfoBarDelegate::Create(infobar_service, profile_);
host_content_settings_map)) {
FlashDeprecationInfoBarDelegate::Create(infobar_service,
host_content_settings_map);
}
#endif
}
......
......@@ -1151,11 +1151,6 @@ 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[] =
......
......@@ -377,7 +377,6 @@ 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