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/browser/renderer_host/render_view_host.h" | 5 #include "chrome/browser/renderer_host/render_view_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "app/l10n_util.h" | |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
13 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
14 #include "base/metrics/stats_counters.h" | 15 #include "base/metrics/stats_counters.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/browser/blocked_plugin_manager.h" | 19 #include "chrome/browser/blocked_plugin_manager.h" |
19 #include "chrome/browser/browser_list.h" | 20 #include "chrome/browser/browser_list.h" |
20 #include "chrome/browser/child_process_security_policy.h" | 21 #include "chrome/browser/child_process_security_policy.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
39 #include "chrome/common/notification_details.h" | 40 #include "chrome/common/notification_details.h" |
40 #include "chrome/common/notification_service.h" | 41 #include "chrome/common/notification_service.h" |
41 #include "chrome/common/notification_type.h" | 42 #include "chrome/common/notification_type.h" |
42 #include "chrome/common/render_messages.h" | 43 #include "chrome/common/render_messages.h" |
43 #include "chrome/common/render_messages_params.h" | 44 #include "chrome/common/render_messages_params.h" |
44 #include "chrome/common/result_codes.h" | 45 #include "chrome/common/result_codes.h" |
45 #include "chrome/common/thumbnail_score.h" | 46 #include "chrome/common/thumbnail_score.h" |
46 #include "chrome/common/translate_errors.h" | 47 #include "chrome/common/translate_errors.h" |
47 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
48 #include "gfx/native_widget_types.h" | 49 #include "gfx/native_widget_types.h" |
50 #include "grit/generated_resources.h" | |
49 #include "net/base/net_util.h" | 51 #include "net/base/net_util.h" |
50 #include "third_party/skia/include/core/SkBitmap.h" | 52 #include "third_party/skia/include/core/SkBitmap.h" |
51 #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" | 53 #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" |
52 #include "webkit/glue/context_menu.h" | 54 #include "webkit/glue/context_menu.h" |
53 #include "webkit/glue/dom_operations.h" | 55 #include "webkit/glue/dom_operations.h" |
54 #include "webkit/glue/form_data.h" | 56 #include "webkit/glue/form_data.h" |
55 #include "webkit/glue/form_field.h" | 57 #include "webkit/glue/form_field.h" |
56 #include "webkit/glue/password_form_dom_manager.h" | 58 #include "webkit/glue/password_form_dom_manager.h" |
57 #include "webkit/glue/webaccessibility.h" | 59 #include "webkit/glue/webaccessibility.h" |
58 #include "webkit/glue/webdropdata.h" | 60 #include "webkit/glue/webdropdata.h" |
(...skipping 1646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1705 | 1707 |
1706 RenderViewHostDelegate::RendererManagement* management_delegate = | 1708 RenderViewHostDelegate::RendererManagement* management_delegate = |
1707 delegate_->GetRendererManagementDelegate(); | 1709 delegate_->GetRendererManagementDelegate(); |
1708 if (management_delegate) { | 1710 if (management_delegate) { |
1709 management_delegate->ShouldClosePage( | 1711 management_delegate->ShouldClosePage( |
1710 unload_ack_is_for_cross_site_transition_, proceed); | 1712 unload_ack_is_for_cross_site_transition_, proceed); |
1711 } | 1713 } |
1712 } | 1714 } |
1713 | 1715 |
1714 void RenderViewHost::OnQueryFormFieldAutoFill( | 1716 void RenderViewHost::OnQueryFormFieldAutoFill( |
1715 int query_id, bool form_autofilled, const webkit_glue::FormField& field) { | 1717 int query_id, bool field_autofilled, const webkit_glue::FormField& field, |
1718 bool autofill_disabled) { | |
1719 ResetAutoFillState(query_id, autofill_disabled); | |
1720 | |
1721 // We first query the autofill delegate for suggestions. We keep track of the | |
1722 // results it gives us, which we will later combine with the autocomplete | |
1723 // suggestions. | |
1716 RenderViewHostDelegate::AutoFill* autofill_delegate = | 1724 RenderViewHostDelegate::AutoFill* autofill_delegate = |
1717 delegate_->GetAutoFillDelegate(); | 1725 delegate_->GetAutoFillDelegate(); |
1718 // We first save the AutoFill delegate's suggestions. Then we fetch the | 1726 if (autofill_delegate) { |
1719 // Autocomplete delegate's suggestions and send the combined results back to | 1727 autofill_delegate->GetAutoFillSuggestions(field_autofilled, field, |
1720 // the render view. | 1728 autofill_disabled); |
1721 if (autofill_delegate && | |
1722 autofill_delegate->GetAutoFillSuggestions(query_id, | |
1723 form_autofilled, | |
1724 field)) { | |
1725 } else { | |
1726 // No suggestions provided, so supply an empty vector as the results. | |
1727 AutoFillSuggestionsReturned(query_id, | |
1728 std::vector<string16>(), | |
1729 std::vector<string16>(), | |
1730 std::vector<string16>(), | |
1731 std::vector<int>()); | |
1732 } | 1729 } |
1733 | 1730 |
1731 // If autofill is disabled but would have otherwise returned suggestions, we | |
1732 // can route the corresponding warning to the renderer without looking at | |
1733 // autocomplete suggestions. | |
1734 if (autofill_disabled && !autofill_values_.empty()) { | |
1735 DCHECK(autofill_unique_ids_.size() == 1); | |
1736 DCHECK(autofill_unique_ids_[0] == -1); | |
1737 Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(), | |
1738 autofill_query_id_, | |
1739 autofill_values_, | |
1740 autofill_labels_, | |
1741 autofill_icons_, | |
1742 autofill_unique_ids_)); | |
1743 return; | |
1744 } | |
1745 | |
1746 // Now query the Autocomplete delegate for suggestions. These will be combined | |
1747 // with the saved autofill suggestions in |AutocompleteSuggestionsReturned()|. | |
1734 RenderViewHostDelegate::Autocomplete* autocomplete_delegate = | 1748 RenderViewHostDelegate::Autocomplete* autocomplete_delegate = |
1735 delegate_->GetAutocompleteDelegate(); | 1749 delegate_->GetAutocompleteDelegate(); |
1736 if (autocomplete_delegate && | 1750 if (autocomplete_delegate) { |
1737 autocomplete_delegate->GetAutocompleteSuggestions( | 1751 autocomplete_delegate->GetAutocompleteSuggestions( |
1738 query_id, field.name(), field.value())) { | 1752 field.name(), field.value()); |
1739 } else { | 1753 } else { |
1740 // No suggestions provided, so send an empty vector as the results. | 1754 AutocompleteSuggestionsReturned(std::vector<string16>()); |
1741 AutocompleteSuggestionsReturned(query_id, std::vector<string16>()); | |
1742 } | 1755 } |
1743 } | 1756 } |
1744 | 1757 |
1745 void RenderViewHost::OnDidShowAutoFillSuggestions() { | 1758 void RenderViewHost::OnDidShowAutoFillSuggestions() { |
1746 NotificationService::current()->Notify( | 1759 NotificationService::current()->Notify( |
1747 NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS, | 1760 NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS, |
1748 Source<RenderViewHost>(this), | 1761 Source<RenderViewHost>(this), |
1749 NotificationService::NoDetails()); | 1762 NotificationService::NoDetails()); |
1750 } | 1763 } |
1751 | 1764 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1785 autofill_delegate->FillAutoFillFormData(query_id, form, unique_id); | 1798 autofill_delegate->FillAutoFillFormData(query_id, form, unique_id); |
1786 } | 1799 } |
1787 | 1800 |
1788 void RenderViewHost::OnDidFillAutoFillFormData() { | 1801 void RenderViewHost::OnDidFillAutoFillFormData() { |
1789 NotificationService::current()->Notify( | 1802 NotificationService::current()->Notify( |
1790 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, | 1803 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, |
1791 Source<RenderViewHost>(this), | 1804 Source<RenderViewHost>(this), |
1792 NotificationService::NoDetails()); | 1805 NotificationService::NoDetails()); |
1793 } | 1806 } |
1794 | 1807 |
1808 void RenderViewHost::ResetAutoFillState(int query_id, bool autofill_disabled) { | |
1809 autofill_query_id_ = query_id; | |
1810 autofill_disabled_ = autofill_disabled; | |
1811 | |
1812 autofill_values_.clear(); | |
1813 autofill_labels_.clear(); | |
1814 autofill_icons_.clear(); | |
1815 autofill_unique_ids_.clear(); | |
1816 } | |
1817 | |
1795 void RenderViewHost::AutoFillSuggestionsReturned( | 1818 void RenderViewHost::AutoFillSuggestionsReturned( |
1796 int query_id, | 1819 const std::vector<string16>& values, |
1797 const std::vector<string16>& names, | |
1798 const std::vector<string16>& labels, | 1820 const std::vector<string16>& labels, |
1799 const std::vector<string16>& icons, | 1821 const std::vector<string16>& icons, |
1800 const std::vector<int>& unique_ids) { | 1822 const std::vector<int>& unique_ids) { |
1801 autofill_values_.assign(names.begin(), names.end()); | 1823 autofill_values_.assign(values.begin(), values.end()); |
1802 autofill_labels_.assign(labels.begin(), labels.end()); | 1824 autofill_labels_.assign(labels.begin(), labels.end()); |
1803 autofill_icons_.assign(icons.begin(), icons.end()); | 1825 autofill_icons_.assign(icons.begin(), icons.end()); |
1804 autofill_unique_ids_.assign(unique_ids.begin(), unique_ids.end()); | 1826 autofill_unique_ids_.assign(unique_ids.begin(), unique_ids.end()); |
1805 } | 1827 } |
1806 | 1828 |
1807 void RenderViewHost::AutocompleteSuggestionsReturned( | 1829 void RenderViewHost::AutocompleteSuggestionsReturned( |
1808 int query_id, const std::vector<string16>& suggestions) { | 1830 const std::vector<string16>& suggestions) { |
1831 if (autofill_disabled_ && suggestions.size() > 0) { | |
dhollowa
2010/11/12 23:44:20
As we discussed, an alternate approach that might
Ilya Sherman
2010/11/13 05:24:43
This patch set mostly does this. I've moved all t
| |
1832 autofill_values_.assign( | |
1833 1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED)); | |
1834 autofill_labels_.assign(1, string16()); | |
1835 autofill_icons_.assign(1, string16()); | |
1836 autofill_unique_ids_.assign(1, -1); | |
1837 Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(), | |
1838 autofill_query_id_, | |
1839 autofill_values_, | |
1840 autofill_labels_, | |
1841 autofill_icons_, | |
1842 autofill_unique_ids_)); | |
1843 return; | |
1844 } | |
1845 | |
1846 // If we could not provide autofill suggestions but can provide autocomplete | |
1847 // suggestions, clear the autofill warning. | |
1848 if (suggestions.size() > 0 && | |
1849 autofill_unique_ids_.size() > 0 && autofill_unique_ids_[0] < 0) { | |
1850 ResetAutoFillState(autofill_query_id_, autofill_disabled_); | |
1851 } | |
1852 | |
1809 // Combine AutoFill and Autocomplete values into values and labels. | 1853 // Combine AutoFill and Autocomplete values into values and labels. |
1810 for (size_t i = 0; i < suggestions.size(); ++i) { | 1854 for (size_t i = 0; i < suggestions.size(); ++i) { |
1811 bool unique = true; | 1855 bool unique = true; |
1812 for (size_t j = 0; j < autofill_values_.size(); ++j) { | 1856 for (size_t j = 0; j < autofill_values_.size(); ++j) { |
1857 // TODO(isherman): Why just when the label is empty? | |
1813 // If the AutoFill label is empty, we need to make sure we don't add a | 1858 // If the AutoFill label is empty, we need to make sure we don't add a |
1814 // duplicate value. | 1859 // duplicate value. |
1815 if (autofill_labels_[j].empty() && | 1860 if (autofill_labels_[j].empty() && |
1816 autofill_values_[j] == suggestions[i]) { | 1861 autofill_values_[j] == suggestions[i]) { |
1817 unique = false; | 1862 unique = false; |
1818 break; | 1863 break; |
1819 } | 1864 } |
1820 } | 1865 } |
1821 | 1866 |
1822 if (unique) { | 1867 if (unique) { |
1823 autofill_values_.push_back(suggestions[i]); | 1868 autofill_values_.push_back(suggestions[i]); |
1824 autofill_labels_.push_back(string16()); | 1869 autofill_labels_.push_back(string16()); |
1825 autofill_icons_.push_back(string16()); | 1870 autofill_icons_.push_back(string16()); |
1826 autofill_unique_ids_.push_back(0); // 0 means no profile. | 1871 autofill_unique_ids_.push_back(0); // 0 means no profile. |
1827 } | 1872 } |
1828 } | 1873 } |
1829 | 1874 |
1830 Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(), | 1875 Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(), |
1831 query_id, | 1876 autofill_query_id_, |
1832 autofill_values_, | 1877 autofill_values_, |
1833 autofill_labels_, | 1878 autofill_labels_, |
1834 autofill_icons_, | 1879 autofill_icons_, |
1835 autofill_unique_ids_)); | 1880 autofill_unique_ids_)); |
1836 } | 1881 } |
1837 | 1882 |
1838 void RenderViewHost::AutoFillFormDataFilled(int query_id, | 1883 void RenderViewHost::AutoFillFormDataFilled(int query_id, |
1839 const FormData& form) { | 1884 const FormData& form) { |
1840 Send(new ViewMsg_AutoFillFormDataFilled(routing_id(), query_id, form)); | 1885 Send(new ViewMsg_AutoFillFormDataFilled(routing_id(), query_id, form)); |
1841 } | 1886 } |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2246 } | 2291 } |
2247 #else | 2292 #else |
2248 void RenderViewHost::OnPagesReadyForPreview(int fd_in_browser) { | 2293 void RenderViewHost::OnPagesReadyForPreview(int fd_in_browser) { |
2249 // TODO(kmadhusu): Function definition needs to be changed. | 2294 // TODO(kmadhusu): Function definition needs to be changed. |
2250 // fd_in_browser should be the file descriptor of the metafile. | 2295 // fd_in_browser should be the file descriptor of the metafile. |
2251 | 2296 |
2252 // Send the printingDone msg for now. | 2297 // Send the printingDone msg for now. |
2253 Send(new ViewMsg_PrintingDone(routing_id(), -1, true)); | 2298 Send(new ViewMsg_PrintingDone(routing_id(), -1, true)); |
2254 } | 2299 } |
2255 #endif | 2300 #endif |
OLD | NEW |