OLD | NEW |
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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
24 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 24 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
25 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" | 25 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" |
26 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" | 26 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" |
27 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 27 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
28 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
29 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
30 #include "chrome/browser/ui/chrome_pages.h" | 30 #include "chrome/browser/ui/chrome_pages.h" |
31 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
32 #include "chrome/browser/web_data_service_factory.h" | 32 #include "chrome/browser/web_data_service_factory.h" |
33 #include "chrome/common/features.h" | |
34 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
35 #include "components/autofill/content/browser/content_autofill_driver.h" | 34 #include "components/autofill/content/browser/content_autofill_driver.h" |
36 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 35 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
37 #include "components/autofill/core/browser/ui/card_unmask_prompt_view.h" | 36 #include "components/autofill/core/browser/ui/card_unmask_prompt_view.h" |
38 #include "components/autofill/core/common/autofill_pref_names.h" | 37 #include "components/autofill/core/common/autofill_pref_names.h" |
39 #include "components/autofill/core/common/autofill_switches.h" | 38 #include "components/autofill/core/common/autofill_switches.h" |
40 #include "components/browser_sync/profile_sync_service.h" | 39 #include "components/browser_sync/profile_sync_service.h" |
41 #include "components/password_manager/content/browser/content_password_manager_d
river.h" | 40 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
42 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
43 #include "components/signin/core/browser/profile_identity_provider.h" | 42 #include "components/signin/core/browser/profile_identity_provider.h" |
44 #include "components/signin/core/browser/signin_header_helper.h" | 43 #include "components/signin/core/browser/signin_header_helper.h" |
45 #include "components/signin/core/browser/signin_metrics.h" | 44 #include "components/signin/core/browser/signin_metrics.h" |
46 #include "components/user_prefs/user_prefs.h" | 45 #include "components/user_prefs/user_prefs.h" |
47 #include "content/public/browser/navigation_entry.h" | 46 #include "content/public/browser/navigation_entry.h" |
48 #include "content/public/browser/render_frame_host.h" | 47 #include "content/public/browser/render_frame_host.h" |
49 #include "content/public/browser/ssl_status.h" | 48 #include "content/public/browser/ssl_status.h" |
50 #include "ui/gfx/geometry/rect.h" | 49 #include "ui/gfx/geometry/rect.h" |
51 | 50 |
52 #if BUILDFLAG(ANDROID_JAVA_UI) | |
53 #include "chrome/browser/android/chrome_application.h" | |
54 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" | |
55 #else | |
56 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
57 #include "components/zoom/zoom_controller.h" | |
58 #endif | |
59 | |
60 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
61 #include "base/android/context_utils.h" | 52 #include "base/android/context_utils.h" |
| 53 #include "chrome/browser/android/chrome_application.h" |
62 #include "chrome/browser/android/signin/signin_promo_util_android.h" | 54 #include "chrome/browser/android/signin/signin_promo_util_android.h" |
63 #include "chrome/browser/infobars/infobar_service.h" | 55 #include "chrome/browser/infobars/infobar_service.h" |
| 56 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" |
64 #include "chrome/browser/ui/android/infobars/autofill_credit_card_filling_infoba
r.h" | 57 #include "chrome/browser/ui/android/infobars/autofill_credit_card_filling_infoba
r.h" |
65 #include "components/autofill/core/browser/autofill_credit_card_filling_infobar_
delegate_mobile.h" | 58 #include "components/autofill/core/browser/autofill_credit_card_filling_infobar_
delegate_mobile.h" |
66 #include "components/autofill/core/browser/autofill_save_card_infobar_delegate_m
obile.h" | 59 #include "components/autofill/core/browser/autofill_save_card_infobar_delegate_m
obile.h" |
67 #include "components/autofill/core/browser/autofill_save_card_infobar_mobile.h" | 60 #include "components/autofill/core/browser/autofill_save_card_infobar_mobile.h" |
68 #include "components/infobars/core/infobar.h" | 61 #include "components/infobars/core/infobar.h" |
69 #include "content/public/browser/android/content_view_core.h" | 62 #include "content/public/browser/android/content_view_core.h" |
70 #else // !OS_ANDROID | 63 #else // !OS_ANDROID |
71 #include "chrome/browser/ui/browser.h" | 64 #include "chrome/browser/ui/browser.h" |
| 65 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 66 #include "components/zoom/zoom_controller.h" |
72 #endif | 67 #endif |
73 | 68 |
74 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); | 69 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); |
75 | 70 |
76 namespace autofill { | 71 namespace autofill { |
77 | 72 |
78 namespace { | 73 namespace { |
79 | 74 |
80 const char kSecurityIndicatorHelpCenterUrl[] = | 75 const char kSecurityIndicatorHelpCenterUrl[] = |
81 "https://support.google.com/chrome/answer/95617"; | 76 "https://support.google.com/chrome/answer/95617"; |
82 | 77 |
83 } // anonymous namespace | 78 } // anonymous namespace |
84 | 79 |
85 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) | 80 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) |
86 : content::WebContentsObserver(web_contents), | 81 : content::WebContentsObserver(web_contents), |
87 unmask_controller_( | 82 unmask_controller_( |
88 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()), | 83 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()), |
89 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 84 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
90 ->IsOffTheRecord()) { | 85 ->IsOffTheRecord()) { |
91 DCHECK(web_contents); | 86 DCHECK(web_contents); |
92 | 87 |
93 #if !BUILDFLAG(ANDROID_JAVA_UI) | 88 #if !defined(OS_ANDROID) |
94 // Since ZoomController is also a WebContentsObserver, we need to be careful | 89 // Since ZoomController is also a WebContentsObserver, we need to be careful |
95 // about disconnecting from it since the relative order of destruction of | 90 // about disconnecting from it since the relative order of destruction of |
96 // WebContentsObservers is not guaranteed. ZoomController silently clears | 91 // WebContentsObservers is not guaranteed. ZoomController silently clears |
97 // its ZoomObserver list during WebContentsDestroyed() so there's no need | 92 // its ZoomObserver list during WebContentsDestroyed() so there's no need |
98 // to explicitly remove ourselves on destruction. | 93 // to explicitly remove ourselves on destruction. |
99 zoom::ZoomController* zoom_controller = | 94 zoom::ZoomController* zoom_controller = |
100 zoom::ZoomController::FromWebContents(web_contents); | 95 zoom::ZoomController::FromWebContents(web_contents); |
101 // There may not always be a ZoomController, e.g. in tests. | 96 // There may not always be a ZoomController, e.g. in tests. |
102 if (zoom_controller) | 97 if (zoom_controller) |
103 zoom_controller->AddObserver(this); | 98 zoom_controller->AddObserver(this); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 131 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
137 return ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 132 return ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
138 } | 133 } |
139 | 134 |
140 IdentityProvider* ChromeAutofillClient::GetIdentityProvider() { | 135 IdentityProvider* ChromeAutofillClient::GetIdentityProvider() { |
141 if (!identity_provider_) { | 136 if (!identity_provider_) { |
142 Profile* profile = | 137 Profile* profile = |
143 Profile::FromBrowserContext(web_contents()->GetBrowserContext()) | 138 Profile::FromBrowserContext(web_contents()->GetBrowserContext()) |
144 ->GetOriginalProfile(); | 139 ->GetOriginalProfile(); |
145 base::Closure login_callback; | 140 base::Closure login_callback; |
146 #if !BUILDFLAG(ANDROID_JAVA_UI) | 141 #if !defined(OS_ANDROID) |
147 login_callback = | 142 login_callback = |
148 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile); | 143 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile); |
149 #endif | 144 #endif |
150 identity_provider_.reset(new ProfileIdentityProvider( | 145 identity_provider_.reset(new ProfileIdentityProvider( |
151 SigninManagerFactory::GetForProfile(profile), | 146 SigninManagerFactory::GetForProfile(profile), |
152 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 147 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
153 login_callback)); | 148 login_callback)); |
154 } | 149 } |
155 | 150 |
156 return identity_provider_.get(); | 151 return identity_provider_.get(); |
157 } | 152 } |
158 | 153 |
159 rappor::RapporServiceImpl* ChromeAutofillClient::GetRapporServiceImpl() { | 154 rappor::RapporServiceImpl* ChromeAutofillClient::GetRapporServiceImpl() { |
160 return g_browser_process->rappor_service(); | 155 return g_browser_process->rappor_service(); |
161 } | 156 } |
162 | 157 |
163 void ChromeAutofillClient::ShowAutofillSettings() { | 158 void ChromeAutofillClient::ShowAutofillSettings() { |
164 #if BUILDFLAG(ANDROID_JAVA_UI) | 159 #if defined(OS_ANDROID) |
165 chrome::android::ChromeApplication::ShowAutofillSettings(); | 160 chrome::android::ChromeApplication::ShowAutofillSettings(); |
166 #else | 161 #else |
167 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 162 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
168 if (browser) | 163 if (browser) |
169 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); | 164 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); |
170 #endif // #if BUILDFLAG(ANDROID_JAVA_UI) | 165 #endif // #if defined(OS_ANDROID) |
171 } | 166 } |
172 | 167 |
173 void ChromeAutofillClient::ShowUnmaskPrompt( | 168 void ChromeAutofillClient::ShowUnmaskPrompt( |
174 const CreditCard& card, | 169 const CreditCard& card, |
175 UnmaskCardReason reason, | 170 UnmaskCardReason reason, |
176 base::WeakPtr<CardUnmaskDelegate> delegate) { | 171 base::WeakPtr<CardUnmaskDelegate> delegate) { |
177 unmask_controller_.ShowPrompt( | 172 unmask_controller_.ShowPrompt( |
178 CreateCardUnmaskPromptView(&unmask_controller_, web_contents()), | 173 CreateCardUnmaskPromptView(&unmask_controller_, web_contents()), |
179 card, reason, delegate); | 174 card, reason, delegate); |
180 } | 175 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 if (password_client) | 286 if (password_client) |
292 password_client->HidePasswordGenerationPopup(); | 287 password_client->HidePasswordGenerationPopup(); |
293 } | 288 } |
294 | 289 |
295 bool ChromeAutofillClient::IsAutocompleteEnabled() { | 290 bool ChromeAutofillClient::IsAutocompleteEnabled() { |
296 // For browser, Autocomplete is always enabled as part of Autofill. | 291 // For browser, Autocomplete is always enabled as part of Autofill. |
297 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 292 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
298 } | 293 } |
299 | 294 |
300 void ChromeAutofillClient::MainFrameWasResized(bool width_changed) { | 295 void ChromeAutofillClient::MainFrameWasResized(bool width_changed) { |
301 #if BUILDFLAG(ANDROID_JAVA_UI) | 296 #if defined(OS_ANDROID) |
302 // Ignore virtual keyboard showing and hiding a strip of suggestions. | 297 // Ignore virtual keyboard showing and hiding a strip of suggestions. |
303 if (!width_changed) | 298 if (!width_changed) |
304 return; | 299 return; |
305 #endif | 300 #endif |
306 | 301 |
307 HideAutofillPopup(); | 302 HideAutofillPopup(); |
308 } | 303 } |
309 | 304 |
310 void ChromeAutofillClient::WebContentsDestroyed() { | 305 void ChromeAutofillClient::WebContentsDestroyed() { |
311 HideAutofillPopup(); | 306 HideAutofillPopup(); |
(...skipping 13 matching lines...) Expand all Loading... |
325 if (driver) { | 320 if (driver) { |
326 driver->GetPasswordGenerationManager()->DetectFormsEligibleForGeneration( | 321 driver->GetPasswordGenerationManager()->DetectFormsEligibleForGeneration( |
327 forms); | 322 forms); |
328 driver->GetPasswordManager()->ProcessAutofillPredictions(driver, forms); | 323 driver->GetPasswordManager()->ProcessAutofillPredictions(driver, forms); |
329 } | 324 } |
330 } | 325 } |
331 | 326 |
332 void ChromeAutofillClient::DidFillOrPreviewField( | 327 void ChromeAutofillClient::DidFillOrPreviewField( |
333 const base::string16& autofilled_value, | 328 const base::string16& autofilled_value, |
334 const base::string16& profile_full_name) { | 329 const base::string16& profile_full_name) { |
335 #if BUILDFLAG(ANDROID_JAVA_UI) | 330 #if defined(OS_ANDROID) |
336 AutofillLoggerAndroid::DidFillOrPreviewField(autofilled_value, | 331 AutofillLoggerAndroid::DidFillOrPreviewField(autofilled_value, |
337 profile_full_name); | 332 profile_full_name); |
338 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 333 #endif // defined(OS_ANDROID) |
339 } | 334 } |
340 | 335 |
341 void ChromeAutofillClient::OnFirstUserGestureObserved() { | 336 void ChromeAutofillClient::OnFirstUserGestureObserved() { |
342 ContentAutofillDriverFactory* factory = | 337 ContentAutofillDriverFactory* factory = |
343 ContentAutofillDriverFactory::FromWebContents(web_contents()); | 338 ContentAutofillDriverFactory::FromWebContents(web_contents()); |
344 DCHECK(factory); | 339 DCHECK(factory); |
345 | 340 |
346 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { | 341 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { |
347 // No need to notify non-live frames. | 342 // No need to notify non-live frames. |
348 // And actually they have no corresponding drivers in the factory's map. | 343 // And actually they have no corresponding drivers in the factory's map. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 395 } |
401 | 396 |
402 void ChromeAutofillClient::ShowHttpNotSecureExplanation() { | 397 void ChromeAutofillClient::ShowHttpNotSecureExplanation() { |
403 web_contents()->OpenURL(content::OpenURLParams( | 398 web_contents()->OpenURL(content::OpenURLParams( |
404 GURL(kSecurityIndicatorHelpCenterUrl), content::Referrer(), | 399 GURL(kSecurityIndicatorHelpCenterUrl), content::Referrer(), |
405 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 400 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
406 false /* is_renderer_initiated */)); | 401 false /* is_renderer_initiated */)); |
407 } | 402 } |
408 | 403 |
409 } // namespace autofill | 404 } // namespace autofill |
OLD | NEW |