Commit 840faeed authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Audio Focus] Fix web app DCHECK

If we clone the web contents we do not set the audio
focus id map and therefore we hit a DCHECK.

BUG=959308

Change-Id: Ib2395c56af4b51b6e9b6fbe5fb0e64a51f0ff296
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1594256Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657283}
parent 0193a35e
......@@ -28,8 +28,7 @@ WebAppTabHelperBase::WebAppTabHelperBase(content::WebContents* web_contents)
WebAppTabHelperBase::~WebAppTabHelperBase() = default;
void WebAppTabHelperBase::Init(WebAppAudioFocusIdMap* audio_focus_id_map) {
DCHECK(!audio_focus_id_map_ && audio_focus_id_map);
audio_focus_id_map_ = audio_focus_id_map;
SetAudioFocusIdMap(audio_focus_id_map);
// Sync app_id with the initial url from WebContents (used in Tab Restore etc)
const GURL init_url = web_contents()->GetSiteInstance()->GetSiteURL();
......@@ -66,10 +65,18 @@ void WebAppTabHelperBase::DidCloneToNewWebContents(
// When the WebContents that this is attached to is cloned, give the new clone
// a WebAppTabHelperBase.
WebAppTabHelperBase* new_tab_helper = CloneForWebContents(new_web_contents);
// Clone common state:
new_tab_helper->SetAudioFocusIdMap(audio_focus_id_map_);
new_tab_helper->SetAppId(app_id());
}
void WebAppTabHelperBase::SetAudioFocusIdMap(
WebAppAudioFocusIdMap* audio_focus_id_map) {
DCHECK(!audio_focus_id_map_ && audio_focus_id_map);
audio_focus_id_map_ = audio_focus_id_map;
}
void WebAppTabHelperBase::OnWebAppInstalled(const AppId& installed_app_id) {
// Check if current web_contents url is in scope for the newly installed app.
const web_app::AppId app_id = FindAppIdInScopeOfUrl(web_contents()->GetURL());
......
......@@ -78,6 +78,8 @@ class WebAppTabHelperBase
private:
friend class WebAppAudioFocusBrowserTest;
void SetAudioFocusIdMap(WebAppAudioFocusIdMap* audio_focus_id_map);
// AppRegistrarObserver:
void OnWebAppInstalled(const AppId& installed_app_id) override;
void OnWebAppUninstalled(const AppId& uninstalled_app_id) override;
......
......@@ -179,6 +179,15 @@ IN_PROC_BROWSER_TEST_F(WebAppAudioFocusBrowserTest, AppHasDifferentAudioFocus) {
EXPECT_EQ(group_id, GetAudioFocusGroupId(new_contents));
}
// Clone the web contents and make sure it has a different group id since it
// is not in an app window.
{
std::unique_ptr<content::WebContents> new_contents = web_contents->Clone();
EXPECT_TRUE(content::WaitForLoadStop(new_contents.get()));
EXPECT_EQ(base::UnguessableToken::Null(),
GetAudioFocusGroupId(new_contents.get()));
}
// Navigate away and check that the group id is still the same because we are
// part of the same window.
NavigateInRenderer(web_contents, GURL("https://www.example.com"));
......
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