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

Side by Side Diff: chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc

Issue 258543005: [rAc Android] Refuse to show rAc dialog if cc info is not requested (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase... Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillDialogControllerTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/autofill_dialog_controller_android. h" 5 #include "chrome/browser/ui/android/autofill/autofill_dialog_controller_android. h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return; 183 return;
184 184
185 JNIEnv* env = base::android::AttachCurrentThread(); 185 JNIEnv* env = base::android::AttachCurrentThread();
186 Java_AutofillDialogControllerAndroid_onDestroy(env, java_object_.obj()); 186 Java_AutofillDialogControllerAndroid_onDestroy(env, java_object_.obj());
187 } 187 }
188 188
189 void AutofillDialogControllerAndroid::Show() { 189 void AutofillDialogControllerAndroid::Show() {
190 JNIEnv* env = base::android::AttachCurrentThread(); 190 JNIEnv* env = base::android::AttachCurrentThread();
191 dialog_shown_timestamp_ = base::Time::Now(); 191 dialog_shown_timestamp_ = base::Time::Now();
192 192
193 // The Autofill dialog is shown in response to a message from the renderer and
194 // as such, it can only be made in the context of the current document. A call
195 // to GetActiveEntry would return a pending entry, if there was one, which
196 // would be a security bug. Therefore, we use the last committed URL for the
197 // access checks.
193 const GURL& current_url = contents_->GetLastCommittedURL(); 198 const GURL& current_url = contents_->GetLastCommittedURL();
194 invoked_from_same_origin_ = 199 invoked_from_same_origin_ =
195 current_url.GetOrigin() == source_url_.GetOrigin(); 200 current_url.GetOrigin() == source_url_.GetOrigin();
196 201
202 // Fail if the dialog factory (e.g. SDK) doesn't support cross-origin calls.
203 if (!Java_AutofillDialogControllerAndroid_isDialogAllowed(
204 env,
205 invoked_from_same_origin_)) {
206 callback_.Run(
207 AutofillManagerDelegate::AutocompleteResultErrorDisabled,
208 base::ASCIIToUTF16("Cross-origin form invocations are not supported."),
209 NULL);
210 delete this;
211 return;
212 }
213
197 // Determine what field types should be included in the dialog. 214 // Determine what field types should be included in the dialog.
198 bool has_types = false; 215 bool has_types = false;
199 bool has_sections = false; 216 bool has_sections = false;
200 form_structure_.ParseFieldTypesFromAutocompleteAttributes( 217 form_structure_.ParseFieldTypesFromAutocompleteAttributes(
201 &has_types, &has_sections); 218 &has_types, &has_sections);
202 219
203 // Fail if the author didn't specify autocomplete types, or 220 // Fail if the author didn't specify autocomplete types, or
204 // if the dialog shouldn't be shown in a given circumstances. 221 // if the dialog shouldn't be shown in a given circumstances.
205 if (!has_types || 222 if (!has_types) {
206 !Java_AutofillDialogControllerAndroid_isDialogAllowed(
207 env,
208 invoked_from_same_origin_)) {
209 callback_.Run( 223 callback_.Run(
210 AutofillManagerDelegate::AutocompleteResultErrorDisabled, 224 AutofillManagerDelegate::AutocompleteResultErrorDisabled,
211 base::ASCIIToUTF16("Form is missing autocomplete attributes."), 225 base::ASCIIToUTF16("Form is missing autocomplete attributes."),
212 NULL); 226 NULL);
213 delete this; 227 delete this;
214 return; 228 return;
215 } 229 }
216 230
231 // Fail if the author didn't ask for at least some kind of credit card
232 // information.
233 bool has_credit_card_field = false;
234 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
235 AutofillType type = form_structure_.field(i)->Type();
236 if (type.html_type() != HTML_TYPE_UNKNOWN && type.group() == CREDIT_CARD) {
237 has_credit_card_field = true;
238 break;
239 }
240 }
241
242 if (!has_credit_card_field) {
243 callback_.Run(
244 AutofillManagerDelegate::AutocompleteResultErrorDisabled,
245 base::ASCIIToUTF16("Form is not a payment form (must contain "
246 "some autocomplete=\"cc-*\" fields). "),
247 NULL);
248 delete this;
249 return;
250 }
251
217 // Log any relevant UI metrics and security exceptions. 252 // Log any relevant UI metrics and security exceptions.
218 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN); 253 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN);
219 254
220 GetMetricLogger().LogDialogSecurityMetric( 255 GetMetricLogger().LogDialogSecurityMetric(
221 AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN); 256 AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN);
222 257
223 if (!invoked_from_same_origin_) { 258 if (!invoked_from_same_origin_) {
224 GetMetricLogger().LogDialogSecurityMetric( 259 GetMetricLogger().LogDialogSecurityMetric(
225 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); 260 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME);
226 } 261 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 defaults->SetString(kLastUsedAccountName, last_used_account_name); 406 defaults->SetString(kLastUsedAccountName, last_used_account_name);
372 defaults->SetBoolean(kLastUsedChoiceIsAutofill, 407 defaults->SetBoolean(kLastUsedChoiceIsAutofill,
373 last_used_choice_is_autofill); 408 last_used_choice_is_autofill);
374 if (!last_used_billing.empty()) 409 if (!last_used_billing.empty())
375 defaults->SetString(kLastUsedBillingAddressGuid, last_used_billing); 410 defaults->SetString(kLastUsedBillingAddressGuid, last_used_billing);
376 if (!last_used_shipping.empty()) 411 if (!last_used_shipping.empty())
377 defaults->SetString(kLastUsedShippingAddressGuid, last_used_shipping); 412 defaults->SetString(kLastUsedShippingAddressGuid, last_used_shipping);
378 if (!last_used_card.empty()) 413 if (!last_used_card.empty())
379 defaults->SetString(kLastUsedCreditCardGuid, last_used_card); 414 defaults->SetString(kLastUsedCreditCardGuid, last_used_card);
380 } else { 415 } else {
381 LOG(ERROR) << "Failed to save AutofillDialog preferences"; 416 DLOG(ERROR) << "Failed to save AutofillDialog preferences";
382 } 417 }
383 } 418 }
384 419
385 LogOnFinishSubmitMetrics(); 420 LogOnFinishSubmitMetrics();
386 421
387 // Callback should be called as late as possible. 422 // Callback should be called as late as possible.
388 callback_.Run(AutofillManagerDelegate::AutocompleteResultSuccess, 423 callback_.Run(AutofillManagerDelegate::AutocompleteResultSuccess,
389 base::string16(), 424 base::string16(),
390 &form_structure_); 425 &form_structure_);
391 426
(...skipping 29 matching lines...) Expand all
421 456
422 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { 457 void AutofillDialogControllerAndroid::LogOnCancelMetrics() {
423 GetMetricLogger().LogDialogUiDuration( 458 GetMetricLogger().LogDialogUiDuration(
424 base::Time::Now() - dialog_shown_timestamp_, 459 base::Time::Now() - dialog_shown_timestamp_,
425 AutofillMetrics::DIALOG_CANCELED); 460 AutofillMetrics::DIALOG_CANCELED);
426 461
427 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); 462 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED);
428 } 463 }
429 464
430 } // namespace autofill 465 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillDialogControllerTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698