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

Side by Side Diff: chrome/renderer/autofill/password_generation_manager.cc

Issue 10168017: Only enable password generation if password manager and autofill are both (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comments Created 8 years, 7 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 (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 sync_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 password sync isn't enabled. 27 // We don't want to generate passwords if the browser won't store or sync
28 if (!sync_enabled_) 28 // them.
29 if (!enabled_)
29 return; 30 return;
30 31
31 if (!ShouldAnalyzeFrame(*frame)) 32 if (!ShouldAnalyzeFrame(*frame))
32 return; 33 return;
33 34
34 WebKit::WebVector<WebKit::WebFormElement> forms; 35 WebKit::WebVector<WebKit::WebFormElement> forms;
35 frame->document().forms(forms); 36 frame->document().forms(forms);
36 for (size_t i = 0; i < forms.size(); ++i) { 37 for (size_t i = 0; i < forms.size(); ++i) {
37 const WebKit::WebFormElement& web_form = forms[i]; 38 const WebKit::WebFormElement& web_form = forms[i];
38 if (!web_form.autoComplete()) 39 if (!web_form.autoComplete())
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), 83 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(),
83 rect)); 84 rect));
84 } 85 }
85 } 86 }
86 87
87 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { 88 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) {
88 bool handled = true; 89 bool handled = true;
89 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) 90 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message)
90 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, 91 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted,
91 OnPasswordAccepted) 92 OnPasswordAccepted)
92 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordSyncEnabled, 93 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled,
93 OnPasswordSyncEnabled) 94 OnPasswordSyncEnabled)
94 IPC_MESSAGE_UNHANDLED(handled = false) 95 IPC_MESSAGE_UNHANDLED(handled = false)
95 IPC_END_MESSAGE_MAP() 96 IPC_END_MESSAGE_MAP()
96 return handled; 97 return handled;
97 } 98 }
98 99
99 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { 100 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) {
100 for (std::vector<WebKit::WebInputElement>::iterator it = 101 for (std::vector<WebKit::WebInputElement>::iterator it =
101 account_creation_elements_.second.begin(); 102 account_creation_elements_.second.begin();
102 it != account_creation_elements_.second.end(); ++it) { 103 it != account_creation_elements_.second.end(); ++it) {
103 it->setValue(password); 104 it->setValue(password);
104 it->setAutofilled(true); 105 it->setAutofilled(true);
105 } 106 }
106 } 107 }
107 108
108 void PasswordGenerationManager::OnPasswordSyncEnabled(bool enabled) { 109 void PasswordGenerationManager::OnPasswordSyncEnabled(bool enabled) {
109 sync_enabled_ = enabled; 110 enabled_ = enabled;
110 } 111 }
111 112
112 } // namespace autofill 113 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698