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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.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/autofill/risk_util.h" | 11 #include "chrome/browser/autofill/risk_util.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 14 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
17 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
18 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 18 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
19 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 19 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
20 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" | 20 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" |
21 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" | 21 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" |
22 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 22 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
26 #include "chrome/browser/ui/chrome_pages.h" | 26 #include "chrome/browser/ui/chrome_pages.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
28 #include "chrome/browser/web_data_service_factory.h" | 28 #include "chrome/browser/web_data_service_factory.h" |
| 29 #include "chrome/common/features.h" |
29 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
30 #include "components/autofill/content/browser/content_autofill_driver.h" | 31 #include "components/autofill/content/browser/content_autofill_driver.h" |
31 #include "components/autofill/content/common/autofill_messages.h" | 32 #include "components/autofill/content/common/autofill_messages.h" |
32 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" | 33 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" |
33 #include "components/autofill/core/browser/ui/card_unmask_prompt_view.h" | 34 #include "components/autofill/core/browser/ui/card_unmask_prompt_view.h" |
34 #include "components/autofill/core/common/autofill_pref_names.h" | 35 #include "components/autofill/core/common/autofill_pref_names.h" |
35 #include "components/password_manager/content/browser/content_password_manager_d
river.h" | 36 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
36 #include "components/signin/core/browser/profile_identity_provider.h" | 37 #include "components/signin/core/browser/profile_identity_provider.h" |
37 #include "components/user_prefs/user_prefs.h" | 38 #include "components/user_prefs/user_prefs.h" |
38 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
39 #include "content/public/browser/render_frame_host.h" | 40 #include "content/public/browser/render_frame_host.h" |
40 #include "ui/gfx/geometry/rect.h" | 41 #include "ui/gfx/geometry/rect.h" |
41 | 42 |
42 #if defined(OS_ANDROID) | 43 #if BUILDFLAG(ANDROID_JAVA_UI) |
43 #include "chrome/browser/android/chrome_application.h" | 44 #include "chrome/browser/android/chrome_application.h" |
44 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" | 45 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" |
45 #else | 46 #else |
46 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 47 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
47 #include "components/ui/zoom/zoom_controller.h" | 48 #include "components/ui/zoom/zoom_controller.h" |
48 #endif | 49 #endif |
49 | 50 |
50 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); | 51 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); |
51 | 52 |
52 namespace autofill { | 53 namespace autofill { |
53 | 54 |
54 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) | 55 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) |
55 : content::WebContentsObserver(web_contents), | 56 : content::WebContentsObserver(web_contents), |
56 unmask_controller_( | 57 unmask_controller_( |
57 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()), | 58 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()), |
58 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 59 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
59 ->IsOffTheRecord()), | 60 ->IsOffTheRecord()), |
60 last_rfh_to_rac_(nullptr) { | 61 last_rfh_to_rac_(nullptr) { |
61 DCHECK(web_contents); | 62 DCHECK(web_contents); |
62 | 63 |
63 #if !defined(OS_ANDROID) | 64 #if !BUILDFLAG(ANDROID_JAVA_UI) |
64 // Since ZoomController is also a WebContentsObserver, we need to be careful | 65 // Since ZoomController is also a WebContentsObserver, we need to be careful |
65 // about disconnecting from it since the relative order of destruction of | 66 // about disconnecting from it since the relative order of destruction of |
66 // WebContentsObservers is not guaranteed. ZoomController silently clears | 67 // WebContentsObservers is not guaranteed. ZoomController silently clears |
67 // its ZoomObserver list during WebContentsDestroyed() so there's no need | 68 // its ZoomObserver list during WebContentsDestroyed() so there's no need |
68 // to explicitly remove ourselves on destruction. | 69 // to explicitly remove ourselves on destruction. |
69 ui_zoom::ZoomController* zoom_controller = | 70 ui_zoom::ZoomController* zoom_controller = |
70 ui_zoom::ZoomController::FromWebContents(web_contents); | 71 ui_zoom::ZoomController::FromWebContents(web_contents); |
71 // There may not always be a ZoomController, e.g. in tests. | 72 // There may not always be a ZoomController, e.g. in tests. |
72 if (zoom_controller) | 73 if (zoom_controller) |
73 zoom_controller->AddObserver(this); | 74 zoom_controller->AddObserver(this); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()) | 106 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()) |
106 ->GetPrefs(); | 107 ->GetPrefs(); |
107 } | 108 } |
108 | 109 |
109 IdentityProvider* ChromeAutofillClient::GetIdentityProvider() { | 110 IdentityProvider* ChromeAutofillClient::GetIdentityProvider() { |
110 if (!identity_provider_) { | 111 if (!identity_provider_) { |
111 Profile* profile = | 112 Profile* profile = |
112 Profile::FromBrowserContext(web_contents()->GetBrowserContext()) | 113 Profile::FromBrowserContext(web_contents()->GetBrowserContext()) |
113 ->GetOriginalProfile(); | 114 ->GetOriginalProfile(); |
114 base::Closure login_callback; | 115 base::Closure login_callback; |
115 #if !defined(OS_ANDROID) | 116 #if !BUILDFLAG(ANDROID_JAVA_UI) |
116 login_callback = | 117 login_callback = |
117 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile); | 118 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile); |
118 #endif | 119 #endif |
119 identity_provider_.reset(new ProfileIdentityProvider( | 120 identity_provider_.reset(new ProfileIdentityProvider( |
120 SigninManagerFactory::GetForProfile(profile), | 121 SigninManagerFactory::GetForProfile(profile), |
121 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 122 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
122 login_callback)); | 123 login_callback)); |
123 } | 124 } |
124 | 125 |
125 return identity_provider_.get(); | 126 return identity_provider_.get(); |
126 } | 127 } |
127 | 128 |
128 rappor::RapporService* ChromeAutofillClient::GetRapporService() { | 129 rappor::RapporService* ChromeAutofillClient::GetRapporService() { |
129 return g_browser_process->rappor_service(); | 130 return g_browser_process->rappor_service(); |
130 } | 131 } |
131 | 132 |
132 void ChromeAutofillClient::ShowAutofillSettings() { | 133 void ChromeAutofillClient::ShowAutofillSettings() { |
133 #if defined(OS_ANDROID) | 134 #if BUILDFLAG(ANDROID_JAVA_UI) |
134 chrome::android::ChromeApplication::ShowAutofillSettings(); | 135 chrome::android::ChromeApplication::ShowAutofillSettings(); |
135 #else | 136 #else |
136 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 137 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
137 if (browser) | 138 if (browser) |
138 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); | 139 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); |
139 #endif // #if defined(OS_ANDROID) | 140 #endif // #if BUILDFLAG(ANDROID_JAVA_UI) |
140 } | 141 } |
141 | 142 |
142 void ChromeAutofillClient::ShowUnmaskPrompt( | 143 void ChromeAutofillClient::ShowUnmaskPrompt( |
143 const CreditCard& card, | 144 const CreditCard& card, |
144 base::WeakPtr<CardUnmaskDelegate> delegate) { | 145 base::WeakPtr<CardUnmaskDelegate> delegate) { |
145 unmask_controller_.ShowPrompt( | 146 unmask_controller_.ShowPrompt( |
146 CreateCardUnmaskPromptView(&unmask_controller_, web_contents()), | 147 CreateCardUnmaskPromptView(&unmask_controller_, web_contents()), |
147 card, delegate); | 148 card, delegate); |
148 } | 149 } |
149 | 150 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 273 |
273 void ChromeAutofillClient::DidNavigateAnyFrame( | 274 void ChromeAutofillClient::DidNavigateAnyFrame( |
274 content::RenderFrameHost* render_frame_host, | 275 content::RenderFrameHost* render_frame_host, |
275 const content::LoadCommittedDetails& details, | 276 const content::LoadCommittedDetails& details, |
276 const content::FrameNavigateParams& params) { | 277 const content::FrameNavigateParams& params) { |
277 if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) | 278 if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) |
278 HideRequestAutocompleteDialog(); | 279 HideRequestAutocompleteDialog(); |
279 } | 280 } |
280 | 281 |
281 void ChromeAutofillClient::MainFrameWasResized(bool width_changed) { | 282 void ChromeAutofillClient::MainFrameWasResized(bool width_changed) { |
282 #if defined(OS_ANDROID) | 283 #if BUILDFLAG(ANDROID_JAVA_UI) |
283 // Ignore virtual keyboard showing and hiding a strip of suggestions. | 284 // Ignore virtual keyboard showing and hiding a strip of suggestions. |
284 if (!width_changed) | 285 if (!width_changed) |
285 return; | 286 return; |
286 #endif | 287 #endif |
287 | 288 |
288 HideAutofillPopup(); | 289 HideAutofillPopup(); |
289 } | 290 } |
290 | 291 |
291 void ChromeAutofillClient::WebContentsDestroyed() { | 292 void ChromeAutofillClient::WebContentsDestroyed() { |
292 HideAutofillPopup(); | 293 HideAutofillPopup(); |
(...skipping 12 matching lines...) Expand all Loading... |
305 rfh); | 306 rfh); |
306 if (driver) { | 307 if (driver) { |
307 driver->GetPasswordGenerationManager()->DetectAccountCreationForms(forms); | 308 driver->GetPasswordGenerationManager()->DetectAccountCreationForms(forms); |
308 driver->GetPasswordManager()->ProcessAutofillPredictions(driver, forms); | 309 driver->GetPasswordManager()->ProcessAutofillPredictions(driver, forms); |
309 } | 310 } |
310 } | 311 } |
311 | 312 |
312 void ChromeAutofillClient::DidFillOrPreviewField( | 313 void ChromeAutofillClient::DidFillOrPreviewField( |
313 const base::string16& autofilled_value, | 314 const base::string16& autofilled_value, |
314 const base::string16& profile_full_name) { | 315 const base::string16& profile_full_name) { |
315 #if defined(OS_ANDROID) | 316 #if BUILDFLAG(ANDROID_JAVA_UI) |
316 AutofillLoggerAndroid::DidFillOrPreviewField(autofilled_value, | 317 AutofillLoggerAndroid::DidFillOrPreviewField(autofilled_value, |
317 profile_full_name); | 318 profile_full_name); |
318 #endif // defined(OS_ANDROID) | 319 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
319 } | 320 } |
320 | 321 |
321 void ChromeAutofillClient::OnFirstUserGestureObserved() { | 322 void ChromeAutofillClient::OnFirstUserGestureObserved() { |
322 web_contents()->SendToAllFrames( | 323 web_contents()->SendToAllFrames( |
323 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); | 324 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); |
324 } | 325 } |
325 | 326 |
326 bool ChromeAutofillClient::IsContextSecure(const GURL& form_origin) { | 327 bool ChromeAutofillClient::IsContextSecure(const GURL& form_origin) { |
327 content::SSLStatus ssl_status; | 328 content::SSLStatus ssl_status; |
328 content::NavigationEntry* navigation_entry = | 329 content::NavigationEntry* navigation_entry = |
329 web_contents()->GetController().GetLastCommittedEntry(); | 330 web_contents()->GetController().GetLastCommittedEntry(); |
330 if (!navigation_entry) | 331 if (!navigation_entry) |
331 return false; | 332 return false; |
332 | 333 |
333 ssl_status = navigation_entry->GetSSL(); | 334 ssl_status = navigation_entry->GetSSL(); |
334 // Note: If changing the implementation below, also change | 335 // Note: If changing the implementation below, also change |
335 // AwAutofillClient::IsContextSecure. See crbug.com/505388 | 336 // AwAutofillClient::IsContextSecure. See crbug.com/505388 |
336 return ssl_status.security_style == | 337 return ssl_status.security_style == |
337 content::SECURITY_STYLE_AUTHENTICATED && | 338 content::SECURITY_STYLE_AUTHENTICATED && |
338 ssl_status.content_status == content::SSLStatus::NORMAL_CONTENT; | 339 ssl_status.content_status == content::SSLStatus::NORMAL_CONTENT; |
339 } | 340 } |
340 | 341 |
341 } // namespace autofill | 342 } // namespace autofill |
OLD | NEW |