Verified Commit a3276114 authored by clairehurst's avatar clairehurst 🌱 Committed by jwilde
Browse files

TB 42655 [android]: Implement "New circuit for this site" on Android

parent 98b7eea2
Loading
Loading
Loading
Loading
+4 −0
Changes for mobile/android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1705,6 +1705,10 @@ class GeckoEngineSession(
        geckoSession.translationsSessionDelegate = GeckoTranslateSessionDelegate(this)
    }

    fun newTorCircuit() {
        geckoSession.newTorCircuit()
    }

    companion object {
        internal const val PROGRESS_START = 25
        internal const val PROGRESS_STOP = 100
+10 −0
Changes for mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/MenuDialogFragment.kt: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -121,6 +121,9 @@ import org.mozilla.fenix.webcompat.middleware.DefaultWebCompatReporterRetrievalS
import org.mozilla.fenix.webcompat.middleware.WebCompatInfoDeserializer
import com.google.android.material.R as materialR

import mozilla.components.browser.engine.gecko.GeckoEngineSession
import android.util.Log

// EXPANDED_MIN_RATIO is used for BottomSheetBehavior.halfExpandedRatio().
// That value needs to be less than the PEEK_HEIGHT.
// If EXPANDED_MIN_RATIO is greater than the PEEK_HEIGHT, then there will be
@@ -861,6 +864,13 @@ class MenuDialogFragment : BottomSheetDialogFragment() {
                                            },
                                        )
                                    },
                                    onNewCircuitButtonClick = {
                                        components.core.store.state.selectedTab?.let {
                                            (it.engineState.engineSession as GeckoEngineSession).newTorCircuit()
                                            components.useCases.sessionUseCases.reload.invoke(it.id)
                                            dismiss()
                                        } ?: Log.e("MenuDialogFragment", "selectedTab was null, tab and tor circuit not refreshed")
                                    },
                                )
                            }

+11 −0
Changes for mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/compose/MainMenu.kt: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ fun MainMenu(
    extensionsMenuItemDescription: String?,
    moreSettingsSubmenu: @Composable () -> Unit,
    extensionSubmenu: @Composable () -> Unit,
    onNewCircuitButtonClick: () -> Unit,
) {
    MenuFrame(
        contentModifier = Modifier
@@ -292,6 +293,7 @@ fun MainMenu(
                extensionsMenuItemDescription = extensionsMenuItemDescription,
                moreSettingsSubmenu = moreSettingsSubmenu,
                extensionSubmenu = extensionSubmenu,
                onNewCircuitButtonClick = onNewCircuitButtonClick,
            )
        }

@@ -365,6 +367,7 @@ private fun ToolsAndActionsMenuGroup(
    extensionsMenuItemDescription: String?,
    moreSettingsSubmenu: @Composable () -> Unit,
    extensionSubmenu: @Composable () -> Unit,
    onNewCircuitButtonClick: (() -> Unit)?,
) {
    MenuGroup {
        val labelId = R.string.browser_menu_desktop_site
@@ -382,6 +385,12 @@ private fun ToolsAndActionsMenuGroup(
            menuItemState = if (isPdf) MenuItemState.DISABLED else MenuItemState.ENABLED
        }

        MenuItem(
            label = stringResource(R.string.library_new_circuit),
            beforeIconPainter = painterResource(R.drawable.new_circuit),
            onClick = onNewCircuitButtonClick,
        )

        if (isBookmarked) {
            MenuItem(
                label = stringResource(id = R.string.browser_menu_edit_bookmark),
@@ -767,6 +776,7 @@ private fun MenuDialogPreview(
                onShareButtonClick = {},
                moreSettingsSubmenu = {},
                extensionSubmenu = {},
                onNewCircuitButtonClick = {},
            )
        }
    }
@@ -856,6 +866,7 @@ private fun MenuDialogPrivatePreview(
                        onWebExtensionMenuItemClick = {},
                    )
                },
                onNewCircuitButtonClick = {},
            )
        }
    }
+14 −0
Changes for mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.engine.gecko.GeckoEngineSession
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.ShareResourceAction
import mozilla.components.browser.state.ext.getUrl
@@ -431,6 +432,14 @@ class DefaultBrowserToolbarMenuController(
                    BrowserFragmentDirections.actionBrowserFragmentToTranslationsDialogFragment()
                navController.navigateSafe(R.id.browserFragment, directions)
            }

            // Remove once moz deletes this old UI (Toolbar Menu is being replaced by MainMenu)
            ToolbarMenu.Item.NewTorCircuit -> {
                currentSession?.let {
                    sessionUseCases.reload.invoke(it.id)
                    (it.engineState.engineSession as GeckoEngineSession).newTorCircuit()
                }
            }
        }
    }

@@ -579,6 +588,11 @@ class DefaultBrowserToolbarMenuController(
                    "translate",
                ),
            )

            // Remove once moz deletes this old UI (Toolbar Menu is being replaced by MainMenu)
            ToolbarMenu.Item.NewTorCircuit -> {
                /* Tor doesn't use telemetry and therefore this doesn't need to be implemented */
            }
        }
    }

+2 −0
Changes for mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -65,5 +65,7 @@ interface ToolbarMenu {
        object Passwords : Item()
        object Downloads : Item()
        object NewTab : Item()
        // Remove once moz deletes this old UI (Toolbar Menu is being replaced by MainMenu)
        object NewTorCircuit : Item()
    }
}
Loading