Skip to content

Commit

Permalink
feat(iOS): fraudulent website warning setting (previously react-nativ…
Browse files Browse the repository at this point in the history
…e-webview#2801) (react-native-webview#2994)

* feat: fraudulentWebsiteWarningEnabled
* chore: test new arch on CI

# Conflicts:
#	docs/Reference.md

* fix: missing type

* feat: add ios13 check

* Update src/WebViewTypes.ts

Co-authored-by: Caleb Clarke <TheAlmightyBob@users.noreply.github.com>

* Update docs/Reference.md

Co-authored-by: Caleb Clarke <TheAlmightyBob@users.noreply.github.com>

* implem adaptation

* Update ios-ci.yml

* Update ios-ci.yml

* Update android-ci.yml

* Update ios-ci.yml

* fix android new arch

* Update ios-ci.yml

---------

Co-authored-by: sunnylqm <sunnylqm@gmail.com>
Co-authored-by: Caleb Clarke <TheAlmightyBob@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 10, 2023
1 parent 9e86156 commit 6d185e6
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 20 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,28 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
newArchEnabled: [false, true]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v2.5.1
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
cache: 'yarn'
- name: Set up JDK
uses: actions/setup-java@v2.5.0
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
- name: Cache /node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Install npm dependencies
run: yarn --frozen-lockfile
shell: bash
- name: Build Android test app
uses: gradle/gradle-build-action@v2.1.3
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: --no-daemon clean build check test
arguments: -PnewArchEnabled=${{matrix.newArchEnabled}} --no-daemon clean build check test
build-root-directory: example/android
timeout-minutes: 60
17 changes: 8 additions & 9 deletions .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ on:
pull_request:
jobs:
build:
strategy:
matrix:
extraEnv: [FOO=BAR, RCT_NEW_ARCH_ENABLED=1]
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v2.5.1
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache /node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
node-version: 18
cache: 'yarn'
- name: Install npm dependencies
run: yarn --frozen-lockfile
- name: Install Pods
run: pod install
run: ${{matrix.extraEnv}} pod install
working-directory: example/ios
- name: Build iOS test app
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ public void setHasOnFileDownload(RNCWebView view, boolean value) {}

@Override
public void setMediaCapturePermissionGrantType(RNCWebView view, @Nullable String value) {}

@Override
public void setFraudulentWebsiteWarningEnabled(RNCWebView view, boolean value) {}
/* !iOS PROPS - no implemented here */

@Override
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
REMAP_WEBVIEW_STRING_PROP(allowingReadAccessToURL)

REMAP_WEBVIEW_PROP(messagingEnabled)
REMAP_WEBVIEW_PROP(fraudulentWebsiteWarningEnabled)
REMAP_WEBVIEW_PROP(enableApplePay)
REMAP_WEBVIEW_PROP(pullToRefreshEnabled)
REMAP_WEBVIEW_PROP(bounces)
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebViewImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
@property (nonatomic, assign) WKContentMode contentMode;
@property (nonatomic, assign) BOOL fraudulentWebsiteWarningEnabled;
#endif

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */
Expand Down
8 changes: 8 additions & 0 deletions apple/RNCWebViewImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
prefs.javaScriptEnabled = NO;
_prefsUsed = YES;
}
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
if (@available(iOS 13.0, *)) {
if (!_fraudulentWebsiteWarningEnabled) {
prefs.fraudulentWebsiteWarningEnabled = NO;
_prefsUsed = YES;
}
}
#endif
if (_allowUniversalAccessFromFileURLs) {
[wkWebViewConfig setValue:@TRUE forKey:@"allowUniversalAccessFromFileURLs"];
}
Expand Down
4 changes: 4 additions & 0 deletions apple/RNCWebViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ - (RNCView *)view
RCT_EXPORT_VIEW_PROPERTY(mediaCapturePermissionGrantType, RNCWebViewPermissionGrantType)
#endif

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
RCT_EXPORT_VIEW_PROPERTY(fraudulentWebsiteWarningEnabled, BOOL)
#endif

/**
* Expose methods to enable messaging the webview.
*/
Expand Down
8 changes: 8 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,14 @@ Whether or not the Webview can play media protected by DRM. Default is false.
| ------- | -------- | -------- |
| boolean | No | Android |

### `fraudulentWebsiteWarningEnabled`[](#props-index)

A Boolean value that indicates whether the web view shows warnings for suspected fraudulent content, such as malware or phishing attempts. The default value is `true`. (iOS 13+)

| Type | Required | Default | Platform |
| ------- | -------- | ------- | -------- |
| boolean | No | true | iOS |

### `webviewDebuggingEnabled`[](#props-index)

Whether or not the webview can be debugged remotely using Safari / Chrome.
Expand Down
1 change: 1 addition & 0 deletions src/RNCWebViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export interface NativeProps extends ViewProps {
menuItems?: ReadonlyArray<Readonly<{label: string, key: string}>>;
// Workaround to watch if listener if defined
hasOnFileDownload?: boolean;
fraudulentWebsiteWarningEnabled?: boolean;
// !iOS only

allowFileAccessFromFileURLs?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/WebView.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const useWarnIfChanges = <T extends unknown>(value: T, name: string) => {
}

const WebViewComponent = forwardRef<{}, IOSWebViewProps>(({
fraudulentWebsiteWarningEnabled = true,
javaScriptEnabled = true,
cacheEnabled = true,
originWhitelist = defaultOriginWhitelist,
Expand Down Expand Up @@ -174,6 +175,7 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>(({
<NativeWebView
key="webViewKey"
{...otherProps}
fraudulentWebsiteWarningEnabled={fraudulentWebsiteWarningEnabled}
javaScriptEnabled={javaScriptEnabled}
cacheEnabled={cacheEnabled}
useSharedProcessPool={useSharedProcessPool}
Expand Down
7 changes: 7 additions & 0 deletions src/WebViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,13 @@ export interface IOSWebViewProps extends WebViewSharedProps {
selectedText: string;
}
}) => void;

/**
* A Boolean value that indicates whether the webview shows warnings for suspected
* fraudulent content, such as malware or phishing attempts.
* @platform ios
*/
fraudulentWebsiteWarningEnabled?: boolean;
}

export interface MacOSWebViewProps extends WebViewSharedProps {
Expand Down

0 comments on commit 6d185e6

Please sign in to comment.