| 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/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/card_unmask_prompt_view.h" |
| 16 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" | 17 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.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), weak_pointer_factory_(this) { |
| 44 DCHECK(web_contents); | 45 DCHECK(web_contents); |
| 45 | 46 |
| 46 #if !defined(OS_ANDROID) | 47 #if !defined(OS_ANDROID) |
| 47 // Since ZoomController is also a WebContentsObserver, we need to be careful | 48 // Since ZoomController is also a WebContentsObserver, we need to be careful |
| 48 // about disconnecting from it since the relative order of destruction of | 49 // about disconnecting from it since the relative order of destruction of |
| 49 // WebContentsObservers is not guaranteed. ZoomController silently clears | 50 // WebContentsObservers is not guaranteed. ZoomController silently clears |
| 50 // its ZoomObserver list during WebContentsDestroyed() so there's no need | 51 // its ZoomObserver list during WebContentsDestroyed() so there's no need |
| 51 // to explicitly remove ourselves on destruction. | 52 // to explicitly remove ourselves on destruction. |
| 52 ZoomController* zoom_controller = | 53 ZoomController* zoom_controller = |
| 53 ZoomController::FromWebContents(web_contents); | 54 ZoomController::FromWebContents(web_contents); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 73 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 73 } | 74 } |
| 74 | 75 |
| 75 void ChromeAutofillClient::TabActivated() { | 76 void ChromeAutofillClient::TabActivated() { |
| 76 if (dialog_controller_.get()) | 77 if (dialog_controller_.get()) |
| 77 dialog_controller_->TabActivated(); | 78 dialog_controller_->TabActivated(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() { | 81 PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() { |
| 81 Profile* profile = | 82 Profile* profile = |
| 82 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 83 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 83 return PersonalDataManagerFactory::GetForProfile( | 84 return PersonalDataManagerFactory::GetForProfile( |
| 84 profile->GetOriginalProfile()); | 85 profile->GetOriginalProfile()); |
| 85 } | 86 } |
| 86 | 87 |
| 87 scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() { | 88 scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() { |
| 88 Profile* profile = | 89 Profile* profile = |
| 89 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 90 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 90 return WebDataServiceFactory::GetAutofillWebDataForProfile( | 91 return WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 91 profile, Profile::EXPLICIT_ACCESS); | 92 profile, Profile::EXPLICIT_ACCESS); |
| 92 } | 93 } |
| 93 | 94 |
| 94 PrefService* ChromeAutofillClient::GetPrefs() { | 95 PrefService* ChromeAutofillClient::GetPrefs() { |
| 95 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 96 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()) |
| 96 ->GetPrefs(); | 97 ->GetPrefs(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void ChromeAutofillClient::ShowAutofillSettings() { | 100 void ChromeAutofillClient::ShowAutofillSettings() { |
| 100 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
| 101 chrome::android::ChromiumApplication::ShowAutofillSettings(); | 102 chrome::android::ChromiumApplication::ShowAutofillSettings(); |
| 102 #else | 103 #else |
| 103 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 104 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 104 if (browser) | 105 if (browser) |
| 105 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); | 106 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); |
| 106 #endif // #if defined(OS_ANDROID) | 107 #endif // #if defined(OS_ANDROID) |
| 107 } | 108 } |
| 108 | 109 |
| 110 void ChromeAutofillClient::ShowUnmaskPrompt() { |
| 111 // TODO(estade): we'll need to store the returned pointer at some point when |
| 112 // the view object gets more complicated. |
| 113 CardUnmaskPromptView::CreateAndShow( |
| 114 web_contents(), base::Bind(&ChromeAutofillClient::OnUnmaskResponse, |
| 115 weak_pointer_factory_.GetWeakPtr())); |
| 116 } |
| 117 |
| 118 void ChromeAutofillClient::OnUnmaskResponse(const base::string16& response) { |
| 119 NOTIMPLEMENTED() << " I should probably do something with this: " << response; |
| 120 } |
| 121 |
| 109 void ChromeAutofillClient::ConfirmSaveCreditCard( | 122 void ChromeAutofillClient::ConfirmSaveCreditCard( |
| 110 const AutofillMetrics& metric_logger, | 123 const AutofillMetrics& metric_logger, |
| 111 const base::Closure& save_card_callback) { | 124 const base::Closure& save_card_callback) { |
| 112 InfoBarService* infobar_service = | 125 InfoBarService* infobar_service = |
| 113 InfoBarService::FromWebContents(web_contents_); | 126 InfoBarService::FromWebContents(web_contents()); |
| 114 AutofillCCInfoBarDelegate::Create( | 127 AutofillCCInfoBarDelegate::Create( |
| 115 infobar_service, &metric_logger, save_card_callback); | 128 infobar_service, &metric_logger, save_card_callback); |
| 116 } | 129 } |
| 117 | 130 |
| 118 bool ChromeAutofillClient::HasCreditCardScanFeature() { | 131 bool ChromeAutofillClient::HasCreditCardScanFeature() { |
| 119 return CreditCardScannerController::HasCreditCardScanFeature(); | 132 return CreditCardScannerController::HasCreditCardScanFeature(); |
| 120 } | 133 } |
| 121 | 134 |
| 122 void ChromeAutofillClient::ScanCreditCard( | 135 void ChromeAutofillClient::ScanCreditCard( |
| 123 const CreditCardScanCallback& callback) { | 136 const CreditCardScanCallback& callback) { |
| 124 CreditCardScannerController::ScanCreditCard(web_contents(), callback); | 137 CreditCardScannerController::ScanCreditCard(web_contents(), callback); |
| 125 } | 138 } |
| 126 | 139 |
| 127 void ChromeAutofillClient::ShowRequestAutocompleteDialog( | 140 void ChromeAutofillClient::ShowRequestAutocompleteDialog( |
| 128 const FormData& form, | 141 const FormData& form, |
| 129 const GURL& source_url, | 142 const GURL& source_url, |
| 130 const ResultCallback& callback) { | 143 const ResultCallback& callback) { |
| 131 HideRequestAutocompleteDialog(); | 144 HideRequestAutocompleteDialog(); |
| 132 | 145 |
| 133 dialog_controller_ = AutofillDialogController::Create( | 146 dialog_controller_ = AutofillDialogController::Create(web_contents(), form, |
| 134 web_contents_, form, source_url, callback); | 147 source_url, callback); |
| 135 if (dialog_controller_) { | 148 if (dialog_controller_) { |
| 136 dialog_controller_->Show(); | 149 dialog_controller_->Show(); |
| 137 } else { | 150 } else { |
| 138 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, | 151 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, |
| 139 base::string16(), | 152 base::string16(), |
| 140 NULL); | 153 NULL); |
| 141 NOTIMPLEMENTED(); | 154 NOTIMPLEMENTED(); |
| 142 } | 155 } |
| 143 } | 156 } |
| 144 | 157 |
| 145 void ChromeAutofillClient::ShowAutofillPopup( | 158 void ChromeAutofillClient::ShowAutofillPopup( |
| 146 const gfx::RectF& element_bounds, | 159 const gfx::RectF& element_bounds, |
| 147 base::i18n::TextDirection text_direction, | 160 base::i18n::TextDirection text_direction, |
| 148 const std::vector<base::string16>& values, | 161 const std::vector<base::string16>& values, |
| 149 const std::vector<base::string16>& labels, | 162 const std::vector<base::string16>& labels, |
| 150 const std::vector<base::string16>& icons, | 163 const std::vector<base::string16>& icons, |
| 151 const std::vector<int>& identifiers, | 164 const std::vector<int>& identifiers, |
| 152 base::WeakPtr<AutofillPopupDelegate> delegate) { | 165 base::WeakPtr<AutofillPopupDelegate> delegate) { |
| 153 // Convert element_bounds to be in screen space. | 166 // Convert element_bounds to be in screen space. |
| 154 gfx::Rect client_area = web_contents_->GetContainerBounds(); | 167 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
| 155 gfx::RectF element_bounds_in_screen_space = | 168 gfx::RectF element_bounds_in_screen_space = |
| 156 element_bounds + client_area.OffsetFromOrigin(); | 169 element_bounds + client_area.OffsetFromOrigin(); |
| 157 | 170 |
| 158 // Will delete or reuse the old |popup_controller_|. | 171 // Will delete or reuse the old |popup_controller_|. |
| 159 popup_controller_ = | 172 popup_controller_ = |
| 160 AutofillPopupControllerImpl::GetOrCreate(popup_controller_, | 173 AutofillPopupControllerImpl::GetOrCreate(popup_controller_, |
| 161 delegate, | 174 delegate, |
| 162 web_contents(), | 175 web_contents(), |
| 163 web_contents()->GetNativeView(), | 176 web_contents()->GetNativeView(), |
| 164 element_bounds_in_screen_space, | 177 element_bounds_in_screen_space, |
| 165 text_direction); | 178 text_direction); |
| 166 | 179 |
| 167 popup_controller_->Show(values, labels, icons, identifiers); | 180 popup_controller_->Show(values, labels, icons, identifiers); |
| 168 } | 181 } |
| 169 | 182 |
| 170 void ChromeAutofillClient::UpdateAutofillPopupDataListValues( | 183 void ChromeAutofillClient::UpdateAutofillPopupDataListValues( |
| 171 const std::vector<base::string16>& values, | 184 const std::vector<base::string16>& values, |
| 172 const std::vector<base::string16>& labels) { | 185 const std::vector<base::string16>& labels) { |
| 173 if (popup_controller_.get()) | 186 if (popup_controller_.get()) |
| 174 popup_controller_->UpdateDataListValues(values, labels); | 187 popup_controller_->UpdateDataListValues(values, labels); |
| 175 } | 188 } |
| 176 | 189 |
| 177 void ChromeAutofillClient::HideAutofillPopup() { | 190 void ChromeAutofillClient::HideAutofillPopup() { |
| 178 if (popup_controller_.get()) | 191 if (popup_controller_.get()) |
| 179 popup_controller_->Hide(); | 192 popup_controller_->Hide(); |
| 180 | 193 |
| 181 // Password generation popups behave in the same fashion and should also | 194 // Password generation popups behave in the same fashion and should also |
| 182 // be hidden. | 195 // be hidden. |
| 183 ChromePasswordManagerClient* password_client = | 196 ChromePasswordManagerClient* password_client = |
| 184 ChromePasswordManagerClient::FromWebContents(web_contents_); | 197 ChromePasswordManagerClient::FromWebContents(web_contents()); |
| 185 if (password_client) | 198 if (password_client) |
| 186 password_client->HidePasswordGenerationPopup(); | 199 password_client->HidePasswordGenerationPopup(); |
| 187 } | 200 } |
| 188 | 201 |
| 189 bool ChromeAutofillClient::IsAutocompleteEnabled() { | 202 bool ChromeAutofillClient::IsAutocompleteEnabled() { |
| 190 // For browser, Autocomplete is always enabled as part of Autofill. | 203 // For browser, Autocomplete is always enabled as part of Autofill. |
| 191 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 204 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 192 } | 205 } |
| 193 | 206 |
| 194 void ChromeAutofillClient::HideRequestAutocompleteDialog() { | 207 void ChromeAutofillClient::HideRequestAutocompleteDialog() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 223 profile_full_name); | 236 profile_full_name); |
| 224 #endif // defined(OS_ANDROID) | 237 #endif // defined(OS_ANDROID) |
| 225 } | 238 } |
| 226 | 239 |
| 227 void ChromeAutofillClient::OnFirstUserGestureObserved() { | 240 void ChromeAutofillClient::OnFirstUserGestureObserved() { |
| 228 web_contents()->SendToAllFrames( | 241 web_contents()->SendToAllFrames( |
| 229 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); | 242 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); |
| 230 } | 243 } |
| 231 | 244 |
| 232 } // namespace autofill | 245 } // namespace autofill |
| OLD | NEW |