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 #ifndef CHROME_BROWSER_UI_ANDROID_AUTOFILL_AUTOFILL_DIALOG_VIEW_ANDROID_H_ | |
6 #define CHROME_BROWSER_UI_ANDROID_AUTOFILL_AUTOFILL_DIALOG_VIEW_ANDROID_H_ | |
7 | |
8 #include <jni.h> | |
9 | |
10 #include "base/android/jni_string.h" | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | |
13 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | |
14 | |
15 namespace autofill { | |
16 | |
17 // Android implementation of the Autofill dialog that handles the imperative | |
18 // autocomplete API call. | |
19 class AutofillDialogViewAndroid : public AutofillDialogView { | |
20 public: | |
21 explicit AutofillDialogViewAndroid(AutofillDialogController* controller); | |
22 virtual ~AutofillDialogViewAndroid(); | |
23 | |
24 // AutofillDialogView implementation: | |
25 virtual void Show() OVERRIDE; | |
26 virtual void Hide() OVERRIDE; | |
27 virtual void UpdateNotificationArea() OVERRIDE; | |
28 virtual void UpdateAccountChooser() OVERRIDE; | |
29 virtual void UpdateButtonStrip() OVERRIDE; | |
30 virtual void UpdateDetailArea() OVERRIDE; | |
31 virtual void UpdateForErrors() OVERRIDE; | |
32 virtual void UpdateAutocheckoutStepsArea() OVERRIDE; | |
33 virtual void UpdateSection(DialogSection section) OVERRIDE; | |
34 virtual void FillSection(DialogSection section, | |
35 const DetailInput& originating_input) OVERRIDE; | |
36 virtual void GetUserInput(DialogSection section, | |
37 DetailOutputMap* output) OVERRIDE; | |
38 virtual string16 GetCvc() OVERRIDE; | |
39 virtual bool SaveDetailsLocally() OVERRIDE; | |
40 virtual const content::NavigationController* ShowSignIn() OVERRIDE; | |
41 virtual void HideSignIn() OVERRIDE; | |
42 virtual void UpdateProgressBar(double value) OVERRIDE; | |
43 virtual void ModelChanged() OVERRIDE; | |
44 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE; | |
45 virtual TestableAutofillDialogView* GetTestableView() OVERRIDE; | |
46 | |
47 // Java to C++ calls | |
48 void ItemSelected(JNIEnv* env, jobject obj, jint section, jint index); | |
49 void AccountSelected(JNIEnv* env, jobject obj, jint index); | |
50 void NotificationCheckboxStateChanged(JNIEnv* env, | |
51 jobject obj, | |
52 jint type, | |
53 jboolean checked); | |
54 void EditingStart(JNIEnv* env, jobject obj, jint section); | |
55 jboolean EditingComplete(JNIEnv* env, jobject obj, jint section); | |
56 void EditingCancel(JNIEnv* env, jobject obj, jint section); | |
57 void EditedOrActivatedField(JNIEnv* env, | |
58 jobject obj, | |
59 jint section, | |
60 jint detail_input, | |
61 jint view_android, | |
62 jstring value, | |
63 jboolean was_edit); | |
64 base::android::ScopedJavaLocalRef<jstring> ValidateField( | |
65 JNIEnv* env, jobject obj, jint section, jint type, jstring value); | |
66 void ValidateSection(JNIEnv* env, jobject obj, jint section); | |
67 void DialogSubmit(JNIEnv* env, jobject obj); | |
68 void DialogCancel(JNIEnv* env, jobject obj); | |
69 void DialogDismissed(JNIEnv* env, jobject obj); | |
70 base::android::ScopedJavaLocalRef<jstring> GetLabelForSection( | |
71 JNIEnv* env, | |
72 jobject obj, | |
73 jint section); | |
74 base::android::ScopedJavaLocalRef<jobjectArray> GetListForField(JNIEnv* env, | |
75 jobject obj, | |
76 jint field); | |
77 void ContinueAutomaticSignin(JNIEnv* env, jobject obj, | |
78 jstring account_name, jstring sid, jstring lsid); | |
79 base::android::ScopedJavaLocalRef<jobject> GetIconForField( | |
80 JNIEnv* env, | |
81 jobject obj, | |
82 jint field_id, | |
83 jstring jinput); | |
84 base::android::ScopedJavaLocalRef<jstring> GetPlaceholderForField( | |
85 JNIEnv* env, | |
86 jobject obj, | |
87 jint section, | |
88 jint field_id); | |
89 base::android::ScopedJavaLocalRef<jstring> GetDialogButtonText( | |
90 JNIEnv* env, | |
91 jobject obj, | |
92 jint dialog_button_id); | |
93 jboolean IsDialogButtonEnabled( | |
94 JNIEnv* env, | |
95 jobject obj, | |
96 jint dialog_button_id); | |
97 base::android::ScopedJavaLocalRef<jstring> GetSaveLocallyText(JNIEnv* env, | |
98 jobject obj); | |
99 base::android::ScopedJavaLocalRef<jstring> GetLegalDocumentsText(JNIEnv* env, | |
100 jobject obj); | |
101 jboolean IsTheAddItem(JNIEnv* env, jobject obj, jint section, jint index); | |
102 | |
103 static bool RegisterAutofillDialogViewAndroid(JNIEnv* env); | |
104 | |
105 private: | |
106 // A button type for a menu item. | |
107 enum MenuItemButtonType { | |
108 MENU_ITEM_BUTTON_TYPE_NONE = 0, | |
109 MENU_ITEM_BUTTON_TYPE_ADD = 1, | |
110 MENU_ITEM_BUTTON_TYPE_EDIT = 2, | |
111 }; | |
112 | |
113 // To fit the return type and GetMenuItemButtonType() name into 80 chars. | |
114 typedef MenuItemButtonType MBT; | |
115 | |
116 // Returns the list of available user accounts. | |
117 std::vector<std::string> GetAvailableUserAccounts(); | |
118 bool ValidateSection(DialogSection section, ValidationType type); | |
119 | |
120 // Starts an automatic sign-in attempt for a given account. | |
121 bool StartAutomaticSignIn(const std::string& username); | |
122 | |
123 // Updates the visibility of the checkbox to save the edited information | |
124 // locally. | |
125 void UpdateSaveLocallyCheckBox(); | |
126 | |
127 // Updates a given |section| to match the state provided by |controller_|. If | |
128 // |clobber_inputs| is true, the user input will be ignored, otherwise it will | |
129 // be preserved for all inputs except for the |field_type_to_always_clobber|. | |
130 void UpdateOrFillSectionToJava(DialogSection section, | |
131 bool clobber_inputs, | |
132 int field_type_to_always_clobber); | |
133 | |
134 // Fills |output| with data the user manually input. | |
135 void GetUserInputImpl(DialogSection section, DetailOutputMap* output) const; | |
136 | |
137 // Returns the model for suggestions for fields that fall under |section|. | |
138 ui::MenuModel* GetMenuModelForSection(DialogSection section) const; | |
139 | |
140 // Returns the index of the currently selected item in |section|, or -1. | |
141 int GetSelectedItemIndexForSection(DialogSection section) const; | |
142 | |
143 // Returns true if the item at |index| in |section| is the "Add...". | |
144 bool IsTheAddMenuItem(DialogSection section, int index) const; | |
145 | |
146 // Returns true if the item at |index| in |section| is the "Manage...". | |
147 bool IsTheManageMenuItem(DialogSection section, int index) const; | |
148 | |
149 // Returns an |image| converted to a Java image, or null if |image| is empty. | |
150 base::android::ScopedJavaLocalRef<jobject> GetJavaBitmap( | |
151 const gfx::Image& image) const; | |
152 | |
153 // Returns the button type for a menu item at |index| in |section|. | |
154 MenuItemButtonType GetMenuItemButtonType( | |
155 DialogSection section, int index) const; | |
156 | |
157 // Collapse the user input into a menu item. | |
158 // TODO(aruslan): http://crbug.com/230685 | |
159 bool CollapseUserDataIntoMenuItem(DialogSection section, | |
160 string16* label, | |
161 string16* sublabel, | |
162 gfx::Image* icon) const; | |
163 | |
164 // The controller that drives this view. Weak pointer, always non-NULL. | |
165 AutofillDialogController* const controller_; | |
166 | |
167 // The corresponding java object. | |
168 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
169 | |
170 DISALLOW_COPY_AND_ASSIGN(AutofillDialogViewAndroid); | |
171 }; | |
172 | |
173 } // namespace autofill | |
174 | |
175 #endif // CHROME_BROWSER_UI_ANDROID_AUTOFILL_AUTOFILL_DIALOG_VIEW_ANDROID_H_ | |
OLD | NEW |