Home | History | Annotate | Download | only in autofill
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_AUTOFILL_TAB_AUTOFILL_MANAGER_DELEGATE_H_
      6 #define CHROME_BROWSER_UI_AUTOFILL_TAB_AUTOFILL_MANAGER_DELEGATE_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/i18n/rtl.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
     13 #include "components/autofill/content/browser/autocheckout_steps.h"
     14 #include "components/autofill/core/browser/autocheckout_bubble_state.h"
     15 #include "components/autofill/core/browser/autofill_manager_delegate.h"
     16 #include "content/public/browser/web_contents_observer.h"
     17 #include "content/public/browser/web_contents_user_data.h"
     18 
     19 namespace content {
     20 struct FrameNavigateParams;
     21 struct LoadCommittedDetails;
     22 class WebContents;
     23 }
     24 
     25 namespace autofill {
     26 
     27 class AutocheckoutBubble;
     28 class AutofillDialogController;
     29 class AutofillPopupControllerImpl;
     30 struct FormData;
     31 
     32 // Chrome implementation of AutofillManagerDelegate.
     33 class TabAutofillManagerDelegate
     34     : public AutofillManagerDelegate,
     35       public content::WebContentsUserData<TabAutofillManagerDelegate>,
     36       public content::WebContentsObserver {
     37  public:
     38   virtual ~TabAutofillManagerDelegate();
     39 
     40   // Called when the tab corresponding to |this| instance is activated.
     41   void TabActivated(int reason);
     42 
     43   // AutofillManagerDelegate implementation.
     44   virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE;
     45   virtual PrefService* GetPrefs() OVERRIDE;
     46   virtual autocheckout::WhitelistManager*
     47       GetAutocheckoutWhitelistManager() const OVERRIDE;
     48   virtual void HideRequestAutocompleteDialog() OVERRIDE;
     49   virtual void OnAutocheckoutError() OVERRIDE;
     50   virtual void OnAutocheckoutSuccess() OVERRIDE;
     51   virtual void ShowAutofillSettings() OVERRIDE;
     52   virtual void ConfirmSaveCreditCard(
     53       const AutofillMetrics& metric_logger,
     54       const CreditCard& credit_card,
     55       const base::Closure& save_card_callback) OVERRIDE;
     56   virtual bool ShowAutocheckoutBubble(
     57       const gfx::RectF& bounds,
     58       bool is_google_user,
     59       const base::Callback<void(AutocheckoutBubbleState)>& callback) OVERRIDE;
     60   virtual void HideAutocheckoutBubble() OVERRIDE;
     61   virtual void ShowRequestAutocompleteDialog(
     62       const FormData& form,
     63       const GURL& source_url,
     64       DialogType dialog_type,
     65       const base::Callback<void(const FormStructure*,
     66                                 const std::string&)>& callback) OVERRIDE;
     67   virtual void ShowAutofillPopup(
     68       const gfx::RectF& element_bounds,
     69       base::i18n::TextDirection text_direction,
     70       const std::vector<string16>& values,
     71       const std::vector<string16>& labels,
     72       const std::vector<string16>& icons,
     73       const std::vector<int>& identifiers,
     74       base::WeakPtr<AutofillPopupDelegate> delegate) OVERRIDE;
     75   virtual void UpdateAutofillPopupDataListValues(
     76       const std::vector<base::string16>& values,
     77       const std::vector<base::string16>& labels) OVERRIDE;
     78   virtual void HideAutofillPopup() OVERRIDE;
     79   virtual bool IsAutocompleteEnabled() OVERRIDE;
     80 
     81   virtual void AddAutocheckoutStep(AutocheckoutStepType step_type) OVERRIDE;
     82   virtual void UpdateAutocheckoutStep(
     83       AutocheckoutStepType step_type,
     84       AutocheckoutStepStatus step_status) OVERRIDE;
     85 
     86   // content::WebContentsObserver implementation.
     87   virtual void DidNavigateMainFrame(
     88       const content::LoadCommittedDetails& details,
     89       const content::FrameNavigateParams& params) OVERRIDE;
     90   virtual void WebContentsDestroyed(
     91       content::WebContents* web_contents) OVERRIDE;
     92   virtual void WasShown() OVERRIDE;
     93 
     94   // Exposed for testing.
     95   AutofillDialogController* GetDialogControllerForTesting() {
     96     return dialog_controller_.get();
     97   }
     98 
     99  private:
    100   explicit TabAutofillManagerDelegate(content::WebContents* web_contents);
    101   friend class content::WebContentsUserData<TabAutofillManagerDelegate>;
    102 
    103   content::WebContents* const web_contents_;
    104   base::WeakPtr<AutofillDialogController> dialog_controller_;
    105   base::WeakPtr<AutocheckoutBubble> autocheckout_bubble_;
    106   base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
    107 
    108   DISALLOW_COPY_AND_ASSIGN(TabAutofillManagerDelegate);
    109 };
    110 
    111 }  // namespace autofill
    112 
    113 #endif  // CHROME_BROWSER_UI_AUTOFILL_TAB_AUTOFILL_MANAGER_DELEGATE_H_
    114