From: Soren Stoutner Date: Thu, 24 Oct 2019 00:30:10 +0000 (-0700) Subject: Add the Sec-Fetch headers to View Source. https://redmine.stoutner.com/issues/503 X-Git-Tag: v3.3~6 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=c4856b8be94ffa3f6075969967d61174dcc1a7ee;p=PrivacyBrowserAndroid.git Add the Sec-Fetch headers to View Source. https://redmine.stoutner.com/issues/503 --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java index 2a320c39..30f9aee9 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java @@ -124,7 +124,7 @@ public class GetSource extends AsyncTask 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 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 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 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 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 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 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 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 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 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 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)); diff --git a/app/src/main/res/layout/view_source_coordinatorlayout.xml b/app/src/main/res/layout/view_source_coordinatorlayout.xml index 03427700..fa1ffd1c 100644 --- a/app/src/main/res/layout/view_source_coordinatorlayout.xml +++ b/app/src/main/res/layout/view_source_coordinatorlayout.xml @@ -31,19 +31,19 @@ android:focusable="true" android:focusableInTouchMode="true" > - + - + - +