From ed334788e821b0c3a14a428961137ce980344d6e Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Thu, 25 Jun 2020 09:54:15 -0700 Subject: [PATCH] For #11903: Enforce private theme in custom tabs --- .../java/org/mozilla/fenix/HomeActivity.kt | 5 ----- .../fenix/browser/BaseBrowserFragment.kt | 14 ++++++++++-- .../mozilla/fenix/browser/BrowserFragment.kt | 6 +---- .../fenix/customtabs/CustomTabsIntegration.kt | 2 +- .../drawable/toolbar_background_private.xml | 22 ------------------- 5 files changed, 14 insertions(+), 35 deletions(-) delete mode 100644 app/src/main/res/drawable/toolbar_background_private.xml diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index d8c5c7124..db2f37b1d 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -511,11 +511,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) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 791971685..9ed9985f7 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -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 @@ -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. @@ -720,6 +721,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session components.useCases.sessionUseCases.reload() } hideToolbar() + + getSessionById()?.let { updateThemeForSession(it) } } @CallSuper @@ -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. */ @@ -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 } } diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index eee14ae28..a932686cf 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -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 @@ -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 @@ -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) } diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt index 900401314..452f1b0d6 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt @@ -67,7 +67,7 @@ class CustomTabsIntegration( ) } - toolbar.background = getDrawable(activity, R.drawable.toolbar_background_private) + toolbar.background = getDrawable(activity, R.drawable.toolbar_background) } } diff --git a/app/src/main/res/drawable/toolbar_background_private.xml b/app/src/main/res/drawable/toolbar_background_private.xml deleted file mode 100644 index 146188097..000000000 --- a/app/src/main/res/drawable/toolbar_background_private.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - -