From b8a33c8bb6bc62342c04d9908ce09bd98d0b866c Mon Sep 17 00:00:00 2001 From: Surya Kumar Date: Mon, 6 Dec 2021 18:21:05 +0530 Subject: [PATCH] [M94 Migration] Bringup Authentication popup Migrated Authentication popup code from M85 Cherry-picked from: https://review.tizen.org/gerrit/267205 Test site: https://the-internet.herokuapp.com/basic_auth Change-Id: I9d130b6962f44905fd5c0acf731c830846059c59 Signed-off-by: Surya Kumar --- .../browser/login_delegate_efl.cc | 90 +++++++------------ .../browser/login_delegate_efl.h | 40 +++++---- .../content_browser_client_efl.cc | 17 ++++ .../content_browser_client_efl.h | 10 +++ tizen_src/ewk/efl_integration/eweb_context.cc | 6 ++ tizen_src/ewk/efl_integration/eweb_context.h | 5 ++ .../private/ewk_auth_challenge_private.h | 2 +- .../private/ewk_context_private.cc | 5 ++ .../private/ewk_context_private.h | 1 + .../ewk/efl_integration/public/ewk_context.cc | 10 ++- .../web_contents_delegate_efl.cc | 6 +- .../web_contents_delegate_efl.h | 4 +- 12 files changed, 113 insertions(+), 83 deletions(-) diff --git a/tizen_src/ewk/efl_integration/browser/login_delegate_efl.cc b/tizen_src/ewk/efl_integration/browser/login_delegate_efl.cc index cd392b96714d..708a1de39cf4 100644 --- a/tizen_src/ewk/efl_integration/browser/login_delegate_efl.cc +++ b/tizen_src/ewk/efl_integration/browser/login_delegate_efl.cc @@ -2,95 +2,69 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "browser/login_delegate_efl.h" - -#include +#include "login_delegate_efl.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" #include "net/base/auth.h" -#include "net/url_request/url_request.h" - +#include "private/ewk_context_private.h" #include "web_contents_delegate_efl.h" -#include "common/web_contents_utils.h" using content::BrowserThread; -using content::RenderViewHost; -using content::RenderFrameHost; using content::WebContents; -LoginDelegateEfl::LoginDelegateEfl(net::AuthChallengeInfo* auth_info, net::URLRequest* request) +/* LCOV_EXCL_START */ +LoginDelegateEfl::LoginDelegateEfl( + const net::AuthChallengeInfo* auth_info, + const GURL& url, + content::WebContents* web_contents, + LoginAuthRequiredCallback auth_required_callback, + bool first_auth_attempt) : auth_info_(auth_info), - request_(request), - render_process_id_(-1), - render_frame_id_(-1) { -#if !defined(EWK_BRINGUP) // FIXME: m85 bringup - bool result = ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_id_, &render_frame_id_); - - DCHECK(result); - DCHECK(render_process_id_ != -1); - DCHECK(render_frame_id_ != -1); -#endif - - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + url_(url), + web_contents_(web_contents), + auth_required_callback_(std::move(auth_required_callback)), + first_auth_attempt_(first_auth_attempt) { + content::GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&LoginDelegateEfl::HandleHttpAuthRequestOnUIThread, base::Unretained(this))); } -LoginDelegateEfl::~LoginDelegateEfl() { -} void LoginDelegateEfl::Proceed(const char* user, const char* password) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - base::PostTask(FROM_HERE, {BrowserThread::IO}, - base::BindOnce(&LoginDelegateEfl::ProceedOnIOThread, - base::Unretained(this), base::UTF8ToUTF16(user), - base::UTF8ToUTF16(password))); + std::move(auth_required_callback_).Run(net::AuthCredentials( + base::UTF8ToUTF16(user), base::UTF8ToUTF16(password))); } void LoginDelegateEfl::Cancel() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - base::PostTask(FROM_HERE, {BrowserThread::IO}, - base::BindOnce(&LoginDelegateEfl::CancelOnIOThread, - base::Unretained(this))); + std::move(auth_required_callback_).Run(absl::nullopt); } void LoginDelegateEfl::HandleHttpAuthRequestOnUIThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - WebContents* web_contents = web_contents_utils::WebContentsFromFrameID(render_process_id_, render_frame_id_); - if (!web_contents) { + if (!web_contents_ || !web_contents_->GetDelegate()) { Cancel(); return; } content::WebContentsDelegateEfl* delegate = - static_cast(web_contents->GetDelegate()); - DCHECK(delegate); - delegate->OnAuthRequired(request_, auth_info_->realm, this); -} + static_cast( + web_contents_->GetDelegate()); -void LoginDelegateEfl::CancelOnIOThread() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (request_) { - request_->CancelAuth(); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); -#endif - request_ = NULL; - } -} + if (first_auth_attempt_ && auth_info_->is_proxy) { + const EWebContext* web_context = delegate->web_view()->context()->GetImpl(); + DCHECK(web_context); -void LoginDelegateEfl::ProceedOnIOThread(const std::u16string& user, - const std::u16string& password) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (request_) { - request_->SetAuth(net::AuthCredentials(user, password)); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); -#endif - request_ = NULL; + if (!web_context->GetProxyUsername().empty()) { + Proceed(web_context->GetProxyUsername().c_str(), + web_context->GetProxyPassword().c_str()); + return; + } } + + delegate->OnAuthRequired(auth_info_->realm, url_, this); } +/* LCOV_EXCL_STOP */ diff --git a/tizen_src/ewk/efl_integration/browser/login_delegate_efl.h b/tizen_src/ewk/efl_integration/browser/login_delegate_efl.h index 1f655fbf5596..fb38567a4258 100644 --- a/tizen_src/ewk/efl_integration/browser/login_delegate_efl.h +++ b/tizen_src/ewk/efl_integration/browser/login_delegate_efl.h @@ -7,31 +7,37 @@ #include "base/memory/ref_counted.h" #include "content/public/browser/login_delegate.h" +#include "url/gurl.h" namespace net { class AuthChallengeInfo; class URLRequest; } +namespace content { +class WebContents; +} + class LoginDelegateEfl : public content::LoginDelegate { public: - LoginDelegateEfl(net::AuthChallengeInfo* auth_info, net::URLRequest* request); - - virtual void Proceed(const char* user, const char* password); - virtual void Cancel(); - virtual ~LoginDelegateEfl(); - - private: - void HandleHttpAuthRequestOnUIThread(); - void CancelOnIOThread(); - void ProceedOnIOThread(const std::u16string& user, - const std::u16string& password); - void DeleteAuthHandlerSoon(); - - std::unique_ptr auth_info_; - net::URLRequest* request_; - int render_process_id_; - int render_frame_id_; + LoginDelegateEfl(const net::AuthChallengeInfo* auth_info, + const GURL& url, + content::WebContents* web_contents, + LoginAuthRequiredCallback auth_required_callback, + bool first_auth_attempt); + + void Proceed(const char* user, const char* password); + void Cancel(); + ~LoginDelegateEfl() override {}; + + private: + void HandleHttpAuthRequestOnUIThread(); + + const net::AuthChallengeInfo* auth_info_; + GURL url_; + content::WebContents* web_contents_; + LoginAuthRequiredCallback auth_required_callback_; + const bool first_auth_attempt_; }; #endif /* LOGIN_DELEGATE_EFL_H_ */ diff --git a/tizen_src/ewk/efl_integration/content_browser_client_efl.cc b/tizen_src/ewk/efl_integration/content_browser_client_efl.cc index 418cbd100fcd..508f87a3f137 100644 --- a/tizen_src/ewk/efl_integration/content_browser_client_efl.cc +++ b/tizen_src/ewk/efl_integration/content_browser_client_efl.cc @@ -465,4 +465,21 @@ void ContentBrowserClientEfl::NotifyAcceptLangsChanged() { } } +std::unique_ptr ContentBrowserClientEfl::CreateLoginDelegate( + const net::AuthChallengeInfo& auth_info, + WebContents* web_contents, + const GlobalRequestID& request_id, + bool is_request_for_main_frame, + const GURL& url, + scoped_refptr response_headers, + bool first_auth_attempt, + LoginAuthRequiredCallback auth_required_callback) { + if (web_contents) { + return std::unique_ptr(new LoginDelegateEfl( + &auth_info, url, web_contents, std::move(auth_required_callback), + first_auth_attempt)); + } + return nullptr; +} + } // namespace content diff --git a/tizen_src/ewk/efl_integration/content_browser_client_efl.h b/tizen_src/ewk/efl_integration/content_browser_client_efl.h index cc11fb112e62..6df35ec94645 100644 --- a/tizen_src/ewk/efl_integration/content_browser_client_efl.h +++ b/tizen_src/ewk/efl_integration/content_browser_client_efl.h @@ -111,6 +111,16 @@ class ContentBrowserClientEfl : public ContentBrowserClient { browser_context_efl_ = context; } + virtual std::unique_ptr CreateLoginDelegate( + const net::AuthChallengeInfo& auth_info, + WebContents* web_contents, + const GlobalRequestID& request_id, + bool is_request_for_main_frame, + const GURL& url, + scoped_refptr response_headers, + bool first_auth_attempt, + LoginAuthRequiredCallback auth_required_callback) override; + std::string GetProduct() override; std::string GetUserAgent() override; diff --git a/tizen_src/ewk/efl_integration/eweb_context.cc b/tizen_src/ewk/efl_integration/eweb_context.cc index d1d9ed8d1d44..d8b5a0f97b02 100644 --- a/tizen_src/ewk/efl_integration/eweb_context.cc +++ b/tizen_src/ewk/efl_integration/eweb_context.cc @@ -512,6 +512,12 @@ void EWebContext::SetProxyUri(const char* uri) { #endif } +void EWebContext::SetProxyDefaultAuth(const char* username, + const char* password) { + proxy_username_ = (username != nullptr) ? string(username) : string(); + proxy_password_ = (password != nullptr) ? string(password) : string(); +} + void EWebContext::SetDidStartDownloadCallback( Ewk_Context_Did_Start_Download_Callback callback, void* user_data) { diff --git a/tizen_src/ewk/efl_integration/eweb_context.h b/tizen_src/ewk/efl_integration/eweb_context.h index e6f94cad08b6..6b068049cc8f 100644 --- a/tizen_src/ewk/efl_integration/eweb_context.h +++ b/tizen_src/ewk/efl_integration/eweb_context.h @@ -110,6 +110,9 @@ class EWebContext { void SetProxyUri(const char* uri); const char* GetProxyUri() const { return proxy_uri_.c_str(); } + void SetProxyDefaultAuth(const char* username, const char* password); + const std::string& GetProxyUsername() const { return proxy_username_; } + const std::string& GetProxyPassword() const { return proxy_password_; } //download start callback handlers void SetDidStartDownloadCallback(Ewk_Context_Did_Start_Download_Callback callback, void* user_data); @@ -184,6 +187,8 @@ class EWebContext { std::unique_ptr tizen_extensible_; std::unique_ptr ewk_favicon_database_; std::string proxy_uri_; + std::string proxy_username_; + std::string proxy_password_; std::string injected_bundle_path_; #if defined(OS_TIZEN) diff --git a/tizen_src/ewk/efl_integration/private/ewk_auth_challenge_private.h b/tizen_src/ewk/efl_integration/private/ewk_auth_challenge_private.h index 14172ff06b6d..ded617d77459 100644 --- a/tizen_src/ewk/efl_integration/private/ewk_auth_challenge_private.h +++ b/tizen_src/ewk/efl_integration/private/ewk_auth_challenge_private.h @@ -24,7 +24,7 @@ struct _Ewk_Auth_Challenge { is_suspended(false) { } - std::unique_ptr login_delegate; + LoginDelegateEfl* login_delegate; std::string url; std::string realm; bool is_decided; diff --git a/tizen_src/ewk/efl_integration/private/ewk_context_private.cc b/tizen_src/ewk/efl_integration/private/ewk_context_private.cc index ef5cd9e50f0b..95ea2678e490 100644 --- a/tizen_src/ewk/efl_integration/private/ewk_context_private.cc +++ b/tizen_src/ewk/efl_integration/private/ewk_context_private.cc @@ -104,6 +104,11 @@ const char* Ewk_Context::GetProxyUri() const { return impl->GetProxyUri(); } +void Ewk_Context::SetProxyDefaultAuth(const char* username, + const char* password) { + impl->SetProxyDefaultAuth(username, password); +} + void Ewk_Context::NotifyLowMemory() { impl->NotifyLowMemory(); } diff --git a/tizen_src/ewk/efl_integration/private/ewk_context_private.h b/tizen_src/ewk/efl_integration/private/ewk_context_private.h index 050b60bcb2d8..4b684afe0ba9 100644 --- a/tizen_src/ewk/efl_integration/private/ewk_context_private.h +++ b/tizen_src/ewk/efl_integration/private/ewk_context_private.h @@ -46,6 +46,7 @@ struct Ewk_Context : public base::RefCounted { // Proxy URI void SetProxyUri(const char* uri); const char* GetProxyUri() const; + void SetProxyDefaultAuth(const char* username, const char* password); // System void NotifyLowMemory(); diff --git a/tizen_src/ewk/efl_integration/public/ewk_context.cc b/tizen_src/ewk/efl_integration/public/ewk_context.cc index 89c0f121fdbf..e9676da585ed 100644 --- a/tizen_src/ewk/efl_integration/public/ewk_context.cc +++ b/tizen_src/ewk/efl_integration/public/ewk_context.cc @@ -756,8 +756,14 @@ const char* ewk_context_proxy_bypass_rule_get(Ewk_Context* context) Eina_Bool ewk_context_proxy_default_auth_set(Ewk_Context* context, const char* username, const char* password) { - LOG_EWK_API_MOCKUP(); - return false; +#if defined(OS_TIZEN_TV_PRODUCT) + EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE); + context->SetProxyDefaultAuth(username, password); + return EINA_TRUE; +#else + LOG_EWK_API_MOCKUP("Only for Tizen TV"); + return EINA_FALSE; +#endif } void ewk_context_password_confirm_popup_callback_set(Ewk_Context* context, Ewk_Context_Password_Confirm_Popup_Callback callback, void* user_data) diff --git a/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc b/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc index 425fe6b9818c..4cccc229c31f 100644 --- a/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc +++ b/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc @@ -323,10 +323,10 @@ void WebContentsDelegateEfl::RequestMediaAccessPermission( } #endif -void WebContentsDelegateEfl::OnAuthRequired(net::URLRequest* request, - const std::string& realm, +void WebContentsDelegateEfl::OnAuthRequired(const std::string& realm, + const GURL& url, LoginDelegateEfl* login_delegate) { - web_view_->InvokeAuthCallback(login_delegate, request->url(), realm); + web_view_->InvokeAuthCallback(login_delegate, url, realm); } void WebContentsDelegateEfl::DidStartProvisionalLoadForFrame( diff --git a/tizen_src/ewk/efl_integration/web_contents_delegate_efl.h b/tizen_src/ewk/efl_integration/web_contents_delegate_efl.h index c99f0bc18405..dbb08ea2d94d 100644 --- a/tizen_src/ewk/efl_integration/web_contents_delegate_efl.h +++ b/tizen_src/ewk/efl_integration/web_contents_delegate_efl.h @@ -186,8 +186,8 @@ class WebContentsDelegateEfl : public WebContentsDelegate, bool was_ignored_by_handler); // EWK_BRINGUP end. - void OnAuthRequired(net::URLRequest* request, - const std::string& realm, + void OnAuthRequired(const std::string& realm, + const GURL& url, LoginDelegateEfl* login_delegate); void DidDownloadFavicon(bool success, -- 2.34.1