Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / components / autofill / core / browser / autofill_manager.h
index b7d74c1..d2ff660 100644 (file)
 #include "base/strings/string16.h"
 #include "base/time/time.h"
 #include "components/autofill/core/browser/autocomplete_history_manager.h"
-#include "components/autofill/core/browser/autofill_download.h"
-#include "components/autofill/core/browser/autofill_manager_delegate.h"
+#include "components/autofill/core/browser/autofill_client.h"
+#include "components/autofill/core/browser/autofill_download_manager.h"
+#include "components/autofill/core/browser/autofill_driver.h"
 #include "components/autofill/core/browser/form_structure.h"
 #include "components/autofill/core/browser/personal_data_manager.h"
 #include "components/autofill/core/common/form_data.h"
-#include "components/autofill/core/common/forms_seen_state.h"
-#include "third_party/WebKit/public/web/WebFormElement.h"
 
 class GURL;
 
@@ -46,12 +45,11 @@ class PrefRegistrySyncable;
 
 namespace autofill {
 
-class AutofillDriver;
 class AutofillDataModel;
 class AutofillDownloadManager;
 class AutofillExternalDelegate;
 class AutofillField;
-class AutofillManagerDelegate;
+class AutofillClient;
 class AutofillManagerTestDelegate;
 class AutofillMetrics;
 class AutofillProfile;
@@ -75,8 +73,12 @@ class AutofillManager : public AutofillDownloadManager::Observer {
   // Registers our Enable/Disable Autofill pref.
   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
 
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+  static void MigrateUserPrefs(PrefService* prefs);
+#endif  // defined(OS_MACOSX) && !defined(OS_IOS)
+
   AutofillManager(AutofillDriver* driver,
-                  autofill::AutofillManagerDelegate* delegate,
+                  AutofillClient* client,
                   const std::string& app_locale,
                   AutofillDownloadManagerState enable_download_manager);
   virtual ~AutofillManager();
@@ -84,14 +86,29 @@ class AutofillManager : public AutofillDownloadManager::Observer {
   // Sets an external delegate.
   void SetExternalDelegate(AutofillExternalDelegate* delegate);
 
+  void ShowAutofillSettings();
+
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+  // Whether the field represented by |fieldData| should show an entry to prompt
+  // the user to give Chrome access to the user's address book.
+  bool ShouldShowAccessAddressBookSuggestion(const FormData& data,
+                                             const FormFieldData& field_data);
+
+  // If Chrome has not prompted for access to the user's address book, the
+  // method prompts the user for permission and blocks the process. Otherwise,
+  // this method has no effect. The return value reflects whether the user was
+  // prompted with a modal dialog.
+  bool AccessAddressBook();
+#endif  // defined(OS_MACOSX) && !defined(OS_IOS)
+
   // Called from our external delegate so they cannot be private.
-  virtual void OnFillAutofillFormData(int query_id,
-                                      const FormData& form,
-                                      const FormFieldData& field,
-                                      int unique_id);
-  void OnDidShowAutofillSuggestions(bool is_new_popup);
+  virtual void FillOrPreviewForm(AutofillDriver::RendererFormDataAction action,
+                                 int query_id,
+                                 const FormData& form,
+                                 const FormFieldData& field,
+                                 int unique_id);
+  void DidShowSuggestions(bool is_new_popup);
   void OnDidFillAutofillFormData(const base::TimeTicks& timestamp);
-  void OnShowAutofillDialog();
   void OnDidPreviewAutofillFormData();
 
   // Remove the credit card or Autofill profile that matches |unique_id|
@@ -108,18 +125,15 @@ class AutofillManager : public AutofillDownloadManager::Observer {
   // Happens when the autocomplete dialog runs its callback when being closed.
   void RequestAutocompleteDialogClosed();
 
-  autofill::AutofillManagerDelegate* delegate() const {
-    return manager_delegate_;
-  }
+  AutofillClient* client() const { return client_; }
 
   const std::string& app_locale() const { return app_locale_; }
 
   // Only for testing.
-  void SetTestDelegate(autofill::AutofillManagerTestDelegate* delegate);
+  void SetTestDelegate(AutofillManagerTestDelegate* delegate);
 
   void OnFormsSeen(const std::vector<FormData>& forms,
-                   const base::TimeTicks& timestamp,
-                   autofill::FormsSeenState state);
+                   const base::TimeTicks& timestamp);
 
   // Processes the submitted |form|, saving any new Autofill data and uploading
   // the possible field types for the submitted fields to the crowdsourcing
@@ -138,44 +152,34 @@ class AutofillManager : public AutofillDownloadManager::Observer {
                                 const gfx::RectF& bounding_box,
                                 bool display_warning);
   void OnDidEndTextFieldEditing();
-  void OnHideAutofillUI();
-  void OnAddPasswordFormMapping(
-      const FormFieldData& form,
-      const PasswordFormFillData& fill_data);
-  void OnShowPasswordSuggestions(
-      const FormFieldData& field,
-      const gfx::RectF& bounds,
-      const std::vector<base::string16>& suggestions,
-      const std::vector<base::string16>& realms);
+  void OnHidePopup();
   void OnSetDataList(const std::vector<base::string16>& values,
                      const std::vector<base::string16>& labels);
 
-  // Requests an interactive autocomplete UI be shown.
-  void OnRequestAutocomplete(const FormData& form,
-                             const GURL& frame_url);
-
-  // Try and upload |form|. This differs from OnFormSubmitted() in a few ways.
+  // Try to label password fields and upload |form|. This differs from
+  // OnFormSubmitted() in a few ways.
   //   - This function will only label the first <input type="password"> field
-  //     as ACCOUNT_CREATION_PASSWORD. Other fields will stay unlabeled, as they
+  //     as |password_type|. Other fields will stay unlabeled, as they
   //     should have been labeled during the upload for OnFormSubmitted().
   //   - This function does not assume that |form| is being uploaded during
   //     the same browsing session as it was originally submitted (as we may
   //     not have the necessary information to classify the form at that time)
   //     so it bypasses the cache and doesn't log the same quality UMA metrics.
-  bool UploadPasswordGenerationForm(const FormData& form);
+  bool UploadPasswordForm(const FormData& form,
+                          const ServerFieldType& pasword_type);
 
   // Resets cache.
   virtual void Reset();
 
+  // Returns the value of the AutofillEnabled pref.
+  virtual bool IsAutofillEnabled() const;
+
  protected:
   // Test code should prefer to use this constructor.
   AutofillManager(AutofillDriver* driver,
-                  autofill::AutofillManagerDelegate* delegate,
+                  AutofillClient* client,
                   PersonalDataManager* personal_data);
 
-  // Returns the value of the AutofillEnabled pref.
-  virtual bool IsAutofillEnabled() const;
-
   // Uploads the form data to the Autofill server.
   virtual void UploadFormData(const FormStructure& submitted_form);
 
@@ -210,35 +214,23 @@ class AutofillManager : public AutofillDownloadManager::Observer {
     return external_delegate_;
   }
 
-  // Causes the dialog for request autocomplete feature to be shown.
-  virtual void ShowRequestAutocompleteDialog(
-      const FormData& form,
-      const GURL& source_url,
-      const base::Callback<void(const FormStructure*)>& callback);
-
-  // Tell the renderer the current interactive autocomplete finished.
-  virtual void ReturnAutocompleteResult(
-      WebKit::WebFormElement::AutocompleteResult result,
-      const FormData& form_data);
-
  private:
   // AutofillDownloadManager::Observer:
   virtual void OnLoadedServerPredictions(
       const std::string& response_xml) OVERRIDE;
 
-  // Passes return data for an OnRequestAutocomplete call back to the page.
-  void ReturnAutocompleteData(const FormStructure* result);
-
-  // Fills |host| with the RenderViewHost for this tab.
-  // Returns false if Autofill is disabled or if the host is unavailable.
-  bool GetHost(content::RenderViewHost** host) const WARN_UNUSED_RESULT;
+  // Returns false if Autofill is disabled or if no Autofill data is available.
+  bool RefreshDataModels() const;
 
   // Unpacks |unique_id| and fills |form_group| and |variant| with the
-  // appropriate data source and variant index.  Returns false if the unpacked
-  // id cannot be found.
+  // appropriate data source and variant index. Sets |is_credit_card| to true
+  // if |data_model| points to a CreditCard data model, false if it's a
+  // profile data model.
+  // Returns false if the unpacked id cannot be found.
   bool GetProfileOrCreditCard(int unique_id,
                               const AutofillDataModel** data_model,
-                              size_t* variant) const WARN_UNUSED_RESULT;
+                              size_t* variant,
+                              bool* is_credit_card) const WARN_UNUSED_RESULT;
 
   // Fills |form_structure| cached element corresponding to |form|.
   // Returns false if the cached element was not found.
@@ -301,7 +293,7 @@ class AutofillManager : public AutofillDownloadManager::Observer {
   // outlive this object.
   AutofillDriver* driver_;
 
-  autofill::AutofillManagerDelegate* const manager_delegate_;
+  AutofillClient* const client_;
 
   std::string app_locale_;
 
@@ -335,8 +327,8 @@ class AutofillManager : public AutofillDownloadManager::Observer {
   bool user_did_autofill_;
   // Has the user edited a field that was previously autofilled?
   bool user_did_edit_autofilled_field_;
-  // When the page finished loading.
-  base::TimeTicks forms_loaded_timestamp_;
+  // When the form finished loading.
+  std::map<FormData, base::TimeTicks> forms_loaded_timestamps_;
   // When the user first interacted with a potentially fillable form on this
   // page.
   base::TimeTicks initial_interaction_timestamp_;
@@ -353,12 +345,12 @@ class AutofillManager : public AutofillDownloadManager::Observer {
   AutofillExternalDelegate* external_delegate_;
 
   // Delegate used in test to get notifications on certain events.
-  autofill::AutofillManagerTestDelegate* test_delegate_;
+  AutofillManagerTestDelegate* test_delegate_;
 
   base::WeakPtrFactory<AutofillManager> weak_ptr_factory_;
 
   friend class AutofillManagerTest;
-  friend class autofill::FormStructureBrowserTest;
+  friend class FormStructureBrowserTest;
   FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest,
                            DeterminePossibleFieldTypesForUpload);
   FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest,