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/password_generation_popup_controller_impl.h
" | 5 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversion_utils.h" | 13 #include "base/strings/utf_string_conversion_utils.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" | 15 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" |
16 #include "chrome/browser/ui/autofill/password_generation_popup_view.h" | 16 #include "chrome/browser/ui/autofill/password_generation_popup_view.h" |
17 #include "chrome/browser/ui/autofill/popup_constants.h" | 17 #include "chrome/browser/ui/autofill/popup_constants.h" |
18 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
19 #include "chrome/browser/ui/browser_navigator_params.h" | 19 #include "chrome/browser/ui/browser_navigator_params.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "chrome/grit/chromium_strings.h" | 21 #include "chrome/grit/chromium_strings.h" |
22 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 23 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 24 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
23 #include "components/autofill/core/browser/password_generator.h" | 25 #include "components/autofill/core/browser/password_generator.h" |
24 #include "components/autofill/core/browser/suggestion.h" | 26 #include "components/autofill/core/browser/suggestion.h" |
25 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 27 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
26 #include "components/password_manager/core/browser/password_manager.h" | 28 #include "components/password_manager/core/browser/password_manager.h" |
27 #include "components/password_manager/core/browser/password_manager_constants.h" | 29 #include "components/password_manager/core/browser/password_manager_constants.h" |
28 #include "components/strings/grit/components_strings.h" | 30 #include "components/strings/grit/components_strings.h" |
29 #include "content/public/browser/native_web_keyboard_event.h" | 31 #include "content/public/browser/native_web_keyboard_event.h" |
30 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
31 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
32 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
44 PasswordGenerationPopupControllerImpl::GetOrCreate( | 46 PasswordGenerationPopupControllerImpl::GetOrCreate( |
45 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous, | 47 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous, |
46 const gfx::RectF& bounds, | 48 const gfx::RectF& bounds, |
47 const PasswordForm& form, | 49 const PasswordForm& form, |
48 int max_length, | 50 int max_length, |
49 password_manager::PasswordManager* password_manager, | 51 password_manager::PasswordManager* password_manager, |
50 password_manager::PasswordManagerDriver* driver, | 52 password_manager::PasswordManagerDriver* driver, |
51 PasswordGenerationPopupObserver* observer, | 53 PasswordGenerationPopupObserver* observer, |
52 content::WebContents* web_contents, | 54 content::WebContents* web_contents, |
53 gfx::NativeView container_view) { | 55 gfx::NativeView container_view) { |
54 if (previous.get() && | 56 if (previous.get() && previous->element_bounds() == bounds && |
55 previous->element_bounds() == bounds && | 57 previous->web_contents_ == web_contents && |
56 previous->web_contents() == web_contents && | |
57 previous->container_view() == container_view) { | 58 previous->container_view() == container_view) { |
58 return previous; | 59 return previous; |
59 } | 60 } |
60 | 61 |
61 if (previous.get()) | 62 if (previous.get()) |
62 previous->Hide(); | 63 previous->Hide(); |
63 | 64 |
64 PasswordGenerationPopupControllerImpl* controller = | 65 PasswordGenerationPopupControllerImpl* controller = |
65 new PasswordGenerationPopupControllerImpl( | 66 new PasswordGenerationPopupControllerImpl( |
66 bounds, form, max_length, password_manager, driver, observer, | 67 bounds, form, max_length, password_manager, driver, observer, |
(...skipping 10 matching lines...) Expand all Loading... |
77 PasswordGenerationPopupObserver* observer, | 78 PasswordGenerationPopupObserver* observer, |
78 content::WebContents* web_contents, | 79 content::WebContents* web_contents, |
79 gfx::NativeView container_view) | 80 gfx::NativeView container_view) |
80 : view_(NULL), | 81 : view_(NULL), |
81 form_(form), | 82 form_(form), |
82 password_manager_(password_manager), | 83 password_manager_(password_manager), |
83 driver_(driver), | 84 driver_(driver), |
84 observer_(observer), | 85 observer_(observer), |
85 generator_(new PasswordGenerator(max_length)), | 86 generator_(new PasswordGenerator(max_length)), |
86 // TODO(estade): use correct text direction. | 87 // TODO(estade): use correct text direction. |
87 controller_common_(bounds, | 88 controller_common_(bounds, base::i18n::LEFT_TO_RIGHT, container_view), |
88 base::i18n::LEFT_TO_RIGHT, | |
89 container_view, | |
90 web_contents), | |
91 password_selected_(false), | 89 password_selected_(false), |
92 display_password_(false), | 90 display_password_(false), |
| 91 web_contents_(web_contents), |
93 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
94 controller_common_.SetKeyPressCallback( | |
95 base::Bind(&PasswordGenerationPopupControllerImpl::HandleKeyPressEvent, | |
96 base::Unretained(this))); | |
97 | |
98 base::string16 link = | 93 base::string16 link = |
99 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); | 94 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); |
100 size_t offset = 0; | 95 size_t offset = 0; |
101 help_text_ = | 96 help_text_ = |
102 l10n_util::GetStringFUTF16(IDS_PASSWORD_GENERATION_PROMPT, link, &offset); | 97 l10n_util::GetStringFUTF16(IDS_PASSWORD_GENERATION_PROMPT, link, &offset); |
103 link_range_ = gfx::Range(offset, offset + link.length()); | 98 link_range_ = gfx::Range(offset, offset + link.length()); |
104 } | 99 } |
105 | 100 |
106 PasswordGenerationPopupControllerImpl::~PasswordGenerationPopupControllerImpl() | 101 PasswordGenerationPopupControllerImpl::~PasswordGenerationPopupControllerImpl() |
107 {} | 102 {} |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return; | 184 return; |
190 } | 185 } |
191 | 186 |
192 CalculateBounds(); | 187 CalculateBounds(); |
193 view_->Show(); | 188 view_->Show(); |
194 } else { | 189 } else { |
195 CalculateBounds(); | 190 CalculateBounds(); |
196 view_->UpdateBoundsAndRedrawPopup(); | 191 view_->UpdateBoundsAndRedrawPopup(); |
197 } | 192 } |
198 | 193 |
199 controller_common_.RegisterKeyPressCallback(); | 194 static_cast<ContentAutofillDriver*>(driver_->GetAutofillDriver()) |
| 195 ->RegisterKeyPressHandler(base::Bind( |
| 196 &PasswordGenerationPopupControllerImpl::HandleKeyPressEvent, |
| 197 base::Unretained(this))); |
200 | 198 |
201 if (observer_) | 199 if (observer_) |
202 observer_->OnPopupShown(display_password_); | 200 observer_->OnPopupShown(display_password_); |
203 } | 201 } |
204 | 202 |
205 void PasswordGenerationPopupControllerImpl::HideAndDestroy() { | 203 void PasswordGenerationPopupControllerImpl::HideAndDestroy() { |
206 Hide(); | 204 Hide(); |
207 } | 205 } |
208 | 206 |
209 void PasswordGenerationPopupControllerImpl::Hide() { | 207 void PasswordGenerationPopupControllerImpl::Hide() { |
210 controller_common_.RemoveKeyPressCallback(); | 208 static_cast<ContentAutofillDriver*>(driver_->GetAutofillDriver()) |
| 209 ->RemoveKeyPressHandler(); |
211 | 210 |
212 if (view_) | 211 if (view_) |
213 view_->Hide(); | 212 view_->Hide(); |
214 | 213 |
215 if (observer_) | 214 if (observer_) |
216 observer_->OnPopupHidden(); | 215 observer_->OnPopupHidden(); |
217 | 216 |
218 delete this; | 217 delete this; |
219 } | 218 } |
220 | 219 |
221 void PasswordGenerationPopupControllerImpl::ViewDestroyed() { | 220 void PasswordGenerationPopupControllerImpl::ViewDestroyed() { |
222 view_ = NULL; | 221 view_ = NULL; |
223 | 222 |
224 Hide(); | 223 Hide(); |
225 } | 224 } |
226 | 225 |
227 void PasswordGenerationPopupControllerImpl::OnSavedPasswordsLinkClicked() { | 226 void PasswordGenerationPopupControllerImpl::OnSavedPasswordsLinkClicked() { |
228 #if defined(OS_ANDROID) | 227 #if defined(OS_ANDROID) |
229 chrome::android::PreferencesLauncher::ShowPasswordSettings(); | 228 chrome::android::PreferencesLauncher::ShowPasswordSettings(); |
230 #else | 229 #else |
231 chrome::NavigateParams params( | 230 chrome::NavigateParams params( |
232 chrome::FindBrowserWithWebContents(web_contents()), | 231 chrome::FindBrowserWithWebContents(web_contents_), |
233 GURL(password_manager::kPasswordManagerAccountDashboardURL), | 232 GURL(password_manager::kPasswordManagerAccountDashboardURL), |
234 ui::PAGE_TRANSITION_LINK); | 233 ui::PAGE_TRANSITION_LINK); |
235 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 234 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
236 chrome::Navigate(¶ms); | 235 chrome::Navigate(¶ms); |
237 #endif | 236 #endif |
238 } | 237 } |
239 | 238 |
240 void PasswordGenerationPopupControllerImpl::SetSelectionAtPoint( | 239 void PasswordGenerationPopupControllerImpl::SetSelectionAtPoint( |
241 const gfx::Point& point) { | 240 const gfx::Point& point) { |
242 PasswordSelected(view_->IsPointInPasswordBounds(point)); | 241 PasswordSelected(view_->IsPointInPasswordBounds(point)); |
243 } | 242 } |
244 | 243 |
245 bool PasswordGenerationPopupControllerImpl::AcceptSelectedLine() { | 244 bool PasswordGenerationPopupControllerImpl::AcceptSelectedLine() { |
246 if (!password_selected_) | 245 if (!password_selected_) |
247 return false; | 246 return false; |
248 | 247 |
249 PasswordAccepted(); | 248 PasswordAccepted(); |
250 return true; | 249 return true; |
251 } | 250 } |
252 | 251 |
253 void PasswordGenerationPopupControllerImpl::SelectionCleared() { | 252 void PasswordGenerationPopupControllerImpl::SelectionCleared() { |
254 PasswordSelected(false); | 253 PasswordSelected(false); |
255 } | 254 } |
256 | 255 |
257 gfx::NativeView PasswordGenerationPopupControllerImpl::container_view() { | 256 gfx::NativeView PasswordGenerationPopupControllerImpl::container_view() { |
258 return controller_common_.container_view(); | 257 return controller_common_.container_view; |
259 } | 258 } |
260 | 259 |
261 gfx::Rect PasswordGenerationPopupControllerImpl::popup_bounds() const { | 260 gfx::Rect PasswordGenerationPopupControllerImpl::popup_bounds() const { |
262 return popup_bounds_; | 261 return popup_bounds_; |
263 } | 262 } |
264 | 263 |
265 const gfx::RectF& PasswordGenerationPopupControllerImpl::element_bounds() | 264 const gfx::RectF& PasswordGenerationPopupControllerImpl::element_bounds() |
266 const { | 265 const { |
267 return controller_common_.element_bounds(); | 266 return controller_common_.element_bounds; |
268 } | 267 } |
269 | 268 |
270 bool PasswordGenerationPopupControllerImpl::IsRTL() const { | 269 bool PasswordGenerationPopupControllerImpl::IsRTL() const { |
271 return base::i18n::IsRTL(); | 270 return base::i18n::IsRTL(); |
272 } | 271 } |
273 | 272 |
274 const std::vector<autofill::Suggestion> | 273 const std::vector<autofill::Suggestion> |
275 PasswordGenerationPopupControllerImpl::GetSuggestions() { | 274 PasswordGenerationPopupControllerImpl::GetSuggestions() { |
276 return std::vector<autofill::Suggestion>(); | 275 return std::vector<autofill::Suggestion>(); |
277 } | 276 } |
(...skipping 26 matching lines...) Expand all Loading... |
304 | 303 |
305 const base::string16& PasswordGenerationPopupControllerImpl::HelpText() { | 304 const base::string16& PasswordGenerationPopupControllerImpl::HelpText() { |
306 return help_text_; | 305 return help_text_; |
307 } | 306 } |
308 | 307 |
309 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() { | 308 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() { |
310 return link_range_; | 309 return link_range_; |
311 } | 310 } |
312 | 311 |
313 } // namespace autofill | 312 } // namespace autofill |
OLD | NEW |