Skip to content

Commit

Permalink
[webview_flutter_tizen] Add tizenEnginePolicy extension api temporary
Browse files Browse the repository at this point in the history
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: #647
  • Loading branch information
JSUYA committed Mar 12, 2024
1 parent 7a4d26f commit 7cbc741
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 0.9.1

* Add ewk_set_version_policy() call.
* Add WebViewController.tizenEnginePolicy extension API temporary.

## 0.9.0

Expand Down
13 changes: 11 additions & 2 deletions packages/webview_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -76,3 +76,12 @@ 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 `WebViewController.tizenEnginePolicy` extension 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
import 'package:webview_flutter_tizen/webview_flutter_tizen.dart';
WebViewController _controller;
_controller.tizenEnginePolicy = true;
```
3 changes: 2 additions & 1 deletion packages/webview_flutter/lib/src/tizen_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>('setEnginePolicy', enginePolicy);

_callPendingMethodCalls();
}
Expand Down
15 changes: 14 additions & 1 deletion packages/webview_flutter/lib/src/tizen_webview_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_tizen/widgets.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';

import 'tizen_webview.dart';
Expand All @@ -20,6 +21,16 @@ const String kTizenNavigationDelegateChannelName =
const String kTizenWebViewControllerChannelName =
'plugins.flutter.io/tizen_webview_controller_';

/// The extension of WebViewController class for the Tizen.
extension TizenWebViewControllerExtension on WebViewController {
/// Set to engine policy.
set tizenEnginePolicy(bool enginePolicy) {
final TizenWebViewController controller =
platform as TizenWebViewController;
controller._enginePolicy = enginePolicy;
}
}

/// An implementation of [PlatformWebViewController] using the Tizen WebView API.
class TizenWebViewController extends PlatformWebViewController {
/// Constructs a [TizenWebViewController].
Expand All @@ -34,6 +45,8 @@ class TizenWebViewController extends PlatformWebViewController {

late final MethodChannel _webviewControllerChannel;

bool _enginePolicy = false;

/// Called when [TizenView] is created.
void createWebviewControllerChannel(int viewId) {
_webviewControllerChannel =
Expand Down Expand Up @@ -79,7 +92,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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 26 additions & 10 deletions packages/webview_flutter/tizen/src/webview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlMethodChannel>(
GetPluginRegistrar()->messenger(), GetWebViewChannelName(),
&flutter::StandardMethodCodec::GetInstance());
Expand Down Expand Up @@ -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<char*>("--disable-pinch"),
Expand All @@ -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(
Expand Down Expand Up @@ -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<FlMethodResult> 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<bool>(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<int32_t>(arguments);
if (mode) {
Expand Down
3 changes: 2 additions & 1 deletion packages/webview_flutter/tizen/src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 7cbc741

Please sign in to comment.