diff --git a/webview_all/lib/src/proxy_controller.dart b/webview_all/lib/src/proxy_controller.dart new file mode 100644 index 0000000..8407786 --- /dev/null +++ b/webview_all/lib/src/proxy_controller.dart @@ -0,0 +1,35 @@ +import 'package:webview_platform_interface/webview_platform_interface.dart'; + +/// Manages process-wide proxy settings for WebViews. +class ProxyController { + /// Constructs a [ProxyController]. + ProxyController() + : this.fromPlatformCreationParams( + const PlatformProxyControllerCreationParams(), + ); + + /// Constructs a [ProxyController] from creation params for a specific + /// platform. + ProxyController.fromPlatformCreationParams( + PlatformProxyControllerCreationParams params, + ) : this.fromPlatform(PlatformProxyController(params)); + + /// Constructs a [ProxyController] from a specific platform implementation. + ProxyController.fromPlatform(this.platform); + + /// Gets a shared [ProxyController] instance. + static ProxyController instance() => ProxyController(); + + /// Implementation of [PlatformProxyController] for the current platform. + final PlatformProxyController platform; + + /// Sets proxy settings for WebViews in this process. + Future setProxyOverride({required ProxySettings settings}) { + return platform.setProxyOverride(settings: settings); + } + + /// Clears process-wide WebView proxy settings. + Future clearProxyOverride() { + return platform.clearProxyOverride(); + } +} diff --git a/webview_all/lib/webview_all.dart b/webview_all/lib/webview_all.dart index 6db306a..6812229 100644 --- a/webview_all/lib/webview_all.dart +++ b/webview_all/lib/webview_all.dart @@ -18,12 +18,17 @@ export 'package:webview_platform_interface/webview_platform_interface.dart' NavigationRequestCallback, PageEventCallback, PlatformNavigationDelegateCreationParams, + PlatformProxyController, + PlatformProxyControllerCreationParams, PlatformWebViewControllerCreationParams, PlatformWebViewCookieManagerCreationParams, PlatformWebViewDataManagerCreationParams, PlatformWebViewPermissionRequest, PlatformWebViewWidgetCreationParams, ProgressCallback, + ProxyRule, + ProxySchemeFilter, + ProxySettings, ScrollPositionChange, UrlChange, WebResourceError, @@ -43,6 +48,7 @@ export 'package:webview_platform_interface/webview_platform_interface.dart' X509Certificate; export 'src/navigation_delegate.dart'; +export 'src/proxy_controller.dart'; export 'src/offscreen_webview_session.dart'; export 'src/webview_controller.dart'; export 'src/webview_cookie_manager.dart'; diff --git a/webview_all_linux/lib/src/linux_proxy_controller.dart b/webview_all_linux/lib/src/linux_proxy_controller.dart new file mode 100644 index 0000000..d2fedad --- /dev/null +++ b/webview_all_linux/lib/src/linux_proxy_controller.dart @@ -0,0 +1,86 @@ +import 'package:webview_platform_interface/webview_platform_interface.dart'; + +import 'linux_webview_controller.dart'; + +/// Linux-specific creation params for [LinuxProxyController]. +class LinuxProxyControllerCreationParams + extends PlatformProxyControllerCreationParams { + /// Creates Linux proxy controller creation params. + const LinuxProxyControllerCreationParams(); + + /// Creates Linux proxy controller creation params from platform params. + const LinuxProxyControllerCreationParams.fromPlatformProxyControllerCreationParams( + PlatformProxyControllerCreationParams params, + ); +} + +/// Controls WebKitGTK proxy settings for Linux WebViews. +class LinuxProxyController extends PlatformProxyController { + /// Creates a [LinuxProxyController]. + LinuxProxyController(PlatformProxyControllerCreationParams params) + : super.implementation( + params is LinuxProxyControllerCreationParams + ? params + : LinuxProxyControllerCreationParams.fromPlatformProxyControllerCreationParams( + params, + ), + ); + + /// Gets a Linux proxy controller instance. + static LinuxProxyController instance() { + return LinuxProxyController(const LinuxProxyControllerCreationParams()); + } + + @override + Future setProxyOverride({required ProxySettings settings}) { + _validateProxySettings(settings); + return LinuxWebViewController.rootChannel.invokeMethod( + 'setProxyOverride', + settings.toMap(), + ); + } + + @override + Future clearProxyOverride() { + return LinuxWebViewController.rootChannel.invokeMethod( + 'clearProxyOverride', + ); + } + + void _validateProxySettings(ProxySettings settings) { + if (settings.proxyRules.isEmpty) { + throw ArgumentError.value( + settings, + 'settings', + 'At least one proxy rule is required.', + ); + } + + for (final ProxyRule rule in settings.proxyRules) { + if (rule.url.isEmpty) { + throw ArgumentError.value( + rule.url, + 'settings.proxyRules.url', + 'Proxy URL must not be empty.', + ); + } + final Uri uri = Uri.parse(rule.url); + if (!uri.hasScheme || uri.host.isEmpty) { + throw ArgumentError.value( + rule.url, + 'settings.proxyRules.url', + 'Proxy URL must be an absolute URI with a host.', + ); + } + final ProxySchemeFilter? schemeFilter = rule.schemeFilter; + if (schemeFilter != null && + !ProxySchemeFilter.values.contains(schemeFilter)) { + throw ArgumentError.value( + schemeFilter, + 'settings.proxyRules.schemeFilter', + 'Unsupported proxy scheme filter.', + ); + } + } + } +} diff --git a/webview_all_linux/lib/src/linux_webview_platform.dart b/webview_all_linux/lib/src/linux_webview_platform.dart index 47c0629..8115c4e 100644 --- a/webview_all_linux/lib/src/linux_webview_platform.dart +++ b/webview_all_linux/lib/src/linux_webview_platform.dart @@ -1,6 +1,7 @@ import 'package:webview_platform_interface/webview_platform_interface.dart'; import 'linux_navigation_delegate.dart'; +import 'linux_proxy_controller.dart'; import 'linux_webview_controller.dart'; import 'linux_webview_cookie_manager.dart'; import 'linux_webview_data_manager.dart'; @@ -42,6 +43,14 @@ class LinuxWebViewPlatform extends WebViewPlatform { return LinuxWebViewCookieManager(params); } + + @override + LinuxProxyController createPlatformProxyController( + PlatformProxyControllerCreationParams params, + ) { + return LinuxProxyController(params); + } + @override LinuxWebViewDataManager createPlatformWebViewDataManager( PlatformWebViewDataManagerCreationParams params, diff --git a/webview_all_linux/lib/webview_all_linux.dart b/webview_all_linux/lib/webview_all_linux.dart index 504b46a..4e92629 100644 --- a/webview_all_linux/lib/webview_all_linux.dart +++ b/webview_all_linux/lib/webview_all_linux.dart @@ -1,4 +1,5 @@ export 'src/linux_navigation_delegate.dart'; +export 'src/linux_proxy_controller.dart'; export 'src/linux_webview_controller.dart'; export 'src/linux_webview_cookie_manager.dart'; export 'src/linux_webview_data_manager.dart'; diff --git a/webview_all_linux/linux/src/plugin/root_channel.cc b/webview_all_linux/linux/src/plugin/root_channel.cc index 625ca61..3b6a86a 100644 --- a/webview_all_linux/linux/src/plugin/root_channel.cc +++ b/webview_all_linux/linux/src/plugin/root_channel.cc @@ -1,6 +1,7 @@ #include "plugin/webview_all_linux_plugin_private.h" #include "common/method_channel_utils.h" +#include #include #include @@ -54,6 +55,92 @@ static void clear_website_data_finished_cb(GObject* object, g_object_unref(method_call); } + +static GPtrArray* proxy_ignore_hosts_from_value(FlValue* value) { + GPtrArray* ignore_hosts = g_ptr_array_new_with_free_func(g_free); + if (value != nullptr && fl_value_get_type(value) == FL_VALUE_TYPE_LIST) { + const size_t length = fl_value_get_length(value); + for (size_t i = 0; i < length; ++i) { + FlValue* item = fl_value_get_list_value(value, i); + if (item != nullptr && fl_value_get_type(item) == FL_VALUE_TYPE_STRING) { + g_ptr_array_add(ignore_hosts, + g_strdup(fl_value_get_string(item))); + } + } + } + g_ptr_array_add(ignore_hosts, nullptr); + return ignore_hosts; +} + +static WebKitNetworkProxySettings* proxy_settings_from_value( + FlValue* value, GError** error) { + FlValue* proxy_rules = map_lookup(value, "proxyRules"); + if (proxy_rules == nullptr || + fl_value_get_type(proxy_rules) != FL_VALUE_TYPE_LIST || + fl_value_get_length(proxy_rules) == 0) { + g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, + "At least one proxy rule is required."); + return nullptr; + } + + GPtrArray* ignore_hosts = + proxy_ignore_hosts_from_value(map_lookup(value, "bypassRules")); + const gchar* default_proxy_uri = nullptr; + GPtrArray* scheme_rules = g_ptr_array_new(); + + const size_t length = fl_value_get_length(proxy_rules); + for (size_t i = 0; i < length; ++i) { + FlValue* rule = fl_value_get_list_value(proxy_rules, i); + if (rule == nullptr || fl_value_get_type(rule) != FL_VALUE_TYPE_MAP) { + continue; + } + + const gchar* proxy_uri = map_lookup_string(rule, "url"); + if (proxy_uri == nullptr || strlen(proxy_uri) == 0) { + g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, + "Proxy rule URL must not be empty."); + g_ptr_array_unref(ignore_hosts); + g_ptr_array_unref(scheme_rules); + return nullptr; + } + + const gchar* scheme_filter = map_lookup_string(rule, "schemeFilter"); + if (scheme_filter == nullptr || strcmp(scheme_filter, "*") == 0) { + if (default_proxy_uri == nullptr) { + default_proxy_uri = proxy_uri; + } + continue; + } + + if (strcmp(scheme_filter, "http") != 0 && + strcmp(scheme_filter, "https") != 0) { + g_set_error(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, + "Unsupported proxy scheme filter: %s", scheme_filter); + g_ptr_array_unref(ignore_hosts); + g_ptr_array_unref(scheme_rules); + return nullptr; + } + + g_ptr_array_add(scheme_rules, rule); + } + + WebKitNetworkProxySettings* settings = webkit_network_proxy_settings_new( + default_proxy_uri, + reinterpret_cast(ignore_hosts->pdata)); + + for (guint i = 0; i < scheme_rules->len; ++i) { + FlValue* rule = static_cast(g_ptr_array_index(scheme_rules, i)); + const gchar* scheme_filter = map_lookup_string(rule, "schemeFilter"); + const gchar* proxy_uri = map_lookup_string(rule, "url"); + webkit_network_proxy_settings_add_proxy_for_scheme(settings, scheme_filter, + proxy_uri); + } + + g_ptr_array_unref(ignore_hosts); + g_ptr_array_unref(scheme_rules); + return settings; +} + static void get_cookies_finished_cb(GObject* object, GAsyncResult* result, gpointer user_data) { @@ -124,6 +211,32 @@ void root_method_call_cb(FlMethodChannel* channel, WebKitWebsiteDataManager* website_data_manager = webkit_web_context_get_website_data_manager(context); + + if (strcmp(method, "setProxyOverride") == 0) { + GError* error = nullptr; + WebKitNetworkProxySettings* proxy_settings = + proxy_settings_from_value(args, &error); + if (error != nullptr) { + respond(method_call, error_response("invalid_proxy_settings", + error->message)); + g_clear_error(&error); + return; + } + + webkit_website_data_manager_set_network_proxy_settings( + website_data_manager, WEBKIT_NETWORK_PROXY_MODE_CUSTOM, proxy_settings); + webkit_network_proxy_settings_free(proxy_settings); + respond(method_call, success_response()); + return; + } + + if (strcmp(method, "clearProxyOverride") == 0) { + webkit_website_data_manager_set_network_proxy_settings( + website_data_manager, WEBKIT_NETWORK_PROXY_MODE_DEFAULT, nullptr); + respond(method_call, success_response()); + return; + } + if (strcmp(method, "clearCookies") == 0) { g_object_ref(method_call); webkit_website_data_manager_clear( diff --git a/webview_all_linux/test/linux_webview_platform_test.dart b/webview_all_linux/test/linux_webview_platform_test.dart index c36f550..cd7f032 100644 --- a/webview_all_linux/test/linux_webview_platform_test.dart +++ b/webview_all_linux/test/linux_webview_platform_test.dart @@ -54,6 +54,12 @@ void main() { ), isA(), ); + expect( + platform.createPlatformProxyController( + const PlatformProxyControllerCreationParams(), + ), + isA(), + ); expect( platform.createPlatformWebViewDataManager( const PlatformWebViewDataManagerCreationParams(), @@ -62,6 +68,32 @@ void main() { ); }); + test('forwards proxy override settings to the root channel', () async { + final List calls = []; + _mockLinuxWebViewCreation(onRootCall: calls.add); + final LinuxProxyController controller = LinuxProxyController.instance(); + + await controller.setProxyOverride( + settings: const ProxySettings( + bypassRules: ['localhost', '127.0.0.1'], + proxyRules: [ + ProxyRule(url: 'http://127.0.0.1:8888'), + ], + ), + ); + await controller.clearProxyOverride(); + + expect(calls, hasLength(2)); + expect(calls[0].method, 'setProxyOverride'); + expect(calls[0].arguments, { + 'bypassRules': ['localhost', '127.0.0.1'], + 'proxyRules': >[ + {'schemeFilter': null, 'url': 'http://127.0.0.1:8888'}, + ], + }); + expect(calls[1].method, 'clearProxyOverride'); + }); + testWidgets('moves the native view when the controller changes', ( WidgetTester tester, ) async { diff --git a/webview_platform_interface/lib/src/platform_proxy_controller.dart b/webview_platform_interface/lib/src/platform_proxy_controller.dart new file mode 100644 index 0000000..911a451 --- /dev/null +++ b/webview_platform_interface/lib/src/platform_proxy_controller.dart @@ -0,0 +1,51 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'types/types.dart'; +import 'webview_platform.dart' show WebViewPlatform; + +/// Interface for a platform implementation that manages WebView proxy settings. +abstract class PlatformProxyController extends PlatformInterface { + /// Creates a new [PlatformProxyController]. + factory PlatformProxyController(PlatformProxyControllerCreationParams params) { + assert( + WebViewPlatform.instance != null, + 'A platform implementation for `webview_all` has not been set. Please ' + 'ensure that an implementation of `WebViewPlatform` has been set to ' + '`WebViewPlatform.instance` before use. For unit testing, ' + '`WebViewPlatform.instance` can be set with your own test implementation.', + ); + final PlatformProxyController controller = WebViewPlatform.instance! + .createPlatformProxyController(params); + PlatformInterface.verify(controller, _token); + return controller; + } + + /// Used by the platform implementation to create a new + /// [PlatformProxyController]. + @protected + PlatformProxyController.implementation(this.params) : super(token: _token); + + static final Object _token = Object(); + + /// The parameters used to initialize this [PlatformProxyController]. + final PlatformProxyControllerCreationParams params; + + /// Sets [ProxySettings] to be used by WebViews in the current process. + Future setProxyOverride({required ProxySettings settings}) { + throw UnimplementedError( + 'setProxyOverride is not implemented on the current platform', + ); + } + + /// Clears proxy settings for WebViews in the current process. + Future clearProxyOverride() { + throw UnimplementedError( + 'clearProxyOverride is not implemented on the current platform', + ); + } +} diff --git a/webview_platform_interface/lib/src/types/platform_proxy_controller_creation_params.dart b/webview_platform_interface/lib/src/types/platform_proxy_controller_creation_params.dart new file mode 100644 index 0000000..0773d68 --- /dev/null +++ b/webview_platform_interface/lib/src/types/platform_proxy_controller_creation_params.dart @@ -0,0 +1,10 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Object specifying creation parameters for creating a +/// [PlatformProxyController]. +class PlatformProxyControllerCreationParams { + /// Creates platform proxy controller creation parameters. + const PlatformProxyControllerCreationParams(); +} diff --git a/webview_platform_interface/lib/src/types/proxy_rule.dart b/webview_platform_interface/lib/src/types/proxy_rule.dart new file mode 100644 index 0000000..7dd4505 --- /dev/null +++ b/webview_platform_interface/lib/src/types/proxy_rule.dart @@ -0,0 +1,56 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'proxy_scheme_filter.dart'; + +/// A proxy rule that maps an optional scheme filter to a proxy URL. +class ProxyRule { + /// Creates a [ProxyRule]. + const ProxyRule({this.schemeFilter, required this.url}); + + /// The optional scheme filter this rule applies to. + final ProxySchemeFilter? schemeFilter; + + /// The proxy URL. + final String url; + + /// Converts this rule to a platform-channel map. + Map toMap() { + return { + 'schemeFilter': schemeFilter?.toValue(), + 'url': url, + }; + } + + /// Converts this rule to a JSON-compatible map. + Map toJson() => toMap(); + + /// Gets a possible [ProxyRule] instance from a map value. + static ProxyRule? fromMap(Map? map) { + if (map == null) { + return null; + } + final Object? url = map['url']; + if (url == null) { + return null; + } + return ProxyRule( + schemeFilter: ProxySchemeFilter.fromValue(map['schemeFilter'] as String?), + url: url as String, + ); + } + + @override + String toString() => toMap().toString(); + + @override + bool operator ==(Object other) { + return other is ProxyRule && + other.schemeFilter == schemeFilter && + other.url == url; + } + + @override + int get hashCode => Object.hash(schemeFilter, url); +} diff --git a/webview_platform_interface/lib/src/types/proxy_scheme_filter.dart b/webview_platform_interface/lib/src/types/proxy_scheme_filter.dart new file mode 100644 index 0000000..c2db40d --- /dev/null +++ b/webview_platform_interface/lib/src/types/proxy_scheme_filter.dart @@ -0,0 +1,55 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Scheme filters used by [ProxyRule]. +class ProxySchemeFilter { + /// Creates a scheme filter with the given string [value]. + const ProxySchemeFilter._(this.value); + + /// Matches all schemes. + static const ProxySchemeFilter matchAllSchemes = ProxySchemeFilter._('*'); + + /// Matches HTTP requests. + static const ProxySchemeFilter matchHttp = ProxySchemeFilter._('http'); + + /// Matches HTTPS requests. + static const ProxySchemeFilter matchHttps = ProxySchemeFilter._('https'); + + /// All known scheme filters. + static const List values = [ + matchAllSchemes, + matchHttp, + matchHttps, + ]; + + /// The string value passed through the platform channel. + final String value; + + /// Gets a possible [ProxySchemeFilter] from a string value. + static ProxySchemeFilter? fromValue(String? value) { + if (value == null) { + return null; + } + for (final ProxySchemeFilter filter in values) { + if (filter.value == value) { + return filter; + } + } + return null; + } + + /// Converts this filter to its string representation for platform messages. + String toValue() => value; + + @override + String toString() => value; + + @override + bool operator ==(Object other) { + return other is ProxySchemeFilter && other.value == value; + } + + @override + int get hashCode => value.hashCode; +} diff --git a/webview_platform_interface/lib/src/types/proxy_settings.dart b/webview_platform_interface/lib/src/types/proxy_settings.dart new file mode 100644 index 0000000..20868ce --- /dev/null +++ b/webview_platform_interface/lib/src/types/proxy_settings.dart @@ -0,0 +1,66 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'proxy_rule.dart'; + +/// Settings used by [PlatformProxyController] to configure WebView proxying. +class ProxySettings { + /// Creates [ProxySettings]. + const ProxySettings({ + this.bypassRules = const [], + this.proxyRules = const [], + }); + + /// Host patterns that should bypass the configured proxies. + final List bypassRules; + + /// Proxy rules to apply. Platform implementations may support a subset of + /// scheme filters. + final List proxyRules; + + /// Returns a copy of this settings object. + ProxySettings copy() { + return ProxySettings( + bypassRules: List.unmodifiable(bypassRules), + proxyRules: List.unmodifiable(proxyRules), + ); + } + + /// Converts this object to a platform-channel map. + Map toMap() { + return { + 'bypassRules': bypassRules, + 'proxyRules': proxyRules.map((ProxyRule rule) => rule.toMap()).toList(), + }; + } + + /// Converts this object to a JSON-compatible map. + Map toJson() => toMap(); + + /// Gets a possible [ProxySettings] instance from a map value. + static ProxySettings? fromMap(Map? map) { + if (map == null) { + return null; + } + final List proxyRules = + (map['proxyRules'] as List?) ?? const []; + final List bypassRules = + (map['bypassRules'] as List?) ?? const []; + return ProxySettings( + bypassRules: bypassRules.whereType().toList(), + proxyRules: proxyRules + .whereType>() + .map( + (Map rule) => ProxyRule.fromMap( + rule.cast(), + ), + ) + .whereType() + .toList(), + ); + } + + @override + String toString() => toMap().toString(); +} diff --git a/webview_platform_interface/lib/src/types/types.dart b/webview_platform_interface/lib/src/types/types.dart index 3037086..55b2e97 100644 --- a/webview_platform_interface/lib/src/types/types.dart +++ b/webview_platform_interface/lib/src/types/types.dart @@ -15,8 +15,12 @@ export 'load_file_params.dart'; export 'load_request_params.dart'; export 'navigation_decision.dart'; export 'navigation_request.dart'; +export 'proxy_rule.dart'; +export 'proxy_scheme_filter.dart'; +export 'proxy_settings.dart'; export 'over_scroll_mode.dart'; export 'platform_navigation_delegate_creation_params.dart'; +export 'platform_proxy_controller_creation_params.dart'; export 'platform_webview_controller_creation_params.dart'; export 'platform_webview_cookie_manager_creation_params.dart'; export 'platform_webview_data_manager_creation_params.dart'; diff --git a/webview_platform_interface/lib/src/webview_platform.dart b/webview_platform_interface/lib/src/webview_platform.dart index 34d5cce..e4477b4 100644 --- a/webview_platform_interface/lib/src/webview_platform.dart +++ b/webview_platform_interface/lib/src/webview_platform.dart @@ -5,6 +5,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'platform_navigation_delegate.dart'; +import 'platform_proxy_controller.dart'; import 'platform_webview_controller.dart'; import 'platform_webview_cookie_manager.dart'; import 'platform_webview_data_manager.dart'; @@ -59,6 +60,18 @@ abstract class WebViewPlatform extends PlatformInterface { ); } + + /// Creates a new [PlatformProxyController]. + /// + /// This function should only be called by the app-facing package. + PlatformProxyController createPlatformProxyController( + PlatformProxyControllerCreationParams params, + ) { + throw UnimplementedError( + 'createPlatformProxyController is not implemented on the current platform.', + ); + } + /// Creates a new [PlatformWebViewDataManager]. /// /// This function should only be called by the app-facing package. diff --git a/webview_platform_interface/lib/webview_platform_interface.dart b/webview_platform_interface/lib/webview_platform_interface.dart index f0a9419..82911f5 100644 --- a/webview_platform_interface/lib/webview_platform_interface.dart +++ b/webview_platform_interface/lib/webview_platform_interface.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. export 'src/platform_navigation_delegate.dart'; +export 'src/platform_proxy_controller.dart'; export 'src/platform_ssl_auth_error.dart'; export 'src/platform_webview_controller.dart'; export 'src/platform_webview_cookie_manager.dart'; diff --git a/webview_platform_interface/test/webview_platform_interface_export_test.dart b/webview_platform_interface/test/webview_platform_interface_export_test.dart index d90a50e..5ed738e 100644 --- a/webview_platform_interface/test/webview_platform_interface_export_test.dart +++ b/webview_platform_interface/test/webview_platform_interface_export_test.dart @@ -22,11 +22,16 @@ void main() { main_file.NavigationRequestCallback; main_file.PageEventCallback; main_file.PlatformNavigationDelegateCreationParams; + main_file.PlatformProxyController; + main_file.PlatformProxyControllerCreationParams; main_file.PlatformWebViewControllerCreationParams; main_file.PlatformWebViewCookieManagerCreationParams; main_file.PlatformWebViewPermissionRequest; main_file.PlatformWebViewWidgetCreationParams; main_file.ProgressCallback; + main_file.ProxyRule; + main_file.ProxySchemeFilter; + main_file.ProxySettings; main_file.WebViewPermissionResourceType; main_file.WebResourceRequest; main_file.WebResourceResponse; diff --git a/webview_platform_interface/test/webview_platform_test.dart b/webview_platform_interface/test/webview_platform_test.dart index 6d4a47f..592602a 100644 --- a/webview_platform_interface/test/webview_platform_test.dart +++ b/webview_platform_interface/test/webview_platform_test.dart @@ -54,6 +54,22 @@ void main() { ), ); + expect( + () => PlatformProxyController( + const PlatformProxyControllerCreationParams(), + ), + throwsA( + isA().having( + (AssertionError error) => error.message, + 'message', + 'A platform implementation for `webview_all` has not been set. Please ' + 'ensure that an implementation of `WebViewPlatform` has been set to ' + '`WebViewPlatform.instance` before use. For unit testing, ' + '`WebViewPlatform.instance` can be set with your own test implementation.', + ), + ), + ); + expect( () => PlatformWebViewCookieManager( const PlatformWebViewCookieManagerCreationParams(), @@ -180,6 +196,20 @@ void main() { }, ); + test( + 'Default implementation of createPlatformProxyController throws', + () { + final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); + + expect( + () => webViewPlatform.createPlatformProxyController( + const PlatformProxyControllerCreationParams(), + ), + throwsUnimplementedError, + ); + }, + ); + test('Default implementation of createPlatformWebViewDataManager throws', () { final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform();