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