Skip to content

Commit

Permalink
Move NewLoginRequest plumbing to AwContentsClientBridge
Browse files Browse the repository at this point in the history
This is the continuation of the work described in https://codereview.chromium.org/2425423004/. This moves NewLoginRequest out of AwContentsIoThreadClient.

BUG=645983

Review-Url: https://chromiumcodereview.appspot.com/2437423002
Cr-Commit-Position: refs/heads/master@{#426898}
  • Loading branch information
sgurun authored and Commit bot committed Oct 21, 2016
1 parent 0757041 commit a0039ea
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 49 deletions.
9 changes: 9 additions & 0 deletions android_webview/browser/aw_contents_client_bridge_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ AwContentsClientBridgeBase* AwContentsClientBridgeBase::FromWebContents(
return UserData::GetContents(web_contents);
}

// static
AwContentsClientBridgeBase* AwContentsClientBridgeBase::FromWebContentsGetter(
const content::ResourceRequestInfo::WebContentsGetter&
web_contents_getter) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
WebContents* web_contents = web_contents_getter.Run();
return UserData::GetContents(web_contents);
}

// static
AwContentsClientBridgeBase* AwContentsClientBridgeBase::FromID(
int render_process_id,
Expand Down
11 changes: 11 additions & 0 deletions android_webview/browser/aw_contents_client_bridge_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/supports_user_data.h"
#include "content/public/browser/certificate_request_result_type.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/resource_request_info.h"

class GURL;

Expand Down Expand Up @@ -37,6 +38,9 @@ class AwContentsClientBridgeBase {
AwContentsClientBridgeBase* handler);
static AwContentsClientBridgeBase* FromWebContents(
content::WebContents* web_contents);
static AwContentsClientBridgeBase* FromWebContentsGetter(
const content::ResourceRequestInfo::WebContentsGetter&
web_contents_getter);
static AwContentsClientBridgeBase* FromID(int render_process_id,
int render_frame_id);

Expand Down Expand Up @@ -76,6 +80,13 @@ class AwContentsClientBridgeBase {
const std::string& content_disposition,
const std::string& mime_type,
int64_t content_length) = 0;

// Called when a new login request is detected. See the documentation for
// WebViewClient.onReceivedLoginRequest for arguments. Note that |account|
// may be empty.
virtual void NewLoginRequest(const std::string& realm,
const std::string& account,
const std::string& args) = 0;
};

} // namespace android_webview
Expand Down
7 changes: 0 additions & 7 deletions android_webview/browser/aw_contents_io_thread_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ class AwContentsIoThreadClient {
// Retrieve the AcceptThirdPartyCookies setting value of this AwContents.
virtual bool ShouldAcceptThirdPartyCookies() const = 0;

// Called when a new login request is detected. See the documentation for
// WebViewClient.onReceivedLoginRequest for arguments. Note that |account|
// may be empty.
virtual void NewLoginRequest(const std::string& realm,
const std::string& account,
const std::string& args) = 0;

// Called when a resource loading error has occured (e.g. an I/O error,
// host name lookup failure etc.)
virtual void OnReceivedError(const net::URLRequest* request) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,26 @@ void DownloadStartingOnUIThread(
const std::string& content_disposition,
const std::string& mime_type,
int64_t content_length) {
WebContents* web_contents = web_contents_getter.Run();
AwContentsClientBridgeBase* client =
AwContentsClientBridgeBase::FromWebContents(web_contents);
AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter);
if (!client)
return;
client->NewDownload(url, user_agent, content_disposition, mime_type,
content_length);
}

void NewLoginRequestOnUIThread(
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const std::string& realm,
const std::string& account,
const std::string& args) {
AwContentsClientBridgeBase* client =
AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter);
if (!client)
return;
client->NewLoginRequest(realm, account, args);
}

} // namespace

namespace android_webview {
Expand Down Expand Up @@ -359,13 +370,11 @@ void AwResourceDispatcherHostDelegate::OnResponseStarted(
// Check for x-auto-login header.
HeaderData header_data;
if (ParserHeaderInResponse(request, ALLOW_ANY_REALM, &header_data)) {
std::unique_ptr<AwContentsIoThreadClient> io_client =
AwContentsIoThreadClient::FromID(request_info->GetChildID(),
request_info->GetRenderFrameID());
if (io_client) {
io_client->NewLoginRequest(header_data.realm, header_data.account,
header_data.args);
}
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&NewLoginRequestOnUIThread,
request_info->GetWebContentsGetterForRequest(),
header_data.realm, header_data.account, header_data.args));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,6 @@ public boolean shouldAcceptThirdPartyCookies() {
return mSettings.getAcceptThirdPartyCookies();
}

@Override
public void newLoginRequest(String realm, String account, String args) {
mContentsClient.getCallbackHelper().postOnReceivedLoginRequest(realm, account, args);
}

@Override
public void onReceivedError(AwContentsClient.AwWebResourceRequest request,
AwContentsClient.AwWebResourceError error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ private void newDownload(String url, String userAgent, String contentDisposition
url, userAgent, contentDisposition, mimeType, contentLength);
}

@CalledByNative
public void newLoginRequest(String realm, String account, String args) {
mClient.getCallbackHelper().postOnReceivedLoginRequest(realm, account, args);
}

@CalledByNativeUnchecked
private boolean shouldOverrideUrlLoading(
String url, boolean hasUserGesture, boolean isRedirect, boolean isMainFrame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public abstract class AwContentsIoThreadClient {
@CalledByNative
public abstract boolean shouldAcceptThirdPartyCookies();

@CalledByNative
public abstract void newLoginRequest(String realm, String account, String args);

@CalledByNative
public abstract AwContentsBackgroundThreadClient getBackgroundThreadClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ public boolean shouldAcceptThirdPartyCookies() {
return false;
}

@Override
public void newLoginRequest(String realm, String account, String args) {}

@Override
public void onReceivedError(AwContentsClient.AwWebResourceRequest request,
AwContentsClient.AwWebResourceError error) {
Expand Down
20 changes: 20 additions & 0 deletions android_webview/native/aw_contents_client_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,26 @@ void AwContentsClientBridge::NewDownload(const GURL& url,
jstring_mime_type, content_length);
}

void AwContentsClientBridge::NewLoginRequest(const std::string& realm,
const std::string& account,
const std::string& args) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return;

ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm);
ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args);

ScopedJavaLocalRef<jstring> jaccount;
if (!account.empty())
jaccount = ConvertUTF8ToJavaString(env, account);

Java_AwContentsClientBridge_newLoginRequest(env, obj, jrealm, jaccount,
jargs);
}

void AwContentsClientBridge::ConfirmJsResult(JNIEnv* env,
const JavaRef<jobject>&,
int id,
Expand Down
4 changes: 4 additions & 0 deletions android_webview/native/aw_contents_client_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class AwContentsClientBridge : public AwContentsClientBridgeBase {
const std::string& mime_type,
int64_t content_length) override;

void NewLoginRequest(const std::string& realm,
const std::string& account,
const std::string& args) override;

// Methods called from Java.
void ProceedSslError(JNIEnv* env,
const base::android::JavaRef<jobject>& obj,
Expand Down
19 changes: 0 additions & 19 deletions android_webview/native/aw_contents_io_thread_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,25 +402,6 @@ bool AwContentsIoThreadClientImpl::ShouldBlockNetworkLoads() const {
java_object_);
}

void AwContentsIoThreadClientImpl::NewLoginRequest(const string& realm,
const string& account,
const string& args) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (java_object_.is_null())
return;

JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm);
ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args);

ScopedJavaLocalRef<jstring> jaccount;
if (!account.empty())
jaccount = ConvertUTF8ToJavaString(env, account);

Java_AwContentsIoThreadClient_newLoginRequest(env, java_object_, jrealm,
jaccount, jargs);
}

void AwContentsIoThreadClientImpl::OnReceivedError(
const net::URLRequest* request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
Expand Down
3 changes: 0 additions & 3 deletions android_webview/native/aw_contents_io_thread_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class AwContentsIoThreadClientImpl : public AwContentsIoThreadClient {
bool ShouldBlockFileUrls() const override;
bool ShouldAcceptThirdPartyCookies() const override;
bool ShouldBlockNetworkLoads() const override;
void NewLoginRequest(const std::string& realm,
const std::string& account,
const std::string& args) override;
void OnReceivedError(const net::URLRequest* request) override;
void OnReceivedHttpError(
const net::URLRequest* request,
Expand Down

0 comments on commit a0039ea

Please sign in to comment.