OLD | NEW |
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 "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/password_manager/password_manager.h" | 8 #include "chrome/browser/password_manager/password_manager.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
11 #include "chrome/browser/sync/profile_sync_service_factory.h" | 11 #include "chrome/browser/sync/profile_sync_service_factory.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "components/autofill/core/browser/autofill_field.h" |
| 17 #include "components/autofill/core/browser/field_types.h" |
| 18 #include "components/autofill/core/browser/form_structure.h" |
16 #include "components/autofill/core/browser/password_generator.h" | 19 #include "components/autofill/core/browser/password_generator.h" |
17 #include "components/autofill/core/common/autofill_messages.h" | 20 #include "components/autofill/core/common/autofill_messages.h" |
| 21 #include "components/autofill/core/common/form_data.h" |
18 #include "components/user_prefs/pref_registry_syncable.h" | 22 #include "components/user_prefs/pref_registry_syncable.h" |
19 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/password_form.h" | 26 #include "content/public/common/password_form.h" |
23 #include "ipc/ipc_message_macros.h" | 27 #include "ipc/ipc_message_macros.h" |
24 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
25 | 29 |
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordGenerationManager); | 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordGenerationManager); |
27 | 31 |
(...skipping 20 matching lines...) Expand all Loading... |
48 | 52 |
49 // static | 53 // static |
50 void PasswordGenerationManager::RegisterProfilePrefs( | 54 void PasswordGenerationManager::RegisterProfilePrefs( |
51 user_prefs::PrefRegistrySyncable* registry) { | 55 user_prefs::PrefRegistrySyncable* registry) { |
52 registry->RegisterBooleanPref( | 56 registry->RegisterBooleanPref( |
53 prefs::kPasswordGenerationEnabled, | 57 prefs::kPasswordGenerationEnabled, |
54 true, | 58 true, |
55 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 59 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
56 } | 60 } |
57 | 61 |
| 62 void PasswordGenerationManager::DetectAccountCreationForms( |
| 63 const std::vector<autofill::FormStructure*>& forms) { |
| 64 std::vector<autofill::FormData> account_creation_forms; |
| 65 for (std::vector<autofill::FormStructure*>::const_iterator form_it = |
| 66 forms.begin(); form_it != forms.end(); ++form_it) { |
| 67 autofill::FormStructure* form = *form_it; |
| 68 for (std::vector<autofill::AutofillField*>::const_iterator field_it = |
| 69 form->begin(); field_it != form->end(); ++field_it) { |
| 70 autofill::AutofillField* field = *field_it; |
| 71 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) { |
| 72 account_creation_forms.push_back(form->ToFormData()); |
| 73 break; |
| 74 } |
| 75 } |
| 76 } |
| 77 SendAccountCreationFormsToRenderer(web_contents()->GetRenderViewHost(), |
| 78 account_creation_forms); |
| 79 } |
| 80 |
58 void PasswordGenerationManager::RegisterWithSyncService() { | 81 void PasswordGenerationManager::RegisterWithSyncService() { |
59 Profile* profile = Profile::FromBrowserContext( | 82 Profile* profile = Profile::FromBrowserContext( |
60 web_contents()->GetBrowserContext()); | 83 web_contents()->GetBrowserContext()); |
61 ProfileSyncService* sync_service = | 84 ProfileSyncService* sync_service = |
62 ProfileSyncServiceFactory::GetForProfile(profile); | 85 ProfileSyncServiceFactory::GetForProfile(profile); |
63 if (sync_service) | 86 if (sync_service) |
64 sync_service->AddObserver(this); | 87 sync_service->AddObserver(this); |
65 } | 88 } |
66 | 89 |
67 void PasswordGenerationManager::SetUpPrefChangeRegistrar() { | 90 void PasswordGenerationManager::SetUpPrefChangeRegistrar() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 SendStateToRenderer(host, enabled_); | 167 SendStateToRenderer(host, enabled_); |
145 } | 168 } |
146 } | 169 } |
147 | 170 |
148 void PasswordGenerationManager::SendStateToRenderer( | 171 void PasswordGenerationManager::SendStateToRenderer( |
149 content::RenderViewHost* host, bool enabled) { | 172 content::RenderViewHost* host, bool enabled) { |
150 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), | 173 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), |
151 enabled)); | 174 enabled)); |
152 } | 175 } |
153 | 176 |
| 177 void PasswordGenerationManager::SendAccountCreationFormsToRenderer( |
| 178 content::RenderViewHost* host, |
| 179 const std::vector<autofill::FormData>& forms) { |
| 180 host->Send(new AutofillMsg_AccountCreationFormsDetected( |
| 181 host->GetRoutingID(), forms)); |
| 182 } |
| 183 |
154 void PasswordGenerationManager::OnShowPasswordGenerationPopup( | 184 void PasswordGenerationManager::OnShowPasswordGenerationPopup( |
155 const gfx::Rect& bounds, | 185 const gfx::Rect& bounds, |
156 int max_length, | 186 int max_length, |
157 const content::PasswordForm& form) { | 187 const content::PasswordForm& form) { |
158 #if defined(OS_ANDROID) | 188 #if defined(OS_ANDROID) |
159 NOTIMPLEMENTED(); | 189 NOTIMPLEMENTED(); |
160 #else | 190 #else |
161 password_generator_.reset(new autofill::PasswordGenerator(max_length)); | 191 password_generator_.reset(new autofill::PasswordGenerator(max_length)); |
162 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 192 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
163 browser->window()->ShowPasswordGenerationBubble(bounds, | 193 browser->window()->ShowPasswordGenerationBubble(bounds, |
164 form, | 194 form, |
165 password_generator_.get()); | 195 password_generator_.get()); |
166 #endif // #if defined(OS_ANDROID) | 196 #endif // #if defined(OS_ANDROID) |
167 } | 197 } |
OLD | NEW |