From 5459f78d0e9ee12926cbf4c089b67b95209677be Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Fri, 16 Feb 2024 16:30:05 +0900 Subject: [PATCH] [webview_flutter_tizen] Add setEnginePolicy api temporary There was a case where the ewk engine failed to load on some devices using Tizen 6.0. As a result, ewk init failed and an engine instance could not be created. We have not found an exact cause for this. Calling ewk_set_version_policy(1) will solve the problem, but using UWE(upgrade web engine) in 3rd party application is not recommended. (The webview works may not be guaranteed to normally.) Therefore, add a temporary API and have user application call it. This API may be deleted in the future depending on whether tizen version 6.0 is supported. related issue: https://github.com/flutter-tizen/plugins/issues/647 --- packages/webview_flutter/CHANGELOG.md | 3 +- packages/webview_flutter/README.md | 10 ++++-- .../lib/src/tizen_webview.dart | 3 +- .../lib/src/tizen_webview_controller.dart | 5 ++- packages/webview_flutter/pubspec.yaml | 2 +- packages/webview_flutter/tizen/src/webview.cc | 36 +++++++++++++------ packages/webview_flutter/tizen/src/webview.h | 3 +- 7 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 859fa9135..c142b6a71 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 0.9.1 * Add ewk_set_version_policy() call. +* Add TizenWebViewController.enginePolicy API temporary. ## 0.9.0 diff --git a/packages/webview_flutter/README.md b/packages/webview_flutter/README.md index a75600ea1..0225e4b9f 100644 --- a/packages/webview_flutter/README.md +++ b/packages/webview_flutter/README.md @@ -23,7 +23,7 @@ This package is not an _endorsed_ implementation of `webview_flutter`. Therefore ```yaml dependencies: webview_flutter: ^4.4.2 - webview_flutter_tizen: ^0.9.0 + webview_flutter_tizen: ^0.9.1 ``` ## Example @@ -63,7 +63,7 @@ This plugin is only supported on Tizen TV devices running Tizen 5.5 or later. ## Note -To play Youtube, make app's background color to transparent. +- To play Youtube, make app's background color to transparent. ```diff --- a/packages/webview_flutter/example/lib/main.dart @@ -76,3 +76,9 @@ To play Youtube, make app's background color to transparent. appBar: AppBar( title: const Text('Flutter WebView example'), ``` + +- In Tizen 6.0, there were some devices that failed to create the web view. In this case, the creation failure is resolved by using the Upgrade Web Engine (UWE) internally. If you set the `TizenWebViewController.enginePolicy` API to `true` before creating the `WebviewWidget`, the webview will internally search for another version of the engine. However, this API can be changed(or removed) at any time and is not officially guaranteed to work. + +```dart +TizenWebViewController.enginePolicy = true; +``` diff --git a/packages/webview_flutter/lib/src/tizen_webview.dart b/packages/webview_flutter/lib/src/tizen_webview.dart index 1ed3051de..67560c01a 100644 --- a/packages/webview_flutter/lib/src/tizen_webview.dart +++ b/packages/webview_flutter/lib/src/tizen_webview.dart @@ -60,12 +60,13 @@ class TizenWebView { } /// Called when [TizenView] is created. Invokes the requested method call before [TizenWebView] is created. - void onCreate(int viewId) { + void onCreate(int viewId, bool enginePolicy) { _isCreated = true; _viewId = viewId; _tizenWebViewChannel = MethodChannel(kTizenWebViewChannelName + viewId.toString()); _tizenWebViewChannel.setMethodCallHandler(_onMethodCall); + _invokeChannelMethod('setEnginePolicy', enginePolicy); _callPendingMethodCalls(); } diff --git a/packages/webview_flutter/lib/src/tizen_webview_controller.dart b/packages/webview_flutter/lib/src/tizen_webview_controller.dart index 88a47bb9c..21c1ab364 100644 --- a/packages/webview_flutter/lib/src/tizen_webview_controller.dart +++ b/packages/webview_flutter/lib/src/tizen_webview_controller.dart @@ -27,6 +27,9 @@ class TizenWebViewController extends PlatformWebViewController { : _webview = TizenWebView(), super.implementation(); + /// Set to engine policy. + static bool enginePolicy = false; + final TizenWebView _webview; late TizenNavigationDelegate _tizenNavigationDelegate; @@ -79,7 +82,7 @@ class TizenWebViewController extends PlatformWebViewController { /// Called when [TizenView] is created. void onCreate(int viewId) { - _webview.onCreate(viewId); + _webview.onCreate(viewId, enginePolicy); if (_webview.hasNavigationDelegate) { _tizenNavigationDelegate.createNavigationDelegateChannel(viewId); } diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index b22c51928..2da5143b8 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_tizen description: Tizen implementation of the webview_flutter plugin. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/master/packages/webview_flutter -version: 0.9.0 +version: 0.9.1 environment: sdk: ">=2.18.0 <4.0.0" diff --git a/packages/webview_flutter/tizen/src/webview.cc b/packages/webview_flutter/tizen/src/webview.cc index 0de9a36c6..38897b587 100644 --- a/packages/webview_flutter/tizen/src/webview.cc +++ b/packages/webview_flutter/tizen/src/webview.cc @@ -115,8 +115,6 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int view_id, })); SetTextureId(texture_registrar_->RegisterTexture(texture_variant_.get())); - InitWebView(); - webview_channel_ = std::make_unique( GetPluginRegistrar()->messenger(), GetWebViewChannelName(), &flutter::StandardMethodCodec::GetInstance()); @@ -287,8 +285,11 @@ void WebView::SetDirection(int direction) { // TODO: Implement if necessary. } -void WebView::InitWebView() { - EwkInternalApiBinding::GetInstance().main.SetVersionPolicy(1); +bool WebView::InitWebView() { + if (engine_policy_) { + LOG_INFO("Upgrade web engine used."); + EwkInternalApiBinding::GetInstance().main.SetVersionPolicy(1); + } char* chromium_argv[] = { const_cast("--disable-pinch"), @@ -304,6 +305,9 @@ void WebView::InitWebView() { Ecore_Evas* evas = ecore_evas_new("wayland_egl", 0, 0, 1, 1, 0); webview_instance_ = ewk_view_add(ecore_evas_get(evas)); + if (!webview_instance_) { + return false; + } ecore_evas_focus_set(evas, true); ewk_view_focus_set(webview_instance_, true); EwkInternalApiBinding::GetInstance().view.OffscreenRenderingEnabledSet( @@ -350,19 +354,31 @@ void WebView::InitWebView() { evas_object_show(webview_instance_); evas_object_data_set(webview_instance_, kEwkInstance, this); + + return true; } void WebView::HandleWebViewMethodCall(const FlMethodCall& method_call, std::unique_ptr result) { - if (!webview_instance_) { - result->Error("Invalid operation", - "The webview instance has not been initialized."); - return; - } - const std::string& method_name = method_call.method_name(); const flutter::EncodableValue* arguments = method_call.arguments(); + if (method_name == "setEnginePolicy") { + const auto* engine_policy = std::get_if(arguments); + if (engine_policy) { + engine_policy_ = *engine_policy; + } + result->Success(); + } + + if (!webview_instance_) { + if (!InitWebView()) { + result->Error("Invalid operation", + "The webview instance initialize failed."); + return; + } + } + if (method_name == "javaScriptMode") { const auto* mode = std::get_if(arguments); if (mode) { diff --git a/packages/webview_flutter/tizen/src/webview.h b/packages/webview_flutter/tizen/src/webview.h index 76eaa25bc..db81a028f 100644 --- a/packages/webview_flutter/tizen/src/webview.h +++ b/packages/webview_flutter/tizen/src/webview.h @@ -67,7 +67,7 @@ class WebView : public PlatformView { std::string GetWebViewControllerChannelName(); std::string GetNavigationDelegateChannelName(); - void InitWebView(); + bool InitWebView(); static void OnFrameRendered(void* data, Evas_Object* obj, void* event_info); static void OnLoadStarted(void* data, Evas_Object* obj, void* event_info); @@ -84,6 +84,7 @@ class WebView : public PlatformView { Evas_Object* webview_instance_ = nullptr; flutter::TextureRegistrar* texture_registrar_; + bool engine_policy_ = false; double width_ = 0.0; double height_ = 0.0; double left_ = 0.0;