// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/renderer/autofill/form_cache.h" #include "base/logging.h" #include "base/utf_string_conversions.h" #include "chrome/renderer/autofill/form_autofill_util.h" #include "grit/generated_resources.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSelectElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" #include "ui/base/l10n/l10n_util.h" #include "webkit/glue/form_data.h" #include "webkit/glue/form_data_predictions.h" #include "webkit/glue/form_field.h" #include "webkit/glue/form_field_predictions.h" using WebKit::WebDocument; using WebKit::WebFormControlElement; using WebKit::WebFormElement; using WebKit::WebFrame; using WebKit::WebInputElement; using WebKit::WebSelectElement; using WebKit::WebString; using WebKit::WebVector; using webkit_glue::FormData; using webkit_glue::FormDataPredictions; namespace { // The number of fields required by Autofill. Ideally we could send the forms // to Autofill no matter how many fields are in the forms; however, finding the // label for each field is a costly operation and we can't spare the cycles if // it's not necessary. const size_t kRequiredAutofillFields = 3; // The maximum number of form fields we are willing to parse, due to // computational costs. Several examples of forms with lots of fields that are // not relevant to Autofill: (1) the Netflix queue; (2) the Amazon wishlist; // (3) router configuration pages; and (4) other configuration pages, e.g. for // Google code project settings. const size_t kMaxParseableFields = 100; } // namespace namespace autofill { FormCache::FormCache() { } FormCache::~FormCache() { } void FormCache::ExtractForms(const WebFrame& frame, std::vector* forms) { // Reset the cache for this frame. ResetFrame(frame); WebDocument document = frame.document(); if (document.isNull()) return; web_documents_.insert(document); WebVector web_forms; document.forms(web_forms); size_t num_fields_seen = 0; for (size_t i = 0; i < web_forms.size(); ++i) { WebFormElement form_element = web_forms[i]; std::vector control_elements; ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, &control_elements); for (size_t j = 0; j < control_elements.size(); ++j) { WebFormControlElement element = control_elements[j]; // Save original values of