@@ -115,7 +115,9 @@ static std::string ErrorCodeToString(int errorCode) {
115
115
case RequestErrorType::UnsupportedSchemeError:
116
116
return " unsupportedScheme" ;
117
117
}
118
- std::string message = " Could not find a string for errorCode: " + errorCode;
118
+
119
+ std::string message =
120
+ " Could not find a string for errorCode: " + std::to_string (errorCode);
119
121
throw std::invalid_argument (message);
120
122
}
121
123
@@ -170,11 +172,12 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
170
172
webview->HandleMethodCall (call, std::move (result));
171
173
});
172
174
175
+ std::string url;
173
176
auto initialUrl = params[flutter::EncodableValue (" initialUrl" )];
174
177
if (std::holds_alternative<std::string>(initialUrl)) {
175
- currentUrl_ = std::get<std::string>(initialUrl);
178
+ url = std::get<std::string>(initialUrl);
176
179
} else {
177
- currentUrl_ = " about:blank" ;
180
+ url = " about:blank" ;
178
181
}
179
182
180
183
auto settings = params[flutter::EncodableValue (" settings" )];
@@ -207,7 +210,8 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
207
210
});
208
211
webViewInstance_->RegisterOnPageLoadedHandler (
209
212
[this ](LWE::WebContainer* container, const std::string& url) {
210
- LOG_DEBUG (" RegisterOnPageLoadedHandler(url: %s)\n " , url.c_str ());
213
+ LOG_DEBUG (" RegisterOnPageLoadedHandler(url: %s)(title:%s)\n " ,
214
+ url.c_str (), container->GetTitle ().c_str ());
211
215
flutter::EncodableMap map;
212
216
map.insert (
213
217
std::make_pair<flutter::EncodableValue, flutter::EncodableValue>(
@@ -261,25 +265,29 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
261
265
return true ;
262
266
});
263
267
264
- webViewInstance_->LoadURL (currentUrl_ );
268
+ webViewInstance_->LoadURL (url );
265
269
}
266
270
267
271
void WebView::ApplySettings (flutter::EncodableMap settings) {
268
272
for (auto const & [key, val] : settings) {
269
273
if (std::holds_alternative<std::string>(key)) {
270
274
std::string k = std::get<std::string>(key);
271
275
if (" jsMode" == k) {
272
- // TODO : Not implemented
276
+ // NOTE : Not supported by LWE on Tizen.
273
277
} else if (" hasNavigationDelegate" == k) {
274
278
if (std::holds_alternative<bool >(val)) {
275
279
hasNavigationDelegate_ = std::get<bool >(val);
276
280
}
277
281
} else if (" debuggingEnabled" == k) {
278
- // TODO : Not implemented
282
+ // NOTE : Not supported by LWE on Tizen.
279
283
} else if (" gestureNavigationEnabled" == k) {
280
- // TODO : Not implemented
284
+ // NOTE : Not supported by LWE on Tizen.
281
285
} else if (" userAgent" == k) {
282
- // TODO: Not implemented
286
+ if (std::holds_alternative<std::string>(val)) {
287
+ auto settings = webViewInstance_->GetSettings ();
288
+ settings.SetUserAgentString (std::get<std::string>(val));
289
+ webViewInstance_->SetSettings (settings);
290
+ }
283
291
} else {
284
292
throw std::invalid_argument (" Unknown WebView setting: " + k);
285
293
}
@@ -739,14 +747,26 @@ void WebView::HandleMethodCall(
739
747
const auto methodName = method_call.method_name ();
740
748
const auto & arguments = *method_call.arguments ();
741
749
742
- LOG_DEBUG (" HandleMethodCall : %s \n " , methodName.c_str ());
750
+ LOG_DEBUG (" WebView:: HandleMethodCall : %s \n " , methodName.c_str ());
743
751
744
752
if (methodName.compare (" loadUrl" ) == 0 ) {
745
- currentUrl_ = ExtractStringFromMap (arguments, " url" );
746
- webViewInstance_->LoadURL (GetCurrentUrl () );
753
+ std::string url = ExtractStringFromMap (arguments, " url" );
754
+ webViewInstance_->LoadURL (url );
747
755
result->Success ();
748
756
} else if (methodName.compare (" updateSettings" ) == 0 ) {
749
- result->NotImplemented ();
757
+ if (std::holds_alternative<flutter::EncodableMap>(arguments)) {
758
+ auto settings = std::get<flutter::EncodableMap>(arguments);
759
+ if (settings.size () > 0 ) {
760
+ try {
761
+ ApplySettings (settings);
762
+ } catch (const std::invalid_argument& ex) {
763
+ LOG_ERROR (" [Exception] %s\n " , ex.what ());
764
+ result->Error (ex.what ());
765
+ return ;
766
+ }
767
+ }
768
+ }
769
+ result->Success ();
750
770
} else if (methodName.compare (" canGoBack" ) == 0 ) {
751
771
result->Success (flutter::EncodableValue (webViewInstance_->CanGoBack ()));
752
772
} else if (methodName.compare (" canGoForward" ) == 0 ) {
@@ -761,7 +781,7 @@ void WebView::HandleMethodCall(
761
781
webViewInstance_->Reload ();
762
782
result->Success ();
763
783
} else if (methodName.compare (" currentUrl" ) == 0 ) {
764
- result->Success (flutter::EncodableValue (GetCurrentUrl (). c_str ()));
784
+ result->Success (flutter::EncodableValue (webViewInstance_-> GetURL ()));
765
785
} else if (methodName.compare (" evaluateJavascript" ) == 0 ) {
766
786
if (std::holds_alternative<std::string>(arguments)) {
767
787
std::string jsString = std::get<std::string>(arguments);
@@ -802,11 +822,17 @@ void WebView::HandleMethodCall(
802
822
webViewInstance_->ClearCache ();
803
823
result->Success ();
804
824
} else if (methodName.compare (" getTitle" ) == 0 ) {
805
- result->NotImplemented ( );
825
+ result->Success ( flutter::EncodableValue (webViewInstance_-> GetTitle ()) );
806
826
} else if (methodName.compare (" scrollTo" ) == 0 ) {
807
- result->NotImplemented ();
827
+ int x = ExtractIntFromMap (arguments, " x" );
828
+ int y = ExtractIntFromMap (arguments, " y" );
829
+ webViewInstance_->ScrollTo (x, y);
830
+ result->Success ();
808
831
} else if (methodName.compare (" scrollBy" ) == 0 ) {
809
- result->NotImplemented ();
832
+ int x = ExtractIntFromMap (arguments, " x" );
833
+ int y = ExtractIntFromMap (arguments, " y" );
834
+ webViewInstance_->ScrollBy (x, y);
835
+ result->Success ();
810
836
} else if (methodName.compare (" getScrollX" ) == 0 ) {
811
837
result->NotImplemented ();
812
838
} else if (methodName.compare (" getScrollY" ) == 0 ) {
0 commit comments