Skip to content
Snippets Groups Projects
Verified Commit ce80a385 authored by Alex Catarineu's avatar Alex Catarineu Committed by Pier Angelo Vendrame
Browse files

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

parent c7e6d9ed
No related branches found
No related tags found
1 merge request!1293Bug 43306: Rebased stable onto 128.5.0esr
Showing
with 62 additions and 1 deletion
......@@ -488,6 +488,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 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
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_24"
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>
......
......@@ -493,6 +493,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 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
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_24"
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>
......
......@@ -488,6 +488,7 @@ interface Toolbar : ScrollableToolbar {
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
/**
* Presenter implementation for a toolbar implementation in order to update the toolbar whenever
......@@ -69,7 +70,11 @@ class ToolbarPresenter(
toolbar.displayProgress(tab.content.progress)
toolbar.siteSecure = if (tab.content.securityInfo.secure) {
if (tab.content.url.isOnionUrl()) {
Toolbar.SiteSecurity.ONION
} else {
Toolbar.SiteSecurity.SECURE
}
} else {
Toolbar.SiteSecurity.INSECURE
}
......
......@@ -245,6 +245,15 @@ fun String.urlContainsQueryParameters(searchParameters: String): Boolean = try {
false
}
/**
* 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"?>
<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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment