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 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { | 1507 void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { |
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 if (webview() && query_id == autofill_query_id_) { | 1517 if (!webview() || query_id != autofill_query_id_) |
1518 std::vector<string16> v(values); | 1518 return; |
1519 std::vector<string16> l(labels); | |
1520 int separator_index = -1; | |
1521 | 1519 |
1522 // The form has been auto-filled, so give the user the chance to clear the | 1520 // Any popup currently showing is now obsolete. |
1523 // form. Append the 'Clear form' menu item. | 1521 webview()->hidePopups(); |
1524 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { | 1522 |
1525 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); | 1523 std::vector<string16> v(values); |
1526 l.push_back(string16()); | 1524 std::vector<string16> l(labels); |
1527 suggestions_clear_index_ = v.size() - 1; | 1525 int separator_index = -1; |
1528 separator_index = values.size(); | |
1529 } | |
1530 | 1526 |
1531 size_t labeled_item_count = 0; | 1527 // The form has been auto-filled, so give the user the chance to clear the |
1532 for (size_t i = 0; i < l.size(); ++i) { | 1528 // form. Append the 'Clear form' menu item. |
1533 if (!l[i].empty()) | 1529 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { |
1534 labeled_item_count++; | 1530 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); |
1535 } | 1531 l.push_back(string16()); |
| 1532 suggestions_clear_index_ = v.size() - 1; |
| 1533 separator_index = values.size(); |
| 1534 } |
1536 | 1535 |
1537 // Only include "AutoFill Options" special menu item if we have labeled | 1536 size_t labeled_item_count = 0; |
1538 // items. | 1537 for (size_t i = 0; i < l.size(); ++i) { |
1539 if (labeled_item_count > 0) { | 1538 if (!l[i].empty()) |
1540 // Append the 'AutoFill Options...' menu item. | 1539 labeled_item_count++; |
1541 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); | 1540 } |
1542 l.push_back(string16()); | |
1543 suggestions_options_index_ = v.size() - 1; | |
1544 separator_index = values.size(); | |
1545 } | |
1546 | 1541 |
1547 // Send to WebKit for display. | 1542 // Only include "AutoFill Options" special menu item if we have labeled |
1548 if (!v.empty()) | 1543 // items. |
1549 webview()->applyAutoFillSuggestions( | 1544 if (labeled_item_count > 0) { |
1550 autofill_query_node_, v, l, separator_index); | 1545 // Append the 'AutoFill Options...' menu item. |
| 1546 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); |
| 1547 l.push_back(string16()); |
| 1548 suggestions_options_index_ = v.size() - 1; |
| 1549 separator_index = values.size(); |
1551 } | 1550 } |
| 1551 |
| 1552 // Send to WebKit for display. |
| 1553 if (!v.empty()) |
| 1554 webview()->applyAutoFillSuggestions( |
| 1555 autofill_query_node_, v, l, separator_index); |
1552 } | 1556 } |
1553 | 1557 |
1554 void RenderView::OnAutoFillFormDataFilled(int query_id, | 1558 void RenderView::OnAutoFillFormDataFilled(int query_id, |
1555 const webkit_glue::FormData& form) { | 1559 const webkit_glue::FormData& form) { |
1556 if (!webview() || query_id != autofill_query_id_) | 1560 if (!webview() || query_id != autofill_query_id_) |
1557 return; | 1561 return; |
1558 | 1562 |
1559 DCHECK_NE(AUTOFILL_NONE, autofill_action_); | 1563 DCHECK_NE(AUTOFILL_NONE, autofill_action_); |
1560 | 1564 |
1561 if (autofill_action_ == AUTOFILL_FILL) | 1565 if (autofill_action_ == AUTOFILL_FILL) |
(...skipping 3751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5313 webkit_glue::FormData form; | 5317 webkit_glue::FormData form; |
5314 const WebInputElement element = node.toConst<WebInputElement>(); | 5318 const WebInputElement element = node.toConst<WebInputElement>(); |
5315 if (!form_manager_.FindFormWithFormControlElement( | 5319 if (!form_manager_.FindFormWithFormControlElement( |
5316 element, FormManager::REQUIRE_NONE, &form)) | 5320 element, FormManager::REQUIRE_NONE, &form)) |
5317 return; | 5321 return; |
5318 | 5322 |
5319 autofill_action_ = action; | 5323 autofill_action_ = action; |
5320 Send(new ViewHostMsg_FillAutoFillFormData( | 5324 Send(new ViewHostMsg_FillAutoFillFormData( |
5321 routing_id_, autofill_query_id_, form, value, label)); | 5325 routing_id_, autofill_query_id_, form, value, label)); |
5322 } | 5326 } |
OLD | NEW |