@@ -172,6 +172,16 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
172
172
webview->HandleMethodCall (call, std::move (result));
173
173
});
174
174
175
+ auto cookieChannel =
176
+ std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
177
+ GetPluginRegistrar ()->messenger (),
178
+ " plugins.flutter.io/cookie_manager" ,
179
+ &flutter::StandardMethodCodec::GetInstance ());
180
+ cookieChannel->SetMethodCallHandler (
181
+ [webview = this ](const auto & call, auto result) {
182
+ webview->HandleCookieMethodCall (call, std::move (result));
183
+ });
184
+
175
185
std::string url;
176
186
auto initialUrl = params[flutter::EncodableValue (" initialUrl" )];
177
187
if (std::holds_alternative<std::string>(initialUrl)) {
@@ -198,6 +208,16 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
198
208
}
199
209
}
200
210
211
+ // TODO: Not implemented
212
+ // auto media = params[flutter::EncodableValue("autoMediaPlaybackPolicy")];
213
+
214
+ auto userAgent = params[flutter::EncodableValue (" userAgent" )];
215
+ if (std::holds_alternative<std::string>(userAgent)) {
216
+ auto settings = webViewInstance_->GetSettings ();
217
+ settings.SetUserAgentString (std::get<std::string>(userAgent));
218
+ webViewInstance_->SetSettings (settings);
219
+ }
220
+
201
221
webViewInstance_->RegisterOnPageStartedHandler (
202
222
[this ](LWE::WebContainer* container, const std::string& url) {
203
223
LOG_DEBUG (" RegisterOnPageStartedHandler(url: %s)\n " , url.c_str ());
@@ -834,9 +854,31 @@ void WebView::HandleMethodCall(
834
854
webViewInstance_->ScrollBy (x, y);
835
855
result->Success ();
836
856
} else if (methodName.compare (" getScrollX" ) == 0 ) {
837
- result->NotImplemented ( );
857
+ result->Success ( flutter::EncodableValue (webViewInstance_-> GetScrollX ()) );
838
858
} else if (methodName.compare (" getScrollY" ) == 0 ) {
859
+ result->Success (flutter::EncodableValue (webViewInstance_->GetScrollY ()));
860
+ } else {
839
861
result->NotImplemented ();
862
+ }
863
+ }
864
+
865
+ void WebView::HandleCookieMethodCall (
866
+ const flutter::MethodCall<flutter::EncodableValue>& method_call,
867
+ std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
868
+ if (webViewInstance_ == nullptr ) {
869
+ result->Error (" Not Webview created" );
870
+ return ;
871
+ }
872
+
873
+ const auto methodName = method_call.method_name ();
874
+ const auto & arguments = *method_call.arguments ();
875
+
876
+ LOG_DEBUG (" WebView::HandleMethodCall : %s \n " , methodName.c_str ());
877
+
878
+ if (methodName.compare (" clearCookies" ) == 0 ) {
879
+ LWE::CookieManager* cookie = LWE::CookieManager::GetInstance ();
880
+ cookie->ClearCookies ();
881
+ result->Success (flutter::EncodableValue (true ));
840
882
} else {
841
883
result->NotImplemented ();
842
884
}
0 commit comments