| Index: chrome/browser/renderer_host/render_view_host.cc
|
| diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
|
| index 134274e3cb61becaf1d6accf71228e6ba647f745..90a704e47bb7079e09911623e160bde94155862a 100644
|
| --- a/chrome/browser/renderer_host/render_view_host.cc
|
| +++ b/chrome/browser/renderer_host/render_view_host.cc
|
| @@ -8,6 +8,7 @@
|
| #include <utility>
|
| #include <vector>
|
|
|
| +#include "app/l10n_util.h"
|
| #include "base/command_line.h"
|
| #include "base/i18n/rtl.h"
|
| #include "base/json/json_reader.h"
|
| @@ -46,6 +47,7 @@
|
| #include "chrome/common/translate_errors.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "gfx/native_widget_types.h"
|
| +#include "grit/generated_resources.h"
|
| #include "net/base/net_util.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
|
| @@ -1712,33 +1714,44 @@ void RenderViewHost::OnMsgShouldCloseACK(bool proceed) {
|
| }
|
|
|
| void RenderViewHost::OnQueryFormFieldAutoFill(
|
| - int query_id, bool form_autofilled, const webkit_glue::FormField& field) {
|
| + int query_id, bool field_autofilled, const webkit_glue::FormField& field,
|
| + bool autofill_disabled) {
|
| + ResetAutoFillState(query_id, autofill_disabled);
|
| +
|
| + // We first query the autofill delegate for suggestions. We keep track of the
|
| + // results it gives us, which we will later combine with the autocomplete
|
| + // suggestions.
|
| RenderViewHostDelegate::AutoFill* autofill_delegate =
|
| delegate_->GetAutoFillDelegate();
|
| - // We first save the AutoFill delegate's suggestions. Then we fetch the
|
| - // Autocomplete delegate's suggestions and send the combined results back to
|
| - // the render view.
|
| - if (autofill_delegate &&
|
| - autofill_delegate->GetAutoFillSuggestions(query_id,
|
| - form_autofilled,
|
| - field)) {
|
| - } else {
|
| - // No suggestions provided, so supply an empty vector as the results.
|
| - AutoFillSuggestionsReturned(query_id,
|
| - std::vector<string16>(),
|
| - std::vector<string16>(),
|
| - std::vector<string16>(),
|
| - std::vector<int>());
|
| + if (autofill_delegate) {
|
| + autofill_delegate->GetAutoFillSuggestions(field_autofilled, field,
|
| + autofill_disabled);
|
| + }
|
| +
|
| + // If autofill is disabled but would have otherwise returned suggestions, we
|
| + // can route the corresponding warning to the renderer without looking at
|
| + // autocomplete suggestions.
|
| + if (autofill_disabled && !autofill_values_.empty()) {
|
| + DCHECK(autofill_unique_ids_.size() == 1);
|
| + DCHECK(autofill_unique_ids_[0] == -1);
|
| + Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(),
|
| + autofill_query_id_,
|
| + autofill_values_,
|
| + autofill_labels_,
|
| + autofill_icons_,
|
| + autofill_unique_ids_));
|
| + return;
|
| }
|
|
|
| + // Now query the Autocomplete delegate for suggestions. These will be combined
|
| + // with the saved autofill suggestions in |AutocompleteSuggestionsReturned()|.
|
| RenderViewHostDelegate::Autocomplete* autocomplete_delegate =
|
| delegate_->GetAutocompleteDelegate();
|
| - if (autocomplete_delegate &&
|
| + if (autocomplete_delegate) {
|
| autocomplete_delegate->GetAutocompleteSuggestions(
|
| - query_id, field.name(), field.value())) {
|
| + field.name(), field.value());
|
| } else {
|
| - // No suggestions provided, so send an empty vector as the results.
|
| - AutocompleteSuggestionsReturned(query_id, std::vector<string16>());
|
| + AutocompleteSuggestionsReturned(std::vector<string16>());
|
| }
|
| }
|
|
|
| @@ -1792,24 +1805,49 @@ void RenderViewHost::OnDidFillAutoFillFormData() {
|
| NotificationService::NoDetails());
|
| }
|
|
|
| +void RenderViewHost::ResetAutoFillState(int query_id, bool autofill_disabled) {
|
| + autofill_query_id_ = query_id;
|
| + autofill_disabled_ = autofill_disabled;
|
| +
|
| + autofill_values_.clear();
|
| + autofill_labels_.clear();
|
| + autofill_icons_.clear();
|
| + autofill_unique_ids_.clear();
|
| +}
|
| +
|
| void RenderViewHost::AutoFillSuggestionsReturned(
|
| - int query_id,
|
| - const std::vector<string16>& names,
|
| + const std::vector<string16>& values,
|
| const std::vector<string16>& labels,
|
| const std::vector<string16>& icons,
|
| const std::vector<int>& unique_ids) {
|
| - autofill_values_.assign(names.begin(), names.end());
|
| + autofill_values_.assign(values.begin(), values.end());
|
| autofill_labels_.assign(labels.begin(), labels.end());
|
| autofill_icons_.assign(icons.begin(), icons.end());
|
| autofill_unique_ids_.assign(unique_ids.begin(), unique_ids.end());
|
| }
|
|
|
| void RenderViewHost::AutocompleteSuggestionsReturned(
|
| - int query_id, const std::vector<string16>& suggestions) {
|
| + const std::vector<string16>& suggestions) {
|
| + if (autofill_disabled_ && suggestions.size() > 0) {
|
| + autofill_values_.assign(
|
| + 1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED));
|
| + autofill_labels_.assign(1, string16());
|
| + autofill_icons_.assign(1, string16());
|
| + autofill_unique_ids_.assign(1, -1);
|
| + Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(),
|
| + autofill_query_id_,
|
| + autofill_values_,
|
| + autofill_labels_,
|
| + autofill_icons_,
|
| + autofill_unique_ids_));
|
| + return;
|
| + }
|
| +
|
| // Combine AutoFill and Autocomplete values into values and labels.
|
| for (size_t i = 0; i < suggestions.size(); ++i) {
|
| bool unique = true;
|
| for (size_t j = 0; j < autofill_values_.size(); ++j) {
|
| + // TODO(isherman): Why just when the label is empty?
|
| // If the AutoFill label is empty, we need to make sure we don't add a
|
| // duplicate value.
|
| if (autofill_labels_[j].empty() &&
|
| @@ -1828,7 +1866,7 @@ void RenderViewHost::AutocompleteSuggestionsReturned(
|
| }
|
|
|
| Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(),
|
| - query_id,
|
| + autofill_query_id_,
|
| autofill_values_,
|
| autofill_labels_,
|
| autofill_icons_,
|
|
|