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/browser/aw_pref_store.h" | 10 #include "android_webview/browser/aw_pref_store.h" |
11 #include "android_webview/native/aw_contents.h" | 11 #include "android_webview/native/aw_contents.h" |
12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
18 #include "base/prefs/pref_service_factory.h" | 18 #include "base/prefs/pref_service_factory.h" |
19 #include "components/autofill/core/browser/autofill_popup_delegate.h" | 19 #include "components/autofill/core/browser/autofill_popup_delegate.h" |
| 20 #include "components/autofill/core/browser/suggestion.h" |
20 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 21 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
21 #include "components/autofill/core/common/autofill_pref_names.h" | 22 #include "components/autofill/core/common/autofill_pref_names.h" |
22 #include "components/user_prefs/user_prefs.h" | 23 #include "components/user_prefs/user_prefs.h" |
23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
24 #include "jni/AwAutofillClient_jni.h" | 25 #include "jni/AwAutofillClient_jni.h" |
25 | 26 |
26 using base::android::AttachCurrentThread; | 27 using base::android::AttachCurrentThread; |
27 using base::android::ConvertUTF16ToJavaString; | 28 using base::android::ConvertUTF16ToJavaString; |
28 using base::android::ScopedJavaLocalRef; | 29 using base::android::ScopedJavaLocalRef; |
29 using content::WebContents; | 30 using content::WebContents; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 AwAutofillClient::GetDatabase() { | 74 AwAutofillClient::GetDatabase() { |
74 android_webview::AwFormDatabaseService* service = | 75 android_webview::AwFormDatabaseService* service = |
75 static_cast<android_webview::AwBrowserContext*>( | 76 static_cast<android_webview::AwBrowserContext*>( |
76 web_contents_->GetBrowserContext())->GetFormDatabaseService(); | 77 web_contents_->GetBrowserContext())->GetFormDatabaseService(); |
77 return service->get_autofill_webdata_service(); | 78 return service->get_autofill_webdata_service(); |
78 } | 79 } |
79 | 80 |
80 void AwAutofillClient::ShowAutofillPopup( | 81 void AwAutofillClient::ShowAutofillPopup( |
81 const gfx::RectF& element_bounds, | 82 const gfx::RectF& element_bounds, |
82 base::i18n::TextDirection text_direction, | 83 base::i18n::TextDirection text_direction, |
83 const std::vector<base::string16>& values, | 84 const std::vector<autofill::Suggestion>& suggestions, |
84 const std::vector<base::string16>& labels, | |
85 const std::vector<base::string16>& icons, | |
86 const std::vector<int>& identifiers, | |
87 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) { | 85 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) { |
88 values_ = values; | 86 suggestions_ = suggestions; |
89 identifiers_ = identifiers; | |
90 delegate_ = delegate; | 87 delegate_ = delegate; |
91 | 88 |
92 // Convert element_bounds to be in screen space. | 89 // Convert element_bounds to be in screen space. |
93 gfx::Rect client_area = web_contents_->GetContainerBounds(); | 90 gfx::Rect client_area = web_contents_->GetContainerBounds(); |
94 gfx::RectF element_bounds_in_screen_space = | 91 gfx::RectF element_bounds_in_screen_space = |
95 element_bounds + client_area.OffsetFromOrigin(); | 92 element_bounds + client_area.OffsetFromOrigin(); |
96 | 93 |
97 ShowAutofillPopupImpl(element_bounds_in_screen_space, | 94 ShowAutofillPopupImpl(element_bounds_in_screen_space, |
98 text_direction == base::i18n::RIGHT_TO_LEFT, | 95 text_direction == base::i18n::RIGHT_TO_LEFT, |
99 values, | 96 suggestions); |
100 labels, | |
101 identifiers); | |
102 } | 97 } |
103 | 98 |
104 void AwAutofillClient::ShowAutofillPopupImpl( | 99 void AwAutofillClient::ShowAutofillPopupImpl( |
105 const gfx::RectF& element_bounds, | 100 const gfx::RectF& element_bounds, |
106 bool is_rtl, | 101 bool is_rtl, |
107 const std::vector<base::string16>& values, | 102 const std::vector<autofill::Suggestion>& suggestions) { |
108 const std::vector<base::string16>& labels, | |
109 const std::vector<int>& identifiers) { | |
110 JNIEnv* env = AttachCurrentThread(); | 103 JNIEnv* env = AttachCurrentThread(); |
111 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 104 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
112 if (obj.is_null()) | 105 if (obj.is_null()) |
113 return; | 106 return; |
114 | 107 |
115 // We need an array of AutofillSuggestion. | 108 // We need an array of AutofillSuggestion. |
116 size_t count = values.size(); | 109 size_t count = suggestions.size(); |
117 | 110 |
118 ScopedJavaLocalRef<jobjectArray> data_array = | 111 ScopedJavaLocalRef<jobjectArray> data_array = |
119 Java_AwAutofillClient_createAutofillSuggestionArray(env, count); | 112 Java_AwAutofillClient_createAutofillSuggestionArray(env, count); |
120 | 113 |
121 for (size_t i = 0; i < count; ++i) { | 114 for (size_t i = 0; i < count; ++i) { |
122 ScopedJavaLocalRef<jstring> name = ConvertUTF16ToJavaString(env, values[i]); | 115 ScopedJavaLocalRef<jstring> name = |
| 116 ConvertUTF16ToJavaString(env, suggestions[i].value); |
123 ScopedJavaLocalRef<jstring> label = | 117 ScopedJavaLocalRef<jstring> label = |
124 ConvertUTF16ToJavaString(env, labels[i]); | 118 ConvertUTF16ToJavaString(env, suggestions[i].label); |
125 Java_AwAutofillClient_addToAutofillSuggestionArray( | 119 Java_AwAutofillClient_addToAutofillSuggestionArray( |
126 env, data_array.obj(), i, name.obj(), label.obj(), identifiers[i]); | 120 env, data_array.obj(), i, name.obj(), label.obj(), |
| 121 suggestions[i].frontend_id); |
127 } | 122 } |
128 | 123 |
129 Java_AwAutofillClient_showAutofillPopup(env, | 124 Java_AwAutofillClient_showAutofillPopup(env, |
130 obj.obj(), | 125 obj.obj(), |
131 element_bounds.x(), | 126 element_bounds.x(), |
132 element_bounds.y(), | 127 element_bounds.y(), |
133 element_bounds.width(), | 128 element_bounds.width(), |
134 element_bounds.height(), | 129 element_bounds.height(), |
135 is_rtl, | 130 is_rtl, |
136 data_array.obj()); | 131 data_array.obj()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 const base::string16& profile_full_name) { | 163 const base::string16& profile_full_name) { |
169 } | 164 } |
170 | 165 |
171 void AwAutofillClient::OnFirstUserGestureObserved() { | 166 void AwAutofillClient::OnFirstUserGestureObserved() { |
172 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
173 } | 168 } |
174 | 169 |
175 void AwAutofillClient::SuggestionSelected(JNIEnv* env, | 170 void AwAutofillClient::SuggestionSelected(JNIEnv* env, |
176 jobject object, | 171 jobject object, |
177 jint position) { | 172 jint position) { |
178 if (delegate_) | 173 if (delegate_) { |
179 delegate_->DidAcceptSuggestion(values_[position], identifiers_[position]); | 174 delegate_->DidAcceptSuggestion(suggestions_[position].value, |
| 175 suggestions_[position].frontend_id); |
| 176 } |
180 } | 177 } |
181 | 178 |
182 void AwAutofillClient::HideRequestAutocompleteDialog() { | 179 void AwAutofillClient::HideRequestAutocompleteDialog() { |
183 NOTIMPLEMENTED(); | 180 NOTIMPLEMENTED(); |
184 } | 181 } |
185 | 182 |
186 void AwAutofillClient::ShowAutofillSettings() { | 183 void AwAutofillClient::ShowAutofillSettings() { |
187 NOTIMPLEMENTED(); | 184 NOTIMPLEMENTED(); |
188 } | 185 } |
189 | 186 |
(...skipping 19 matching lines...) Expand all Loading... |
209 const GURL& source_url, | 206 const GURL& source_url, |
210 const ResultCallback& callback) { | 207 const ResultCallback& callback) { |
211 NOTIMPLEMENTED(); | 208 NOTIMPLEMENTED(); |
212 } | 209 } |
213 | 210 |
214 bool RegisterAwAutofillClient(JNIEnv* env) { | 211 bool RegisterAwAutofillClient(JNIEnv* env) { |
215 return RegisterNativesImpl(env); | 212 return RegisterNativesImpl(env); |
216 } | 213 } |
217 | 214 |
218 } // namespace android_webview | 215 } // namespace android_webview |
OLD | NEW |