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