Skip to content

Commit

Permalink
Android: Permissions issue in Custom Tab (#4461)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/488551667048375/1207149305479467/f

### Description
Addressed the issue where permissions popups were not displayed in
Custom Tab.

### Steps to test this PR

- [x] This was already tested. See the task for testing details as an
account is needed.
https://app.asana.com/0/0/1207092601847905/1207159233439502/f

### NO UI changes
  • Loading branch information
anikiki authored Apr 26, 2024
1 parent 5b9287f commit 13a8a7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import com.duckduckgo.app.browser.commands.Command
import com.duckduckgo.app.browser.commands.Command.ShowBackNavigationHistory
import com.duckduckgo.app.browser.commands.NavigationCommand
import com.duckduckgo.app.browser.cookies.ThirdPartyCookieManager
import com.duckduckgo.app.browser.customtabs.CustomTabActivity
import com.duckduckgo.app.browser.customtabs.CustomTabPixelNames
import com.duckduckgo.app.browser.customtabs.CustomTabViewModel.Companion.CUSTOM_TAB_NAME_PREFIX
import com.duckduckgo.app.browser.databinding.ContentSiteLocationPermissionDialogBinding
Expand Down Expand Up @@ -1301,6 +1302,8 @@ class BrowserTabFragment :
if (isActiveCustomTab()) {
webView?.hitTestResult?.extra?.let { data ->
webView?.loadUrl(Uri.parse(data).toString())
} ?: run {
(activity as CustomTabActivity).openMessageInNewFragmentInCustomTab(it.message, this, customTabToolbarColor)
}
} else {
browserActivity?.openMessageInNewTab(it.message, it.sourceTabId)
Expand Down Expand Up @@ -1646,7 +1649,7 @@ class BrowserTabFragment :
}

private fun askSiteLocationPermission(locationPermission: LocationPermission) {
if (!isActiveTab) {
if (!isActiveCustomTab() && !isActiveTab) {
Timber.v("Will not launch a dialog for an inactive tab")
return
}
Expand Down Expand Up @@ -1999,7 +2002,7 @@ class BrowserTabFragment :
}

private fun showAuthenticationDialog(request: BasicAuthenticationRequest) {
if (!isActiveTab) {
if (!isActiveCustomTab() && !isActiveTab) {
Timber.v("Will not launch a dialog for an inactive tab")
return
}
Expand Down Expand Up @@ -3966,7 +3969,7 @@ class BrowserTabFragment :
permissionsToRequest: SitePermissions,
request: PermissionRequest,
) {
if (!isActiveTab) {
if (!isActiveCustomTab() && !isActiveTab) {
Timber.v("Will not launch a dialog for an inactive tab")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.duckduckgo.app.browser.customtabs
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Message
import androidx.browser.customtabs.CustomTabsIntent
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
Expand All @@ -32,6 +33,7 @@ import com.duckduckgo.app.global.intentText
import com.duckduckgo.common.ui.DuckDuckGoActivity
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.di.scopes.ActivityScope
import java.util.UUID
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import timber.log.Timber
Expand Down Expand Up @@ -59,6 +61,20 @@ class CustomTabActivity : DuckDuckGoActivity() {
viewModel.onCustomTabCreated(url, toolbarColor)
}

fun openMessageInNewFragmentInCustomTab(
message: Message,
currentFragment: BrowserTabFragment,
toolbarColor: Int,
) {
val tabId = "${CustomTabViewModel.CUSTOM_TAB_NAME_PREFIX}${UUID.randomUUID()}"
val newFragment = BrowserTabFragment.newInstanceForCustomTab(tabId, null, true, toolbarColor)
val transaction = supportFragmentManager.beginTransaction()
transaction.hide(currentFragment)
transaction.add(R.id.fragmentTabContainer, newFragment, tabId)
transaction.commit()
newFragment.messageFromPreviousTab = message
}

override fun onStart() {
super.onStart()
viewModel.onShowCustomTab()
Expand Down

0 comments on commit 13a8a7d

Please sign in to comment.