// 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 */
#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_ */
}
}
+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
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;
#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) {
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);
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)
is_suspended(false) {
}
- std::unique_ptr<LoginDelegateEfl> login_delegate;
+ LoginDelegateEfl* login_delegate;
std::string url;
std::string realm;
bool is_decided;
return impl->GetProxyUri();
}
+void Ewk_Context::SetProxyDefaultAuth(const char* username,
+ const char* password) {
+ impl->SetProxyDefaultAuth(username, password);
+}
+
void Ewk_Context::NotifyLowMemory() {
impl->NotifyLowMemory();
}
// Proxy URI
void SetProxyUri(const char* uri);
const char* GetProxyUri() const;
+ void SetProxyDefaultAuth(const char* username, const char* password);
// System
void NotifyLowMemory();
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)
}
#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(
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,