Unverified Commit b9984e10 authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Merge remote-tracking branch 'acatgl/34377' into android-components-57.0.6-10.0-2

parents abf37979 81be6dd2
......@@ -476,6 +476,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>
......
......@@ -385,6 +385,7 @@ interface Toolbar {
enum class SiteSecurity {
INSECURE,
SECURE,
ONION,
}
/**
......
......@@ -16,6 +16,7 @@ import mozilla.components.concept.toolbar.Toolbar
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
/**
......@@ -64,7 +65,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
}
......
......@@ -115,6 +115,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>
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