| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 if (!osd_url.is_empty()) | 1508 if (!osd_url.is_empty()) |
| 1509 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, | 1509 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
| 1510 autodetected)); | 1510 autodetected)); |
| 1511 } | 1511 } |
| 1512 | 1512 |
| 1513 void RenderView::OnAutoFillSuggestionsReturned( | 1513 void RenderView::OnAutoFillSuggestionsReturned( |
| 1514 int query_id, | 1514 int query_id, |
| 1515 const std::vector<string16>& values, | 1515 const std::vector<string16>& values, |
| 1516 const std::vector<string16>& labels, | 1516 const std::vector<string16>& labels, |
| 1517 const std::vector<int>& unique_ids) { | 1517 const std::vector<int>& unique_ids) { |
| 1518 if (webview() && query_id == autofill_query_id_) { | 1518 if (!webview() || query_id != autofill_query_id_) |
| 1519 std::vector<string16> v(values); | 1519 return; |
| 1520 std::vector<string16> l(labels); | |
| 1521 std::vector<int> ids(unique_ids); | |
| 1522 int separator_index = -1; | |
| 1523 | 1520 |
| 1524 // The form has been auto-filled, so give the user the chance to clear the | 1521 // Any popup currently showing is now obsolete. |
| 1525 // form. Append the 'Clear form' menu item. | 1522 webview()->hidePopups(); |
| 1526 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { | |
| 1527 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); | |
| 1528 l.push_back(string16()); | |
| 1529 ids.push_back(0); | |
| 1530 suggestions_clear_index_ = v.size() - 1; | |
| 1531 separator_index = values.size(); | |
| 1532 } | |
| 1533 | 1523 |
| 1534 size_t labeled_item_count = 0; | 1524 std::vector<string16> v(values); |
| 1535 for (size_t i = 0; i < l.size(); ++i) { | 1525 std::vector<string16> l(labels); |
| 1536 if (!l[i].empty()) | 1526 std::vector<int> ids(unique_ids); |
| 1537 labeled_item_count++; | 1527 int separator_index = -1; |
| 1538 } | |
| 1539 | 1528 |
| 1540 // Only include "AutoFill Options" special menu item if we have labeled | 1529 // The form has been auto-filled, so give the user the chance to clear the |
| 1541 // items. | 1530 // form. Append the 'Clear form' menu item. |
| 1542 if (labeled_item_count > 0) { | 1531 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { |
| 1543 // Append the 'AutoFill Options...' menu item. | 1532 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); |
| 1544 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); | 1533 l.push_back(string16()); |
| 1545 l.push_back(string16()); | 1534 ids.push_back(0); |
| 1546 ids.push_back(0); | 1535 suggestions_clear_index_ = v.size() - 1; |
| 1547 suggestions_options_index_ = v.size() - 1; | 1536 separator_index = values.size(); |
| 1548 separator_index = values.size(); | 1537 } |
| 1549 } | |
| 1550 | 1538 |
| 1551 // Send to WebKit for display. | 1539 size_t labeled_item_count = 0; |
| 1552 if (!v.empty()) | 1540 for (size_t i = 0; i < l.size(); ++i) { |
| 1553 webview()->applyAutoFillSuggestions( | 1541 if (!l[i].empty()) |
| 1554 autofill_query_node_, v, l, ids, separator_index); | 1542 labeled_item_count++; |
| 1555 } | 1543 } |
| 1544 |
| 1545 // Only include "AutoFill Options" special menu item if we have labeled |
| 1546 // items. |
| 1547 if (labeled_item_count > 0) { |
| 1548 // Append the 'AutoFill Options...' menu item. |
| 1549 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); |
| 1550 l.push_back(string16()); |
| 1551 ids.push_back(0); |
| 1552 suggestions_options_index_ = v.size() - 1; |
| 1553 separator_index = values.size(); |
| 1554 } |
| 1555 |
| 1556 // Send to WebKit for display. |
| 1557 if (!v.empty()) |
| 1558 webview()->applyAutoFillSuggestions( |
| 1559 autofill_query_node_, v, l, ids, separator_index); |
| 1556 } | 1560 } |
| 1557 | 1561 |
| 1558 void RenderView::OnAutoFillFormDataFilled(int query_id, | 1562 void RenderView::OnAutoFillFormDataFilled(int query_id, |
| 1559 const webkit_glue::FormData& form) { | 1563 const webkit_glue::FormData& form) { |
| 1560 if (!webview() || query_id != autofill_query_id_) | 1564 if (!webview() || query_id != autofill_query_id_) |
| 1561 return; | 1565 return; |
| 1562 | 1566 |
| 1563 DCHECK_NE(AUTOFILL_NONE, autofill_action_); | 1567 DCHECK_NE(AUTOFILL_NONE, autofill_action_); |
| 1564 | 1568 |
| 1565 if (autofill_action_ == AUTOFILL_FILL) | 1569 if (autofill_action_ == AUTOFILL_FILL) |
| (...skipping 3759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5325 webkit_glue::FormData form; | 5329 webkit_glue::FormData form; |
| 5326 const WebInputElement element = node.toConst<WebInputElement>(); | 5330 const WebInputElement element = node.toConst<WebInputElement>(); |
| 5327 if (!form_manager_.FindFormWithFormControlElement( | 5331 if (!form_manager_.FindFormWithFormControlElement( |
| 5328 element, FormManager::REQUIRE_NONE, &form)) | 5332 element, FormManager::REQUIRE_NONE, &form)) |
| 5329 return; | 5333 return; |
| 5330 | 5334 |
| 5331 autofill_action_ = action; | 5335 autofill_action_ = action; |
| 5332 Send(new ViewHostMsg_FillAutoFillFormData( | 5336 Send(new ViewHostMsg_FillAutoFillFormData( |
| 5333 routing_id_, autofill_query_id_, form, value, label, unique_id)); | 5337 routing_id_, autofill_query_id_, form, value, label, unique_id)); |
| 5334 } | 5338 } |
| OLD | NEW |