Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android .h" | 5 #include "chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android .h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_helper.h" | 8 #include "base/android/jni_helper.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" | 11 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" |
| 12 #include "chrome/browser/ui/auto_login_infobar_delegate.h" | 12 #include "chrome/browser/ui/auto_login_infobar_delegate.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "jni/AutoLoginDelegate_jni.h" | 16 #include "jni/AutoLoginDelegate_jni.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 | 18 |
| 19 using base::android::AttachCurrentThread; | |
| 20 using base::android::ConvertUTF8ToJavaString; | 19 using base::android::ConvertUTF8ToJavaString; |
| 21 using base::android::ScopedJavaGlobalRef; | |
| 22 using base::android::ScopedJavaLocalRef; | 20 using base::android::ScopedJavaLocalRef; |
| 23 | 21 |
| 24 AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid( | 22 AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid( |
| 25 InfoBarService* owner, | 23 InfoBarService* owner, |
| 26 const Params& params) | 24 const Params& params) |
| 27 : AutoLoginInfoBarDelegate(owner, params), params_(params) {} | 25 : AutoLoginInfoBarDelegate(owner, params), |
| 26 params_(params) { | |
| 27 } | |
| 28 | 28 |
| 29 AutoLoginInfoBarDelegateAndroid::~AutoLoginInfoBarDelegateAndroid() {} | 29 AutoLoginInfoBarDelegateAndroid::~AutoLoginInfoBarDelegateAndroid() { |
| 30 } | |
| 30 | 31 |
| 31 bool AutoLoginInfoBarDelegateAndroid::AttachAccount( | 32 bool AutoLoginInfoBarDelegateAndroid::AttachAccount( |
| 32 JavaObjectWeakGlobalRef weak_java_auto_login_delegate) { | 33 JavaObjectWeakGlobalRef weak_java_auto_login_delegate) { |
| 33 weak_java_auto_login_delegate_ = weak_java_auto_login_delegate; | 34 weak_java_auto_login_delegate_ = weak_java_auto_login_delegate; |
| 34 JNIEnv* env = AttachCurrentThread(); | 35 JNIEnv* env = base::android::AttachCurrentThread(); |
| 35 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm()); | 36 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm()); |
| 36 ScopedJavaLocalRef<jstring> jaccount = | 37 ScopedJavaLocalRef<jstring> jaccount = |
| 37 ConvertUTF8ToJavaString(env, account()); | 38 ConvertUTF8ToJavaString(env, account()); |
| 38 ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args()); | 39 ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args()); |
| 39 DCHECK(!jrealm.is_null() && !jaccount.is_null() && !jargs.is_null()); | 40 DCHECK(!jrealm.is_null()); |
| 41 DCHECK(!jaccount.is_null()); | |
| 42 DCHECK(!jargs.is_null()); | |
| 40 | 43 |
| 41 ScopedJavaLocalRef<jobject> delegate = | 44 ScopedJavaLocalRef<jobject> delegate = |
| 42 weak_java_auto_login_delegate_.get(env); | 45 weak_java_auto_login_delegate_.get(env); |
| 43 DCHECK(delegate.obj()); | 46 DCHECK(delegate.obj()); |
| 44 user_ = ConvertJavaStringToUTF8( | 47 user_ = ConvertJavaStringToUTF8(Java_AutoLoginDelegate_initializeAccount( |
| 45 Java_AutoLoginDelegate_initializeAccount(env, | 48 env, delegate.obj(), reinterpret_cast<jint>(this), jrealm.obj(), |
| 46 delegate.obj(), | 49 jaccount.obj(), jargs.obj())); |
| 47 reinterpret_cast<jint>(this), | |
| 48 jrealm.obj(), | |
| 49 jaccount.obj(), | |
| 50 jargs.obj())); | |
| 51 return !user_.empty(); | 50 return !user_.empty(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 string16 AutoLoginInfoBarDelegateAndroid::GetMessageText() const { | 53 string16 AutoLoginInfoBarDelegateAndroid::GetMessageText() const { |
| 55 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE, | 54 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE, |
| 56 UTF8ToUTF16(user_)); | 55 UTF8ToUTF16(user_)); |
| 57 } | 56 } |
| 58 | 57 |
| 59 bool AutoLoginInfoBarDelegateAndroid::Accept() { | 58 bool AutoLoginInfoBarDelegateAndroid::Accept() { |
| 60 JNIEnv* env = AttachCurrentThread(); | 59 JNIEnv* env = base::android::AttachCurrentThread(); |
|
Miguel Garcia
2013/09/25 23:23:48
curious on why the namespace shortcut is not ok f
Peter Kasting
2013/09/25 23:26:23
Why does the unqualified ConvertJavaStringToUTF8()
| |
| 61 ScopedJavaLocalRef<jobject> delegate = | 60 ScopedJavaLocalRef<jobject> delegate = |
| 62 weak_java_auto_login_delegate_.get(env); | 61 weak_java_auto_login_delegate_.get(env); |
| 63 DCHECK(delegate.obj()); | 62 DCHECK(delegate.obj()); |
| 64 | 63 |
| 65 Java_AutoLoginDelegate_logIn( | 64 Java_AutoLoginDelegate_logIn(env, delegate.obj(), |
| 66 env, delegate.obj(), reinterpret_cast<jint>(this)); | 65 reinterpret_cast<jint>(this)); |
| 67 | 66 |
| 68 // Do not close the infobar on accept, it will be closed as part | 67 // Do not close the infobar on accept, it will be closed as part |
| 69 // of the log in callback. | 68 // of the log in callback. |
| 70 return false; | 69 return false; |
| 71 } | 70 } |
| 72 | 71 |
| 73 bool AutoLoginInfoBarDelegateAndroid::Cancel() { | 72 bool AutoLoginInfoBarDelegateAndroid::Cancel() { |
| 74 JNIEnv* env = AttachCurrentThread(); | 73 JNIEnv* env = base::android::AttachCurrentThread(); |
| 75 ScopedJavaLocalRef<jobject> delegate = | 74 ScopedJavaLocalRef<jobject> delegate = |
| 76 weak_java_auto_login_delegate_.get(env); | 75 weak_java_auto_login_delegate_.get(env); |
| 77 DCHECK(delegate.obj()); | 76 DCHECK(delegate.obj()); |
| 78 Java_AutoLoginDelegate_cancelLogIn( | 77 Java_AutoLoginDelegate_cancelLogIn(env, delegate.obj(), |
| 79 env, delegate.obj(), reinterpret_cast<jint>(this)); | 78 reinterpret_cast<jint>(this)); |
| 80 return true; | 79 return true; |
| 81 } | 80 } |
| 82 | 81 |
| 83 void AutoLoginInfoBarDelegateAndroid::LoginSuccess(JNIEnv* env, | 82 void AutoLoginInfoBarDelegateAndroid::LoginSuccess(JNIEnv* env, |
| 84 jobject obj, | 83 jobject obj, |
| 85 jstring result) { | 84 jstring result) { |
| 86 if (owner()) { | 85 if (owner()) { |
| 87 content::WebContents* web_contents = owner()->web_contents(); | 86 content::WebContents* web_contents = owner()->web_contents(); |
| 88 if (web_contents) { | 87 if (web_contents) { |
| 89 web_contents->Stop(); | 88 web_contents->Stop(); |
| 90 web_contents->OpenURL(content::OpenURLParams( | 89 web_contents->OpenURL(content::OpenURLParams( |
| 91 GURL(base::android::ConvertJavaStringToUTF8(env, result)), | 90 GURL(base::android::ConvertJavaStringToUTF8(env, result)), |
| 92 content::Referrer(), | 91 content::Referrer(), |
| 93 CURRENT_TAB, | 92 CURRENT_TAB, |
| 94 content::PAGE_TRANSITION_AUTO_BOOKMARK, | 93 content::PAGE_TRANSITION_AUTO_BOOKMARK, |
| 95 false)); | 94 false)); |
| 96 } | 95 } |
| 97 owner()->RemoveInfoBar(this); | 96 owner()->RemoveInfoBar(this); |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 | 99 |
| 101 void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) { | 100 void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) { |
| 102 ScopedJavaLocalRef<jobject> delegate = | 101 ScopedJavaLocalRef<jobject> delegate = |
| 103 weak_java_auto_login_delegate_.get(env); | 102 weak_java_auto_login_delegate_.get(env); |
| 104 DCHECK(delegate.obj()); | 103 DCHECK(delegate.obj()); |
| 105 if (owner()) { | 104 if (owner()) { |
| 106 SimpleAlertInfoBarDelegate::Create( | 105 SimpleAlertInfoBarDelegate::Create( |
| 107 owner(), | 106 owner(), IDR_INFOBAR_WARNING, |
| 108 IDR_INFOBAR_WARNING, | 107 l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false); |
| 109 l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), | |
| 110 false); | |
| 111 owner()->RemoveInfoBar(this); | 108 owner()->RemoveInfoBar(this); |
| 112 } | 109 } |
| 113 } | 110 } |
| 114 | 111 |
| 115 void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) { | 112 void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) { |
| 116 if (owner()) | 113 if (owner()) |
| 117 owner()->RemoveInfoBar(this); | 114 owner()->RemoveInfoBar(this); |
| 118 } | 115 } |
| 119 | 116 |
| 120 // Register Android JNI bindings. | |
| 121 bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) { | 117 bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) { |
| 122 return RegisterNativesImpl(env); | 118 return RegisterNativesImpl(env); |
| 123 } | 119 } |
| OLD | NEW |