windows: added WebViewEnvironment support for headlessinappwebview and inappbrowser

This commit is contained in:
unknown 2024-01-27 21:36:37 +01:00
parent c452082219
commit db9ff8c4e6
19 changed files with 83 additions and 65 deletions

View File

@ -24,6 +24,7 @@ class _HeadlessInAppWebViewExampleScreenState
: WebUri("http://localhost:${Uri.base.port}/page.html"); : WebUri("http://localhost:${Uri.base.port}/page.html");
headlessWebView = HeadlessInAppWebView( headlessWebView = HeadlessInAppWebView(
webViewEnvironment: webViewEnvironment,
initialUrlRequest: URLRequest(url: url), initialUrlRequest: URLRequest(url: url),
initialSettings: InAppWebViewSettings( initialSettings: InAppWebViewSettings(
isInspectable: kDebugMode, isInspectable: kDebugMode,

View File

@ -17,7 +17,8 @@ class MyInAppBrowser extends InAppBrowser {
: super( : super(
windowId: windowId, windowId: windowId,
initialUserScripts: initialUserScripts, initialUserScripts: initialUserScripts,
pullToRefreshController: pullToRefreshController); pullToRefreshController: pullToRefreshController,
webViewEnvironment: webViewEnvironment,);
@override @override
Future onBrowserCreated() async { Future onBrowserCreated() async {

View File

@ -5,10 +5,12 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import flutter_inappwebview_macos
import path_provider_foundation import path_provider_foundation
import url_launcher_macos import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
} }

View File

@ -35,14 +35,14 @@ dependencies:
dependency_overrides: dependency_overrides:
flutter_inappwebview_platform_interface: flutter_inappwebview_platform_interface:
path: ../../flutter_inappwebview_platform_interface path: ../../flutter_inappwebview_platform_interface
#flutter_inappwebview_android: flutter_inappwebview_android:
# path: ../../flutter_inappwebview_android path: ../../flutter_inappwebview_android
#flutter_inappwebview_ios: flutter_inappwebview_ios:
# path: ../../flutter_inappwebview_ios path: ../../flutter_inappwebview_ios
#flutter_inappwebview_macos: flutter_inappwebview_macos:
# path: ../../flutter_inappwebview_macos path: ../../flutter_inappwebview_macos
#flutter_inappwebview_web: flutter_inappwebview_web:
# path: ../../flutter_inappwebview_web path: ../../flutter_inappwebview_web
flutter_inappwebview_windows: flutter_inappwebview_windows:
path: ../../flutter_inappwebview_windows path: ../../flutter_inappwebview_windows

View File

@ -11,6 +11,7 @@ import '../find_interaction/find_interaction_controller.dart';
import '../pull_to_refresh/main.dart'; import '../pull_to_refresh/main.dart';
import '../in_app_webview/in_app_webview_controller.dart'; import '../in_app_webview/in_app_webview_controller.dart';
import '../webview_environment/webview_environment.dart';
///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser} ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser}
class InAppBrowser implements PlatformInAppBrowserEvents { class InAppBrowser implements PlatformInAppBrowserEvents {
@ -22,14 +23,17 @@ class InAppBrowser implements PlatformInAppBrowserEvents {
PullToRefreshController? pullToRefreshController, PullToRefreshController? pullToRefreshController,
FindInteractionController? findInteractionController, FindInteractionController? findInteractionController,
UnmodifiableListView<UserScript>? initialUserScripts, UnmodifiableListView<UserScript>? initialUserScripts,
int? windowId}) int? windowId,
WebViewEnvironment? webViewEnvironment,
})
: this.fromPlatformCreationParams( : this.fromPlatformCreationParams(
PlatformInAppBrowserCreationParams( PlatformInAppBrowserCreationParams(
contextMenu: contextMenu, contextMenu: contextMenu,
pullToRefreshController: pullToRefreshController?.platform, pullToRefreshController: pullToRefreshController?.platform,
findInteractionController: findInteractionController?.platform, findInteractionController: findInteractionController?.platform,
initialUserScripts: initialUserScripts, initialUserScripts: initialUserScripts,
windowId: windowId), windowId: windowId,
webViewEnvironment: webViewEnvironment?.platform,),
); );
/// Constructs a [InAppBrowser] from creation params for a specific /// Constructs a [InAppBrowser] from creation params for a specific

View File

@ -5,6 +5,7 @@ import 'dart:ui';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
import '../find_interaction/find_interaction_controller.dart'; import '../find_interaction/find_interaction_controller.dart';
import '../webview_environment/webview_environment.dart';
import 'in_app_webview_controller.dart'; import 'in_app_webview_controller.dart';
import '../pull_to_refresh/pull_to_refresh_controller.dart'; import '../pull_to_refresh/pull_to_refresh_controller.dart';
@ -42,6 +43,7 @@ class HeadlessInAppWebView {
HeadlessInAppWebView? headlessWebView, HeadlessInAppWebView? headlessWebView,
InAppWebViewKeepAlive? keepAlive, InAppWebViewKeepAlive? keepAlive,
bool? preventGestureDelay, bool? preventGestureDelay,
WebViewEnvironment? webViewEnvironment,
@Deprecated('Use onGeolocationPermissionsHidePrompt instead') @Deprecated('Use onGeolocationPermissionsHidePrompt instead')
void Function(InAppWebViewController controller)? void Function(InAppWebViewController controller)?
androidOnGeolocationPermissionsHidePrompt, androidOnGeolocationPermissionsHidePrompt,
@ -307,6 +309,7 @@ class HeadlessInAppWebView {
pullToRefreshController: pullToRefreshController?.platform, pullToRefreshController: pullToRefreshController?.platform,
findInteractionController: findInteractionController?.platform, findInteractionController: findInteractionController?.platform,
contextMenu: contextMenu, contextMenu: contextMenu,
webViewEnvironment: webViewEnvironment?.platform,
onWebViewCreated: onWebViewCreated != null onWebViewCreated: onWebViewCreated != null
? (controller) => onWebViewCreated.call(controller) ? (controller) => onWebViewCreated.call(controller)
: null, : null,

View File

@ -18,12 +18,11 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_inappwebview_platform_interface: #^1.0.10 flutter_inappwebview_platform_interface: ^1.0.10
path: ../flutter_inappwebview_platform_interface flutter_inappwebview_android: ^1.0.12
#flutter_inappwebview_android: ^1.0.12 flutter_inappwebview_ios: ^1.0.13
#flutter_inappwebview_ios: ^1.0.13 flutter_inappwebview_macos: ^1.0.11
#flutter_inappwebview_macos: ^1.0.11 flutter_inappwebview_web: ^1.0.8
#flutter_inappwebview_web: ^1.0.8
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View File

@ -19,6 +19,7 @@ import '../in_app_webview/in_app_webview_settings.dart';
import '../print_job/main.dart'; import '../print_job/main.dart';
import '../web_uri.dart'; import '../web_uri.dart';
import '../webview_environment/platform_webview_environment.dart';
import 'in_app_browser_menu_item.dart'; import 'in_app_browser_menu_item.dart';
import 'in_app_browser_settings.dart'; import 'in_app_browser_settings.dart';
import '../debug_logging_settings.dart'; import '../debug_logging_settings.dart';
@ -36,7 +37,9 @@ class PlatformInAppBrowserCreationParams {
this.pullToRefreshController, this.pullToRefreshController,
this.findInteractionController, this.findInteractionController,
this.initialUserScripts, this.initialUserScripts,
this.windowId}); this.windowId,
this.webViewEnvironment,
});
///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser.contextMenu} ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser.contextMenu}
final ContextMenu? contextMenu; final ContextMenu? contextMenu;
@ -52,6 +55,12 @@ class PlatformInAppBrowserCreationParams {
///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser.windowId} ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser.windowId}
final int? windowId; final int? windowId;
///Used create the [PlatformInAppBrowser] using the specified environment.
///
///**Officially Supported Platforms/Implementations**:
///- Windows
final PlatformWebViewEnvironment? webViewEnvironment;
} }
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser} ///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser}

View File

@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import '../inappwebview_platform.dart'; import '../inappwebview_platform.dart';
import '../types/disposable.dart'; import '../types/disposable.dart';
import '../webview_environment/platform_webview_environment.dart';
import 'platform_inappwebview_controller.dart'; import 'platform_inappwebview_controller.dart';
import 'platform_webview.dart'; import 'platform_webview.dart';
@ -17,6 +18,7 @@ class PlatformHeadlessInAppWebViewCreationParams
/// Used by the platform implementation to create a new [PlatformHeadlessInAppWebView]. /// Used by the platform implementation to create a new [PlatformHeadlessInAppWebView].
const PlatformHeadlessInAppWebViewCreationParams( const PlatformHeadlessInAppWebViewCreationParams(
{this.initialSize = const Size(-1, -1), {this.initialSize = const Size(-1, -1),
this.webViewEnvironment,
super.controllerFromPlatform, super.controllerFromPlatform,
super.windowId, super.windowId,
super.onWebViewCreated, super.onWebViewCreated,
@ -141,6 +143,12 @@ class PlatformHeadlessInAppWebViewCreationParams
///- Web ///- Web
///- MacOS ///- MacOS
final Size initialSize; final Size initialSize;
///Used create the [PlatformHeadlessInAppWebView] using the specified environment.
///
///**Officially Supported Platforms/Implementations**:
///- Windows
final PlatformWebViewEnvironment? webViewEnvironment;
} }
///{@template flutter_inappwebview_platform_interface.PlatformHeadlessInAppWebView} ///{@template flutter_inappwebview_platform_interface.PlatformHeadlessInAppWebView}

View File

@ -7,6 +7,7 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_pla
import '../find_interaction/find_interaction_controller.dart'; import '../find_interaction/find_interaction_controller.dart';
import '../in_app_webview/in_app_webview_controller.dart'; import '../in_app_webview/in_app_webview_controller.dart';
import '../webview_environment/webview_environment.dart';
/// Object specifying creation parameters for creating a [WindowsInAppBrowser]. /// Object specifying creation parameters for creating a [WindowsInAppBrowser].
/// ///
@ -21,7 +22,8 @@ class WindowsInAppBrowserCreationParams
super.pullToRefreshController, super.pullToRefreshController,
this.findInteractionController, this.findInteractionController,
super.initialUserScripts, super.initialUserScripts,
super.windowId}); super.windowId,
this.webViewEnvironment});
/// Creates a [WindowsInAppBrowserCreationParams] instance based on [PlatformInAppBrowserCreationParams]. /// Creates a [WindowsInAppBrowserCreationParams] instance based on [PlatformInAppBrowserCreationParams].
factory WindowsInAppBrowserCreationParams.fromPlatformInAppBrowserCreationParams( factory WindowsInAppBrowserCreationParams.fromPlatformInAppBrowserCreationParams(
@ -34,11 +36,15 @@ class WindowsInAppBrowserCreationParams
findInteractionController: findInteractionController:
params.findInteractionController as WindowsFindInteractionController?, params.findInteractionController as WindowsFindInteractionController?,
initialUserScripts: params.initialUserScripts, initialUserScripts: params.initialUserScripts,
windowId: params.windowId); windowId: params.windowId,
webViewEnvironment: params.webViewEnvironment as WindowsWebViewEnvironment?);
} }
@override @override
final WindowsFindInteractionController? findInteractionController; final WindowsFindInteractionController? findInteractionController;
@override
final WindowsWebViewEnvironment? webViewEnvironment;
} }
///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser} ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser}
@ -168,6 +174,7 @@ class WindowsInAppBrowser extends PlatformInAppBrowser with ChannelController {
() => initialUserScripts?.map((e) => e.toMap()).toList() ?? []); () => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
args.putIfAbsent('pullToRefreshSettings', () => pullToRefreshSettings); args.putIfAbsent('pullToRefreshSettings', () => pullToRefreshSettings);
args.putIfAbsent('menuItems', () => menuItemList); args.putIfAbsent('menuItems', () => menuItemList);
args.putIfAbsent('webViewEnvironmentId', () => _windowsParams.webViewEnvironment?.id);
return args; return args;
} }

View File

@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
import '../find_interaction/find_interaction_controller.dart'; import '../find_interaction/find_interaction_controller.dart';
import '../webview_environment/webview_environment.dart';
import 'in_app_webview_controller.dart'; import 'in_app_webview_controller.dart';
/// Object specifying creation parameters for creating a [WindowsHeadlessInAppWebView]. /// Object specifying creation parameters for creating a [WindowsHeadlessInAppWebView].
@ -18,6 +19,7 @@ class WindowsHeadlessInAppWebViewCreationParams
WindowsHeadlessInAppWebViewCreationParams( WindowsHeadlessInAppWebViewCreationParams(
{super.controllerFromPlatform, {super.controllerFromPlatform,
super.initialSize, super.initialSize,
this.webViewEnvironment,
super.windowId, super.windowId,
super.onWebViewCreated, super.onWebViewCreated,
super.onLoadStart, super.onLoadStart,
@ -133,6 +135,7 @@ class WindowsHeadlessInAppWebViewCreationParams
PlatformHeadlessInAppWebViewCreationParams params) PlatformHeadlessInAppWebViewCreationParams params)
: this( : this(
controllerFromPlatform: params.controllerFromPlatform, controllerFromPlatform: params.controllerFromPlatform,
webViewEnvironment: params.webViewEnvironment as WindowsWebViewEnvironment?,
initialSize: params.initialSize, initialSize: params.initialSize,
windowId: params.windowId, windowId: params.windowId,
onWebViewCreated: params.onWebViewCreated, onWebViewCreated: params.onWebViewCreated,
@ -242,6 +245,9 @@ class WindowsHeadlessInAppWebViewCreationParams
@override @override
final WindowsFindInteractionController? findInteractionController; final WindowsFindInteractionController? findInteractionController;
@override
final WindowsWebViewEnvironment? webViewEnvironment;
} }
///{@macro flutter_inappwebview_platform_interface.PlatformHeadlessInAppWebView} ///{@macro flutter_inappwebview_platform_interface.PlatformHeadlessInAppWebView}
@ -339,7 +345,8 @@ class WindowsHeadlessInAppWebView extends PlatformHeadlessInAppWebView
params.initialUserScripts?.map((e) => e.toMap()).toList() ?? params.initialUserScripts?.map((e) => e.toMap()).toList() ??
[], [],
'pullToRefreshSettings': pullToRefreshSettings, 'pullToRefreshSettings': pullToRefreshSettings,
'initialSize': params.initialSize.toMap() 'initialSize': params.initialSize.toMap(),
'webViewEnvironmentId': params.webViewEnvironment?.id,
}); });
try { try {
await _sharedChannel.invokeMethod('run', args); await _sharedChannel.invokeMethod('run', args);

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
import '../webview_environment/webview_environment.dart';
import 'headless_in_app_webview.dart'; import 'headless_in_app_webview.dart';
import '../find_interaction/find_interaction_controller.dart'; import '../find_interaction/find_interaction_controller.dart';
@ -23,7 +24,7 @@ class WindowsInAppWebViewWidgetCreationParams
super.keepAlive, super.keepAlive,
super.preventGestureDelay, super.preventGestureDelay,
super.windowId, super.windowId,
super.webViewEnvironment, this.webViewEnvironment,
super.onWebViewCreated, super.onWebViewCreated,
super.onLoadStart, super.onLoadStart,
super.onLoadStop, super.onLoadStop,
@ -146,7 +147,7 @@ class WindowsInAppWebViewWidgetCreationParams
keepAlive: params.keepAlive, keepAlive: params.keepAlive,
preventGestureDelay: params.preventGestureDelay, preventGestureDelay: params.preventGestureDelay,
windowId: params.windowId, windowId: params.windowId,
webViewEnvironment: params.webViewEnvironment, webViewEnvironment: params.webViewEnvironment as WindowsWebViewEnvironment?,
onWebViewCreated: params.onWebViewCreated, onWebViewCreated: params.onWebViewCreated,
onLoadStart: params.onLoadStart, onLoadStart: params.onLoadStart,
onLoadStop: params.onLoadStop, onLoadStop: params.onLoadStop,
@ -254,6 +255,9 @@ class WindowsInAppWebViewWidgetCreationParams
@override @override
final WindowsFindInteractionController? findInteractionController; final WindowsFindInteractionController? findInteractionController;
@override
final WindowsWebViewEnvironment? webViewEnvironment;
} }
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewWidget} ///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewWidget}

View File

@ -26,12 +26,7 @@ namespace flutter_inappwebview_plugin
nullptr, nullptr,
windowClass_.hInstance, nullptr); windowClass_.hInstance, nullptr);
CreateInAppWebViewEnvParams webViewEnvParams = { InAppWebView::createInAppWebViewEnv(hwnd, false, nullptr,
hwnd,
false
};
InAppWebView::createInAppWebViewEnv(webViewEnvParams, nullptr,
[=](wil::com_ptr<ICoreWebView2Environment> webViewEnv, [=](wil::com_ptr<ICoreWebView2Environment> webViewEnv,
wil::com_ptr<ICoreWebView2Controller> webViewController, wil::com_ptr<ICoreWebView2Controller> webViewController,
wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController) wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController)
@ -80,7 +75,6 @@ namespace flutter_inappwebview_plugin
if (expiresDate.has_value()) { if (expiresDate.has_value()) {
parameters["expires"] = expiresDate.value() / 1000; parameters["expires"] = expiresDate.value() / 1000;
} }
debugLog(maxAge.value());
if (maxAge.has_value()) { if (maxAge.has_value()) {
// time(NULL) represents the current unix timestamp in seconds // time(NULL) represents the current unix timestamp in seconds
parameters["expires"] = time(NULL) + maxAge.value(); parameters["expires"] = time(NULL) + maxAge.value();

View File

@ -56,7 +56,7 @@ namespace flutter_inappwebview_plugin
auto initialFile = get_optional_fl_map_value<std::string>(params, "initialFile"); auto initialFile = get_optional_fl_map_value<std::string>(params, "initialFile");
auto initialDataMap = get_optional_fl_map_value<flutter::EncodableMap>(params, "initialData"); auto initialDataMap = get_optional_fl_map_value<flutter::EncodableMap>(params, "initialData");
auto initialUserScriptList = get_optional_fl_map_value<flutter::EncodableList>(params, "initialUserScripts"); auto initialUserScriptList = get_optional_fl_map_value<flutter::EncodableList>(params, "initialUserScripts");
auto webViewEnvironmentId = get_optional_fl_map_value<std::string>(*arguments, "webViewEnvironmentId"); auto webViewEnvironmentId = get_optional_fl_map_value<std::string>(params, "webViewEnvironmentId");
RECT bounds; RECT bounds;
GetClientRect(plugin->registrar->GetView()->GetNativeWindow(), &bounds); GetClientRect(plugin->registrar->GetView()->GetNativeWindow(), &bounds);
@ -70,15 +70,10 @@ namespace flutter_inappwebview_plugin
nullptr, nullptr,
windowClass_.hInstance, nullptr); windowClass_.hInstance, nullptr);
CreateInAppWebViewEnvParams webViewEnvParams = {
hwnd,
false
};
auto webViewEnvironment = webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, webViewEnvironmentId.value()) auto webViewEnvironment = webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, webViewEnvironmentId.value())
? plugin->webViewEnvironmentManager->webViewEnvironments.at(webViewEnvironmentId.value()).get() : nullptr; ? plugin->webViewEnvironmentManager->webViewEnvironments.at(webViewEnvironmentId.value()).get() : nullptr;
InAppWebView::createInAppWebViewEnv(webViewEnvParams, webViewEnvironment, InAppWebView::createInAppWebViewEnv(hwnd, false, webViewEnvironment,
[=](wil::com_ptr<ICoreWebView2Environment> webViewEnv, [=](wil::com_ptr<ICoreWebView2Environment> webViewEnv,
wil::com_ptr<ICoreWebView2Controller> webViewController, wil::com_ptr<ICoreWebView2Controller> webViewController,
wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController) wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController)

View File

@ -42,12 +42,6 @@ namespace flutter_inappwebview_plugin
ShowWindow(m_hWnd, settings->hidden ? SW_HIDE : SW_SHOW); ShowWindow(m_hWnd, settings->hidden ? SW_HIDE : SW_SHOW);
CreateInAppWebViewEnvParams webViewEnvParams = {
m_hWnd,
false
};
InAppWebViewCreationParams webViewParams = { InAppWebViewCreationParams webViewParams = {
id, id,
params.initialWebViewSettings, params.initialWebViewSettings,
@ -57,7 +51,7 @@ namespace flutter_inappwebview_plugin
auto webViewEnvironment = params.webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, params.webViewEnvironmentId.value()) auto webViewEnvironment = params.webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, params.webViewEnvironmentId.value())
? plugin->webViewEnvironmentManager->webViewEnvironments.at(params.webViewEnvironmentId.value()).get() : nullptr; ? plugin->webViewEnvironmentManager->webViewEnvironments.at(params.webViewEnvironmentId.value()).get() : nullptr;
InAppWebView::createInAppWebViewEnv(webViewEnvParams, webViewEnvironment, InAppWebView::createInAppWebViewEnv(m_hWnd, false, webViewEnvironment,
[this, params, webViewParams](wil::com_ptr<ICoreWebView2Environment> webViewEnv, wil::com_ptr<ICoreWebView2Controller> webViewController, wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController) -> void [this, params, webViewParams](wil::com_ptr<ICoreWebView2Environment> webViewEnv, wil::com_ptr<ICoreWebView2Controller> webViewController, wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController) -> void
{ {
if (webViewEnv && webViewController) { if (webViewEnv && webViewController) {

View File

@ -26,7 +26,7 @@ namespace flutter_inappwebview_plugin
if (string_equals(methodName, "open")) { if (string_equals(methodName, "open")) {
createInAppBrowser(arguments); createInAppBrowser(arguments);
result->Success(flutter::EncodableValue(true)); result->Success(true);
} }
else if (string_equals(methodName, "openWithSystemBrowser")) { else if (string_equals(methodName, "openWithSystemBrowser")) {
auto url = get_fl_map_value<std::string>(*arguments, "url"); auto url = get_fl_map_value<std::string>(*arguments, "url");

View File

@ -57,11 +57,11 @@ namespace flutter_inappwebview_plugin
this->inAppBrowser = inAppBrowser; this->inAppBrowser = inAppBrowser;
} }
void InAppWebView::createInAppWebViewEnv(const CreateInAppWebViewEnvParams& params, const WebViewEnvironment* webViewEnvironment, std::function<void(wil::com_ptr<ICoreWebView2Environment> webViewEnv, void InAppWebView::createInAppWebViewEnv(const HWND parentWindow, const bool& willBeSurface, const WebViewEnvironment* webViewEnvironment, std::function<void(wil::com_ptr<ICoreWebView2Environment> webViewEnv,
wil::com_ptr<ICoreWebView2Controller> webViewController, wil::com_ptr<ICoreWebView2Controller> webViewController,
wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController)> completionHandler) wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController)> completionHandler)
{ {
auto callback = [params, completionHandler](HRESULT result, wil::com_ptr<ICoreWebView2Environment> env) -> HRESULT auto callback = [parentWindow, willBeSurface, completionHandler](HRESULT result, wil::com_ptr<ICoreWebView2Environment> env) -> HRESULT
{ {
if (failedAndLog(result) || !env) { if (failedAndLog(result) || !env) {
completionHandler(nullptr, nullptr, nullptr); completionHandler(nullptr, nullptr, nullptr);
@ -69,8 +69,8 @@ namespace flutter_inappwebview_plugin
} }
wil::com_ptr<ICoreWebView2Environment3> webViewEnv3; wil::com_ptr<ICoreWebView2Environment3> webViewEnv3;
if (params.willBeSurface && succeededOrLog(env->QueryInterface(IID_PPV_ARGS(&webViewEnv3)))) { if (willBeSurface && succeededOrLog(env->QueryInterface(IID_PPV_ARGS(&webViewEnv3)))) {
failedLog(webViewEnv3->CreateCoreWebView2CompositionController(params.parentWindow, Callback<ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler>( failedLog(webViewEnv3->CreateCoreWebView2CompositionController(parentWindow, Callback<ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler>(
[completionHandler, env](HRESULT result, wil::com_ptr<ICoreWebView2CompositionController> compositionController) -> HRESULT [completionHandler, env](HRESULT result, wil::com_ptr<ICoreWebView2CompositionController> compositionController) -> HRESULT
{ {
wil::com_ptr<ICoreWebView2Controller3> webViewController = compositionController.try_query<ICoreWebView2Controller3>(); wil::com_ptr<ICoreWebView2Controller3> webViewController = compositionController.try_query<ICoreWebView2Controller3>();
@ -93,7 +93,7 @@ namespace flutter_inappwebview_plugin
).Get())); ).Get()));
} }
else { else {
failedLog(env->CreateCoreWebView2Controller(params.parentWindow, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>( failedLog(env->CreateCoreWebView2Controller(parentWindow, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
[completionHandler, env](HRESULT result, wil::com_ptr<ICoreWebView2Controller> controller) -> HRESULT [completionHandler, env](HRESULT result, wil::com_ptr<ICoreWebView2Controller> controller) -> HRESULT
{ {
if (failedAndLog(result) || !controller) { if (failedAndLog(result) || !controller) {

View File

@ -12,10 +12,10 @@
#include "../plugin_scripts_js/plugin_scripts_util.h" #include "../plugin_scripts_js/plugin_scripts_util.h"
#include "../types/content_world.h" #include "../types/content_world.h"
#include "../types/navigation_action.h" #include "../types/navigation_action.h"
#include "../types/screenshot_configuration.h"
#include "../types/url_request.h" #include "../types/url_request.h"
#include "../types/web_history.h" #include "../types/web_history.h"
#include "../webview_environment/webview_environment.h" #include "../webview_environment/webview_environment.h"
#include "../types/screenshot_configuration.h"
#include "in_app_webview_settings.h" #include "in_app_webview_settings.h"
#include "user_content_controller.h" #include "user_content_controller.h"
#include "webview_channel_delegate.h" #include "webview_channel_delegate.h"
@ -83,11 +83,6 @@ namespace flutter_inappwebview_plugin
const std::optional<std::vector<std::shared_ptr<UserScript>>> initialUserScripts; const std::optional<std::vector<std::shared_ptr<UserScript>>> initialUserScripts;
}; };
struct CreateInAppWebViewEnvParams {
const HWND parentWindow;
const bool willBeSurface;
};
class InAppWebView class InAppWebView
{ {
public: public:
@ -114,7 +109,7 @@ namespace flutter_inappwebview_plugin
wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController); wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController);
~InAppWebView(); ~InAppWebView();
static void createInAppWebViewEnv(const CreateInAppWebViewEnvParams& params, const WebViewEnvironment* webViewEnvironment, std::function<void(wil::com_ptr<ICoreWebView2Environment> webViewEnv, static void createInAppWebViewEnv(const HWND parentWindow, const bool& willBeSurface, const WebViewEnvironment* webViewEnvironment, std::function<void(wil::com_ptr<ICoreWebView2Environment> webViewEnv,
wil::com_ptr<ICoreWebView2Controller> webViewController, wil::com_ptr<ICoreWebView2Controller> webViewController,
wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController)> completionHandler); wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController)> completionHandler);

View File

@ -11,8 +11,8 @@
#include "../utils/log.h" #include "../utils/log.h"
#include "../utils/string.h" #include "../utils/string.h"
#include "../utils/vector.h" #include "../utils/vector.h"
#include "in_app_webview_manager.h"
#include "../webview_environment/webview_environment_manager.h" #include "../webview_environment/webview_environment_manager.h"
#include "in_app_webview_manager.h"
namespace flutter_inappwebview_plugin namespace flutter_inappwebview_plugin
{ {
@ -95,15 +95,10 @@ namespace flutter_inappwebview_plugin
nullptr, nullptr,
windowClass_.hInstance, nullptr); windowClass_.hInstance, nullptr);
CreateInAppWebViewEnvParams webViewEnvParams = {
hwnd,
true
};
auto webViewEnvironment = webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, webViewEnvironmentId.value()) auto webViewEnvironment = webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, webViewEnvironmentId.value())
? plugin->webViewEnvironmentManager->webViewEnvironments.at(webViewEnvironmentId.value()).get() : nullptr; ? plugin->webViewEnvironmentManager->webViewEnvironments.at(webViewEnvironmentId.value()).get() : nullptr;
InAppWebView::createInAppWebViewEnv(webViewEnvParams, webViewEnvironment, InAppWebView::createInAppWebViewEnv(hwnd, true, webViewEnvironment,
[=](wil::com_ptr<ICoreWebView2Environment> webViewEnv, [=](wil::com_ptr<ICoreWebView2Environment> webViewEnv,
wil::com_ptr<ICoreWebView2Controller> webViewController, wil::com_ptr<ICoreWebView2Controller> webViewController,
wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController) wil::com_ptr<ICoreWebView2CompositionController> webViewCompositionController)
@ -147,7 +142,7 @@ namespace flutter_inappwebview_plugin
webViews.insert({ textureId, std::move(customPlatformView) }); webViews.insert({ textureId, std::move(customPlatformView) });
result_->Success(flutter::EncodableValue(textureId)); result_->Success(textureId);
} }
else { else {
result_->Error("0", "Cannot create the InAppWebView instance!"); result_->Error("0", "Cannot create the InAppWebView instance!");