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"
36 AutofillClientEfl* AutofillClientEfl::FromWebContents(
37 content::WebContents* web_contents) {
38 return static_cast<AutofillClientEfl*>(
39 ContentAutofillClient::FromWebContents(web_contents));
43 void AutofillClientEfl::CreateForWebContents(content::WebContents* contents) {
45 if (!FromWebContents(contents)) {
46 contents->SetUserData(UserDataKey(),
47 base::WrapUnique(new AutofillClientEfl(contents)));
51 AutofillClientEfl::AutofillClientEfl(content::WebContents* web_contents)
52 : ContentAutofillClient(web_contents,
53 base::BindRepeating(&BrowserDriverInitHook,
55 EWebView::GetPlatformLocale())),
56 content::WebContentsObserver(web_contents),
57 web_contents_(web_contents) {
61 AutofillClientEfl::~AutofillClientEfl() {
62 if (popup_controller_)
63 delete popup_controller_;
64 popup_controller_ = NULL;
67 PersonalDataManager* AutofillClientEfl::GetPersonalDataManager() {
68 if (webview_ && webview_->context()) {
69 content::BrowserContextEfl* ctx =
70 webview_->context()->GetImpl()->browser_context();
72 PersonalDataManagerFactoryEfl* factory =
73 PersonalDataManagerFactoryEfl::GetInstance();
75 return factory->PersonalDataManagerForContext(ctx);
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);
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);
101 syncer::SyncService* AutofillClientEfl::GetSyncService() {
106 void AutofillClientEfl::ShowAutofillSettings(PopupType popup_type) {
110 void AutofillClientEfl::ConfirmSaveCreditCardLocally(
111 const CreditCard& card,
112 SaveCreditCardOptions options,
113 LocalSaveCardPromptCallback callback) {
117 void AutofillClientEfl::ConfirmSaveCreditCardToCloud(
118 const CreditCard& card,
119 const LegalMessageLines& legal_message_lines,
120 SaveCreditCardOptions options,
121 UploadSaveCardPromptCallback callback) {
125 void AutofillClientEfl::ConfirmCreditCardFillAssist(
126 const CreditCard& card,
127 base::OnceClosure callback) {
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";
142 // Do not show sugestions when Remember form data is disabled
143 if (!IsAutocompleteSavingEnabled())
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));
152 popup_controller_->UpdateFormDataPopup(open_args.element_bounds);
154 popup_controller_->Show();
158 void AutofillClientEfl::ShowUnmaskPrompt(
159 const CreditCard& card,
160 const CardUnmaskPromptOptions& card_unmask_prompt_options,
161 base::WeakPtr<CardUnmaskDelegate> delegate) {
165 void AutofillClientEfl::UpdateAutofillPopupDataListValues(
166 const std::vector<std::u16string>& values,
167 const std::vector<std::u16string>& labels) {
171 void AutofillClientEfl::OnUnmaskVerificationResult(PaymentsRpcResult result) {
175 bool AutofillClientEfl::HasCreditCardScanFeature() {
179 void AutofillClientEfl::ScanCreditCard(CreditCardScanCallback callback) {
183 bool AutofillClientEfl::IsContextSecure() const {
184 content::SSLStatus ssl_status;
185 content::NavigationEntry* navigation_entry =
186 web_contents_->GetController().GetLastCommittedEntry();
187 if (!navigation_entry)
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);
200 signin::IdentityManager* AutofillClientEfl::GetIdentityManager() {
205 ukm::UkmRecorder* AutofillClientEfl::GetUkmRecorder() {
210 ukm::SourceId AutofillClientEfl::GetUkmSourceId() {
212 return ukm::kInvalidSourceId;
215 AddressNormalizer* AutofillClientEfl::GetAddressNormalizer() {
220 security_state::SecurityLevel
221 AutofillClientEfl::GetSecurityLevelForUmaHistograms() {
223 return security_state::SecurityLevel::SECURITY_LEVEL_COUNT;
226 void AutofillClientEfl::ExecuteCommand(int id) {
230 void AutofillClientEfl::HideAutofillPopup(PopupHidingReason reason) {
231 #if defined(TIZEN_AUTOFILL_FW)
232 LOG(INFO) << "[Autofill] " << __FUNCTION__
233 << " Autofill fw is enabled. return directly";
236 if (popup_controller_) {
237 popup_controller_->Hide();
241 bool AutofillClientEfl::IsAutocompleteEnabled() const {
243 return webview_->GetSettings()->autofillProfileForm();
247 void AutofillClientEfl::PropagateAutofillPredictions(
248 autofill::AutofillDriver* autofill_driver,
249 const std::vector<FormStructure*>& forms) {
253 bool AutofillClientEfl::IsAutocompleteSavingEnabled() {
255 return webview_->GetSettings()->formCandidateData();
259 FormDataImporter* AutofillClientEfl::GetFormDataImporter() {
264 StrikeDatabase* AutofillClientEfl::GetStrikeDatabase() {
269 void AutofillClientEfl::ShowLocalCardMigrationDialog(
270 base::OnceClosure show_migration_dialog_closure) {
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) {
282 AutocompleteHistoryManager* AutofillClientEfl::GetAutocompleteHistoryManager() {
283 if (!webview_ || !webview_->context())
286 content::BrowserContextEfl* ctx =
287 webview_->context()->GetImpl()->browser_context();
288 auto* factory = AutocompleteHistoryManagerFactoryEfl::GetInstance();
289 return factory->AutocompleteHistoryManagerForContext(ctx);
292 payments::PaymentsClient* AutofillClientEfl::GetPaymentsClient() {
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";
304 if (GetOrCreatePopupController())
305 popup_controller_->ShowSavePasswordPopup(std::move(form_to_save));
308 void AutofillClientEfl::PrimaryMainFrameWasResized(bool width_changed) {
309 // Ignore virtual keyboard showing and hiding a strip of suggestions.
313 HideAutofillPopup(PopupHidingReason::kNavigation);
316 void AutofillClientEfl::WebContentsDestroyed() {
317 HideAutofillPopup(PopupHidingReason::kViewDestroyed);
320 AutofillPopupViewEfl * AutofillClientEfl::GetOrCreatePopupController() {
321 if (webview_ && !popup_controller_)
322 popup_controller_ = new AutofillPopupViewEfl(webview_);
323 return popup_controller_;
326 void AutofillClientEfl::DidFillOrPreviewField(
327 const std::u16string& autofilled_value,
328 const std::u16string& profile_full_name) {
332 bool AutofillClientEfl::IsOffTheRecord() {
333 return web_contents_->GetBrowserContext()->IsOffTheRecord();
336 scoped_refptr<network::SharedURLLoaderFactory>
337 AutofillClientEfl::GetURLLoaderFactory() {
338 return web_contents_->GetBrowserContext()
339 ->GetDefaultStoragePartition()
340 ->GetURLLoaderFactoryForBrowserProcess();
343 void AutofillClientEfl::ConfirmSaveIBANLocally(
345 bool should_show_prompt,
346 LocalSaveIBANPromptCallback callback) {
350 void AutofillClientEfl::DidFillOrPreviewForm(
351 mojom::RendererFormDataAction action,
352 AutofillTriggerSource trigger_source,
357 FormInteractionsFlowId AutofillClientEfl::GetCurrentFormInteractionsFlowId() {
362 void AutofillClientEfl::UpdateAutofillIfRequired() {
363 if (popup_controller_ && popup_controller_->IsVisible()) {
364 auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
365 web_contents_->GetRenderWidgetHostView());
367 rwhva->host()->UpdateFocusedNodeBounds();
371 #if defined(TIZEN_AUTOFILL_FW)
372 void AutofillClientEfl::ResetLastInteractedElements() {
373 auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
374 web_contents_->GetRenderWidgetHostView());
376 rwhva->host()->ResetLastInteractedElements();
380 void AutofillClientEfl::DidChangeFocusedNodeBounds(
381 const gfx::RectF& node_bounds) {
382 if (popup_controller_)
383 popup_controller_->UpdateLocation(GetElementBoundsInScreen(node_bounds));
386 gfx::RectF AutofillClientEfl::GetElementBoundsInScreen(
387 const gfx::RectF& element_bounds) {
388 auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
389 web_contents_->GetRenderWidgetHostView());
393 double scale_factor = 1.0;
395 scale_factor = webview_->GetScale();
398 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
401 if (!rwhva->offscreen_helper())
402 return element_bounds;
404 gfx::Vector2d view_offset =
405 gfx::ToEnclosingRect(
406 gfx::ConvertRectToDips(
407 rwhva->offscreen_helper()->GetViewBoundsInPix(), scale_factor))
409 return element_bounds + view_offset;
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) {
420 void AutofillClientEfl::ShowWebauthnOfferDialog(
421 WebauthnDialogCallback offer_dialog_callback) {
425 void AutofillClientEfl::ShowWebauthnVerifyPendingDialog(
426 WebauthnDialogCallback verify_pending_dialog_callback) {
430 void AutofillClientEfl::UpdateWebauthnOfferDialogWithError() {
434 bool AutofillClientEfl::CloseWebauthnDialog() {
439 void AutofillClientEfl::ConfirmSaveUpiIdLocally(
440 const std::string& upi_id,
441 base::OnceCallback<void(bool user_decision)> callback) {
445 void AutofillClientEfl::OfferVirtualCardOptions(
446 const std::vector<CreditCard*>& candidates,
447 base::OnceCallback<void(const std::string&)> callback) {
451 void AutofillClientEfl::CreditCardUploadCompleted(bool card_saved) {
455 void AutofillClientEfl::PinPopupView() {
459 AutofillClient::PopupOpenArgs AutofillClientEfl::GetReopenPopupArgs() const {
464 std::vector<Suggestion> AutofillClientEfl::GetPopupSuggestions() const {
466 return std::vector<Suggestion>();
469 void AutofillClientEfl::UpdatePopup(const std::vector<Suggestion>& suggestions,
470 PopupType popup_type) {
474 const GURL& AutofillClientEfl::GetLastCommittedPrimaryMainFrameURL() const {
475 DCHECK(web_contents_);
476 content::NavigationEntry* entry =
477 web_contents_->GetController().GetLastCommittedEntry();
479 return GURL::EmptyGURL();
481 return entry->GetURL();
484 std::vector<std::string>
485 AutofillClientEfl::GetAllowedMerchantsForVirtualCards() {
487 return std::vector<std::string>();
490 std::vector<std::string>
491 AutofillClientEfl::GetAllowedBinRangesForVirtualCards() {
493 return std::vector<std::string>();
496 const translate::LanguageState* AutofillClientEfl::GetLanguageState() {
500 translate::TranslateDriver* AutofillClientEfl::GetTranslateDriver() {
504 void AutofillClientEfl::ConfirmSaveAddressProfile(
505 const AutofillProfile& profile,
506 const AutofillProfile* original_profile,
507 AutofillClient::SaveAddressProfilePromptOptions options,
508 AddressProfileSavePromptCallback callback) {
512 void AutofillClientEfl::LoadRiskData(
513 base::OnceCallback<void(const std::string&)> callback) {
517 url::Origin AutofillClientEfl::GetLastCommittedPrimaryMainFrameOrigin() const {
519 return url::Origin();
522 void AutofillClientEfl::OpenPromoCodeOfferDetailsURL(const GURL& url) {
526 void AutofillClientEfl::HideTouchToFillCreditCard() {
530 } // namespace autofill
532 #endif // TIZEN_AUTOFILL