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.
5 #if defined(TIZEN_AUTOFILL)
7 #include "browser/autofill/autofill_client_efl.h"
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"
35 AutofillClientEfl::AutofillClientEfl(content::WebContents* web_contents)
36 : content::WebContentsObserver(web_contents),
37 content::WebContentsUserData<AutofillClientEfl>(*web_contents),
38 web_contents_(web_contents) {
42 AutofillClientEfl::~AutofillClientEfl() {
43 if (popup_controller_)
44 delete popup_controller_;
45 popup_controller_ = NULL;
48 PersonalDataManager* AutofillClientEfl::GetPersonalDataManager() {
49 if (webview_ && webview_->context()) {
50 content::BrowserContextEfl* ctx =
51 webview_->context()->GetImpl()->browser_context();
53 PersonalDataManagerFactoryEfl* factory =
54 PersonalDataManagerFactoryEfl::GetInstance();
56 return factory->PersonalDataManagerForContext(ctx);
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);
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);
82 syncer::SyncService* AutofillClientEfl::GetSyncService() {
87 void AutofillClientEfl::ShowAutofillSettings(PopupType popup_type) {
91 void AutofillClientEfl::ConfirmSaveCreditCardLocally(
92 const CreditCard& card,
93 SaveCreditCardOptions options,
94 LocalSaveCardPromptCallback callback) {
98 void AutofillClientEfl::ConfirmSaveCreditCardToCloud(
99 const CreditCard& card,
100 const LegalMessageLines& legal_message_lines,
101 SaveCreditCardOptions options,
102 UploadSaveCardPromptCallback callback) {
106 void AutofillClientEfl::ConfirmCreditCardFillAssist(
107 const CreditCard& card,
108 base::OnceClosure callback) {
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";
123 // Do not show sugestions when Remember form data is disabled
124 if (!IsAutocompleteSavingEnabled())
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));
133 popup_controller_->UpdateFormDataPopup(open_args.element_bounds);
135 popup_controller_->Show();
139 void AutofillClientEfl::ShowUnmaskPrompt(
140 const CreditCard& card,
141 const CardUnmaskPromptOptions& card_unmask_prompt_options,
142 base::WeakPtr<CardUnmaskDelegate> delegate) {
146 void AutofillClientEfl::UpdateAutofillPopupDataListValues(
147 const std::vector<std::u16string>& values,
148 const std::vector<std::u16string>& labels) {
152 void AutofillClientEfl::OnUnmaskVerificationResult(PaymentsRpcResult result) {
156 bool AutofillClientEfl::HasCreditCardScanFeature() {
160 void AutofillClientEfl::ScanCreditCard(CreditCardScanCallback callback) {
164 bool AutofillClientEfl::IsContextSecure() const {
165 content::SSLStatus ssl_status;
166 content::NavigationEntry* navigation_entry =
167 web_contents_->GetController().GetLastCommittedEntry();
168 if (!navigation_entry)
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);
181 signin::IdentityManager* AutofillClientEfl::GetIdentityManager() {
186 ukm::UkmRecorder* AutofillClientEfl::GetUkmRecorder() {
191 ukm::SourceId AutofillClientEfl::GetUkmSourceId() {
193 return ukm::kInvalidSourceId;
196 AddressNormalizer* AutofillClientEfl::GetAddressNormalizer() {
201 security_state::SecurityLevel
202 AutofillClientEfl::GetSecurityLevelForUmaHistograms() {
204 return security_state::SecurityLevel::SECURITY_LEVEL_COUNT;
207 void AutofillClientEfl::ExecuteCommand(int id) {
211 void AutofillClientEfl::HideAutofillPopup(PopupHidingReason reason) {
212 #if defined(TIZEN_AUTOFILL_FW)
213 LOG(INFO) << "[Autofill] " << __FUNCTION__
214 << " Autofill fw is enabled. return directly";
217 if (popup_controller_) {
218 popup_controller_->Hide();
222 bool AutofillClientEfl::IsAutocompleteEnabled() const {
224 return webview_->GetSettings()->autofillProfileForm();
228 void AutofillClientEfl::PropagateAutofillPredictions(
229 autofill::AutofillDriver* autofill_driver,
230 const std::vector<FormStructure*>& forms) {
234 bool AutofillClientEfl::IsAutocompleteSavingEnabled() {
236 return webview_->GetSettings()->formCandidateData();
240 FormDataImporter* AutofillClientEfl::GetFormDataImporter() {
245 StrikeDatabase* AutofillClientEfl::GetStrikeDatabase() {
250 void AutofillClientEfl::ShowLocalCardMigrationDialog(
251 base::OnceClosure show_migration_dialog_closure) {
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) {
263 AutocompleteHistoryManager* AutofillClientEfl::GetAutocompleteHistoryManager() {
264 if (!webview_ || !webview_->context())
267 content::BrowserContextEfl* ctx =
268 webview_->context()->GetImpl()->browser_context();
269 auto* factory = AutocompleteHistoryManagerFactoryEfl::GetInstance();
270 return factory->AutocompleteHistoryManagerForContext(ctx);
273 payments::PaymentsClient* AutofillClientEfl::GetPaymentsClient() {
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";
285 if (GetOrCreatePopupController())
286 popup_controller_->ShowSavePasswordPopup(std::move(form_to_save));
289 void AutofillClientEfl::PrimaryMainFrameWasResized(bool width_changed) {
290 // Ignore virtual keyboard showing and hiding a strip of suggestions.
294 HideAutofillPopup(PopupHidingReason::kNavigation);
297 void AutofillClientEfl::WebContentsDestroyed() {
298 HideAutofillPopup(PopupHidingReason::kViewDestroyed);
301 AutofillPopupViewEfl * AutofillClientEfl::GetOrCreatePopupController() {
302 if (webview_ && !popup_controller_)
303 popup_controller_ = new AutofillPopupViewEfl(webview_);
304 return popup_controller_;
307 void AutofillClientEfl::DidFillOrPreviewField(
308 const std::u16string& autofilled_value,
309 const std::u16string& profile_full_name) {
313 bool AutofillClientEfl::IsOffTheRecord() {
318 scoped_refptr<network::SharedURLLoaderFactory>
319 AutofillClientEfl::GetURLLoaderFactory() {
321 return scoped_refptr<network::SharedURLLoaderFactory>();
324 void AutofillClientEfl::ConfirmSaveIBANLocally(
326 bool should_show_prompt,
327 LocalSaveIBANPromptCallback callback) {
331 void AutofillClientEfl::DidFillOrPreviewForm(
332 mojom::RendererFormDataAction action,
333 AutofillTriggerSource trigger_source,
338 FormInteractionsFlowId AutofillClientEfl::GetCurrentFormInteractionsFlowId() {
342 void AutofillClientEfl::UpdateAutofillIfRequired() {
343 if (popup_controller_ && popup_controller_->IsVisible()) {
344 auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
345 web_contents_->GetRenderWidgetHostView());
347 rwhva->host()->UpdateFocusedNodeBounds();
351 #if defined(TIZEN_AUTOFILL_FW)
352 void AutofillClientEfl::ResetLastInteractedElements() {
353 auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
354 web_contents_->GetRenderWidgetHostView());
356 rwhva->host()->ResetLastInteractedElements();
360 void AutofillClientEfl::DidChangeFocusedNodeBounds(
361 const gfx::RectF& node_bounds) {
362 if (popup_controller_)
363 popup_controller_->UpdateLocation(GetElementBoundsInScreen(node_bounds));
366 gfx::RectF AutofillClientEfl::GetElementBoundsInScreen(
367 const gfx::RectF& element_bounds) {
368 auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
369 web_contents_->GetRenderWidgetHostView());
373 double scale_factor = 1.0;
375 scale_factor = webview_->GetScale();
378 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
381 if (!rwhva->offscreen_helper())
382 return element_bounds;
384 gfx::Vector2d view_offset =
385 gfx::ToEnclosingRect(
386 gfx::ConvertRectToDips(
387 rwhva->offscreen_helper()->GetViewBoundsInPix(), scale_factor))
389 return element_bounds + view_offset;
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) {
400 void AutofillClientEfl::ShowWebauthnOfferDialog(
401 WebauthnDialogCallback offer_dialog_callback) {
405 void AutofillClientEfl::ShowWebauthnVerifyPendingDialog(
406 WebauthnDialogCallback verify_pending_dialog_callback) {
410 void AutofillClientEfl::UpdateWebauthnOfferDialogWithError() {
414 bool AutofillClientEfl::CloseWebauthnDialog() {
419 void AutofillClientEfl::ConfirmSaveUpiIdLocally(
420 const std::string& upi_id,
421 base::OnceCallback<void(bool user_decision)> callback) {
425 void AutofillClientEfl::OfferVirtualCardOptions(
426 const std::vector<CreditCard*>& candidates,
427 base::OnceCallback<void(const std::string&)> callback) {
431 void AutofillClientEfl::CreditCardUploadCompleted(bool card_saved) {
435 void AutofillClientEfl::PinPopupView() {
439 AutofillClient::PopupOpenArgs AutofillClientEfl::GetReopenPopupArgs() const {
444 std::vector<Suggestion> AutofillClientEfl::GetPopupSuggestions() const {
446 return std::vector<Suggestion>();
449 void AutofillClientEfl::UpdatePopup(const std::vector<Suggestion>& suggestions,
450 PopupType popup_type) {
454 const GURL& AutofillClientEfl::GetLastCommittedPrimaryMainFrameURL() const {
455 DCHECK(web_contents_);
456 content::NavigationEntry* entry =
457 web_contents_->GetController().GetLastCommittedEntry();
459 return GURL::EmptyGURL();
461 return entry->GetURL();
464 std::vector<std::string>
465 AutofillClientEfl::GetAllowedMerchantsForVirtualCards() {
467 return std::vector<std::string>();
470 std::vector<std::string>
471 AutofillClientEfl::GetAllowedBinRangesForVirtualCards() {
473 return std::vector<std::string>();
476 const translate::LanguageState* AutofillClientEfl::GetLanguageState() {
480 translate::TranslateDriver* AutofillClientEfl::GetTranslateDriver() {
484 void AutofillClientEfl::ConfirmSaveAddressProfile(
485 const AutofillProfile& profile,
486 const AutofillProfile* original_profile,
487 AutofillClient::SaveAddressProfilePromptOptions options,
488 AddressProfileSavePromptCallback callback) {
492 void AutofillClientEfl::LoadRiskData(
493 base::OnceCallback<void(const std::string&)> callback) {
497 url::Origin AutofillClientEfl::GetLastCommittedPrimaryMainFrameOrigin() const {
499 return url::Origin();
502 void AutofillClientEfl::OpenPromoCodeOfferDetailsURL(const GURL& url) {
506 void AutofillClientEfl::HideTouchToFillCreditCard() {
510 WEB_CONTENTS_USER_DATA_KEY_IMPL(AutofillClientEfl);
511 } // namespace autofill
513 #endif // TIZEN_AUTOFILL