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

Side by Side Diff: chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 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
OLDNEW
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/infobar.h"
11 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" 12 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h"
12 #include "chrome/browser/ui/auto_login_infobar_delegate.h" 13 #include "chrome/browser/ui/auto_login_infobar_delegate.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
16 #include "jni/AutoLoginDelegate_jni.h" 17 #include "jni/AutoLoginDelegate_jni.h"
17 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
18 19
19 using base::android::ConvertUTF8ToJavaString; 20 using base::android::ConvertUTF8ToJavaString;
20 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
21 22
23
22 AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid( 24 AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid(
23 InfoBarService* owner,
24 const Params& params) 25 const Params& params)
25 : AutoLoginInfoBarDelegate(owner, params), 26 : AutoLoginInfoBarDelegate(params),
26 params_(params) { 27 params_(params) {
27 } 28 }
28 29
29 AutoLoginInfoBarDelegateAndroid::~AutoLoginInfoBarDelegateAndroid() { 30 AutoLoginInfoBarDelegateAndroid::~AutoLoginInfoBarDelegateAndroid() {
30 } 31 }
31 32
32 bool AutoLoginInfoBarDelegateAndroid::AttachAccount( 33 bool AutoLoginInfoBarDelegateAndroid::AttachAccount(
33 JavaObjectWeakGlobalRef weak_java_auto_login_delegate) { 34 JavaObjectWeakGlobalRef weak_java_auto_login_delegate) {
34 weak_java_auto_login_delegate_ = weak_java_auto_login_delegate; 35 weak_java_auto_login_delegate_ = weak_java_auto_login_delegate;
35 JNIEnv* env = base::android::AttachCurrentThread(); 36 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 18 matching lines...) Expand all
54 string16 AutoLoginInfoBarDelegateAndroid::GetMessageText() const { 55 string16 AutoLoginInfoBarDelegateAndroid::GetMessageText() const {
55 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE, 56 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE,
56 UTF8ToUTF16(user_)); 57 UTF8ToUTF16(user_));
57 } 58 }
58 59
59 bool AutoLoginInfoBarDelegateAndroid::Accept() { 60 bool AutoLoginInfoBarDelegateAndroid::Accept() {
60 JNIEnv* env = base::android::AttachCurrentThread(); 61 JNIEnv* env = base::android::AttachCurrentThread();
61 ScopedJavaLocalRef<jobject> delegate = 62 ScopedJavaLocalRef<jobject> delegate =
62 weak_java_auto_login_delegate_.get(env); 63 weak_java_auto_login_delegate_.get(env);
63 DCHECK(delegate.obj()); 64 DCHECK(delegate.obj());
64
65 Java_AutoLoginDelegate_logIn(env, delegate.obj(), 65 Java_AutoLoginDelegate_logIn(env, delegate.obj(),
66 reinterpret_cast<jint>(this)); 66 reinterpret_cast<jint>(this));
67
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 = base::android::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(env, delegate.obj(), 77 Java_AutoLoginDelegate_cancelLogIn(env, delegate.obj(),
79 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 // TODO(pkasting): Can this and LoginFailed() really be called when the
87 content::WebContents* web_contents = owner()->web_contents(); 86 // infobar is unowned?
88 if (web_contents) { 87 if (infobar()->owner()) {
89 web_contents->Stop(); 88 content::WebContents* contents = web_contents();
90 web_contents->OpenURL(content::OpenURLParams( 89 contents->Stop();
91 GURL(base::android::ConvertJavaStringToUTF8(env, result)), 90 // It's not obvious whether calling OpenURL() will auto-close us or not. If
92 content::Referrer(), CURRENT_TAB, 91 // it did, we wouldn't want to try to RemoveSelf() afterwards. So for
93 content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); 92 // safety, we always call RemoveSelf() directly, and then navigate
94 } 93 // afterwards.
95 owner()->RemoveInfoBar(this); 94 infobar()->RemoveSelf();
95 // WARNING: |this| may be deleted at this point! Do not access any members!
96 contents->OpenURL(content::OpenURLParams(
97 GURL(base::android::ConvertJavaStringToUTF8(env, result)),
98 content::Referrer(), CURRENT_TAB,
99 content::PAGE_TRANSITION_LINK, false));
96 } 100 }
97 } 101 }
98 102
99 void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) { 103 void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) {
100 ScopedJavaLocalRef<jobject> delegate = 104 ScopedJavaLocalRef<jobject> delegate =
101 weak_java_auto_login_delegate_.get(env); 105 weak_java_auto_login_delegate_.get(env);
102 DCHECK(delegate.obj()); 106 DCHECK(delegate.obj());
103 if (owner()) { 107 if (infobar()->owner()) {
104 SimpleAlertInfoBarDelegate::Create( 108 SimpleAlertInfoBarDelegate::Create(
105 owner(), IDR_INFOBAR_WARNING, 109 infobar()->owner(), IDR_INFOBAR_WARNING,
106 l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false); 110 l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false);
107 owner()->RemoveInfoBar(this); 111 infobar()->RemoveSelf();
108 } 112 }
109 } 113 }
110 114
111 void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) { 115 void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) {
112 if (owner()) 116 infobar()->RemoveSelf();
113 owner()->RemoveInfoBar(this);
114 } 117 }
115 118
116 bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) { 119 bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) {
117 return RegisterNativesImpl(env); 120 return RegisterNativesImpl(env);
118 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698