From db9ff8c4e6c80b6bb4fc9d240c22e36b0669e33c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 27 Jan 2024 21:36:37 +0100 Subject: [PATCH] windows: added WebViewEnvironment support for headlessinappwebview and inappbrowser --- .../lib/headless_in_app_webview.screen.dart | 1 + .../lib/in_app_browser_example.screen.dart | 3 ++- .../Flutter/GeneratedPluginRegistrant.swift | 2 ++ flutter_inappwebview/example/pubspec.yaml | 16 ++++++++-------- .../lib/src/in_app_browser/in_app_browser.dart | 8 ++++++-- .../in_app_webview/headless_in_app_webview.dart | 3 +++ flutter_inappwebview/pubspec.yaml | 11 +++++------ .../in_app_browser/platform_in_app_browser.dart | 11 ++++++++++- .../platform_headless_in_app_webview.dart | 8 ++++++++ .../lib/src/in_app_browser/in_app_browser.dart | 11 +++++++++-- .../in_app_webview/headless_in_app_webview.dart | 9 ++++++++- .../lib/src/in_app_webview/in_app_webview.dart | 8 ++++++-- .../windows/cookie_manager.cpp | 8 +------- .../headless_in_app_webview_manager.cpp | 9 ++------- .../windows/in_app_browser/in_app_browser.cpp | 8 +------- .../in_app_browser/in_app_browser_manager.cpp | 2 +- .../windows/in_app_webview/in_app_webview.cpp | 10 +++++----- .../windows/in_app_webview/in_app_webview.h | 9 ++------- .../in_app_webview/in_app_webview_manager.cpp | 11 +++-------- 19 files changed, 83 insertions(+), 65 deletions(-) diff --git a/flutter_inappwebview/example/lib/headless_in_app_webview.screen.dart b/flutter_inappwebview/example/lib/headless_in_app_webview.screen.dart index 87e3dc20..5bfa5db1 100755 --- a/flutter_inappwebview/example/lib/headless_in_app_webview.screen.dart +++ b/flutter_inappwebview/example/lib/headless_in_app_webview.screen.dart @@ -24,6 +24,7 @@ class _HeadlessInAppWebViewExampleScreenState : WebUri("http://localhost:${Uri.base.port}/page.html"); headlessWebView = HeadlessInAppWebView( + webViewEnvironment: webViewEnvironment, initialUrlRequest: URLRequest(url: url), initialSettings: InAppWebViewSettings( isInspectable: kDebugMode, diff --git a/flutter_inappwebview/example/lib/in_app_browser_example.screen.dart b/flutter_inappwebview/example/lib/in_app_browser_example.screen.dart index 15f2bd7b..e063f85c 100755 --- a/flutter_inappwebview/example/lib/in_app_browser_example.screen.dart +++ b/flutter_inappwebview/example/lib/in_app_browser_example.screen.dart @@ -17,7 +17,8 @@ class MyInAppBrowser extends InAppBrowser { : super( windowId: windowId, initialUserScripts: initialUserScripts, - pullToRefreshController: pullToRefreshController); + pullToRefreshController: pullToRefreshController, + webViewEnvironment: webViewEnvironment,); @override Future onBrowserCreated() async { diff --git a/flutter_inappwebview/example/macos/Flutter/GeneratedPluginRegistrant.swift b/flutter_inappwebview/example/macos/Flutter/GeneratedPluginRegistrant.swift index a1cdfd0c..959e5aa0 100644 --- a/flutter_inappwebview/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/flutter_inappwebview/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,10 +5,12 @@ import FlutterMacOS import Foundation +import flutter_inappwebview_macos import path_provider_foundation import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/flutter_inappwebview/example/pubspec.yaml b/flutter_inappwebview/example/pubspec.yaml index dffe2a82..59aa16aa 100755 --- a/flutter_inappwebview/example/pubspec.yaml +++ b/flutter_inappwebview/example/pubspec.yaml @@ -35,14 +35,14 @@ dependencies: dependency_overrides: flutter_inappwebview_platform_interface: path: ../../flutter_inappwebview_platform_interface - #flutter_inappwebview_android: - # path: ../../flutter_inappwebview_android - #flutter_inappwebview_ios: - # path: ../../flutter_inappwebview_ios - #flutter_inappwebview_macos: - # path: ../../flutter_inappwebview_macos - #flutter_inappwebview_web: - # path: ../../flutter_inappwebview_web + flutter_inappwebview_android: + path: ../../flutter_inappwebview_android + flutter_inappwebview_ios: + path: ../../flutter_inappwebview_ios + flutter_inappwebview_macos: + path: ../../flutter_inappwebview_macos + flutter_inappwebview_web: + path: ../../flutter_inappwebview_web flutter_inappwebview_windows: path: ../../flutter_inappwebview_windows diff --git a/flutter_inappwebview/lib/src/in_app_browser/in_app_browser.dart b/flutter_inappwebview/lib/src/in_app_browser/in_app_browser.dart index 3393cafd..b17a68a8 100755 --- a/flutter_inappwebview/lib/src/in_app_browser/in_app_browser.dart +++ b/flutter_inappwebview/lib/src/in_app_browser/in_app_browser.dart @@ -11,6 +11,7 @@ import '../find_interaction/find_interaction_controller.dart'; import '../pull_to_refresh/main.dart'; import '../in_app_webview/in_app_webview_controller.dart'; +import '../webview_environment/webview_environment.dart'; ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser} class InAppBrowser implements PlatformInAppBrowserEvents { @@ -22,14 +23,17 @@ class InAppBrowser implements PlatformInAppBrowserEvents { PullToRefreshController? pullToRefreshController, FindInteractionController? findInteractionController, UnmodifiableListView? initialUserScripts, - int? windowId}) + int? windowId, + WebViewEnvironment? webViewEnvironment, + }) : this.fromPlatformCreationParams( PlatformInAppBrowserCreationParams( contextMenu: contextMenu, pullToRefreshController: pullToRefreshController?.platform, findInteractionController: findInteractionController?.platform, initialUserScripts: initialUserScripts, - windowId: windowId), + windowId: windowId, + webViewEnvironment: webViewEnvironment?.platform,), ); /// Constructs a [InAppBrowser] from creation params for a specific diff --git a/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart b/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart index 5f714d67..f7c21662 100644 --- a/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart @@ -5,6 +5,7 @@ import 'dart:ui'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import '../find_interaction/find_interaction_controller.dart'; +import '../webview_environment/webview_environment.dart'; import 'in_app_webview_controller.dart'; import '../pull_to_refresh/pull_to_refresh_controller.dart'; @@ -42,6 +43,7 @@ class HeadlessInAppWebView { HeadlessInAppWebView? headlessWebView, InAppWebViewKeepAlive? keepAlive, bool? preventGestureDelay, + WebViewEnvironment? webViewEnvironment, @Deprecated('Use onGeolocationPermissionsHidePrompt instead') void Function(InAppWebViewController controller)? androidOnGeolocationPermissionsHidePrompt, @@ -307,6 +309,7 @@ class HeadlessInAppWebView { pullToRefreshController: pullToRefreshController?.platform, findInteractionController: findInteractionController?.platform, contextMenu: contextMenu, + webViewEnvironment: webViewEnvironment?.platform, onWebViewCreated: onWebViewCreated != null ? (controller) => onWebViewCreated.call(controller) : null, diff --git a/flutter_inappwebview/pubspec.yaml b/flutter_inappwebview/pubspec.yaml index 03b3d522..ef480d4a 100755 --- a/flutter_inappwebview/pubspec.yaml +++ b/flutter_inappwebview/pubspec.yaml @@ -18,12 +18,11 @@ environment: dependencies: flutter: sdk: flutter - flutter_inappwebview_platform_interface: #^1.0.10 - path: ../flutter_inappwebview_platform_interface - #flutter_inappwebview_android: ^1.0.12 - #flutter_inappwebview_ios: ^1.0.13 - #flutter_inappwebview_macos: ^1.0.11 - #flutter_inappwebview_web: ^1.0.8 + flutter_inappwebview_platform_interface: ^1.0.10 + flutter_inappwebview_android: ^1.0.12 + flutter_inappwebview_ios: ^1.0.13 + flutter_inappwebview_macos: ^1.0.11 + flutter_inappwebview_web: ^1.0.8 dev_dependencies: flutter_test: diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart index b2567865..c1ebeefe 100755 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart @@ -19,6 +19,7 @@ import '../in_app_webview/in_app_webview_settings.dart'; import '../print_job/main.dart'; import '../web_uri.dart'; +import '../webview_environment/platform_webview_environment.dart'; import 'in_app_browser_menu_item.dart'; import 'in_app_browser_settings.dart'; import '../debug_logging_settings.dart'; @@ -36,7 +37,9 @@ class PlatformInAppBrowserCreationParams { this.pullToRefreshController, this.findInteractionController, this.initialUserScripts, - this.windowId}); + this.windowId, + this.webViewEnvironment, + }); ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser.contextMenu} final ContextMenu? contextMenu; @@ -52,6 +55,12 @@ class PlatformInAppBrowserCreationParams { ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser.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} diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_headless_in_app_webview.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_headless_in_app_webview.dart index b953d3b4..9fd5c7ab 100644 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_headless_in_app_webview.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_headless_in_app_webview.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import '../inappwebview_platform.dart'; import '../types/disposable.dart'; +import '../webview_environment/platform_webview_environment.dart'; import 'platform_inappwebview_controller.dart'; import 'platform_webview.dart'; @@ -17,6 +18,7 @@ class PlatformHeadlessInAppWebViewCreationParams /// Used by the platform implementation to create a new [PlatformHeadlessInAppWebView]. const PlatformHeadlessInAppWebViewCreationParams( {this.initialSize = const Size(-1, -1), + this.webViewEnvironment, super.controllerFromPlatform, super.windowId, super.onWebViewCreated, @@ -141,6 +143,12 @@ class PlatformHeadlessInAppWebViewCreationParams ///- Web ///- MacOS 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} diff --git a/flutter_inappwebview_windows/lib/src/in_app_browser/in_app_browser.dart b/flutter_inappwebview_windows/lib/src/in_app_browser/in_app_browser.dart index 4c1f892d..7920c613 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_browser/in_app_browser.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_browser/in_app_browser.dart @@ -7,6 +7,7 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_pla import '../find_interaction/find_interaction_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]. /// @@ -21,7 +22,8 @@ class WindowsInAppBrowserCreationParams super.pullToRefreshController, this.findInteractionController, super.initialUserScripts, - super.windowId}); + super.windowId, + this.webViewEnvironment}); /// Creates a [WindowsInAppBrowserCreationParams] instance based on [PlatformInAppBrowserCreationParams]. factory WindowsInAppBrowserCreationParams.fromPlatformInAppBrowserCreationParams( @@ -34,11 +36,15 @@ class WindowsInAppBrowserCreationParams findInteractionController: params.findInteractionController as WindowsFindInteractionController?, initialUserScripts: params.initialUserScripts, - windowId: params.windowId); + windowId: params.windowId, + webViewEnvironment: params.webViewEnvironment as WindowsWebViewEnvironment?); } @override final WindowsFindInteractionController? findInteractionController; + + @override + final WindowsWebViewEnvironment? webViewEnvironment; } ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser} @@ -168,6 +174,7 @@ class WindowsInAppBrowser extends PlatformInAppBrowser with ChannelController { () => initialUserScripts?.map((e) => e.toMap()).toList() ?? []); args.putIfAbsent('pullToRefreshSettings', () => pullToRefreshSettings); args.putIfAbsent('menuItems', () => menuItemList); + args.putIfAbsent('webViewEnvironmentId', () => _windowsParams.webViewEnvironment?.id); return args; } diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart index 0f6299a7..1bede448 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart @@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import '../find_interaction/find_interaction_controller.dart'; +import '../webview_environment/webview_environment.dart'; import 'in_app_webview_controller.dart'; /// Object specifying creation parameters for creating a [WindowsHeadlessInAppWebView]. @@ -18,6 +19,7 @@ class WindowsHeadlessInAppWebViewCreationParams WindowsHeadlessInAppWebViewCreationParams( {super.controllerFromPlatform, super.initialSize, + this.webViewEnvironment, super.windowId, super.onWebViewCreated, super.onLoadStart, @@ -133,6 +135,7 @@ class WindowsHeadlessInAppWebViewCreationParams PlatformHeadlessInAppWebViewCreationParams params) : this( controllerFromPlatform: params.controllerFromPlatform, + webViewEnvironment: params.webViewEnvironment as WindowsWebViewEnvironment?, initialSize: params.initialSize, windowId: params.windowId, onWebViewCreated: params.onWebViewCreated, @@ -242,6 +245,9 @@ class WindowsHeadlessInAppWebViewCreationParams @override final WindowsFindInteractionController? findInteractionController; + + @override + final WindowsWebViewEnvironment? webViewEnvironment; } ///{@macro flutter_inappwebview_platform_interface.PlatformHeadlessInAppWebView} @@ -339,7 +345,8 @@ class WindowsHeadlessInAppWebView extends PlatformHeadlessInAppWebView params.initialUserScripts?.map((e) => e.toMap()).toList() ?? [], 'pullToRefreshSettings': pullToRefreshSettings, - 'initialSize': params.initialSize.toMap() + 'initialSize': params.initialSize.toMap(), + 'webViewEnvironmentId': params.webViewEnvironment?.id, }); try { await _sharedChannel.invokeMethod('run', args); diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart index df3d744a..61f44880 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.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 '../find_interaction/find_interaction_controller.dart'; @@ -23,7 +24,7 @@ class WindowsInAppWebViewWidgetCreationParams super.keepAlive, super.preventGestureDelay, super.windowId, - super.webViewEnvironment, + this.webViewEnvironment, super.onWebViewCreated, super.onLoadStart, super.onLoadStop, @@ -146,7 +147,7 @@ class WindowsInAppWebViewWidgetCreationParams keepAlive: params.keepAlive, preventGestureDelay: params.preventGestureDelay, windowId: params.windowId, - webViewEnvironment: params.webViewEnvironment, + webViewEnvironment: params.webViewEnvironment as WindowsWebViewEnvironment?, onWebViewCreated: params.onWebViewCreated, onLoadStart: params.onLoadStart, onLoadStop: params.onLoadStop, @@ -254,6 +255,9 @@ class WindowsInAppWebViewWidgetCreationParams @override final WindowsFindInteractionController? findInteractionController; + + @override + final WindowsWebViewEnvironment? webViewEnvironment; } ///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewWidget} diff --git a/flutter_inappwebview_windows/windows/cookie_manager.cpp b/flutter_inappwebview_windows/windows/cookie_manager.cpp index d962755d..23500931 100644 --- a/flutter_inappwebview_windows/windows/cookie_manager.cpp +++ b/flutter_inappwebview_windows/windows/cookie_manager.cpp @@ -26,12 +26,7 @@ namespace flutter_inappwebview_plugin nullptr, windowClass_.hInstance, nullptr); - CreateInAppWebViewEnvParams webViewEnvParams = { - hwnd, - false - }; - - InAppWebView::createInAppWebViewEnv(webViewEnvParams, nullptr, + InAppWebView::createInAppWebViewEnv(hwnd, false, nullptr, [=](wil::com_ptr webViewEnv, wil::com_ptr webViewController, wil::com_ptr webViewCompositionController) @@ -80,7 +75,6 @@ namespace flutter_inappwebview_plugin if (expiresDate.has_value()) { parameters["expires"] = expiresDate.value() / 1000; } - debugLog(maxAge.value()); if (maxAge.has_value()) { // time(NULL) represents the current unix timestamp in seconds parameters["expires"] = time(NULL) + maxAge.value(); diff --git a/flutter_inappwebview_windows/windows/headless_in_app_webview/headless_in_app_webview_manager.cpp b/flutter_inappwebview_windows/windows/headless_in_app_webview/headless_in_app_webview_manager.cpp index 9c6e3d9e..ff235315 100644 --- a/flutter_inappwebview_windows/windows/headless_in_app_webview/headless_in_app_webview_manager.cpp +++ b/flutter_inappwebview_windows/windows/headless_in_app_webview/headless_in_app_webview_manager.cpp @@ -56,7 +56,7 @@ namespace flutter_inappwebview_plugin auto initialFile = get_optional_fl_map_value(params, "initialFile"); auto initialDataMap = get_optional_fl_map_value(params, "initialData"); auto initialUserScriptList = get_optional_fl_map_value(params, "initialUserScripts"); - auto webViewEnvironmentId = get_optional_fl_map_value(*arguments, "webViewEnvironmentId"); + auto webViewEnvironmentId = get_optional_fl_map_value(params, "webViewEnvironmentId"); RECT bounds; GetClientRect(plugin->registrar->GetView()->GetNativeWindow(), &bounds); @@ -70,15 +70,10 @@ namespace flutter_inappwebview_plugin nullptr, windowClass_.hInstance, nullptr); - CreateInAppWebViewEnvParams webViewEnvParams = { - hwnd, - false - }; - auto webViewEnvironment = webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, webViewEnvironmentId.value()) ? plugin->webViewEnvironmentManager->webViewEnvironments.at(webViewEnvironmentId.value()).get() : nullptr; - InAppWebView::createInAppWebViewEnv(webViewEnvParams, webViewEnvironment, + InAppWebView::createInAppWebViewEnv(hwnd, false, webViewEnvironment, [=](wil::com_ptr webViewEnv, wil::com_ptr webViewController, wil::com_ptr webViewCompositionController) diff --git a/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser.cpp b/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser.cpp index baa749a5..682c4aa5 100644 --- a/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser.cpp +++ b/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser.cpp @@ -42,12 +42,6 @@ namespace flutter_inappwebview_plugin ShowWindow(m_hWnd, settings->hidden ? SW_HIDE : SW_SHOW); - CreateInAppWebViewEnvParams webViewEnvParams = { - m_hWnd, - false - }; - - InAppWebViewCreationParams webViewParams = { id, params.initialWebViewSettings, @@ -57,7 +51,7 @@ namespace flutter_inappwebview_plugin auto webViewEnvironment = params.webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, params.webViewEnvironmentId.value()) ? 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 webViewEnv, wil::com_ptr webViewController, wil::com_ptr webViewCompositionController) -> void { if (webViewEnv && webViewController) { diff --git a/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser_manager.cpp b/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser_manager.cpp index b414c806..46130067 100644 --- a/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser_manager.cpp +++ b/flutter_inappwebview_windows/windows/in_app_browser/in_app_browser_manager.cpp @@ -26,7 +26,7 @@ namespace flutter_inappwebview_plugin if (string_equals(methodName, "open")) { createInAppBrowser(arguments); - result->Success(flutter::EncodableValue(true)); + result->Success(true); } else if (string_equals(methodName, "openWithSystemBrowser")) { auto url = get_fl_map_value(*arguments, "url"); diff --git a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp index 530dc7a5..9540048b 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp +++ b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp @@ -57,11 +57,11 @@ namespace flutter_inappwebview_plugin this->inAppBrowser = inAppBrowser; } - void InAppWebView::createInAppWebViewEnv(const CreateInAppWebViewEnvParams& params, const WebViewEnvironment* webViewEnvironment, std::function webViewEnv, + void InAppWebView::createInAppWebViewEnv(const HWND parentWindow, const bool& willBeSurface, const WebViewEnvironment* webViewEnvironment, std::function webViewEnv, wil::com_ptr webViewController, wil::com_ptr webViewCompositionController)> completionHandler) { - auto callback = [params, completionHandler](HRESULT result, wil::com_ptr env) -> HRESULT + auto callback = [parentWindow, willBeSurface, completionHandler](HRESULT result, wil::com_ptr env) -> HRESULT { if (failedAndLog(result) || !env) { completionHandler(nullptr, nullptr, nullptr); @@ -69,8 +69,8 @@ namespace flutter_inappwebview_plugin } wil::com_ptr webViewEnv3; - if (params.willBeSurface && succeededOrLog(env->QueryInterface(IID_PPV_ARGS(&webViewEnv3)))) { - failedLog(webViewEnv3->CreateCoreWebView2CompositionController(params.parentWindow, Callback( + if (willBeSurface && succeededOrLog(env->QueryInterface(IID_PPV_ARGS(&webViewEnv3)))) { + failedLog(webViewEnv3->CreateCoreWebView2CompositionController(parentWindow, Callback( [completionHandler, env](HRESULT result, wil::com_ptr compositionController) -> HRESULT { wil::com_ptr webViewController = compositionController.try_query(); @@ -93,7 +93,7 @@ namespace flutter_inappwebview_plugin ).Get())); } else { - failedLog(env->CreateCoreWebView2Controller(params.parentWindow, Callback( + failedLog(env->CreateCoreWebView2Controller(parentWindow, Callback( [completionHandler, env](HRESULT result, wil::com_ptr controller) -> HRESULT { if (failedAndLog(result) || !controller) { diff --git a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h index dfc0082d..3caf70ca 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h +++ b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h @@ -12,10 +12,10 @@ #include "../plugin_scripts_js/plugin_scripts_util.h" #include "../types/content_world.h" #include "../types/navigation_action.h" +#include "../types/screenshot_configuration.h" #include "../types/url_request.h" #include "../types/web_history.h" #include "../webview_environment/webview_environment.h" -#include "../types/screenshot_configuration.h" #include "in_app_webview_settings.h" #include "user_content_controller.h" #include "webview_channel_delegate.h" @@ -83,11 +83,6 @@ namespace flutter_inappwebview_plugin const std::optional>> initialUserScripts; }; - struct CreateInAppWebViewEnvParams { - const HWND parentWindow; - const bool willBeSurface; - }; - class InAppWebView { public: @@ -114,7 +109,7 @@ namespace flutter_inappwebview_plugin wil::com_ptr webViewCompositionController); ~InAppWebView(); - static void createInAppWebViewEnv(const CreateInAppWebViewEnvParams& params, const WebViewEnvironment* webViewEnvironment, std::function webViewEnv, + static void createInAppWebViewEnv(const HWND parentWindow, const bool& willBeSurface, const WebViewEnvironment* webViewEnvironment, std::function webViewEnv, wil::com_ptr webViewController, wil::com_ptr webViewCompositionController)> completionHandler); diff --git a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp index f3ebce7e..173e85a6 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp +++ b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp @@ -11,8 +11,8 @@ #include "../utils/log.h" #include "../utils/string.h" #include "../utils/vector.h" -#include "in_app_webview_manager.h" #include "../webview_environment/webview_environment_manager.h" +#include "in_app_webview_manager.h" namespace flutter_inappwebview_plugin { @@ -95,15 +95,10 @@ namespace flutter_inappwebview_plugin nullptr, windowClass_.hInstance, nullptr); - CreateInAppWebViewEnvParams webViewEnvParams = { - hwnd, - true - }; - auto webViewEnvironment = webViewEnvironmentId.has_value() && map_contains(plugin->webViewEnvironmentManager->webViewEnvironments, webViewEnvironmentId.value()) ? plugin->webViewEnvironmentManager->webViewEnvironments.at(webViewEnvironmentId.value()).get() : nullptr; - InAppWebView::createInAppWebViewEnv(webViewEnvParams, webViewEnvironment, + InAppWebView::createInAppWebViewEnv(hwnd, true, webViewEnvironment, [=](wil::com_ptr webViewEnv, wil::com_ptr webViewController, wil::com_ptr webViewCompositionController) @@ -147,7 +142,7 @@ namespace flutter_inappwebview_plugin webViews.insert({ textureId, std::move(customPlatformView) }); - result_->Success(flutter::EncodableValue(textureId)); + result_->Success(textureId); } else { result_->Error("0", "Cannot create the InAppWebView instance!");