Chromium Code Reviews| 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" |
| 18 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
| 19 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/password_form.h" | 25 #include "content/public/common/password_form.h" |
| 23 #include "ipc/ipc_message_macros.h" | 26 #include "ipc/ipc_message_macros.h" |
| 24 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
| 25 | 28 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 48 | 51 |
| 49 // static | 52 // static |
| 50 void PasswordGenerationManager::RegisterProfilePrefs( | 53 void PasswordGenerationManager::RegisterProfilePrefs( |
| 51 user_prefs::PrefRegistrySyncable* registry) { | 54 user_prefs::PrefRegistrySyncable* registry) { |
| 52 registry->RegisterBooleanPref( | 55 registry->RegisterBooleanPref( |
| 53 prefs::kPasswordGenerationEnabled, | 56 prefs::kPasswordGenerationEnabled, |
| 54 true, | 57 true, |
| 55 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 58 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 56 } | 59 } |
| 57 | 60 |
| 61 void PasswordGenerationManager::DetectAccountCreationForms( | |
| 62 const std::vector<autofill::FormStructure*>& forms) { | |
| 63 std::vector<GURL> account_creation_form_origins; | |
| 64 for (std::vector<autofill::FormStructure*>::const_iterator form_it = | |
| 65 forms.begin(); form_it != forms.end(); ++form_it) { | |
| 66 autofill::FormStructure* form = *form_it; | |
| 67 for (std::vector<autofill::AutofillField*>::const_iterator field_it = | |
| 68 form->begin(); field_it != form->end(); ++field_it) { | |
|
Ilya Sherman
2013/08/29 23:08:13
nit: Indent this line 5 more spaces.
zysxqn
2013/09/03 23:00:20
Done.
| |
| 69 autofill::AutofillField* field = *field_it; | |
| 70 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) { | |
| 71 account_creation_form_origins.push_back(form->source_url()); | |
|
Garrett Casto
2013/08/29 22:45:13
So I don't have an example to point to right now,
zysxqn
2013/09/03 23:00:20
Done.
| |
| 72 break; | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 SendAccountCreationFormsToRenderer(web_contents()->GetRenderViewHost(), | |
| 77 account_creation_form_origins); | |
| 78 } | |
| 79 | |
| 58 void PasswordGenerationManager::RegisterWithSyncService() { | 80 void PasswordGenerationManager::RegisterWithSyncService() { |
| 59 Profile* profile = Profile::FromBrowserContext( | 81 Profile* profile = Profile::FromBrowserContext( |
| 60 web_contents()->GetBrowserContext()); | 82 web_contents()->GetBrowserContext()); |
| 61 ProfileSyncService* sync_service = | 83 ProfileSyncService* sync_service = |
| 62 ProfileSyncServiceFactory::GetForProfile(profile); | 84 ProfileSyncServiceFactory::GetForProfile(profile); |
| 63 if (sync_service) | 85 if (sync_service) |
| 64 sync_service->AddObserver(this); | 86 sync_service->AddObserver(this); |
| 65 } | 87 } |
| 66 | 88 |
| 67 void PasswordGenerationManager::SetUpPrefChangeRegistrar() { | 89 void PasswordGenerationManager::SetUpPrefChangeRegistrar() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 SendStateToRenderer(host, enabled_); | 166 SendStateToRenderer(host, enabled_); |
| 145 } | 167 } |
| 146 } | 168 } |
| 147 | 169 |
| 148 void PasswordGenerationManager::SendStateToRenderer( | 170 void PasswordGenerationManager::SendStateToRenderer( |
| 149 content::RenderViewHost* host, bool enabled) { | 171 content::RenderViewHost* host, bool enabled) { |
| 150 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), | 172 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), |
| 151 enabled)); | 173 enabled)); |
| 152 } | 174 } |
| 153 | 175 |
| 176 void PasswordGenerationManager::SendAccountCreationFormsToRenderer( | |
| 177 content::RenderViewHost* host, const std::vector<GURL>& origins) { | |
| 178 host->Send(new AutofillMsg_AccountCreationFormsDetected( | |
| 179 host->GetRoutingID(), origins)); | |
| 180 } | |
|
Ilya Sherman
2013/08/29 23:08:13
nit: Why not just inline this method?
zysxqn
2013/09/03 23:00:20
I don't have strong preference on this one but I u
| |
| 181 | |
| 154 void PasswordGenerationManager::OnShowPasswordGenerationPopup( | 182 void PasswordGenerationManager::OnShowPasswordGenerationPopup( |
| 155 const gfx::Rect& bounds, | 183 const gfx::Rect& bounds, |
| 156 int max_length, | 184 int max_length, |
| 157 const content::PasswordForm& form) { | 185 const content::PasswordForm& form) { |
| 158 #if defined(OS_ANDROID) | 186 #if defined(OS_ANDROID) |
| 159 NOTIMPLEMENTED(); | 187 NOTIMPLEMENTED(); |
| 160 #else | 188 #else |
| 161 password_generator_.reset(new autofill::PasswordGenerator(max_length)); | 189 password_generator_.reset(new autofill::PasswordGenerator(max_length)); |
| 162 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 190 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 163 browser->window()->ShowPasswordGenerationBubble(bounds, | 191 browser->window()->ShowPasswordGenerationBubble(bounds, |
| 164 form, | 192 form, |
| 165 password_generator_.get()); | 193 password_generator_.get()); |
| 166 #endif // #if defined(OS_ANDROID) | 194 #endif // #if defined(OS_ANDROID) |
| 167 } | 195 } |
| OLD | NEW |