Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: chrome/browser/password_manager/password_generation_manager.cc

Issue 147533005: [Password Generation] Update UI to match final mocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replace_password_generation_ui
Patch Set: Merge Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/password_manager/password_generation_manager.h" 5 #include "chrome/browser/password_manager/password_generation_manager.h"
6 6
7 #include "chrome/browser/password_manager/password_manager.h" 7 #include "chrome/browser/password_manager/password_manager.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/profile_sync_service.h" 9 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/sync/profile_sync_service_factory.h" 10 #include "chrome/browser/sync/profile_sync_service_factory.h"
11 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h "
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
14 #include "components/autofill/content/common/autofill_messages.h" 15 #include "components/autofill/content/common/autofill_messages.h"
15 #include "components/autofill/core/browser/autofill_field.h" 16 #include "components/autofill/core/browser/autofill_field.h"
16 #include "components/autofill/core/browser/field_types.h" 17 #include "components/autofill/core/browser/field_types.h"
17 #include "components/autofill/core/browser/form_structure.h" 18 #include "components/autofill/core/browser/form_structure.h"
18 #include "components/autofill/core/browser/password_generator.h" 19 #include "components/autofill/core/browser/password_generator.h"
19 #include "components/autofill/core/common/form_data.h" 20 #include "components/autofill/core/common/form_data.h"
20 #include "components/autofill/core/common/password_form.h" 21 #include "components/autofill/core/common/password_form.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_view.h"
24 #include "ipc/ipc_message_macros.h" 26 #include "ipc/ipc_message_macros.h"
25 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
26 28
27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordGenerationManager); 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordGenerationManager);
28 30
29 PasswordGenerationManager::PasswordGenerationManager( 31 PasswordGenerationManager::PasswordGenerationManager(
30 content::WebContents* contents) 32 content::WebContents* contents)
31 : content::WebContentsObserver(contents) {} 33 : content::WebContentsObserver(contents),
34 observer_(NULL) {}
32 35
33 PasswordGenerationManager::~PasswordGenerationManager() {} 36 PasswordGenerationManager::~PasswordGenerationManager() {}
34 37
38 void PasswordGenerationManager::SetTestObserver(
39 autofill::PasswordGenerationPopupObserver* observer) {
40 observer_ = observer;
41 }
42
35 void PasswordGenerationManager::DetectAccountCreationForms( 43 void PasswordGenerationManager::DetectAccountCreationForms(
36 const std::vector<autofill::FormStructure*>& forms) { 44 const std::vector<autofill::FormStructure*>& forms) {
37 std::vector<autofill::FormData> account_creation_forms; 45 std::vector<autofill::FormData> account_creation_forms;
38 for (std::vector<autofill::FormStructure*>::const_iterator form_it = 46 for (std::vector<autofill::FormStructure*>::const_iterator form_it =
39 forms.begin(); form_it != forms.end(); ++form_it) { 47 forms.begin(); form_it != forms.end(); ++form_it) {
40 autofill::FormStructure* form = *form_it; 48 autofill::FormStructure* form = *form_it;
41 for (std::vector<autofill::AutofillField*>::const_iterator field_it = 49 for (std::vector<autofill::AutofillField*>::const_iterator field_it =
42 form->begin(); field_it != form->end(); ++field_it) { 50 form->begin(); field_it != form->end(); ++field_it) {
43 autofill::AutofillField* field = *field_it; 51 autofill::AutofillField* field = *field_it;
44 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) { 52 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) {
45 account_creation_forms.push_back(form->ToFormData()); 53 account_creation_forms.push_back(form->ToFormData());
46 break; 54 break;
47 } 55 }
48 } 56 }
49 } 57 }
50 if (!account_creation_forms.empty() && IsGenerationEnabled()) { 58 if (!account_creation_forms.empty() && IsGenerationEnabled()) {
51 SendAccountCreationFormsToRenderer(web_contents()->GetRenderViewHost(), 59 SendAccountCreationFormsToRenderer(web_contents()->GetRenderViewHost(),
52 account_creation_forms); 60 account_creation_forms);
53 } 61 }
54 } 62 }
55 63
56 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { 64 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) {
57 bool handled = true; 65 bool handled = true;
58 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) 66 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message)
59 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, 67 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup,
60 OnShowPasswordGenerationPopup) 68 OnShowPasswordGenerationPopup)
69 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup,
70 OnShowPasswordEditingPopup)
71 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup,
72 OnHidePasswordGenerationPopup)
61 IPC_MESSAGE_UNHANDLED(handled = false) 73 IPC_MESSAGE_UNHANDLED(handled = false)
62 IPC_END_MESSAGE_MAP() 74 IPC_END_MESSAGE_MAP()
63 75
64 return handled; 76 return handled;
65 } 77 }
66 78
67 // In order for password generation to be enabled, we need to make sure: 79 // In order for password generation to be enabled, we need to make sure:
68 // (1) Password sync is enabled, and 80 // (1) Password sync is enabled, and
69 // (2) Password saving is enabled. 81 // (2) Password saving is enabled.
70 bool PasswordGenerationManager::IsGenerationEnabled() const { 82 bool PasswordGenerationManager::IsGenerationEnabled() const {
(...skipping 24 matching lines...) Expand all
95 return true; 107 return true;
96 } 108 }
97 109
98 void PasswordGenerationManager::SendAccountCreationFormsToRenderer( 110 void PasswordGenerationManager::SendAccountCreationFormsToRenderer(
99 content::RenderViewHost* host, 111 content::RenderViewHost* host,
100 const std::vector<autofill::FormData>& forms) { 112 const std::vector<autofill::FormData>& forms) {
101 host->Send(new AutofillMsg_AccountCreationFormsDetected( 113 host->Send(new AutofillMsg_AccountCreationFormsDetected(
102 host->GetRoutingID(), forms)); 114 host->GetRoutingID(), forms));
103 } 115 }
104 116
117 gfx::RectF PasswordGenerationManager::GetBoundsInScreenSpace(
118 const gfx::RectF& bounds) {
119 gfx::Rect client_area;
120 web_contents()->GetView()->GetContainerBounds(&client_area);
121 return bounds + client_area.OffsetFromOrigin();
122 }
123
105 void PasswordGenerationManager::OnShowPasswordGenerationPopup( 124 void PasswordGenerationManager::OnShowPasswordGenerationPopup(
106 const gfx::Rect& bounds, 125 const gfx::RectF& bounds,
107 int max_length, 126 int max_length,
108 const autofill::PasswordForm& form) { 127 const autofill::PasswordForm& form) {
109 #if defined(OS_ANDROID) 128 // TODO(gcasto): Validate data in PasswordForm.
110 NOTIMPLEMENTED(); 129 form_ = form;
111 #else 130
131 // Only implemented for Aura right now.
132 #if defined(USE_AURA)
133 // Convert element_bounds to be in screen space.
134 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds);
135
112 password_generator_.reset(new autofill::PasswordGenerator(max_length)); 136 password_generator_.reset(new autofill::PasswordGenerator(max_length));
113 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 137
114 browser->window()->ShowPasswordGenerationBubble(bounds, 138 popup_controller_ =
115 form, 139 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate(
116 password_generator_.get()); 140 popup_controller_,
117 #endif // #if defined(OS_ANDROID) 141 element_bounds_in_screen_space,
142 &form_,
143 password_generator_.get(),
144 PasswordManager::FromWebContents(web_contents()),
145 observer_,
146 web_contents(),
147 web_contents()->GetView()->GetNativeView());
148 popup_controller_->Show(true /* display_password */);
149 #endif // #if defined(USE_AURA)
118 } 150 }
151
152 void PasswordGenerationManager::OnShowPasswordEditingPopup(
153 const gfx::RectF& bounds) {
154 // Only implemented for Aura right now.
155 #if defined(USE_AURA)
156 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds);
157
158 popup_controller_ =
159 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate(
160 popup_controller_,
161 element_bounds_in_screen_space,
162 NULL,
163 NULL,
164 NULL,
165 observer_,
166 web_contents(),
167 web_contents()->GetView()->GetNativeView());
168 popup_controller_->Show(false /* display_password */);
169 #endif // #if defined(USE_AURA)
170 }
171
172 void PasswordGenerationManager::OnHidePasswordGenerationPopup() {
173 HidePopup();
174 }
175
176 void PasswordGenerationManager::HidePopup() {
177 if (popup_controller_)
178 popup_controller_->HideAndDestroy();
179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698