GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Bug 40075: Integrate Modify Android-Components WebExtensions Menu patch

parent 8694517b
From b95463e9c2461b56185ecb9efdd45c01d447e37f Mon Sep 17 00:00:00 2001
From: Matthew Finkel <sysrqb@torproject.org>
Date: Fri, 4 Sep 2020 14:21:58 +0000
Subject: [PATCH 1/2] Bug 40016 - Modify Default toolbar menu
---
.../browser/menu/WebExtensionBrowserMenu.kt | 36 ++++++++++++++++++-
.../menu/WebExtensionBrowserMenuBuilder.kt | 26 ++++----------
2 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenu.kt b/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenu.kt
index 77b37502d..c07c3fc91 100644
--- a/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenu.kt
+++ b/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenu.kt
@@ -9,6 +9,8 @@ import android.widget.PopupWindow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.collect
+import mozilla.components.concept.engine.webextension.WebExtensionBrowserAction
+import mozilla.components.concept.engine.webextension.WebExtensionPageAction
import mozilla.components.browser.menu.facts.emitOpenMenuItemFact
import mozilla.components.browser.menu.item.WebExtensionBrowserMenuItem
import mozilla.components.browser.state.selector.selectedTab
@@ -74,7 +76,39 @@ class WebExtensionBrowserMenu internal constructor(
): List<BrowserMenuItem> {
val menuItems = ArrayList<BrowserMenuItem>()
val extensions = state.extensions.values.toList()
- extensions.filter { it.enabled }.sortedBy { it.name }
+ extensions.filter { it.enabled }.filter {
+ // When a BrowserAction is defined, it is only shown when the badgeText is
+ // set. Specifically, NoScript always enables its BrowserAction but assigns
+ // the badgeText as "" when zero elements were blocked on the page.
+ // We filter PageActions in a similar way, but NoScript and HTTPS Everywhere
+ // don't use it.
+ val browserAction: WebExtensionBrowserAction? = it.browserAction
+ val enabled: Boolean? = it.enabled
+ val pageAction: WebExtensionPageAction? = it.pageAction
+ val tabBrowserAction = tab?.extensionState?.get(it.id)?.browserAction
+ val tabPageAction = tab?.extensionState?.get(it.id)?.pageAction
+ val actionList = listOf(browserAction) + pageAction + tabBrowserAction + tabPageAction
+ var keep = false
+
+ actionList.forEach { action ->
+ if (action != null) {
+ val badgeText: String? = action.badgeText
+ if (badgeText != null) {
+ keep = keep || (badgeText != "")
+ // There may exist rare cases where the badgeText is set, but the Action
+ // is disabled.
+ if (keep && enabled != null) {
+ keep = keep || enabled
+ }
+ } else {
+ keep = keep || false
+ }
+ } else {
+ keep = keep || false
+ }
+ }
+ keep
+ }.sortedBy { it.name }
.forEach { extension ->
if (!extension.allowedInPrivateBrowsing && tab?.content?.private == true) {
return@forEach
diff --git a/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenuBuilder.kt b/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenuBuilder.kt
index 4dd73c75e..7c216577c 100644
--- a/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenuBuilder.kt
+++ b/components/browser/menu/src/main/java/mozilla/components/browser/menu/WebExtensionBrowserMenuBuilder.kt
@@ -50,20 +50,10 @@ class WebExtensionBrowserMenuBuilder(
iconTintColorResource = webExtIconTintColorResource
)
- val addonsManagerMenuItem = BrowserMenuImageText(
- label = context.getString(R.string.mozac_browser_menu_addons_manager),
- imageResource = R.drawable.mozac_ic_extensions,
- iconTintColorResource = webExtIconTintColorResource
- ) {
- onAddonsManagerTapped.invoke()
- }
-
val webExtSubMenuItems = if (appendExtensionSubMenuAtStart) {
- listOf(backPressMenuItem) + BrowserMenuDivider() +
- extensionMenuItems +
- BrowserMenuDivider() + addonsManagerMenuItem
+ listOf<BrowserMenuItem>(backPressMenuItem) + BrowserMenuDivider() +
+ extensionMenuItems
} else {
- listOf(addonsManagerMenuItem) + BrowserMenuDivider() +
extensionMenuItems +
BrowserMenuDivider() + backPressMenuItem
}
@@ -79,17 +69,13 @@ class WebExtensionBrowserMenuBuilder(
endOfMenuAlwaysVisible = endOfMenuAlwaysVisible
)
} else {
- BrowserMenuImageText(
- label = context.getString(R.string.mozac_browser_menu_addons),
- imageResource = R.drawable.mozac_ic_extensions,
- iconTintColorResource = webExtIconTintColorResource
- ) {
- onAddonsManagerTapped.invoke()
- }
+ null
}
val menuItems =
- if (appendExtensionSubMenuAtStart) {
+ if (webExtMenuItem == null) {
+ items
+ } else if (appendExtensionSubMenuAtStart) {
listOf(webExtMenuItem) + items
} else {
items + webExtMenuItem
--
2.20.1
......@@ -24,6 +24,7 @@ tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
cd $builddir-[% c('version') %]
patch -p1 < $rootdir/git.patch
patch -p1 < $rootdir/0001-Bug-40016-Modify-Default-toolbar-menu.patch
patch -p1 < $rootdir/0002-Bug-40001-Disable-PWA-until-it-is-audited.patch
[% IF c("var/fetch_gradle_dependencies") %]
# XXX: fetching deps for `assembleGeckoBeta -x lint` by using that same target
......
......@@ -36,4 +36,5 @@ input_files:
- URL: https://people.torproject.org/~gk/mirrors/sources/glean-parser-[% c('var/glean_parser') %].tar.bz2
sha256sum: 69234aa1ae38fd5dda4de71bd5e536795073703c3ed5bb994b9b8485bd7a55dc
enable: '[% !c("var/fetch_gradle_dependencies") %]'
- filename: 0001-Bug-40016-Modify-Default-toolbar-menu.patch
- filename: 0002-Bug-40001-Disable-PWA-until-it-is-audited.patch
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment