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

Side by Side Diff: chrome/browser/ui/autofill/chrome_autofill_client.cc

Issue 756333003: Prompt for unmasking Wallet credit card on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix AW Created 6 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/autofill/chrome_autofill_client.h" 5 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" 9 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
10 #include "chrome/browser/autofill/personal_data_manager_factory.h" 10 #include "chrome/browser/autofill/personal_data_manager_factory.h"
11 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 12 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 14 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
15 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 15 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
16 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" 16 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h"
17 #include "chrome/browser/ui/autofill/instrument_unmask_prompt_view.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/chrome_pages.h" 21 #include "chrome/browser/ui/chrome_pages.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
22 #include "chrome/browser/webdata/web_data_service_factory.h" 23 #include "chrome/browser/webdata/web_data_service_factory.h"
23 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
24 #include "components/autofill/content/browser/content_autofill_driver.h" 25 #include "components/autofill/content/browser/content_autofill_driver.h"
25 #include "components/autofill/content/common/autofill_messages.h" 26 #include "components/autofill/content/common/autofill_messages.h"
26 #include "components/autofill/core/common/autofill_pref_names.h" 27 #include "components/autofill/core/common/autofill_pref_names.h"
27 #include "components/password_manager/content/browser/content_password_manager_d river.h" 28 #include "components/password_manager/content/browser/content_password_manager_d river.h"
28 #include "content/public/browser/render_view_host.h" 29 #include "content/public/browser/render_view_host.h"
29 #include "ui/gfx/rect.h" 30 #include "ui/gfx/rect.h"
30 31
31 #if defined(OS_ANDROID) 32 #if defined(OS_ANDROID)
32 #include "chrome/browser/android/chromium_application.h" 33 #include "chrome/browser/android/chromium_application.h"
33 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" 34 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h"
34 #else 35 #else
35 #include "chrome/browser/ui/zoom/zoom_controller.h" 36 #include "chrome/browser/ui/zoom/zoom_controller.h"
36 #endif 37 #endif
37 38
38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); 39 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient);
39 40
40 namespace autofill { 41 namespace autofill {
41 42
42 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) 43 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents)
43 : content::WebContentsObserver(web_contents), web_contents_(web_contents) { 44 : content::WebContentsObserver(web_contents),
45 weak_pointer_factory_(this) {
44 DCHECK(web_contents); 46 DCHECK(web_contents);
45 47
46 #if !defined(OS_ANDROID) 48 #if !defined(OS_ANDROID)
47 // Since ZoomController is also a WebContentsObserver, we need to be careful 49 // Since ZoomController is also a WebContentsObserver, we need to be careful
48 // about disconnecting from it since the relative order of destruction of 50 // about disconnecting from it since the relative order of destruction of
49 // WebContentsObservers is not guaranteed. ZoomController silently clears 51 // WebContentsObservers is not guaranteed. ZoomController silently clears
50 // its ZoomObserver list during WebContentsDestroyed() so there's no need 52 // its ZoomObserver list during WebContentsDestroyed() so there's no need
51 // to explicitly remove ourselves on destruction. 53 // to explicitly remove ourselves on destruction.
52 ZoomController* zoom_controller = 54 ZoomController* zoom_controller =
53 ZoomController::FromWebContents(web_contents); 55 ZoomController::FromWebContents(web_contents);
(...skipping 18 matching lines...) Expand all
72 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 74 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
73 } 75 }
74 76
75 void ChromeAutofillClient::TabActivated() { 77 void ChromeAutofillClient::TabActivated() {
76 if (dialog_controller_.get()) 78 if (dialog_controller_.get())
77 dialog_controller_->TabActivated(); 79 dialog_controller_->TabActivated();
78 } 80 }
79 81
80 PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() { 82 PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() {
81 Profile* profile = 83 Profile* profile =
82 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 84 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
83 return PersonalDataManagerFactory::GetForProfile( 85 return PersonalDataManagerFactory::GetForProfile(
84 profile->GetOriginalProfile()); 86 profile->GetOriginalProfile());
85 } 87 }
86 88
87 scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() { 89 scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() {
88 Profile* profile = 90 Profile* profile =
89 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 91 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
90 return WebDataServiceFactory::GetAutofillWebDataForProfile( 92 return WebDataServiceFactory::GetAutofillWebDataForProfile(
91 profile, Profile::EXPLICIT_ACCESS); 93 profile, Profile::EXPLICIT_ACCESS);
92 } 94 }
93 95
94 PrefService* ChromeAutofillClient::GetPrefs() { 96 PrefService* ChromeAutofillClient::GetPrefs() {
95 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()) 97 return Profile::FromBrowserContext(web_contents()->GetBrowserContext())
96 ->GetPrefs(); 98 ->GetPrefs();
97 } 99 }
98 100
99 void ChromeAutofillClient::ShowAutofillSettings() { 101 void ChromeAutofillClient::ShowAutofillSettings() {
100 #if defined(OS_ANDROID) 102 #if defined(OS_ANDROID)
101 chrome::android::ChromiumApplication::ShowAutofillSettings(); 103 chrome::android::ChromiumApplication::ShowAutofillSettings();
102 #else 104 #else
103 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 105 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
104 if (browser) 106 if (browser)
105 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); 107 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage);
106 #endif // #if defined(OS_ANDROID) 108 #endif // #if defined(OS_ANDROID)
107 } 109 }
108 110
111 void ChromeAutofillClient::ShowUnmaskPrompt() {
112 // TODO(estade): we'll need to store the returned pointer at some point when
113 // the view object gets more complicated.
114 InstrumentUnmaskPromptView::CreateAndShow(
115 web_contents(), base::Bind(&ChromeAutofillClient::OnUnmaskResponse,
116 weak_pointer_factory_.GetWeakPtr()));
117 }
118
119 void ChromeAutofillClient::OnUnmaskResponse(const base::string16& response) {
120 NOTIMPLEMENTED() << " I should probably do something with this: " << response;
121 }
122
109 void ChromeAutofillClient::ConfirmSaveCreditCard( 123 void ChromeAutofillClient::ConfirmSaveCreditCard(
110 const AutofillMetrics& metric_logger, 124 const AutofillMetrics& metric_logger,
111 const base::Closure& save_card_callback) { 125 const base::Closure& save_card_callback) {
112 InfoBarService* infobar_service = 126 InfoBarService* infobar_service =
113 InfoBarService::FromWebContents(web_contents_); 127 InfoBarService::FromWebContents(web_contents());
114 AutofillCCInfoBarDelegate::Create( 128 AutofillCCInfoBarDelegate::Create(
115 infobar_service, &metric_logger, save_card_callback); 129 infobar_service, &metric_logger, save_card_callback);
116 } 130 }
117 131
118 bool ChromeAutofillClient::HasCreditCardScanFeature() { 132 bool ChromeAutofillClient::HasCreditCardScanFeature() {
119 return CreditCardScannerController::HasCreditCardScanFeature(); 133 return CreditCardScannerController::HasCreditCardScanFeature();
120 } 134 }
121 135
122 void ChromeAutofillClient::ScanCreditCard( 136 void ChromeAutofillClient::ScanCreditCard(
123 const CreditCardScanCallback& callback) { 137 const CreditCardScanCallback& callback) {
124 CreditCardScannerController::ScanCreditCard(web_contents(), callback); 138 CreditCardScannerController::ScanCreditCard(web_contents(), callback);
125 } 139 }
126 140
127 void ChromeAutofillClient::ShowRequestAutocompleteDialog( 141 void ChromeAutofillClient::ShowRequestAutocompleteDialog(
128 const FormData& form, 142 const FormData& form,
129 const GURL& source_url, 143 const GURL& source_url,
130 const ResultCallback& callback) { 144 const ResultCallback& callback) {
131 HideRequestAutocompleteDialog(); 145 HideRequestAutocompleteDialog();
132 146
133 dialog_controller_ = AutofillDialogController::Create( 147 dialog_controller_ = AutofillDialogController::Create(
134 web_contents_, form, source_url, callback); 148 web_contents(), form, source_url, callback);
135 if (dialog_controller_) { 149 if (dialog_controller_) {
136 dialog_controller_->Show(); 150 dialog_controller_->Show();
137 } else { 151 } else {
138 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, 152 callback.Run(AutofillClient::AutocompleteResultErrorDisabled,
139 base::string16(), 153 base::string16(),
140 NULL); 154 NULL);
141 NOTIMPLEMENTED(); 155 NOTIMPLEMENTED();
142 } 156 }
143 } 157 }
144 158
145 void ChromeAutofillClient::ShowAutofillPopup( 159 void ChromeAutofillClient::ShowAutofillPopup(
146 const gfx::RectF& element_bounds, 160 const gfx::RectF& element_bounds,
147 base::i18n::TextDirection text_direction, 161 base::i18n::TextDirection text_direction,
148 const std::vector<base::string16>& values, 162 const std::vector<base::string16>& values,
149 const std::vector<base::string16>& labels, 163 const std::vector<base::string16>& labels,
150 const std::vector<base::string16>& icons, 164 const std::vector<base::string16>& icons,
151 const std::vector<int>& identifiers, 165 const std::vector<int>& identifiers,
152 base::WeakPtr<AutofillPopupDelegate> delegate) { 166 base::WeakPtr<AutofillPopupDelegate> delegate) {
153 // Convert element_bounds to be in screen space. 167 // Convert element_bounds to be in screen space.
154 gfx::Rect client_area = web_contents_->GetContainerBounds(); 168 gfx::Rect client_area = web_contents()->GetContainerBounds();
155 gfx::RectF element_bounds_in_screen_space = 169 gfx::RectF element_bounds_in_screen_space =
156 element_bounds + client_area.OffsetFromOrigin(); 170 element_bounds + client_area.OffsetFromOrigin();
157 171
158 // Will delete or reuse the old |popup_controller_|. 172 // Will delete or reuse the old |popup_controller_|.
159 popup_controller_ = 173 popup_controller_ =
160 AutofillPopupControllerImpl::GetOrCreate(popup_controller_, 174 AutofillPopupControllerImpl::GetOrCreate(popup_controller_,
161 delegate, 175 delegate,
162 web_contents(), 176 web_contents(),
163 web_contents()->GetNativeView(), 177 web_contents()->GetNativeView(),
164 element_bounds_in_screen_space, 178 element_bounds_in_screen_space,
165 text_direction); 179 text_direction);
166 180
167 popup_controller_->Show(values, labels, icons, identifiers); 181 popup_controller_->Show(values, labels, icons, identifiers);
168 } 182 }
169 183
170 void ChromeAutofillClient::UpdateAutofillPopupDataListValues( 184 void ChromeAutofillClient::UpdateAutofillPopupDataListValues(
171 const std::vector<base::string16>& values, 185 const std::vector<base::string16>& values,
172 const std::vector<base::string16>& labels) { 186 const std::vector<base::string16>& labels) {
173 if (popup_controller_.get()) 187 if (popup_controller_.get())
174 popup_controller_->UpdateDataListValues(values, labels); 188 popup_controller_->UpdateDataListValues(values, labels);
175 } 189 }
176 190
177 void ChromeAutofillClient::HideAutofillPopup() { 191 void ChromeAutofillClient::HideAutofillPopup() {
178 if (popup_controller_.get()) 192 if (popup_controller_.get())
179 popup_controller_->Hide(); 193 popup_controller_->Hide();
180 194
181 // Password generation popups behave in the same fashion and should also 195 // Password generation popups behave in the same fashion and should also
182 // be hidden. 196 // be hidden.
183 ChromePasswordManagerClient* password_client = 197 ChromePasswordManagerClient* password_client =
184 ChromePasswordManagerClient::FromWebContents(web_contents_); 198 ChromePasswordManagerClient::FromWebContents(web_contents());
185 if (password_client) 199 if (password_client)
186 password_client->HidePasswordGenerationPopup(); 200 password_client->HidePasswordGenerationPopup();
187 } 201 }
188 202
189 bool ChromeAutofillClient::IsAutocompleteEnabled() { 203 bool ChromeAutofillClient::IsAutocompleteEnabled() {
190 // For browser, Autocomplete is always enabled as part of Autofill. 204 // For browser, Autocomplete is always enabled as part of Autofill.
191 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); 205 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
192 } 206 }
193 207
194 void ChromeAutofillClient::HideRequestAutocompleteDialog() { 208 void ChromeAutofillClient::HideRequestAutocompleteDialog() {
(...skipping 26 matching lines...) Expand all
221 profile_full_name); 235 profile_full_name);
222 #endif // defined(OS_ANDROID) 236 #endif // defined(OS_ANDROID)
223 } 237 }
224 238
225 void ChromeAutofillClient::OnFirstUserGestureObserved() { 239 void ChromeAutofillClient::OnFirstUserGestureObserved() {
226 web_contents()->SendToAllFrames( 240 web_contents()->SendToAllFrames(
227 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); 241 new AutofillMsg_FirstUserGestureObservedInTab(routing_id()));
228 } 242 }
229 243
230 } // namespace autofill 244 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698