OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_autofill_client.h" | 5 #include "android_webview/native/aw_autofill_client.h" |
6 | 6 |
7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
8 #include "android_webview/browser/aw_content_browser_client.h" | 8 #include "android_webview/browser/aw_content_browser_client.h" |
9 #include "android_webview/browser/aw_form_database_service.h" | 9 #include "android_webview/browser/aw_form_database_service.h" |
10 #include "android_webview/native/aw_contents.h" | 10 #include "android_webview/native/aw_contents.h" |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
13 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "components/autofill/core/browser/autofill_popup_delegate.h" | 15 #include "components/autofill/core/browser/autofill_popup_delegate.h" |
16 #include "components/autofill/core/browser/suggestion.h" | 16 #include "components/autofill/core/browser/suggestion.h" |
17 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 17 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
18 #include "components/autofill/core/common/autofill_pref_names.h" | 18 #include "components/autofill/core/common/autofill_pref_names.h" |
19 #include "components/prefs/pref_registry_simple.h" | 19 #include "components/prefs/pref_registry_simple.h" |
20 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
21 #include "components/prefs/pref_service_factory.h" | 21 #include "components/prefs/pref_service_factory.h" |
22 #include "components/user_prefs/user_prefs.h" | 22 #include "components/user_prefs/user_prefs.h" |
23 #include "content/public/browser/android/content_view_core.h" | |
23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
25 #include "content/public/common/ssl_status.h" | 26 #include "content/public/common/ssl_status.h" |
26 #include "jni/AwAutofillClient_jni.h" | 27 #include "jni/AwAutofillClient_jni.h" |
28 #include "ui/android/view_android.h" | |
27 #include "ui/gfx/geometry/rect_f.h" | 29 #include "ui/gfx/geometry/rect_f.h" |
28 | 30 |
29 using base::android::AttachCurrentThread; | 31 using base::android::AttachCurrentThread; |
30 using base::android::ConvertUTF16ToJavaString; | 32 using base::android::ConvertUTF16ToJavaString; |
31 using base::android::ScopedJavaLocalRef; | 33 using base::android::ScopedJavaLocalRef; |
32 using content::WebContents; | 34 using content::WebContents; |
33 | 35 |
34 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::AwAutofillClient); | 36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::AwAutofillClient); |
35 | 37 |
36 namespace android_webview { | 38 namespace android_webview { |
37 | 39 |
38 // Ownership: The native object is created (if autofill enabled) and owned by | 40 // Ownership: The native object is created (if autofill enabled) and owned by |
39 // AwContents. The native object creates the java peer which handles most | 41 // AwContents. The native object creates the java peer which handles most |
40 // autofill functionality at the java side. The java peer is owned by Java | 42 // autofill functionality at the java side. The java peer is owned by Java |
41 // AwContents. The native object only maintains a weak ref to it. | 43 // AwContents. The native object only maintains a weak ref to it. |
42 AwAutofillClient::AwAutofillClient(WebContents* contents) | 44 AwAutofillClient::AwAutofillClient(WebContents* contents) |
43 : web_contents_(contents), save_form_data_(false) { | 45 : web_contents_(contents), save_form_data_(false) { |
44 JNIEnv* env = AttachCurrentThread(); | 46 JNIEnv* env = AttachCurrentThread(); |
45 ScopedJavaLocalRef<jobject> delegate; | 47 ScopedJavaLocalRef<jobject> delegate; |
46 delegate.Reset( | 48 delegate.Reset( |
47 Java_AwAutofillClient_create(env, reinterpret_cast<intptr_t>(this))); | 49 Java_AwAutofillClient_create(env, reinterpret_cast<intptr_t>(this))); |
48 | 50 |
49 AwContents* aw_contents = AwContents::FromWebContents(web_contents_); | 51 AwContents* aw_contents = AwContents::FromWebContents(web_contents_); |
52 view_android_ = web_contents_->GetContentNativeView(); | |
no sievers
2016/07/18 22:14:16
Sorry, I changed my mind after looking at the auto
Jinsuk Kim
2016/07/19 07:08:39
Done.
| |
50 aw_contents->SetAwAutofillClient(delegate.obj()); | 53 aw_contents->SetAwAutofillClient(delegate.obj()); |
51 java_ref_ = JavaObjectWeakGlobalRef(env, delegate.obj()); | 54 java_ref_ = JavaObjectWeakGlobalRef(env, delegate.obj()); |
52 } | 55 } |
53 | 56 |
54 AwAutofillClient::~AwAutofillClient() { | 57 AwAutofillClient::~AwAutofillClient() { |
55 HideAutofillPopup(); | 58 HideAutofillPopup(); |
56 } | 59 } |
57 | 60 |
58 void AwAutofillClient::SetSaveFormData(bool enabled) { | 61 void AwAutofillClient::SetSaveFormData(bool enabled) { |
59 save_form_data_ = enabled; | 62 save_form_data_ = enabled; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 130 |
128 for (size_t i = 0; i < count; ++i) { | 131 for (size_t i = 0; i < count; ++i) { |
129 ScopedJavaLocalRef<jstring> name = | 132 ScopedJavaLocalRef<jstring> name = |
130 ConvertUTF16ToJavaString(env, suggestions[i].value); | 133 ConvertUTF16ToJavaString(env, suggestions[i].value); |
131 ScopedJavaLocalRef<jstring> label = | 134 ScopedJavaLocalRef<jstring> label = |
132 ConvertUTF16ToJavaString(env, suggestions[i].label); | 135 ConvertUTF16ToJavaString(env, suggestions[i].label); |
133 Java_AwAutofillClient_addToAutofillSuggestionArray( | 136 Java_AwAutofillClient_addToAutofillSuggestionArray( |
134 env, data_array.obj(), i, name.obj(), label.obj(), | 137 env, data_array.obj(), i, name.obj(), label.obj(), |
135 suggestions[i].frontend_id); | 138 suggestions[i].frontend_id); |
136 } | 139 } |
137 | 140 if (!anchor_view_) { |
141 anchor_view_.reset(view_android_->AcquireAnchorView()); | |
142 } | |
no sievers
2016/07/18 22:14:16
I'd handle |anchor_view_.view_.is_null()| here and
Jinsuk Kim
2016/07/19 07:08:39
Done.
| |
143 view_android_->SetAnchorRect(anchor_view_->ref(), element_bounds); | |
138 Java_AwAutofillClient_showAutofillPopup(env, | 144 Java_AwAutofillClient_showAutofillPopup(env, |
139 obj.obj(), | 145 obj.obj(), |
140 element_bounds.x(), | 146 anchor_view_->obj(), |
141 element_bounds.y(), | |
142 element_bounds.width(), | 147 element_bounds.width(), |
143 element_bounds.height(), | |
144 is_rtl, | 148 is_rtl, |
145 data_array.obj()); | 149 data_array.obj()); |
146 } | 150 } |
147 | 151 |
148 void AwAutofillClient::UpdateAutofillPopupDataListValues( | 152 void AwAutofillClient::UpdateAutofillPopupDataListValues( |
149 const std::vector<base::string16>& values, | 153 const std::vector<base::string16>& values, |
150 const std::vector<base::string16>& labels) { | 154 const std::vector<base::string16>& labels) { |
151 // Leaving as an empty method since updating autofill popup window | 155 // Leaving as an empty method since updating autofill popup window |
152 // dynamically does not seem to be a useful feature for android webview. | 156 // dynamically does not seem to be a useful feature for android webview. |
153 // See crrev.com/18102002 if need to implement. | 157 // See crrev.com/18102002 if need to implement. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 !(ssl_status.content_status & | 200 !(ssl_status.content_status & |
197 content::SSLStatus::RAN_INSECURE_CONTENT); | 201 content::SSLStatus::RAN_INSECURE_CONTENT); |
198 } | 202 } |
199 | 203 |
200 bool AwAutofillClient::ShouldShowSigninPromo() { | 204 bool AwAutofillClient::ShouldShowSigninPromo() { |
201 return false; | 205 return false; |
202 } | 206 } |
203 | 207 |
204 void AwAutofillClient::StartSigninFlow() {} | 208 void AwAutofillClient::StartSigninFlow() {} |
205 | 209 |
210 void AwAutofillClient::Dismissed(JNIEnv* env, | |
211 const JavaParamRef<jobject>& obj) { | |
212 if (anchor_view_) { | |
213 anchor_view_.reset(); | |
214 } | |
215 } | |
216 | |
206 void AwAutofillClient::SuggestionSelected(JNIEnv* env, | 217 void AwAutofillClient::SuggestionSelected(JNIEnv* env, |
207 const JavaParamRef<jobject>& object, | 218 const JavaParamRef<jobject>& object, |
208 jint position) { | 219 jint position) { |
209 if (delegate_) { | 220 if (delegate_) { |
210 delegate_->DidAcceptSuggestion(suggestions_[position].value, | 221 delegate_->DidAcceptSuggestion(suggestions_[position].value, |
211 suggestions_[position].frontend_id, | 222 suggestions_[position].frontend_id, |
212 position); | 223 position); |
213 } | 224 } |
214 } | 225 } |
215 | 226 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 | 263 |
253 void AwAutofillClient::ScanCreditCard(const CreditCardScanCallback& callback) { | 264 void AwAutofillClient::ScanCreditCard(const CreditCardScanCallback& callback) { |
254 NOTIMPLEMENTED(); | 265 NOTIMPLEMENTED(); |
255 } | 266 } |
256 | 267 |
257 bool RegisterAwAutofillClient(JNIEnv* env) { | 268 bool RegisterAwAutofillClient(JNIEnv* env) { |
258 return RegisterNativesImpl(env); | 269 return RegisterNativesImpl(env); |
259 } | 270 } |
260 | 271 |
261 } // namespace android_webview | 272 } // namespace android_webview |
OLD | NEW |