Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/browser/autocheckout/whitelist_manager.h" | |
| 19 #include "components/autofill/browser/autofill_external_delegate.h" | |
| 20 #include "components/autofill/browser/webdata/autofill_webdata_service.h" | |
| 21 #include "components/autofill/common/autofill_pref_names.h" | |
| 22 #include "components/user_prefs/user_prefs.h" | |
| 23 #include "content/public/browser/web_contents.h" | |
| 24 #include "content/public/browser/web_contents_view.h" | |
| 25 #include "jni/AwAutofillManagerDelegate_jni.h" | |
| 26 | |
| 27 using base::android::AttachCurrentThread; | |
| 28 using base::android::ConvertUTF16ToJavaString; | |
| 29 using base::android::ScopedJavaLocalRef; | |
| 30 using content::WebContents; | |
| 31 | |
| 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::AwAutofillManagerDelegate); | |
| 33 | |
| 34 namespace android_webview { | |
| 35 | |
| 36 // Ownership: The native object is created (if autofill enabled) and owned by | |
| 37 // AwContents. The native object creates the java peer which handles most | |
| 38 // autofill functionality at the java side. The java peer is owned by Java | |
| 39 // AwContents. The native object only maintains a weak ref to it. | |
| 40 AwAutofillManagerDelegate::AwAutofillManagerDelegate(WebContents* contents) | |
| 41 : web_contents_(contents), | |
| 42 save_form_data_(false) { | |
| 43 JNIEnv* env = AttachCurrentThread(); | |
| 44 ScopedJavaLocalRef<jobject> delegate; | |
| 45 delegate.Reset( | |
| 46 Java_AwAutofillManagerDelegate_create(env, reinterpret_cast<jint>(this))); | |
| 47 | |
| 48 AwContents* aw_contents = AwContents::FromWebContents(web_contents_); | |
| 49 if (!aw_contents) | |
| 50 return; | |
|
benm (inactive)
2013/06/17 17:23:17
this seems a bit dodgy... we'll return a half cons
sgurun-gerrit only
2013/06/25 02:44:32
If it is null it will crash anyway. Maybe do no ch
| |
| 51 aw_contents->SetAwAutofillManagerDelegate(delegate.obj()); | |
| 52 java_ref_ = JavaObjectWeakGlobalRef(env, delegate.obj()); | |
| 53 } | |
| 54 | |
| 55 AwAutofillManagerDelegate::~AwAutofillManagerDelegate() { | |
| 56 HideAutofillPopup(); | |
| 57 } | |
| 58 | |
| 59 void AwAutofillManagerDelegate::SetSaveFormData(bool enabled) { | |
| 60 save_form_data_ = enabled; | |
| 61 } | |
| 62 | |
| 63 bool AwAutofillManagerDelegate::GetSaveFormData() { | |
| 64 return save_form_data_; | |
| 65 } | |
| 66 | |
| 67 PrefService* AwAutofillManagerDelegate::GetPrefs() { | |
| 68 return user_prefs::UserPrefs::Get( | |
| 69 AwContentBrowserClient::GetAwBrowserContext()); | |
| 70 } | |
| 71 | |
| 72 autofill::PersonalDataManager* | |
| 73 AwAutofillManagerDelegate::GetPersonalDataManager() { | |
| 74 return NULL; | |
| 75 } | |
| 76 | |
| 77 autofill::autocheckout::WhitelistManager* | |
| 78 AwAutofillManagerDelegate::GetAutocheckoutWhitelistManager() const { | |
| 79 return NULL; | |
| 80 } | |
| 81 | |
| 82 void AwAutofillManagerDelegate::HideRequestAutocompleteDialog() { | |
| 83 } | |
| 84 | |
| 85 void AwAutofillManagerDelegate::OnAutocheckoutError() { | |
| 86 } | |
| 87 | |
| 88 void AwAutofillManagerDelegate::OnAutocheckoutSuccess() { | |
| 89 } | |
| 90 | |
| 91 void AwAutofillManagerDelegate::ShowAutofillSettings() { | |
| 92 } | |
| 93 | |
| 94 void AwAutofillManagerDelegate::ConfirmSaveCreditCard( | |
| 95 const autofill::AutofillMetrics& metric_logger, | |
| 96 const autofill::CreditCard& credit_card, | |
| 97 const base::Closure& save_card_callback) { | |
| 98 } | |
| 99 | |
| 100 void AwAutofillManagerDelegate::ShowAutocheckoutBubble( | |
| 101 const gfx::RectF& bounding_box, | |
| 102 bool is_google_user, | |
| 103 const base::Callback<void(bool)>& callback) { | |
| 104 } | |
| 105 | |
| 106 void AwAutofillManagerDelegate::HideAutocheckoutBubble() { | |
| 107 } | |
| 108 | |
| 109 void AwAutofillManagerDelegate::ShowRequestAutocompleteDialog( | |
| 110 const autofill::FormData& form, | |
| 111 const GURL& source_url, | |
| 112 autofill::DialogType dialog_type, | |
| 113 const base::Callback<void(const autofill::FormStructure*, | |
| 114 const std::string&)>& callback) { | |
| 115 } | |
| 116 | |
| 117 void AwAutofillManagerDelegate::ShowAutofillPopup( | |
| 118 const gfx::RectF& element_bounds, | |
| 119 const std::vector<string16>& values, | |
| 120 const std::vector<string16>& labels, | |
| 121 const std::vector<string16>& icons, | |
| 122 const std::vector<int>& identifiers, | |
| 123 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) { | |
| 124 | |
| 125 values_ = values; | |
|
benm (inactive)
2013/06/17 17:23:17
I think it'd be clearer to move the methods we imp
sgurun-gerrit only
2013/06/25 02:44:32
Done.
| |
| 126 identifiers_ = identifiers; | |
| 127 delegate_ = delegate; | |
| 128 | |
| 129 // Convert element_bounds to be in screen space. | |
| 130 gfx::Rect client_area; | |
| 131 web_contents_->GetView()->GetContainerBounds(&client_area); | |
| 132 gfx::RectF element_bounds_in_screen_space = | |
| 133 element_bounds + client_area.OffsetFromOrigin(); | |
| 134 | |
| 135 ShowAutofillPopupImpl(element_bounds_in_screen_space, | |
| 136 values, | |
| 137 labels, | |
| 138 identifiers); | |
| 139 } | |
| 140 | |
| 141 void AwAutofillManagerDelegate::ShowAutofillPopupImpl( | |
| 142 const gfx::RectF& element_bounds, | |
| 143 const std::vector<string16>& values, | |
| 144 const std::vector<string16>& labels, | |
| 145 const std::vector<int>& identifiers) { | |
| 146 JNIEnv* env = AttachCurrentThread(); | |
| 147 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 148 if (obj.is_null()) | |
| 149 return; | |
| 150 | |
| 151 // We need an array of AutofillSuggestion. | |
| 152 size_t count = values.size(); | |
| 153 | |
| 154 ScopedJavaLocalRef<jobjectArray> data_array = | |
| 155 Java_AwAutofillManagerDelegate_createAutofillSuggestionArray(env, count); | |
| 156 | |
| 157 for (size_t i = 0; i < count; ++i) { | |
| 158 ScopedJavaLocalRef<jstring> name = ConvertUTF16ToJavaString(env, values[i]); | |
| 159 ScopedJavaLocalRef<jstring> label = | |
| 160 ConvertUTF16ToJavaString(env, labels[i]); | |
| 161 Java_AwAutofillManagerDelegate_addToAutofillSuggestionArray( | |
| 162 env, | |
| 163 data_array.obj(), | |
| 164 i, | |
| 165 name.obj(), | |
| 166 label.obj(), | |
| 167 identifiers[i]); | |
| 168 } | |
| 169 | |
| 170 Java_AwAutofillManagerDelegate_showAutofillPopup( | |
| 171 env, | |
| 172 obj.obj(), | |
| 173 element_bounds.x(), | |
| 174 element_bounds.y(), element_bounds.width(), | |
| 175 element_bounds.height(), data_array.obj()); | |
| 176 } | |
| 177 | |
| 178 void AwAutofillManagerDelegate::HideAutofillPopup() { | |
| 179 JNIEnv* env = AttachCurrentThread(); | |
| 180 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 181 if (obj.is_null()) | |
| 182 return; | |
| 183 delegate_.reset(); | |
| 184 Java_AwAutofillManagerDelegate_hideAutofillPopup(env, obj.obj()); | |
| 185 } | |
| 186 | |
| 187 void AwAutofillManagerDelegate::UpdateProgressBar(double value) { | |
| 188 } | |
| 189 | |
| 190 bool AwAutofillManagerDelegate::ShouldIgnoreFormData() { | |
| 191 return web_contents_->GetBrowserContext()->IsOffTheRecord(); | |
| 192 } | |
| 193 | |
| 194 void AwAutofillManagerDelegate::SuggestionSelected(JNIEnv* env, | |
| 195 jobject object, | |
| 196 jint position) { | |
| 197 | |
| 198 if (delegate_) | |
| 199 delegate_->DidAcceptSuggestion(values_[position], identifiers_[position]); | |
| 200 } | |
| 201 | |
| 202 bool RegisterAwAutofillManagerDelegate(JNIEnv* env) { | |
| 203 return RegisterNativesImpl(env) >= 0; | |
| 204 } | |
| 205 | |
| 206 } // namespace android_webview | |
| OLD | NEW |