#include #include #include #include "../in_app_webview/in_app_webview_settings.h" #include "../utils/flutter.h" #include "../utils/log.h" #include "../utils/string.h" #include "../utils/vector.h" #include "webview_environment_manager.h" namespace flutter_inappwebview_plugin { WebViewEnvironmentManager::WebViewEnvironmentManager(const FlutterInappwebviewWindowsPlugin* plugin) : plugin(plugin), ChannelDelegate(plugin->registrar->messenger(), WebViewEnvironmentManager::METHOD_CHANNEL_NAME) {} void WebViewEnvironmentManager::HandleMethodCall(const flutter::MethodCall& method_call, std::unique_ptr> result) { auto* arguments = std::get_if(method_call.arguments()); auto& methodName = method_call.method_name(); if (string_equals(methodName, "create")) { auto id = get_fl_map_value(*arguments, "id"); auto settingsMap = get_optional_fl_map_value(*arguments, "settings"); auto settings = settingsMap.has_value() ? std::make_unique(settingsMap.value()) : nullptr; createWebViewEnvironment(id, std::move(settings), std::move(result)); } else { result->NotImplemented(); } } void WebViewEnvironmentManager::createWebViewEnvironment(const std::string& id, std::unique_ptr settings, std::unique_ptr> result) { auto result_ = std::shared_ptr>(std::move(result)); auto webViewEnvironment = std::make_unique(plugin, id); webViewEnvironment->create(std::move(settings), [this, id, result_](HRESULT errorCode) { if (succeededOrLog(errorCode)) { result_->Success(true); } else { result_->Error("0", "Cannot create WebViewEnvironment: " + getHRMessage(errorCode)); if (map_contains(webViewEnvironments, id)) { webViewEnvironments.erase(id); } } }); webViewEnvironments.insert({ id, std::move(webViewEnvironment) }); } WebViewEnvironmentManager::~WebViewEnvironmentManager() { debugLog("dealloc WebViewEnvironmentManager"); webViewEnvironments.clear(); plugin = nullptr; } }