Commit f43545fb authored by Christian Sadilek's avatar Christian Sadilek Committed by mergify[bot]
Browse files

Closes #8113: Remove logic to reset private browsing setting for extensions

parent d53097c3
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ class GeckoEngine(
) : Engine, WebExtensionRuntime {
    private val executor by lazy { executorProvider.invoke() }
    private val localeUpdater = LocaleSettingUpdater(context, runtime)
    private val sharedPref = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
    @VisibleForTesting internal val speculativeConnectionFactory = SpeculativeSessionFactory()
    private var webExtensionDelegate: WebExtensionDelegate? = null
    private val webExtensionActionHandler = object : ActionHandler {
@@ -331,23 +330,11 @@ class GeckoEngine(
                extension -> GeckoWebExtension(extension, runtime)
            } ?: emptyList()

            val privateBrowsingMigrated = sharedPref.getBoolean(MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT, false)
            extensions.forEach { extension ->
                // As a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1621385,
                // we set all installed extensions to be allowed in private browsing mode.
                // We need to revert back to false which is now the default.
                if (!extension.isBuiltIn() && extension.isAllowedInPrivateBrowsing() && !privateBrowsingMigrated) {
                    setAllowedInPrivateBrowsing(extension, false)
                }

                extension.registerActionHandler(webExtensionActionHandler)
                extension.registerTabHandler(webExtensionTabHandler)
            }

            if (!privateBrowsingMigrated) {
                sharedPref.edit().putBoolean(MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT, true).apply()
            }

            onSuccess(extensions)
            GeckoResult<Void>()
        }, { throwable ->
@@ -720,13 +707,6 @@ class GeckoEngine(
            cookiesHasBeenBlocked = cookiesHasBeenBlocked
        )
    }

    companion object {
        private const val PREFERENCE_NAME =
            "MOZAC_GECKO_ENGINE"
        private const val MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT =
            "MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT"
    }
}

internal fun ContentBlockingController.LogEntry.BlockingData.hasBlockedCookies(): Boolean {
+0 −43
Original line number Diff line number Diff line
@@ -1352,49 +1352,6 @@ class GeckoEngineTest {
        assertNotNull(extensions)
    }

    @Test
    fun `migrate private browsing default`() {
        val bundle = GeckoBundle()
        bundle.putString("webExtensionId", "id")
        bundle.putString("locationURI", "uri")
        val metaDataBundle = GeckoBundle()
        metaDataBundle.putBoolean("privateBrowsingAllowed", true)
        metaDataBundle.putStringArray("disabledFlags", emptyArray())
        bundle.putBundle("metaData", metaDataBundle)
        val installedExtension = MockWebExtension(bundle)

        val installedExtensions = listOf<GeckoWebExtension>(installedExtension)
        val installedExtensionResult = GeckoResult<List<GeckoWebExtension>>()

        val runtime = mock<GeckoRuntime>()
        val extensionController: WebExtensionController = mock()
        whenever(extensionController.list()).thenReturn(installedExtensionResult)
        whenever(runtime.webExtensionController).thenReturn(extensionController)

        val allowedInPrivateBrowsingExtensionResult = GeckoResult<GeckoWebExtension>()
        whenever(extensionController.setAllowedInPrivateBrowsing(any(), anyBoolean())).thenReturn(allowedInPrivateBrowsingExtensionResult)

        val engine = spy(GeckoEngine(testContext, runtime = runtime))
        var extensions: List<WebExtension>? = null
        var onErrorCalled = false

        engine.listInstalledWebExtensions(
                onSuccess = { extensions = it },
                onError = { onErrorCalled = true }
        )
        installedExtensionResult.complete(installedExtensions)
        assertFalse(onErrorCalled)
        assertNotNull(extensions)
        val installedWebExtension = extensions!![0]
        verify(engine, times(1)).setAllowedInPrivateBrowsing(eq(installedWebExtension), eq(false), any(), any())

        engine.listInstalledWebExtensions(
                onSuccess = { extensions = it },
                onError = { onErrorCalled = true }
        )
        verify(engine, times(1)).setAllowedInPrivateBrowsing(eq(installedWebExtension), eq(false), any(), any())
    }

    @Test
    fun `list web extensions failure`() {
        val installedExtensionResult = GeckoResult<List<GeckoWebExtension>>()