OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/tab_autofill_manager_delegate.h" | 5 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.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/autocheckout_whitelist_manager_factory.h" | |
10 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 9 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
11 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/autofill/autocheckout_bubble.h" | |
15 #include "chrome/browser/ui/autofill/autocheckout_bubble_controller.h" | |
16 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 13 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
17 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 14 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
18 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
20 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
23 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
24 #include "components/autofill/content/browser/autofill_driver_impl.h" | 21 #include "components/autofill/content/browser/autofill_driver_impl.h" |
25 #include "components/autofill/core/common/autofill_messages.h" | 22 #include "components/autofill/core/common/autofill_messages.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 59 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
63 return PersonalDataManagerFactory::GetForProfile( | 60 return PersonalDataManagerFactory::GetForProfile( |
64 profile->GetOriginalProfile()); | 61 profile->GetOriginalProfile()); |
65 } | 62 } |
66 | 63 |
67 PrefService* TabAutofillManagerDelegate::GetPrefs() { | 64 PrefService* TabAutofillManagerDelegate::GetPrefs() { |
68 return Profile::FromBrowserContext(web_contents_->GetBrowserContext())-> | 65 return Profile::FromBrowserContext(web_contents_->GetBrowserContext())-> |
69 GetPrefs(); | 66 GetPrefs(); |
70 } | 67 } |
71 | 68 |
72 autocheckout::WhitelistManager* | |
73 TabAutofillManagerDelegate::GetAutocheckoutWhitelistManager() const { | |
74 Profile* profile = | |
75 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
76 return autocheckout::WhitelistManagerFactory::GetForProfile( | |
77 profile->GetOriginalProfile()); | |
78 } | |
79 | |
80 void TabAutofillManagerDelegate::OnAutocheckoutError() { | |
81 // |dialog_controller_| is a WeakPtr, but we require it to be present when | |
82 // |OnAutocheckoutError| is called, so we intentionally do not do NULL check. | |
83 dialog_controller_->OnAutocheckoutError(); | |
84 } | |
85 | |
86 void TabAutofillManagerDelegate::OnAutocheckoutSuccess() { | |
87 dialog_controller_->OnAutocheckoutSuccess(); | |
88 } | |
89 | |
90 void TabAutofillManagerDelegate::ShowAutofillSettings() { | 69 void TabAutofillManagerDelegate::ShowAutofillSettings() { |
91 #if defined(OS_ANDROID) | 70 #if defined(OS_ANDROID) |
92 NOTIMPLEMENTED(); | 71 NOTIMPLEMENTED(); |
93 #else | 72 #else |
94 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 73 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
95 if (browser) | 74 if (browser) |
96 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); | 75 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); |
97 #endif // #if defined(OS_ANDROID) | 76 #endif // #if defined(OS_ANDROID) |
98 } | 77 } |
99 | 78 |
100 void TabAutofillManagerDelegate::ConfirmSaveCreditCard( | 79 void TabAutofillManagerDelegate::ConfirmSaveCreditCard( |
101 const AutofillMetrics& metric_logger, | 80 const AutofillMetrics& metric_logger, |
102 const CreditCard& credit_card, | 81 const CreditCard& credit_card, |
103 const base::Closure& save_card_callback) { | 82 const base::Closure& save_card_callback) { |
104 InfoBarService* infobar_service = | 83 InfoBarService* infobar_service = |
105 InfoBarService::FromWebContents(web_contents_); | 84 InfoBarService::FromWebContents(web_contents_); |
106 AutofillCCInfoBarDelegate::Create( | 85 AutofillCCInfoBarDelegate::Create( |
107 infobar_service, &metric_logger, save_card_callback); | 86 infobar_service, &metric_logger, save_card_callback); |
108 } | 87 } |
109 | 88 |
110 bool TabAutofillManagerDelegate::ShowAutocheckoutBubble( | |
111 const gfx::RectF& bounding_box, | |
112 bool is_google_user, | |
113 const base::Callback<void(AutocheckoutBubbleState)>& callback) { | |
114 #if !defined(TOOLKIT_VIEWS) | |
115 callback.Run(AUTOCHECKOUT_BUBBLE_CANCELED); | |
116 NOTIMPLEMENTED(); | |
117 return false; | |
118 #else | |
119 HideAutocheckoutBubble(); | |
120 | |
121 // Convert |bounding_box| to be in screen space. | |
122 gfx::Rect container_rect; | |
123 web_contents_->GetView()->GetContainerBounds(&container_rect); | |
124 gfx::RectF anchor = bounding_box + container_rect.OffsetFromOrigin(); | |
125 | |
126 autocheckout_bubble_ = | |
127 AutocheckoutBubble::Create(scoped_ptr<AutocheckoutBubbleController>( | |
128 new AutocheckoutBubbleController( | |
129 anchor, | |
130 web_contents_->GetView()->GetTopLevelNativeWindow(), | |
131 is_google_user, | |
132 callback))); | |
133 | |
134 if (!autocheckout_bubble_) | |
135 return false; | |
136 | |
137 autocheckout_bubble_->ShowBubble(); | |
138 return true; | |
139 #endif // #if !defined(TOOLKIT_VIEWS) | |
140 } | |
141 | |
142 void TabAutofillManagerDelegate::HideAutocheckoutBubble() { | |
143 if (autocheckout_bubble_.get()) | |
144 autocheckout_bubble_->HideBubble(); | |
145 } | |
146 | |
147 void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog( | 89 void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog( |
148 const FormData& form, | 90 const FormData& form, |
149 const GURL& source_url, | 91 const GURL& source_url, |
150 DialogType dialog_type, | 92 DialogType dialog_type, |
151 const base::Callback<void(const FormStructure*, | 93 const base::Callback<void(const FormStructure*, |
152 const std::string&)>& callback) { | 94 const std::string&)>& callback) { |
153 HideRequestAutocompleteDialog(); | 95 HideRequestAutocompleteDialog(); |
154 | 96 |
155 dialog_controller_ = AutofillDialogController::Create(web_contents_, | 97 dialog_controller_ = AutofillDialogController::Create(web_contents_, |
156 form, | 98 form, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 const std::vector<base::string16>& labels) { | 137 const std::vector<base::string16>& labels) { |
196 if (popup_controller_.get()) | 138 if (popup_controller_.get()) |
197 popup_controller_->UpdateDataListValues(values, labels); | 139 popup_controller_->UpdateDataListValues(values, labels); |
198 } | 140 } |
199 | 141 |
200 void TabAutofillManagerDelegate::HideAutofillPopup() { | 142 void TabAutofillManagerDelegate::HideAutofillPopup() { |
201 if (popup_controller_.get()) | 143 if (popup_controller_.get()) |
202 popup_controller_->Hide(); | 144 popup_controller_->Hide(); |
203 } | 145 } |
204 | 146 |
205 void TabAutofillManagerDelegate::AddAutocheckoutStep( | |
206 AutocheckoutStepType step_type) { | |
207 dialog_controller_->AddAutocheckoutStep(step_type); | |
208 } | |
209 | |
210 void TabAutofillManagerDelegate::UpdateAutocheckoutStep( | |
211 AutocheckoutStepType step_type, | |
212 AutocheckoutStepStatus step_status) { | |
213 dialog_controller_->UpdateAutocheckoutStep(step_type, step_status); | |
214 } | |
215 | |
216 bool TabAutofillManagerDelegate::IsAutocompleteEnabled() { | 147 bool TabAutofillManagerDelegate::IsAutocompleteEnabled() { |
217 // For browser, Autocomplete is always enabled as part of Autofill. | 148 // For browser, Autocomplete is always enabled as part of Autofill. |
218 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 149 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
219 } | 150 } |
220 | 151 |
221 void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() { | 152 void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() { |
222 if (dialog_controller_.get()) | 153 if (dialog_controller_.get()) |
223 dialog_controller_->Hide(); | 154 dialog_controller_->Hide(); |
224 } | 155 } |
225 | 156 |
226 void TabAutofillManagerDelegate::WasShown() { | 157 void TabAutofillManagerDelegate::WasShown() { |
227 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 158 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
228 if (!host) | 159 if (!host) |
229 return; | 160 return; |
230 host->Send(new AutofillMsg_PageShown(host->GetRoutingID())); | 161 host->Send(new AutofillMsg_PageShown(host->GetRoutingID())); |
231 } | 162 } |
232 | 163 |
233 void TabAutofillManagerDelegate::DidNavigateMainFrame( | 164 void TabAutofillManagerDelegate::DidNavigateMainFrame( |
234 const content::LoadCommittedDetails& details, | 165 const content::LoadCommittedDetails& details, |
235 const content::FrameNavigateParams& params) { | 166 const content::FrameNavigateParams& params) { |
236 | |
237 HideAutocheckoutBubble(); | |
238 | |
239 if (!dialog_controller_.get()) | 167 if (!dialog_controller_.get()) |
240 return; | 168 return; |
241 | 169 |
242 // A redirect immediately after a successful Autocheckout flow shouldn't hide | |
243 // the dialog. | |
244 bool preserve_dialog = AutofillDriverImpl::FromWebContents(web_contents())-> | |
245 autofill_manager()->autocheckout_manager()->should_preserve_dialog(); | |
246 bool was_redirect = details.entry && | 170 bool was_redirect = details.entry && |
247 content::PageTransitionIsRedirect(details.entry->GetTransitionType()); | 171 content::PageTransitionIsRedirect(details.entry->GetTransitionType()); |
248 | 172 |
249 if (dialog_controller_->GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE || | 173 if (dialog_controller_->GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE || |
250 (!was_redirect && !preserve_dialog)) { | 174 !was_redirect) { |
251 HideRequestAutocompleteDialog(); | 175 HideRequestAutocompleteDialog(); |
252 } | 176 } |
253 } | 177 } |
254 | 178 |
255 void TabAutofillManagerDelegate::WebContentsDestroyed( | 179 void TabAutofillManagerDelegate::WebContentsDestroyed( |
256 content::WebContents* web_contents) { | 180 content::WebContents* web_contents) { |
257 HideAutofillPopup(); | 181 HideAutofillPopup(); |
258 } | 182 } |
259 | 183 |
260 } // namespace autofill | 184 } // namespace autofill |
OLD | NEW |