1 // Copyright 2013 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 COMPONENTS_AUTOFILL_CONTENT_BROWSER_AUTOFILL_DRIVER_IMPL_H_ 6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_AUTOFILL_DRIVER_IMPL_H_ 7 8 #include <string> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "base/supports_user_data.h" 12 #include "components/autofill/core/browser/autofill_driver.h" 13 #include "components/autofill/core/browser/autofill_external_delegate.h" 14 #include "components/autofill/core/browser/autofill_manager.h" 15 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/web_contents_observer.h" 18 19 namespace content { 20 class WebContents; 21 } 22 23 namespace IPC { 24 class Message; 25 } 26 27 namespace autofill { 28 29 class AutofillContext; 30 class AutofillManagerDelegate; 31 32 // Class that drives autofill flow in the browser process based on 33 // communication from the renderer and from the external world. There is one 34 // instance per WebContents. 35 class AutofillDriverImpl : public AutofillDriver, 36 public content::NotificationObserver, 37 public content::WebContentsObserver, 38 public base::SupportsUserData::Data { 39 public: 40 static void CreateForWebContentsAndDelegate( 41 content::WebContents* contents, 42 autofill::AutofillManagerDelegate* delegate, 43 const std::string& app_locale, 44 AutofillManager::AutofillDownloadManagerState enable_download_manager); 45 static AutofillDriverImpl* FromWebContents(content::WebContents* contents); 46 47 // AutofillDriver: 48 virtual content::WebContents* GetWebContents() OVERRIDE; 49 virtual bool RendererIsAvailable() OVERRIDE; 50 virtual void SetRendererActionOnFormDataReception( 51 RendererFormDataAction action) OVERRIDE; 52 virtual void SendFormDataToRenderer(int query_id, 53 const FormData& data) OVERRIDE; 54 virtual void SendAutofillTypePredictionsToRenderer( 55 const std::vector<FormStructure*>& forms) OVERRIDE; 56 virtual void RendererShouldClearFilledForm() OVERRIDE; 57 virtual void RendererShouldClearPreviewedForm() OVERRIDE; 58 59 AutofillExternalDelegate* autofill_external_delegate() { 60 return autofill_external_delegate_.get(); 61 } 62 63 // Sets the external delegate to |delegate| both within this class and in the 64 // shared Autofill code. Takes ownership of |delegate|. 65 void SetAutofillExternalDelegate( 66 scoped_ptr<AutofillExternalDelegate> delegate); 67 68 AutofillManager* autofill_manager() { return autofill_manager_.get(); } 69 70 protected: 71 AutofillDriverImpl( 72 content::WebContents* web_contents, 73 autofill::AutofillManagerDelegate* delegate, 74 const std::string& app_locale, 75 AutofillManager::AutofillDownloadManagerState enable_download_manager); 76 virtual ~AutofillDriverImpl(); 77 78 // content::WebContentsObserver: 79 virtual void DidNavigateMainFrame( 80 const content::LoadCommittedDetails& details, 81 const content::FrameNavigateParams& params) OVERRIDE; 82 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 83 84 // Sets the manager to |manager| and sets |manager|'s external delegate 85 // to |autofill_external_delegate_|. Takes ownership of |manager|. 86 void SetAutofillManager(scoped_ptr<AutofillManager> manager); 87 88 private: 89 // content::NotificationObserver: 90 virtual void Observe(int type, 91 const content::NotificationSource& source, 92 const content::NotificationDetails& details) OVERRIDE; 93 94 // A scoped container for notification registries. 95 content::NotificationRegistrar registrar_; 96 97 // AutofillExternalDelegate instance that this object instantiates in the 98 // case where the autofill native UI is enabled. 99 scoped_ptr<AutofillExternalDelegate> autofill_external_delegate_; 100 101 // AutofillManager instance via which this object drives the shared Autofill 102 // code. 103 scoped_ptr<AutofillManager> autofill_manager_; 104 }; 105 106 } // namespace autofill 107 108 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_AUTOFILL_DRIVER_IMPL_H_ 109