Skip to content

Commit

Permalink
For mozilla-mobile#11903: Enforce private theme in custom tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods committed Jun 26, 2020
1 parent c958cc0 commit bbbcdf4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 35 deletions.
5 changes: 0 additions & 5 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
}
}

fun updateThemeForSession(session: Session) {
val sessionMode = BrowsingMode.fromBoolean(session.private)
browsingModeManager.mode = sessionMode
}

override fun attachBaseContext(base: Context) {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
super.attachBaseContext(base)
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.readermode.DefaultReaderModeController
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.FindInPageIntegration
Expand Down Expand Up @@ -690,7 +691,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session

@CallSuper
override fun onSessionSelected(session: Session) {
(activity as HomeActivity).updateThemeForSession(session)
updateThemeForSession(session)
if (!browserInitialized) {
// Initializing a new coroutineScope to avoid ConcurrentModificationException in ObserverRegistry
// This will be removed when ObserverRegistry is deprecated by browser-state.
Expand Down Expand Up @@ -720,6 +721,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
components.useCases.sessionUseCases.reload()
}
hideToolbar()

getSessionById()?.let { updateThemeForSession(it) }
}

@CallSuper
Expand Down Expand Up @@ -872,6 +875,14 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
}
}

/**
* Set the activity normal/private theme to match the current session.
*/
private fun updateThemeForSession(session: Session) {
val sessionMode = BrowsingMode.fromBoolean(session.private)
(activity as HomeActivity).browsingModeManager.mode = sessionMode
}

/**
* Returns the current session.
*/
Expand Down Expand Up @@ -997,6 +1008,5 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2
private const val REQUEST_CODE_APP_PERMISSIONS = 3
private const val SNACKBAR_ELEVATION = 80f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.tabs.WindowFeature
import mozilla.components.support.base.feature.UserInteractionHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.addons.runIfFragmentIsAttached
import org.mozilla.fenix.components.FenixSnackbar
Expand All @@ -40,8 +39,8 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.navigateSafe
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.shortcut.FirstTimePwaObserver
import org.mozilla.fenix.trackingprotection.TrackingProtectionOverlay

Expand Down Expand Up @@ -178,9 +177,6 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {

override fun onResume() {
super.onResume()
getSessionById()?.let {
(activity as HomeActivity).updateThemeForSession(it)
}
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CustomTabsIntegration(
)
}

toolbar.background = getDrawable(activity, R.drawable.toolbar_background_private)
toolbar.background = getDrawable(activity, R.drawable.toolbar_background)
}
}

Expand Down
22 changes: 0 additions & 22 deletions app/src/main/res/drawable/toolbar_background_private.xml

This file was deleted.

0 comments on commit bbbcdf4

Please sign in to comment.