Chromium Code Reviews| 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 #include "components/autofill/content/browser/content_autofill_driver.h" | 5 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 10 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
| 11 #include "components/autofill/core/browser/autofill_client.h" | 11 #include "components/autofill/core/browser/autofill_client.h" |
| 12 #include "components/autofill/core/browser/autofill_external_delegate.h" | 12 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 13 #include "components/autofill/core/browser/autofill_handler_proxy.h" | |
| 13 #include "components/autofill/core/browser/autofill_manager.h" | 14 #include "components/autofill/core/browser/autofill_manager.h" |
| 14 #include "components/autofill/core/browser/form_structure.h" | 15 #include "components/autofill/core/browser/form_structure.h" |
| 15 #include "components/autofill/core/common/autofill_switches.h" | 16 #include "components/autofill/core/common/autofill_switches.h" |
| 16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/render_widget_host.h" | 22 #include "content/public/browser/render_widget_host.h" |
| 22 #include "content/public/browser/render_widget_host_view.h" | 23 #include "content/public/browser/render_widget_host_view.h" |
| 23 #include "content/public/browser/site_instance.h" | 24 #include "content/public/browser/site_instance.h" |
| 24 #include "content/public/browser/storage_partition.h" | 25 #include "content/public/browser/storage_partition.h" |
| 25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 26 #include "services/service_manager/public/cpp/interface_provider.h" | 27 #include "services/service_manager/public/cpp/interface_provider.h" |
| 27 #include "ui/gfx/geometry/size_f.h" | 28 #include "ui/gfx/geometry/size_f.h" |
| 28 | 29 |
| 29 namespace autofill { | 30 namespace autofill { |
| 30 | 31 |
| 31 ContentAutofillDriver::ContentAutofillDriver( | 32 ContentAutofillDriver::ContentAutofillDriver( |
| 32 content::RenderFrameHost* render_frame_host, | 33 content::RenderFrameHost* render_frame_host, |
| 33 AutofillClient* client, | 34 AutofillClient* client, |
| 34 const std::string& app_locale, | 35 const std::string& app_locale, |
| 35 AutofillManager::AutofillDownloadManagerState enable_download_manager) | 36 AutofillManager::AutofillDownloadManagerState enable_download_manager, |
| 37 AutofillProvider* provider) | |
| 36 : render_frame_host_(render_frame_host), | 38 : render_frame_host_(render_frame_host), |
| 37 autofill_manager_(new AutofillManager(this, | 39 autofill_manager_(nullptr), |
| 38 client, | |
| 39 app_locale, | |
| 40 enable_download_manager)), | |
| 41 autofill_external_delegate_(autofill_manager_.get(), this), | |
| 42 key_press_handler_manager_(this), | 40 key_press_handler_manager_(this), |
| 43 binding_(this) { | 41 binding_(this) { |
| 44 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); | 42 if (provider) { |
|
Mathieu
2017/05/24 18:02:02
Please comment the behavior here. What is a provid
michaelbai
2017/05/26 23:12:08
Done.
| |
| 43 autofill_handler_ = base::MakeUnique<AutofillHandlerProxy>(this, provider); | |
| 44 } else { | |
| 45 autofill_handler_ = base::MakeUnique<AutofillManager>( | |
| 46 this, client, app_locale, enable_download_manager); | |
| 47 autofill_manager_ = static_cast<AutofillManager*>(autofill_handler_.get()); | |
| 48 autofill_external_delegate_ = | |
| 49 base::MakeUnique<AutofillExternalDelegate>(autofill_manager_, this); | |
| 50 autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get()); | |
| 51 } | |
| 45 } | 52 } |
| 46 | 53 |
| 47 ContentAutofillDriver::~ContentAutofillDriver() {} | 54 ContentAutofillDriver::~ContentAutofillDriver() {} |
| 48 | 55 |
| 49 // static | 56 // static |
| 50 ContentAutofillDriver* ContentAutofillDriver::GetForRenderFrameHost( | 57 ContentAutofillDriver* ContentAutofillDriver::GetForRenderFrameHost( |
| 51 content::RenderFrameHost* render_frame_host) { | 58 content::RenderFrameHost* render_frame_host) { |
| 52 ContentAutofillDriverFactory* factory = | 59 ContentAutofillDriverFactory* factory = |
| 53 ContentAutofillDriverFactory::FromWebContents( | 60 ContentAutofillDriverFactory::FromWebContents( |
| 54 content::WebContents::FromRenderFrameHost(render_frame_host)); | 61 content::WebContents::FromRenderFrameHost(render_frame_host)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( | 148 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( |
| 142 const base::string16& value) { | 149 const base::string16& value) { |
| 143 if (!RendererIsAvailable()) | 150 if (!RendererIsAvailable()) |
| 144 return; | 151 return; |
| 145 GetAutofillAgent()->PreviewFieldWithValue(value); | 152 GetAutofillAgent()->PreviewFieldWithValue(value); |
| 146 } | 153 } |
| 147 | 154 |
| 148 void ContentAutofillDriver::PopupHidden() { | 155 void ContentAutofillDriver::PopupHidden() { |
| 149 // If the unmask prompt is showing, keep showing the preview. The preview | 156 // If the unmask prompt is showing, keep showing the preview. The preview |
| 150 // will be cleared when the prompt closes. | 157 // will be cleared when the prompt closes. |
| 151 if (!autofill_manager_->IsShowingUnmaskPrompt()) | 158 if (autofill_manager_ && !autofill_manager_->IsShowingUnmaskPrompt()) |
|
Roger McFarlane (Chromium)
2017/05/24 04:18:22
maybe add IsShowingUnmaskPrompt as a, default fals
michaelbai
2017/05/24 05:14:09
I didn't add this method to the interface because
| |
| 152 RendererShouldClearPreviewedForm(); | 159 RendererShouldClearPreviewedForm(); |
| 153 } | 160 } |
| 154 | 161 |
| 155 gfx::RectF ContentAutofillDriver::TransformBoundingBoxToViewportCoordinates( | 162 gfx::RectF ContentAutofillDriver::TransformBoundingBoxToViewportCoordinates( |
| 156 const gfx::RectF& bounding_box) { | 163 const gfx::RectF& bounding_box) { |
| 157 content::RenderWidgetHostView* view = render_frame_host_->GetView(); | 164 content::RenderWidgetHostView* view = render_frame_host_->GetView(); |
| 158 if (!view) | 165 if (!view) |
| 159 return bounding_box; | 166 return bounding_box; |
| 160 | 167 |
| 161 gfx::Point orig_point(bounding_box.x(), bounding_box.y()); | 168 gfx::Point orig_point(bounding_box.x(), bounding_box.y()); |
| 162 gfx::Point transformed_point = | 169 gfx::Point transformed_point = |
| 163 view->TransformPointToRootCoordSpace(orig_point); | 170 view->TransformPointToRootCoordSpace(orig_point); |
| 164 return gfx::RectF(transformed_point.x(), transformed_point.y(), | 171 return gfx::RectF(transformed_point.x(), transformed_point.y(), |
| 165 bounding_box.width(), bounding_box.height()); | 172 bounding_box.width(), bounding_box.height()); |
| 166 } | 173 } |
| 167 | 174 |
| 168 void ContentAutofillDriver::DidInteractWithCreditCardForm() { | 175 void ContentAutofillDriver::DidInteractWithCreditCardForm() { |
| 169 // Notify the WebContents about credit card inputs on HTTP pages. | 176 // Notify the WebContents about credit card inputs on HTTP pages. |
| 170 content::WebContents* contents = | 177 content::WebContents* contents = |
| 171 content::WebContents::FromRenderFrameHost(render_frame_host_); | 178 content::WebContents::FromRenderFrameHost(render_frame_host_); |
| 172 if (contents->GetVisibleURL().SchemeIsCryptographic()) | 179 if (contents->GetVisibleURL().SchemeIsCryptographic()) |
| 173 return; | 180 return; |
| 174 contents->OnCreditCardInputShownOnHttp(); | 181 contents->OnCreditCardInputShownOnHttp(); |
| 175 } | 182 } |
| 176 | 183 |
| 177 void ContentAutofillDriver::FormsSeen(const std::vector<FormData>& forms, | 184 void ContentAutofillDriver::FormsSeen(const std::vector<FormData>& forms, |
| 178 base::TimeTicks timestamp) { | 185 base::TimeTicks timestamp) { |
| 179 autofill_manager_->OnFormsSeen(forms, timestamp); | 186 autofill_handler_->OnFormsSeen(forms, timestamp); |
| 180 } | 187 } |
| 181 | 188 |
| 182 void ContentAutofillDriver::WillSubmitForm(const FormData& form, | 189 void ContentAutofillDriver::WillSubmitForm(const FormData& form, |
| 183 base::TimeTicks timestamp) { | 190 base::TimeTicks timestamp) { |
| 184 autofill_manager_->OnWillSubmitForm(form, timestamp); | 191 autofill_handler_->OnWillSubmitForm(form, timestamp); |
| 185 } | 192 } |
| 186 | 193 |
| 187 void ContentAutofillDriver::FormSubmitted(const FormData& form) { | 194 void ContentAutofillDriver::FormSubmitted(const FormData& form) { |
| 188 autofill_manager_->OnFormSubmitted(form); | 195 autofill_handler_->OnFormSubmitted(form); |
| 189 } | 196 } |
| 190 | 197 |
| 191 void ContentAutofillDriver::TextFieldDidChange(const FormData& form, | 198 void ContentAutofillDriver::TextFieldDidChange(const FormData& form, |
| 192 const FormFieldData& field, | 199 const FormFieldData& field, |
| 193 base::TimeTicks timestamp) { | 200 base::TimeTicks timestamp) { |
| 194 autofill_manager_->OnTextFieldDidChange(form, field, timestamp); | 201 autofill_handler_->OnTextFieldDidChange(form, field, timestamp); |
| 195 } | 202 } |
| 196 | 203 |
| 197 void ContentAutofillDriver::QueryFormFieldAutofill( | 204 void ContentAutofillDriver::QueryFormFieldAutofill( |
| 198 int32_t id, | 205 int32_t id, |
| 199 const FormData& form, | 206 const FormData& form, |
| 200 const FormFieldData& field, | 207 const FormFieldData& field, |
| 201 const gfx::RectF& bounding_box) { | 208 const gfx::RectF& bounding_box) { |
| 202 autofill_manager_->OnQueryFormFieldAutofill(id, form, field, bounding_box); | 209 autofill_handler_->OnQueryFormFieldAutofill(id, form, field, bounding_box); |
| 203 } | 210 } |
| 204 | 211 |
| 205 void ContentAutofillDriver::HidePopup() { | 212 void ContentAutofillDriver::HidePopup() { |
| 206 autofill_manager_->OnHidePopup(); | 213 autofill_handler_->OnHidePopup(); |
| 207 } | 214 } |
| 208 | 215 |
| 209 void ContentAutofillDriver::FocusNoLongerOnForm() { | 216 void ContentAutofillDriver::FocusNoLongerOnForm() { |
| 210 autofill_manager_->OnFocusNoLongerOnForm(); | 217 autofill_handler_->OnFocusNoLongerOnForm(); |
| 211 } | 218 } |
| 212 | 219 |
| 213 void ContentAutofillDriver::DidFillAutofillFormData(const FormData& form, | 220 void ContentAutofillDriver::DidFillAutofillFormData(const FormData& form, |
| 214 base::TimeTicks timestamp) { | 221 base::TimeTicks timestamp) { |
| 215 autofill_manager_->OnDidFillAutofillFormData(form, timestamp); | 222 autofill_handler_->OnDidFillAutofillFormData(form, timestamp); |
| 216 } | 223 } |
| 217 | 224 |
| 218 void ContentAutofillDriver::DidPreviewAutofillFormData() { | 225 void ContentAutofillDriver::DidPreviewAutofillFormData() { |
| 219 autofill_manager_->OnDidPreviewAutofillFormData(); | 226 autofill_handler_->OnDidPreviewAutofillFormData(); |
| 220 } | 227 } |
| 221 | 228 |
| 222 void ContentAutofillDriver::DidEndTextFieldEditing() { | 229 void ContentAutofillDriver::DidEndTextFieldEditing() { |
| 223 autofill_manager_->OnDidEndTextFieldEditing(); | 230 autofill_handler_->OnDidEndTextFieldEditing(); |
| 224 } | 231 } |
| 225 | 232 |
| 226 void ContentAutofillDriver::SetDataList( | 233 void ContentAutofillDriver::SetDataList( |
| 227 const std::vector<base::string16>& values, | 234 const std::vector<base::string16>& values, |
| 228 const std::vector<base::string16>& labels) { | 235 const std::vector<base::string16>& labels) { |
| 229 autofill_manager_->OnSetDataList(values, labels); | 236 autofill_handler_->OnSetDataList(values, labels); |
| 230 } | 237 } |
| 231 | 238 |
| 232 void ContentAutofillDriver::DidNavigateFrame( | 239 void ContentAutofillDriver::DidNavigateFrame( |
| 233 content::NavigationHandle* navigation_handle) { | 240 content::NavigationHandle* navigation_handle) { |
| 234 if (navigation_handle->IsInMainFrame() && | 241 if (navigation_handle->IsInMainFrame() && |
| 235 !navigation_handle->IsSameDocument()) { | 242 !navigation_handle->IsSameDocument()) { |
| 236 autofill_manager_->Reset(); | 243 autofill_handler_->Reset(); |
| 237 } | 244 } |
| 238 } | 245 } |
| 239 | 246 |
| 240 void ContentAutofillDriver::SetAutofillManager( | 247 void ContentAutofillDriver::SetAutofillManager( |
| 241 std::unique_ptr<AutofillManager> manager) { | 248 std::unique_ptr<AutofillManager> manager) { |
| 242 autofill_manager_ = std::move(manager); | 249 CHECK(autofill_manager_); |
| 243 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); | 250 autofill_handler_ = std::move(manager); |
| 251 autofill_manager_ = static_cast<AutofillManager*>(autofill_handler_.get()); | |
| 252 autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get()); | |
| 244 } | 253 } |
| 245 | 254 |
| 246 const mojom::AutofillAgentPtr& ContentAutofillDriver::GetAutofillAgent() { | 255 const mojom::AutofillAgentPtr& ContentAutofillDriver::GetAutofillAgent() { |
| 247 // Here is a lazy binding, and will not reconnect after connection error. | 256 // Here is a lazy binding, and will not reconnect after connection error. |
| 248 if (!autofill_agent_) { | 257 if (!autofill_agent_) { |
| 249 render_frame_host_->GetRemoteInterfaces()->GetInterface( | 258 render_frame_host_->GetRemoteInterfaces()->GetInterface( |
| 250 mojo::MakeRequest(&autofill_agent_)); | 259 mojo::MakeRequest(&autofill_agent_)); |
| 251 } | 260 } |
| 252 | 261 |
| 253 return autofill_agent_; | 262 return autofill_agent_; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 272 | 281 |
| 273 void ContentAutofillDriver::RemoveHandler( | 282 void ContentAutofillDriver::RemoveHandler( |
| 274 const content::RenderWidgetHost::KeyPressEventCallback& handler) { | 283 const content::RenderWidgetHost::KeyPressEventCallback& handler) { |
| 275 content::RenderWidgetHostView* view = render_frame_host_->GetView(); | 284 content::RenderWidgetHostView* view = render_frame_host_->GetView(); |
| 276 if (!view) | 285 if (!view) |
| 277 return; | 286 return; |
| 278 view->GetRenderWidgetHost()->RemoveKeyPressEventCallback(handler); | 287 view->GetRenderWidgetHost()->RemoveKeyPressEventCallback(handler); |
| 279 } | 288 } |
| 280 | 289 |
| 281 } // namespace autofill | 290 } // namespace autofill |
| OLD | NEW |