Skip to content

Commit a438093

Browse files
seungsoo47bwikbs
authored andcommitted
[webview_flutter] Add evaluateJavascript() function (#25)
* Change the order of the headers to build the webview plugin * Implement the evaluateJavascript() function of the webview plugin Signed-off-by: Seungsoo Lee <[email protected]>
1 parent 0d2c271 commit a438093

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

packages/webview_flutter/tizen/src/webview.cc

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

2+
#include "webview.h"
3+
4+
#include <Ecore_IMF_Evas.h>
5+
#include <Ecore_Input_Evas.h>
26
#include <flutter/method_channel.h>
3-
#include <flutter/plugin_registrar.h>
4-
#include <flutter/standard_method_codec.h>
5-
#include <flutter/standard_message_codec.h>
67
#include <flutter_platform_view.h>
78
#include <flutter_texture_registrar.h>
8-
#include "webview_flutter_tizen_plugin.h"
9-
#include "webview.h"
109

1110
#include <map>
1211
#include <memory>
@@ -18,10 +17,6 @@
1817
#include "lwe/PlatformIntegrationData.h"
1918
#include "webview_factory.h"
2019

21-
#include <Ecore_Input_Evas.h>
22-
#include <Ecore_IMF_Evas.h>
23-
24-
2520
#define LWE_EXPORT
2621
extern "C" size_t LWE_EXPORT createWebViewInstance(
2722
unsigned x, unsigned y, unsigned width, unsigned height,
@@ -64,12 +59,12 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
6459
FlutterTextureRegistrar* textureRegistrar, double width,
6560
double height, const std::string initialUrl)
6661
: PlatformView(registrar, viewId),
67-
tbmSurface_(nullptr),
6862
textureRegistrar_(textureRegistrar),
6963
webViewInstance_(nullptr),
7064
currentUrl_(initialUrl),
7165
width_(width),
72-
height_(height) {
66+
height_(height),
67+
tbmSurface_(nullptr) {
7368
SetTextureId(FlutterRegisterExternalTexture(textureRegistrar_));
7469
InitWebView();
7570
auto channel =
@@ -473,7 +468,9 @@ void WebView::InitWebView() {
473468
}
474469
float scaleFactor = 1;
475470

476-
webViewInstance_ = (LWE::WebContainer*)createWebViewInstance(0,0,width_, height_,scaleFactor, "SamsungOneUI", "ko-KR", "Asia/Seoul",[this]() -> LWE::WebContainer::ExternalImageInfo {
471+
webViewInstance_ = (LWE::WebContainer*)createWebViewInstance(
472+
0, 0, width_, height_, scaleFactor, "SamsungOneUI", "ko-KR", "Asia/Seoul",
473+
[this]() -> LWE::WebContainer::ExternalImageInfo {
477474
LWE::WebContainer::ExternalImageInfo result;
478475
tbmSurface_ = tbm_surface_create(width_, height_, TBM_FORMAT_ARGB8888);
479476
tbm_surface_info_s tbmSurfaceInfo;
@@ -482,7 +479,8 @@ void WebView::InitWebView() {
482479
result.imageAddress = (void*)tbmSurface_;
483480
}
484481
return result;
485-
}, [this](LWE::WebContainer* c) {
482+
},
483+
[this](LWE::WebContainer* c) {
486484
FlutterMarkExternalTextureFrameAvailable(textureRegistrar_,
487485
GetTextureId(), tbmSurface_);
488486
tbm_surface_destroy(tbmSurface_);
@@ -528,7 +526,19 @@ void WebView::HandleMethodCall(
528526
} else if (methodName.compare("currentUrl") == 0) {
529527
result->Success(flutter::EncodableValue(GetCurrentUrl().c_str()));
530528
} else if (methodName.compare("evaluateJavascript") == 0) {
531-
result->NotImplemented();
529+
if (std::holds_alternative<std::string>(arguments)) {
530+
std::string jsString = std::get<std::string>(arguments);
531+
webViewInstance_->EvaluateJavaScript(
532+
jsString, [res = result.release()](std::string value) {
533+
LOG_DEBUG("value: %s\n", value.c_str());
534+
if (res) {
535+
res->Success(flutter::EncodableValue(value));
536+
delete res;
537+
}
538+
});
539+
} else {
540+
result->Error("Invalid Arguments", "Invalid Arguments");
541+
}
532542
} else if (methodName.compare("addJavascriptChannels") == 0) {
533543
result->NotImplemented();
534544
} else if (methodName.compare("removeJavascriptChannels") == 0) {

packages/webview_flutter/tizen/src/webview.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#ifndef FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_H_
22
#define FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_H_
33

4+
#include <flutter/plugin_registrar.h>
5+
#include <flutter/standard_message_codec.h>
6+
#include <flutter/standard_method_codec.h>
47
#include <flutter_platform_view.h>
58
#include <flutter_plugin_registrar.h>
9+
#include <flutter_texture_registrar.h>
610
#include <tbm_surface.h>
711

812
// #include "lwe/LWEWebView.h"

0 commit comments

Comments
 (0)