OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autofill_agent.h" | 5 #include "chrome/renderer/autofill/autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/common/autofill_messages.h" | 11 #include "chrome/common/autofill_messages.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/renderer/autofill/form_autofill_util.h" | 13 #include "chrome/renderer/autofill/form_autofill_util.h" |
14 #include "chrome/renderer/autofill/password_autofill_manager.h" | 14 #include "chrome/renderer/autofill/password_autofill_manager.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
23 #include "ui/base/keycodes/keyboard_codes.h" | 24 #include "ui/base/keycodes/keyboard_codes.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 #include "webkit/glue/form_data.h" | 26 #include "webkit/glue/form_data.h" |
26 #include "webkit/glue/form_data_predictions.h" | 27 #include "webkit/glue/form_data_predictions.h" |
27 #include "webkit/glue/form_field.h" | 28 #include "webkit/glue/form_field.h" |
28 #include "webkit/glue/password_form.h" | 29 #include "webkit/glue/password_form.h" |
29 | 30 |
30 using WebKit::WebFormControlElement; | 31 using WebKit::WebFormControlElement; |
31 using WebKit::WebFormElement; | 32 using WebKit::WebFormElement; |
(...skipping 20 matching lines...) Expand all Loading... | |
52 PasswordAutofillManager* password_autofill_manager) | 53 PasswordAutofillManager* password_autofill_manager) |
53 : content::RenderViewObserver(render_view), | 54 : content::RenderViewObserver(render_view), |
54 password_autofill_manager_(password_autofill_manager), | 55 password_autofill_manager_(password_autofill_manager), |
55 autofill_query_id_(0), | 56 autofill_query_id_(0), |
56 autofill_action_(AUTOFILL_NONE), | 57 autofill_action_(AUTOFILL_NONE), |
57 display_warning_if_disabled_(false), | 58 display_warning_if_disabled_(false), |
58 was_query_node_autofilled_(false), | 59 was_query_node_autofilled_(false), |
59 suggestions_clear_index_(-1), | 60 suggestions_clear_index_(-1), |
60 suggestions_options_index_(-1), | 61 suggestions_options_index_(-1), |
61 has_shown_autofill_popup_for_current_edit_(false), | 62 has_shown_autofill_popup_for_current_edit_(false), |
63 has_external_delegate_(false), | |
62 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 64 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
63 render_view->GetWebView()->setAutofillClient(this); | 65 render_view->GetWebView()->setAutofillClient(this); |
64 } | 66 } |
65 | 67 |
66 AutofillAgent::~AutofillAgent() {} | 68 AutofillAgent::~AutofillAgent() {} |
67 | 69 |
68 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { | 70 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { |
69 bool handled = true; | 71 bool handled = true; |
70 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) | 72 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) |
71 IPC_MESSAGE_HANDLER(AutofillMsg_SuggestionsReturned, OnSuggestionsReturned) | 73 IPC_MESSAGE_HANDLER(AutofillMsg_SuggestionsReturned, OnSuggestionsReturned) |
72 IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) | 74 IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) |
73 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, | 75 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, |
74 OnFieldTypePredictionsAvailable) | 76 OnFieldTypePredictionsAvailable) |
75 IPC_MESSAGE_HANDLER(AutofillMsg_SelectAutofillSuggestionAtIndex, | 77 IPC_MESSAGE_HANDLER(AutofillMsg_SelectAutofillSuggestionAtIndex, |
76 OnSelectAutofillSuggestionAtIndex) | 78 OnSelectAutofillSuggestionAtIndex) |
79 IPC_MESSAGE_HANDLER(AutofillMsg_SetHasExternalDelegate, | |
80 OnSetHasExternalDelegate) | |
77 IPC_MESSAGE_UNHANDLED(handled = false) | 81 IPC_MESSAGE_UNHANDLED(handled = false) |
78 IPC_END_MESSAGE_MAP() | 82 IPC_END_MESSAGE_MAP() |
79 return handled; | 83 return handled; |
80 } | 84 } |
81 | 85 |
82 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { | 86 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { |
83 // The document has now been fully loaded. Scan for forms to be sent up to | 87 // The document has now been fully loaded. Scan for forms to be sent up to |
84 // the browser. | 88 // the browser. |
85 std::vector<webkit_glue::FormData> forms; | 89 std::vector<webkit_glue::FormData> forms; |
86 form_cache_.ExtractForms(*frame, &forms); | 90 form_cache_.ExtractForms(*frame, &forms); |
(...skipping 30 matching lines...) Expand all Loading... | |
117 bool AutofillAgent::InputElementClicked(const WebInputElement& element, | 121 bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
118 bool was_focused, | 122 bool was_focused, |
119 bool is_focused) { | 123 bool is_focused) { |
120 if (was_focused) | 124 if (was_focused) |
121 ShowSuggestions(element, true, false, true); | 125 ShowSuggestions(element, true, false, true); |
122 | 126 |
123 return false; | 127 return false; |
124 } | 128 } |
125 | 129 |
126 bool AutofillAgent::InputElementLostFocus() { | 130 bool AutofillAgent::InputElementLostFocus() { |
131 if (has_external_delegate_) | |
John Grabowski
2011/11/08 20:46:02
Can you confirm this is called when, for example,
csharp
2011/11/09 16:18:37
This function is not called in both of these cases
Ilya Sherman
2011/11/09 20:34:19
My hunch is that we'll want to add something along
| |
132 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | |
133 | |
127 return false; | 134 return false; |
128 } | 135 } |
129 | 136 |
130 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, | 137 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, |
131 const WebString& value, | 138 const WebString& value, |
132 const WebString& label, | 139 const WebString& label, |
133 int unique_id, | 140 int unique_id, |
134 unsigned index) { | 141 unsigned index) { |
135 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) | 142 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) |
136 return; | 143 return; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 // Append the 'Chrome Autofill options' menu item; | 315 // Append the 'Chrome Autofill options' menu item; |
309 v.push_back(l10n_util::GetStringFUTF16(IDS_AUTOFILL_OPTIONS_POPUP, | 316 v.push_back(l10n_util::GetStringFUTF16(IDS_AUTOFILL_OPTIONS_POPUP, |
310 WideToUTF16(chrome::kBrowserAppName))); | 317 WideToUTF16(chrome::kBrowserAppName))); |
311 l.push_back(string16()); | 318 l.push_back(string16()); |
312 i.push_back(string16()); | 319 i.push_back(string16()); |
313 ids.push_back(0); | 320 ids.push_back(0); |
314 suggestions_options_index_ = v.size() - 1; | 321 suggestions_options_index_ = v.size() - 1; |
315 separator_index = values.size(); | 322 separator_index = values.size(); |
316 } | 323 } |
317 | 324 |
318 // Send to WebKit for display. | |
319 if (!v.empty() && !autofill_query_element_.isNull() && | 325 if (!v.empty() && !autofill_query_element_.isNull() && |
320 autofill_query_element_.isFocusable()) { | 326 autofill_query_element_.isFocusable()) { |
321 web_view->applyAutofillSuggestions( | 327 if (has_external_delegate_) { |
322 autofill_query_element_, v, l, i, ids, separator_index); | 328 // Send to an external delegate for display. |
329 WebKit::WebRect autofill_element_rect = | |
330 autofill_query_element_.getRect(); | |
331 | |
332 Send(new AutofillHostMsg_AutofillElementBounds( | |
333 routing_id(), | |
334 autofill_element_rect.x, | |
335 autofill_element_rect.y, | |
336 autofill_element_rect.width, | |
337 autofill_element_rect.height)); | |
338 } else { | |
339 // Send to WebKit for display. | |
340 web_view->applyAutofillSuggestions( | |
341 autofill_query_element_, v, l, i, ids, separator_index); | |
342 } | |
323 } | 343 } |
324 | 344 |
325 Send(new AutofillHostMsg_DidShowAutofillSuggestions( | 345 Send(new AutofillHostMsg_DidShowAutofillSuggestions( |
326 routing_id(), | 346 routing_id(), |
327 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); | 347 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
328 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 348 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
329 } | 349 } |
330 | 350 |
331 void AutofillAgent::OnFormDataFilled(int query_id, | 351 void AutofillAgent::OnFormDataFilled(int query_id, |
332 const webkit_glue::FormData& form) { | 352 const webkit_glue::FormData& form) { |
(...skipping 22 matching lines...) Expand all Loading... | |
355 form_cache_.ShowPredictions(forms[i]); | 375 form_cache_.ShowPredictions(forms[i]); |
356 } | 376 } |
357 } | 377 } |
358 | 378 |
359 void AutofillAgent::OnSelectAutofillSuggestionAtIndex(int listIndex) { | 379 void AutofillAgent::OnSelectAutofillSuggestionAtIndex(int listIndex) { |
360 NOTIMPLEMENTED(); | 380 NOTIMPLEMENTED(); |
361 // TODO(jrg): enable once changes land in WebKit | 381 // TODO(jrg): enable once changes land in WebKit |
362 // render_view()->webview()->selectAutofillSuggestionAtIndex(listIndex); | 382 // render_view()->webview()->selectAutofillSuggestionAtIndex(listIndex); |
363 } | 383 } |
364 | 384 |
385 void AutofillAgent::OnSetHasExternalDelegate(bool has_external_delegate) { | |
386 has_external_delegate_ = has_external_delegate; | |
387 } | |
388 | |
365 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 389 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
366 bool autofill_on_empty_values, | 390 bool autofill_on_empty_values, |
367 bool requires_caret_at_end, | 391 bool requires_caret_at_end, |
368 bool display_warning_if_disabled) { | 392 bool display_warning_if_disabled) { |
369 // If autocomplete is disabled at the form level, then we might want to show | 393 // If autocomplete is disabled at the form level, then we might want to show |
370 // a warning in place of suggestions. However, if autocomplete is disabled | 394 // a warning in place of suggestions. However, if autocomplete is disabled |
371 // specifically for this field, we never want to show a warning. Otherwise, | 395 // specifically for this field, we never want to show a warning. Otherwise, |
372 // we might interfere with custom popups (e.g. search suggestions) used by | 396 // we might interfere with custom popups (e.g. search suggestions) used by |
373 // the website. | 397 // the website. |
374 const WebFormElement form = element.form(); | 398 const WebFormElement form = element.form(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 return; | 455 return; |
432 } | 456 } |
433 | 457 |
434 autofill_action_ = action; | 458 autofill_action_ = action; |
435 was_query_node_autofilled_ = field.is_autofilled; | 459 was_query_node_autofilled_ = field.is_autofilled; |
436 Send(new AutofillHostMsg_FillAutofillFormData( | 460 Send(new AutofillHostMsg_FillAutofillFormData( |
437 routing_id(), autofill_query_id_, form, field, unique_id)); | 461 routing_id(), autofill_query_id_, form, field, unique_id)); |
438 } | 462 } |
439 | 463 |
440 } // namespace autofill | 464 } // namespace autofill |
OLD | NEW |