Fix use of RecentlyAudible in extensions_tab_util.
Extensions can interact with WebContents that aren't housed in a
tabstrip. In this case there will be no attached RecentlyAudible
helper. Use WebContents::IsCurrentlyAudible instead.
BUG=849165
Change-Id: I2bf30a38f601e292d84e5f0f4864ad47652c5381
Reviewed-on: https://chromium-review.googlesource.com/1085488
Commit-Queue: Chris Hamilton <[email protected]>
Reviewed-by: Devlin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#564159}
diff --git a/chrome/browser/extensions/extension_tab_util.cc b/chrome/browser/extensions/extension_tab_util.cc
index efdd65f..5abb7a6 100644
--- a/chrome/browser/extensions/extension_tab_util.cc
+++ b/chrome/browser/extensions/extension_tab_util.cc
@@ -354,8 +354,17 @@
tab_object->highlighted = tab_strip && tab_strip->IsTabSelected(tab_index);
tab_object->pinned = tab_strip && tab_strip->IsTabPinned(tab_index);
auto* audible_helper = RecentlyAudibleHelper::FromWebContents(contents);
- tab_object->audible =
- std::make_unique<bool>(audible_helper->WasRecentlyAudible());
+ bool audible = false;
+ if (audible_helper) {
+ // WebContents in a tab strip have RecentlyAudible helpers. They endow the
+ // tab with a notion of audibility that has a timeout for quiet periods. Use
+ // that if available.
+ audible = audible_helper->WasRecentlyAudible();
+ } else {
+ // Otherwise use the instantaneous notion of audibility.
+ audible = contents->IsCurrentlyAudible();
+ }
+ tab_object->audible = std::make_unique<bool>(audible);
auto* tab_lifeycle_unit_external =
resource_coordinator::TabLifecycleUnitExternal::FromWebContents(contents);
tab_object->discarded =