windows c++ code format
This commit is contained in:
parent
dcfeeb7497
commit
8499949a22
|
@ -30,7 +30,6 @@ class MyInAppBrowser extends InAppBrowser {
|
||||||
@override
|
@override
|
||||||
Future onLoadStop(url) async {
|
Future onLoadStop(url) async {
|
||||||
pullToRefreshController?.endRefreshing();
|
pullToRefreshController?.endRefreshing();
|
||||||
print(await webViewController?.getUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -9,7 +9,8 @@ namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
// static
|
// static
|
||||||
void FlutterInappwebviewWindowsPlugin::RegisterWithRegistrar(
|
void FlutterInappwebviewWindowsPlugin::RegisterWithRegistrar(
|
||||||
flutter::PluginRegistrarWindows* registrar) {
|
flutter::PluginRegistrarWindows* registrar)
|
||||||
|
{
|
||||||
auto plugin = std::make_unique<FlutterInappwebviewWindowsPlugin>(registrar);
|
auto plugin = std::make_unique<FlutterInappwebviewWindowsPlugin>(registrar);
|
||||||
registrar->AddPlugin(std::move(plugin));
|
registrar->AddPlugin(std::move(plugin));
|
||||||
}
|
}
|
||||||
|
@ -21,7 +22,5 @@ namespace flutter_inappwebview_plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
FlutterInappwebviewWindowsPlugin::~FlutterInappwebviewWindowsPlugin()
|
FlutterInappwebviewWindowsPlugin::~FlutterInappwebviewWindowsPlugin()
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -5,7 +5,8 @@
|
||||||
#include "flutter_inappwebview_windows_plugin.h"
|
#include "flutter_inappwebview_windows_plugin.h"
|
||||||
|
|
||||||
void FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
|
void FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
|
||||||
FlutterDesktopPluginRegistrarRef registrar) {
|
FlutterDesktopPluginRegistrarRef registrar)
|
||||||
|
{
|
||||||
flutter_inappwebview_plugin::FlutterInappwebviewWindowsPlugin::RegisterWithRegistrar(
|
flutter_inappwebview_plugin::FlutterInappwebviewWindowsPlugin::RegisterWithRegistrar(
|
||||||
flutter::PluginRegistrarManager::GetInstance()
|
flutter::PluginRegistrarManager::GetInstance()
|
||||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include "in_app_browser.h"
|
|
||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
|
#include "in_app_browser.h"
|
||||||
#include "in_app_browser_manager.h"
|
#include "in_app_browser_manager.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
|
@ -38,7 +39,8 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
ShowWindow(m_hWnd, SW_SHOW);
|
ShowWindow(m_hWnd, SW_SHOW);
|
||||||
|
|
||||||
webView = std::make_unique<InAppWebView>(plugin, id, m_hWnd, InAppBrowser::METHOD_CHANNEL_NAME_PREFIX + id, [this]() -> void {
|
webView = std::make_unique<InAppWebView>(plugin, id, m_hWnd, InAppBrowser::METHOD_CHANNEL_NAME_PREFIX + id, [this]() -> void
|
||||||
|
{
|
||||||
if (channelDelegate) {
|
if (channelDelegate) {
|
||||||
channelDelegate->onBrowserCreated();
|
channelDelegate->onBrowserCreated();
|
||||||
}
|
}
|
||||||
|
@ -144,7 +146,8 @@ namespace flutter_inappwebview_plugin
|
||||||
UINT message,
|
UINT message,
|
||||||
WPARAM wparam,
|
WPARAM wparam,
|
||||||
LPARAM lparam
|
LPARAM lparam
|
||||||
) noexcept {
|
) noexcept
|
||||||
|
{
|
||||||
if (message == WM_NCCREATE) {
|
if (message == WM_NCCREATE) {
|
||||||
auto window_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
|
auto window_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
|
||||||
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(window_struct->lpCreateParams));
|
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(window_struct->lpCreateParams));
|
||||||
|
@ -161,7 +164,8 @@ namespace flutter_inappwebview_plugin
|
||||||
UINT message,
|
UINT message,
|
||||||
WPARAM wparam,
|
WPARAM wparam,
|
||||||
LPARAM lparam
|
LPARAM lparam
|
||||||
) noexcept {
|
) noexcept
|
||||||
|
{
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_DESTROY: {
|
case WM_DESTROY: {
|
||||||
// might receive multiple WM_DESTROY messages.
|
// might receive multiple WM_DESTROY messages.
|
||||||
|
@ -205,7 +209,8 @@ namespace flutter_inappwebview_plugin
|
||||||
return DefWindowProc(hwnd, message, wparam, lparam);
|
return DefWindowProc(hwnd, message, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
InAppBrowser* InAppBrowser::GetThisFromHandle(HWND const window) noexcept {
|
InAppBrowser* InAppBrowser::GetThisFromHandle(HWND const window) noexcept
|
||||||
|
{
|
||||||
return reinterpret_cast<InAppBrowser*>(
|
return reinterpret_cast<InAppBrowser*>(
|
||||||
GetWindowLongPtr(window, GWLP_USERDATA));
|
GetWindowLongPtr(window, GWLP_USERDATA));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_H_
|
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_H_
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_H_
|
||||||
|
|
||||||
#include <Windows.h>
|
|
||||||
#include <string>
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
#include <wil/com.h>
|
#include <wil/com.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
#include "../flutter_inappwebview_windows_plugin.h"
|
#include "../flutter_inappwebview_windows_plugin.h"
|
||||||
#include "../in_app_webview/in_app_webview.h"
|
#include "../in_app_webview/in_app_webview.h"
|
||||||
#include "../types/url_request.h"
|
#include "../types/url_request.h"
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
|
#include "../utils/util.h"
|
||||||
#include "in_app_browser.h"
|
#include "in_app_browser.h"
|
||||||
#include "in_app_browser_channel_delegate.h"
|
#include "in_app_browser_channel_delegate.h"
|
||||||
|
|
||||||
#include "../utils/util.h"
|
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
InAppBrowserChannelDelegate::InAppBrowserChannelDelegate(const std::string& id, flutter::BinaryMessenger* messenger)
|
InAppBrowserChannelDelegate::InAppBrowserChannelDelegate(const std::string& id, flutter::BinaryMessenger* messenger)
|
||||||
: ChannelDelegate(messenger, InAppBrowser::METHOD_CHANNEL_NAME_PREFIX + id)
|
: ChannelDelegate(messenger, InAppBrowser::METHOD_CHANNEL_NAME_PREFIX + id)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void InAppBrowserChannelDelegate::HandleMethodCall(const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
void InAppBrowserChannelDelegate::HandleMethodCall(const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
||||||
|
|
|
@ -1,21 +1,15 @@
|
||||||
#include <memory>
|
|
||||||
#include <flutter/method_channel.h>
|
#include <flutter/method_channel.h>
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
#include "in_app_browser_manager.h"
|
|
||||||
|
|
||||||
#include "../types/url_request.h"
|
#include "../types/url_request.h"
|
||||||
|
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
|
#include "in_app_browser_manager.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
InAppBrowserManager::InAppBrowserManager(FlutterInappwebviewWindowsPlugin* plugin)
|
InAppBrowserManager::InAppBrowserManager(FlutterInappwebviewWindowsPlugin* plugin)
|
||||||
: plugin(plugin), ChannelDelegate(plugin->registrar->messenger(), InAppBrowserManager::METHOD_CHANNEL_NAME)
|
: plugin(plugin), ChannelDelegate(plugin->registrar->messenger(), InAppBrowserManager::METHOD_CHANNEL_NAME)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_MANAGER_H_
|
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_MANAGER_H_
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_MANAGER_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_BROWSER_MANAGER_H_
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <flutter/method_channel.h>
|
#include <flutter/method_channel.h>
|
||||||
#include <flutter/standard_message_codec.h>
|
#include <flutter/standard_message_codec.h>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "../flutter_inappwebview_windows_plugin.h"
|
#include "../flutter_inappwebview_windows_plugin.h"
|
||||||
|
|
||||||
#include "in_app_browser.h"
|
|
||||||
|
|
||||||
#include "../types/channel_delegate.h"
|
#include "../types/channel_delegate.h"
|
||||||
|
#include "in_app_browser.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#pragma comment(lib, "Shlwapi.lib")
|
#pragma comment(lib, "Shlwapi.lib")
|
||||||
|
|
||||||
#include "in_app_webview.h"
|
#include <Shlwapi.h>
|
||||||
#include <WebView2EnvironmentOptions.h>
|
#include <WebView2EnvironmentOptions.h>
|
||||||
#include <wil/wrl.h>
|
#include <wil/wrl.h>
|
||||||
#include <Shlwapi.h>
|
|
||||||
|
#include "../types/web_resource_error.h"
|
||||||
|
#include "../types/web_resource_request.h"
|
||||||
#include "../utils/strconv.h"
|
#include "../utils/strconv.h"
|
||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
#include "../types/web_resource_request.h"
|
#include "in_app_webview.h"
|
||||||
#include "../types/web_resource_error.h"
|
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
|
@ -29,11 +30,13 @@ namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,
|
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,
|
||||||
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
|
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
|
||||||
[parentWindow, completionHandler, this](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
|
[parentWindow, completionHandler, this](HRESULT result, ICoreWebView2Environment* env) -> HRESULT
|
||||||
|
{
|
||||||
webViewEnv = env;
|
webViewEnv = env;
|
||||||
// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window HWND
|
// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window HWND
|
||||||
env->CreateCoreWebView2Controller(parentWindow, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
|
env->CreateCoreWebView2Controller(parentWindow, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
|
||||||
[parentWindow, completionHandler, this](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {
|
[parentWindow, completionHandler, this](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT
|
||||||
|
{
|
||||||
if (controller != nullptr) {
|
if (controller != nullptr) {
|
||||||
webViewController = controller;
|
webViewController = controller;
|
||||||
webViewController->get_CoreWebView2(webView.put());
|
webViewController->get_CoreWebView2(webView.put());
|
||||||
|
@ -62,7 +65,8 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
webView->add_NavigationStarting(
|
webView->add_NavigationStarting(
|
||||||
Callback<ICoreWebView2NavigationStartingEventHandler>(
|
Callback<ICoreWebView2NavigationStartingEventHandler>(
|
||||||
[this](ICoreWebView2* sender, ICoreWebView2NavigationStartingEventArgs* args) {
|
[this](ICoreWebView2* sender, ICoreWebView2NavigationStartingEventArgs* args)
|
||||||
|
{
|
||||||
if (!channelDelegate) {
|
if (!channelDelegate) {
|
||||||
args->put_Cancel(false);
|
args->put_Cancel(false);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -79,8 +83,7 @@ namespace flutter_inappwebview_plugin
|
||||||
wil::com_ptr<ICoreWebView2HttpHeadersCollectionIterator> iterator;
|
wil::com_ptr<ICoreWebView2HttpHeadersCollectionIterator> iterator;
|
||||||
requestHeaders->GetIterator(&iterator);
|
requestHeaders->GetIterator(&iterator);
|
||||||
BOOL hasCurrent = FALSE;
|
BOOL hasCurrent = FALSE;
|
||||||
while (SUCCEEDED(iterator->get_HasCurrentHeader(&hasCurrent)) && hasCurrent)
|
while (SUCCEEDED(iterator->get_HasCurrentHeader(&hasCurrent)) && hasCurrent) {
|
||||||
{
|
|
||||||
wil::unique_cotaskmem_string name;
|
wil::unique_cotaskmem_string name;
|
||||||
wil::unique_cotaskmem_string value;
|
wil::unique_cotaskmem_string value;
|
||||||
|
|
||||||
|
@ -106,7 +109,7 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
UINT64 navigationId;
|
UINT64 navigationId;
|
||||||
if (SUCCEEDED(args->get_NavigationId(&navigationId))) {
|
if (SUCCEEDED(args->get_NavigationId(&navigationId))) {
|
||||||
navigationActions.insert({navigationId, navigationAction});
|
navigationActions.insert({ navigationId, navigationAction });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callShouldOverrideUrlLoading && requestMethod == nullptr) {
|
if (callShouldOverrideUrlLoading && requestMethod == nullptr) {
|
||||||
|
@ -114,19 +117,22 @@ namespace flutter_inappwebview_plugin
|
||||||
// so ignore the shouldOverrideUrlLoading event.
|
// so ignore the shouldOverrideUrlLoading event.
|
||||||
|
|
||||||
auto callback = std::make_unique<WebViewChannelDelegate::ShouldOverrideUrlLoadingCallback>();
|
auto callback = std::make_unique<WebViewChannelDelegate::ShouldOverrideUrlLoadingCallback>();
|
||||||
callback->nonNullSuccess = [this, urlRequest](const NavigationActionPolicy actionPolicy) {
|
callback->nonNullSuccess = [this, urlRequest](const NavigationActionPolicy actionPolicy)
|
||||||
|
{
|
||||||
callShouldOverrideUrlLoading = false;
|
callShouldOverrideUrlLoading = false;
|
||||||
if (actionPolicy == allow) {
|
if (actionPolicy == allow) {
|
||||||
loadUrl(*urlRequest);
|
loadUrl(*urlRequest);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
auto defaultBehaviour = [this, urlRequest](const std::optional<NavigationActionPolicy> actionPolicy) {
|
auto defaultBehaviour = [this, urlRequest](const std::optional<NavigationActionPolicy> actionPolicy)
|
||||||
|
{
|
||||||
callShouldOverrideUrlLoading = false;
|
callShouldOverrideUrlLoading = false;
|
||||||
loadUrl(*urlRequest);
|
loadUrl(*urlRequest);
|
||||||
};
|
};
|
||||||
callback->defaultBehaviour = defaultBehaviour;
|
callback->defaultBehaviour = defaultBehaviour;
|
||||||
callback->error = [defaultBehaviour](const std::string& error_code, const std::string& error_message, const flutter::EncodableValue* error_details) {
|
callback->error = [defaultBehaviour](const std::string& error_code, const std::string& error_message, const flutter::EncodableValue* error_details)
|
||||||
|
{
|
||||||
debugLog(error_code + ", " + error_message);
|
debugLog(error_code + ", " + error_message);
|
||||||
defaultBehaviour(std::nullopt);
|
defaultBehaviour(std::nullopt);
|
||||||
};
|
};
|
||||||
|
@ -145,7 +151,8 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
webView->add_NavigationCompleted(
|
webView->add_NavigationCompleted(
|
||||||
Callback<ICoreWebView2NavigationCompletedEventHandler>(
|
Callback<ICoreWebView2NavigationCompletedEventHandler>(
|
||||||
[this](ICoreWebView2* sender, ICoreWebView2NavigationCompletedEventArgs* args) {
|
[this](ICoreWebView2* sender, ICoreWebView2NavigationCompletedEventArgs* args)
|
||||||
|
{
|
||||||
std::shared_ptr<NavigationAction> navigationAction;
|
std::shared_ptr<NavigationAction> navigationAction;
|
||||||
UINT64 navigationId;
|
UINT64 navigationId;
|
||||||
if (SUCCEEDED(args->get_NavigationId(&navigationId))) {
|
if (SUCCEEDED(args->get_NavigationId(&navigationId))) {
|
||||||
|
@ -239,7 +246,8 @@ namespace flutter_inappwebview_plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InAppWebView::isSslError(const COREWEBVIEW2_WEB_ERROR_STATUS& webErrorStatus) {
|
bool InAppWebView::isSslError(const COREWEBVIEW2_WEB_ERROR_STATUS& webErrorStatus)
|
||||||
|
{
|
||||||
return webErrorStatus >= COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_COMMON_NAME_IS_INCORRECT && webErrorStatus <= COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_IS_INVALID;
|
return webErrorStatus >= COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_COMMON_NAME_IS_INCORRECT && webErrorStatus <= COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_IS_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_WEBVIEW_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_IN_APP_WEBVIEW_H_
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <WebView2.h>
|
#include <WebView2.h>
|
||||||
#include <wil/com.h>
|
#include <wil/com.h>
|
||||||
#include "../types/url_request.h"
|
|
||||||
#include "../types/navigation_action.h"
|
|
||||||
#include "webview_channel_delegate.h"
|
|
||||||
#include "../flutter_inappwebview_windows_plugin.h"
|
#include "../flutter_inappwebview_windows_plugin.h"
|
||||||
|
#include "../types/navigation_action.h"
|
||||||
|
#include "../types/url_request.h"
|
||||||
|
#include "webview_channel_delegate.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,26 +1,23 @@
|
||||||
#include "in_app_webview.h"
|
#include "../types/base_callback_result.h"
|
||||||
#include "webview_channel_delegate.h"
|
|
||||||
|
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
#include "../utils/strconv.h"
|
#include "../utils/strconv.h"
|
||||||
#include "../types/base_callback_result.h"
|
#include "in_app_webview.h"
|
||||||
|
#include "webview_channel_delegate.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
WebViewChannelDelegate::WebViewChannelDelegate(InAppWebView* webView, flutter::BinaryMessenger* messenger)
|
WebViewChannelDelegate::WebViewChannelDelegate(InAppWebView* webView, flutter::BinaryMessenger* messenger)
|
||||||
: webView(webView), ChannelDelegate(messenger, InAppWebView::METHOD_CHANNEL_NAME_PREFIX + variant_to_string(webView->id))
|
: webView(webView), ChannelDelegate(messenger, InAppWebView::METHOD_CHANNEL_NAME_PREFIX + variant_to_string(webView->id))
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WebViewChannelDelegate::WebViewChannelDelegate(InAppWebView* webView, flutter::BinaryMessenger* messenger, const std::string& name)
|
WebViewChannelDelegate::WebViewChannelDelegate(InAppWebView* webView, flutter::BinaryMessenger* messenger, const std::string& name)
|
||||||
: webView(webView), ChannelDelegate(messenger, name)
|
: webView(webView), ChannelDelegate(messenger, name)
|
||||||
|
{}
|
||||||
|
|
||||||
|
WebViewChannelDelegate::ShouldOverrideUrlLoadingCallback::ShouldOverrideUrlLoadingCallback()
|
||||||
|
{
|
||||||
|
decodeResult = [](const flutter::EncodableValue* value)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WebViewChannelDelegate::ShouldOverrideUrlLoadingCallback::ShouldOverrideUrlLoadingCallback() {
|
|
||||||
decodeResult = [](const flutter::EncodableValue* value) {
|
|
||||||
if (value->IsNull()) {
|
if (value->IsNull()) {
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +54,7 @@ namespace flutter_inappwebview_plugin
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto arguments = std::make_unique<flutter::EncodableValue>(flutter::EncodableMap {
|
auto arguments = std::make_unique<flutter::EncodableValue>(flutter::EncodableMap{
|
||||||
{flutter::EncodableValue("url"), make_fl_value(url)},
|
{flutter::EncodableValue("url"), make_fl_value(url)},
|
||||||
});
|
});
|
||||||
channel->InvokeMethod("onLoadStart", std::move(arguments));
|
channel->InvokeMethod("onLoadStart", std::move(arguments));
|
||||||
|
|
|
@ -4,18 +4,18 @@
|
||||||
#include <flutter/method_channel.h>
|
#include <flutter/method_channel.h>
|
||||||
#include <flutter/standard_message_codec.h>
|
#include <flutter/standard_message_codec.h>
|
||||||
|
|
||||||
#include "../types/channel_delegate.h"
|
|
||||||
#include "../types/base_callback_result.h"
|
#include "../types/base_callback_result.h"
|
||||||
|
#include "../types/channel_delegate.h"
|
||||||
#include "../types/navigation_action.h"
|
#include "../types/navigation_action.h"
|
||||||
#include "../types/web_resource_request.h"
|
|
||||||
#include "../types/web_resource_error.h"
|
#include "../types/web_resource_error.h"
|
||||||
|
#include "../types/web_resource_request.h"
|
||||||
#include "../types/web_resource_response.h"
|
#include "../types/web_resource_response.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
class InAppWebView;
|
class InAppWebView;
|
||||||
|
|
||||||
enum NavigationActionPolicy {cancel = 0, allow = 1};
|
enum NavigationActionPolicy { cancel = 0, allow = 1 };
|
||||||
|
|
||||||
class WebViewChannelDelegate : public ChannelDelegate
|
class WebViewChannelDelegate : public ChannelDelegate
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
|
FLUTTER_PLUGIN_EXPORT void FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
|
||||||
FlutterDesktopPluginRegistrarRef registrar);
|
FlutterDesktopPluginRegistrarRef registrar);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_BASE_CALLBACK_RESULT_H_
|
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_BASE_CALLBACK_RESULT_H_
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_BASE_CALLBACK_RESULT_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_BASE_CALLBACK_RESULT_H_
|
||||||
|
|
||||||
#include <flutter/standard_method_codec.h>
|
|
||||||
#include <flutter/method_result_functions.h>
|
#include <flutter/method_result_functions.h>
|
||||||
|
#include <flutter/standard_method_codec.h>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
|
@ -20,7 +20,8 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
BaseCallbackResult<T>() :
|
BaseCallbackResult<T>() :
|
||||||
MethodResultFunctions(
|
MethodResultFunctions(
|
||||||
[this](const flutter::EncodableValue* val) {
|
[this](const flutter::EncodableValue* val)
|
||||||
|
{
|
||||||
std::optional<T> result = decodeResult ? decodeResult(val) : std::nullopt;
|
std::optional<T> result = decodeResult ? decodeResult(val) : std::nullopt;
|
||||||
auto shouldRunDefaultBehaviour = false;
|
auto shouldRunDefaultBehaviour = false;
|
||||||
if (result.has_value()) {
|
if (result.has_value()) {
|
||||||
|
@ -33,19 +34,22 @@ namespace flutter_inappwebview_plugin
|
||||||
defaultBehaviour(result);
|
defaultBehaviour(result);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[this](const std::string& error_code, const std::string& error_message, const flutter::EncodableValue* error_details) {
|
[this](const std::string& error_code, const std::string& error_message, const flutter::EncodableValue* error_details)
|
||||||
|
{
|
||||||
if (error) {
|
if (error) {
|
||||||
error(error_code, error_message, error_details);
|
error(error_code, error_message, error_details);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[this]() {
|
[this]()
|
||||||
|
{
|
||||||
if (defaultBehaviour) {
|
if (defaultBehaviour) {
|
||||||
defaultBehaviour(std::nullopt);
|
defaultBehaviour(std::nullopt);
|
||||||
}
|
}
|
||||||
if (notImplemented) {
|
if (notImplemented) {
|
||||||
notImplemented();
|
notImplemented();
|
||||||
}
|
}
|
||||||
}) {};
|
})
|
||||||
|
{};
|
||||||
virtual ~BaseCallbackResult<T>() {};
|
virtual ~BaseCallbackResult<T>() {};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#include <flutter/method_channel.h>
|
#include <flutter/method_channel.h>
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
|
|
||||||
#include "channel_delegate.h"
|
|
||||||
|
|
||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
|
#include "channel_delegate.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
|
@ -14,7 +13,8 @@ namespace flutter_inappwebview_plugin
|
||||||
&flutter::StandardMethodCodec::GetInstance()
|
&flutter::StandardMethodCodec::GetInstance()
|
||||||
);
|
);
|
||||||
channel->SetMethodCallHandler(
|
channel->SetMethodCallHandler(
|
||||||
[this](const auto& call, auto result) {
|
[this](const auto& call, auto result)
|
||||||
|
{
|
||||||
this->HandleMethodCall(call, std::move(result));
|
this->HandleMethodCall(call, std::move(result));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,7 @@ namespace flutter_inappwebview_plugin
|
||||||
void ChannelDelegate::HandleMethodCall(
|
void ChannelDelegate::HandleMethodCall(
|
||||||
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)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelDelegate::~ChannelDelegate()
|
ChannelDelegate::~ChannelDelegate()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,20 +1,17 @@
|
||||||
|
#include "../utils/flutter.h"
|
||||||
#include "navigation_action.h"
|
#include "navigation_action.h"
|
||||||
|
|
||||||
#include "../utils/util.h"
|
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
NavigationAction::NavigationAction(std::shared_ptr<URLRequest> request, const bool& isForMainFrame)
|
NavigationAction::NavigationAction(std::shared_ptr<URLRequest> request, const bool& isForMainFrame)
|
||||||
: request(std::move(request)), isForMainFrame(isForMainFrame)
|
: request(std::move(request)), isForMainFrame(isForMainFrame)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
flutter::EncodableMap NavigationAction::toEncodableMap() const
|
||||||
|
|
||||||
flutter::EncodableMap NavigationAction::toEncodableMap()
|
|
||||||
{
|
{
|
||||||
return flutter::EncodableMap{
|
return flutter::EncodableMap{
|
||||||
{flutter::EncodableValue("request"), request->toEncodableMap()},
|
{make_fl_value("request"), request->toEncodableMap()},
|
||||||
{flutter::EncodableValue("isForMainFrame"), flutter::EncodableValue(isForMainFrame)}
|
{make_fl_value("isForMainFrame"), make_fl_value(isForMainFrame)}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "url_request.h"
|
#include "url_request.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
|
@ -15,7 +16,8 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
NavigationAction(std::shared_ptr<URLRequest> request, const bool& isForMainFrame);
|
NavigationAction(std::shared_ptr<URLRequest> request, const bool& isForMainFrame);
|
||||||
~NavigationAction() = default;
|
~NavigationAction() = default;
|
||||||
flutter::EncodableMap toEncodableMap();
|
|
||||||
|
flutter::EncodableMap toEncodableMap() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,21 @@
|
||||||
#include "url_request.h"
|
|
||||||
|
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
|
#include "url_request.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
URLRequest::URLRequest(const std::optional<std::string>& url, const std::optional<std::string>& method,
|
URLRequest::URLRequest(const std::optional<std::string>& url, const std::optional<std::string>& method,
|
||||||
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<std::vector<uint8_t>>& body)
|
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<std::vector<uint8_t>>& body)
|
||||||
: url(url), method(method), headers(headers), body(body)
|
: url(url), method(method), headers(headers), body(body)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
URLRequest::URLRequest(const flutter::EncodableMap& map)
|
URLRequest::URLRequest(const flutter::EncodableMap& map)
|
||||||
: url(get_optional_fl_map_value<std::string>(map, "url")),
|
: url(get_optional_fl_map_value<std::string>(map, "url")),
|
||||||
method(get_optional_fl_map_value<std::string>(map, "method")),
|
method(get_optional_fl_map_value<std::string>(map, "method")),
|
||||||
headers(get_optional_fl_map_value<std::string, std::string>(map, "headers")),
|
headers(get_optional_fl_map_value<std::string, std::string>(map, "headers")),
|
||||||
body(get_optional_fl_map_value<std::vector<uint8_t>>(map, "body"))
|
body(get_optional_fl_map_value<std::vector<uint8_t>>(map, "body"))
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
flutter::EncodableMap URLRequest::toEncodableMap() const
|
||||||
|
|
||||||
flutter::EncodableMap URLRequest::toEncodableMap()
|
|
||||||
{
|
{
|
||||||
return flutter::EncodableMap{
|
return flutter::EncodableMap{
|
||||||
{make_fl_value("url"), make_fl_value(url)},
|
{make_fl_value("url"), make_fl_value(url)},
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_URL_REQUEST_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_URL_REQUEST_H_
|
||||||
|
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include "../utils/flutter.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
class URLRequest
|
class URLRequest
|
||||||
|
@ -19,7 +20,8 @@ namespace flutter_inappwebview_plugin
|
||||||
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<std::vector<uint8_t>>& body);
|
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<std::vector<uint8_t>>& body);
|
||||||
URLRequest(const flutter::EncodableMap& map);
|
URLRequest(const flutter::EncodableMap& map);
|
||||||
~URLRequest() = default;
|
~URLRequest() = default;
|
||||||
flutter::EncodableMap toEncodableMap();
|
|
||||||
|
flutter::EncodableMap toEncodableMap() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,18 @@
|
||||||
#include "web_resource_error.h"
|
|
||||||
|
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
|
#include "web_resource_error.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
WebResourceError::WebResourceError(const std::string& description, const int type)
|
WebResourceError::WebResourceError(const std::string& description, const int type)
|
||||||
: description(description), type(type)
|
: description(description), type(type)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WebResourceError::WebResourceError(const flutter::EncodableMap& map)
|
WebResourceError::WebResourceError(const flutter::EncodableMap& map)
|
||||||
: description(get_fl_map_value<std::string>(map, "description")),
|
: description(get_fl_map_value<std::string>(map, "description")),
|
||||||
type(get_fl_map_value<int>(map, "type"))
|
type(get_fl_map_value<int>(map, "type"))
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
flutter::EncodableMap WebResourceError::toEncodableMap() const
|
||||||
|
|
||||||
flutter::EncodableMap WebResourceError::toEncodableMap()
|
|
||||||
{
|
{
|
||||||
return flutter::EncodableMap{
|
return flutter::EncodableMap{
|
||||||
{make_fl_value("description"), make_fl_value(description)},
|
{make_fl_value("description"), make_fl_value(description)},
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_WEB_RESOURCE_ERROR_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_WEB_RESOURCE_ERROR_H_
|
||||||
|
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
|
@ -39,7 +38,8 @@ namespace flutter_inappwebview_plugin
|
||||||
WebResourceError(const std::string& description, const int type);
|
WebResourceError(const std::string& description, const int type);
|
||||||
WebResourceError(const flutter::EncodableMap& map);
|
WebResourceError(const flutter::EncodableMap& map);
|
||||||
~WebResourceError() = default;
|
~WebResourceError() = default;
|
||||||
flutter::EncodableMap toEncodableMap();
|
|
||||||
|
flutter::EncodableMap toEncodableMap() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,21 @@
|
||||||
#include "web_resource_request.h"
|
|
||||||
|
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
|
#include "web_resource_request.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
WebResourceRequest::WebResourceRequest(const std::optional<std::string>& url, const std::optional<std::string>& method,
|
WebResourceRequest::WebResourceRequest(const std::optional<std::string>& url, const std::optional<std::string>& method,
|
||||||
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<bool>& isForMainFrame)
|
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<bool>& isForMainFrame)
|
||||||
: url(url), method(method), headers(headers), isForMainFrame(isForMainFrame)
|
: url(url), method(method), headers(headers), isForMainFrame(isForMainFrame)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WebResourceRequest::WebResourceRequest(const flutter::EncodableMap& map)
|
WebResourceRequest::WebResourceRequest(const flutter::EncodableMap& map)
|
||||||
: url(get_optional_fl_map_value<std::string>(map, "url")),
|
: url(get_optional_fl_map_value<std::string>(map, "url")),
|
||||||
method(get_optional_fl_map_value<std::string>(map, "method")),
|
method(get_optional_fl_map_value<std::string>(map, "method")),
|
||||||
headers(get_optional_fl_map_value<std::string, std::string>(map, "headers")),
|
headers(get_optional_fl_map_value<std::string, std::string>(map, "headers")),
|
||||||
isForMainFrame(get_optional_fl_map_value<bool>(map, "isForMainFrame"))
|
isForMainFrame(get_optional_fl_map_value<bool>(map, "isForMainFrame"))
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
flutter::EncodableMap WebResourceRequest::toEncodableMap() const
|
||||||
|
|
||||||
flutter::EncodableMap WebResourceRequest::toEncodableMap()
|
|
||||||
{
|
{
|
||||||
return flutter::EncodableMap{
|
return flutter::EncodableMap{
|
||||||
{make_fl_value("url"), make_fl_value(url)},
|
{make_fl_value("url"), make_fl_value(url)},
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_WEB_RESOURCE_REQUEST_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_WEB_RESOURCE_REQUEST_H_
|
||||||
|
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
|
@ -19,7 +18,8 @@ namespace flutter_inappwebview_plugin
|
||||||
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<bool>& isForMainFrame);
|
const std::optional<std::map<std::string, std::string>>& headers, const std::optional<bool>& isForMainFrame);
|
||||||
WebResourceRequest(const flutter::EncodableMap& map);
|
WebResourceRequest(const flutter::EncodableMap& map);
|
||||||
~WebResourceRequest() = default;
|
~WebResourceRequest() = default;
|
||||||
flutter::EncodableMap toEncodableMap();
|
|
||||||
|
flutter::EncodableMap toEncodableMap() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
#include "web_resource_response.h"
|
|
||||||
|
|
||||||
#include "../utils/flutter.h"
|
#include "../utils/flutter.h"
|
||||||
|
#include "web_resource_response.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
WebResourceResponse::WebResourceResponse(const std::optional<int>& statusCode)
|
WebResourceResponse::WebResourceResponse(const std::optional<int>& statusCode)
|
||||||
: statusCode(statusCode)
|
: statusCode(statusCode)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WebResourceResponse::WebResourceResponse(const flutter::EncodableMap& map)
|
WebResourceResponse::WebResourceResponse(const flutter::EncodableMap& map)
|
||||||
: statusCode(get_optional_fl_map_value<int>(map, "statusCode"))
|
: statusCode(get_optional_fl_map_value<int>(map, "statusCode"))
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
flutter::EncodableMap WebResourceResponse::toEncodableMap() const
|
||||||
|
|
||||||
flutter::EncodableMap WebResourceResponse::toEncodableMap()
|
|
||||||
{
|
{
|
||||||
return flutter::EncodableMap{
|
return flutter::EncodableMap{
|
||||||
{make_fl_value("statusCode"), make_fl_value(statusCode)}
|
{make_fl_value("statusCode"), make_fl_value(statusCode)}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_WEB_RESOURCE_RESPONSE_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_WEB_RESOURCE_RESPONSE_H_
|
||||||
|
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
|
@ -15,7 +14,8 @@ namespace flutter_inappwebview_plugin
|
||||||
WebResourceResponse(const std::optional<int>& statusCode);
|
WebResourceResponse(const std::optional<int>& statusCode);
|
||||||
WebResourceResponse(const flutter::EncodableMap& map);
|
WebResourceResponse(const flutter::EncodableMap& map);
|
||||||
~WebResourceResponse() = default;
|
~WebResourceResponse() = default;
|
||||||
flutter::EncodableMap toEncodableMap();
|
|
||||||
|
flutter::EncodableMap toEncodableMap() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_FLUTTER_UTIL_H_
|
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_FLUTTER_UTIL_H_
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_FLUTTER_UTIL_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_FLUTTER_UTIL_H_
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <optional>
|
|
||||||
#include <flutter/encodable_value.h>
|
#include <flutter/encodable_value.h>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -26,21 +26,55 @@ namespace flutter_inappwebview_plugin
|
||||||
return val == nullptr ? make_fl_value() : flutter::EncodableValue(val);
|
return val == nullptr ? make_fl_value() : flutter::EncodableValue(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline flutter::EncodableValue make_fl_value(const std::vector<T>& vec)
|
||||||
|
{
|
||||||
|
auto encodableList = flutter::EncodableList{};
|
||||||
|
for (auto const& val : vec) {
|
||||||
|
encodableList.push_back(make_fl_value(val));
|
||||||
|
}
|
||||||
|
return encodableList;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename K, typename T>
|
||||||
|
static inline flutter::EncodableValue make_fl_value(const std::map<K, T>& map)
|
||||||
|
{
|
||||||
|
auto encodableMap = flutter::EncodableMap{};
|
||||||
|
for (auto const& [key, val] : map) {
|
||||||
|
encodableMap.insert({ make_fl_value(key), make_fl_value(val) });
|
||||||
|
}
|
||||||
|
return encodableMap;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline flutter::EncodableValue make_fl_value(const std::optional<T>& optional)
|
static inline flutter::EncodableValue make_fl_value(const std::optional<T>& optional)
|
||||||
{
|
{
|
||||||
return optional.has_value() ? make_fl_value(optional.value()) : make_fl_value();
|
return optional.has_value() ? make_fl_value(optional.value()) : make_fl_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline flutter::EncodableValue make_fl_value(const std::optional<std::map<std::string, std::string>>& optional)
|
template<typename T>
|
||||||
|
static inline flutter::EncodableValue make_fl_value(const std::optional<std::vector<T>>& optional)
|
||||||
|
{
|
||||||
|
if (!optional.has_value()) {
|
||||||
|
return make_fl_value();
|
||||||
|
}
|
||||||
|
auto& vecValue = optional.value();
|
||||||
|
auto encodableList = flutter::EncodableList{};
|
||||||
|
for (auto const& val : vecValue) {
|
||||||
|
encodableList.push_back(make_fl_value(val));
|
||||||
|
}
|
||||||
|
return encodableList;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename K, typename T>
|
||||||
|
static inline flutter::EncodableValue make_fl_value(const std::optional<std::map<K, T>>& optional)
|
||||||
{
|
{
|
||||||
if (!optional.has_value()) {
|
if (!optional.has_value()) {
|
||||||
return make_fl_value();
|
return make_fl_value();
|
||||||
}
|
}
|
||||||
auto& mapValue = optional.value();
|
auto& mapValue = optional.value();
|
||||||
auto encodableMap = flutter::EncodableMap{};
|
auto encodableMap = flutter::EncodableMap{};
|
||||||
for (auto const& [key, val] : mapValue)
|
for (auto const& [key, val] : mapValue) {
|
||||||
{
|
|
||||||
encodableMap.insert({ make_fl_value(key), make_fl_value(val) });
|
encodableMap.insert({ make_fl_value(key), make_fl_value(val) });
|
||||||
}
|
}
|
||||||
return encodableMap;
|
return encodableMap;
|
||||||
|
@ -64,8 +98,7 @@ namespace flutter_inappwebview_plugin
|
||||||
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(string)));
|
||||||
if (flMap) {
|
if (flMap) {
|
||||||
auto mapValue = std::map<K, T>{};
|
auto mapValue = std::map<K, T>{};
|
||||||
for (auto itr = flMap->begin(); itr != flMap->end(); itr++)
|
for (auto itr = flMap->begin(); itr != flMap->end(); itr++) {
|
||||||
{
|
|
||||||
mapValue.insert({ std::get<K>(itr->first), std::get<T>(itr->second) });
|
mapValue.insert({ std::get<K>(itr->first), std::get<T>(itr->second) });
|
||||||
}
|
}
|
||||||
return make_pointer_optional<std::map<K, T>>(&mapValue);
|
return make_pointer_optional<std::map<K, T>>(&mapValue);
|
||||||
|
|
|
@ -390,12 +390,10 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
static inline HANDLE handle_for_ostream(std::ostream& ostrm)
|
static inline HANDLE handle_for_ostream(std::ostream& ostrm)
|
||||||
{
|
{
|
||||||
if (&ostrm == &std::cout)
|
if (&ostrm == &std::cout) {
|
||||||
{
|
|
||||||
return GetStdHandle(STD_OUTPUT_HANDLE);
|
return GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
}
|
}
|
||||||
else if (&ostrm == &std::cerr)
|
else if (&ostrm == &std::cerr) {
|
||||||
{
|
|
||||||
return GetStdHandle(STD_ERROR_HANDLE);
|
return GetStdHandle(STD_ERROR_HANDLE);
|
||||||
}
|
}
|
||||||
return INVALID_HANDLE_VALUE;
|
return INVALID_HANDLE_VALUE;
|
||||||
|
@ -407,18 +405,15 @@ namespace flutter_inappwebview_plugin
|
||||||
std::wstring ws = vformat(format, args);
|
std::wstring ws = vformat(format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
HANDLE h = handle_for_ostream(ostrm);
|
HANDLE h = handle_for_ostream(ostrm);
|
||||||
if (h == INVALID_HANDLE_VALUE)
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DWORD dwNumberOfCharsWrite;
|
DWORD dwNumberOfCharsWrite;
|
||||||
if (GetFileType(h) != FILE_TYPE_CHAR)
|
if (GetFileType(h) != FILE_TYPE_CHAR) {
|
||||||
{
|
|
||||||
std::string s = wide_to_cp(ws, GetConsoleOutputCP());
|
std::string s = wide_to_cp(ws, GetConsoleOutputCP());
|
||||||
WriteFile(h, s.c_str(), (DWORD)s.size(), &dwNumberOfCharsWrite, NULL);
|
WriteFile(h, s.c_str(), (DWORD)s.size(), &dwNumberOfCharsWrite, NULL);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
WriteConsoleW(h,
|
WriteConsoleW(h,
|
||||||
ws.c_str(),
|
ws.c_str(),
|
||||||
(DWORD)ws.size(),
|
(DWORD)ws.size(),
|
||||||
|
@ -433,18 +428,15 @@ namespace flutter_inappwebview_plugin
|
||||||
std::string s = vformat(format, args);
|
std::string s = vformat(format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
HANDLE h = handle_for_ostream(ostrm);
|
HANDLE h = handle_for_ostream(ostrm);
|
||||||
if (h == INVALID_HANDLE_VALUE)
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DWORD dwNumberOfCharsWrite;
|
DWORD dwNumberOfCharsWrite;
|
||||||
if (GetFileType(h) != FILE_TYPE_CHAR)
|
if (GetFileType(h) != FILE_TYPE_CHAR) {
|
||||||
{
|
|
||||||
s = utf8_to_cp(s, GetConsoleOutputCP());
|
s = utf8_to_cp(s, GetConsoleOutputCP());
|
||||||
WriteFile(h, s.c_str(), (DWORD)s.size(), &dwNumberOfCharsWrite, NULL);
|
WriteFile(h, s.c_str(), (DWORD)s.size(), &dwNumberOfCharsWrite, NULL);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
std::wstring ws = utf8_to_wide(s);
|
std::wstring ws = utf8_to_wide(s);
|
||||||
WriteConsoleW(h,
|
WriteConsoleW(h,
|
||||||
ws.c_str(),
|
ws.c_str(),
|
||||||
|
@ -461,18 +453,15 @@ namespace flutter_inappwebview_plugin
|
||||||
std::u8string s = vformat(format, args);
|
std::u8string s = vformat(format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
HANDLE h = handle_for_ostream(ostrm);
|
HANDLE h = handle_for_ostream(ostrm);
|
||||||
if (h == INVALID_HANDLE_VALUE)
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DWORD dwNumberOfCharsWrite;
|
DWORD dwNumberOfCharsWrite;
|
||||||
if (GetFileType(h) != FILE_TYPE_CHAR)
|
if (GetFileType(h) != FILE_TYPE_CHAR) {
|
||||||
{
|
|
||||||
std::string str = char8_to_cp(s, GetConsoleOutputCP());
|
std::string str = char8_to_cp(s, GetConsoleOutputCP());
|
||||||
WriteFile(h, (const char*)str.c_str(), (DWORD)str.size(), &dwNumberOfCharsWrite, NULL);
|
WriteFile(h, (const char*)str.c_str(), (DWORD)str.size(), &dwNumberOfCharsWrite, NULL);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
std::wstring ws = char8_to_wide(s);
|
std::wstring ws = char8_to_wide(s);
|
||||||
WriteConsoleW(h,
|
WriteConsoleW(h,
|
||||||
ws.c_str(),
|
ws.c_str(),
|
||||||
|
@ -490,8 +479,7 @@ namespace flutter_inappwebview_plugin
|
||||||
UINT m_target_cp;
|
UINT m_target_cp;
|
||||||
bool is_ascii(const std::string& s)
|
bool is_ascii(const std::string& s)
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < s.size(); i++)
|
for (std::size_t i = 0; i < s.size(); i++) {
|
||||||
{
|
|
||||||
unsigned char c = (unsigned char)s[i];
|
unsigned char c = (unsigned char)s[i];
|
||||||
if (c > 0x7f)
|
if (c > 0x7f)
|
||||||
return false;
|
return false;
|
||||||
|
@ -511,12 +499,10 @@ namespace flutter_inappwebview_plugin
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << x;
|
oss << x;
|
||||||
std::string output = oss.str();
|
std::string output = oss.str();
|
||||||
if (is_ascii(output))
|
if (is_ascii(output)) {
|
||||||
{
|
|
||||||
(*m_ostrm) << x;
|
(*m_ostrm) << x;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
(*m_ostrm) << utf8_to_cp(output, m_target_cp);
|
(*m_ostrm) << utf8_to_cp(output, m_target_cp);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_
|
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_
|
||||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_
|
#define FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <optional>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
#include "strconv.h"
|
#include "strconv.h"
|
||||||
|
|
||||||
namespace flutter_inappwebview_plugin
|
namespace flutter_inappwebview_plugin
|
||||||
{
|
{
|
||||||
static inline void debugLog(const std::string& msg) {
|
static inline void debugLog(const std::string& msg)
|
||||||
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
std::cout << msg << std::endl;
|
std::cout << msg << std::endl;
|
||||||
OutputDebugString(ansi_to_wide(msg + "\n").c_str());
|
OutputDebugString(ansi_to_wide(msg + "\n").c_str());
|
||||||
|
@ -24,7 +28,8 @@ namespace flutter_inappwebview_plugin
|
||||||
|
|
||||||
static inline std::string variant_to_string(const std::variant<std::string, int>& var)
|
static inline std::string variant_to_string(const std::variant<std::string, int>& var)
|
||||||
{
|
{
|
||||||
return std::visit([](auto&& arg) {
|
return std::visit([](auto&& arg)
|
||||||
|
{
|
||||||
using T = std::decay_t<decltype(arg)>;
|
using T = std::decay_t<decltype(arg)>;
|
||||||
if constexpr (std::is_same_v<T, std::string>)
|
if constexpr (std::is_same_v<T, std::string>)
|
||||||
return arg;
|
return arg;
|
||||||
|
|
Loading…
Reference in New Issue