| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_ |
| 6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/supports_user_data.h" | 11 #include "base/supports_user_data.h" |
| 12 #include "components/autofill/content/public/interfaces/autofill_agent.mojom.h" | 12 #include "components/autofill/content/public/interfaces/autofill_agent.mojom.h" |
| 13 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" | 13 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" |
| 14 #include "components/autofill/core/browser/autofill_driver.h" | 14 #include "components/autofill/core/browser/autofill_driver.h" |
| 15 #include "components/autofill/core/browser/autofill_external_delegate.h" | 15 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 16 #include "components/autofill/core/browser/autofill_manager.h" | 16 #include "components/autofill/core/browser/autofill_manager.h" |
| 17 #include "mojo/public/cpp/bindings/binding_set.h" | 17 #include "mojo/public/cpp/bindings/binding.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 class BrowserContext; | 20 class BrowserContext; |
| 21 class RenderFrameHost; | 21 class RenderFrameHost; |
| 22 struct FrameNavigateParams; | 22 struct FrameNavigateParams; |
| 23 struct LoadCommittedDetails; | 23 struct LoadCommittedDetails; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace IPC { | |
| 27 class Message; | |
| 28 } | |
| 29 | |
| 30 namespace autofill { | 26 namespace autofill { |
| 31 | 27 |
| 32 class AutofillClient; | 28 class AutofillClient; |
| 33 | 29 |
| 34 // Class that drives autofill flow in the browser process based on | 30 // Class that drives autofill flow in the browser process based on |
| 35 // communication from the renderer and from the external world. There is one | 31 // communication from the renderer and from the external world. There is one |
| 36 // instance per RenderFrameHost. | 32 // instance per RenderFrameHost. |
| 37 class ContentAutofillDriver : public AutofillDriver, | 33 class ContentAutofillDriver : public AutofillDriver, |
| 38 public mojom::AutofillDriver { | 34 public mojom::AutofillDriver { |
| 39 public: | 35 public: |
| 40 ContentAutofillDriver( | 36 ContentAutofillDriver( |
| 41 content::RenderFrameHost* render_frame_host, | 37 content::RenderFrameHost* render_frame_host, |
| 42 AutofillClient* client, | 38 AutofillClient* client, |
| 43 const std::string& app_locale, | 39 const std::string& app_locale, |
| 44 AutofillManager::AutofillDownloadManagerState enable_download_manager); | 40 AutofillManager::AutofillDownloadManagerState enable_download_manager); |
| 45 ~ContentAutofillDriver() override; | 41 ~ContentAutofillDriver() override; |
| 46 | 42 |
| 43 // Gets the driver for |render_frame_host|. |
| 44 static ContentAutofillDriver* GetForRenderFrameHost( |
| 45 content::RenderFrameHost* render_frame_host); |
| 46 |
| 47 void BindRequest(mojom::AutofillDriverRequest request); | 47 void BindRequest(mojom::AutofillDriverRequest request); |
| 48 | 48 |
| 49 // AutofillDriver: | 49 // AutofillDriver: |
| 50 bool IsOffTheRecord() const override; | 50 bool IsOffTheRecord() const override; |
| 51 net::URLRequestContextGetter* GetURLRequestContext() override; | 51 net::URLRequestContextGetter* GetURLRequestContext() override; |
| 52 base::SequencedWorkerPool* GetBlockingPool() override; | 52 base::SequencedWorkerPool* GetBlockingPool() override; |
| 53 bool RendererIsAvailable() override; | 53 bool RendererIsAvailable() override; |
| 54 void SendFormDataToRenderer(int query_id, | 54 void SendFormDataToRenderer(int query_id, |
| 55 RendererFormDataAction action, | 55 RendererFormDataAction action, |
| 56 const FormData& data) override; | 56 const FormData& data) override; |
| 57 void PropagateAutofillPredictions( | 57 void PropagateAutofillPredictions( |
| 58 const std::vector<autofill::FormStructure*>& forms) override; | 58 const std::vector<autofill::FormStructure*>& forms) override; |
| 59 void SendAutofillTypePredictionsToRenderer( | 59 void SendAutofillTypePredictionsToRenderer( |
| 60 const std::vector<FormStructure*>& forms) override; | 60 const std::vector<FormStructure*>& forms) override; |
| 61 void RendererShouldAcceptDataListSuggestion( | 61 void RendererShouldAcceptDataListSuggestion( |
| 62 const base::string16& value) override; | 62 const base::string16& value) override; |
| 63 void RendererShouldClearFilledForm() override; | 63 void RendererShouldClearFilledForm() override; |
| 64 void RendererShouldClearPreviewedForm() override; | 64 void RendererShouldClearPreviewedForm() override; |
| 65 void RendererShouldFillFieldWithValue(const base::string16& value) override; | 65 void RendererShouldFillFieldWithValue(const base::string16& value) override; |
| 66 void RendererShouldPreviewFieldWithValue( | 66 void RendererShouldPreviewFieldWithValue( |
| 67 const base::string16& value) override; | 67 const base::string16& value) override; |
| 68 void PopupHidden() override; | 68 void PopupHidden() override; |
| 69 gfx::RectF TransformBoundingBoxToViewportCoordinates( | 69 gfx::RectF TransformBoundingBoxToViewportCoordinates( |
| 70 const gfx::RectF& bounding_box) override; | 70 const gfx::RectF& bounding_box) override; |
| 71 | 71 |
| 72 // mojom::AutofillDriver: | 72 // mojom::AutofillDriver: |
| 73 void FirstUserGestureObserved() override; | 73 void FirstUserGestureObserved() override; |
| 74 | 74 void FormsSeen(mojo::Array<FormData> forms, |
| 75 // Handles a message that came from the associated render frame. | 75 const base::TimeTicks& timestamp) override; |
| 76 bool HandleMessage(const IPC::Message& message); | 76 void WillSubmitForm(const FormData& form, |
| 77 const base::TimeTicks& timestamp) override; |
| 78 void FormSubmitted(const FormData& form) override; |
| 79 void TextFieldDidChange(const FormData& form, |
| 80 const FormFieldData& field, |
| 81 const base::TimeTicks& timestamp) override; |
| 82 void QueryFormFieldAutofill(int32_t id, |
| 83 const FormData& form, |
| 84 const FormFieldData& field, |
| 85 const gfx::RectF& bounding_box) override; |
| 86 void HidePopup() override; |
| 87 void PingAck() override; |
| 88 void FocusNoLongerOnForm() override; |
| 89 void DidFillAutofillFormData(const FormData& form, |
| 90 const base::TimeTicks& timestamp) override; |
| 91 void DidPreviewAutofillFormData() override; |
| 92 void DidEndTextFieldEditing() override; |
| 93 void SetDataList(mojo::Array<mojo::String> values, |
| 94 mojo::Array<mojo::String> labels) override; |
| 77 | 95 |
| 78 // Called when the frame has navigated. | 96 // Called when the frame has navigated. |
| 79 void DidNavigateFrame(const content::LoadCommittedDetails& details, | 97 void DidNavigateFrame(const content::LoadCommittedDetails& details, |
| 80 const content::FrameNavigateParams& params); | 98 const content::FrameNavigateParams& params); |
| 81 | 99 |
| 82 // Tells the render frame that a user gesture was observed | 100 // Tells the render frame that a user gesture was observed |
| 83 // somewhere in the tab (including in a different frame). | 101 // somewhere in the tab (including in a different frame). |
| 84 void NotifyFirstUserGestureObservedInTab(); | 102 void NotifyFirstUserGestureObservedInTab(); |
| 85 | 103 |
| 86 AutofillExternalDelegate* autofill_external_delegate() { | 104 AutofillExternalDelegate* autofill_external_delegate() { |
| 87 return &autofill_external_delegate_; | 105 return &autofill_external_delegate_; |
| 88 } | 106 } |
| 89 | 107 |
| 90 AutofillManager* autofill_manager() { return autofill_manager_.get(); } | 108 AutofillManager* autofill_manager() { return autofill_manager_.get(); } |
| 91 content::RenderFrameHost* render_frame_host() { return render_frame_host_; } | 109 content::RenderFrameHost* render_frame_host() { return render_frame_host_; } |
| 92 | 110 |
| 111 const mojom::AutofillAgentPtr& GetAutofillAgent(); |
| 112 |
| 93 protected: | 113 protected: |
| 94 // Sets the manager to |manager| and sets |manager|'s external delegate | 114 // Sets the manager to |manager| and sets |manager|'s external delegate |
| 95 // to |autofill_external_delegate_|. Takes ownership of |manager|. | 115 // to |autofill_external_delegate_|. Takes ownership of |manager|. |
| 96 void SetAutofillManager(std::unique_ptr<AutofillManager> manager); | 116 void SetAutofillManager(std::unique_ptr<AutofillManager> manager); |
| 97 | 117 |
| 98 private: | 118 private: |
| 99 void ConnectToMojoAutofillAgentIfNeeded(); | |
| 100 | |
| 101 // Weak ref to the RenderFrameHost the driver is associated with. Should | 119 // Weak ref to the RenderFrameHost the driver is associated with. Should |
| 102 // always be non-NULL and valid for lifetime of |this|. | 120 // always be non-NULL and valid for lifetime of |this|. |
| 103 content::RenderFrameHost* const render_frame_host_; | 121 content::RenderFrameHost* const render_frame_host_; |
| 104 | 122 |
| 105 // The per-tab client. | 123 // The per-tab client. |
| 106 AutofillClient* client_; | 124 AutofillClient* client_; |
| 107 | 125 |
| 108 // AutofillManager instance via which this object drives the shared Autofill | 126 // AutofillManager instance via which this object drives the shared Autofill |
| 109 // code. | 127 // code. |
| 110 std::unique_ptr<AutofillManager> autofill_manager_; | 128 std::unique_ptr<AutofillManager> autofill_manager_; |
| 111 | 129 |
| 112 // AutofillExternalDelegate instance that this object instantiates in the | 130 // AutofillExternalDelegate instance that this object instantiates in the |
| 113 // case where the Autofill native UI is enabled. | 131 // case where the Autofill native UI is enabled. |
| 114 AutofillExternalDelegate autofill_external_delegate_; | 132 AutofillExternalDelegate autofill_external_delegate_; |
| 115 | 133 |
| 116 mojo::BindingSet<mojom::AutofillDriver> bindings_; | 134 mojo::Binding<mojom::AutofillDriver> binding_; |
| 117 | 135 |
| 118 mojom::AutofillAgentPtr mojo_autofill_agent_; | 136 mojom::AutofillAgentPtr mojo_autofill_agent_; |
| 119 }; | 137 }; |
| 120 | 138 |
| 121 } // namespace autofill | 139 } // namespace autofill |
| 122 | 140 |
| 123 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_ | 141 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_ |
| OLD | NEW |