Skip to content

Commit

Permalink
[webview_flutter] Update webview_flutter to 4.2.3 (flutter-tizen#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swanseo0 authored Oct 12, 2023
1 parent 8e82fd6 commit f61b144
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 110 deletions.
6 changes: 5 additions & 1 deletion packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## NEXT
## 0.8.0

* Update webivew_flutter to 4.2.3.
* Update webview_flutter_platform_interface to 2.3.0.
* Update integration_test.
* Implement `NavigationDelegate(onUrlChange)`.
* Increase the minimum Flutter version to 3.3.

## 0.7.1
Expand Down
4 changes: 2 additions & 2 deletions packages/webview_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ This package is not an _endorsed_ implementation of `webview_flutter`. Therefore

```yaml
dependencies:
webview_flutter: ^4.0.2
webview_flutter_tizen: ^0.7.1
webview_flutter: ^4.2.3
webview_flutter_tizen: ^0.8.0
```
## Example
Expand Down

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion packages/webview_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Page resource error:
debugPrint('allowing navigation to ${request.url}');
return NavigationDecision.navigate;
},
onUrlChange: (UrlChange change) {
debugPrint('url change to ${change.url}');
},
),
)
..addJavaScriptChannel(
Expand Down Expand Up @@ -407,7 +410,7 @@ class SampleMenu extends StatelessWidget {
}

Widget _getCookieList(String cookies) {
if (cookies == null || cookies == '""') {
if (cookies == '""') {
return Container();
}
final List<String> cookieList = cookies.split(';');
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
path_provider: ^2.0.7
path_provider_tizen:
path: ../../path_provider/
webview_flutter: ^4.0.2
webview_flutter: ^4.2.3
webview_flutter_tizen:
path: ../

Expand Down
5 changes: 5 additions & 0 deletions packages/webview_flutter/lib/src/tizen_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class TizenWebView {
///
/// Defaults to false.
bool hasNavigationDelegate = false;
late int _viewId;

/// Get the if of tizen webview.
int get viewId => _viewId;

late final MethodChannel _tizenWebViewChannel;
bool _isCreated = false;
Expand Down Expand Up @@ -58,6 +62,7 @@ class TizenWebView {
/// Called when [TizenView] is created. Invokes the requested method call before [TizenWebView] is created.
void onCreate(int viewId) {
_isCreated = true;
_viewId = viewId;
_tizenWebViewChannel =
MethodChannel(kTizenWebViewChannelName + viewId.toString());
_tizenWebViewChannel.setMethodCallHandler(_onMethodCall);
Expand Down
34 changes: 30 additions & 4 deletions packages/webview_flutter/lib/src/tizen_webview_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class TizenWebViewController extends PlatformWebViewController {

/// Called when [TizenView] is created.
void onCreate(int viewId) {
_webview.onCreate(viewId);
if (_webview.hasNavigationDelegate) {
_tizenNavigationDelegate.onCreate(viewId);
_tizenNavigationDelegate.createNavigationDelegateChannel(viewId);
}
_webview.onCreate(viewId);
}

@override
Expand Down Expand Up @@ -139,7 +139,11 @@ class TizenWebViewController extends PlatformWebViewController {
Future<void> setPlatformNavigationDelegate(
covariant TizenNavigationDelegate handler) async {
_tizenNavigationDelegate = handler;
_webview.hasNavigationDelegate = true;
if (_webview.hasNavigationDelegate) {
_tizenNavigationDelegate.createNavigationDelegateChannel(_webview.viewId);
} else {
_webview.hasNavigationDelegate = true;
}
}

@override
Expand All @@ -158,6 +162,17 @@ class TizenWebViewController extends PlatformWebViewController {
@override
Future<void> setUserAgent(String? userAgent) =>
_webview.setUserAgent(userAgent);

@override
Future<void> setOnPlatformPermissionRequest(
void Function(
PlatformWebViewPermissionRequest request,
) onPermissionRequest,
) async {
throw UnimplementedError(
'This version of `TizenWebViewController` currently has no '
'implementation.');
}
}

/// An implementation of [PlatformWebViewWidget] with the Tizen WebView API.
Expand Down Expand Up @@ -272,9 +287,10 @@ class TizenNavigationDelegate extends PlatformNavigationDelegate {
ProgressCallback? _onProgress;
WebResourceErrorCallback? _onWebResourceError;
NavigationRequestCallback? _onNavigationRequest;
UrlChangeCallback? _onUrlChange;

/// Called when [TizenView] is created.
void onCreate(int viewId) {
void createNavigationDelegateChannel(int viewId) {
_navigationDelegateChannel =
MethodChannel(kTizenNavigationDelegateChannelName + viewId.toString());
_navigationDelegateChannel.setMethodCallHandler((MethodCall call) async {
Expand Down Expand Up @@ -309,6 +325,11 @@ class TizenNavigationDelegate extends PlatformNavigationDelegate {
));
}
return null;
case 'onUrlChange':
if (_onUrlChange != null) {
_onUrlChange!(UrlChange(url: arguments['url']! as String));
}
return null;
}

throw MissingPluginException(
Expand Down Expand Up @@ -381,4 +402,9 @@ class TizenNavigationDelegate extends PlatformNavigationDelegate {
) async {
_onWebResourceError = onWebResourceError;
}

@override
Future<void> setOnUrlChange(UrlChangeCallback onUrlChange) async {
_onUrlChange = onUrlChange;
}
}
6 changes: 3 additions & 3 deletions 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.7.1
version: 0.8.0

environment:
sdk: ">=2.18.0 <4.0.0"
Expand All @@ -20,5 +20,5 @@ dependencies:
flutter:
sdk: flutter
flutter_tizen: ^0.2.1
webview_flutter: ^4.0.2
webview_flutter_platform_interface: ^2.0.1
webview_flutter: ^4.2.3
webview_flutter_platform_interface: ^2.3.0
13 changes: 13 additions & 0 deletions packages/webview_flutter/tizen/src/webview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ void WebView::Dispose() {
evas_object_smart_callback_del(webview_instance_,
"policy,navigation,decide",
&WebView::OnNavigationPolicy);
evas_object_smart_callback_del(webview_instance_, "url,changed",
&WebView::OnUrlChange);
evas_object_del(webview_instance_);
}
}
Expand Down Expand Up @@ -297,6 +299,8 @@ void WebView::InitWebView() {
&WebView::OnConsoleMessage, this);
evas_object_smart_callback_add(webview_instance_, "policy,navigation,decide",
&WebView::OnNavigationPolicy, this);
evas_object_smart_callback_add(webview_instance_, "url,changed",
&WebView::OnUrlChange, this);

Resize(width_, height_);
evas_object_show(webview_instance_);
Expand Down Expand Up @@ -665,6 +669,15 @@ void WebView::OnNavigationPolicy(void* data, Evas_Object* obj,
std::move(result));
}

void WebView::OnUrlChange(void* data, Evas_Object* obj, void* event_info) {
WebView* webview = static_cast<WebView*>(data);
std::string url = std::string(ewk_view_url_get(webview->webview_instance_));
flutter::EncodableMap args = {
{flutter::EncodableValue("url"), flutter::EncodableValue(url)}};
webview->navigation_delegate_channel_->InvokeMethod(
"onUrlChange", std::make_unique<flutter::EncodableValue>(args));
}

void WebView::OnEvaluateJavaScript(Evas_Object* obj, const char* result_value,
void* user_data) {
FlMethodResult* result = static_cast<FlMethodResult*>(user_data);
Expand Down
1 change: 1 addition & 0 deletions packages/webview_flutter/tizen/src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class WebView : public PlatformView {
static void OnConsoleMessage(void* data, Evas_Object* obj, void* event_info);
static void OnNavigationPolicy(void* data, Evas_Object* obj,
void* event_info);
static void OnUrlChange(void* data, Evas_Object* obj, void* event_info);
static void OnEvaluateJavaScript(Evas_Object* obj, const char* result_value,
void* user_data);
static void OnJavaScriptMessage(Evas_Object* obj, Ewk_Script_Message message);
Expand Down

0 comments on commit f61b144

Please sign in to comment.