Commit 568b4f11 authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Tidy up LoginHandler callbacks.

LoginInterstitialDelegate should take a OnceClosure, and all these
static methods (probably predating base::Callback) can be normal
methods.

This is some small cleanup to make the upcoming big change to
LoginHandler smaller.

Bug: 908926
Change-Id: Idec46fe691ac82b298ed6e90f8e5bcaac31e4a32
Reviewed-on: https://chromium-review.googlesource.com/c/1388039
Commit-Queue: David Benjamin <davidben@chromium.org>
Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626246}
parent efda77e5
...@@ -531,21 +531,19 @@ void LoginHandler::GetDialogStrings(const GURL& request_url, ...@@ -531,21 +531,19 @@ void LoginHandler::GetDialogStrings(const GURL& request_url,
} }
} }
// static
void LoginHandler::ShowLoginPrompt(const GURL& request_url, void LoginHandler::ShowLoginPrompt(const GURL& request_url,
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info) {
LoginHandler* handler) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
WebContents* parent_contents = handler->GetWebContentsForLogin(); WebContents* parent_contents = GetWebContentsForLogin();
if (!parent_contents) { if (!parent_contents) {
handler->CancelAuth(); CancelAuth();
return; return;
} }
prerender::PrerenderContents* prerender_contents = prerender::PrerenderContents* prerender_contents =
prerender::PrerenderContents::FromWebContents(parent_contents); prerender::PrerenderContents::FromWebContents(parent_contents);
if (prerender_contents) { if (prerender_contents) {
prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED); prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED);
handler->CancelAuth(); CancelAuth();
return; return;
} }
...@@ -554,7 +552,7 @@ void LoginHandler::ShowLoginPrompt(const GURL& request_url, ...@@ -554,7 +552,7 @@ void LoginHandler::ShowLoginPrompt(const GURL& request_url,
GetDialogStrings(request_url, *auth_info, &authority, &explanation); GetDialogStrings(request_url, *auth_info, &authority, &explanation);
password_manager::PasswordManager* password_manager = password_manager::PasswordManager* password_manager =
handler->GetPasswordManagerForLogin(); GetPasswordManagerForLogin();
if (!password_manager) { if (!password_manager) {
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
...@@ -565,11 +563,11 @@ void LoginHandler::ShowLoginPrompt(const GURL& request_url, ...@@ -565,11 +563,11 @@ void LoginHandler::ShowLoginPrompt(const GURL& request_url,
if (guest && if (guest &&
extensions::GetViewType(guest->owner_web_contents()) != extensions::GetViewType(guest->owner_web_contents()) !=
extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
handler->BuildViewWithoutPasswordManager(authority, explanation); BuildViewWithoutPasswordManager(authority, explanation);
return; return;
} }
#endif #endif
handler->CancelAuth(); CancelAuth();
return; return;
} }
...@@ -582,26 +580,24 @@ void LoginHandler::ShowLoginPrompt(const GURL& request_url, ...@@ -582,26 +580,24 @@ void LoginHandler::ShowLoginPrompt(const GURL& request_url,
} }
PasswordForm observed_form( PasswordForm observed_form(
LoginHandler::MakeInputForPasswordManager(request_url, *auth_info)); MakeInputForPasswordManager(request_url, *auth_info));
handler->BuildViewWithPasswordManager(authority, explanation, BuildViewWithPasswordManager(authority, explanation, password_manager,
password_manager, observed_form); observed_form);
} }
// static
void LoginHandler::LoginDialogCallback( void LoginHandler::LoginDialogCallback(
const GURL& request_url, const GURL& request_url,
const content::GlobalRequestID& request_id, const content::GlobalRequestID& request_id,
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info,
scoped_refptr<net::HttpResponseHeaders> response_headers, scoped_refptr<net::HttpResponseHeaders> response_headers,
LoginHandler* handler,
bool is_main_frame) { bool is_main_frame) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
WebContents* parent_contents = handler->GetWebContentsForLogin(); WebContents* parent_contents = GetWebContentsForLogin();
if (!parent_contents || handler->WasAuthHandled()) { if (!parent_contents || WasAuthHandled()) {
// The request may have been canceled, or it may be for a renderer not // The request may have been canceled, or it may be for a renderer not
// hosted by a tab (e.g. an extension). Cancel just in case (canceling twice // hosted by a tab (e.g. an extension). Cancel just in case (canceling twice
// is a no-op). // is a no-op).
handler->CancelAuth(); CancelAuth();
return; return;
} }
...@@ -612,9 +608,9 @@ void LoginHandler::LoginDialogCallback( ...@@ -612,9 +608,9 @@ void LoginHandler::LoginDialogCallback(
auto* api = auto* api =
extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
parent_contents->GetBrowserContext()); parent_contents->GetBrowserContext());
auto continuation = base::BindOnce(&LoginHandler::MaybeSetUpLoginPrompt, auto continuation =
request_url, base::RetainedRef(auth_info), base::BindOnce(&LoginHandler::MaybeSetUpLoginPrompt, this, request_url,
base::RetainedRef(handler), is_main_frame); base::RetainedRef(auth_info), is_main_frame);
if (api->MaybeProxyAuthRequest(auth_info, std::move(response_headers), if (api->MaybeProxyAuthRequest(auth_info, std::move(response_headers),
request_id, is_main_frame, request_id, is_main_frame,
std::move(continuation))) { std::move(continuation))) {
...@@ -622,36 +618,34 @@ void LoginHandler::LoginDialogCallback( ...@@ -622,36 +618,34 @@ void LoginHandler::LoginDialogCallback(
} }
#endif #endif
MaybeSetUpLoginPrompt(request_url, auth_info, handler, is_main_frame, MaybeSetUpLoginPrompt(request_url, auth_info, is_main_frame, base::nullopt,
base::nullopt, false /* should_cancel */); false /* should_cancel */);
} }
// static
void LoginHandler::MaybeSetUpLoginPrompt( void LoginHandler::MaybeSetUpLoginPrompt(
const GURL& request_url, const GURL& request_url,
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info,
LoginHandler* handler,
bool is_request_for_main_frame, bool is_request_for_main_frame,
const base::Optional<net::AuthCredentials>& credentials, const base::Optional<net::AuthCredentials>& credentials,
bool should_cancel) { bool should_cancel) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
WebContents* parent_contents = handler->GetWebContentsForLogin(); WebContents* parent_contents = GetWebContentsForLogin();
if (!parent_contents || handler->WasAuthHandled()) { if (!parent_contents || WasAuthHandled()) {
// The request may have been canceled, or it may be for a renderer not // The request may have been canceled, or it may be for a renderer not
// hosted by a tab (e.g. an extension). Cancel just in case (canceling twice // hosted by a tab (e.g. an extension). Cancel just in case (canceling twice
// is a no-op). // is a no-op).
handler->CancelAuth(); CancelAuth();
return; return;
} }
if (should_cancel) { if (should_cancel) {
handler->CancelAuth(); CancelAuth();
return; return;
} }
if (credentials) { if (credentials) {
handler->SetAuth(credentials->username(), credentials->password()); SetAuth(credentials->username(), credentials->password());
return; return;
} }
...@@ -693,15 +687,15 @@ void LoginHandler::MaybeSetUpLoginPrompt( ...@@ -693,15 +687,15 @@ void LoginHandler::MaybeSetUpLoginPrompt(
// Show a blank interstitial for main-frame, cross origin requests // Show a blank interstitial for main-frame, cross origin requests
// so that the correct URL is shown in the omnibox. // so that the correct URL is shown in the omnibox.
base::Closure callback = base::OnceClosure callback =
base::Bind(&LoginHandler::ShowLoginPrompt, request_url, base::BindOnce(&LoginHandler::ShowLoginPrompt, this, request_url,
base::RetainedRef(auth_info), base::RetainedRef(handler)); base::RetainedRef(auth_info));
// The interstitial delegate is owned by the interstitial that it creates. // The interstitial delegate is owned by the interstitial that it creates.
// This cancels any existing interstitial. // This cancels any existing interstitial.
handler->SetInterstitialDelegate( SetInterstitialDelegate(
(new LoginInterstitialDelegate( (new LoginInterstitialDelegate(
parent_contents, auth_info->is_proxy ? GURL() : request_url, parent_contents, auth_info->is_proxy ? GURL() : request_url,
callback)) std::move(callback)))
->GetWeakPtr()); ->GetWeakPtr());
} else { } else {
...@@ -712,7 +706,7 @@ void LoginHandler::MaybeSetUpLoginPrompt( ...@@ -712,7 +706,7 @@ void LoginHandler::MaybeSetUpLoginPrompt(
? AUTH_PROMPT_TYPE_SUBRESOURCE_CROSS_ORIGIN ? AUTH_PROMPT_TYPE_SUBRESOURCE_CROSS_ORIGIN
: AUTH_PROMPT_TYPE_SUBRESOURCE_SAME_ORIGIN); : AUTH_PROMPT_TYPE_SUBRESOURCE_SAME_ORIGIN);
} }
ShowLoginPrompt(request_url, auth_info, handler); ShowLoginPrompt(request_url, auth_info);
} }
} }
...@@ -730,8 +724,8 @@ scoped_refptr<LoginHandler> CreateLoginPrompt( ...@@ -730,8 +724,8 @@ scoped_refptr<LoginHandler> CreateLoginPrompt(
auth_info, web_contents_getter, std::move(auth_required_callback)); auth_info, web_contents_getter, std::move(auth_required_callback));
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, {BrowserThread::UI},
base::BindOnce(&LoginHandler::LoginDialogCallback, url, request_id, base::BindOnce(&LoginHandler::LoginDialogCallback, handler, url,
base::RetainedRef(auth_info), std::move(response_headers), request_id, base::RetainedRef(auth_info),
base::RetainedRef(handler), is_request_for_main_frame)); std::move(response_headers), is_request_for_main_frame));
return handler; return handler;
} }
...@@ -200,9 +200,8 @@ class LoginHandler : public content::LoginDelegate, ...@@ -200,9 +200,8 @@ class LoginHandler : public content::LoginDelegate,
base::string16* authority, base::string16* authority,
base::string16* explanation); base::string16* explanation);
static void ShowLoginPrompt(const GURL& request_url, void ShowLoginPrompt(const GURL& request_url,
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info);
LoginHandler* handler);
// This callback is run on the UI thread and creates a constrained window with // This callback is run on the UI thread and creates a constrained window with
// a LoginView to prompt the user. If the prompt is triggered because of a // a LoginView to prompt the user. If the prompt is triggered because of a
...@@ -211,12 +210,11 @@ class LoginHandler : public content::LoginDelegate, ...@@ -211,12 +210,11 @@ class LoginHandler : public content::LoginDelegate,
// created directly in this callback. In both cases, the response will be sent // created directly in this callback. In both cases, the response will be sent
// to LoginHandler, which then routes it to the net::URLRequest on the I/O // to LoginHandler, which then routes it to the net::URLRequest on the I/O
// thread. // thread.
static void LoginDialogCallback( void LoginDialogCallback(
const GURL& request_url, const GURL& request_url,
const content::GlobalRequestID& request_id, const content::GlobalRequestID& request_id,
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info,
scoped_refptr<net::HttpResponseHeaders> response_headers, scoped_refptr<net::HttpResponseHeaders> response_headers,
LoginHandler* handler,
bool is_main_frame); bool is_main_frame);
// Continuation from |LoginDialogCallback()| after any potential interception // Continuation from |LoginDialogCallback()| after any potential interception
...@@ -224,10 +222,9 @@ class LoginHandler : public content::LoginDelegate, ...@@ -224,10 +222,9 @@ class LoginHandler : public content::LoginDelegate,
// request is cancelled. Otherwise |credentials| are used if supplied. Finally // request is cancelled. Otherwise |credentials| are used if supplied. Finally
// if the request is NOT cancelled AND |credentials| is empty, then we'll // if the request is NOT cancelled AND |credentials| is empty, then we'll
// actually show a login prompt. // actually show a login prompt.
static void MaybeSetUpLoginPrompt( void MaybeSetUpLoginPrompt(
const GURL& request_url, const GURL& request_url,
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info,
LoginHandler* handler,
bool is_main_frame, bool is_main_frame,
const base::Optional<net::AuthCredentials>& credentials, const base::Optional<net::AuthCredentials>& credentials,
bool should_cancel); bool should_cancel);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/login/login_interstitial_delegate.h" #include "chrome/browser/ui/login/login_interstitial_delegate.h"
#include <utility>
const content::InterstitialPageDelegate::TypeID const content::InterstitialPageDelegate::TypeID
LoginInterstitialDelegate::kTypeForTesting = LoginInterstitialDelegate::kTypeForTesting =
&LoginInterstitialDelegate::kTypeForTesting; &LoginInterstitialDelegate::kTypeForTesting;
...@@ -11,8 +13,8 @@ const content::InterstitialPageDelegate::TypeID ...@@ -11,8 +13,8 @@ const content::InterstitialPageDelegate::TypeID
LoginInterstitialDelegate::LoginInterstitialDelegate( LoginInterstitialDelegate::LoginInterstitialDelegate(
content::WebContents* web_contents, content::WebContents* web_contents,
const GURL& request_url, const GURL& request_url,
base::Closure& callback) base::OnceClosure callback)
: callback_(callback), : callback_(std::move(callback)),
interstitial_page_(content::InterstitialPage::Create(web_contents, interstitial_page_(content::InterstitialPage::Create(web_contents,
true, true,
request_url, request_url,
...@@ -39,7 +41,7 @@ LoginInterstitialDelegate::GetWeakPtr() { ...@@ -39,7 +41,7 @@ LoginInterstitialDelegate::GetWeakPtr() {
} }
void LoginInterstitialDelegate::CommandReceived(const std::string& command) { void LoginInterstitialDelegate::CommandReceived(const std::string& command) {
callback_.Run(); std::move(callback_).Run();
} }
content::InterstitialPageDelegate::TypeID content::InterstitialPageDelegate::TypeID
......
...@@ -27,7 +27,7 @@ class LoginInterstitialDelegate : public content::InterstitialPageDelegate { ...@@ -27,7 +27,7 @@ class LoginInterstitialDelegate : public content::InterstitialPageDelegate {
LoginInterstitialDelegate(content::WebContents* web_contents, LoginInterstitialDelegate(content::WebContents* web_contents,
const GURL& request_url, const GURL& request_url,
base::Closure& callback); base::OnceClosure callback);
~LoginInterstitialDelegate() override; ~LoginInterstitialDelegate() override;
...@@ -43,7 +43,7 @@ class LoginInterstitialDelegate : public content::InterstitialPageDelegate { ...@@ -43,7 +43,7 @@ class LoginInterstitialDelegate : public content::InterstitialPageDelegate {
std::string GetHTMLContents() override; std::string GetHTMLContents() override;
private: private:
base::Closure callback_; base::OnceClosure callback_;
content::InterstitialPage* interstitial_page_; content::InterstitialPage* interstitial_page_;
base::WeakPtrFactory<LoginInterstitialDelegate> weak_ptr_factory_; base::WeakPtrFactory<LoginInterstitialDelegate> weak_ptr_factory_;
......
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