Commit dbce3023 authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

[WebView] Remove Bind on an ownerless refcounted instance.

CL https://chromium-review.googlesource.com/1144813 prevents ownerless
RefCounted receiver on base::Bind.

The class AwLoginDelegate does a PostTask in its constructor using
'this'. This violate a CHECK(...).

The CL makes the constructor private. It introduces the static method
Create(). It wraps the raw pointer in the scoped_refptr class first and
THEN call base::Bind on it.

Bug: 870479
Change-Id: Iebbd51e3136fb1a52962b8f5a0951f6b89145742
Reviewed-on: https://chromium-review.googlesource.com/1179758Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584092}
parent 3eb3b6ab
......@@ -714,9 +714,9 @@ AwContentBrowserClient::CreateLoginDelegate(
scoped_refptr<net::HttpResponseHeaders> response_headers,
bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) {
return base::MakeRefCounted<AwLoginDelegate>(
auth_info, web_contents_getter, first_auth_attempt,
std::move(auth_required_callback));
return AwLoginDelegate::Create(auth_info, web_contents_getter,
first_auth_attempt,
std::move(auth_required_callback));
}
bool AwContentBrowserClient::HandleExternalProtocol(
......
......@@ -20,19 +20,27 @@ using content::WebContents;
namespace android_webview {
AwLoginDelegate::AwLoginDelegate(
// static
scoped_refptr<AwLoginDelegate> AwLoginDelegate::Create(
net::AuthChallengeInfo* auth_info,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback)
: auth_info_(auth_info),
auth_required_callback_(std::move(auth_required_callback)) {
LoginAuthRequiredCallback auth_required_callback) {
scoped_refptr<AwLoginDelegate> instance(
new AwLoginDelegate(auth_info, std::move(auth_required_callback)));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(&AwLoginDelegate::HandleHttpAuthRequestOnUIThread, this,
first_auth_attempt, web_contents_getter));
base::BindOnce(&AwLoginDelegate::HandleHttpAuthRequestOnUIThread,
instance, first_auth_attempt, web_contents_getter));
return instance;
}
AwLoginDelegate::AwLoginDelegate(
net::AuthChallengeInfo* auth_info,
LoginAuthRequiredCallback auth_required_callback)
: auth_info_(auth_info),
auth_required_callback_(std::move(auth_required_callback)) {}
AwLoginDelegate::~AwLoginDelegate() {
// The Auth handler holds a ref count back on |this| object, so it should be
// impossible to reach here while this object still owns an auth handler.
......
......@@ -24,7 +24,7 @@ namespace android_webview {
class AwLoginDelegate : public content::LoginDelegate {
public:
AwLoginDelegate(
static scoped_refptr<AwLoginDelegate> Create(
net::AuthChallengeInfo* auth_info,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
bool first_auth_attempt,
......@@ -38,6 +38,8 @@ class AwLoginDelegate : public content::LoginDelegate {
void OnRequestCancelled() override;
private:
AwLoginDelegate(net::AuthChallengeInfo* auth_info,
LoginAuthRequiredCallback auth_required_callback);
~AwLoginDelegate() override;
void HandleHttpAuthRequestOnUIThread(
bool first_auth_attempt,
......
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