Commit 7f939a86 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Fix the flaky Mojo connection of ContentSettingsManager

The reason for the flaky Mojo connection of ContentSettingsManager
was that |content_settings_manager_| tried to connect to its
receiver via BrowserInterfaceBroker in ContentSettingsAgentImpl
ctor once, but BrowserInterfaceBroker could be reset before
|content_settings_manager_| was connected.
This CL ensures its connection to retry in DidCommitProvisionalLoad
if it is not connected.

Bug: 936482
Change-Id: I29db1ea13e2fa4de49f431d07ac249ed6e318d1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1897576Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#713626}
parent 173feb99
......@@ -125,9 +125,7 @@ ContentSettingsAgentImpl::ContentSettingsAgentImpl(
render_frame->GetAssociatedInterfaceRegistry()->AddInterface(
base::Bind(&ContentSettingsAgentImpl::OnContentSettingsAgentRequest,
base::Unretained(this)));
render_frame->GetBrowserInterfaceBroker()->GetInterface(
content_settings_manager_.BindNewPipeAndPassReceiver());
EnsureContentSettingsManagerConnection();
content::RenderFrame* main_frame =
render_frame->GetRenderView()->GetMainRenderFrame();
......@@ -147,6 +145,16 @@ ContentSettingsAgentImpl::ContentSettingsAgentImpl(
ContentSettingsAgentImpl::~ContentSettingsAgentImpl() {}
void ContentSettingsAgentImpl::EnsureContentSettingsManagerConnection() {
if (content_settings_manager_.is_bound() &&
content_settings_manager_.is_connected())
return;
content_settings_manager_.reset();
render_frame()->GetBrowserInterfaceBroker()->GetInterface(
content_settings_manager_.BindNewPipeAndPassReceiver());
}
#if BUILDFLAG(ENABLE_EXTENSIONS)
void ContentSettingsAgentImpl::SetExtensionDispatcher(
extensions::Dispatcher* extension_dispatcher) {
......@@ -204,6 +212,8 @@ void ContentSettingsAgentImpl::DidCommitProvisionalLoad(
if (frame->Parent())
return; // Not a top-level navigation.
EnsureContentSettingsManagerConnection();
if (!is_same_document_navigation) {
// Clear "block" flags for the new page. This needs to happen before any of
// |allowScript()|, |allowScriptFromSource()|, |allowImage()|, or
......
......@@ -165,6 +165,9 @@ class ContentSettingsAgentImpl
bool AllowStorageAccess(
chrome::mojom::ContentSettingsManager::StorageType storage_type);
// Ensures that |content_settings_manager_| is connected.
void EnsureContentSettingsManagerConnection();
mojo::Remote<chrome::mojom::ContentSettingsManager> content_settings_manager_;
#if BUILDFLAG(ENABLE_EXTENSIONS)
......
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