Show sound content setting in Page Info when tab is audible

Bug: 774256
Change-Id: I38d9fe9fcbfeb016553be61ebc69d9d4eb6d294c
Reviewed-on: https://chromium-review.googlesource.com/717256
Reviewed-by: Lucas Garron <[email protected]>
Commit-Queue: Tommy Steimel <[email protected]>
Cr-Commit-Position: refs/heads/master@{#508864}
diff --git a/chrome/browser/ui/page_info/page_info.cc b/chrome/browser/ui/page_info/page_info.cc
index 237d3a07..22ba481 100644
--- a/chrome/browser/ui/page_info/page_info.cc
+++ b/chrome/browser/ui/page_info/page_info.cc
@@ -136,7 +136,8 @@
 // applies to permissions listed in |kPermissionType|.
 bool ShouldShowPermission(const PageInfoUI::PermissionInfo& info,
                           const GURL& site_url,
-                          HostContentSettingsMap* content_settings) {
+                          HostContentSettingsMap* content_settings,
+                          content::WebContents* web_contents) {
   // Note |CONTENT_SETTINGS_TYPE_ADS| will show up regardless of its default
   // value when it has been activated on the current origin.
   if (info.type == CONTENT_SETTINGS_TYPE_ADS) {
@@ -152,6 +153,16 @@
                nullptr) != nullptr;
   }
 
+  if (info.type == CONTENT_SETTINGS_TYPE_SOUND) {
+    if (!base::FeatureList::IsEnabled(features::kSoundContentSetting))
+      return false;
+
+    // The sound content setting should show always show up when the tab is
+    // playing audio or has recently played audio.
+    if (web_contents && web_contents->WasRecentlyAudible())
+      return true;
+  }
+
 #if defined(OS_ANDROID)
   // Special geolocation DSE settings apply only on Android, so make sure it
   // gets checked there regardless of default setting on Desktop.
@@ -173,9 +184,6 @@
     return false;
 #endif
 
-  if (info.type == CONTENT_SETTINGS_TYPE_SOUND)
-    return base::FeatureList::IsEnabled(features::kSoundContentSetting);
-
   return true;
 }
 
@@ -821,8 +829,10 @@
         permission_info.setting = permission_result.content_setting;
     }
 
-    if (ShouldShowPermission(permission_info, site_url_, content_settings_))
+    if (ShouldShowPermission(permission_info, site_url_, content_settings_,
+                             web_contents())) {
       permission_info_list.push_back(permission_info);
+    }
   }
 
   for (const ChooserUIInfo& ui_info : kChooserUIInfo) {