2019-09-04 22:27:30 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2019-09-14 06:29:11 +02:00
|
|
|
package org.mozilla.fenix.settings.deletebrowsingdata
|
2019-09-04 22:27:30 +02:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import mozilla.components.concept.engine.Engine
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import kotlin.coroutines.CoroutineContext
|
|
|
|
|
|
|
|
interface DeleteBrowsingDataController {
|
|
|
|
suspend fun deleteTabs()
|
|
|
|
suspend fun deleteBrowsingData()
|
2019-09-14 21:35:17 +02:00
|
|
|
suspend fun deleteHistoryAndDOMStorages()
|
2019-09-04 22:27:30 +02:00
|
|
|
suspend fun deleteCookies()
|
|
|
|
suspend fun deleteCachedFiles()
|
|
|
|
suspend fun deleteSitePermissions()
|
|
|
|
}
|
|
|
|
|
|
|
|
class DefaultDeleteBrowsingDataController(
|
|
|
|
val context: Context,
|
|
|
|
val coroutineContext: CoroutineContext = Dispatchers.Main
|
|
|
|
) : DeleteBrowsingDataController {
|
2019-09-14 21:35:17 +02:00
|
|
|
|
2019-09-04 22:27:30 +02:00
|
|
|
override suspend fun deleteTabs() {
|
|
|
|
withContext(coroutineContext) {
|
|
|
|
context.components.useCases.tabsUseCases.removeAllTabs.invoke()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun deleteBrowsingData() {
|
2019-10-02 19:43:37 +02:00
|
|
|
deleteHistoryAndDOMStorages()
|
2019-09-10 22:29:21 +02:00
|
|
|
}
|
|
|
|
|
2019-09-14 21:35:17 +02:00
|
|
|
override suspend fun deleteHistoryAndDOMStorages() {
|
2019-09-10 22:29:21 +02:00
|
|
|
withContext(coroutineContext) {
|
|
|
|
context.components.core.engine.clearData(Engine.BrowsingData.select(Engine.BrowsingData.DOM_STORAGES))
|
2019-09-04 22:27:30 +02:00
|
|
|
}
|
|
|
|
context.components.core.historyStorage.deleteEverything()
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun deleteCookies() {
|
|
|
|
withContext(coroutineContext) {
|
2019-09-06 16:39:15 +02:00
|
|
|
context.components.core.engine.clearData(
|
|
|
|
Engine.BrowsingData.select(
|
|
|
|
Engine.BrowsingData.COOKIES,
|
|
|
|
Engine.BrowsingData.AUTH_SESSIONS
|
|
|
|
)
|
|
|
|
)
|
2019-09-04 22:27:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun deleteCachedFiles() {
|
|
|
|
withContext(coroutineContext) {
|
|
|
|
context.components.core.engine.clearData(
|
|
|
|
Engine.BrowsingData.select(Engine.BrowsingData.ALL_CACHES)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun deleteSitePermissions() {
|
|
|
|
withContext(coroutineContext) {
|
|
|
|
context.components.core.engine.clearData(
|
|
|
|
Engine.BrowsingData.select(Engine.BrowsingData.ALL_SITE_SETTINGS)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
context.components.core.permissionStorage.deleteAllSitePermissions()
|
|
|
|
}
|
|
|
|
}
|