diff options
author | jcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 22:57:44 +0000 |
---|---|---|
committer | jcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 22:57:44 +0000 |
commit | 679f128fc208f1d983c4e5913f108ae4ff018e6b (patch) | |
tree | 719fd7f47eb63c7416344ff9362f8b1bf6e3ee98 /chrome/renderer/password_autocomplete_manager.cc | |
parent | 540659481e1a9f87872566b59d15ba1ce75d1c1f (diff) | |
download | chromium_src-679f128fc208f1d983c4e5913f108ae4ff018e6b.zip chromium_src-679f128fc208f1d983c4e5913f108ae4ff018e6b.tar.gz chromium_src-679f128fc208f1d983c4e5913f108ae4ff018e6b.tar.bz2 |
This CL creates a new class AutofillHelper that factors out the autofill related code out of render_view.cc.
This is to limit the bloating of RenderView code, which would soon get even worse once we move the Webkit autofill to Chrome.
There is no logic change in this CL.
BUG=None
TEST=Make sure form autofill and autocomplete work as expected.
Review URL: http://codereview.chromium.org/2834060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53413 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/password_autocomplete_manager.cc')
-rw-r--r-- | chrome/renderer/password_autocomplete_manager.cc | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/chrome/renderer/password_autocomplete_manager.cc b/chrome/renderer/password_autocomplete_manager.cc index f8f10ec..0cc3732 100644 --- a/chrome/renderer/password_autocomplete_manager.cc +++ b/chrome/renderer/password_autocomplete_manager.cc @@ -7,14 +7,18 @@ #include "base/keyboard_codes.h" #include "base/message_loop.h" #include "base/scoped_ptr.h" +#include "chrome/common/render_messages.h" +#include "chrome/renderer/render_view.h" #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "webkit/glue/form_field.h" +#include "webkit/glue/password_form.h" #include "webkit/glue/password_form_dom_manager.h" namespace { @@ -166,7 +170,8 @@ bool DoUsernamesMatch(const string16& username1, PasswordAutocompleteManager::PasswordAutocompleteManager( RenderView* render_view) - : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + : render_view_(render_view), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { } PasswordAutocompleteManager::~PasswordAutocompleteManager() { @@ -338,6 +343,43 @@ void PasswordAutocompleteManager::PerformInlineAutocomplete( FillUserNameAndPassword(&username, &password, fill_data, false); } +void PasswordAutocompleteManager::SendPasswordForms(WebKit::WebFrame* frame, + bool only_visible) { + // Make sure that this security origin is allowed to use password manager. + WebKit::WebSecurityOrigin security_origin = frame->securityOrigin(); + if (!security_origin.canAccessPasswordManager()) + return; + + WebKit::WebVector<WebKit::WebFormElement> forms; + frame->forms(forms); + + std::vector<webkit_glue::PasswordForm> password_forms; + for (size_t i = 0; i < forms.size(); ++i) { + const WebKit::WebFormElement& form = forms[i]; + + // Respect autocomplete=off. + if (!form.autoComplete()) + continue; + if (only_visible && !form.hasNonEmptyBoundingBox()) + continue; + scoped_ptr<webkit_glue::PasswordForm> password_form( + webkit_glue::PasswordFormDomManager::CreatePasswordForm(form)); + if (password_form.get()) + password_forms.push_back(*password_form); + } + + if (password_forms.empty()) + return; + + if (only_visible) { + render_view_->Send( + new ViewHostMsg_PasswordFormsVisible(GetRoutingID(), password_forms)); + } else { + render_view_->Send( + new ViewHostMsg_PasswordFormsFound(GetRoutingID(), password_forms)); + } +} + //////////////////////////////////////////////////////////////////////////////// // PasswordAutocompleteManager, private: @@ -414,3 +456,6 @@ bool PasswordAutocompleteManager::FillUserNameAndPassword( return true; } +int PasswordAutocompleteManager::GetRoutingID() const { + return render_view_->routing_id(); +} |