| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/prefs/pref_service.h" | |
| 9 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | |
| 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" | |
| 11 #include "chrome/browser/infobars/infobar_service.h" | |
| 12 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | |
| 15 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | |
| 16 #include "chrome/browser/ui/browser.h" | |
| 17 #include "chrome/browser/ui/browser_finder.h" | |
| 18 #include "chrome/browser/ui/browser_window.h" | |
| 19 #include "chrome/browser/ui/chrome_pages.h" | |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | |
| 21 #include "chrome/browser/webdata/web_data_service_factory.h" | |
| 22 #include "chrome/common/url_constants.h" | |
| 23 #include "components/autofill/content/browser/content_autofill_driver.h" | |
| 24 #include "components/autofill/content/common/autofill_messages.h" | |
| 25 #include "components/autofill/core/common/autofill_pref_names.h" | |
| 26 #include "content/public/browser/render_view_host.h" | |
| 27 #include "ui/gfx/rect.h" | |
| 28 | |
| 29 #if defined(OS_ANDROID) | |
| 30 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" | |
| 31 #endif | |
| 32 | |
| 33 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::TabAutofillManagerDelegate); | |
| 34 | |
| 35 namespace autofill { | |
| 36 | |
| 37 TabAutofillManagerDelegate::TabAutofillManagerDelegate( | |
| 38 content::WebContents* web_contents) | |
| 39 : content::WebContentsObserver(web_contents), | |
| 40 web_contents_(web_contents) { | |
| 41 DCHECK(web_contents); | |
| 42 } | |
| 43 | |
| 44 TabAutofillManagerDelegate::~TabAutofillManagerDelegate() { | |
| 45 // NOTE: It is too late to clean up the autofill popup; that cleanup process | |
| 46 // requires that the WebContents instance still be valid and it is not at | |
| 47 // this point (in particular, the WebContentsImpl destructor has already | |
| 48 // finished running and we are now in the base class destructor). | |
| 49 DCHECK(!popup_controller_); | |
| 50 } | |
| 51 | |
| 52 void TabAutofillManagerDelegate::TabActivated() { | |
| 53 if (dialog_controller_.get()) | |
| 54 dialog_controller_->TabActivated(); | |
| 55 } | |
| 56 | |
| 57 PersonalDataManager* TabAutofillManagerDelegate::GetPersonalDataManager() { | |
| 58 Profile* profile = | |
| 59 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 60 return PersonalDataManagerFactory::GetForProfile( | |
| 61 profile->GetOriginalProfile()); | |
| 62 } | |
| 63 | |
| 64 scoped_refptr<AutofillWebDataService> | |
| 65 TabAutofillManagerDelegate::GetDatabase() { | |
| 66 Profile* profile = | |
| 67 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 68 return WebDataServiceFactory::GetAutofillWebDataForProfile( | |
| 69 profile, Profile::EXPLICIT_ACCESS); | |
| 70 } | |
| 71 | |
| 72 PrefService* TabAutofillManagerDelegate::GetPrefs() { | |
| 73 return Profile::FromBrowserContext(web_contents_->GetBrowserContext())-> | |
| 74 GetPrefs(); | |
| 75 } | |
| 76 | |
| 77 void TabAutofillManagerDelegate::ShowAutofillSettings() { | |
| 78 #if defined(OS_ANDROID) | |
| 79 NOTIMPLEMENTED(); | |
| 80 #else | |
| 81 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | |
| 82 if (browser) | |
| 83 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); | |
| 84 #endif // #if defined(OS_ANDROID) | |
| 85 } | |
| 86 | |
| 87 void TabAutofillManagerDelegate::ConfirmSaveCreditCard( | |
| 88 const AutofillMetrics& metric_logger, | |
| 89 const base::Closure& save_card_callback) { | |
| 90 InfoBarService* infobar_service = | |
| 91 InfoBarService::FromWebContents(web_contents_); | |
| 92 AutofillCCInfoBarDelegate::Create( | |
| 93 infobar_service, &metric_logger, save_card_callback); | |
| 94 } | |
| 95 | |
| 96 void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog( | |
| 97 const FormData& form, | |
| 98 const GURL& source_url, | |
| 99 const ResultCallback& callback) { | |
| 100 HideRequestAutocompleteDialog(); | |
| 101 | |
| 102 dialog_controller_ = AutofillDialogController::Create(web_contents_, | |
| 103 form, | |
| 104 source_url, | |
| 105 callback); | |
| 106 if (dialog_controller_) { | |
| 107 dialog_controller_->Show(); | |
| 108 } else { | |
| 109 callback.Run(AutofillManagerDelegate::AutocompleteResultErrorDisabled, | |
| 110 base::string16(), | |
| 111 NULL); | |
| 112 NOTIMPLEMENTED(); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 void TabAutofillManagerDelegate::ShowAutofillPopup( | |
| 117 const gfx::RectF& element_bounds, | |
| 118 base::i18n::TextDirection text_direction, | |
| 119 const std::vector<base::string16>& values, | |
| 120 const std::vector<base::string16>& labels, | |
| 121 const std::vector<base::string16>& icons, | |
| 122 const std::vector<int>& identifiers, | |
| 123 base::WeakPtr<AutofillPopupDelegate> delegate) { | |
| 124 // Convert element_bounds to be in screen space. | |
| 125 gfx::Rect client_area = web_contents_->GetContainerBounds(); | |
| 126 gfx::RectF element_bounds_in_screen_space = | |
| 127 element_bounds + client_area.OffsetFromOrigin(); | |
| 128 | |
| 129 // Will delete or reuse the old |popup_controller_|. | |
| 130 popup_controller_ = AutofillPopupControllerImpl::GetOrCreate( | |
| 131 popup_controller_, | |
| 132 delegate, | |
| 133 web_contents(), | |
| 134 web_contents()->GetNativeView(), | |
| 135 element_bounds_in_screen_space, | |
| 136 text_direction); | |
| 137 | |
| 138 popup_controller_->Show(values, labels, icons, identifiers); | |
| 139 } | |
| 140 | |
| 141 void TabAutofillManagerDelegate::UpdateAutofillPopupDataListValues( | |
| 142 const std::vector<base::string16>& values, | |
| 143 const std::vector<base::string16>& labels) { | |
| 144 if (popup_controller_.get()) | |
| 145 popup_controller_->UpdateDataListValues(values, labels); | |
| 146 } | |
| 147 | |
| 148 void TabAutofillManagerDelegate::HideAutofillPopup() { | |
| 149 if (popup_controller_.get()) | |
| 150 popup_controller_->Hide(); | |
| 151 | |
| 152 // Password generation popups behave in the same fashion and should also | |
| 153 // be hidden. | |
| 154 ChromePasswordManagerClient* password_client = | |
| 155 ChromePasswordManagerClient::FromWebContents(web_contents_); | |
| 156 if (password_client) | |
| 157 password_client->HidePasswordGenerationPopup(); | |
| 158 } | |
| 159 | |
| 160 bool TabAutofillManagerDelegate::IsAutocompleteEnabled() { | |
| 161 // For browser, Autocomplete is always enabled as part of Autofill. | |
| 162 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | |
| 163 } | |
| 164 | |
| 165 void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() { | |
| 166 if (dialog_controller_.get()) | |
| 167 dialog_controller_->Hide(); | |
| 168 } | |
| 169 | |
| 170 void TabAutofillManagerDelegate::WebContentsDestroyed() { | |
| 171 HideAutofillPopup(); | |
| 172 } | |
| 173 | |
| 174 void TabAutofillManagerDelegate::DetectAccountCreationForms( | |
| 175 const std::vector<autofill::FormStructure*>& forms) { | |
| 176 password_manager::PasswordGenerationManager* manager = | |
| 177 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | |
| 178 web_contents_); | |
| 179 if (manager) | |
| 180 manager->DetectAccountCreationForms(forms); | |
| 181 } | |
| 182 | |
| 183 void TabAutofillManagerDelegate::DidFillOrPreviewField( | |
| 184 const base::string16& autofilled_value, | |
| 185 const base::string16& profile_full_name) { | |
| 186 #if defined(OS_ANDROID) | |
| 187 AutofillLoggerAndroid::DidFillOrPreviewField( | |
| 188 autofilled_value, profile_full_name); | |
| 189 #endif // defined(OS_ANDROID) | |
| 190 } | |
| 191 | |
| 192 } // namespace autofill | |
| OLD | NEW |