windows: updated webview and browser creation params, added support for openWithSystemBrowser
This commit is contained in:
parent
a4c044a0f1
commit
b27036e59b
|
@ -83,29 +83,53 @@ abstract class PlatformInAppBrowser extends PlatformInterface
|
||||||
|
|
||||||
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.contextMenu}
|
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.contextMenu}
|
||||||
///Context menu used by the browser. It should be set before opening the browser.
|
///Context menu used by the browser. It should be set before opening the browser.
|
||||||
|
///
|
||||||
|
///**Officially Supported Platforms/Implementations**:
|
||||||
|
///- Android native WebView
|
||||||
|
///- iOS
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
ContextMenu? get contextMenu => params.contextMenu;
|
ContextMenu? get contextMenu => params.contextMenu;
|
||||||
|
|
||||||
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.pullToRefreshController}
|
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.pullToRefreshController}
|
||||||
///Represents the pull-to-refresh feature controller.
|
///Represents the pull-to-refresh feature controller.
|
||||||
|
///
|
||||||
|
///**Officially Supported Platforms/Implementations**:
|
||||||
|
///- Android native WebView
|
||||||
|
///- iOS
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
PlatformPullToRefreshController? get pullToRefreshController =>
|
PlatformPullToRefreshController? get pullToRefreshController =>
|
||||||
params.pullToRefreshController;
|
params.pullToRefreshController;
|
||||||
|
|
||||||
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.findInteractionController}
|
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.findInteractionController}
|
||||||
///Represents the find interaction feature controller.
|
///Represents the find interaction feature controller.
|
||||||
|
///
|
||||||
|
///**Officially Supported Platforms/Implementations**:
|
||||||
|
///- Android native WebView
|
||||||
|
///- iOS
|
||||||
|
///- MacOS
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
PlatformFindInteractionController? get findInteractionController =>
|
PlatformFindInteractionController? get findInteractionController =>
|
||||||
params.findInteractionController;
|
params.findInteractionController;
|
||||||
|
|
||||||
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.initialUserScripts}
|
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.initialUserScripts}
|
||||||
///Initial list of user scripts to be loaded at start or end of a page loading.
|
///Initial list of user scripts to be loaded at start or end of a page loading.
|
||||||
|
///
|
||||||
|
///**Officially Supported Platforms/Implementations**:
|
||||||
|
///- Android native WebView
|
||||||
|
///- iOS
|
||||||
|
///- MacOS
|
||||||
|
///- Windows
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
UnmodifiableListView<UserScript>? get initialUserScripts =>
|
UnmodifiableListView<UserScript>? get initialUserScripts =>
|
||||||
params.initialUserScripts;
|
params.initialUserScripts;
|
||||||
|
|
||||||
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.windowId}
|
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.windowId}
|
||||||
///The window id of a [CreateWindowAction.windowId].
|
///The window id of a [CreateWindowAction.windowId].
|
||||||
|
///
|
||||||
|
///**Officially Supported Platforms/Implementations**:
|
||||||
|
///- Android native WebView
|
||||||
|
///- iOS
|
||||||
|
///- MacOS
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
int? get windowId => params.windowId;
|
int? get windowId => params.windowId;
|
||||||
|
|
||||||
|
@ -227,6 +251,7 @@ abstract class PlatformInAppBrowser extends PlatformInterface
|
||||||
///- Android native WebView
|
///- Android native WebView
|
||||||
///- iOS
|
///- iOS
|
||||||
///- MacOS
|
///- MacOS
|
||||||
|
///- Windows
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
Future<void> openFile(
|
Future<void> openFile(
|
||||||
{required String assetFilePath,
|
{required String assetFilePath,
|
||||||
|
@ -254,6 +279,7 @@ abstract class PlatformInAppBrowser extends PlatformInterface
|
||||||
///- Android native WebView
|
///- Android native WebView
|
||||||
///- iOS
|
///- iOS
|
||||||
///- MacOS
|
///- MacOS
|
||||||
|
///- Windows
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
Future<void> openData(
|
Future<void> openData(
|
||||||
{required String data,
|
{required String data,
|
||||||
|
@ -276,6 +302,7 @@ abstract class PlatformInAppBrowser extends PlatformInterface
|
||||||
///- Android native WebView
|
///- Android native WebView
|
||||||
///- iOS
|
///- iOS
|
||||||
///- MacOS
|
///- MacOS
|
||||||
|
///- Windows
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
Future<void> openWithSystemBrowser({required WebUri url}) {
|
Future<void> openWithSystemBrowser({required WebUri url}) {
|
||||||
throw UnimplementedError(
|
throw UnimplementedError(
|
||||||
|
|
|
@ -1124,6 +1124,7 @@ class PlatformWebViewCreationParams<T> {
|
||||||
///- Android native WebView
|
///- Android native WebView
|
||||||
///- iOS
|
///- iOS
|
||||||
///- MacOS
|
///- MacOS
|
||||||
|
///- Windows
|
||||||
///{@endtemplate}
|
///{@endtemplate}
|
||||||
final UnmodifiableListView<UserScript>? initialUserScripts;
|
final UnmodifiableListView<UserScript>? initialUserScripts;
|
||||||
|
|
||||||
|
|
|
@ -315,9 +315,7 @@ class WindowsInAppWebViewWidget extends PlatformInAppWebViewWidget {
|
||||||
: null,
|
: null,
|
||||||
'initialUserScripts':
|
'initialUserScripts':
|
||||||
params.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
|
params.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
|
||||||
'pullToRefreshSettings': pullToRefreshSettings,
|
|
||||||
'keepAliveId': params.keepAlive?.id,
|
'keepAliveId': params.keepAlive?.id,
|
||||||
'preventGestureDelay': params.preventGestureDelay
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ namespace flutter_inappwebview_plugin
|
||||||
: plugin(plugin),
|
: plugin(plugin),
|
||||||
m_hInstance(GetModuleHandle(nullptr)),
|
m_hInstance(GetModuleHandle(nullptr)),
|
||||||
id(params.id),
|
id(params.id),
|
||||||
initialUrlRequest(params.urlRequest),
|
|
||||||
settings(params.initialSettings),
|
settings(params.initialSettings),
|
||||||
channelDelegate(std::make_unique<InAppBrowserChannelDelegate>(id, plugin->registrar->messenger()))
|
channelDelegate(std::make_unique<InAppBrowserChannelDelegate>(id, plugin->registrar->messenger()))
|
||||||
{
|
{
|
||||||
|
@ -26,29 +25,30 @@ namespace flutter_inappwebview_plugin
|
||||||
RegisterClass(&wndClass);
|
RegisterClass(&wndClass);
|
||||||
|
|
||||||
m_hWnd = CreateWindowEx(
|
m_hWnd = CreateWindowEx(
|
||||||
0, // Optional window styles.
|
0, // Optional window styles.
|
||||||
wndClass.lpszClassName, // Window class
|
wndClass.lpszClassName, // Window class
|
||||||
L"", // Window text
|
L"", // Window text
|
||||||
WS_OVERLAPPEDWINDOW, // Window style
|
WS_OVERLAPPEDWINDOW, // Window style
|
||||||
|
|
||||||
// Size and position
|
// Size and position
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
|
|
||||||
NULL, // Parent window
|
NULL, // Parent window
|
||||||
NULL, // Menu
|
NULL, // Menu
|
||||||
wndClass.hInstance,// Instance handle
|
wndClass.hInstance, // Instance handle
|
||||||
this // Additional application data
|
this // Additional application data
|
||||||
);
|
);
|
||||||
|
|
||||||
ShowWindow(m_hWnd, settings->hidden ? SW_HIDE : SW_SHOW);
|
ShowWindow(m_hWnd, settings->hidden ? SW_HIDE : SW_SHOW);
|
||||||
|
|
||||||
InAppWebViewCreationParams webViewParams = {
|
InAppWebViewCreationParams webViewParams = {
|
||||||
id,
|
id,
|
||||||
params.initialWebViewSettings
|
params.initialWebViewSettings,
|
||||||
|
params.initialUserScripts
|
||||||
};
|
};
|
||||||
|
|
||||||
InAppWebView::createInAppWebViewEnv(m_hWnd, false,
|
InAppWebView::createInAppWebViewEnv(m_hWnd, false,
|
||||||
[this, 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) {
|
||||||
webView = std::make_unique<InAppWebView>(this, this->plugin, webViewParams, m_hWnd, std::move(webViewEnv), std::move(webViewController), nullptr);
|
webView = std::make_unique<InAppWebView>(this, this->plugin, webViewParams, m_hWnd, std::move(webViewEnv), std::move(webViewController), nullptr);
|
||||||
|
@ -58,8 +58,14 @@ namespace flutter_inappwebview_plugin
|
||||||
channelDelegate->onBrowserCreated();
|
channelDelegate->onBrowserCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialUrlRequest.has_value()) {
|
if (params.urlRequest.has_value()) {
|
||||||
webView->loadUrl(initialUrlRequest.value());
|
webView->loadUrl(params.urlRequest.value());
|
||||||
|
}
|
||||||
|
else if (params.assetFilePath.has_value()) {
|
||||||
|
webView->loadFile(params.assetFilePath.value());
|
||||||
|
}
|
||||||
|
else if (params.data.has_value()) {
|
||||||
|
webView->loadData(params.data.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -19,8 +19,11 @@ namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
const std::string id;
|
const std::string id;
|
||||||
const std::optional<std::shared_ptr<URLRequest>> urlRequest;
|
const std::optional<std::shared_ptr<URLRequest>> urlRequest;
|
||||||
|
const std::optional<std::string> assetFilePath;
|
||||||
|
const std::optional<std::string> data;
|
||||||
const std::shared_ptr<InAppBrowserSettings> initialSettings;
|
const std::shared_ptr<InAppBrowserSettings> initialSettings;
|
||||||
const std::shared_ptr<InAppWebViewSettings> initialWebViewSettings;
|
const std::shared_ptr<InAppWebViewSettings> initialWebViewSettings;
|
||||||
|
const std::optional<std::vector<std::shared_ptr<UserScript>>> initialUserScripts;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InAppBrowser {
|
class InAppBrowser {
|
||||||
|
@ -35,7 +38,6 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
const FlutterInappwebviewWindowsPlugin* plugin;
|
const FlutterInappwebviewWindowsPlugin* plugin;
|
||||||
const std::string id;
|
const std::string id;
|
||||||
const std::optional<std::shared_ptr<URLRequest>> initialUrlRequest;
|
|
||||||
std::unique_ptr<InAppWebView> webView;
|
std::unique_ptr<InAppWebView> webView;
|
||||||
std::unique_ptr<InAppBrowserChannelDelegate> channelDelegate;
|
std::unique_ptr<InAppBrowserChannelDelegate> channelDelegate;
|
||||||
const std::shared_ptr<InAppBrowserSettings> settings;
|
const std::shared_ptr<InAppBrowserSettings> settings;
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
#include <flutter/method_channel.h>
|
#include <flutter/method_channel.h>
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
#include "../in_app_webview/in_app_webview_settings.h"
|
#include "../in_app_webview/in_app_webview_settings.h"
|
||||||
#include "../types/url_request.h"
|
#include "../types/url_request.h"
|
||||||
|
#include "../types/user_script.h"
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
#include "../utils/log.h"
|
#include "../utils/log.h"
|
||||||
|
#include "../utils/string.h"
|
||||||
|
#include "../utils/vector.h"
|
||||||
#include "in_app_browser_manager.h"
|
#include "in_app_browser_manager.h"
|
||||||
#include "in_app_browser_settings.h"
|
#include "in_app_browser_settings.h"
|
||||||
|
|
||||||
|
@ -17,31 +21,56 @@ namespace flutter_inappwebview_plugin
|
||||||
void InAppBrowserManager::HandleMethodCall(const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
void InAppBrowserManager::HandleMethodCall(const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
||||||
{
|
{
|
||||||
if (method_call.method_name().compare("open") == 0) {
|
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
|
||||||
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
|
auto& methodName = method_call.method_name();
|
||||||
createInAppWebView(arguments);
|
|
||||||
|
if (string_equals(methodName, "open")) {
|
||||||
|
createInAppBrowser(arguments);
|
||||||
result->Success(flutter::EncodableValue(true));
|
result->Success(flutter::EncodableValue(true));
|
||||||
}
|
}
|
||||||
|
else if (string_equals(methodName, "openWithSystemBrowser")) {
|
||||||
|
auto url = get_fl_map_value<std::string>(*arguments, "url");
|
||||||
|
|
||||||
|
int status = static_cast<int>(reinterpret_cast<INT_PTR>(
|
||||||
|
ShellExecute(nullptr, TEXT("open"), ansi_to_wide(url).c_str(),
|
||||||
|
nullptr, nullptr, SW_SHOWNORMAL)));
|
||||||
|
|
||||||
|
// Anything >32 indicates success.
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea#return-value
|
||||||
|
if (status <= 32) {
|
||||||
|
std::cerr << "Failed to open " << url << ": ShellExecute error code " << status << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
result->NotImplemented();
|
result->NotImplemented();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InAppBrowserManager::createInAppWebView(const flutter::EncodableMap* arguments)
|
void InAppBrowserManager::createInAppBrowser(const flutter::EncodableMap* arguments)
|
||||||
{
|
{
|
||||||
auto id = get_fl_map_value<std::string>(*arguments, "id");
|
auto id = get_fl_map_value<std::string>(*arguments, "id");
|
||||||
auto urlRequestMap = get_optional_fl_map_value<flutter::EncodableMap>(*arguments, "urlRequest");
|
auto urlRequestMap = get_optional_fl_map_value<flutter::EncodableMap>(*arguments, "urlRequest");
|
||||||
|
auto assetFilePath = get_optional_fl_map_value<std::string>(*arguments, "assetFilePath");
|
||||||
|
auto data = get_optional_fl_map_value<std::string>(*arguments, "data");
|
||||||
|
auto initialUserScriptList = get_optional_fl_map_value<flutter::EncodableList>(*arguments, "initialUserScripts");
|
||||||
|
|
||||||
std::optional<std::shared_ptr<URLRequest>> urlRequest = urlRequestMap.has_value() ? std::make_shared<URLRequest>(urlRequestMap.value()) : std::optional<std::shared_ptr<URLRequest>>{};
|
std::optional<std::shared_ptr<URLRequest>> urlRequest = urlRequestMap.has_value() ? std::make_shared<URLRequest>(urlRequestMap.value()) : std::optional<std::shared_ptr<URLRequest>>{};
|
||||||
|
|
||||||
auto settingsMap = get_fl_map_value<flutter::EncodableMap>(*arguments, "settings");
|
auto settingsMap = get_fl_map_value<flutter::EncodableMap>(*arguments, "settings");
|
||||||
auto initialSettings = std::make_unique<InAppBrowserSettings>(settingsMap);
|
auto initialSettings = std::make_unique<InAppBrowserSettings>(settingsMap);
|
||||||
auto initialWebViewSettings = std::make_unique<InAppWebViewSettings>(settingsMap);
|
auto initialWebViewSettings = std::make_unique<InAppWebViewSettings>(settingsMap);
|
||||||
|
std::optional<std::vector<std::shared_ptr<UserScript>>> initialUserScripts = initialUserScriptList.has_value() ?
|
||||||
|
functional_map(initialUserScriptList.value(), [](const flutter::EncodableValue& map) { return std::make_shared<UserScript>(std::get<flutter::EncodableMap>(map)); }) :
|
||||||
|
std::optional<std::vector<std::shared_ptr<UserScript>>>{};
|
||||||
|
|
||||||
InAppBrowserCreationParams params = {
|
InAppBrowserCreationParams params = {
|
||||||
id,
|
id,
|
||||||
urlRequest,
|
urlRequest,
|
||||||
|
assetFilePath,
|
||||||
|
data,
|
||||||
std::move(initialSettings),
|
std::move(initialSettings),
|
||||||
std::move(initialWebViewSettings)
|
std::move(initialWebViewSettings),
|
||||||
|
initialUserScripts
|
||||||
};
|
};
|
||||||
|
|
||||||
auto inAppBrowser = std::make_unique<InAppBrowser>(plugin, params);
|
auto inAppBrowser = std::make_unique<InAppBrowser>(plugin, params);
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace flutter_inappwebview_plugin
|
||||||
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||||
|
|
||||||
void createInAppWebView(const flutter::EncodableMap* arguments);
|
void createInAppBrowser(const flutter::EncodableMap* arguments);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_MANAGER_H_
|
#endif //FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_MANAGER_H_
|
|
@ -44,7 +44,7 @@ namespace flutter_inappwebview_plugin
|
||||||
this->webViewController->put_Bounds(bounds);
|
this->webViewController->put_Bounds(bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare();
|
prepare(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
InAppWebView::InAppWebView(InAppBrowser* inAppBrowser, const FlutterInappwebviewWindowsPlugin* plugin, const InAppWebViewCreationParams& params, const HWND parentWindow, wil::com_ptr<ICoreWebView2Environment> webViewEnv,
|
InAppWebView::InAppWebView(InAppBrowser* inAppBrowser, const FlutterInappwebviewWindowsPlugin* plugin, const InAppWebViewCreationParams& params, const HWND parentWindow, wil::com_ptr<ICoreWebView2Environment> webViewEnv,
|
||||||
|
@ -118,7 +118,7 @@ namespace flutter_inappwebview_plugin
|
||||||
std::make_unique<WebViewChannelDelegate>(this, plugin->registrar->messenger());
|
std::make_unique<WebViewChannelDelegate>(this, plugin->registrar->messenger());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InAppWebView::prepare()
|
void InAppWebView::prepare(const InAppWebViewCreationParams& params)
|
||||||
{
|
{
|
||||||
if (!webView) {
|
if (!webView) {
|
||||||
return;
|
return;
|
||||||
|
@ -140,6 +140,10 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
userContentController->addPluginScript(std::move(createJavaScriptBridgePluginScript()));
|
userContentController->addPluginScript(std::move(createJavaScriptBridgePluginScript()));
|
||||||
|
|
||||||
|
if (params.initialUserScripts.has_value()) {
|
||||||
|
userContentController->addUserOnlyScripts(params.initialUserScripts.value());
|
||||||
|
}
|
||||||
|
|
||||||
registerEventHandlers();
|
registerEventHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ namespace flutter_inappwebview_plugin
|
||||||
struct InAppWebViewCreationParams {
|
struct InAppWebViewCreationParams {
|
||||||
const std::variant<std::string, int64_t> id;
|
const std::variant<std::string, int64_t> id;
|
||||||
const std::shared_ptr<InAppWebViewSettings> initialSettings;
|
const std::shared_ptr<InAppWebViewSettings> initialSettings;
|
||||||
|
const std::optional<std::vector<std::shared_ptr<UserScript>>> initialUserScripts;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InAppWebView
|
class InAppWebView
|
||||||
|
@ -129,7 +130,7 @@ namespace flutter_inappwebview_plugin
|
||||||
winrt::com_ptr<ABI::Windows::UI::Composition::ICompositor> compositor);
|
winrt::com_ptr<ABI::Windows::UI::Composition::ICompositor> compositor);
|
||||||
|
|
||||||
void initChannel(const std::optional<std::variant<std::string, int64_t>> viewId, const std::optional<std::string> channelName);
|
void initChannel(const std::optional<std::variant<std::string, int64_t>> viewId, const std::optional<std::string> channelName);
|
||||||
void prepare();
|
void prepare(const InAppWebViewCreationParams& params);
|
||||||
std::optional<std::string> getUrl() const;
|
std::optional<std::string> getUrl() const;
|
||||||
std::optional<std::string> getTitle() const;
|
std::optional<std::string> getTitle() const;
|
||||||
void loadUrl(const std::shared_ptr<URLRequest> urlRequest) const;
|
void loadUrl(const std::shared_ptr<URLRequest> urlRequest) const;
|
||||||
|
|
|
@ -6,8 +6,11 @@
|
||||||
|
|
||||||
#include "../in_app_webview/in_app_webview_settings.h"
|
#include "../in_app_webview/in_app_webview_settings.h"
|
||||||
#include "../types/url_request.h"
|
#include "../types/url_request.h"
|
||||||
|
#include "../types/user_script.h"
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
#include "../utils/log.h"
|
#include "../utils/log.h"
|
||||||
|
#include "../utils/string.h"
|
||||||
|
#include "../utils/vector.h"
|
||||||
#include "in_app_webview_manager.h"
|
#include "in_app_webview_manager.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
|
@ -49,16 +52,17 @@ namespace flutter_inappwebview_plugin
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
||||||
{
|
{
|
||||||
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
|
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
|
||||||
|
auto& methodName = method_call.method_name();
|
||||||
|
|
||||||
if (method_call.method_name().compare("createInAppWebView") == 0) {
|
if (string_equals(methodName, "createInAppWebView")) {
|
||||||
if (isSupported()) {
|
if (isSupported()) {
|
||||||
createInAppWebView(arguments, std::move(result));
|
createInAppBrowser(arguments, std::move(result));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result->Error("0", "Creating an InAppWebView instance is not supported! Graphics Context is not valid!");
|
result->Error("0", "Creating an InAppWebView instance is not supported! Graphics Context is not valid!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (method_call.method_name().compare("dispose") == 0) {
|
else if (string_equals(methodName, "dispose")) {
|
||||||
auto id = get_fl_map_value<int64_t>(*arguments, "id");
|
auto id = get_fl_map_value<int64_t>(*arguments, "id");
|
||||||
if (map_contains(webViews, (uint64_t)id)) {
|
if (map_contains(webViews, (uint64_t)id)) {
|
||||||
webViews.erase(id);
|
webViews.erase(id);
|
||||||
|
@ -70,7 +74,7 @@ namespace flutter_inappwebview_plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InAppWebViewManager::createInAppWebView(const flutter::EncodableMap* arguments, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
void InAppWebViewManager::createInAppBrowser(const flutter::EncodableMap* arguments, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
||||||
{
|
{
|
||||||
auto result_ = std::shared_ptr<flutter::MethodResult<flutter::EncodableValue>>(std::move(result));
|
auto result_ = std::shared_ptr<flutter::MethodResult<flutter::EncodableValue>>(std::move(result));
|
||||||
|
|
||||||
|
@ -78,6 +82,7 @@ namespace flutter_inappwebview_plugin
|
||||||
auto urlRequestMap = get_optional_fl_map_value<flutter::EncodableMap>(*arguments, "initialUrlRequest");
|
auto urlRequestMap = get_optional_fl_map_value<flutter::EncodableMap>(*arguments, "initialUrlRequest");
|
||||||
auto initialFile = get_optional_fl_map_value<std::string>(*arguments, "initialFile");
|
auto initialFile = get_optional_fl_map_value<std::string>(*arguments, "initialFile");
|
||||||
auto initialDataMap = get_optional_fl_map_value<flutter::EncodableMap>(*arguments, "initialData");
|
auto initialDataMap = get_optional_fl_map_value<flutter::EncodableMap>(*arguments, "initialData");
|
||||||
|
auto initialUserScriptList = get_optional_fl_map_value<flutter::EncodableList>(*arguments, "initialUserScripts");
|
||||||
|
|
||||||
auto hwnd = CreateWindowEx(0, windowClass_.lpszClassName, L"", 0, CW_DEFAULT,
|
auto hwnd = CreateWindowEx(0, windowClass_.lpszClassName, L"", 0, CW_DEFAULT,
|
||||||
CW_DEFAULT, 0, 0, HWND_MESSAGE, nullptr,
|
CW_DEFAULT, 0, 0, HWND_MESSAGE, nullptr,
|
||||||
|
@ -90,10 +95,14 @@ namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
if (webViewEnv && webViewController && webViewCompositionController) {
|
if (webViewEnv && webViewController && webViewCompositionController) {
|
||||||
auto initialSettings = std::make_unique<InAppWebViewSettings>(settingsMap);
|
auto initialSettings = std::make_unique<InAppWebViewSettings>(settingsMap);
|
||||||
|
std::optional<std::vector<std::shared_ptr<UserScript>>> initialUserScripts = initialUserScriptList.has_value() ?
|
||||||
|
functional_map(initialUserScriptList.value(), [](const flutter::EncodableValue& map) { return std::make_shared<UserScript>(std::get<flutter::EncodableMap>(map)); }) :
|
||||||
|
std::optional<std::vector<std::shared_ptr<UserScript>>>{};
|
||||||
|
|
||||||
InAppWebViewCreationParams params = {
|
InAppWebViewCreationParams params = {
|
||||||
"",
|
"",
|
||||||
std::move(initialSettings),
|
std::move(initialSettings),
|
||||||
|
initialUserScripts
|
||||||
};
|
};
|
||||||
|
|
||||||
auto inAppWebView = std::make_unique<InAppWebView>(plugin, params, hwnd,
|
auto inAppWebView = std::make_unique<InAppWebView>(plugin, params, hwnd,
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace flutter_inappwebview_plugin
|
||||||
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||||
|
|
||||||
void createInAppWebView(const flutter::EncodableMap* arguments, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
void createInAppBrowser(const flutter::EncodableMap* arguments, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<rx::RoHelper> rohelper_;
|
std::unique_ptr<rx::RoHelper> rohelper_;
|
||||||
winrt::com_ptr<ABI::Windows::System::IDispatcherQueueController>
|
winrt::com_ptr<ABI::Windows::System::IDispatcherQueueController>
|
||||||
|
|
|
@ -81,32 +81,36 @@ namespace flutter_inappwebview_plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline T get_fl_map_value(const flutter::EncodableMap& map, const char* string)
|
static inline T get_fl_map_value(const flutter::EncodableMap& map, const char* key)
|
||||||
{
|
{
|
||||||
return std::get<T>(map.at(make_fl_value(string)));
|
return std::get<T>(map.at(make_fl_value(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename std::enable_if<((!is_mappish<T>::value && !is_vector<T>::value) ||
|
template<typename T, typename std::enable_if<((!is_mappish<T>::value && !is_vector<T>::value) ||
|
||||||
std::is_same<T, flutter::EncodableMap>::value || std::is_same<T, flutter::EncodableList>::value), int>::type* = nullptr>
|
std::is_same<T, flutter::EncodableMap>::value || std::is_same<T, flutter::EncodableList>::value), int>::type* = nullptr>
|
||||||
static inline std::optional<T> get_optional_fl_map_value(const flutter::EncodableMap& map, const char* string)
|
static inline std::optional<T> get_optional_fl_map_value(const flutter::EncodableMap& map, const char* key)
|
||||||
{
|
{
|
||||||
return make_pointer_optional<T>(std::get_if<T>(&map.at(make_fl_value(string))));
|
auto fl_key = make_fl_value(key);
|
||||||
|
if (map_contains<flutter::EncodableValue, flutter::EncodableValue>(map, fl_key)) {
|
||||||
|
return make_pointer_optional<T>(std::get_if<T>(&map.at(fl_key)));
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline T get_fl_map_value(const flutter::EncodableMap& map, const char* string, const T& defaultValue)
|
static inline T get_fl_map_value(const flutter::EncodableMap& map, const char* key, const T& defaultValue)
|
||||||
{
|
{
|
||||||
auto optional = get_optional_fl_map_value<T>(map, string);
|
auto optional = get_optional_fl_map_value<T>(map, key);
|
||||||
return !optional.has_value() ? defaultValue : optional.value();
|
return !optional.has_value() ? defaultValue : optional.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename std::enable_if<(is_mappish<T>::value && !std::is_same<T, flutter::EncodableMap>::value)>::type* = nullptr>
|
template<typename T, typename std::enable_if<(is_mappish<T>::value && !std::is_same<T, flutter::EncodableMap>::value)>::type* = nullptr>
|
||||||
static inline std::optional<T> get_optional_fl_map_value(const flutter::EncodableMap& map, const char* string)
|
static inline std::optional<T> get_optional_fl_map_value(const flutter::EncodableMap& map, const char* key)
|
||||||
{
|
{
|
||||||
using K = typename T::key_type;
|
using K = typename T::key_type;
|
||||||
using V = typename T::mapped_type;
|
using V = typename T::mapped_type;
|
||||||
|
|
||||||
auto flMap = std::get_if<flutter::EncodableMap>(&map.at(make_fl_value(string)));
|
auto flMap = std::get_if<flutter::EncodableMap>(&map.at(make_fl_value(key)));
|
||||||
if (flMap) {
|
if (flMap) {
|
||||||
T mapValue = {};
|
T mapValue = {};
|
||||||
for (auto itr = flMap->begin(); itr != flMap->end(); itr++) {
|
for (auto itr = flMap->begin(); itr != flMap->end(); itr++) {
|
||||||
|
@ -118,18 +122,18 @@ namespace flutter_inappwebview_plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
static inline std::map<K, T> get_fl_map_value(const flutter::EncodableMap& map, const char* string, const std::map<K, T>& defaultValue)
|
static inline std::map<K, T> get_fl_map_value(const flutter::EncodableMap& map, const char* key, const std::map<K, T>& defaultValue)
|
||||||
{
|
{
|
||||||
auto optional = get_optional_fl_map_value<std::map<K, T>>(map, string);
|
auto optional = get_optional_fl_map_value<std::map<K, T>>(map, key);
|
||||||
return !optional.has_value() ? defaultValue : optional.value();
|
return !optional.has_value() ? defaultValue : optional.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename std::enable_if<(is_vector<T>::value && !std::is_same<T, flutter::EncodableList>::value), bool>::type* = nullptr>
|
template<typename T, typename std::enable_if<(is_vector<T>::value && !std::is_same<T, flutter::EncodableList>::value), bool>::type* = nullptr>
|
||||||
static inline std::optional<T> get_optional_fl_map_value(const flutter::EncodableMap& map, const char* string)
|
static inline std::optional<T> get_optional_fl_map_value(const flutter::EncodableMap& map, const char* key)
|
||||||
{
|
{
|
||||||
using V = typename T::value_type;
|
using V = typename T::value_type;
|
||||||
|
|
||||||
auto flList = std::get_if<flutter::EncodableList>(&map.at(make_fl_value(string)));
|
auto flList = std::get_if<flutter::EncodableList>(&map.at(make_fl_value(key)));
|
||||||
if (flList) {
|
if (flList) {
|
||||||
T vecValue(flList->size());
|
T vecValue(flList->size());
|
||||||
for (auto itr = flList->begin(); itr != flList->end(); itr++) {
|
for (auto itr = flList->begin(); itr != flList->end(); itr++) {
|
||||||
|
@ -141,9 +145,9 @@ namespace flutter_inappwebview_plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline std::vector<T> get_fl_map_value(const flutter::EncodableMap& map, const char* string, const std::vector<T>& defaultValue)
|
static inline std::vector<T> get_fl_map_value(const flutter::EncodableMap& map, const char* key, const std::vector<T>& defaultValue)
|
||||||
{
|
{
|
||||||
auto optional = get_optional_fl_map_value<std::vector<T>>(map, string);
|
auto optional = get_optional_fl_map_value<std::vector<T>>(map, key);
|
||||||
return !optional.has_value() ? defaultValue : optional.value();
|
return !optional.has_value() ? defaultValue : optional.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue