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

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

Issue 156173004: Abstract IPC send out of PasswordGenerationManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + response to review 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_client.h" 8 #include "chrome/browser/password_manager/password_manager_client.h"
9 #include "chrome/browser/password_manager/password_manager_driver.h" 9 #include "chrome/browser/password_manager/password_manager_driver.h"
10 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " 10 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h "
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "components/autofill/content/common/autofill_messages.h" 14 #include "components/autofill/content/common/autofill_messages.h"
15 #include "components/autofill/core/browser/autofill_field.h" 15 #include "components/autofill/core/browser/autofill_field.h"
16 #include "components/autofill/core/browser/field_types.h" 16 #include "components/autofill/core/browser/field_types.h"
17 #include "components/autofill/core/browser/form_structure.h" 17 #include "components/autofill/core/browser/form_structure.h"
18 #include "components/autofill/core/browser/password_generator.h" 18 #include "components/autofill/core/browser/password_generator.h"
19 #include "components/autofill/core/common/form_data.h" 19 #include "components/autofill/core/common/form_data.h"
20 #include "components/autofill/core/common/password_form.h" 20 #include "components/autofill/core/common/password_form.h"
21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_contents_view.h" 22 #include "content/public/browser/web_contents_view.h"
24 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
25 24
26 PasswordGenerationManager::PasswordGenerationManager( 25 PasswordGenerationManager::PasswordGenerationManager(
27 content::WebContents* contents, 26 content::WebContents* contents,
28 PasswordManagerClient* client) 27 PasswordManagerClient* client)
29 : web_contents_(contents), 28 : web_contents_(contents),
30 observer_(NULL), 29 observer_(NULL),
31 client_(client), 30 client_(client),
(...skipping 14 matching lines...) Expand all
46 autofill::FormStructure* form = *form_it; 45 autofill::FormStructure* form = *form_it;
47 for (std::vector<autofill::AutofillField*>::const_iterator field_it = 46 for (std::vector<autofill::AutofillField*>::const_iterator field_it =
48 form->begin(); field_it != form->end(); ++field_it) { 47 form->begin(); field_it != form->end(); ++field_it) {
49 autofill::AutofillField* field = *field_it; 48 autofill::AutofillField* field = *field_it;
50 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) { 49 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) {
51 account_creation_forms.push_back(form->ToFormData()); 50 account_creation_forms.push_back(form->ToFormData());
52 break; 51 break;
53 } 52 }
54 } 53 }
55 } 54 }
56 if (!account_creation_forms.empty() && IsGenerationEnabled()) { 55 if (!account_creation_forms.empty() && IsGenerationEnabled())
57 SendAccountCreationFormsToRenderer(web_contents_->GetRenderViewHost(), 56 driver_->AccountCreationFormsFound(account_creation_forms);
58 account_creation_forms);
59 }
60 } 57 }
61 58
62 // In order for password generation to be enabled, we need to make sure: 59 // In order for password generation to be enabled, we need to make sure:
63 // (1) Password sync is enabled, and 60 // (1) Password sync is enabled, and
64 // (2) Password saving is enabled. 61 // (2) Password saving is enabled.
65 bool PasswordGenerationManager::IsGenerationEnabled() const { 62 bool PasswordGenerationManager::IsGenerationEnabled() const {
66 if (!driver_->GetPasswordManager()->IsSavingEnabled()) { 63 if (!driver_->GetPasswordManager()->IsSavingEnabled()) {
67 DVLOG(2) << "Generation disabled because password saving is disabled"; 64 DVLOG(2) << "Generation disabled because password saving is disabled";
68 return false; 65 return false;
69 } 66 }
70 67
71 if (!client_->IsPasswordSyncEnabled()) { 68 if (!client_->IsPasswordSyncEnabled()) {
72 DVLOG(2) << "Generation disabled because passwords are not being synced"; 69 DVLOG(2) << "Generation disabled because passwords are not being synced";
73 return false; 70 return false;
74 } 71 }
75 72
76 return true; 73 return true;
77 } 74 }
78 75
79 void PasswordGenerationManager::SendAccountCreationFormsToRenderer(
80 content::RenderViewHost* host,
81 const std::vector<autofill::FormData>& forms) {
82 host->Send(new AutofillMsg_AccountCreationFormsDetected(
83 host->GetRoutingID(), forms));
84 }
85
86 gfx::RectF PasswordGenerationManager::GetBoundsInScreenSpace( 76 gfx::RectF PasswordGenerationManager::GetBoundsInScreenSpace(
87 const gfx::RectF& bounds) { 77 const gfx::RectF& bounds) {
88 gfx::Rect client_area; 78 gfx::Rect client_area;
89 web_contents_->GetView()->GetContainerBounds(&client_area); 79 web_contents_->GetView()->GetContainerBounds(&client_area);
90 return bounds + client_area.OffsetFromOrigin(); 80 return bounds + client_area.OffsetFromOrigin();
91 } 81 }
92 82
93 void PasswordGenerationManager::OnShowPasswordGenerationPopup( 83 void PasswordGenerationManager::OnShowPasswordGenerationPopup(
94 const gfx::RectF& bounds, 84 const gfx::RectF& bounds,
95 int max_length, 85 int max_length,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 129 }
140 130
141 void PasswordGenerationManager::OnHidePasswordGenerationPopup() { 131 void PasswordGenerationManager::OnHidePasswordGenerationPopup() {
142 HidePopup(); 132 HidePopup();
143 } 133 }
144 134
145 void PasswordGenerationManager::HidePopup() { 135 void PasswordGenerationManager::HidePopup() {
146 if (popup_controller_) 136 if (popup_controller_)
147 popup_controller_->HideAndDestroy(); 137 popup_controller_->HideAndDestroy();
148 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698