diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 22:41:20 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 22:41:20 +0000 |
commit | 1cf47dd588567f66cebdab0078e2a1d5a38a9c5e (patch) | |
tree | 4ac8ff9d83140956738e9be36588f7028043cae8 /chrome/renderer | |
parent | ff0aa753808fca0e8b3ff5717ed2104bfccd5232 (diff) | |
download | chromium_src-1cf47dd588567f66cebdab0078e2a1d5a38a9c5e.zip chromium_src-1cf47dd588567f66cebdab0078e2a1d5a38a9c5e.tar.gz chromium_src-1cf47dd588567f66cebdab0078e2a1d5a38a9c5e.tar.bz2 |
AutoFill: Implement the 'AutoFill Options...' entry in the AutoFill suggestions
popup.
BUG=45144
TEST=none
Review URL: http://codereview.chromium.org/2773005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49463 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rwxr-xr-x | chrome/renderer/render_view.cc | 33 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 14 | ||||
-rw-r--r-- | chrome/renderer/render_view_unittest.cc | 35 |
3 files changed, 54 insertions, 28 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 74dd7ac..563fdf6 100755 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -427,6 +427,7 @@ RenderView::RenderView(RenderThreadBase* render_thread, browser_window_id_(-1), autofill_query_id_(0), autofill_action_(AUTOFILL_NONE), + suggestions_count_(0), ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), @@ -1508,11 +1509,15 @@ void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { void RenderView::OnAutoFillSuggestionsReturned( int query_id, const std::vector<string16>& values, - const std::vector<string16>& labels, - int default_suggestion_index) { + const std::vector<string16>& labels) { if (webview() && query_id == autofill_query_id_) { + std::vector<string16> v(values); + std::vector<string16> l(labels); + v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_MENU_ITEM)); + l.push_back(string16()); + suggestions_count_ = v.size(); webview()->applyAutoFillSuggestions( - autofill_query_node_, values, labels, default_suggestion_index); + autofill_query_node_, v, l, v.size() - 1); } } @@ -2055,19 +2060,35 @@ void RenderView::queryAutofillSuggestions(const WebNode& node, // data in FormManager. field.set_label(FormManager::LabelForElement(element)); - Send(new ViewHostMsg_QueryFormFieldAutofill( + Send(new ViewHostMsg_QueryFormFieldAutoFill( routing_id_, autofill_query_id_, field)); } void RenderView::removeAutofillSuggestions(const WebString& name, const WebString& value) { - Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value)); + Send(new ViewHostMsg_RemoveAutocompleteEntry(routing_id_, name, value)); } void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node, const WebKit::WebString& value, const WebKit::WebString& label) { - QueryAutoFillFormData(node, value, label, AUTOFILL_FILL); + // DEPRECATED + didAcceptAutoFillSuggestion(node, value, label, -1); +} + +void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node, + const WebKit::WebString& value, + const WebKit::WebString& label, + unsigned index) { + DCHECK_NE(0U, suggestions_count_); + + // User selected 'AutoFill Options...'. + if (index == suggestions_count_ - 1) + Send(new ViewHostMsg_ShowAutoFillDialog(routing_id_)); + else + QueryAutoFillFormData(node, value, label, AUTOFILL_FILL); + + suggestions_count_ = 0; } void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node, diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 6b6016c..b93d98b 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -379,9 +379,14 @@ class RenderView : public RenderWidget, const WebKit::WebString& value); virtual void removeAutofillSuggestions(const WebKit::WebString& name, const WebKit::WebString& value); + // DEPRECATED. virtual void didAcceptAutoFillSuggestion(const WebKit::WebNode& node, const WebKit::WebString& value, const WebKit::WebString& label); + virtual void didAcceptAutoFillSuggestion(const WebKit::WebNode& node, + const WebKit::WebString& value, + const WebKit::WebString& label, + unsigned index); virtual void didSelectAutoFillSuggestion(const WebKit::WebNode& node, const WebKit::WebString& value, const WebKit::WebString& label); @@ -577,6 +582,7 @@ class RenderView : public RenderWidget, #endif FRIEND_TEST(RenderViewTest, JSBlockSentAfterPageLoad); FRIEND_TEST(RenderViewTest, UpdateTargetURLWithInvalidURL); + FRIEND_TEST(RenderViewTest, SendForms); typedef std::map<GURL, ContentSettings> HostContentSettings; typedef std::map<GURL, int> HostZoomLevels; @@ -686,8 +692,7 @@ class RenderView : public RenderWidget, void OnAutoFillSuggestionsReturned( int query_id, const std::vector<string16>& values, - const std::vector<string16>& labels, - int default_suggestions_index); + const std::vector<string16>& labels); void OnCancelDownload(int32 download_id); void OnClearFocusedNode(); void OnClosePage(const ViewMsg_ClosePage_Params& params); @@ -1133,7 +1138,7 @@ class RenderView : public RenderWidget, // https://bugs.webkit.org/show_bug.cgi?id=32807. base::RepeatingTimer<RenderView> preferred_size_change_timer_; - // Autofill ------------------------------------------------------------------ + // AutoFill ------------------------------------------------------------------ // The id of the last request sent for form field AutoFill. Used to ignore // out of date responses. @@ -1146,6 +1151,9 @@ class RenderView : public RenderWidget, // The action to take when receiving AutoFill data from the AutoFillManager. AutoFillAction autofill_action_; + // The number of suggestions sent to the AutoFill popup in WebKit. + size_t suggestions_count_; + // Plugins ------------------------------------------------------------------- // Remember the first uninstalled plugin, so that we can ask the plugin diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc index 92521e4..b07f2b6 100644 --- a/chrome/renderer/render_view_unittest.cc +++ b/chrome/renderer/render_view_unittest.cc @@ -952,17 +952,11 @@ TEST_F(RenderViewTest, SendForms) { // loop, it will generate an update. view_->set_send_content_state_immediately(true); - LoadHTML("\ - <html>\ - <body>\ - <form method=\"POST\">\ - <input type=\"text\" id=\"firstname\" name=\"First Name\"/>\ - <input type=\"text\" name=\"Middle Name\" autoComplete=\"off\"/>\ - <input type=\"hidden\" name=\"Last Name\"/>\ - </form>\ - </body>\ - </html>\ - "); + LoadHTML("<form method=\"POST\">" + " <input type=\"text\" id=\"firstname\"/>" + " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" + " <input type=\"hidden\" id=\"lastname\"/>" + "</form>"); // Verify that "FormsSeen" sends the expected number of fields. ProcessPendingMessages(); @@ -976,19 +970,19 @@ TEST_F(RenderViewTest, SendForms) { ASSERT_EQ(3UL, forms[0].fields.size()); EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( FormField(string16(), - ASCIIToUTF16("First Name"), + ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), 20))) << forms[0].fields[0]; EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( FormField(string16(), - ASCIIToUTF16("Middle Name"), + ASCIIToUTF16("middlename"), string16(), ASCIIToUTF16("text"), 20))) << forms[0].fields[1]; EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack( FormField(string16(), - ASCIIToUTF16("Last Name"), + ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("hidden"), 0))) << forms[0].fields[2]; @@ -999,9 +993,12 @@ TEST_F(RenderViewTest, SendForms) { WebDocument document = web_frame->document(); WebInputElement firstname = document.getElementById("firstname").to<WebInputElement>(); + // didAcceptAutoFillSuggestions expects a non-zero number of suggestions. + view_->suggestions_count_ = 1; view_->didAcceptAutoFillSuggestion(firstname, - WebKit::WebString(), - WebKit::WebString()); + WebKit::WebString(), + WebKit::WebString(), + -1); ProcessPendingMessages(); const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( @@ -1013,19 +1010,19 @@ TEST_F(RenderViewTest, SendForms) { ASSERT_EQ(3UL, form2.fields.size()); EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( FormField(string16(), - ASCIIToUTF16("First Name"), + ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), 20))) << form2.fields[0]; EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( FormField(string16(), - ASCIIToUTF16("Middle Name"), + ASCIIToUTF16("middlename"), string16(), ASCIIToUTF16("text"), 20))) << form2.fields[1]; EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( FormField(string16(), - ASCIIToUTF16("Last Name"), + ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("hidden"), 0))) << form2.fields[2]; |