Flash: Hook up deprecation warning infobar to browser startup

This CL hooks up the deprecation warning infobar into browser startup.
Note this is behind a feature flag.

It only triggers if the user has Flash enabled and the setting is not
managed.

Bug: 918428
Change-Id: I8a626604e89c55487592854eda3f4de45cc877c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1536604
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645855}
diff --git a/chrome/browser/plugins/flash_deprecation_infobar_delegate.cc b/chrome/browser/plugins/flash_deprecation_infobar_delegate.cc
index 094e5b4f..966b410 100644
--- a/chrome/browser/plugins/flash_deprecation_infobar_delegate.cc
+++ b/chrome/browser/plugins/flash_deprecation_infobar_delegate.cc
@@ -4,11 +4,17 @@
 
 #include "chrome/browser/plugins/flash_deprecation_infobar_delegate.h"
 
+#include "base/feature_list.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/common/chrome_features.h"
 #include "chrome/grit/generated_resources.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
 #include "components/infobars/core/infobar.h"
 #include "ui/base/l10n/l10n_util.h"
+#include "url/url_constants.h"
 
 // static
 void FlashDeprecationInfoBarDelegate::Create(InfoBarService* infobar_service) {
@@ -16,23 +22,40 @@
       std::make_unique<FlashDeprecationInfoBarDelegate>()));
 }
 
+// static
+bool FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
+    Profile* profile) {
+  DCHECK(profile);
+
+  if (!base::FeatureList::IsEnabled(features::kFlashDeprecationWarning))
+    return false;
+
+  bool is_managed = false;
+  auto* settings_map = HostContentSettingsMapFactory::GetForProfile(profile);
+  ContentSetting flash_setting =
+      PluginUtils::UnsafeGetRawDefaultFlashContentSetting(settings_map,
+                                                          &is_managed);
+
+  // 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;
+
+  // Display the infobar if the Flash setting is anything other than BLOCK.
+  return flash_setting != CONTENT_SETTING_BLOCK;
+}
+
 infobars::InfoBarDelegate::InfoBarIdentifier
 FlashDeprecationInfoBarDelegate::GetIdentifier() const {
   return FLASH_DEPRECATION_INFOBAR_DELEGATE;
 }
 
 const gfx::VectorIcon& FlashDeprecationInfoBarDelegate::GetVectorIcon() const {
-  // TODO(tommycli): Replace this placeholder vector icon.
-  return kExtensionCrashedIcon;
+  return kExtensionIcon;
 }
 
 base::string16 FlashDeprecationInfoBarDelegate::GetMessageText() const {
-  // TODO(tommycli): Replace empty string with real IDS once we use reference
-  // this infobar from production code. Currently, this IDS is stripped by
-  // enable_resource_whitelist_generation = true, and this crashes the
-  // Windows infobar browsertest (which tries to fetch the stripped IDS).
-  // return l10n_util::GetStringUTF16(IDS_PLUGIN_FLASH_DEPRECATION_PROMPT);
-  return base::string16();
+  return l10n_util::GetStringUTF16(IDS_PLUGIN_FLASH_DEPRECATION_PROMPT);
 }
 
 int FlashDeprecationInfoBarDelegate::GetButtons() const {
diff --git a/chrome/browser/plugins/flash_deprecation_infobar_delegate.h b/chrome/browser/plugins/flash_deprecation_infobar_delegate.h
index 699958c..df8a664 100644
--- a/chrome/browser/plugins/flash_deprecation_infobar_delegate.h
+++ b/chrome/browser/plugins/flash_deprecation_infobar_delegate.h
@@ -8,11 +8,15 @@
 #include "components/infobars/core/confirm_infobar_delegate.h"
 
 class InfoBarService;
+class Profile;
 
 class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate {
  public:
   static void Create(InfoBarService* infobar_service);
 
+  // Returns true if we should display a deprecation warning for |profile|.
+  static bool ShouldDisplayFlashDeprecation(Profile* profile);
+
   FlashDeprecationInfoBarDelegate() = default;
   ~FlashDeprecationInfoBarDelegate() override = default;
 
diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
index ae97262..8dbfd65 100644
--- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
@@ -81,6 +81,10 @@
 #include "chrome/credential_provider/common/gcp_strings.h"
 #endif  // defined(OS_WIN)
 
+#if BUILDFLAG(ENABLE_PLUGINS)
+#include "chrome/browser/plugins/flash_deprecation_infobar_delegate.h"
+#endif
+
 #if BUILDFLAG(ENABLE_RLZ)
 #include "components/google/core/common/google_util.h"
 #include "components/rlz/rlz_tracker.h"  // nogncheck
@@ -834,6 +838,13 @@
       }
     }
 #endif
+
+#if BUILDFLAG(ENABLE_PLUGINS)
+    if (FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
+            profile_)) {
+      FlashDeprecationInfoBarDelegate::Create(infobar_service);
+    }
+#endif
   }
 }