| 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 "chrome/browser/password_manager/password_manager.h" | 7 #include "chrome/browser/password_manager/password_manager.h" |
| 8 #include "chrome/browser/password_manager/password_manager_delegate.h" |
| 9 #include "chrome/browser/password_manager/password_manager_driver.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/sync/profile_sync_service.h" | 11 #include "chrome/browser/sync/profile_sync_service.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_factory.h" | 12 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 11 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" | 13 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "components/autofill/content/common/autofill_messages.h" | 17 #include "components/autofill/content/common/autofill_messages.h" |
| 16 #include "components/autofill/core/browser/autofill_field.h" | 18 #include "components/autofill/core/browser/autofill_field.h" |
| 17 #include "components/autofill/core/browser/field_types.h" | 19 #include "components/autofill/core/browser/field_types.h" |
| 18 #include "components/autofill/core/browser/form_structure.h" | 20 #include "components/autofill/core/browser/form_structure.h" |
| 19 #include "components/autofill/core/browser/password_generator.h" | 21 #include "components/autofill/core/browser/password_generator.h" |
| 20 #include "components/autofill/core/common/form_data.h" | 22 #include "components/autofill/core/common/form_data.h" |
| 21 #include "components/autofill/core/common/password_form.h" | 23 #include "components/autofill/core/common/password_form.h" |
| 22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_view.h" | 27 #include "content/public/browser/web_contents_view.h" |
| 26 #include "ipc/ipc_message_macros.h" | 28 #include "ipc/ipc_message_macros.h" |
| 27 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 28 | 30 |
| 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordGenerationManager); | |
| 30 | |
| 31 PasswordGenerationManager::PasswordGenerationManager( | 31 PasswordGenerationManager::PasswordGenerationManager( |
| 32 content::WebContents* contents) | 32 content::WebContents* contents, |
| 33 PasswordManagerDelegate* delegate) |
| 33 : content::WebContentsObserver(contents), | 34 : content::WebContentsObserver(contents), |
| 34 observer_(NULL) {} | 35 observer_(NULL), |
| 36 delegate_(delegate), |
| 37 driver_(delegate->GetDriver()) {} |
| 35 | 38 |
| 36 PasswordGenerationManager::~PasswordGenerationManager() {} | 39 PasswordGenerationManager::~PasswordGenerationManager() {} |
| 37 | 40 |
| 38 void PasswordGenerationManager::SetTestObserver( | 41 void PasswordGenerationManager::SetTestObserver( |
| 39 autofill::PasswordGenerationPopupObserver* observer) { | 42 autofill::PasswordGenerationPopupObserver* observer) { |
| 40 observer_ = observer; | 43 observer_ = observer; |
| 41 } | 44 } |
| 42 | 45 |
| 43 void PasswordGenerationManager::DetectAccountCreationForms( | 46 void PasswordGenerationManager::DetectAccountCreationForms( |
| 44 const std::vector<autofill::FormStructure*>& forms) { | 47 const std::vector<autofill::FormStructure*>& forms) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // In order for password generation to be enabled, we need to make sure: | 82 // In order for password generation to be enabled, we need to make sure: |
| 80 // (1) Password sync is enabled, and | 83 // (1) Password sync is enabled, and |
| 81 // (2) Password saving is enabled. | 84 // (2) Password saving is enabled. |
| 82 bool PasswordGenerationManager::IsGenerationEnabled() const { | 85 bool PasswordGenerationManager::IsGenerationEnabled() const { |
| 83 if (!web_contents()) | 86 if (!web_contents()) |
| 84 return false; | 87 return false; |
| 85 | 88 |
| 86 Profile* profile = Profile::FromBrowserContext( | 89 Profile* profile = Profile::FromBrowserContext( |
| 87 web_contents()->GetBrowserContext()); | 90 web_contents()->GetBrowserContext()); |
| 88 | 91 |
| 89 if (!PasswordManager::FromWebContents(web_contents())->IsSavingEnabled()) { | 92 if (!driver_->GetPasswordManager()->IsSavingEnabled()) { |
| 90 DVLOG(2) << "Generation disabled because password saving is disabled"; | 93 DVLOG(2) << "Generation disabled because password saving is disabled"; |
| 91 return false; | 94 return false; |
| 92 } | 95 } |
| 93 | 96 |
| 94 bool password_sync_enabled = false; | 97 bool password_sync_enabled = false; |
| 95 ProfileSyncService* sync_service = | 98 ProfileSyncService* sync_service = |
| 96 ProfileSyncServiceFactory::GetForProfile(profile); | 99 ProfileSyncServiceFactory::GetForProfile(profile); |
| 97 if (sync_service) { | 100 if (sync_service) { |
| 98 syncer::ModelTypeSet sync_set = sync_service->GetActiveDataTypes(); | 101 syncer::ModelTypeSet sync_set = sync_service->GetActiveDataTypes(); |
| 99 password_sync_enabled = (sync_service->HasSyncSetupCompleted() && | 102 password_sync_enabled = (sync_service->HasSyncSetupCompleted() && |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 136 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 134 | 137 |
| 135 password_generator_.reset(new autofill::PasswordGenerator(max_length)); | 138 password_generator_.reset(new autofill::PasswordGenerator(max_length)); |
| 136 | 139 |
| 137 popup_controller_ = | 140 popup_controller_ = |
| 138 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 141 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 139 popup_controller_, | 142 popup_controller_, |
| 140 element_bounds_in_screen_space, | 143 element_bounds_in_screen_space, |
| 141 form, | 144 form, |
| 142 password_generator_.get(), | 145 password_generator_.get(), |
| 143 PasswordManager::FromWebContents(web_contents()), | 146 driver_->GetPasswordManager(), |
| 144 observer_, | 147 observer_, |
| 145 web_contents(), | 148 web_contents(), |
| 146 web_contents()->GetView()->GetNativeView()); | 149 web_contents()->GetView()->GetNativeView()); |
| 147 popup_controller_->Show(); | 150 popup_controller_->Show(); |
| 148 #endif // #if defined(USE_AURA) | 151 #endif // #if defined(USE_AURA) |
| 149 } | 152 } |
| 150 | 153 |
| 151 void PasswordGenerationManager::OnShowPasswordEditingPopup( | 154 void PasswordGenerationManager::OnShowPasswordEditingPopup( |
| 152 const gfx::RectF& bounds) { | 155 const gfx::RectF& bounds) { |
| 153 // TODO(gcasto): Enable this. | 156 // TODO(gcasto): Enable this. |
| 154 } | 157 } |
| 155 | 158 |
| 156 void PasswordGenerationManager::OnHidePasswordGenerationPopup() { | 159 void PasswordGenerationManager::OnHidePasswordGenerationPopup() { |
| 157 HidePopup(); | 160 HidePopup(); |
| 158 } | 161 } |
| 159 | 162 |
| 160 void PasswordGenerationManager::HidePopup() { | 163 void PasswordGenerationManager::HidePopup() { |
| 161 if (popup_controller_) | 164 if (popup_controller_) |
| 162 popup_controller_->HideAndDestroy(); | 165 popup_controller_->HideAndDestroy(); |
| 163 } | 166 } |
| OLD | NEW |