Skip to content
Snippets Groups Projects
Unverified Commit 38a51d2b authored by Alex Catarineu's avatar Alex Catarineu Committed by boklm
Browse files

Bug 40015: Port padlock states for .onion services

parent e7ee2512
No related branches found
No related tags found
1 merge request!69Rebase android-components patches to v91.0.8
Showing with 43 additions and 1 deletion
......@@ -499,6 +499,7 @@ class DisplayToolbar internal constructor(
@ColorInt val color = when (siteSecurity) {
Toolbar.SiteSecurity.INSECURE -> colors.securityIconInsecure
Toolbar.SiteSecurity.SECURE -> colors.securityIconSecure
Toolbar.SiteSecurity.ONION -> colors.securityIconSecure
}
if (color == Color.TRANSPARENT) {
views.securityIndicator.clearColorFilter()
......
......@@ -43,6 +43,11 @@ internal class SiteSecurityIconView @JvmOverloads constructor(
View.mergeDrawableStates(drawableState, intArrayOf(R.attr.state_site_secure))
drawableState
}
SiteSecurity.ONION -> {
val drawableState = super.onCreateDrawableState(extraSpace + 1)
View.mergeDrawableStates(drawableState, intArrayOf(R.attr.state_site_onion))
drawableState
}
}
}
}
......@@ -3,6 +3,9 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- 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_lock"
ac:state_site_secure="true" />
......
......@@ -27,6 +27,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>
......
......@@ -414,6 +414,7 @@ interface Toolbar {
enum class SiteSecurity {
INSECURE,
SECURE,
ONION,
}
/**
......
......@@ -18,6 +18,7 @@ import mozilla.components.concept.toolbar.Toolbar.Highlight
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.isOnionUrl
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
/**
......@@ -65,7 +66,11 @@ class ToolbarPresenter(
toolbar.displayProgress(tab.content.progress)
toolbar.siteSecure = if (tab.content.securityInfo.secure) {
Toolbar.SiteSecurity.SECURE
if (tab.content.url.isOnionUrl()) {
Toolbar.SiteSecurity.ONION
} else {
Toolbar.SiteSecurity.SECURE
}
} else {
Toolbar.SiteSecurity.INSECURE
}
......
......@@ -113,6 +113,15 @@ fun String.tryGetHostFromUrl(): String = try {
this
}
/**
* 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.
......
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="m12.0215,20.5903c0,0 0,-1.2728 0,-1.2728 4.0319,-0.0117 7.2965,-3.283 7.2965,-7.3177 0,-4.0345 -3.2646,-7.3058 -7.2965,-7.3175 0,0 0,-1.2728 0,-1.2728 4.7348,0.0119 8.5691,3.8529 8.5691,8.5903 0,4.7377 -3.8342,8.5789 -8.5691,8.5906 0,0 0,0 0,0m0,-4.4551c2.2741,-0.012 4.1148,-1.8582 4.1148,-4.1355 0,-2.277 -1.8407,-4.1233 -4.1148,-4.1352 0,0 0,-1.2726 0,-1.2726 2.9773,0.0116 5.3877,2.4278 5.3877,5.4078 0,2.9802 -2.4103,5.3964 -5.3877,5.408 0,0 0,-1.2725 0,-1.2725m0,-6.3616c1.2199,0.0116 2.2057,1.0033 2.2057,2.2261 0,1.2231 -0.9858,2.2147 -2.2057,2.2264 0,0 0,-4.4525 0,-4.4525M1.5,11.9997C1.5,17.799 6.2008,22.5 12,22.5 17.799,22.5 22.5,17.799 22.5,11.9997 22.5,6.2008 17.799,1.5 12,1.5 6.2008,1.5 1.5,6.2008 1.5,11.9997c0,0 0,0 0,0"
android:strokeWidth="1.49999"
android:fillColor="@color/mozac_ui_icons_fill"/>
</vector>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment