OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/account_chooser_infobar.h" | 5 #include "chrome/browser/ui/android/infobars/account_chooser_infobar.h" |
6 | 6 |
7 #include "base/android/scoped_java_ref.h" | 7 #include "base/android/scoped_java_ref.h" |
8 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 8 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_andro id.h" | 10 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_andro id.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 } | 89 } |
90 | 90 |
91 }; // namespace | 91 }; // namespace |
92 | 92 |
93 AccountChooserInfoBar::AccountChooserInfoBar( | 93 AccountChooserInfoBar::AccountChooserInfoBar( |
94 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) | 94 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) |
95 : InfoBarAndroid(delegate.Pass()) { | 95 : InfoBarAndroid(delegate.Pass()) { |
96 } | 96 } |
97 | 97 |
98 AccountChooserInfoBar::~AccountChooserInfoBar() { | 98 AccountChooserInfoBar::~AccountChooserInfoBar() { |
99 if (java_info_bar()) { | |
David Trainor- moved to gerrit
2015/06/03 19:38:46
Just override onNativeDestroyed() in Java?
Changwan Ryu
2015/06/04 01:42:27
Done.
| |
100 JNIEnv* env = base::android::AttachCurrentThread(); | |
101 Java_AccountChooserInfoBar_onNativeDestroyed(env, java_info_bar()); | |
102 } | |
99 } | 103 } |
100 | 104 |
101 base::android::ScopedJavaLocalRef<jobject> | 105 base::android::ScopedJavaLocalRef<jobject> |
102 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { | 106 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
103 size_t credential_array_size = | 107 size_t credential_array_size = |
104 GetDelegate()->local_credentials_forms().size() + | 108 GetDelegate()->local_credentials_forms().size() + |
105 GetDelegate()->federated_credentials_forms().size(); | 109 GetDelegate()->federated_credentials_forms().size(); |
106 ScopedJavaLocalRef<jobjectArray> java_credentials_array = | 110 ScopedJavaLocalRef<jobjectArray> java_credentials_array = |
107 CreateNativeCredentialArray(env, credential_array_size); | 111 CreateNativeCredentialArray(env, credential_array_size); |
108 AddElementsToJavaCredentialArray( | 112 AddElementsToJavaCredentialArray( |
109 env, java_credentials_array, GetDelegate()->local_credentials_forms(), | 113 env, java_credentials_array, GetDelegate()->local_credentials_forms(), |
110 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 114 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
111 AddElementsToJavaCredentialArray( | 115 AddElementsToJavaCredentialArray( |
112 env, java_credentials_array, GetDelegate()->federated_credentials_forms(), | 116 env, java_credentials_array, GetDelegate()->federated_credentials_forms(), |
113 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED, | 117 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED, |
114 GetDelegate()->local_credentials_forms().size()); | 118 GetDelegate()->local_credentials_forms().size()); |
115 base::android::ScopedJavaGlobalRef<jobject> java_infobar_global; | 119 base::android::ScopedJavaGlobalRef<jobject> java_infobar_global; |
116 java_infobar_global.Reset(Java_AccountChooserInfoBar_show( | 120 java_infobar_global.Reset(Java_AccountChooserInfoBar_show( |
117 env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(), | 121 env, GetEnumeratedIconId(), java_credentials_array.obj())); |
118 java_credentials_array.obj())); | |
119 base::android::ScopedJavaLocalRef<jobject> java_infobar(java_infobar_global); | 122 base::android::ScopedJavaLocalRef<jobject> java_infobar(java_infobar_global); |
120 content::WebContents* web_contents = | 123 content::WebContents* web_contents = |
121 InfoBarService::WebContentsFromInfoBar(this); | 124 InfoBarService::WebContentsFromInfoBar(this); |
122 net::URLRequestContextGetter* request_context = | 125 net::URLRequestContextGetter* request_context = |
123 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 126 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
124 ->GetRequestContext(); | 127 ->GetRequestContext(); |
125 FetchAvatars(java_infobar_global, GetDelegate()->local_credentials_forms(), 0, | 128 FetchAvatars(java_infobar_global, GetDelegate()->local_credentials_forms(), 0, |
126 request_context); | 129 request_context); |
127 FetchAvatars( | 130 FetchAvatars( |
128 java_infobar_global, GetDelegate()->federated_credentials_forms(), | 131 java_infobar_global, GetDelegate()->federated_credentials_forms(), |
(...skipping 17 matching lines...) Expand all Loading... | |
146 return; // We're closing; don't call anything, it might access the owner. | 149 return; // We're closing; don't call anything, it might access the owner. |
147 GetDelegate()->ChooseCredential( | 150 GetDelegate()->ChooseCredential( |
148 -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); | 151 -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); |
149 RemoveSelf(); | 152 RemoveSelf(); |
150 } | 153 } |
151 | 154 |
152 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() { | 155 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() { |
153 return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); | 156 return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); |
154 } | 157 } |
155 | 158 |
159 void AccountChooserInfoBar::SetJavaInfoBar( | |
160 const base::android::JavaRef<jobject>& java_info_bar) { | |
161 InfoBarAndroid::SetJavaInfoBar(java_info_bar); | |
162 JNIEnv* env = base::android::AttachCurrentThread(); | |
163 Java_AccountChooserInfoBar_setNativePtr(env, java_info_bar.obj(), | |
164 reinterpret_cast<intptr_t>(this)); | |
165 } | |
166 | |
156 bool RegisterAccountChooserInfoBar(JNIEnv* env) { | 167 bool RegisterAccountChooserInfoBar(JNIEnv* env) { |
157 return RegisterNativesImpl(env); | 168 return RegisterNativesImpl(env); |
158 } | 169 } |
OLD | NEW |