[M94 Migration] Bringup Authentication popup 19/267719/1
authorSurya Kumar <surya.kumar7@samsung.com>
Mon, 6 Dec 2021 12:51:05 +0000 (18:21 +0530)
committerSurya Kumar <surya.kumar7@samsung.com>
Thu, 9 Dec 2021 06:49:11 +0000 (12:19 +0530)
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 <surya.kumar7@samsung.com>
12 files changed:
tizen_src/ewk/efl_integration/browser/login_delegate_efl.cc
tizen_src/ewk/efl_integration/browser/login_delegate_efl.h
tizen_src/ewk/efl_integration/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/content_browser_client_efl.h
tizen_src/ewk/efl_integration/eweb_context.cc
tizen_src/ewk/efl_integration/eweb_context.h
tizen_src/ewk/efl_integration/private/ewk_auth_challenge_private.h
tizen_src/ewk/efl_integration/private/ewk_context_private.cc
tizen_src/ewk/efl_integration/private/ewk_context_private.h
tizen_src/ewk/efl_integration/public/ewk_context.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.h

index cd392b96714dc38c54fea351e411367c774a480c..708a1de39cf4774ddeef62579e80b680072eb91c 100644 (file)
@@ -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 <assert.h>
+#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<content::WebContentsDelegateEfl*>(web_contents->GetDelegate());
-  DCHECK(delegate);
-  delegate->OnAuthRequired(request_, auth_info_->realm, this);
-}
+      static_cast<content::WebContentsDelegateEfl*>(
+          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 */
index 1f655fbf5596955a8a1f4782839d8a4fa49f4c97..fb38567a4258b8e77d5a8a182a6eeba5afc484de 100644 (file)
@@ -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<net::AuthChallengeInfo> 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_ */
index 418cbd100fcde0c96e262bb667258fa19ac5e2ff..508f87a3f1378b161dda97622a3a168da35bd95d 100644 (file)
@@ -465,4 +465,21 @@ void ContentBrowserClientEfl::NotifyAcceptLangsChanged() {
   }
 }
 
+std::unique_ptr<LoginDelegate> 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<net::HttpResponseHeaders> response_headers,
+    bool first_auth_attempt,
+    LoginAuthRequiredCallback auth_required_callback) {
+  if (web_contents) {
+    return std::unique_ptr<LoginDelegate>(new LoginDelegateEfl(
+        &auth_info, url, web_contents, std::move(auth_required_callback),
+        first_auth_attempt));
+  }
+  return nullptr;
+}
+
 }  // namespace content
index cc11fb112e62b54b3da60a0a86c9bdfad2577dc3..6df35ec94645ea89709663eef18957742aa99de6 100644 (file)
@@ -111,6 +111,16 @@ class ContentBrowserClientEfl : public ContentBrowserClient {
     browser_context_efl_ = context;
   }
 
+  virtual std::unique_ptr<LoginDelegate> CreateLoginDelegate(
+      const net::AuthChallengeInfo& auth_info,
+      WebContents* web_contents,
+      const GlobalRequestID& request_id,
+      bool is_request_for_main_frame,
+      const GURL& url,
+      scoped_refptr<net::HttpResponseHeaders> response_headers,
+      bool first_auth_attempt,
+      LoginAuthRequiredCallback auth_required_callback) override;
+
   std::string GetProduct() override;
   std::string GetUserAgent() override;
 
index d1d9ed8d1d44cd4d026f2061ef2d2e69688fd737..d8b5a0f97b02e7bb58cde388978f7506903f99af 100644 (file)
@@ -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) {
index e6f94cad08b6b27f800d85205ad1fcfe7f3a2bda..6b068049cc8f675b3df97fb0eaffd5b9eef10f75 100644 (file)
@@ -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<TizenExtensible> tizen_extensible_;
   std::unique_ptr<EwkFaviconDatabase> ewk_favicon_database_;
   std::string proxy_uri_;
+  std::string proxy_username_;
+  std::string proxy_password_;
   std::string injected_bundle_path_;
 
 #if defined(OS_TIZEN)
index 14172ff06b6d45dadd05f925c697b52eea10cf5f..ded617d774599c261617c707109c0b10b77b5cdb 100644 (file)
@@ -24,7 +24,7 @@ struct _Ewk_Auth_Challenge {
         is_suspended(false) {
   }
 
-  std::unique_ptr<LoginDelegateEfl> login_delegate;
+  LoginDelegateEfl* login_delegate;
   std::string url;
   std::string realm;
   bool is_decided;
index ef5cd9e50f0b081073487fcf7ccab8d257a49306..95ea2678e490ed0c2306772823778a72519d5692 100644 (file)
@@ -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();
 }
index 050b60bcb2d86232f21474cbb0983af8cdd2e3e3..4b684afe0ba94611666b0a6ca3304b3be7de8bb9 100644 (file)
@@ -46,6 +46,7 @@ struct Ewk_Context : public base::RefCounted<Ewk_Context> {
   // Proxy URI
   void SetProxyUri(const char* uri);
   const char* GetProxyUri() const;
+  void SetProxyDefaultAuth(const char* username, const char* password);
 
   // System
   void NotifyLowMemory();
index 89c0f121fdbff80a993f9481a84971503f1a9fb7..e9676da585ed533997041ddc7629279cb1ab9446 100644 (file)
@@ -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)
index 425fe6b9818c479e832d8972ff24d82a451e319c..4cccc229c31f052262fe7d089204379c512e21c6 100644 (file)
@@ -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(
index c99f0bc184058d23c55819c9bc52d790d3921194..dbb08ea2d94daad8297f260c8459fb2ad825d541 100644 (file)
@@ -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,