Commit 3579cc52 authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] WebContent delegate handling.

Before this patch, we cleared the delegate for web_content
unconditionally. That means we would remove an already existing delegate
from web_content.

This patch introduces a bool in the controller to track whether the delegate
should be cleared in the destructor.

After this patch, we will no longer stomp on other components setting
a delegate in web_contents.

R=gogerald@chromium.org

Bug: 806868
Change-Id: I92ce1ef2dcf4a48f6709bddee0f76871a58c2df4
Reviewed-on: https://chromium-review.googlesource.com/c/1263118Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596978}
parent d6b169ed
......@@ -89,6 +89,7 @@ Controller::Controller(
allow_autostart_(true),
periodic_script_check_scheduled_(false),
periodic_script_check_count_(false),
clear_web_contents_delegate_(false),
weak_ptr_factory_(this) {
DCHECK(parameters_);
......@@ -98,6 +99,7 @@ Controller::Controller(
// of using the controller as a web_contents delegate. It may interfere with
// an already existing delegate.
if (web_contents->GetDelegate() == nullptr) {
clear_web_contents_delegate_ = true;
web_contents->SetDelegate(this);
}
......@@ -109,7 +111,9 @@ Controller::Controller(
}
Controller::~Controller() {
web_contents()->SetDelegate(nullptr);
if (clear_web_contents_delegate_) {
web_contents()->SetDelegate(nullptr);
}
}
void Controller::GetOrCheckScripts(const GURL& url) {
......
......@@ -114,6 +114,10 @@ class Controller : public ScriptExecutorDelegate,
// Number of remaining periodic checks.
int periodic_script_check_count_;
// Whether to clear the web_contents delegate when the controller is
// destroyed.
bool clear_web_contents_delegate_;
base::WeakPtrFactory<Controller> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(Controller);
......
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