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 "base/strings/utf_string_conversions.h" | |
| 10 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 12 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
| 12 #include "components/autofill/content/common/autofill_messages.h" | 13 #include "components/autofill/content/common/autofill_messages.h" |
| 13 #include "components/autofill/core/browser/autofill_client.h" | 14 #include "components/autofill/core/browser/autofill_client.h" |
| 14 #include "components/autofill/core/browser/autofill_external_delegate.h" | 15 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 15 #include "components/autofill/core/browser/autofill_manager.h" | 16 #include "components/autofill/core/browser/autofill_manager.h" |
| 16 #include "components/autofill/core/browser/form_structure.h" | 17 #include "components/autofill/core/browser/form_structure.h" |
| 17 #include "components/autofill/core/common/autofill_switches.h" | 18 #include "components/autofill/core/common/autofill_switches.h" |
| 18 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/navigation_controller.h" | 21 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
| 25 #include "content/public/browser/site_instance.h" | 26 #include "content/public/browser/site_instance.h" |
| 26 #include "content/public/browser/storage_partition.h" | 27 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 #include "mojo/common/common_type_converters.h" | |
| 29 #include "services/shell/public/cpp/interface_provider.h" | 29 #include "services/shell/public/cpp/interface_provider.h" |
| 30 #include "ui/gfx/geometry/size_f.h" | 30 #include "ui/gfx/geometry/size_f.h" |
| 31 | 31 |
| 32 namespace autofill { | 32 namespace autofill { |
| 33 | 33 |
| 34 ContentAutofillDriver::ContentAutofillDriver( | 34 ContentAutofillDriver::ContentAutofillDriver( |
| 35 content::RenderFrameHost* render_frame_host, | 35 content::RenderFrameHost* render_frame_host, |
| 36 AutofillClient* client, | 36 AutofillClient* client, |
| 37 const std::string& app_locale, | 37 const std::string& app_locale, |
| 38 AutofillManager::AutofillDownloadManagerState enable_download_manager) | 38 AutofillManager::AutofillDownloadManagerState enable_download_manager) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 const std::vector<FormStructure*>& forms) { | 109 const std::vector<FormStructure*>& forms) { |
| 110 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 110 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 111 switches::kShowAutofillTypePredictions)) | 111 switches::kShowAutofillTypePredictions)) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 if (!RendererIsAvailable()) | 114 if (!RendererIsAvailable()) |
| 115 return; | 115 return; |
| 116 | 116 |
| 117 std::vector<FormDataPredictions> type_predictions = | 117 std::vector<FormDataPredictions> type_predictions = |
| 118 FormStructure::GetFieldTypePredictions(forms); | 118 FormStructure::GetFieldTypePredictions(forms); |
| 119 GetAutofillAgent()->FieldTypePredictionsAvailable( | 119 GetAutofillAgent()->FieldTypePredictionsAvailable(type_predictions); |
| 120 std::move(type_predictions)); | |
| 121 } | 120 } |
| 122 | 121 |
| 123 void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion( | 122 void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion( |
| 124 const base::string16& value) { | 123 const base::string16& value) { |
| 125 if (!RendererIsAvailable()) | 124 if (!RendererIsAvailable()) |
| 126 return; | 125 return; |
| 127 GetAutofillAgent()->AcceptDataListSuggestion(mojo::String::From(value)); | 126 GetAutofillAgent()->AcceptDataListSuggestion(base::UTF16ToUTF8(value)); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void ContentAutofillDriver::RendererShouldClearFilledForm() { | 129 void ContentAutofillDriver::RendererShouldClearFilledForm() { |
| 131 if (!RendererIsAvailable()) | 130 if (!RendererIsAvailable()) |
| 132 return; | 131 return; |
| 133 GetAutofillAgent()->ClearForm(); | 132 GetAutofillAgent()->ClearForm(); |
| 134 } | 133 } |
| 135 | 134 |
| 136 void ContentAutofillDriver::RendererShouldClearPreviewedForm() { | 135 void ContentAutofillDriver::RendererShouldClearPreviewedForm() { |
| 137 if (!RendererIsAvailable()) | 136 if (!RendererIsAvailable()) |
| 138 return; | 137 return; |
| 139 GetAutofillAgent()->ClearPreviewedForm(); | 138 GetAutofillAgent()->ClearPreviewedForm(); |
| 140 } | 139 } |
| 141 | 140 |
| 142 void ContentAutofillDriver::RendererShouldFillFieldWithValue( | 141 void ContentAutofillDriver::RendererShouldFillFieldWithValue( |
| 143 const base::string16& value) { | 142 const base::string16& value) { |
| 144 if (!RendererIsAvailable()) | 143 if (!RendererIsAvailable()) |
| 145 return; | 144 return; |
| 146 GetAutofillAgent()->FillFieldWithValue(mojo::String::From(value)); | 145 GetAutofillAgent()->FillFieldWithValue(base::UTF16ToUTF8(value)); |
| 147 } | 146 } |
| 148 | 147 |
| 149 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( | 148 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( |
| 150 const base::string16& value) { | 149 const base::string16& value) { |
| 151 if (!RendererIsAvailable()) | 150 if (!RendererIsAvailable()) |
| 152 return; | 151 return; |
| 153 GetAutofillAgent()->PreviewFieldWithValue(mojo::String::From(value)); | 152 GetAutofillAgent()->PreviewFieldWithValue(base::UTF16ToUTF8(value)); |
| 154 } | 153 } |
| 155 | 154 |
| 156 void ContentAutofillDriver::PopupHidden() { | 155 void ContentAutofillDriver::PopupHidden() { |
| 157 // 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 |
| 158 // will be cleared when the prompt closes. | 157 // will be cleared when the prompt closes. |
| 159 if (!autofill_manager_->IsShowingUnmaskPrompt()) | 158 if (!autofill_manager_->IsShowingUnmaskPrompt()) |
| 160 RendererShouldClearPreviewedForm(); | 159 RendererShouldClearPreviewedForm(); |
| 161 } | 160 } |
| 162 | 161 |
| 163 gfx::RectF ContentAutofillDriver::TransformBoundingBoxToViewportCoordinates( | 162 gfx::RectF ContentAutofillDriver::TransformBoundingBoxToViewportCoordinates( |
| 164 const gfx::RectF& bounding_box) { | 163 const gfx::RectF& bounding_box) { |
| 165 gfx::Point orig_point(bounding_box.x(), bounding_box.y()); | 164 gfx::Point orig_point(bounding_box.x(), bounding_box.y()); |
| 166 gfx::Point transformed_point; | 165 gfx::Point transformed_point; |
| 167 transformed_point = | 166 transformed_point = |
| 168 render_frame_host_->GetView()->TransformPointToRootCoordSpace(orig_point); | 167 render_frame_host_->GetView()->TransformPointToRootCoordSpace(orig_point); |
| 169 | 168 |
| 170 gfx::RectF new_box; | 169 gfx::RectF new_box; |
| 171 new_box.SetRect(transformed_point.x(), transformed_point.y(), | 170 new_box.SetRect(transformed_point.x(), transformed_point.y(), |
| 172 bounding_box.width(), bounding_box.height()); | 171 bounding_box.width(), bounding_box.height()); |
| 173 return new_box; | 172 return new_box; |
| 174 } | 173 } |
| 175 | 174 |
| 176 // mojom::AutofillDriver: | 175 // mojom::AutofillDriver: |
| 177 void ContentAutofillDriver::FirstUserGestureObserved() { | 176 void ContentAutofillDriver::FirstUserGestureObserved() { |
| 178 client_->OnFirstUserGestureObserved(); | 177 client_->OnFirstUserGestureObserved(); |
| 179 } | 178 } |
| 180 | 179 |
| 181 void ContentAutofillDriver::FormsSeen(mojo::Array<FormData> forms, | 180 void ContentAutofillDriver::FormsSeen(const std::vector<FormData>& forms, |
| 182 base::TimeTicks timestamp) { | 181 base::TimeTicks timestamp) { |
| 183 autofill_manager_->OnFormsSeen(forms.storage(), timestamp); | 182 autofill_manager_->OnFormsSeen(forms, timestamp); |
| 184 } | 183 } |
| 185 | 184 |
| 186 void ContentAutofillDriver::WillSubmitForm(const FormData& form, | 185 void ContentAutofillDriver::WillSubmitForm(const FormData& form, |
| 187 base::TimeTicks timestamp) { | 186 base::TimeTicks timestamp) { |
| 188 autofill_manager_->OnWillSubmitForm(form, timestamp); | 187 autofill_manager_->OnWillSubmitForm(form, timestamp); |
| 189 } | 188 } |
| 190 | 189 |
| 191 void ContentAutofillDriver::FormSubmitted(const FormData& form) { | 190 void ContentAutofillDriver::FormSubmitted(const FormData& form) { |
| 192 autofill_manager_->OnFormSubmitted(form); | 191 autofill_manager_->OnFormSubmitted(form); |
| 193 } | 192 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 224 } | 223 } |
| 225 | 224 |
| 226 void ContentAutofillDriver::DidPreviewAutofillFormData() { | 225 void ContentAutofillDriver::DidPreviewAutofillFormData() { |
| 227 autofill_manager_->OnDidPreviewAutofillFormData(); | 226 autofill_manager_->OnDidPreviewAutofillFormData(); |
| 228 } | 227 } |
| 229 | 228 |
| 230 void ContentAutofillDriver::DidEndTextFieldEditing() { | 229 void ContentAutofillDriver::DidEndTextFieldEditing() { |
| 231 autofill_manager_->OnDidEndTextFieldEditing(); | 230 autofill_manager_->OnDidEndTextFieldEditing(); |
| 232 } | 231 } |
| 233 | 232 |
| 234 void ContentAutofillDriver::SetDataList(mojo::Array<mojo::String> values, | 233 void ContentAutofillDriver::SetDataList( |
| 235 mojo::Array<mojo::String> labels) { | 234 const std::vector<std::string>& values, |
| 236 autofill_manager_->OnSetDataList(values.To<std::vector<base::string16>>(), | 235 const std::vector<std::string>& labels) { |
| 237 labels.To<std::vector<base::string16>>()); | 236 std::vector<base::string16> values16; |
|
yzshen1
2016/07/26 16:45:36
nit: please reserve the same size as |values| to a
leonhsl(Using Gerrit)
2016/07/27 02:50:26
Yeah, I have the same feeling.. Seems lots of inte
yzshen1
2016/07/27 06:21:20
SGTM Thanks!
leonhsl(Using Gerrit)
2016/07/27 09:25:32
Done. Use base::string16 typemap now, removed thes
| |
| 237 for (const auto& i : values) | |
| 238 values16.emplace_back(base::UTF8ToUTF16(i)); | |
| 239 std::vector<base::string16> labels16; | |
|
yzshen1
2016/07/26 16:45:36
ditto
leonhsl(Using Gerrit)
2016/07/27 02:50:26
Acknowledged.
leonhsl(Using Gerrit)
2016/07/27 09:25:32
Done. Use base::string16 typemap now, removed thes
| |
| 240 for (const auto& i : labels) | |
| 241 labels16.emplace_back(base::UTF8ToUTF16(i)); | |
| 242 autofill_manager_->OnSetDataList(values16, labels16); | |
| 238 } | 243 } |
| 239 | 244 |
| 240 void ContentAutofillDriver::DidNavigateFrame( | 245 void ContentAutofillDriver::DidNavigateFrame( |
| 241 const content::LoadCommittedDetails& details, | 246 const content::LoadCommittedDetails& details, |
| 242 const content::FrameNavigateParams& params) { | 247 const content::FrameNavigateParams& params) { |
| 243 if (details.is_navigation_to_different_page()) | 248 if (details.is_navigation_to_different_page()) |
| 244 autofill_manager_->Reset(); | 249 autofill_manager_->Reset(); |
| 245 } | 250 } |
| 246 | 251 |
| 247 void ContentAutofillDriver::SetAutofillManager( | 252 void ContentAutofillDriver::SetAutofillManager( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 258 // Here is a lazy binding, and will not reconnect after connection error. | 263 // Here is a lazy binding, and will not reconnect after connection error. |
| 259 if (!mojo_autofill_agent_) { | 264 if (!mojo_autofill_agent_) { |
| 260 render_frame_host_->GetRemoteInterfaces()->GetInterface( | 265 render_frame_host_->GetRemoteInterfaces()->GetInterface( |
| 261 mojo::GetProxy(&mojo_autofill_agent_)); | 266 mojo::GetProxy(&mojo_autofill_agent_)); |
| 262 } | 267 } |
| 263 | 268 |
| 264 return mojo_autofill_agent_; | 269 return mojo_autofill_agent_; |
| 265 } | 270 } |
| 266 | 271 |
| 267 } // namespace autofill | 272 } // namespace autofill |
| OLD | NEW |