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

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 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
22 23
23 AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid( 24 AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid(
24 InfoBarService* owner,
25 const Params& params) 25 const Params& params)
26 : AutoLoginInfoBarDelegate(owner, params), 26 : AutoLoginInfoBarDelegate(params),
27 params_(params) { 27 params_(params) {
28 } 28 }
29 29
30 AutoLoginInfoBarDelegateAndroid::~AutoLoginInfoBarDelegateAndroid() { 30 AutoLoginInfoBarDelegateAndroid::~AutoLoginInfoBarDelegateAndroid() {
31 } 31 }
32 32
33 bool AutoLoginInfoBarDelegateAndroid::AttachAccount( 33 bool AutoLoginInfoBarDelegateAndroid::AttachAccount(
34 JavaObjectWeakGlobalRef weak_java_auto_login_delegate) { 34 JavaObjectWeakGlobalRef weak_java_auto_login_delegate) {
35 weak_java_auto_login_delegate_ = weak_java_auto_login_delegate; 35 weak_java_auto_login_delegate_ = weak_java_auto_login_delegate;
36 JNIEnv* env = base::android::AttachCurrentThread(); 36 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 weak_java_auto_login_delegate_.get(env); 75 weak_java_auto_login_delegate_.get(env);
76 DCHECK(delegate.obj()); 76 DCHECK(delegate.obj());
77 Java_AutoLoginDelegate_cancelLogIn(env, delegate.obj(), 77 Java_AutoLoginDelegate_cancelLogIn(env, delegate.obj(),
78 reinterpret_cast<intptr_t>(this)); 78 reinterpret_cast<intptr_t>(this));
79 return true; 79 return true;
80 } 80 }
81 81
82 void AutoLoginInfoBarDelegateAndroid::LoginSuccess(JNIEnv* env, 82 void AutoLoginInfoBarDelegateAndroid::LoginSuccess(JNIEnv* env,
83 jobject obj, 83 jobject obj,
84 jstring result) { 84 jstring result) {
85 if (!owner()) 85 if (!infobar()->owner())
86 return; // We're closing; don't call anything, it might access the owner. 86 return; // We're closing; don't call anything, it might access the owner.
87 87
88 // TODO(miguelg): Test whether the Stop() and RemoveInfoBar() calls here are 88 // TODO(miguelg): Test whether the Stop() and RemoveInfoBar() calls here are
89 // necessary, or whether OpenURL() will do this for us. 89 // necessary, or whether OpenURL() will do this for us.
90 content::WebContents* web_contents = owner()->web_contents(); 90 content::WebContents* contents = web_contents();
91 web_contents->Stop(); 91 contents->Stop();
92 owner()->RemoveInfoBar(this); 92 infobar()->RemoveSelf();
93 // WARNING: |this| may be deleted at this point! Do not access any members! 93 // WARNING: |this| may be deleted at this point! Do not access any members!
94 web_contents->OpenURL(content::OpenURLParams( 94 contents->OpenURL(content::OpenURLParams(
95 GURL(base::android::ConvertJavaStringToUTF8(env, result)), 95 GURL(base::android::ConvertJavaStringToUTF8(env, result)),
96 content::Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, 96 content::Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK,
97 false)); 97 false));
98 } 98 }
99 99
100 void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) { 100 void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) {
101 if (!owner()) 101 if (!infobar()->owner())
102 return; // We're closing; don't call anything, it might access the owner. 102 return; // We're closing; don't call anything, it might access the owner.
103 103
104 // TODO(miguelg): Using SimpleAlertInfoBarDelegate::Create() animates in a new 104 // TODO(miguelg): Using SimpleAlertInfoBarDelegate::Create() animates in a new
105 // infobar while we animate the current one closed. It would be better to use 105 // infobar while we animate the current one closed. It would be better to use
106 // ReplaceInfoBar(). 106 // ReplaceInfoBar().
107 SimpleAlertInfoBarDelegate::Create( 107 SimpleAlertInfoBarDelegate::Create(
108 owner(), IDR_INFOBAR_WARNING, 108 infobar()->owner(), IDR_INFOBAR_WARNING,
109 l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false); 109 l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false);
110 owner()->RemoveInfoBar(this); 110 infobar()->RemoveSelf();
111 } 111 }
112 112
113 void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) { 113 void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) {
114 if (owner()) 114 infobar()->RemoveSelf();
115 owner()->RemoveInfoBar(this);
116 } 115 }
117 116
118 bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) { 117 bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) {
119 return RegisterNativesImpl(env); 118 return RegisterNativesImpl(env);
120 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698