Skip to content
This repository was archived by the owner on Jan 4, 2019. It is now read-only.

Commit 17d20ff

Browse files
darkdhbridiver
authored andcommitted
Add clearAutocompleteData & clearAutofillData
Required by brave/browser-laptop#3458 Auditors: @bridiver, @bbondy
1 parent 3bee689 commit 17d20ff

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

atom/browser/api/atom_api_autofill.cc

+70-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ namespace api {
149149

150150
Autofill::Autofill(v8::Isolate* isolate,
151151
content::BrowserContext* browser_context)
152-
: browser_context_(browser_context) {
152+
: browser_context_(browser_context),
153+
weak_ptr_factory_(this) {
153154
Init(isolate);
154155
}
155156

@@ -340,6 +341,71 @@ bool Autofill::RemoveCreditCard(const std::string guid) {
340341
return true;
341342
}
342343

344+
void Autofill::ClearAutocompleteData() {
345+
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
346+
static_cast<brave::BraveBrowserContext*>(browser_context_)
347+
->GetAutofillWebdataService();
348+
349+
if (web_data_service.get()) {
350+
base::Time delete_begin;
351+
base::Time delete_end;
352+
// TODO(Anthony Tseng): Specify time range from front end
353+
delete_begin = delete_begin.UnixEpoch();
354+
delete_end = delete_end.Now();
355+
web_data_service->RemoveFormElementsAddedBetween(delete_begin,
356+
delete_end);
357+
// thread. So wait for it.
358+
content::BrowserThread::PostTaskAndReply(content::BrowserThread::DB,
359+
FROM_HERE,
360+
base::Bind(&base::DoNothing),
361+
base::Bind(&Autofill::OnClearedAutocompleteData,
362+
weak_ptr_factory_.GetWeakPtr()));
363+
364+
autofill::PersonalDataManager* data_manager =
365+
autofill::PersonalDataManagerFactory::GetForBrowserContext(
366+
browser_context_);
367+
if (data_manager)
368+
data_manager->Refresh();
369+
}
370+
}
371+
372+
void Autofill::ClearAutofillData() {
373+
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
374+
static_cast<brave::BraveBrowserContext*>(browser_context_)
375+
->GetAutofillWebdataService();
376+
377+
if (web_data_service.get()) {
378+
base::Time delete_begin;
379+
base::Time delete_end;
380+
// TODO(Anthony Tseng): Specify time range from front end
381+
delete_begin = delete_begin.UnixEpoch();
382+
delete_end = delete_end.Now();
383+
web_data_service->RemoveAutofillDataModifiedBetween(delete_begin,
384+
delete_end);
385+
// The above calls are done on the UI thread but do their work on the DB
386+
// thread. So wait for it.
387+
content::BrowserThread::PostTaskAndReply(content::BrowserThread::DB,
388+
FROM_HERE,
389+
base::Bind(&base::DoNothing),
390+
base::Bind(&Autofill::OnClearedAutofillData,
391+
weak_ptr_factory_.GetWeakPtr()));
392+
393+
autofill::PersonalDataManager* data_manager =
394+
autofill::PersonalDataManagerFactory::GetForBrowserContext(
395+
browser_context_);
396+
if (data_manager)
397+
data_manager->Refresh();
398+
}
399+
}
400+
401+
void Autofill::OnClearedAutocompleteData() {
402+
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
403+
}
404+
405+
void Autofill::OnClearedAutofillData() {
406+
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
407+
}
408+
343409
// static
344410
mate::Handle<Autofill> Autofill::Create(
345411
v8::Isolate* isolate,
@@ -357,7 +423,9 @@ void Autofill::BuildPrototype(v8::Isolate* isolate,
357423
.SetMethod("removeProfile", &Autofill::RemoveProfile)
358424
.SetMethod("addCreditCard", &Autofill::AddCreditCard)
359425
.SetMethod("getCreditCard", &Autofill::GetCreditCard)
360-
.SetMethod("removeCreditCard", &Autofill::RemoveCreditCard);
426+
.SetMethod("removeCreditCard", &Autofill::RemoveCreditCard)
427+
.SetMethod("clearAutocompleteData", &Autofill::ClearAutocompleteData)
428+
.SetMethod("clearAutofillData", &Autofill::ClearAutofillData);
361429
}
362430

363431
} // namespace api

atom/browser/api/atom_api_autofill.h

+8
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ class Autofill : public mate::TrackableObject<Autofill> {
5050
autofill::CreditCard* GetCreditCard(std::string guid);
5151
bool RemoveCreditCard(const std::string guid);
5252

53+
void ClearAutocompleteData();
54+
void ClearAutofillData();
55+
5356
brave::BraveBrowserContext* browser_context() {
5457
return static_cast<brave::BraveBrowserContext*>(browser_context_);
5558
}
5659

5760
private:
61+
void OnClearedAutocompleteData();
62+
void OnClearedAutofillData();
63+
5864
content::BrowserContext* browser_context_; // not owned
5965

66+
base::WeakPtrFactory<Autofill> weak_ptr_factory_;
67+
6068
DISALLOW_COPY_AND_ASSIGN(Autofill);
6169
};
6270

0 commit comments

Comments
 (0)