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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_ANDROID_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_ANDROID_H_
6 #define CHROME_BROWSER_UI_ANDROID_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_ANDROID_H_
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
14 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
20 // This class defines the form-filling host and JNI glue for the Java-side
21 // implementation of the requestAutocomplete dialog.
22 class AutofillDialogControllerAndroid : public AutofillDialogController {
24 // Creates an instance of the AutofillDialogControllerAndroid.
25 static base::WeakPtr<AutofillDialogController> Create(
26 content::WebContents* contents,
27 const FormData& form_structure,
28 const GURL& source_url,
29 const base::Callback<void(const FormStructure*)>& callback);
31 virtual ~AutofillDialogControllerAndroid();
33 // AutofillDialogController implementation:
34 virtual void Show() OVERRIDE;
35 virtual void Hide() OVERRIDE;
36 virtual void TabActivated() OVERRIDE;
38 // JNI bindings for Java-side AutofillDialogDelegate:
39 void DialogCancel(JNIEnv* env, jobject obj);
40 void DialogContinue(JNIEnv* env,
43 jboolean last_used_choice_is_autofill,
44 jstring last_used_account_name,
45 jstring last_used_billing,
46 jstring last_used_shipping,
47 jstring last_used_credit_card);
49 // Establishes JNI bindings.
50 static bool RegisterAutofillDialogControllerAndroid(JNIEnv* env);
53 AutofillDialogControllerAndroid(
54 content::WebContents* contents,
55 const FormData& form_structure,
56 const GURL& source_url,
57 const base::Callback<void(const FormStructure*)>& callback);
59 const AutofillMetrics& GetMetricLogger() const {
60 return metric_logger_;
63 // Logs metrics when the dialog is submitted.
64 void LogOnFinishSubmitMetrics();
66 // Logs metrics when the dialog is canceled.
67 void LogOnCancelMetrics();
69 bool RequestingCreditCardInfo() const;
70 bool TransmissionWillBeSecure() const;
72 // The |profile| for |contents_|.
73 Profile* const profile_;
75 // The WebContents where the Autocomplete/Checkout action originated.
76 content::WebContents* const contents_;
78 // For logging UMA metrics.
79 const AutofillMetrics metric_logger_;
80 base::Time dialog_shown_timestamp_;
81 AutofillMetrics::DialogInitialUserStateMetric initial_user_state_;
83 FormStructure form_structure_;
85 // Whether the URL visible to the user when this dialog was requested to be
86 // invoked is the same as |source_url_|.
87 bool invoked_from_same_origin_;
89 // The URL of the invoking site.
92 // The callback via which we return the collected data.
93 base::Callback<void(const FormStructure*)> callback_;
95 // Whether |form_structure_| has asked for any details that would indicate
96 // we should show a shipping section.
97 bool cares_about_shipping_;
99 base::WeakPtrFactory<AutofillDialogControllerAndroid>
102 // Whether the latency to display to the UI was logged to UMA yet.
103 bool was_ui_latency_logged_;
105 // The corresponding java object.
106 base::android::ScopedJavaGlobalRef<jobject> java_object_;
108 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerAndroid);
111 } // namespace autofill
113 #endif // CHROME_BROWSER_UI_ANDROID_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_ANDROID_H_