From 35992d2c79ec56ecf9b13698d04343dce7243d5e Mon Sep 17 00:00:00 2001 From: sethkfman <10342624+sethkfman@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:29:46 -0600 Subject: [PATCH] fix(browser): added remaining fields in WebSourceResponse patch (#6479) * added remaining fields in WebSourceResposne patch * updated patch to provide reasonPhrase if empty * updated to remove build code --------- Co-authored-by: Cal Leung --- patches/react-native-webview+11.13.0.patch | 83 ++++++++++++---------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/patches/react-native-webview+11.13.0.patch b/patches/react-native-webview+11.13.0.patch index 311d1734e94..a2aabc78601 100644 --- a/patches/react-native-webview+11.13.0.patch +++ b/patches/react-native-webview+11.13.0.patch @@ -83,7 +83,7 @@ index 0000000..f4a6af9 + } +} diff --git a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java -index f743bbc..ede5475 100644 +index f743bbc..406a7d4 100644 --- a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -5,6 +5,7 @@ import android.annotation.TargetApi; @@ -128,7 +128,7 @@ index f743bbc..ede5475 100644 import android.widget.FrameLayout; import androidx.annotation.Nullable; -@@ -88,18 +96,54 @@ import com.reactnativecommunity.webview.events.TopRenderProcessGoneEvent; +@@ -88,18 +96,55 @@ import com.reactnativecommunity.webview.events.TopRenderProcessGoneEvent; import org.json.JSONException; import org.json.JSONObject; @@ -162,6 +162,7 @@ index f743bbc..ede5475 100644 +import java.util.Set; import java.util.concurrent.atomic.AtomicReference; ++import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; @@ -183,7 +184,7 @@ index f743bbc..ede5475 100644 /** * Manages instances of {@link WebView} *

-@@ -137,13 +181,19 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -137,13 +182,19 @@ public class RNCWebViewManager extends SimpleViewManager { public static final int COMMAND_LOAD_URL = 7; public static final int COMMAND_FOCUS = 8; @@ -204,7 +205,7 @@ index f743bbc..ede5475 100644 protected static final String HTML_MIME_TYPE = "text/html"; protected static final String JAVASCRIPT_INTERFACE = "ReactNativeWebView"; protected static final String HTTP_METHOD_POST = "POST"; -@@ -155,13 +205,19 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -155,13 +206,19 @@ public class RNCWebViewManager extends SimpleViewManager { protected RNCWebChromeClient mWebChromeClient = null; protected boolean mAllowsFullscreenVideo = false; @@ -229,7 +230,7 @@ index f743bbc..ede5475 100644 }; } -@@ -182,6 +238,7 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -182,6 +239,7 @@ public class RNCWebViewManager extends SimpleViewManager { @TargetApi(Build.VERSION_CODES.LOLLIPOP) protected WebView createViewInstance(ThemedReactContext reactContext) { RNCWebView webView = createRNCWebViewInstance(reactContext); @@ -237,7 +238,7 @@ index f743bbc..ede5475 100644 setupWebChromeClient(reactContext, webView); reactContext.addLifecycleEventListener(webView); mWebViewConfig.configWebView(webView); -@@ -209,47 +266,161 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -209,47 +267,171 @@ public class RNCWebViewManager extends SimpleViewManager { } webView.setDownloadListener(new DownloadListener() { @@ -415,7 +416,17 @@ index f743bbc..ede5475 100644 + is = new InputStreamWithInjectedJS(is, reactWebView.injectedJSBeforeContentLoaded, charset); + } + -+ return new WebResourceResponse("text/html", charset.name(), is); ++ Headers headers = response.headers(); ++ Map headerMap = new HashMap(); ++ for (String headerName : headers.names()) { ++ String headerValue = headers.get(headerName); ++ headerMap.put(headerName, headerValue); ++ } ++ ++ //Response message is generally empty but response is valid. Populate a string of the response code if nothing exists ++ String reasonPhrase = response.message().isEmpty() ? Integer.toString(response.code()) : response.message(); ++ ++ return new WebResourceResponse("text/html", charset.name(), response.code(), reasonPhrase, headerMap, is); + } catch (IOException e) { + return null; + } @@ -424,7 +435,7 @@ index f743bbc..ede5475 100644 @ReactProp(name = "javaScriptEnabled") public void setJavaScriptEnabled(WebView view, boolean enabled) { view.getSettings().setJavaScriptEnabled(enabled); -@@ -285,13 +456,10 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -285,13 +467,10 @@ public class RNCWebViewManager extends SimpleViewManager { if (enabled) { Context ctx = view.getContext(); if (ctx != null) { @@ -438,7 +449,7 @@ index f743bbc..ede5475 100644 } } -@@ -327,12 +495,12 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -327,12 +506,12 @@ public class RNCWebViewManager extends SimpleViewManager { public void setLayerType(WebView view, String layerTypeString) { int layerType = View.LAYER_TYPE_NONE; switch (layerTypeString) { @@ -457,7 +468,7 @@ index f743bbc..ede5475 100644 } view.setLayerType(layerType, null); } -@@ -387,9 +555,9 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -387,9 +566,9 @@ public class RNCWebViewManager extends SimpleViewManager { @ReactProp(name = "userAgent") public void setUserAgent(WebView view, @Nullable String userAgent) { if (userAgent != null) { @@ -469,7 +480,7 @@ index f743bbc..ede5475 100644 } this.setUserAgentString(view); } -@@ -399,19 +567,19 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -399,19 +578,19 @@ public class RNCWebViewManager extends SimpleViewManager { if(applicationName != null) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { String defaultUserAgent = WebSettings.getDefaultUserAgent(view.getContext()); @@ -495,7 +506,7 @@ index f743bbc..ede5475 100644 } else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // handle unsets of `userAgent` prop as long as device is >= API 17 view.getSettings().setUserAgentString(WebSettings.getDefaultUserAgent(view.getContext())); -@@ -490,7 +658,6 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -490,7 +669,6 @@ public class RNCWebViewManager extends SimpleViewManager { // Disable caching view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); @@ -503,7 +514,7 @@ index f743bbc..ede5475 100644 view.clearHistory(); view.clearCache(true); -@@ -842,13 +1009,116 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -842,13 +1020,116 @@ public class RNCWebViewManager extends SimpleViewManager { } } @@ -588,7 +599,7 @@ index f743bbc..ede5475 100644 + return nextByte; + } + } -+ + + if (!headWasFound) { + int nextByte = pageIS.read(); + contentBuffer.append((char) nextByte); @@ -609,7 +620,7 @@ index f743bbc..ede5475 100644 + } + + protected class RNCWebViewClient extends WebViewClient { - ++ + protected static final String REACT_CLASS = "RNCWebViewClient"; protected boolean mLastLoadFailed = false; protected @Nullable @@ -621,7 +632,7 @@ index f743bbc..ede5475 100644 public void setIgnoreErrFailedForThisURL(@Nullable String url) { ignoreErrFailedForThisURL = url; -@@ -857,24 +1127,26 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -857,24 +1138,26 @@ public class RNCWebViewManager extends SimpleViewManager { @Override public void onPageFinished(WebView webView, String url) { super.onPageFinished(webView, url); @@ -653,7 +664,7 @@ index f743bbc..ede5475 100644 ((RNCWebView) webView).dispatchEvent( webView, new TopLoadingStartEvent( -@@ -882,6 +1154,20 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -882,6 +1165,20 @@ public class RNCWebViewManager extends SimpleViewManager { createWebViewEvent(webView, url))); } @@ -674,7 +685,7 @@ index f743bbc..ede5475 100644 @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { final RNCWebView rncWebView = (RNCWebView) view; -@@ -891,7 +1177,6 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -891,7 +1188,6 @@ public class RNCWebViewManager extends SimpleViewManager { final Pair> lock = RNCWebViewModule.shouldOverrideUrlLoadingLock.getNewLock(); final int lockIdentifier = lock.first; final AtomicReference lockObject = lock.second; @@ -682,7 +693,7 @@ index f743bbc..ede5475 100644 final WritableMap event = createWebViewEvent(view, url); event.putInt("lockIdentifier", lockIdentifier); rncWebView.sendDirectMessage("onShouldStartLoadWithRequest", event); -@@ -919,6 +1204,17 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -919,6 +1215,17 @@ public class RNCWebViewManager extends SimpleViewManager { RNCWebViewModule.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier); return shouldOverride; @@ -700,7 +711,7 @@ index f743bbc..ede5475 100644 } else { FLog.w(TAG, "Couldn't use blocking synchronous call for onShouldStartLoadWithRequest due to debugging or missing Catalyst instance, falling back to old event-and-load."); progressChangedFilter.setWaitingForCommandLoadUrl(true); -@@ -934,67 +1230,86 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -934,67 +1241,86 @@ public class RNCWebViewManager extends SimpleViewManager { @TargetApi(Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { @@ -795,7 +806,8 @@ index f743bbc..ede5475 100644 + int code = error.getPrimaryError(); + String description = ""; + String descriptionPrefix = "SSL error: "; -+ + +- description = descriptionPrefix + description; + // https://developer.android.com/reference/android/net/http/SslError.html + switch (code) { + case SslError.SSL_DATE_INVALID: @@ -821,15 +833,14 @@ index f743bbc..ede5475 100644 + break; + } -- description = descriptionPrefix + description; -+ description = descriptionPrefix + description; - - this.onReceivedError( - webView, - code, - description, - failingUrl - ); ++ description = descriptionPrefix + description; ++ + this.onReceivedError( + webView, + code, @@ -839,7 +850,7 @@ index f743bbc..ede5475 100644 } @Override -@@ -1005,9 +1320,9 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1005,9 +1331,9 @@ public class RNCWebViewManager extends SimpleViewManager { String failingUrl) { if (ignoreErrFailedForThisURL != null @@ -852,7 +863,7 @@ index f743bbc..ede5475 100644 // This is a workaround for a bug in the WebView. // See these chromium issues for more context: -@@ -1056,36 +1371,36 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1056,36 +1382,36 @@ public class RNCWebViewManager extends SimpleViewManager { @TargetApi(Build.VERSION_CODES.O) @Override public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail detail) { @@ -913,7 +924,7 @@ index f743bbc..ede5475 100644 } protected void emitFinishEvent(WebView webView, String url) { -@@ -1138,6 +1453,7 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1138,6 +1464,7 @@ public class RNCWebViewManager extends SimpleViewManager { protected View mVideoView; protected WebChromeClient.CustomViewCallback mCustomViewCallback; @@ -921,7 +932,7 @@ index f743bbc..ede5475 100644 /* * - Permissions - -@@ -1217,19 +1533,44 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1217,19 +1544,44 @@ public class RNCWebViewManager extends SimpleViewManager { ArrayList requestedAndroidPermissions = new ArrayList<>(); for (String requestedResource : request.getResources()) { String androidPermission = null; @@ -967,7 +978,7 @@ index f743bbc..ede5475 100644 } else { requestedAndroidPermissions.add(androidPermission); } -@@ -1238,8 +1579,11 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1238,8 +1590,11 @@ public class RNCWebViewManager extends SimpleViewManager { // If all the permissions are already granted, send the response to the WebView synchronously if (requestedAndroidPermissions.isEmpty()) { @@ -981,7 +992,7 @@ index f743bbc..ede5475 100644 return; } -@@ -1250,6 +1594,10 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1250,6 +1605,10 @@ public class RNCWebViewManager extends SimpleViewManager { requestPermissions(requestedAndroidPermissions); } @@ -992,7 +1003,7 @@ index f743bbc..ede5475 100644 @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { -@@ -1402,6 +1750,15 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1402,6 +1761,15 @@ public class RNCWebViewManager extends SimpleViewManager { } } @@ -1008,7 +1019,7 @@ index f743bbc..ede5475 100644 @Override public void onHostPause() { } -@@ -1447,6 +1804,13 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1447,6 +1815,13 @@ public class RNCWebViewManager extends SimpleViewManager { protected boolean nestedScrollEnabled = false; protected ProgressChangedFilter progressChangedFilter; @@ -1022,7 +1033,7 @@ index f743bbc..ede5475 100644 /** * WebView must be created with an context of the current activity *

-@@ -1475,6 +1839,42 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1475,6 +1850,42 @@ public class RNCWebViewManager extends SimpleViewManager { this.nestedScrollEnabled = nestedScrollEnabled; } @@ -1065,7 +1076,7 @@ index f743bbc..ede5475 100644 @Override public void onHostResume() { // do nothing -@@ -1533,6 +1933,8 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1533,6 +1944,8 @@ public class RNCWebViewManager extends SimpleViewManager { } } @@ -1074,7 +1085,7 @@ index f743bbc..ede5475 100644 public @Nullable RNCWebViewClient getRNCWebViewClient() { return mRNCWebViewClient; -@@ -1609,8 +2011,8 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1609,8 +2022,8 @@ public class RNCWebViewManager extends SimpleViewManager { public void callInjectedJavaScriptBeforeContentLoaded() { if (getSettings().getJavaScriptEnabled() && @@ -1085,7 +1096,7 @@ index f743bbc..ede5475 100644 evaluateJavascriptWithFallback("(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();"); } } -@@ -1672,16 +2074,16 @@ public class RNCWebViewManager extends SimpleViewManager { +@@ -1672,16 +2085,16 @@ public class RNCWebViewManager extends SimpleViewManager { if (mOnScrollDispatchHelper.onScrollChanged(x, y)) { ScrollEvent event = ScrollEvent.obtain(