Add the Sec-Fetch headers to View Source. https://redmine.stoutner.com/issues/503 master
authorSoren Stoutner <soren@stoutner.com>
Thu, 24 Oct 2019 00:30:10 +0000 (17:30 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 24 Oct 2019 00:30:10 +0000 (17:30 -0700)
app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java
app/src/main/res/layout/view_source_coordinatorlayout.xml

index 2a320c39bdb64f65af7209a64069cfda8d0edfde..30f9aee9e2f4521388c0fd5eb66fe9bacca58df9 100644 (file)
@@ -124,7 +124,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("Host");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  ");
             requestHeadersBuilder.append(url.getHost());
@@ -141,7 +141,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("Connection");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  keep-alive");
 
@@ -157,7 +157,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("Upgrade-Insecure_Requests");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  1");
 
@@ -173,7 +173,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("User-Agent");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  ");
             requestHeadersBuilder.append(userAgent);
@@ -190,11 +190,59 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("x-requested-with");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  ");
 
 
+            // Set the `Sec-Fetch-Site` header property.
+            httpUrlConnection.setRequestProperty("Sec-Fetch-Site", "none");
+
+            // Add the `Sec-Fetch-Site` header to the string builder and format the text.
+            requestHeadersBuilder.append(System.getProperty("line.separator"));
+            if (Build.VERSION.SDK_INT >= 21) {  // Newer versions of Android are so smart.
+                requestHeadersBuilder.append("Sec-Fetch-Site", new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+            } else {  // Older versions not so much.
+                oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
+                requestHeadersBuilder.append("Sec-Fetch-Site");
+                newRequestHeadersBuilderLength = requestHeadersBuilder.length();
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+            }
+            requestHeadersBuilder.append(":  none");
+
+
+            // Set the `Sec-Fetch-Mode` header property.
+            httpUrlConnection.setRequestProperty("Sec-Fetch-Mode", "navigate");
+
+            // Add the `Sec-Fetch-Mode` header to the string builder and format the text.
+            requestHeadersBuilder.append(System.getProperty("line.separator"));
+            if (Build.VERSION.SDK_INT >= 21) {  // Newer versions of Android are so smart.
+                requestHeadersBuilder.append("Sec-Fetch-Mode", new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+            } else {  // Older versions not so much.
+                oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
+                requestHeadersBuilder.append("Sec-Fetch-Mode");
+                newRequestHeadersBuilderLength = requestHeadersBuilder.length();
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+            }
+            requestHeadersBuilder.append(":  navigate");
+
+
+            // Set the `Sec-Fetch-User` header property.
+            httpUrlConnection.setRequestProperty("Sec-Fetch-User", "?1");
+
+            // Add the `Sec-Fetch-User` header to the string builder and format the text.
+            requestHeadersBuilder.append(System.getProperty("line.separator"));
+            if (Build.VERSION.SDK_INT >= 21) {  // Newer versions of Android are so smart.
+                requestHeadersBuilder.append("Sec-Fetch-User", new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+            } else {  // Older versions not so much.
+                oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
+                requestHeadersBuilder.append("Sec-Fetch-User");
+                newRequestHeadersBuilderLength = requestHeadersBuilder.length();
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+            }
+            requestHeadersBuilder.append(":  ?1");
+
+
             // Get a handle for the shared preferences.
             SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
 
@@ -211,7 +259,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                     oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                     requestHeadersBuilder.append("dnt");
                     newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                    requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                    requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                 }
                 requestHeadersBuilder.append(":  1");
             }
@@ -228,7 +276,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("Accept");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  ");
             requestHeadersBuilder.append("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
@@ -306,7 +354,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("Accept-Language");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  ");
             requestHeadersBuilder.append(localeString);
@@ -328,7 +376,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                     oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                     requestHeadersBuilder.append("Cookie");
                     newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                    requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                    requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                 }
                 requestHeadersBuilder.append(":  ");
                 requestHeadersBuilder.append(cookiesString);
@@ -344,7 +392,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                 oldRequestHeadersBuilderLength = requestHeadersBuilder.length();
                 requestHeadersBuilder.append("Accept-Encoding");
                 newRequestHeadersBuilderLength = requestHeadersBuilder.length();
-                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
             requestHeadersBuilder.append(":  gzip");
 
@@ -386,7 +434,7 @@ public class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]>
                         int oldLength = responseHeadersBuilder.length();
                         responseHeadersBuilder.append(httpUrlConnection.getHeaderFieldKey(i));
                         int newLength = responseHeadersBuilder.length();
-                        responseHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldLength + 1, newLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+                        responseHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldLength, newLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                     }
                     responseHeadersBuilder.append(":  ");
                     responseHeadersBuilder.append(httpUrlConnection.getHeaderField(i));
index 03427700289c87c3c36d33072b1a31642053929e..fa1ffd1c3271879577ac0090ea51b554ef1c9ea4 100644 (file)
     android:focusable="true"
     android:focusableInTouchMode="true" >
 
-    <!-- The `LinearLayout` with `orientation="vertical"` moves the content below the app bar layout. -->
+    <!-- The linear layout with `orientation="vertical"` moves the content below the app bar layout. -->
     <LinearLayout
         android:layout_height="match_parent"
         android:layout_width="match_parent"
         android:orientation="vertical" >
 
-        <!-- The `AppBarLayout` theme has to be defined here because the activity uses a `NoActionBar` theme. -->
+        <!-- The app bar layout theme has to be defined here because the activity uses a `NoActionBar` theme. -->
         <com.google.android.material.appbar.AppBarLayout
             android:layout_height="wrap_content"
             android:layout_width="match_parent"
             android:theme="@style/PrivacyBrowserAppBarLight" >
 
-            <!-- The `FrameLayout` allows the toolbar and the progress bar to occupy the same space. -->
+            <!-- The frame layout allows the toolbar and the progress bar to occupy the same space. -->
             <FrameLayout
                 android:layout_height="wrap_content"
                 android:layout_width="match_parent" >