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

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

Issue 151413008: Move ownership of Password(Generation)Manager to ContentPasswordDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix up unittests 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 | Annotate | Revision Log
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/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
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 18 matching lines...) Expand all
118 const gfx::RectF& bounds) { 121 const gfx::RectF& bounds) {
119 gfx::Rect client_area; 122 gfx::Rect client_area;
120 web_contents()->GetView()->GetContainerBounds(&client_area); 123 web_contents()->GetView()->GetContainerBounds(&client_area);
121 return bounds + client_area.OffsetFromOrigin(); 124 return bounds + client_area.OffsetFromOrigin();
122 } 125 }
123 126
124 void PasswordGenerationManager::OnShowPasswordGenerationPopup( 127 void PasswordGenerationManager::OnShowPasswordGenerationPopup(
125 const gfx::RectF& bounds, 128 const gfx::RectF& bounds,
126 int max_length, 129 int max_length,
127 const autofill::PasswordForm& form) { 130 const autofill::PasswordForm& form) {
131 // TODO(blundell): Should this short-circuit out if web_contents() is NULL?
Garrett Casto 2014/02/04 12:53:36 Won't web_contents_ always be valid if this object
blundell 2014/02/04 13:16:18 There is a period of time for WCO's when web_conte
132
128 // TODO(gcasto): Validate data in PasswordForm. 133 // TODO(gcasto): Validate data in PasswordForm.
129 134
130 // Only implemented for Aura right now. 135 // Only implemented for Aura right now.
131 #if defined(USE_AURA) 136 #if defined(USE_AURA)
132 // Convert element_bounds to be in screen space. 137 // Convert element_bounds to be in screen space.
133 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); 138 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds);
134 139
135 password_generator_.reset(new autofill::PasswordGenerator(max_length)); 140 password_generator_.reset(new autofill::PasswordGenerator(max_length));
136 141
137 popup_controller_ = 142 popup_controller_ =
138 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( 143 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate(
139 popup_controller_, 144 popup_controller_,
140 element_bounds_in_screen_space, 145 element_bounds_in_screen_space,
141 form, 146 form,
142 password_generator_.get(), 147 password_generator_.get(),
143 PasswordManager::FromWebContents(web_contents()), 148 driver_->GetPasswordManager(),
144 observer_, 149 observer_,
145 web_contents(), 150 web_contents(),
146 web_contents()->GetView()->GetNativeView()); 151 web_contents()->GetView()->GetNativeView());
147 popup_controller_->Show(); 152 popup_controller_->Show();
148 #endif // #if defined(USE_AURA) 153 #endif // #if defined(USE_AURA)
149 } 154 }
150 155
151 void PasswordGenerationManager::OnShowPasswordEditingPopup( 156 void PasswordGenerationManager::OnShowPasswordEditingPopup(
152 const gfx::RectF& bounds) { 157 const gfx::RectF& bounds) {
153 // TODO(gcasto): Enable this. 158 // TODO(gcasto): Enable this.
154 } 159 }
155 160
156 void PasswordGenerationManager::OnHidePasswordGenerationPopup() { 161 void PasswordGenerationManager::OnHidePasswordGenerationPopup() {
157 HidePopup(); 162 HidePopup();
158 } 163 }
159 164
160 void PasswordGenerationManager::HidePopup() { 165 void PasswordGenerationManager::HidePopup() {
161 if (popup_controller_) 166 if (popup_controller_)
162 popup_controller_->HideAndDestroy(); 167 popup_controller_->HideAndDestroy();
163 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698