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

Side by Side Diff: android_webview/native/aw_autofill_manager_delegate.cc

Issue 16212007: Implement the autofill UI for chromium powered android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue15097004
Patch Set: convert NOTREACHED to NOTIMPLEMENTED Created 7 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "android_webview/native/aw_autofill_manager_delegate.h"
6
7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_content_browser_client.h"
9 #include "android_webview/browser/aw_pref_store.h"
10 #include "android_webview/native/aw_contents.h"
11 #include "base/android/jni_android.h"
12 #include "base/android/jni_string.h"
13 #include "base/android/scoped_java_ref.h"
14 #include "base/logging.h"
15 #include "base/prefs/pref_registry_simple.h"
16 #include "base/prefs/pref_service.h"
17 #include "base/prefs/pref_service_builder.h"
18 #include "components/autofill/content/browser/autocheckout/whitelist_manager.h"
19 #include "components/autofill/core/browser/autofill_popup_delegate.h"
20 #include "components/autofill/core/common/autofill_pref_names.h"
21 #include "components/user_prefs/user_prefs.h"
22 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_contents_view.h"
24 #include "jni/AwAutofillManagerDelegate_jni.h"
25
26 using base::android::AttachCurrentThread;
27 using base::android::ConvertUTF16ToJavaString;
28 using base::android::ScopedJavaLocalRef;
29 using content::WebContents;
30
31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::AwAutofillManagerDelegate);
32
33 namespace android_webview {
34
35 // Ownership: The native object is created (if autofill enabled) and owned by
36 // AwContents. The native object creates the java peer which handles most
37 // autofill functionality at the java side. The java peer is owned by Java
38 // AwContents. The native object only maintains a weak ref to it.
39 AwAutofillManagerDelegate::AwAutofillManagerDelegate(WebContents* contents)
40 : web_contents_(contents),
41 save_form_data_(false) {
42 JNIEnv* env = AttachCurrentThread();
43 ScopedJavaLocalRef<jobject> delegate;
44 delegate.Reset(
45 Java_AwAutofillManagerDelegate_create(env, reinterpret_cast<jint>(this)));
46
47 AwContents* aw_contents = AwContents::FromWebContents(web_contents_);
48 aw_contents->SetAwAutofillManagerDelegate(delegate.obj());
49 java_ref_ = JavaObjectWeakGlobalRef(env, delegate.obj());
50 }
51
52 AwAutofillManagerDelegate::~AwAutofillManagerDelegate() {
53 HideAutofillPopup();
54 }
55
56 void AwAutofillManagerDelegate::SetSaveFormData(bool enabled) {
57 save_form_data_ = enabled;
58 }
59
60 bool AwAutofillManagerDelegate::GetSaveFormData() {
61 return save_form_data_;
62 }
63
64 PrefService* AwAutofillManagerDelegate::GetPrefs() {
65 return user_prefs::UserPrefs::Get(
66 AwContentBrowserClient::GetAwBrowserContext());
67 }
68
69 autofill::PersonalDataManager*
70 AwAutofillManagerDelegate::GetPersonalDataManager() {
71 return NULL;
72 }
73
74 autofill::autocheckout::WhitelistManager*
75 AwAutofillManagerDelegate::GetAutocheckoutWhitelistManager() const {
76 return NULL;
77 }
78
79 void AwAutofillManagerDelegate::ShowAutofillPopup(
80 const gfx::RectF& element_bounds,
81 base::i18n::TextDirection text_direction,
82 const std::vector<string16>& values,
83 const std::vector<string16>& labels,
84 const std::vector<string16>& icons,
85 const std::vector<int>& identifiers,
86 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) {
87
88 values_ = values;
89 identifiers_ = identifiers;
90 delegate_ = delegate;
91
92 // Convert element_bounds to be in screen space.
93 gfx::Rect client_area;
94 web_contents_->GetView()->GetContainerBounds(&client_area);
95 gfx::RectF element_bounds_in_screen_space =
96 element_bounds + client_area.OffsetFromOrigin();
97
98 ShowAutofillPopupImpl(element_bounds_in_screen_space,
99 values,
100 labels,
101 identifiers);
102 }
103
104 void AwAutofillManagerDelegate::ShowAutofillPopupImpl(
105 const gfx::RectF& element_bounds,
106 const std::vector<string16>& values,
107 const std::vector<string16>& labels,
108 const std::vector<int>& identifiers) {
109 JNIEnv* env = AttachCurrentThread();
110 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
111 if (obj.is_null())
112 return;
113
114 // We need an array of AutofillSuggestion.
115 size_t count = values.size();
116
117 ScopedJavaLocalRef<jobjectArray> data_array =
118 Java_AwAutofillManagerDelegate_createAutofillSuggestionArray(env, count);
119
120 for (size_t i = 0; i < count; ++i) {
121 ScopedJavaLocalRef<jstring> name = ConvertUTF16ToJavaString(env, values[i]);
122 ScopedJavaLocalRef<jstring> label =
123 ConvertUTF16ToJavaString(env, labels[i]);
124 Java_AwAutofillManagerDelegate_addToAutofillSuggestionArray(
125 env,
126 data_array.obj(),
127 i,
128 name.obj(),
129 label.obj(),
130 identifiers[i]);
131 }
132
133 Java_AwAutofillManagerDelegate_showAutofillPopup(
134 env,
135 obj.obj(),
136 element_bounds.x(),
137 element_bounds.y(), element_bounds.width(),
138 element_bounds.height(), data_array.obj());
139 }
140
141 void AwAutofillManagerDelegate::HideAutofillPopup() {
142 JNIEnv* env = AttachCurrentThread();
143 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
144 if (obj.is_null())
145 return;
146 delegate_.reset();
147 Java_AwAutofillManagerDelegate_hideAutofillPopup(env, obj.obj());
148 }
149
150 bool AwAutofillManagerDelegate::IsAutocompleteEnabled() {
151 return GetSaveFormData();
152 }
153
154 void AwAutofillManagerDelegate::SuggestionSelected(JNIEnv* env,
155 jobject object,
156 jint position) {
157 if (delegate_)
158 delegate_->DidAcceptSuggestion(values_[position], identifiers_[position]);
159 }
160
161 void AwAutofillManagerDelegate::HideRequestAutocompleteDialog() {
162 NOTIMPLEMENTED();
163 }
164
165 void AwAutofillManagerDelegate::OnAutocheckoutError() {
166 NOTIMPLEMENTED();
167 }
168
169 void AwAutofillManagerDelegate::OnAutocheckoutSuccess() {
170 NOTIMPLEMENTED();
171 }
172
173 void AwAutofillManagerDelegate::ShowAutofillSettings() {
174 NOTIMPLEMENTED();
175 }
176
177 void AwAutofillManagerDelegate::ConfirmSaveCreditCard(
178 const autofill::AutofillMetrics& metric_logger,
179 const autofill::CreditCard& credit_card,
180 const base::Closure& save_card_callback) {
181 NOTIMPLEMENTED();
182 }
183
184 void AwAutofillManagerDelegate::ShowAutocheckoutBubble(
185 const gfx::RectF& bounding_box,
186 bool is_google_user,
187 const base::Callback<void(bool)>& callback) {
188 NOTIMPLEMENTED();
189 }
190
191 void AwAutofillManagerDelegate::HideAutocheckoutBubble() {
192 NOTIMPLEMENTED();
193 }
194
195 void AwAutofillManagerDelegate::ShowRequestAutocompleteDialog(
196 const autofill::FormData& form,
197 const GURL& source_url,
198 autofill::DialogType dialog_type,
199 const base::Callback<void(const autofill::FormStructure*,
200 const std::string&)>& callback) {
201 NOTIMPLEMENTED();
202 }
203
204 void AwAutofillManagerDelegate::AddAutocheckoutStep(
205 autofill::AutocheckoutStepType step_type) {
206 NOTIMPLEMENTED();
207 }
208
209 void AwAutofillManagerDelegate::UpdateAutocheckoutStep(
210 autofill::AutocheckoutStepType step_type,
211 autofill::AutocheckoutStepStatus step_status) {
212 NOTIMPLEMENTED();
213 }
214
215 bool RegisterAwAutofillManagerDelegate(JNIEnv* env) {
216 return RegisterNativesImpl(env) >= 0;
217 }
218
219 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_autofill_manager_delegate.h ('k') | android_webview/native/aw_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698