Skip to content

Commit

Permalink
Apply code review and update CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
seungsoo47 committed Jan 6, 2025
1 parent b629b16 commit b16fbad
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 43 deletions.
4 changes: 4 additions & 0 deletions packages/webview_flutter_lwe/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Fix an issue where platform channel isn't called on the main thread.

## 0.3.4

* Update lightweight web engine(1.3.3).
Expand Down
1 change: 1 addition & 0 deletions packages/webview_flutter_lwe/tizen/lib/armel/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.3.3
14 changes: 3 additions & 11 deletions packages/webview_flutter_lwe/tizen/src/message_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@ MessageDispatcher::MessageDispatcher() { ecore_init(); }
MessageDispatcher::~MessageDispatcher() { ecore_shutdown(); }

void MessageDispatcher::dispatchTaskOnMainThread(std::function<void()> fn) {
struct Param {
std::function<void()> fn;
};

Param* p = new Param;
p->fn = fn;

ecore_main_loop_thread_safe_call_sync(
[](void* data) -> void* {
Param* p = (Param*)data;
p->fn();
delete p;
auto fn = static_cast<std::function<void()>*>(data);
if (fn) (*fn)();
return nullptr;
},
p);
&fn);
}
62 changes: 31 additions & 31 deletions packages/webview_flutter_lwe/tizen/src/webview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int view_id,

InitWebView();

dispatcher = new MessageDispatcher();
dispatcher_ = std::make_unique<MessageDispatcher>();

webview_channel_ = std::make_unique<FlMethodChannel>(
GetPluginRegistrar()->messenger(), GetWebViewChannelName(),
Expand All @@ -150,43 +150,47 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int view_id,

webview_instance_->RegisterOnPageStartedHandler(
[this](LWE::WebContainer* container, const std::string& url) {
dispatcher->dispatchTaskOnMainThread([&]() {
flutter::EncodableMap args = {
{flutter::EncodableValue("url"), flutter::EncodableValue(url)}};
flutter::EncodableMap args = {
{flutter::EncodableValue("url"), flutter::EncodableValue(url)}};

dispatcher_->dispatchTaskOnMainThread([this, &args]() {
navigation_delegate_channel_->InvokeMethod(
"onPageStarted", std::make_unique<flutter::EncodableValue>(args));
});
});
webview_instance_->RegisterOnPageLoadedHandler(
[this](LWE::WebContainer* container, const std::string& url) {
dispatcher->dispatchTaskOnMainThread([&]() {
flutter::EncodableMap args = {
{flutter::EncodableValue("url"), flutter::EncodableValue(url)}};
flutter::EncodableMap args = {
{flutter::EncodableValue("url"), flutter::EncodableValue(url)}};

dispatcher_->dispatchTaskOnMainThread([this, &args]() {
navigation_delegate_channel_->InvokeMethod(
"onPageFinished",
std::make_unique<flutter::EncodableValue>(args));
});
});
webview_instance_->RegisterOnProgressChangedHandler(
[this](LWE::WebContainer* container, int progress) {
dispatcher->dispatchTaskOnMainThread([&]() {
flutter::EncodableMap args = {{flutter::EncodableValue("progress"),
flutter::EncodableValue(progress)}};
flutter::EncodableMap args = {{flutter::EncodableValue("progress"),
flutter::EncodableValue(progress)}};

dispatcher_->dispatchTaskOnMainThread([this, &args]() {
navigation_delegate_channel_->InvokeMethod(
"onProgress", std::make_unique<flutter::EncodableValue>(args));
});
});
webview_instance_->RegisterOnReceivedErrorHandler(
[this](LWE::WebContainer* container, LWE::ResourceError error) {
dispatcher->dispatchTaskOnMainThread([&]() {
flutter::EncodableMap args = {
{flutter::EncodableValue("errorCode"),
flutter::EncodableValue(error.GetErrorCode())},
{flutter::EncodableValue("description"),
flutter::EncodableValue(error.GetDescription())},
{flutter::EncodableValue("failingUrl"),
flutter::EncodableValue(error.GetUrl())},
};
flutter::EncodableMap args = {
{flutter::EncodableValue("errorCode"),
flutter::EncodableValue(error.GetErrorCode())},
{flutter::EncodableValue("description"),
flutter::EncodableValue(error.GetDescription())},
{flutter::EncodableValue("failingUrl"),
flutter::EncodableValue(error.GetUrl())},
};

dispatcher_->dispatchTaskOnMainThread([this, &args]() {
navigation_delegate_channel_->InvokeMethod(
"onWebResourceError",
std::make_unique<flutter::EncodableValue>(args));
Expand All @@ -197,12 +201,13 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int view_id,
if (!has_navigation_delegate_) {
return false;
}
dispatcher->dispatchTaskOnMainThread([&]() {
flutter::EncodableMap args = {
{flutter::EncodableValue("url"), flutter::EncodableValue(url)},
{flutter::EncodableValue("isForMainFrame"),
flutter::EncodableValue(true)},
};
flutter::EncodableMap args = {
{flutter::EncodableValue("url"), flutter::EncodableValue(url)},
{flutter::EncodableValue("isForMainFrame"),
flutter::EncodableValue(true)},
};

dispatcher_->dispatchTaskOnMainThread([this, &args, url]() {
auto result = std::make_unique<NavigationRequestResult>(url, this);
navigation_delegate_channel_->InvokeMethod(
"navigationRequest",
Expand All @@ -226,7 +231,7 @@ void WebView::RegisterJavaScriptChannelName(const std::string& name) {
{flutter::EncodableValue("channel"), flutter::EncodableValue(name)},
{flutter::EncodableValue("message"), flutter::EncodableValue(message)},
};
dispatcher->dispatchTaskOnMainThread([&]() {
dispatcher_->dispatchTaskOnMainThread([this, &args]() {
webview_channel_->InvokeMethod(
"javaScriptChannelMessage",
std::make_unique<flutter::EncodableValue>(args));
Expand Down Expand Up @@ -254,11 +259,6 @@ void WebView::Dispose() {
webview_instance_->Destroy();
webview_instance_ = nullptr;
}

if (dispatcher) {
delete dispatcher;
dispatcher = nullptr;
}
}

void WebView::Resize(double width, double height) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter_lwe/tizen/src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class WebView : public PlatformView {
void InitWebView();

LWE::WebContainer* webview_instance_ = nullptr;
MessageDispatcher* dispatcher = nullptr;
flutter::TextureRegistrar* texture_registrar_;
double width_;
double height_;
Expand All @@ -77,6 +76,7 @@ class WebView : public PlatformView {
BufferUnit* rendered_surface_ = nullptr;
bool is_mouse_lbutton_down_ = false;
bool has_navigation_delegate_ = false;
std::unique_ptr<MessageDispatcher> dispatcher_;
std::unique_ptr<FlMethodChannel> webview_channel_;
std::unique_ptr<FlMethodChannel> navigation_delegate_channel_;
std::unique_ptr<flutter::TextureVariant> texture_variant_;
Expand Down

0 comments on commit b16fbad

Please sign in to comment.