Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(949)

Side by Side Diff: android_webview/native/aw_http_auth_handler.cc

Issue 11661013: Tell java side when the native auth handler is gone (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix2 Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « android_webview/java/src/org/chromium/android_webview/AwHttpAuthHandler.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/native/aw_http_auth_handler.h" 5 #include "android_webview/native/aw_http_auth_handler.h"
6 6
7 #include "android_webview/browser/aw_login_delegate.h" 7 #include "android_webview/browser/aw_login_delegate.h"
8 #include "android_webview/native/aw_contents.h" 8 #include "android_webview/native/aw_contents.h"
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "content/public/browser/browser_thread.h"
11 #include "jni/AwHttpAuthHandler_jni.h" 12 #include "jni/AwHttpAuthHandler_jni.h"
12 #include "net/base/auth.h" 13 #include "net/base/auth.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 15
15 using base::android::ConvertJavaStringToUTF16; 16 using base::android::ConvertJavaStringToUTF16;
16 17
17 namespace android_webview { 18 namespace android_webview {
18 19
19 AwHttpAuthHandler::AwHttpAuthHandler(AwLoginDelegate* login_delegate, 20 AwHttpAuthHandler::AwHttpAuthHandler(AwLoginDelegate* login_delegate,
20 net::AuthChallengeInfo* auth_info, 21 net::AuthChallengeInfo* auth_info,
21 bool first_auth_attempt) 22 bool first_auth_attempt)
22 : login_delegate_(make_scoped_refptr(login_delegate)), 23 : login_delegate_(login_delegate),
23 host_(auth_info->challenger.host()), 24 host_(auth_info->challenger.host()),
24 realm_(auth_info->realm) { 25 realm_(auth_info->realm) {
26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
25 JNIEnv* env = base::android::AttachCurrentThread(); 27 JNIEnv* env = base::android::AttachCurrentThread();
26 http_auth_handler_.Reset( 28 http_auth_handler_.Reset(
27 Java_AwHttpAuthHandler_create( 29 Java_AwHttpAuthHandler_create(
28 env, reinterpret_cast<jint>(this), first_auth_attempt)); 30 env, reinterpret_cast<jint>(this), first_auth_attempt));
29 } 31 }
30 32
31 AwHttpAuthHandler:: ~AwHttpAuthHandler() { 33 AwHttpAuthHandler:: ~AwHttpAuthHandler() {
32 // TODO(joth): tell java counterpart, so it can null its native back-pointer. 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
35 Java_AwHttpAuthHandler_handlerDestroyed(base::android::AttachCurrentThread(),
36 http_auth_handler_.obj());
33 } 37 }
34 38
35 void AwHttpAuthHandler::Proceed(JNIEnv* env, 39 void AwHttpAuthHandler::Proceed(JNIEnv* env,
36 jobject obj, 40 jobject obj,
37 jstring user, 41 jstring user,
38 jstring password) { 42 jstring password) {
39 login_delegate_->Proceed(ConvertJavaStringToUTF16(env, user), 43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
40 ConvertJavaStringToUTF16(env, password)); 44 if (login_delegate_) {
45 login_delegate_->Proceed(ConvertJavaStringToUTF16(env, user),
46 ConvertJavaStringToUTF16(env, password));
47 login_delegate_ = NULL;
48 }
41 } 49 }
42 50
43 void AwHttpAuthHandler::Cancel(JNIEnv* env, jobject obj) { 51 void AwHttpAuthHandler::Cancel(JNIEnv* env, jobject obj) {
44 login_delegate_->Cancel(); 52 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
53 if (login_delegate_) {
54 login_delegate_->Cancel();
55 login_delegate_ = NULL;
56 }
45 } 57 }
46 58
47 void AwHttpAuthHandler::HandleOnUIThread(content::WebContents* web_contents) { 59 void AwHttpAuthHandler::HandleOnUIThread(content::WebContents* web_contents) {
48 DCHECK(web_contents); 60 DCHECK(web_contents);
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
49 AwContents* aw_contents = AwContents::FromWebContents(web_contents); 62 AwContents* aw_contents = AwContents::FromWebContents(web_contents);
50 63
51 aw_contents->onReceivedHttpAuthRequest( 64 aw_contents->onReceivedHttpAuthRequest(
52 http_auth_handler_, host_, realm_); 65 http_auth_handler_, host_, realm_);
53 } 66 }
54 67
55 // static 68 // static
56 AwHttpAuthHandlerBase* AwHttpAuthHandlerBase::Create( 69 AwHttpAuthHandlerBase* AwHttpAuthHandlerBase::Create(
57 AwLoginDelegate* login_delegate, 70 AwLoginDelegate* login_delegate,
58 net::AuthChallengeInfo* auth_info, 71 net::AuthChallengeInfo* auth_info,
59 bool first_auth_attempt) { 72 bool first_auth_attempt) {
60 return new AwHttpAuthHandler(login_delegate, auth_info, first_auth_attempt); 73 return new AwHttpAuthHandler(login_delegate, auth_info, first_auth_attempt);
61 } 74 }
62 75
63 bool RegisterAwHttpAuthHandler(JNIEnv* env) { 76 bool RegisterAwHttpAuthHandler(JNIEnv* env) {
64 return RegisterNativesImpl(env) >= 0; 77 return RegisterNativesImpl(env) >= 0;
65 } 78 }
66 79
67 } // namespace android_webview 80 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/java/src/org/chromium/android_webview/AwHttpAuthHandler.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698