Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/autofill/password_generation_manager.h" | 5 #include "chrome/renderer/autofill/password_generation_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/common/autofill_messages.h" | 8 #include "chrome/common/autofill_messages.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 17 | 17 |
| 18 namespace autofill { | 18 namespace autofill { |
| 19 | 19 |
| 20 PasswordGenerationManager::PasswordGenerationManager( | 20 PasswordGenerationManager::PasswordGenerationManager( |
| 21 content::RenderView* render_view) | 21 content::RenderView* render_view) |
| 22 : content::RenderViewObserver(render_view), | 22 : content::RenderViewObserver(render_view), |
| 23 enabled_(false) {} | 23 enabled_(false) {} |
| 24 PasswordGenerationManager::~PasswordGenerationManager() {} | 24 PasswordGenerationManager::~PasswordGenerationManager() {} |
| 25 | 25 |
| 26 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { | 26 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { |
| 27 // We don't want to generate passwords if the browser won't store or sync | 27 // We don't want to generate passwords if browser doesn't think so. |
|
Ilya Sherman
2012/05/01 22:27:48
nit: Please preserve the previous comment, or else
zysxqn
2012/05/03 00:57:24
Done.
| |
| 28 // them. | |
| 29 if (!enabled_) | 28 if (!enabled_) |
| 30 return; | 29 return; |
| 31 | 30 |
| 32 if (!ShouldAnalyzeFrame(*frame)) | 31 if (!ShouldAnalyzeFrame(*frame)) |
| 33 return; | 32 return; |
| 34 | 33 |
| 35 WebKit::WebVector<WebKit::WebFormElement> forms; | 34 WebKit::WebVector<WebKit::WebFormElement> forms; |
| 36 frame->document().forms(forms); | 35 frame->document().forms(forms); |
| 37 for (size_t i = 0; i < forms.size(); ++i) { | 36 for (size_t i = 0; i < forms.size(); ++i) { |
| 38 const WebKit::WebFormElement& web_form = forms[i]; | 37 const WebKit::WebFormElement& web_form = forms[i]; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 rect)); | 83 rect)); |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { | 87 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { |
| 89 bool handled = true; | 88 bool handled = true; |
| 90 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) | 89 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) |
| 91 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, | 90 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, |
| 92 OnPasswordAccepted) | 91 OnPasswordAccepted) |
| 93 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, | 92 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, |
| 94 OnPasswordSyncEnabled) | 93 OnPasswordGenerationEnabled) |
|
Ilya Sherman
2012/05/01 22:27:48
Good catch, thanks for fixing this :)
| |
| 95 IPC_MESSAGE_UNHANDLED(handled = false) | 94 IPC_MESSAGE_UNHANDLED(handled = false) |
| 96 IPC_END_MESSAGE_MAP() | 95 IPC_END_MESSAGE_MAP() |
| 97 return handled; | 96 return handled; |
| 98 } | 97 } |
| 99 | 98 |
| 100 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { | 99 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { |
| 101 for (std::vector<WebKit::WebInputElement>::iterator it = | 100 for (std::vector<WebKit::WebInputElement>::iterator it = |
| 102 account_creation_elements_.second.begin(); | 101 account_creation_elements_.second.begin(); |
| 103 it != account_creation_elements_.second.end(); ++it) { | 102 it != account_creation_elements_.second.end(); ++it) { |
| 104 it->setValue(password); | 103 it->setValue(password); |
| 105 it->setAutofilled(true); | 104 it->setAutofilled(true); |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 | 107 |
| 109 void PasswordGenerationManager::OnPasswordSyncEnabled(bool enabled) { | 108 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { |
| 110 enabled_ = enabled; | 109 enabled_ = enabled; |
| 111 } | 110 } |
| 112 | 111 |
| 113 } // namespace autofill | 112 } // namespace autofill |
| OLD | NEW |