Skip to content

Commit

Permalink
windows: Implemented shouldInterceptRequest, onLoadResourceWithCustom…
Browse files Browse the repository at this point in the history
…Scheme WebView events, platform interface: Added WebViewEnvironment.customSchemeRegistrations parameter for Windows, Added CustomSchemeRegistration type
  • Loading branch information
pichillilorenzo committed Oct 2, 2024
1 parent 1834bed commit 43a7980
Show file tree
Hide file tree
Showing 32 changed files with 607 additions and 29 deletions.
9 changes: 4 additions & 5 deletions flutter_inappwebview/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ Future main() async {

if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) {
final availableVersion = await WebViewEnvironment.getAvailableVersion();
assert(availableVersion != null, 'Failed to find an installed WebView2 runtime or non-stable Microsoft Edge installation.');
assert(availableVersion != null,
'Failed to find an installed WebView2 runtime or non-stable Microsoft Edge installation.');

webViewEnvironment = await WebViewEnvironment.create(settings:
WebViewEnvironmentSettings(
userDataFolder: 'custom_path'
));
webViewEnvironment = await WebViewEnvironment.create(
settings: WebViewEnvironmentSettings(userDataFolder: 'custom_path'));
}

if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
Expand Down
6 changes: 6 additions & 0 deletions flutter_inappwebview_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.3.0

- Added `WebViewEnvironment.customSchemeRegistrations` parameter for Windows
- Added `CustomSchemeRegistration` type
- Updated docs

## 1.2.0

- Updated `Uint8List` conversion inside `fromMap` methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ abstract class PlatformInAppBrowserEvents {
///- Android native WebView
///- iOS ([Official API - WKURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkurlschemehandler))
///- MacOS ([Official API - WKURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkurlschemehandler))
///- Windows
Future<CustomSchemeResponse?>? onLoadResourceWithCustomScheme(
WebResourceRequest request) {
return null;
Expand Down Expand Up @@ -1149,6 +1150,7 @@ abstract class PlatformInAppBrowserEvents {
///
///**Officially Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewClient.shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest)))
///- Windows ([ICoreWebView2.add_WebResourceRequested](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2478.35#add_webresourcerequested))
Future<WebResourceResponse?>? shouldInterceptRequest(
WebResourceRequest request) {
return null;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class PlatformWebViewCreationParams<T> {
///- Android native WebView
///- iOS ([Official API - WKURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkurlschemehandler))
///- MacOS ([Official API - WKURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkurlschemehandler))
///- Windows
///{@endtemplate}
final Future<CustomSchemeResponse?> Function(
T controller, WebResourceRequest request)? onLoadResourceWithCustomScheme;
Expand Down Expand Up @@ -745,6 +746,7 @@ class PlatformWebViewCreationParams<T> {
///
///**Officially Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewClient.shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest)))
///- Windows ([ICoreWebView2.add_WebResourceRequested](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2478.35#add_webresourcerequested))
///{@endtemplate}
final Future<WebResourceResponse?> Function(
T controller, WebResourceRequest request)? shouldInterceptRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';

import '../webview_environment/webview_environment_settings.dart';

part 'custom_scheme_registration.g.dart';

///Class that represents the registration of a custom scheme for [WebViewEnvironmentSettings] method.
@SupportedPlatforms(platforms: [WindowsPlatform()])
@ExchangeableObject()
class CustomSchemeRegistration_ {
///The name of the custom scheme to register.
String scheme;

///List of origins that are allowed to issue requests with the custom scheme, such as XHRs and subresource requests that have an Origin header.
List<String>? allowedOrigins;

///Whether the sites with this scheme will be treated as a Secure Context like an HTTPS site.
///This flag is only effective when [hasAuthorityComponent] is also set to `true`. `false` by default.
bool? treatAsSecure;

///Set this property to `true` if the URIs with this custom scheme will have an authority component (a host for custom schemes).
///Specifically, if you have a URI of the following form you should set the HasAuthorityComponent value as listed.
bool? hasAuthorityComponent;

CustomSchemeRegistration_({required this.scheme, this.allowedOrigins, this.treatAsSecure, this.hasAuthorityComponent});
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,6 @@ export 'tracing_mode.dart' show TracingMode;
export 'tracing_category.dart' show TracingCategory;
export 'custom_tabs_post_message_result_type.dart'
show CustomTabsPostMessageResultType;
export 'custom_scheme_registration.dart'
show CustomSchemeRegistration;
export 'disposable.dart';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';

import 'platform_webview_environment.dart';
import '../types/custom_scheme_registration.dart';

part 'webview_environment_settings.g.dart';

Expand Down Expand Up @@ -100,11 +101,22 @@ class WebViewEnvironmentSettings_ {
])
final String? targetCompatibleBrowserVersion;

///Set the array of custom scheme registrations to be used.
@SupportedPlatforms(platforms: [
WindowsPlatform(
apiName:
'ICoreWebView2EnvironmentOptions4.SetCustomSchemeRegistrations',
apiUrl:
'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environmentoptions4?view=webview2-1.0.2739.15#setcustomschemeregistrations')
])
final List<CustomSchemeRegistration_>? customSchemeRegistrations;

WebViewEnvironmentSettings_(
{this.browserExecutableFolder,
this.userDataFolder,
this.additionalBrowserArguments,
this.allowSingleSignOnUsingOSPrimaryAccount,
this.language,
this.targetCompatibleBrowserVersion});
this.targetCompatibleBrowserVersion,
this.customSchemeRegistrations});
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flutter_inappwebview_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_inappwebview_platform_interface
description: A common platform interface for the flutter_inappwebview plugin.
version: 1.2.0
version: 1.3.0
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_platform_interface
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
Expand Down
5 changes: 5 additions & 0 deletions flutter_inappwebview_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.5.0

- Implemented `shouldInterceptRequest`, `onLoadResourceWithCustomScheme` WebView events
- Updated flutter_inappwebview_platform_interface version to ^1.3.0

## 0.4.1

- Implemented `incognito` for `InAppWebViewSettings`
Expand Down
2 changes: 1 addition & 1 deletion flutter_inappwebview_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_inappwebview_windows
description: Windows implementation of the flutter_inappwebview plugin.
version: 0.4.1
version: 0.5.0
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_windows
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
Expand Down
18 changes: 17 additions & 1 deletion flutter_inappwebview_windows/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ list(APPEND PLUGIN_SOURCES
"types/ssl_certificate.h"
"types/permission_response.cpp"
"types/permission_response.h"
"types/custom_scheme_response.cpp"
"types/custom_scheme_response.h"
"types/custom_scheme_registration.cpp"
"types/custom_scheme_registration.h"
"custom_platform_view/custom_platform_view.cc"
"custom_platform_view/custom_platform_view.h"
"custom_platform_view/texture_bridge.cc"
Expand Down Expand Up @@ -175,7 +179,19 @@ endif()
# Apply a standard set of build settings that are configured in the
# application-level CMakeLists.txt. This can be removed for plugins that want
# full control over build settings.
apply_standard_settings(${PLUGIN_NAME})
# apply_standard_settings(${PLUGIN_NAME})
#
# IMPORTANT: The apply_standard_settings function is not used here because it
# is causing the plugin to fail to compile because of the usage of /WX flag.
# So, creating here a custom function to apply the standard settings without the /WX flag.
function(FLUTTER_INAPPWEBVIEW_WINDOWS_APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_17)
target_compile_options(${TARGET} PRIVATE /W4 /wd"4100")
target_compile_options(${TARGET} PRIVATE /EHsc)
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
endfunction()
flutter_inappwebview_windows_apply_standard_settings(${PLUGIN_NAME})

target_link_libraries(${PLUGIN_NAME} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets)
target_link_libraries(${PLUGIN_NAME} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.ImplementationLibrary/build/native/Microsoft.Windows.ImplementationLibrary.targets)
Expand Down
Loading

0 comments on commit 43a7980

Please sign in to comment.