-
-
Notifications
You must be signed in to change notification settings - Fork 10
Add more control on inline video playback #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
didarul-codes
merged 2 commits into
develop
from
feature/add-stoploading-method-in-controller
Sep 16, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "flutter": "3.29.0", | ||
| "flutter": "3.32.8", | ||
| "flavors": {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,8 +6,11 @@ import 'package:adblocker_webview/src/adblocker_webview_controller.dart'; | |||||||||||||||||
| import 'package:adblocker_webview/src/block_resource_loading.dart'; | ||||||||||||||||||
| import 'package:adblocker_webview/src/elem_hide.dart'; | ||||||||||||||||||
| import 'package:adblocker_webview/src/logger.dart'; | ||||||||||||||||||
| import 'package:flutter/foundation.dart'; | ||||||||||||||||||
| import 'package:flutter/material.dart'; | ||||||||||||||||||
| import 'package:webview_flutter/webview_flutter.dart'; | ||||||||||||||||||
| import 'package:webview_flutter_android/webview_flutter_android.dart'; | ||||||||||||||||||
| import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart'; | ||||||||||||||||||
|
|
||||||||||||||||||
| /// A webview implementation of in Flutter that blocks most of the ads that | ||||||||||||||||||
| /// appear inside of the webpages. | ||||||||||||||||||
|
|
@@ -84,7 +87,25 @@ class _AdBlockerWebviewState extends State<AdBlockerWebview> { | |||||||||||||||||
| ..clear() | ||||||||||||||||||
| ..addAll(widget.adBlockerWebviewController.bannedResourceRules); | ||||||||||||||||||
|
|
||||||||||||||||||
| _webViewController = WebViewController(); | ||||||||||||||||||
| late final PlatformWebViewControllerCreationParams params; | ||||||||||||||||||
| if (WebViewPlatform.instance is WebKitWebViewPlatform) { | ||||||||||||||||||
| params = WebKitWebViewControllerCreationParams( | ||||||||||||||||||
| allowsInlineMediaPlayback: true, | ||||||||||||||||||
| ); | ||||||||||||||||||
| } else { | ||||||||||||||||||
| params = const PlatformWebViewControllerCreationParams(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| _webViewController = WebViewController.fromPlatformCreationParams(params); | ||||||||||||||||||
| // ··· | ||||||||||||||||||
| if (_webViewController.platform is AndroidWebViewController) { | ||||||||||||||||||
| unawaited(AndroidWebViewController.enableDebugging(kDebugMode)); | ||||||||||||||||||
| unawaited( | ||||||||||||||||||
| (_webViewController.platform as AndroidWebViewController) | ||||||||||||||||||
| .setMediaPlaybackRequiresUserGesture(true), | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| await Future.wait([ | ||||||||||||||||||
| _webViewController.setOnConsoleMessage((message) { | ||||||||||||||||||
| debugLog('[FLUTTER_WEBVIEW_LOG]: ${message.message}'); | ||||||||||||||||||
|
|
@@ -128,49 +149,54 @@ class _AdBlockerWebviewState extends State<AdBlockerWebview> { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| void _setNavigationDelegate() { | ||||||||||||||||||
| _webViewController.setNavigationDelegate( | ||||||||||||||||||
| NavigationDelegate( | ||||||||||||||||||
| onNavigationRequest: (request) { | ||||||||||||||||||
| final shouldBlock = widget.adBlockerWebviewController | ||||||||||||||||||
| .shouldBlockResource(request.url); | ||||||||||||||||||
| if (shouldBlock) { | ||||||||||||||||||
| debugLog('Blocking resource: ${request.url}'); | ||||||||||||||||||
| return NavigationDecision.prevent; | ||||||||||||||||||
| } | ||||||||||||||||||
| return NavigationDecision.navigate; | ||||||||||||||||||
| }, | ||||||||||||||||||
| onPageStarted: (url) async { | ||||||||||||||||||
| if (widget.shouldBlockAds) { | ||||||||||||||||||
| // Inject resource blocking script as early as possible | ||||||||||||||||||
| unawaited( | ||||||||||||||||||
| _webViewController.runJavaScript( | ||||||||||||||||||
| getResourceLoadingBlockerScript(_urlsToBlock), | ||||||||||||||||||
| ), | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
| widget.onLoadStart?.call(url); | ||||||||||||||||||
| }, | ||||||||||||||||||
| onPageFinished: (url) { | ||||||||||||||||||
| if (widget.shouldBlockAds) { | ||||||||||||||||||
| // Apply element hiding after page load | ||||||||||||||||||
| final cssRules = | ||||||||||||||||||
| widget.adBlockerWebviewController.getCssRulesForWebsite(url); | ||||||||||||||||||
| unawaited( | ||||||||||||||||||
| _webViewController.runJavaScript(generateHidingScript(cssRules)), | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| widget.onLoadFinished?.call(url); | ||||||||||||||||||
| }, | ||||||||||||||||||
| onProgress: (progress) => widget.onProgress?.call(progress), | ||||||||||||||||||
| onHttpError: | ||||||||||||||||||
| (error) => widget.onLoadError?.call( | ||||||||||||||||||
| error.request?.uri.toString(), | ||||||||||||||||||
| error.response?.statusCode ?? -1, | ||||||||||||||||||
| final navigationDelegate = NavigationDelegate( | ||||||||||||||||||
| onNavigationRequest: (request) { | ||||||||||||||||||
| final shouldBlock = widget.adBlockerWebviewController | ||||||||||||||||||
| .shouldBlockResource(request.url); | ||||||||||||||||||
| if (shouldBlock) { | ||||||||||||||||||
| debugLog('Blocking resource: ${request.url}'); | ||||||||||||||||||
| return NavigationDecision.prevent; | ||||||||||||||||||
| } | ||||||||||||||||||
| return NavigationDecision.navigate; | ||||||||||||||||||
| }, | ||||||||||||||||||
| onPageStarted: (url) async { | ||||||||||||||||||
| if (widget.shouldBlockAds) { | ||||||||||||||||||
| // Inject resource blocking script as early as possible | ||||||||||||||||||
| unawaited( | ||||||||||||||||||
| _webViewController.runJavaScript( | ||||||||||||||||||
| getResourceLoadingBlockerScript(_urlsToBlock), | ||||||||||||||||||
| ), | ||||||||||||||||||
| onUrlChange: (change) => widget.onUrlChanged?.call(change.url), | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
| widget.onLoadStart?.call(url); | ||||||||||||||||||
| }, | ||||||||||||||||||
| onPageFinished: (url) { | ||||||||||||||||||
| if (widget.shouldBlockAds) { | ||||||||||||||||||
| // Apply element hiding after page load | ||||||||||||||||||
| final cssRules = widget.adBlockerWebviewController | ||||||||||||||||||
| .getCssRulesForWebsite(url); | ||||||||||||||||||
| unawaited( | ||||||||||||||||||
| _webViewController.runJavaScript(generateHidingScript(cssRules)), | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| widget.onLoadFinished?.call(url); | ||||||||||||||||||
| }, | ||||||||||||||||||
| onProgress: (progress) => widget.onProgress?.call(progress), | ||||||||||||||||||
| onHttpError: (error) => widget.onLoadError?.call( | ||||||||||||||||||
| error.request?.uri.toString(), | ||||||||||||||||||
| error.response?.statusCode ?? -1, | ||||||||||||||||||
| ), | ||||||||||||||||||
| onUrlChange: (change) => widget.onUrlChanged?.call(change.url), | ||||||||||||||||||
| ); | ||||||||||||||||||
| if (WebViewPlatform.instance is WebKitWebViewPlatform) { | ||||||||||||||||||
| final WebKitNavigationDelegate webKitDelegate = | ||||||||||||||||||
| navigationDelegate.platform as WebKitNavigationDelegate; | ||||||||||||||||||
| } else if (WebViewPlatform.instance is AndroidWebViewPlatform) { | ||||||||||||||||||
| final AndroidNavigationDelegate androidDelegate = | ||||||||||||||||||
| navigationDelegate.platform as AndroidNavigationDelegate; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+192
to
+198
|
||||||||||||||||||
| if (WebViewPlatform.instance is WebKitWebViewPlatform) { | |
| final WebKitNavigationDelegate webKitDelegate = | |
| navigationDelegate.platform as WebKitNavigationDelegate; | |
| } else if (WebViewPlatform.instance is AndroidWebViewPlatform) { | |
| final AndroidNavigationDelegate androidDelegate = | |
| navigationDelegate.platform as AndroidNavigationDelegate; | |
| } | |
| // Platform-specific navigation delegates can be configured here if needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment '// ···' is unclear and doesn't provide meaningful information about the code that follows. Replace with a descriptive comment explaining the platform-specific configuration setup.