| OLD | NEW |
| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace | 177 } // namespace |
| 178 | 178 |
| 179 | 179 |
| 180 // static | 180 // static |
| 181 base::WeakPtr<AutofillDialogController> AutofillDialogControllerAndroid::Create( | 181 base::WeakPtr<AutofillDialogController> AutofillDialogControllerAndroid::Create( |
| 182 content::WebContents* contents, | 182 content::WebContents* contents, |
| 183 const FormData& form_structure, | 183 const FormData& form_structure, |
| 184 const GURL& source_url, | 184 const GURL& source_url, |
| 185 const AutofillManagerDelegate::ResultCallback& callback) { | 185 const AutofillClient::ResultCallback& callback) { |
| 186 // AutofillDialogControllerAndroid owns itself. | 186 // AutofillDialogControllerAndroid owns itself. |
| 187 AutofillDialogControllerAndroid* autofill_dialog_controller = | 187 AutofillDialogControllerAndroid* autofill_dialog_controller = |
| 188 new AutofillDialogControllerAndroid(contents, | 188 new AutofillDialogControllerAndroid(contents, |
| 189 form_structure, | 189 form_structure, |
| 190 source_url, | 190 source_url, |
| 191 callback); | 191 callback); |
| 192 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); | 192 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 #if defined(ENABLE_AUTOFILL_DIALOG) | 195 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 196 // static | 196 // static |
| 197 base::WeakPtr<AutofillDialogController> | 197 base::WeakPtr<AutofillDialogController> |
| 198 AutofillDialogController::Create( | 198 AutofillDialogController::Create( |
| 199 content::WebContents* contents, | 199 content::WebContents* contents, |
| 200 const FormData& form_structure, | 200 const FormData& form_structure, |
| 201 const GURL& source_url, | 201 const GURL& source_url, |
| 202 const AutofillManagerDelegate::ResultCallback& callback) { | 202 const AutofillClient::ResultCallback& callback) { |
| 203 return AutofillDialogControllerAndroid::Create(contents, | 203 return AutofillDialogControllerAndroid::Create(contents, |
| 204 form_structure, | 204 form_structure, |
| 205 source_url, | 205 source_url, |
| 206 callback); | 206 callback); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // static | 209 // static |
| 210 void AutofillDialogController::RegisterPrefs(PrefRegistrySimple* registry) {} | 210 void AutofillDialogController::RegisterPrefs(PrefRegistrySimple* registry) {} |
| 211 | 211 |
| 212 // static | 212 // static |
| (...skipping 24 matching lines...) Expand all Loading... |
| 237 // access checks. | 237 // access checks. |
| 238 const GURL& current_url = contents_->GetLastCommittedURL(); | 238 const GURL& current_url = contents_->GetLastCommittedURL(); |
| 239 invoked_from_same_origin_ = | 239 invoked_from_same_origin_ = |
| 240 current_url.GetOrigin() == source_url_.GetOrigin(); | 240 current_url.GetOrigin() == source_url_.GetOrigin(); |
| 241 | 241 |
| 242 // Fail if the dialog factory (e.g. SDK) doesn't support cross-origin calls. | 242 // Fail if the dialog factory (e.g. SDK) doesn't support cross-origin calls. |
| 243 if (!Java_AutofillDialogControllerAndroid_isDialogAllowed( | 243 if (!Java_AutofillDialogControllerAndroid_isDialogAllowed( |
| 244 env, | 244 env, |
| 245 invoked_from_same_origin_)) { | 245 invoked_from_same_origin_)) { |
| 246 callback_.Run( | 246 callback_.Run( |
| 247 AutofillManagerDelegate::AutocompleteResultErrorDisabled, | 247 AutofillClient::AutocompleteResultErrorDisabled, |
| 248 base::ASCIIToUTF16("Cross-origin form invocations are not supported."), | 248 base::ASCIIToUTF16("Cross-origin form invocations are not supported."), |
| 249 NULL); | 249 NULL); |
| 250 delete this; | 250 delete this; |
| 251 return; | 251 return; |
| 252 } | 252 } |
| 253 | 253 |
| 254 // Determine what field types should be included in the dialog. | 254 // Determine what field types should be included in the dialog. |
| 255 bool has_types = false; | 255 bool has_types = false; |
| 256 bool has_sections = false; | 256 bool has_sections = false; |
| 257 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 257 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
| 258 &has_types, &has_sections); | 258 &has_types, &has_sections); |
| 259 | 259 |
| 260 // Fail if the author didn't specify autocomplete types, or | 260 // Fail if the author didn't specify autocomplete types, or |
| 261 // if the dialog shouldn't be shown in a given circumstances. | 261 // if the dialog shouldn't be shown in a given circumstances. |
| 262 if (!has_types) { | 262 if (!has_types) { |
| 263 callback_.Run( | 263 callback_.Run( |
| 264 AutofillManagerDelegate::AutocompleteResultErrorDisabled, | 264 AutofillClient::AutocompleteResultErrorDisabled, |
| 265 base::ASCIIToUTF16("Form is missing autocomplete attributes."), | 265 base::ASCIIToUTF16("Form is missing autocomplete attributes."), |
| 266 NULL); | 266 NULL); |
| 267 delete this; | 267 delete this; |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Fail if the author didn't ask for at least some kind of credit card | 271 // Fail if the author didn't ask for at least some kind of credit card |
| 272 // information. | 272 // information. |
| 273 bool has_credit_card_field = false; | 273 bool has_credit_card_field = false; |
| 274 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 274 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
| 275 AutofillType type = form_structure_.field(i)->Type(); | 275 AutofillType type = form_structure_.field(i)->Type(); |
| 276 if (type.html_type() != HTML_TYPE_UNKNOWN && type.group() == CREDIT_CARD) { | 276 if (type.html_type() != HTML_TYPE_UNKNOWN && type.group() == CREDIT_CARD) { |
| 277 has_credit_card_field = true; | 277 has_credit_card_field = true; |
| 278 break; | 278 break; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 if (!has_credit_card_field) { | 282 if (!has_credit_card_field) { |
| 283 callback_.Run( | 283 callback_.Run( |
| 284 AutofillManagerDelegate::AutocompleteResultErrorDisabled, | 284 AutofillClient::AutocompleteResultErrorDisabled, |
| 285 base::ASCIIToUTF16("Form is not a payment form (must contain " | 285 base::ASCIIToUTF16("Form is not a payment form (must contain " |
| 286 "some autocomplete=\"cc-*\" fields). "), | 286 "some autocomplete=\"cc-*\" fields). "), |
| 287 NULL); | 287 NULL); |
| 288 delete this; | 288 delete this; |
| 289 return; | 289 return; |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Log any relevant UI metrics and security exceptions. | 292 // Log any relevant UI metrics and security exceptions. |
| 293 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN); | 293 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN); |
| 294 | 294 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 425 |
| 426 // static | 426 // static |
| 427 bool AutofillDialogControllerAndroid:: | 427 bool AutofillDialogControllerAndroid:: |
| 428 RegisterAutofillDialogControllerAndroid(JNIEnv* env) { | 428 RegisterAutofillDialogControllerAndroid(JNIEnv* env) { |
| 429 return RegisterNativesImpl(env); | 429 return RegisterNativesImpl(env); |
| 430 } | 430 } |
| 431 | 431 |
| 432 void AutofillDialogControllerAndroid::DialogCancel(JNIEnv* env, | 432 void AutofillDialogControllerAndroid::DialogCancel(JNIEnv* env, |
| 433 jobject obj) { | 433 jobject obj) { |
| 434 LogOnCancelMetrics(); | 434 LogOnCancelMetrics(); |
| 435 callback_.Run(AutofillManagerDelegate::AutocompleteResultErrorCancel, | 435 callback_.Run(AutofillClient::AutocompleteResultErrorCancel, |
| 436 base::string16(), | 436 base::string16(), |
| 437 NULL); | 437 NULL); |
| 438 } | 438 } |
| 439 | 439 |
| 440 void AutofillDialogControllerAndroid::DialogContinue( | 440 void AutofillDialogControllerAndroid::DialogContinue( |
| 441 JNIEnv* env, | 441 JNIEnv* env, |
| 442 jobject obj, | 442 jobject obj, |
| 443 jobject wallet, | 443 jobject wallet, |
| 444 jboolean jlast_used_choice_is_autofill, | 444 jboolean jlast_used_choice_is_autofill, |
| 445 jstring jlast_used_account_name, | 445 jstring jlast_used_account_name, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 if (!last_used_card.empty()) | 483 if (!last_used_card.empty()) |
| 484 defaults->SetString(kLastUsedCreditCardGuid, last_used_card); | 484 defaults->SetString(kLastUsedCreditCardGuid, last_used_card); |
| 485 } else { | 485 } else { |
| 486 DLOG(ERROR) << "Failed to save AutofillDialog preferences"; | 486 DLOG(ERROR) << "Failed to save AutofillDialog preferences"; |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 LogOnFinishSubmitMetrics(); | 490 LogOnFinishSubmitMetrics(); |
| 491 | 491 |
| 492 // Callback should be called as late as possible. | 492 // Callback should be called as late as possible. |
| 493 callback_.Run(AutofillManagerDelegate::AutocompleteResultSuccess, | 493 callback_.Run(AutofillClient::AutocompleteResultSuccess, |
| 494 base::string16(), | 494 base::string16(), |
| 495 &form_structure_); | 495 &form_structure_); |
| 496 | 496 |
| 497 // This might delete us. | 497 // This might delete us. |
| 498 Hide(); | 498 Hide(); |
| 499 } | 499 } |
| 500 | 500 |
| 501 AutofillDialogControllerAndroid::AutofillDialogControllerAndroid( | 501 AutofillDialogControllerAndroid::AutofillDialogControllerAndroid( |
| 502 content::WebContents* contents, | 502 content::WebContents* contents, |
| 503 const FormData& form_structure, | 503 const FormData& form_structure, |
| 504 const GURL& source_url, | 504 const GURL& source_url, |
| 505 const AutofillManagerDelegate::ResultCallback& callback) | 505 const AutofillClient::ResultCallback& callback) |
| 506 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 506 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 507 contents_(contents), | 507 contents_(contents), |
| 508 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 508 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 509 form_structure_(form_structure), | 509 form_structure_(form_structure), |
| 510 invoked_from_same_origin_(true), | 510 invoked_from_same_origin_(true), |
| 511 source_url_(source_url), | 511 source_url_(source_url), |
| 512 callback_(callback), | 512 callback_(callback), |
| 513 cares_about_shipping_(true), | 513 cares_about_shipping_(true), |
| 514 weak_ptr_factory_(this), | 514 weak_ptr_factory_(this), |
| 515 was_ui_latency_logged_(false) { | 515 was_ui_latency_logged_(false) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 526 | 526 |
| 527 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { | 527 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { |
| 528 GetMetricLogger().LogDialogUiDuration( | 528 GetMetricLogger().LogDialogUiDuration( |
| 529 base::Time::Now() - dialog_shown_timestamp_, | 529 base::Time::Now() - dialog_shown_timestamp_, |
| 530 AutofillMetrics::DIALOG_CANCELED); | 530 AutofillMetrics::DIALOG_CANCELED); |
| 531 | 531 |
| 532 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); | 532 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); |
| 533 } | 533 } |
| 534 | 534 |
| 535 } // namespace autofill | 535 } // namespace autofill |
| OLD | NEW |