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

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

Issue 23537014: rAc: Get rid of dialog type in rAc, there is only one type left now. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 } // namespace 140 } // namespace
141 141
142 142
143 // static 143 // static
144 base::WeakPtr<AutofillDialogController> AutofillDialogControllerAndroid::Create( 144 base::WeakPtr<AutofillDialogController> AutofillDialogControllerAndroid::Create(
145 content::WebContents* contents, 145 content::WebContents* contents,
146 const FormData& form_structure, 146 const FormData& form_structure,
147 const GURL& source_url, 147 const GURL& source_url,
148 const DialogType dialog_type,
149 const base::Callback<void(const FormStructure*, 148 const base::Callback<void(const FormStructure*,
150 const std::string&)>& callback) { 149 const std::string&)>& callback) {
151 // AutofillDialogControllerAndroid owns itself. 150 // AutofillDialogControllerAndroid owns itself.
152 AutofillDialogControllerAndroid* autofill_dialog_controller = 151 AutofillDialogControllerAndroid* autofill_dialog_controller =
153 new AutofillDialogControllerAndroid(contents, 152 new AutofillDialogControllerAndroid(contents,
154 form_structure, 153 form_structure,
155 source_url, 154 source_url,
156 dialog_type,
157 callback); 155 callback);
158 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); 156 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr();
159 } 157 }
160 158
161 // static 159 // static
162 void AutofillDialogControllerAndroid::RegisterProfilePrefs( 160 void AutofillDialogControllerAndroid::RegisterProfilePrefs(
163 user_prefs::PrefRegistrySyncable* registry) { 161 user_prefs::PrefRegistrySyncable* registry) {
164 registry->RegisterDictionaryPref( 162 registry->RegisterDictionaryPref(
165 ::prefs::kAutofillDialogDefaults, 163 ::prefs::kAutofillDialogDefaults,
166 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 164 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
167 } 165 }
168 166
169 // static 167 // static
170 base::WeakPtr<AutofillDialogController> 168 base::WeakPtr<AutofillDialogController>
171 AutofillDialogController::Create( 169 AutofillDialogController::Create(
172 content::WebContents* contents, 170 content::WebContents* contents,
173 const FormData& form_structure, 171 const FormData& form_structure,
174 const GURL& source_url, 172 const GURL& source_url,
175 const DialogType dialog_type,
176 const base::Callback<void(const FormStructure*, 173 const base::Callback<void(const FormStructure*,
177 const std::string&)>& callback) { 174 const std::string&)>& callback) {
178 return AutofillDialogControllerAndroid::Create(contents, 175 return AutofillDialogControllerAndroid::Create(contents,
179 form_structure, 176 form_structure,
180 source_url, 177 source_url,
181 dialog_type,
182 callback); 178 callback);
183 } 179 }
184 180
185 // static 181 // static
186 void AutofillDialogController::RegisterProfilePrefs( 182 void AutofillDialogController::RegisterProfilePrefs(
187 user_prefs::PrefRegistrySyncable* registry) { 183 user_prefs::PrefRegistrySyncable* registry) {
188 AutofillDialogControllerAndroid::RegisterProfilePrefs(registry); 184 AutofillDialogControllerAndroid::RegisterProfilePrefs(registry);
189 } 185 }
190 186
191 AutofillDialogControllerAndroid::~AutofillDialogControllerAndroid() { 187 AutofillDialogControllerAndroid::~AutofillDialogControllerAndroid() {
192 JNIEnv* env = base::android::AttachCurrentThread(); 188 JNIEnv* env = base::android::AttachCurrentThread();
193 Java_AutofillDialogControllerAndroid_onDestroy(env, java_object_.obj()); 189 Java_AutofillDialogControllerAndroid_onDestroy(env, java_object_.obj());
194 } 190 }
195 191
196 void AutofillDialogControllerAndroid::Show() { 192 void AutofillDialogControllerAndroid::Show() {
197 dialog_shown_timestamp_ = base::Time::Now(); 193 dialog_shown_timestamp_ = base::Time::Now();
198 194
199 content::NavigationEntry* entry = contents_->GetController().GetActiveEntry(); 195 content::NavigationEntry* entry = contents_->GetController().GetActiveEntry();
200 const GURL& active_url = entry ? entry->GetURL() : contents_->GetURL(); 196 const GURL& active_url = entry ? entry->GetURL() : contents_->GetURL();
201 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); 197 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin();
202 198
203 // Log any relevant UI metrics and security exceptions. 199 // Log any relevant UI metrics and security exceptions.
204 GetMetricLogger().LogDialogUiEvent( 200 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN);
205 GetDialogType(), AutofillMetrics::DIALOG_UI_SHOWN);
206 201
207 GetMetricLogger().LogDialogSecurityMetric( 202 GetMetricLogger().LogDialogSecurityMetric(
208 GetDialogType(), AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN); 203 AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN);
209 204
210 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) { 205 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) {
211 GetMetricLogger().LogDialogSecurityMetric( 206 GetMetricLogger().LogDialogSecurityMetric(
212 GetDialogType(),
213 AutofillMetrics::SECURITY_METRIC_CREDIT_CARD_OVER_HTTP); 207 AutofillMetrics::SECURITY_METRIC_CREDIT_CARD_OVER_HTTP);
214 } 208 }
215 209
216 if (!invoked_from_same_origin_) { 210 if (!invoked_from_same_origin_) {
217 GetMetricLogger().LogDialogSecurityMetric( 211 GetMetricLogger().LogDialogSecurityMetric(
218 GetDialogType(),
219 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); 212 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME);
220 } 213 }
221 214
222 // Determine what field types should be included in the dialog. 215 // Determine what field types should be included in the dialog.
223 bool has_types = false; 216 bool has_types = false;
224 bool has_sections = false; 217 bool has_sections = false;
225 form_structure_.ParseFieldTypesFromAutocompleteAttributes( 218 form_structure_.ParseFieldTypesFromAutocompleteAttributes(
226 &has_types, &has_sections); 219 &has_types, &has_sections);
227 220
228 // Fail if the author didn't specify autocomplete types. 221 // Fail if the author didn't specify autocomplete types.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 jmerchant_domain.obj())); 313 jmerchant_domain.obj()));
321 } 314 }
322 315
323 void AutofillDialogControllerAndroid::Hide() { 316 void AutofillDialogControllerAndroid::Hide() {
324 // TODO(aruslan): http://crbug.com/177373 Autocheckout. 317 // TODO(aruslan): http://crbug.com/177373 Autocheckout.
325 NOTIMPLEMENTED(); 318 NOTIMPLEMENTED();
326 } 319 }
327 320
328 void AutofillDialogControllerAndroid::TabActivated() {} 321 void AutofillDialogControllerAndroid::TabActivated() {}
329 322
330 DialogType AutofillDialogControllerAndroid::GetDialogType() const {
331 return dialog_type_;
332 }
333
334 // static 323 // static
335 bool AutofillDialogControllerAndroid:: 324 bool AutofillDialogControllerAndroid::
336 RegisterAutofillDialogControllerAndroid(JNIEnv* env) { 325 RegisterAutofillDialogControllerAndroid(JNIEnv* env) {
337 return RegisterNativesImpl(env); 326 return RegisterNativesImpl(env);
338 } 327 }
339 328
340 void AutofillDialogControllerAndroid::DialogCancel(JNIEnv* env, 329 void AutofillDialogControllerAndroid::DialogCancel(JNIEnv* env,
341 jobject obj) { 330 jobject obj) {
342 LogOnCancelMetrics(); 331 LogOnCancelMetrics();
343 callback_.Run(NULL, std::string()); 332 callback_.Run(NULL, std::string());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 LOG(ERROR) << "Failed to save AutofillDialog preferences"; 382 LOG(ERROR) << "Failed to save AutofillDialog preferences";
394 } 383 }
395 } 384 }
396 385
397 LogOnFinishSubmitMetrics(); 386 LogOnFinishSubmitMetrics();
398 387
399 // Callback should be called as late as possible. 388 // Callback should be called as late as possible.
400 callback_.Run(&form_structure_, google_transaction_id); 389 callback_.Run(&form_structure_, google_transaction_id);
401 390
402 // This might delete us. 391 // This might delete us.
403 if (GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) 392 Hide();
404 Hide();
405 } 393 }
406 394
407 AutofillDialogControllerAndroid::AutofillDialogControllerAndroid( 395 AutofillDialogControllerAndroid::AutofillDialogControllerAndroid(
408 content::WebContents* contents, 396 content::WebContents* contents,
409 const FormData& form_structure, 397 const FormData& form_structure,
410 const GURL& source_url, 398 const GURL& source_url,
411 const DialogType dialog_type,
412 const base::Callback<void(const FormStructure*, 399 const base::Callback<void(const FormStructure*,
413 const std::string&)>& callback) 400 const std::string&)>& callback)
414 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), 401 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())),
415 contents_(contents), 402 contents_(contents),
416 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), 403 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN),
417 dialog_type_(dialog_type),
418 form_structure_(form_structure), 404 form_structure_(form_structure),
419 invoked_from_same_origin_(true), 405 invoked_from_same_origin_(true),
420 source_url_(source_url), 406 source_url_(source_url),
421 callback_(callback), 407 callback_(callback),
422 cares_about_shipping_(true), 408 cares_about_shipping_(true),
423 weak_ptr_factory_(this), 409 weak_ptr_factory_(this),
424 was_ui_latency_logged_(false) { 410 was_ui_latency_logged_(false) {
425 DCHECK(!callback_.is_null()); 411 DCHECK(!callback_.is_null());
426 } 412 }
427 413
428 bool AutofillDialogControllerAndroid::RequestingCreditCardInfo() const { 414 bool AutofillDialogControllerAndroid::RequestingCreditCardInfo() const {
429 DCHECK_GT(form_structure_.field_count(), 0U); 415 DCHECK_GT(form_structure_.field_count(), 0U);
430 416
431 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 417 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
432 AutofillType type = form_structure_.field(i)->Type(); 418 AutofillType type = form_structure_.field(i)->Type();
433 if (common::IsCreditCardType(type.GetStorableType())) 419 if (common::IsCreditCardType(type.GetStorableType()))
434 return true; 420 return true;
435 } 421 }
436 422
437 return false; 423 return false;
438 } 424 }
439 425
440 bool AutofillDialogControllerAndroid::TransmissionWillBeSecure() const { 426 bool AutofillDialogControllerAndroid::TransmissionWillBeSecure() const {
441 return source_url_.SchemeIs(content::kHttpsScheme); 427 return source_url_.SchemeIs(content::kHttpsScheme);
442 } 428 }
443 429
444 void AutofillDialogControllerAndroid::LogOnFinishSubmitMetrics() { 430 void AutofillDialogControllerAndroid::LogOnFinishSubmitMetrics() {
445 GetMetricLogger().LogDialogUiDuration( 431 GetMetricLogger().LogDialogUiDuration(
446 base::Time::Now() - dialog_shown_timestamp_, 432 base::Time::Now() - dialog_shown_timestamp_,
447 GetDialogType(),
448 AutofillMetrics::DIALOG_ACCEPTED); 433 AutofillMetrics::DIALOG_ACCEPTED);
449 434
450 GetMetricLogger().LogDialogUiEvent( 435 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_ACCEPTED);
451 GetDialogType(), AutofillMetrics::DIALOG_UI_ACCEPTED);
452 } 436 }
453 437
454 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { 438 void AutofillDialogControllerAndroid::LogOnCancelMetrics() {
455 GetMetricLogger().LogDialogUiDuration( 439 GetMetricLogger().LogDialogUiDuration(
456 base::Time::Now() - dialog_shown_timestamp_, 440 base::Time::Now() - dialog_shown_timestamp_,
457 GetDialogType(),
458 AutofillMetrics::DIALOG_CANCELED); 441 AutofillMetrics::DIALOG_CANCELED);
459 442
460 GetMetricLogger().LogDialogUiEvent( 443 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED);
461 GetDialogType(), AutofillMetrics::DIALOG_UI_CANCELED);
462 } 444 }
463 445
464 } // namespace autofill 446 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698