Skip to content

Commit 6352721

Browse files
authored
fix: remove do you want to download file.bin alert on iOS cp-7.61.0 (#23383)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Remove "do you want to download file.bin" alert on iOS PR for react-native-webview-mm: MetaMask/react-native-webview-mm#74 ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: Fixed a bug where we prompt do you want to download file.bin alert ## **Related issues** Fixes: #20359 ## **Manual testing steps** ```gherkin Feature: remove do you want to download file.bin alert Scenario: user not seeing the alert Given user navigates to browser tab When user navigates to sites like https://adtech.org/metamask-iframe-example/ Then user should not see an alert that says "do you want to download file.bin" ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <img width="211" height="458" alt="Screenshot 2025-11-27 at 12 31 40 PM" src="https://github.com/user-attachments/assets/0bfbd86f-1196-4320-b6f8-2dd499349437" /> ### **After** Not showing the alert ![iOS after](https://github.com/user-attachments/assets/8b55ad4c-acf6-4de8-a303-215219d1b191) Can still download files ![downloads](https://github.com/user-attachments/assets/9c722df1-e6e6-4905-898c-e1775dce6915) ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] 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. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Suppresses the iOS "download File.bin" alert for data URLs and consolidates Android WebView permission handling into a single dialog with safer granting/cleanup. > > - **iOS (RNCWebViewImpl)**: > - Suppress downloads for `application/octet-stream` data URLs by inferring extension early and ignoring `.bin`, preventing the "Do you want to download File.bin" alert. > - Minor refactor: compute `fileExtension` before decoding and reuse it. > - **Android (RNCWebChromeClient)**: > - Rework permission flow: reset state, aggregate multiple permissions into a single user prompt, map OS permissions to WebView resources, and grant immediately when possible. > - Add robust state cleanup and try/catch around `grant` to avoid IllegalStateException; handle negative responses and pending system permission requests correctly. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 59d75e8. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent d682ccc commit 6352721

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.yarn/patches/@metamask-react-native-webview-npm-14.5.0-b34fed6d50.patch

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,29 @@ index d1459423fe85502017d2b424f61718ce1ae082b1..7fda7cf056af3e7e8904a0e2aa3391dc
152152
}
153153

154154
if (!pendingPermissions.isEmpty()) {
155+
diff --git a/apple/RNCWebViewImpl.m b/apple/RNCWebViewImpl.m
156+
index c3bb7cc41097a39964b56386dbde321f7d52b35a..ebbb771d6bba6182e03f3c96ae8c9ab6514bd4f9 100644
157+
--- a/apple/RNCWebViewImpl.m
158+
+++ b/apple/RNCWebViewImpl.m
159+
@@ -973,11 +973,20 @@ -(void)setKeyboardDisplayRequiresUserAction:(BOOL)keyboardDisplayRequiresUserAct
160+
}
161+
162+
- (void)downloadBase64File:(NSString *)base64String {
163+
+ // Infer file extension from the data: URL before doing any heavy work.
164+
+ // For generic application/octet-stream payloads we suppress the download
165+
+ // entirely (no "Do you want to download File.bin?" alert), since these
166+
+ // are typically iframe-driven noise rather than user‑initiated downloads.
167+
+ NSString *fileExtension = [self fileExtensionFromBase64String:base64String];
168+
+ if ([[fileExtension lowercaseString] isEqualToString:@"bin"]) {
169+
+ NSLog(@"RNCWebViewImpl: Ignoring generic binary download (File.bin) from data: URL");
170+
+ return;
171+
+ }
172+
+
173+
NSArray *components = [base64String componentsSeparatedByString:@","];
174+
NSString *base64ContentPart = components.lastObject;
175+
176+
NSData *fileData = [[NSData alloc] initWithBase64EncodedString:base64ContentPart options:NSDataBase64DecodingIgnoreUnknownCharacters];
177+
- NSString *fileExtension = [self fileExtensionFromBase64String:base64String];
178+
[self showDownloadAlert:fileExtension invokeDownload:^{
179+
NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"File.%@", fileExtension]];
180+
[fileData writeToFile:tempFilePath atomically:YES];

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9357,14 +9357,14 @@ __metadata:
93579357

93589358
"@metamask/react-native-webview@patch:@metamask/react-native-webview@npm%3A14.5.0#~/.yarn/patches/@metamask-react-native-webview-npm-14.5.0-b34fed6d50.patch":
93599359
version: 14.5.0
9360-
resolution: "@metamask/react-native-webview@patch:@metamask/react-native-webview@npm%3A14.5.0#~/.yarn/patches/@metamask-react-native-webview-npm-14.5.0-b34fed6d50.patch::version=14.5.0&hash=c64f43"
9360+
resolution: "@metamask/react-native-webview@patch:@metamask/react-native-webview@npm%3A14.5.0#~/.yarn/patches/@metamask-react-native-webview-npm-14.5.0-b34fed6d50.patch::version=14.5.0&hash=c6e87d"
93619361
dependencies:
93629362
escape-string-regexp: "npm:^4.0.0"
93639363
invariant: "npm:2.2.4"
93649364
peerDependencies:
93659365
react: "*"
93669366
react-native: "*"
9367-
checksum: 10/ea801ba7e33c39df045bbe6dd882792b96b89f32b391c7a46c1a2878a5987f275549682b308c7014fba46fc07d1c5605b0499c0425d21076c98f65bb4bb56b05
9367+
checksum: 10/f22bae5e15763e77ec0e21f34b31d97a48fadb35590a5e75341c93b269cbdb702fcafb4bd7d4b9041977ca525b03b49b558a3800126faadf08e64b8787fb1cb3
93689368
languageName: node
93699369
linkType: hard
93709370

0 commit comments

Comments
 (0)