Skip to content

Commit 05f8a45

Browse files
committed
🔒 Add contextual identity
1 parent 961cf36 commit 05f8a45

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

‎.idea/misc.xml‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/src/main/java/co/dothq/browser/BrowserActivity.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class BrowserActivity : AppCompatActivity() {
4141
session.open(runtime)
4242
view.setSession(session)
4343
session.navigationDelegate = BrowserDelegates().createNavigationDelegate("main", this, applicationContext);
44+
session.progressDelegate = BrowserDelegates().createProgressDelegate("main", this, applicationContext);
45+
4446

4547
val addressBar = findViewById<LinearLayout>(R.id.addressBarContainer);
4648

‎app/src/main/java/co/dothq/browser/BrowserDelegates.kt‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,45 @@ package co.dothq.browser
22

33
import android.app.Activity
44
import android.content.Context
5+
import android.graphics.drawable.Drawable
6+
import android.widget.ImageView
57
import android.widget.TextView
8+
import android.widget.Toast
9+
import androidx.core.content.ContextCompat
610
import co.dothq.browser.managers.StorageManager
711
import org.mozilla.geckoview.AllowOrDeny
812
import org.mozilla.geckoview.GeckoResult
913
import org.mozilla.geckoview.GeckoSession
1014

1115
class BrowserDelegates {
16+
fun createProgressDelegate(area: String, context: Context, applicationCtx: Context): GeckoSession.ProgressDelegate {
17+
return object : GeckoSession.ProgressDelegate {
18+
19+
override fun onPageStop(session: GeckoSession, success: Boolean) = Unit
20+
21+
override fun onSecurityChange(session: GeckoSession, securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) {
22+
23+
if (area == "main") {
24+
val activity: Activity = (context as Activity)
25+
val contextualIdIcon = activity.findViewById<ImageView>(R.id.contextIdentityIcon);
26+
27+
if (securityInfo.isSecure) contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_secure_filled))
28+
if (!securityInfo.isSecure) contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_unsecure_filled))
29+
Toast.makeText(context, securityInfo.securityMode.toString(), Toast.LENGTH_LONG).show()
30+
}
31+
}
32+
33+
override fun onPageStart(session: GeckoSession, url: String) {
34+
35+
}
36+
37+
38+
override fun onProgressChange(session: GeckoSession, progress: Int) {
39+
40+
}
41+
}
42+
}
43+
1244
public fun createNavigationDelegate(area: String, context: Context, applicationCtx: Context): GeckoSession.NavigationDelegate {
1345
return object : GeckoSession.NavigationDelegate {
1446

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="16dp"
4+
android:viewportWidth="16"
5+
android:viewportHeight="16">
6+
<path
7+
android:pathData="M1,15L15,1"
8+
android:strokeLineJoin="round"
9+
android:strokeWidth="2"
10+
android:fillColor="#00000000"
11+
android:strokeColor="#FF4752"
12+
android:strokeLineCap="round"/>
13+
<path
14+
android:pathData="M13.8764,5.6591C14.5615,6.2089 15,7.0533 15,8V13C15,14.6569 13.6569,16 12,16H4C3.8528,16 3.7081,15.9894 3.5666,15.9689L13.8764,5.6591ZM1,11.4645V8C1,6.4273 2.2102,5.1373 3.7501,5.0103C3.8877,4.9989 4,4.8881 4,4.75V4C4,1.7909 5.7909,0 8,0C9.2228,0 10.3174,0.5487 11.0512,1.4133L9.6274,2.8371C9.2645,2.3303 8.6708,2 8,2C6.8954,2 6,2.8954 6,4V4.75C6,4.8881 6.1119,5 6.25,5H7.4645L1,11.4645Z"
15+
android:fillColor="#000000"
16+
android:fillType="evenOdd"/>
17+
</vector>

‎app/src/main/res/layout/activity_main.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
android:orientation="vertical">
4040

4141
<ImageView
42-
android:id="@+id/websiteSecurityIdentifier"
42+
android:id="@+id/contextIdentityIcon"
4343
android:layout_width="14dp"
4444
android:layout_height="wrap_content"
4545
android:layout_gravity="center"

0 commit comments

Comments
 (0)