Skip to content

Commit 34236b0

Browse files
Added ContentBlockerActionType.BLOCK_COOKIES and ContentBlockerActionType.IGNORE_PREVIOUS_RULES for iOS and macOS platforms, Updated ContentBlockerTrigger.urlFilterIsCaseSensitive for Android, Fixed Android ContentBlockerActionType.CSS_DISPLAY_NONE usage
1 parent 92329cd commit 34236b0

File tree

7 files changed

+169
-21
lines changed

7 files changed

+169
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 6.0.0-beta.13
2+
3+
- Added `ContentBlockerActionType.BLOCK_COOKIES` and `ContentBlockerActionType.IGNORE_PREVIOUS_RULES` for iOS and macOS platforms
4+
- Updated `ContentBlockerTrigger.urlFilterIsCaseSensitive` for Android
5+
- Fixed Android `ContentBlockerActionType.CSS_DISPLAY_NONE` usage
6+
17
## 6.0.0-beta.12
28

39
- Removed `willSuppressErrorPage` WebView Android setting in favor of `disableDefaultErrorPage`.

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/content_blocker/ContentBlockerHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import androidx.annotation.Nullable;
99

1010
import com.pichillilorenzo.flutter_inappwebview.webview.in_app_webview.InAppWebView;
11+
import com.pichillilorenzo.flutter_inappwebview.plugin_scripts_js.JavaScriptBridgeJS;
1112
import com.pichillilorenzo.flutter_inappwebview.Util;
1213

1314
import java.io.ByteArrayInputStream;
@@ -150,9 +151,9 @@ public void run() {
150151
final String cssSelector = action.getSelector();
151152
final String jsScript = "(function(d) { " +
152153
" function hide () { " +
153-
" if (!d.getElementById('css-display-none-style')) { " +
154+
" if (!d.getElementById('" + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + "-css-display-none-style')) { " +
154155
" var c = d.createElement('style'); " +
155-
" c.id = 'css-display-none-style'; " +
156+
" c.id = '" + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + "-css-display-none-style'; " +
156157
" c.innerHTML = '" + cssSelector + " { display: none !important; }'; " +
157158
" d.body.appendChild(c); " +
158159
" }" +
@@ -165,7 +166,7 @@ public void run() {
165166
"})(document);";
166167

167168
final Handler handler = new Handler(webView.getWebViewLooper());
168-
handler.post(new Runnable() {
169+
handler.postDelayed(new Runnable() {
169170
@Override
170171
public void run() {
171172
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
@@ -174,7 +175,7 @@ public void run() {
174175
webView.loadUrl("javascript:" + jsScript);
175176
}
176177
}
177-
});
178+
}, 800);
178179
break;
179180

180181
case MAKE_HTTPS:

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/content_blocker/ContentBlockerTrigger.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ public class ContentBlockerTrigger {
2525
public ContentBlockerTrigger(@NonNull String urlFilter, @Nullable Boolean urlFilterIsCaseSensitive, @Nullable List<ContentBlockerTriggerResourceType> resourceType,
2626
@Nullable List<String> ifDomain, @Nullable List<String> unlessDomain, @Nullable List<String> loadType,
2727
@Nullable List<String> ifTopUrl, @Nullable List<String> unlessTopUrl) {
28+
this.urlFilterIsCaseSensitive = urlFilterIsCaseSensitive != null ? urlFilterIsCaseSensitive : false;
29+
2830
this.urlFilter = urlFilter;
29-
this.urlFilterPatternCompiled = Pattern.compile(this.urlFilter);
31+
this.urlFilterPatternCompiled = Pattern.compile(this.urlFilter, this.urlFilterIsCaseSensitive ? 0 : Pattern.CASE_INSENSITIVE);
3032

3133
this.resourceType = resourceType != null ? resourceType : this.resourceType;
32-
this.urlFilterIsCaseSensitive = urlFilterIsCaseSensitive != null ? urlFilterIsCaseSensitive : false;
3334
this.ifDomain = ifDomain != null ? ifDomain : this.ifDomain;
3435
this.unlessDomain = unlessDomain != null ? unlessDomain : this.unlessDomain;
3536
if ((!(this.ifDomain.isEmpty() || this.unlessDomain.isEmpty()) != false))

lib/src/content_blocker.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ class ContentBlockerTrigger {
4949
///- MacOS
5050
List<String> ifFrameUrl;
5151

52-
///A Boolean value. The default value is `false`.
52+
///A Boolean value indicating if the URL matching should be case-sensitive.
53+
///The default value is `false`.
5354
///
5455
///**Supported Platforms/Implementations**:
56+
///- Android native WebView
5557
///- iOS
5658
///- MacOS
5759
bool urlFilterIsCaseSensitive;
5860

59-
///A list of [ContentBlockerTriggerResourceType] representing the resource types (how the browser intends to use the resource) that the rule should match.
61+
///A list of [ContentBlockerTriggerResourceType] representing the resource types
62+
///(how the browser intends to use the resource) that the rule should match.
6063
///If not specified, the rule matches all resource types.
6164
///
6265
///**Supported Platforms/Implementations**:
@@ -66,7 +69,8 @@ class ContentBlockerTrigger {
6669
List<ContentBlockerTriggerResourceType> resourceType;
6770

6871
///A list of strings matched to a URL's domain; limits action to a list of specific domains.
69-
///Values must be lowercase ASCII, or punycode for non-ASCII. Add * in front to match domain and subdomains. Can't be used with [ContentBlockerTrigger.unlessDomain].
72+
///Values must be lowercase ASCII, or punycode for non-ASCII.
73+
///Add * in front to match domain and subdomains. Can't be used with [ContentBlockerTrigger.unlessDomain].
7074
///
7175
///**Supported Platforms/Implementations**:
7276
///- Android native WebView
@@ -75,15 +79,17 @@ class ContentBlockerTrigger {
7579
List<String> ifDomain;
7680

7781
///A list of strings matched to a URL's domain; acts on any site except domains in a provided list.
78-
///Values must be lowercase ASCII, or punycode for non-ASCII. Add * in front to match domain and subdomains. Can't be used with [ContentBlockerTrigger.ifDomain].
82+
///Values must be lowercase ASCII, or punycode for non-ASCII.
83+
///Add * in front to match domain and subdomains. Can't be used with [ContentBlockerTrigger.ifDomain].
7984
///
8085
///**Supported Platforms/Implementations**:
8186
///- Android native WebView
8287
///- iOS
8388
///- MacOS
8489
List<String> unlessDomain;
8590

86-
///A list of [ContentBlockerTriggerLoadType] that can include one of two mutually exclusive values. If not specified, the rule matches all load types.
91+
///A list of [ContentBlockerTriggerLoadType] that can include one of two mutually exclusive values.
92+
///If not specified, the rule matches all load types.
8793
///
8894
///**Supported Platforms/Implementations**:
8995
///- Android native WebView

lib/src/types/content_blocker_action_type.dart

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
23

34
import '../content_blocker.dart';
@@ -9,18 +10,55 @@ part 'content_blocker_action_type.g.dart';
910
class ContentBlockerActionType_ {
1011
// ignore: unused_field
1112
final String _value;
13+
1214
const ContentBlockerActionType_._internal(this._value);
1315

1416
///Stops loading of the resource. If the resource was cached, the cache is ignored.
17+
@EnumSupportedPlatforms(platforms: [
18+
EnumAndroidPlatform(value: 'block'),
19+
EnumIOSPlatform(value: 'block'),
20+
EnumMacOSPlatform(value: 'block')
21+
])
1522
static const BLOCK = const ContentBlockerActionType_._internal('block');
1623

17-
///Hides elements of the page based on a CSS selector. A selector field contains the selector list. Any matching element has its display property set to none, which hides it.
24+
///Hides elements of the page based on a CSS selector.
25+
///A selector field contains the selector list.
26+
///Any matching element has its display property set to none, which hides it.
1827
///
1928
///**NOTE**: on Android, JavaScript must be enabled.
29+
@EnumSupportedPlatforms(platforms: [
30+
EnumAndroidPlatform(value: 'css-display-none'),
31+
EnumIOSPlatform(value: 'css-display-none'),
32+
EnumMacOSPlatform(value: 'css-display-none')
33+
])
2034
static const CSS_DISPLAY_NONE =
2135
const ContentBlockerActionType_._internal('css-display-none');
2236

23-
///Changes a URL from http to https. URLs with a specified (nondefault) port and links using other protocols are unaffected.
37+
///Changes a URL from http to https.
38+
///URLs with a specified (nondefault) port and links using other protocols are unaffected.
39+
@EnumSupportedPlatforms(platforms: [
40+
EnumAndroidPlatform(value: 'make-https'),
41+
EnumIOSPlatform(value: 'make-https'),
42+
EnumMacOSPlatform(value: 'make-https')
43+
])
2444
static const MAKE_HTTPS =
2545
const ContentBlockerActionType_._internal('make-https');
46+
47+
///Strips cookies from the header before sending it to the server.
48+
///This only blocks cookies otherwise acceptable to WebView's privacy policy.
49+
///Combining with [IGNORE_PREVIOUS_RULES] doesn't override the browser’s privacy settings.
50+
@EnumSupportedPlatforms(platforms: [
51+
EnumIOSPlatform(value: 'block-cookies'),
52+
EnumMacOSPlatform(value: 'block-cookies')
53+
])
54+
static const BLOCK_COOKIES =
55+
const ContentBlockerActionType_._internal('block-cookies');
56+
57+
///Ignores previously triggered actions.
58+
@EnumSupportedPlatforms(platforms: [
59+
EnumIOSPlatform(value: 'ignore-previous-rules'),
60+
EnumMacOSPlatform(value: 'ignore-previous-rules')
61+
])
62+
static const IGNORE_PREVIOUS_RULES =
63+
const ContentBlockerActionType_._internal('ignore-previous-rules');
2664
}

lib/src/types/content_blocker_action_type.g.dart

Lines changed: 103 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_inappwebview
22
description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
3-
version: 6.0.0-beta.12
3+
version: 6.0.0-beta.13
44
homepage: https://inappwebview.dev/
55
repository: https://github.com/pichillilorenzo/flutter_inappwebview
66
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues

0 commit comments

Comments
 (0)