2019-09-10 22:29:21 +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-10 22:29:21 +02:00
|
|
|
|
2019-09-14 20:51:12 +02:00
|
|
|
import android.app.Activity
|
2020-01-02 23:31:52 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar
|
2019-09-10 22:29:21 +02:00
|
|
|
import kotlinx.coroutines.CoroutineScope
|
2019-09-14 21:35:17 +02:00
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
|
import kotlinx.coroutines.joinAll
|
2019-09-10 22:29:21 +02:00
|
|
|
import kotlinx.coroutines.launch
|
2019-09-14 21:35:17 +02:00
|
|
|
import kotlinx.coroutines.withContext
|
2020-01-02 23:31:52 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-10-21 18:57:06 +02:00
|
|
|
import org.mozilla.fenix.components.FenixSnackbar
|
2020-07-29 15:21:01 +02:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-09-14 21:35:17 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-09-10 22:29:21 +02:00
|
|
|
|
|
|
|
/**
|
2019-09-14 20:51:12 +02:00
|
|
|
* Deletes selected browsing data and finishes the activity.
|
2019-09-10 22:29:21 +02:00
|
|
|
*/
|
2019-10-21 18:57:06 +02:00
|
|
|
fun deleteAndQuit(activity: Activity, coroutineScope: CoroutineScope, snackbar: FenixSnackbar?) {
|
2019-09-10 22:29:21 +02:00
|
|
|
coroutineScope.launch {
|
2019-09-14 21:35:17 +02:00
|
|
|
val settings = activity.settings()
|
2020-07-29 15:21:01 +02:00
|
|
|
val controller = DefaultDeleteBrowsingDataController(
|
|
|
|
activity.components.useCases.tabsUseCases.removeAllTabs,
|
|
|
|
activity.components.core.historyStorage,
|
|
|
|
activity.components.core.permissionStorage,
|
|
|
|
activity.components.core.engine,
|
|
|
|
coroutineContext
|
|
|
|
)
|
2019-09-14 20:51:12 +02:00
|
|
|
|
2020-01-02 23:31:52 +01:00
|
|
|
snackbar?.apply {
|
|
|
|
setText(activity.getString(R.string.deleting_browsing_data_in_progress))
|
|
|
|
duration = Snackbar.LENGTH_INDEFINITE
|
|
|
|
show()
|
|
|
|
}
|
2019-10-21 18:57:06 +02:00
|
|
|
|
2019-09-14 21:35:17 +02:00
|
|
|
DeleteBrowsingDataOnQuitType.values().map { type ->
|
|
|
|
launch {
|
|
|
|
if (settings.getDeleteDataOnQuit(type)) {
|
|
|
|
controller.deleteType(type)
|
|
|
|
}
|
2019-09-10 22:29:21 +02:00
|
|
|
}
|
2019-09-14 21:35:17 +02:00
|
|
|
}.joinAll()
|
2019-09-14 20:51:12 +02:00
|
|
|
|
2019-10-21 18:57:06 +02:00
|
|
|
snackbar?.dismiss()
|
|
|
|
|
2019-09-14 20:51:12 +02:00
|
|
|
activity.finish()
|
2019-09-10 22:29:21 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-14 21:35:17 +02:00
|
|
|
|
|
|
|
private suspend fun DeleteBrowsingDataController.deleteType(type: DeleteBrowsingDataOnQuitType) {
|
|
|
|
when (type) {
|
|
|
|
DeleteBrowsingDataOnQuitType.TABS -> deleteTabs()
|
|
|
|
DeleteBrowsingDataOnQuitType.HISTORY -> deleteHistoryAndDOMStorages()
|
|
|
|
DeleteBrowsingDataOnQuitType.COOKIES -> deleteCookies()
|
|
|
|
DeleteBrowsingDataOnQuitType.CACHE -> deleteCachedFiles()
|
|
|
|
DeleteBrowsingDataOnQuitType.PERMISSIONS -> withContext(IO) {
|
|
|
|
deleteSitePermissions()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|