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 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 namespace autofill { | 38 namespace autofill { |
39 | 39 |
40 base::WeakPtr<PasswordGenerationPopupControllerImpl> | 40 base::WeakPtr<PasswordGenerationPopupControllerImpl> |
41 PasswordGenerationPopupControllerImpl::GetOrCreate( | 41 PasswordGenerationPopupControllerImpl::GetOrCreate( |
42 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous, | 42 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous, |
43 const gfx::RectF& bounds, | 43 const gfx::RectF& bounds, |
44 const PasswordForm& form, | 44 const PasswordForm& form, |
45 int max_length, | 45 int max_length, |
46 password_manager::PasswordManager* password_manager, | 46 password_manager::PasswordManager* password_manager, |
| 47 password_manager::PasswordManagerDriver* driver, |
47 PasswordGenerationPopupObserver* observer, | 48 PasswordGenerationPopupObserver* observer, |
48 content::WebContents* web_contents, | 49 content::WebContents* web_contents, |
49 gfx::NativeView container_view) { | 50 gfx::NativeView container_view) { |
50 if (previous.get() && | 51 if (previous.get() && |
51 previous->element_bounds() == bounds && | 52 previous->element_bounds() == bounds && |
52 previous->web_contents() == web_contents && | 53 previous->web_contents() == web_contents && |
53 previous->container_view() == container_view) { | 54 previous->container_view() == container_view) { |
54 return previous; | 55 return previous; |
55 } | 56 } |
56 | 57 |
57 if (previous.get()) | 58 if (previous.get()) |
58 previous->Hide(); | 59 previous->Hide(); |
59 | 60 |
60 PasswordGenerationPopupControllerImpl* controller = | 61 PasswordGenerationPopupControllerImpl* controller = |
61 new PasswordGenerationPopupControllerImpl( | 62 new PasswordGenerationPopupControllerImpl( |
62 bounds, | 63 bounds, form, max_length, password_manager, driver, observer, |
63 form, | 64 web_contents, container_view); |
64 max_length, | |
65 password_manager, | |
66 observer, | |
67 web_contents, | |
68 container_view); | |
69 return controller->GetWeakPtr(); | 65 return controller->GetWeakPtr(); |
70 } | 66 } |
71 | 67 |
72 PasswordGenerationPopupControllerImpl::PasswordGenerationPopupControllerImpl( | 68 PasswordGenerationPopupControllerImpl::PasswordGenerationPopupControllerImpl( |
73 const gfx::RectF& bounds, | 69 const gfx::RectF& bounds, |
74 const PasswordForm& form, | 70 const PasswordForm& form, |
75 int max_length, | 71 int max_length, |
76 password_manager::PasswordManager* password_manager, | 72 password_manager::PasswordManager* password_manager, |
| 73 password_manager::PasswordManagerDriver* driver, |
77 PasswordGenerationPopupObserver* observer, | 74 PasswordGenerationPopupObserver* observer, |
78 content::WebContents* web_contents, | 75 content::WebContents* web_contents, |
79 gfx::NativeView container_view) | 76 gfx::NativeView container_view) |
80 : view_(NULL), | 77 : view_(NULL), |
81 form_(form), | 78 form_(form), |
82 password_manager_(password_manager), | 79 password_manager_(password_manager), |
| 80 driver_(driver), |
83 observer_(observer), | 81 observer_(observer), |
84 generator_(new PasswordGenerator(max_length)), | 82 generator_(new PasswordGenerator(max_length)), |
85 controller_common_(bounds, container_view, web_contents), | 83 controller_common_(bounds, container_view, web_contents), |
86 password_selected_(false), | 84 password_selected_(false), |
87 display_password_(false), | 85 display_password_(false), |
88 weak_ptr_factory_(this) { | 86 weak_ptr_factory_(this) { |
89 controller_common_.SetKeyPressCallback( | 87 controller_common_.SetKeyPressCallback( |
90 base::Bind(&PasswordGenerationPopupControllerImpl::HandleKeyPressEvent, | 88 base::Bind(&PasswordGenerationPopupControllerImpl::HandleKeyPressEvent, |
91 base::Unretained(this))); | 89 base::Unretained(this))); |
92 | 90 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 146 } |
149 | 147 |
150 void PasswordGenerationPopupControllerImpl::PasswordAccepted() { | 148 void PasswordGenerationPopupControllerImpl::PasswordAccepted() { |
151 if (!display_password_) | 149 if (!display_password_) |
152 return; | 150 return; |
153 | 151 |
154 web_contents()->GetRenderViewHost()->Send( | 152 web_contents()->GetRenderViewHost()->Send( |
155 new AutofillMsg_GeneratedPasswordAccepted( | 153 new AutofillMsg_GeneratedPasswordAccepted( |
156 web_contents()->GetRenderViewHost()->GetRoutingID(), | 154 web_contents()->GetRenderViewHost()->GetRoutingID(), |
157 current_password_)); | 155 current_password_)); |
158 password_manager_->SetFormHasGeneratedPassword(form_); | 156 password_manager_->SetFormHasGeneratedPassword(driver_, form_); |
159 Hide(); | 157 Hide(); |
160 } | 158 } |
161 | 159 |
162 int PasswordGenerationPopupControllerImpl::GetMinimumWidth() { | 160 int PasswordGenerationPopupControllerImpl::GetMinimumWidth() { |
163 // Minimum width in pixels. | 161 // Minimum width in pixels. |
164 const int minimum_width = 350; | 162 const int minimum_width = 350; |
165 | 163 |
166 // If the width of the field is longer than the minimum, use that instead. | 164 // If the width of the field is longer than the minimum, use that instead. |
167 return std::max(minimum_width, | 165 return std::max(minimum_width, |
168 controller_common_.RoundedElementBounds().width()); | 166 controller_common_.RoundedElementBounds().width()); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 281 |
284 base::string16 PasswordGenerationPopupControllerImpl::AccessibleName() { | 282 base::string16 PasswordGenerationPopupControllerImpl::AccessibleName() { |
285 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_ACCESSIBLE_TITLE); | 283 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_ACCESSIBLE_TITLE); |
286 } | 284 } |
287 | 285 |
288 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() { | 286 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() { |
289 return link_range_; | 287 return link_range_; |
290 } | 288 } |
291 | 289 |
292 } // namespace autofill | 290 } // namespace autofill |
OLD | NEW |