| 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_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/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/render_view_host.h" | |
| 23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_view.h" | 23 #include "content/public/browser/web_contents_view.h" |
| 25 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| 26 | 25 |
| 27 PasswordGenerationManager::PasswordGenerationManager( | 26 PasswordGenerationManager::PasswordGenerationManager( |
| 28 content::WebContents* contents, | 27 content::WebContents* contents, |
| 29 PasswordManagerClient* client) | 28 PasswordManagerClient* client) |
| 30 : web_contents_(contents), | 29 : web_contents_(contents), |
| 31 observer_(NULL), | 30 observer_(NULL), |
| 32 client_(client), | 31 client_(client), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 47 autofill::FormStructure* form = *form_it; | 46 autofill::FormStructure* form = *form_it; |
| 48 for (std::vector<autofill::AutofillField*>::const_iterator field_it = | 47 for (std::vector<autofill::AutofillField*>::const_iterator field_it = |
| 49 form->begin(); field_it != form->end(); ++field_it) { | 48 form->begin(); field_it != form->end(); ++field_it) { |
| 50 autofill::AutofillField* field = *field_it; | 49 autofill::AutofillField* field = *field_it; |
| 51 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) { | 50 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD) { |
| 52 account_creation_forms.push_back(form->ToFormData()); | 51 account_creation_forms.push_back(form->ToFormData()); |
| 53 break; | 52 break; |
| 54 } | 53 } |
| 55 } | 54 } |
| 56 } | 55 } |
| 57 if (!account_creation_forms.empty() && IsGenerationEnabled()) { | 56 if (!account_creation_forms.empty() && IsGenerationEnabled()) |
| 58 SendAccountCreationFormsToRenderer(web_contents_->GetRenderViewHost(), | 57 driver_->AccountCreationFormsFound(account_creation_forms); |
| 59 account_creation_forms); | |
| 60 } | |
| 61 } | 58 } |
| 62 | 59 |
| 63 // In order for password generation to be enabled, we need to make sure: | 60 // In order for password generation to be enabled, we need to make sure: |
| 64 // (1) Password sync is enabled, and | 61 // (1) Password sync is enabled, and |
| 65 // (2) Password saving is enabled. | 62 // (2) Password saving is enabled. |
| 66 bool PasswordGenerationManager::IsGenerationEnabled() const { | 63 bool PasswordGenerationManager::IsGenerationEnabled() const { |
| 67 if (!driver_->GetPasswordManager()->IsSavingEnabled()) { | 64 if (!driver_->GetPasswordManager()->IsSavingEnabled()) { |
| 68 DVLOG(2) << "Generation disabled because password saving is disabled"; | 65 DVLOG(2) << "Generation disabled because password saving is disabled"; |
| 69 return false; | 66 return false; |
| 70 } | 67 } |
| 71 | 68 |
| 72 if (!client_->IsPasswordSyncEnabled()) { | 69 if (!client_->IsPasswordSyncEnabled()) { |
| 73 DVLOG(2) << "Generation disabled because passwords are not being synced"; | 70 DVLOG(2) << "Generation disabled because passwords are not being synced"; |
| 74 return false; | 71 return false; |
| 75 } | 72 } |
| 76 | 73 |
| 77 return true; | 74 return true; |
| 78 } | 75 } |
| 79 | 76 |
| 80 void PasswordGenerationManager::SendAccountCreationFormsToRenderer( | |
| 81 content::RenderViewHost* host, | |
| 82 const std::vector<autofill::FormData>& forms) { | |
| 83 host->Send(new AutofillMsg_AccountCreationFormsDetected( | |
| 84 host->GetRoutingID(), forms)); | |
| 85 } | |
| 86 | |
| 87 gfx::RectF PasswordGenerationManager::GetBoundsInScreenSpace( | 77 gfx::RectF PasswordGenerationManager::GetBoundsInScreenSpace( |
| 88 const gfx::RectF& bounds) { | 78 const gfx::RectF& bounds) { |
| 89 gfx::Rect client_area; | 79 gfx::Rect client_area; |
| 90 web_contents_->GetView()->GetContainerBounds(&client_area); | 80 web_contents_->GetView()->GetContainerBounds(&client_area); |
| 91 return bounds + client_area.OffsetFromOrigin(); | 81 return bounds + client_area.OffsetFromOrigin(); |
| 92 } | 82 } |
| 93 | 83 |
| 94 void PasswordGenerationManager::OnShowPasswordGenerationPopup( | 84 void PasswordGenerationManager::OnShowPasswordGenerationPopup( |
| 95 const gfx::RectF& bounds, | 85 const gfx::RectF& bounds, |
| 96 int max_length, | 86 int max_length, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 124 } | 114 } |
| 125 | 115 |
| 126 void PasswordGenerationManager::OnHidePasswordGenerationPopup() { | 116 void PasswordGenerationManager::OnHidePasswordGenerationPopup() { |
| 127 HidePopup(); | 117 HidePopup(); |
| 128 } | 118 } |
| 129 | 119 |
| 130 void PasswordGenerationManager::HidePopup() { | 120 void PasswordGenerationManager::HidePopup() { |
| 131 if (popup_controller_) | 121 if (popup_controller_) |
| 132 popup_controller_->HideAndDestroy(); | 122 popup_controller_->HideAndDestroy(); |
| 133 } | 123 } |
| OLD | NEW |