[Autofill] Make AutofillClientEfl implement ContentAutofillClient
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / browser / autofill / autofill_client_efl.cc
1 // Copyright 2014 Samsung Electronics. 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 #if defined(TIZEN_AUTOFILL)
6
7 #include "browser/autofill/autofill_client_efl.h"
8
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "browser/autofill/autocomplete_history_manager_factory.h"
12 #include "browser/autofill/personal_data_manager_factory.h"
13 #include "browser/password_manager/password_manager_client_efl.h"
14 #include "browser_context_efl.h"
15 #include "common/render_messages_ewk.h"
16 #include "components/autofill/content/browser/content_autofill_driver.h"
17 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
18 #include "components/autofill/core/browser/autofill_client.h"
19 #include "components/autofill/core/common/autofill_prefs.h"
20 #include "components/prefs/pref_service.h"
21 #include "components/user_prefs/user_prefs.h"
22 #include "content/browser/renderer_host/render_widget_host_impl.h"
23 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/ssl_status.h"
27 #include "private/ewk_context_private.h"
28 #include "tizen/system_info.h"
29 #include "ui/display/screen.h"
30 #include "ui/gfx/geometry/dip_util.h"
31 #include "ui/gfx/geometry/rect.h"
32
33 namespace autofill {
34
35 // static
36 AutofillClientEfl* AutofillClientEfl::FromWebContents(
37     content::WebContents* web_contents) {
38   return static_cast<AutofillClientEfl*>(
39       ContentAutofillClient::FromWebContents(web_contents));
40 }
41
42 // static
43 void AutofillClientEfl::CreateForWebContents(content::WebContents* contents) {
44   DCHECK(contents);
45   if (!FromWebContents(contents)) {
46     contents->SetUserData(UserDataKey(),
47                           base::WrapUnique(new AutofillClientEfl(contents)));
48   }
49 }
50
51 AutofillClientEfl::AutofillClientEfl(content::WebContents* web_contents)
52     : ContentAutofillClient(web_contents,
53                             base::BindRepeating(&BrowserDriverInitHook,
54                                                 this,
55                                                 EWebView::GetPlatformLocale())),
56       content::WebContentsObserver(web_contents),
57       web_contents_(web_contents) {
58   DCHECK(web_contents);
59 }
60
61 AutofillClientEfl::~AutofillClientEfl() {
62   if (popup_controller_)
63     delete popup_controller_;
64   popup_controller_ = NULL;
65 }
66
67 PersonalDataManager* AutofillClientEfl::GetPersonalDataManager() {
68   if (webview_ && webview_->context()) {
69     content::BrowserContextEfl* ctx =
70         webview_->context()->GetImpl()->browser_context();
71
72     PersonalDataManagerFactoryEfl* factory =
73         PersonalDataManagerFactoryEfl::GetInstance();
74
75     return factory->PersonalDataManagerForContext(ctx);
76   }
77
78   return NULL;
79 }
80
81 PrefService* AutofillClientEfl::GetPrefs() {
82   if (webview_ && webview_->context()) {
83     content::BrowserContextEfl* ctx =
84         webview_->context()->GetImpl()->browser_context();
85     return user_prefs::UserPrefs::Get(ctx);
86   }
87
88   return NULL;
89 }
90
91 const PrefService* AutofillClientEfl::GetPrefs() const {
92   if (webview_ && webview_->context()) {
93     content::BrowserContextEfl* ctx =
94         webview_->context()->GetImpl()->browser_context();
95     return user_prefs::UserPrefs::Get(ctx);
96   }
97
98   return NULL;
99 }
100
101 syncer::SyncService* AutofillClientEfl::GetSyncService() {
102   NOTIMPLEMENTED();
103   return nullptr;
104 }
105
106 void AutofillClientEfl::ShowAutofillSettings(PopupType popup_type) {
107   NOTIMPLEMENTED();
108 }
109
110 void AutofillClientEfl::ConfirmSaveCreditCardLocally(
111     const CreditCard& card,
112     SaveCreditCardOptions options,
113     LocalSaveCardPromptCallback callback) {
114   NOTIMPLEMENTED();
115 }
116
117 void AutofillClientEfl::ConfirmSaveCreditCardToCloud(
118     const CreditCard& card,
119     const LegalMessageLines& legal_message_lines,
120     SaveCreditCardOptions options,
121     UploadSaveCardPromptCallback callback) {
122   NOTIMPLEMENTED();
123 }
124
125 void AutofillClientEfl::ConfirmCreditCardFillAssist(
126     const CreditCard& card,
127     base::OnceClosure callback) {
128   NOTIMPLEMENTED();
129 }
130
131 void AutofillClientEfl::ShowAutofillPopup(
132     const PopupOpenArgs& open_args,
133     base::WeakPtr<autofill::AutofillPopupDelegate> delegate) {
134   DCHECK(web_contents_);
135   LOG(INFO) << "[Autofill] " << __FUNCTION__
136             << " suggestions.size : " << open_args.suggestions.size();
137 #if defined(TIZEN_AUTOFILL_FW)
138   LOG(INFO) << "[Autofill] " << __FUNCTION__
139             << " Autofill fw is enabled. return directly";
140   return;
141 #endif
142   // Do not show sugestions when Remember form data is disabled
143   if (!IsAutocompleteSavingEnabled())
144     return;
145
146   if (GetOrCreatePopupController()) {
147     popup_controller_->InitFormData(open_args.suggestions, delegate);
148 #if BUILDFLAG(IS_TIZEN)
149     popup_controller_->UpdateFormDataPopup(
150         GetElementBoundsInScreen(open_args.element_bounds));
151 #else
152     popup_controller_->UpdateFormDataPopup(open_args.element_bounds);
153 #endif
154     popup_controller_->Show();
155   }
156 }
157
158 void AutofillClientEfl::ShowUnmaskPrompt(
159     const CreditCard& card,
160     const CardUnmaskPromptOptions& card_unmask_prompt_options,
161     base::WeakPtr<CardUnmaskDelegate> delegate) {
162   NOTIMPLEMENTED();
163 }
164
165 void AutofillClientEfl::UpdateAutofillPopupDataListValues(
166     const std::vector<std::u16string>& values,
167     const std::vector<std::u16string>& labels) {
168   NOTIMPLEMENTED();
169 }
170
171 void AutofillClientEfl::OnUnmaskVerificationResult(PaymentsRpcResult result) {
172   NOTIMPLEMENTED();
173 }
174
175 bool AutofillClientEfl::HasCreditCardScanFeature() {
176   return false;
177 }
178
179 void AutofillClientEfl::ScanCreditCard(CreditCardScanCallback callback) {
180   NOTIMPLEMENTED();
181 }
182
183 bool AutofillClientEfl::IsContextSecure() const {
184   content::SSLStatus ssl_status;
185   content::NavigationEntry* navigation_entry =
186       web_contents_->GetController().GetLastCommittedEntry();
187   if (!navigation_entry)
188      return false;
189
190   ssl_status = navigation_entry->GetSSL();
191   // Note: If changing the implementation below, also change
192   // AwAutofillClient::IsContextSecure. See crbug.com/505388
193   return navigation_entry->GetURL().SchemeIsCryptographic() &&
194          ssl_status.certificate &&
195          (!net::IsCertStatusError(ssl_status.cert_status)) &&
196          !(ssl_status.content_status &
197            content::SSLStatus::RAN_INSECURE_CONTENT);
198 }
199
200 signin::IdentityManager* AutofillClientEfl::GetIdentityManager() {
201   NOTIMPLEMENTED();
202   return nullptr;
203 }
204
205 ukm::UkmRecorder* AutofillClientEfl::GetUkmRecorder() {
206   NOTIMPLEMENTED();
207   return nullptr;
208 }
209
210 ukm::SourceId AutofillClientEfl::GetUkmSourceId() {
211   NOTIMPLEMENTED();
212   return ukm::kInvalidSourceId;
213 }
214
215 AddressNormalizer* AutofillClientEfl::GetAddressNormalizer() {
216   NOTIMPLEMENTED();
217   return nullptr;
218 }
219
220 security_state::SecurityLevel
221 AutofillClientEfl::GetSecurityLevelForUmaHistograms() {
222   NOTIMPLEMENTED();
223   return security_state::SecurityLevel::SECURITY_LEVEL_COUNT;
224 }
225
226 void AutofillClientEfl::ExecuteCommand(int id) {
227   NOTIMPLEMENTED();
228 }
229
230 void AutofillClientEfl::HideAutofillPopup(PopupHidingReason reason) {
231 #if defined(TIZEN_AUTOFILL_FW)
232   LOG(INFO) << "[Autofill] " << __FUNCTION__
233             << " Autofill fw is enabled. return directly";
234   return;
235 #endif
236   if (popup_controller_) {
237     popup_controller_->Hide();
238   }
239 }
240
241 bool AutofillClientEfl::IsAutocompleteEnabled() const {
242   if (webview_)
243     return webview_->GetSettings()->autofillProfileForm();
244   return false;
245 }
246
247 void AutofillClientEfl::PropagateAutofillPredictions(
248     autofill::AutofillDriver* autofill_driver,
249     const std::vector<FormStructure*>& forms) {
250   NOTIMPLEMENTED();
251 }
252
253 bool AutofillClientEfl::IsAutocompleteSavingEnabled() {
254   if (webview_)
255     return webview_->GetSettings()->formCandidateData();
256   return false;
257 }
258
259 FormDataImporter* AutofillClientEfl::GetFormDataImporter() {
260   NOTIMPLEMENTED();
261   return nullptr;
262 }
263
264 StrikeDatabase* AutofillClientEfl::GetStrikeDatabase() {
265   NOTIMPLEMENTED();
266   return nullptr;
267 }
268
269 void AutofillClientEfl::ShowLocalCardMigrationDialog(
270     base::OnceClosure show_migration_dialog_closure) {
271   NOTIMPLEMENTED();
272 }
273
274 void AutofillClientEfl::ShowLocalCardMigrationResults(
275     const bool has_server_error,
276     const std::u16string& tip_message,
277     const std::vector<MigratableCreditCard>& migratable_credit_cards,
278     MigrationDeleteCardCallback delete_local_card_callback) {
279   NOTIMPLEMENTED();
280 }
281
282 AutocompleteHistoryManager* AutofillClientEfl::GetAutocompleteHistoryManager() {
283   if (!webview_ || !webview_->context())
284     return nullptr;
285
286   content::BrowserContextEfl* ctx =
287       webview_->context()->GetImpl()->browser_context();
288   auto* factory = AutocompleteHistoryManagerFactoryEfl::GetInstance();
289   return factory->AutocompleteHistoryManagerForContext(ctx);
290 }
291
292 payments::PaymentsClient* AutofillClientEfl::GetPaymentsClient() {
293   NOTIMPLEMENTED();
294   return nullptr;
295 }
296
297 void AutofillClientEfl::ShowSavePasswordPopup(
298     std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save) {
299 #if defined(TIZEN_AUTOFILL_FW)
300   LOG(INFO) << "[Autofill] " << __FUNCTION__
301             << " Autofill fw is enabled. return directly";
302   return;
303 #endif
304   if (GetOrCreatePopupController())
305     popup_controller_->ShowSavePasswordPopup(std::move(form_to_save));
306 }
307
308 void AutofillClientEfl::PrimaryMainFrameWasResized(bool width_changed) {
309   // Ignore virtual keyboard showing and hiding a strip of suggestions.
310   if (!width_changed)
311     return;
312
313   HideAutofillPopup(PopupHidingReason::kNavigation);
314 }
315
316 void AutofillClientEfl::WebContentsDestroyed() {
317   HideAutofillPopup(PopupHidingReason::kViewDestroyed);
318 }
319
320 AutofillPopupViewEfl * AutofillClientEfl::GetOrCreatePopupController() {
321   if (webview_ && !popup_controller_)
322     popup_controller_ = new AutofillPopupViewEfl(webview_);
323   return popup_controller_;
324 }
325
326 void AutofillClientEfl::DidFillOrPreviewField(
327     const std::u16string& autofilled_value,
328     const std::u16string& profile_full_name) {
329   NOTIMPLEMENTED();
330 }
331
332 bool AutofillClientEfl::IsOffTheRecord() {
333   return web_contents_->GetBrowserContext()->IsOffTheRecord();
334 }
335
336 scoped_refptr<network::SharedURLLoaderFactory>
337 AutofillClientEfl::GetURLLoaderFactory() {
338   return web_contents_->GetBrowserContext()
339       ->GetDefaultStoragePartition()
340       ->GetURLLoaderFactoryForBrowserProcess();
341 }
342
343 void AutofillClientEfl::ConfirmSaveIBANLocally(
344     const IBAN& iban,
345     bool should_show_prompt,
346     LocalSaveIBANPromptCallback callback) {
347   NOTIMPLEMENTED();
348 }
349
350 void AutofillClientEfl::DidFillOrPreviewForm(
351     mojom::RendererFormDataAction action,
352     AutofillTriggerSource trigger_source,
353     bool is_refill) {
354   NOTIMPLEMENTED();
355 }
356
357 FormInteractionsFlowId AutofillClientEfl::GetCurrentFormInteractionsFlowId() {
358   NOTIMPLEMENTED();
359   return {};
360 }
361
362 void AutofillClientEfl::UpdateAutofillIfRequired() {
363   if (popup_controller_ && popup_controller_->IsVisible()) {
364     auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
365         web_contents_->GetRenderWidgetHostView());
366     if (rwhva)
367       rwhva->host()->UpdateFocusedNodeBounds();
368   }
369 }
370
371 #if defined(TIZEN_AUTOFILL_FW)
372 void AutofillClientEfl::ResetLastInteractedElements() {
373   auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
374       web_contents_->GetRenderWidgetHostView());
375   if (rwhva)
376     rwhva->host()->ResetLastInteractedElements();
377 }
378 #endif
379
380 void AutofillClientEfl::DidChangeFocusedNodeBounds(
381     const gfx::RectF& node_bounds) {
382   if (popup_controller_)
383     popup_controller_->UpdateLocation(GetElementBoundsInScreen(node_bounds));
384 }
385
386 gfx::RectF AutofillClientEfl::GetElementBoundsInScreen(
387     const gfx::RectF& element_bounds) {
388   auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
389       web_contents_->GetRenderWidgetHostView());
390   if (!rwhva)
391     return gfx::RectF();
392
393   double scale_factor = 1.0;
394   if (IsTvProfile()) {
395     scale_factor = webview_->GetScale();
396   } else {
397     scale_factor =
398         display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
399   }
400
401   if (!rwhva->offscreen_helper())
402     return element_bounds;
403
404   gfx::Vector2d view_offset =
405       gfx::ToEnclosingRect(
406           gfx::ConvertRectToDips(
407               rwhva->offscreen_helper()->GetViewBoundsInPix(), scale_factor))
408           .OffsetFromOrigin();
409   return element_bounds + view_offset;
410 }
411
412 void AutofillClientEfl::ConfirmMigrateLocalCardToCloud(
413     const LegalMessageLines& legal_message_lines,
414     const std::string& user_email,
415     const std::vector<MigratableCreditCard>& migratable_credit_cards,
416     LocalCardMigrationCallback start_migrating_cards_callback) {
417   NOTIMPLEMENTED();
418 }
419
420 void AutofillClientEfl::ShowWebauthnOfferDialog(
421     WebauthnDialogCallback offer_dialog_callback) {
422   NOTIMPLEMENTED();
423 }
424
425 void AutofillClientEfl::ShowWebauthnVerifyPendingDialog(
426     WebauthnDialogCallback verify_pending_dialog_callback) {
427   NOTIMPLEMENTED();
428 }
429
430 void AutofillClientEfl::UpdateWebauthnOfferDialogWithError() {
431   NOTIMPLEMENTED();
432 }
433
434 bool AutofillClientEfl::CloseWebauthnDialog() {
435   NOTIMPLEMENTED();
436   return false;
437 }
438
439 void AutofillClientEfl::ConfirmSaveUpiIdLocally(
440     const std::string& upi_id,
441     base::OnceCallback<void(bool user_decision)> callback) {
442   NOTIMPLEMENTED();
443 }
444
445 void AutofillClientEfl::OfferVirtualCardOptions(
446     const std::vector<CreditCard*>& candidates,
447     base::OnceCallback<void(const std::string&)> callback) {
448   NOTIMPLEMENTED();
449 }
450
451 void AutofillClientEfl::CreditCardUploadCompleted(bool card_saved) {
452   NOTIMPLEMENTED();
453 }
454
455 void AutofillClientEfl::PinPopupView() {
456   NOTIMPLEMENTED();
457 }
458
459 AutofillClient::PopupOpenArgs AutofillClientEfl::GetReopenPopupArgs() const {
460   NOTIMPLEMENTED();
461   return {};
462 }
463
464 std::vector<Suggestion> AutofillClientEfl::GetPopupSuggestions() const {
465   NOTIMPLEMENTED();
466   return std::vector<Suggestion>();
467 }
468
469 void AutofillClientEfl::UpdatePopup(const std::vector<Suggestion>& suggestions,
470                                     PopupType popup_type) {
471   NOTIMPLEMENTED();
472 }
473
474 const GURL& AutofillClientEfl::GetLastCommittedPrimaryMainFrameURL() const {
475   DCHECK(web_contents_);
476   content::NavigationEntry* entry =
477       web_contents_->GetController().GetLastCommittedEntry();
478   if (!entry)
479     return GURL::EmptyGURL();
480
481   return entry->GetURL();
482 }
483
484 std::vector<std::string>
485 AutofillClientEfl::GetAllowedMerchantsForVirtualCards() {
486   NOTIMPLEMENTED();
487   return std::vector<std::string>();
488 }
489
490 std::vector<std::string>
491 AutofillClientEfl::GetAllowedBinRangesForVirtualCards() {
492   NOTIMPLEMENTED();
493   return std::vector<std::string>();
494 }
495
496 const translate::LanguageState* AutofillClientEfl::GetLanguageState() {
497   NOTIMPLEMENTED();
498   return nullptr;
499 }
500 translate::TranslateDriver* AutofillClientEfl::GetTranslateDriver() {
501   NOTIMPLEMENTED();
502   return nullptr;
503 }
504 void AutofillClientEfl::ConfirmSaveAddressProfile(
505     const AutofillProfile& profile,
506     const AutofillProfile* original_profile,
507     AutofillClient::SaveAddressProfilePromptOptions options,
508     AddressProfileSavePromptCallback callback) {
509   NOTIMPLEMENTED();
510 }
511
512 void AutofillClientEfl::LoadRiskData(
513     base::OnceCallback<void(const std::string&)> callback) {
514   NOTIMPLEMENTED();
515 }
516
517 url::Origin AutofillClientEfl::GetLastCommittedPrimaryMainFrameOrigin() const {
518   NOTREACHED();
519   return url::Origin();
520 }
521
522 void AutofillClientEfl::OpenPromoCodeOfferDetailsURL(const GURL& url) {
523   NOTIMPLEMENTED();
524 }
525
526 void AutofillClientEfl::HideTouchToFillCreditCard() {
527   NOTIMPLEMENTED();
528 }
529
530 }  // namespace autofill
531
532 #endif  // TIZEN_AUTOFILL