Skip to content

Commit

Permalink
fix: update webview to grant location (#8840)
Browse files Browse the repository at this point in the history
## **Description**

More info here: #MetaMask/mobile-planning#1482

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
tommasini committed Mar 5, 2024
1 parent d669eb3 commit a1358ce
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions patches/react-native-webview+11.13.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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..06d172f 100644
index f743bbc..b520532 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;
Expand Down Expand Up @@ -1022,7 +1022,31 @@ index f743bbc..06d172f 100644

@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
@@ -1402,6 +1756,15 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1266,7 +1620,22 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
requestPermissions(Collections.singletonList(Manifest.permission.ACCESS_FINE_LOCATION));

} else {
- callback.invoke(origin, true, false);
+ String alertMessage = String.format("Allow this app to use your location?");
+ AlertDialog.Builder builder = new AlertDialog.Builder(this.mWebView.getContext());
+ builder.setMessage(alertMessage);
+ builder.setCancelable(false);
+ builder.setPositiveButton("Allow", (dialog, which) -> {
+ callback.invoke(origin, true, false);
+ });
+ builder.setNegativeButton("Don't allow", (dialog, which) -> {
+ callback.invoke(origin, false, false);
+ });
+ AlertDialog alertDialog = builder.create();
+ alertDialog.show();
+ //Delay making `allow` clickable for 500ms to avoid unwanted presses.
+ Button posButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+ posButton.setEnabled(false);
+ this.runDelayed(() -> posButton.setEnabled(true), 500);
}
}

@@ -1402,6 +1771,15 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
}
}

Expand All @@ -1038,7 +1062,7 @@ index f743bbc..06d172f 100644
@Override
public void onHostPause() { }

@@ -1447,6 +1810,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1447,6 +1825,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
protected boolean nestedScrollEnabled = false;
protected ProgressChangedFilter progressChangedFilter;

Expand All @@ -1052,7 +1076,7 @@ index f743bbc..06d172f 100644
/**
* WebView must be created with an context of the current activity
* <p>
@@ -1475,6 +1845,42 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1475,6 +1860,42 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
this.nestedScrollEnabled = nestedScrollEnabled;
}

Expand Down Expand Up @@ -1095,7 +1119,7 @@ index f743bbc..06d172f 100644
@Override
public void onHostResume() {
// do nothing
@@ -1533,6 +1939,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1533,6 +1954,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
}
}

Expand All @@ -1104,7 +1128,7 @@ index f743bbc..06d172f 100644
public @Nullable
RNCWebViewClient getRNCWebViewClient() {
return mRNCWebViewClient;
@@ -1609,8 +2017,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1609,8 +2032,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {

public void callInjectedJavaScriptBeforeContentLoaded() {
if (getSettings().getJavaScriptEnabled() &&
Expand All @@ -1115,7 +1139,7 @@ index f743bbc..06d172f 100644
evaluateJavascriptWithFallback("(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();");
}
}
@@ -1672,16 +2080,16 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1672,16 +2095,16 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {

if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
ScrollEvent event = ScrollEvent.obtain(
Expand Down Expand Up @@ -1174,39 +1198,39 @@ diff --git a/node_modules/react-native-webview/apple/RNCWebView.m b/node_modules
index 28c078a..9bb5368 100644
--- a/node_modules/react-native-webview/apple/RNCWebView.m
+++ b/node_modules/react-native-webview/apple/RNCWebView.m
@@ -105,6 +105,7 @@ @implementation RNCWebView
@@ -105,6 +105,7 @@ static NSDictionary* customCertificatesForHost;
UIStatusBarStyle _savedStatusBarStyle;
#endif // !TARGET_OS_OSX
BOOL _savedStatusBarHidden;
+ BOOL _disablePromptDuringLoading; //Disables the display of prompts during site navigation/loading

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
UIScrollViewContentInsetAdjustmentBehavior _savedContentInsetAdjustmentBehavior;
@@ -139,6 +140,7 @@ - (instancetype)initWithFrame:(CGRect)frame
@@ -139,6 +140,7 @@ static NSDictionary* customCertificatesForHost;
_injectedJavaScriptForMainFrameOnly = YES;
_injectedJavaScriptBeforeContentLoaded = nil;
_injectedJavaScriptBeforeContentLoadedForMainFrameOnly = YES;
+ _disablePromptDuringLoading = YES;

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
_savedContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
@@ -417,6 +419,7 @@ -(void)keyboardDisplacementFix
@@ -417,6 +419,7 @@ static NSDictionary* customCertificatesForHost;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
if ([keyPath isEqual:@"estimatedProgress"] && object == self.webView) {
if(_onLoadingProgress){
+ _disablePromptDuringLoading = YES;
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
[event addEntriesFromDictionary:@{@"progress":[NSNumber numberWithDouble:self.webView.estimatedProgress]}];
_onLoadingProgress(event);
@@ -492,6 +495,7 @@ - (void)userContentController:(WKUserContentController *)userContentController
@@ -492,6 +495,7 @@ static NSDictionary* customCertificatesForHost;
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
[event addEntriesFromDictionary: @{@"navigationType": message.body}];
_onLoadingFinish(event);
+ _disablePromptDuringLoading = NO;
}
} else if ([message.name isEqualToString:MessageHandlerName]) {
if (_onMessage) {
@@ -851,11 +855,13 @@ - (void) webView:(WKWebView *)webView
@@ -851,11 +855,13 @@ static NSDictionary* customCertificatesForHost;
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
{
#if !TARGET_OS_OSX
Expand All @@ -1225,7 +1249,7 @@ index 28c078a..9bb5368 100644
#else
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:message];
@@ -868,6 +874,51 @@ - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSStrin
@@ -868,6 +874,51 @@ static NSDictionary* customCertificatesForHost;
/**
* confirm
*/
Expand Down Expand Up @@ -1277,7 +1301,7 @@ index 28c078a..9bb5368 100644
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler{
#if !TARGET_OS_OSX
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
@@ -894,44 +945,49 @@ - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSStr
@@ -894,44 +945,49 @@ static NSDictionary* customCertificatesForHost;
* prompt
*/
- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *))completionHandler{
Expand Down Expand Up @@ -1362,15 +1386,15 @@ index 28c078a..9bb5368 100644
}

#if !TARGET_OS_OSX
@@ -1157,6 +1213,7 @@ - (void)webView:(WKWebView *)webView
@@ -1157,6 +1213,7 @@ static NSDictionary* customCertificatesForHost;
}

if (_onLoadingFinish) {
+ _disablePromptDuringLoading = NO;
_onLoadingFinish([self baseEvent]);
}
}
@@ -1446,3 +1503,4 @@ - (void)userContentController:(WKUserContentController *)userContentController d
@@ -1446,3 +1503,4 @@ static NSDictionary* customCertificatesForHost;
}

@end
Expand Down

0 comments on commit a1358ce

Please sign in to comment.