tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit edbdedea9df1ea0d5b9354bcf52525169871bab3
parent 07cdd1f846509ce0e5abf0abe0c1d9a47f392ec0
Author: Alex Catarineu <acat@torproject.org>
Date:   Fri,  2 Oct 2020 21:12:23 +0200

TB 40015: [android] Port padlock states for .onion services

Originally, android-components#40015.

Diffstat:
Mmobile/android/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt | 1+
Mmobile/android/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteInfoIconView.kt | 5+++++
Mmobile/android/android-components/components/browser/toolbar/src/main/res/drawable/mozac_ic_site_info.xml | 3+++
Mmobile/android/android-components/components/browser/toolbar/src/main/res/values/attrs_browser_toolbar.xml | 4++++
Mmobile/android/android-components/components/concept/toolbar/src/main/java/mozilla/components/concept/toolbar/Toolbar.kt | 1+
Mmobile/android/android-components/components/feature/toolbar/src/main/java/mozilla/components/feature/toolbar/ToolbarPresenter.kt | 7++++++-
Mmobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/kotlin/String.kt | 9+++++++++
Amobile/android/android-components/components/ui/icons/src/main/res/drawable/mozac_ic_onion.xml | 20++++++++++++++++++++
8 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/mobile/android/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt b/mobile/android/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt @@ -540,6 +540,7 @@ class DisplayToolbar internal constructor( Toolbar.SiteInfo.INSECURE -> colors.siteInfoIconInsecure Toolbar.SiteInfo.SECURE -> colors.siteInfoIconSecure Toolbar.SiteInfo.LOCAL_PDF -> colors.siteInfoIconLocalPdf + Toolbar.SiteInfo.ONION -> colors.siteInfoIconSecure } if (color == Color.TRANSPARENT) { views.siteInfoIndicator.clearColorFilter() diff --git a/mobile/android/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteInfoIconView.kt b/mobile/android/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteInfoIconView.kt @@ -48,6 +48,11 @@ internal class SiteInfoIconView @JvmOverloads constructor( View.mergeDrawableStates(drawableState, intArrayOf(R.attr.state_site_secure)) drawableState } + SiteInfo.ONION -> { + val drawableState = super.onCreateDrawableState(extraSpace + 1) + View.mergeDrawableStates(drawableState, intArrayOf(R.attr.state_site_onion)) + drawableState + } } } } diff --git a/mobile/android/android-components/components/browser/toolbar/src/main/res/drawable/mozac_ic_site_info.xml b/mobile/android/android-components/components/browser/toolbar/src/main/res/drawable/mozac_ic_site_info.xml @@ -4,6 +4,9 @@ - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> <selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ac="http://schemas.android.com/apk/res-auto"> <item + android:drawable="@drawable/mozac_ic_onion" + ac:state_site_onion="true" /> + <item android:drawable="@drawable/mozac_ic_shield_checkmark_24" ac:state_site_secure="true" /> <item diff --git a/mobile/android/android-components/components/browser/toolbar/src/main/res/values/attrs_browser_toolbar.xml b/mobile/android/android-components/components/browser/toolbar/src/main/res/values/attrs_browser_toolbar.xml @@ -13,6 +13,10 @@ <attr name="state_site_secure" format="boolean"/> </declare-styleable> + <declare-styleable name="BrowserToolbarSiteOnionState"> + <attr name="state_site_onion" format="boolean"/> + </declare-styleable> + <declare-styleable name="ActionContainer"> <attr name="actionContainerItemSize" format="dimension" /> </declare-styleable> diff --git a/mobile/android/android-components/components/concept/toolbar/src/main/java/mozilla/components/concept/toolbar/Toolbar.kt b/mobile/android/android-components/components/concept/toolbar/src/main/java/mozilla/components/concept/toolbar/Toolbar.kt @@ -494,6 +494,7 @@ interface Toolbar : ScrollableToolbar { INSECURE, SECURE, LOCAL_PDF, + ONION, } /** diff --git a/mobile/android/android-components/components/feature/toolbar/src/main/java/mozilla/components/feature/toolbar/ToolbarPresenter.kt b/mobile/android/android-components/components/feature/toolbar/src/main/java/mozilla/components/feature/toolbar/ToolbarPresenter.kt @@ -19,6 +19,7 @@ import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection import mozilla.components.feature.toolbar.internal.URLRenderer import mozilla.components.lib.state.ext.flowScoped import mozilla.components.support.ktx.kotlin.isContentUrl +import mozilla.components.support.ktx.kotlin.isOnionUrl /** * Presenter implementation for a toolbar implementation in order to update the toolbar whenever @@ -72,7 +73,11 @@ class ToolbarPresenter( toolbar.siteInfo = if (tab.content.url.isContentUrl()) { Toolbar.SiteInfo.LOCAL_PDF } else if (tab.content.securityInfo.isSecure) { - Toolbar.SiteInfo.SECURE + if (tab.content.url.isOnionUrl()) { + Toolbar.SiteInfo.ONION + } else { + Toolbar.SiteInfo.SECURE + } } else { Toolbar.SiteInfo.INSECURE } diff --git a/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/kotlin/String.kt b/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/kotlin/String.kt @@ -266,6 +266,15 @@ fun String.urlContainsQueryParameters(searchParameters: String): Boolean = try { } /** + * Returns whether the string is an .onion URL. + */ +fun String.isOnionUrl(): Boolean = try { + URL(this).host.endsWith(".onion") +} catch (e: MalformedURLException) { + false +} + +/** * Compares 2 URLs and returns true if they have the same origin, * which means: same protocol, same host, same port. * It will return false if either this or [other] is not a valid URL. diff --git a/mobile/android/android-components/components/ui/icons/src/main/res/drawable/mozac_ic_onion.xml b/mobile/android/android-components/components/ui/icons/src/main/res/drawable/mozac_ic_onion.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + + <path + android:fillColor="@color/mozac_ui_icons_fill" + android:fillType="evenOdd" + android:pathData="M12 18.25c2.0711 0 3.75-1.6789 3.75-3.75s-1.6789-3.75-3.75-3.75c-2.0711 0-3.75 1.6789-3.75 3.75s1.6789 3.75 3.75 3.75zm0 1.25c2.7614 0 5-2.2386 5-5s-2.2386-5-5-5c-2.7614 0-5 2.2386-5 5s2.2386 5 5 5z" /> + <path + android:fillColor="@color/mozac_ui_icons_fill" + android:fillType="evenOdd" + android:pathData="M12 15.75c0.6903 0 1.25-0.5596 1.25-1.25 0-0.6903-0.5597-1.25-1.25-1.25s-1.25 0.5597-1.25 1.25c0 0.6904 0.5597 1.25 1.25 1.25zm0 1.25c1.3807 0 2.5-1.1193 2.5-2.5s-1.1193-2.5-2.5-2.5-2.5 1.1193-2.5 2.5 1.1193 2.5 2.5 2.5z" /> + <path + android:fillColor="@color/mozac_ui_icons_fill" + android:fillType="evenOdd" + android:pathData="M17 8.9097c1.5344 1.3733 2.5 3.3691 2.5 5.5903 0 4.1421-3.3579 7.5-7.5 7.5-4.1421 0-7.5-3.3579-7.5-7.5 0-2.2212 0.96563-4.217 2.5-5.5903v-1.9097c0-2.7614 2.2386-5 5-5 2.7614 0 5 2.2386 5 5zm-8.4375-1.0774c1.0298-0.53198 2.1985-0.83239 3.4375-0.83239s2.4078 0.30041 3.4375 0.83239v-0.83239c0-1.8985-1.539-3.4375-3.4375-3.4375s-3.4375 1.539-3.4375 3.4375zm9.6875 6.6676c0 3.4518-2.7982 6.25-6.25 6.25-3.4518 0-6.25-2.7982-6.25-6.25s2.7982-6.25 6.25-6.25c3.4518 0 6.25 2.7982 6.25 6.25z" /> +</vector>