Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit a7ece38

Browse files
committed
Modify existing code to use JavascriptChannelRegistry.
This commit modifies the existing code to make use of the JavascriptChannelRegistry class.
1 parent f3d0dd9 commit a7ece38

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

packages/webview_flutter/webview_flutter_platform_interface/lib/src/method_channel/webview_method_channel.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ import 'dart:async';
66

77
import 'package:flutter/services.dart';
88

9+
import '../platform_interface/javascript_channel_registry.dart';
910
import '../platform_interface/platform_interface.dart';
1011
import '../types/types.dart';
1112

1213
/// A [WebViewPlatformController] that uses a method channel to control the webview.
1314
class MethodChannelWebViewPlatform implements WebViewPlatformController {
1415
/// Constructs an instance that will listen for webviews broadcasting to the
1516
/// given [id], using the given [WebViewPlatformCallbacksHandler].
16-
MethodChannelWebViewPlatform(int id, this._platformCallbacksHandler)
17-
: assert(_platformCallbacksHandler != null),
17+
MethodChannelWebViewPlatform(
18+
int id,
19+
this._platformCallbacksHandler,
20+
this._javascriptChannelRegistry,
21+
) : assert(_platformCallbacksHandler != null),
1822
_channel = MethodChannel('plugins.flutter.io/webview_$id') {
1923
_channel.setMethodCallHandler(_onMethodCall);
2024
}
2125

26+
final JavascriptChannelRegistry _javascriptChannelRegistry;
27+
2228
final WebViewPlatformCallbacksHandler _platformCallbacksHandler;
2329

2430
final MethodChannel _channel;
@@ -31,7 +37,7 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController {
3137
case 'javascriptChannelMessage':
3238
final String channel = call.arguments['channel']!;
3339
final String message = call.arguments['message']!;
34-
_platformCallbacksHandler.onJavaScriptChannelMessage(channel, message);
40+
_javascriptChannelRegistry.onJavascriptChannelMessage(channel, message);
3541
return true;
3642
case 'navigationRequest':
3743
return await _platformCallbacksHandler.onNavigationRequest(

packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/platform_interface.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
export 'javascript_channel_registry.dart';
56
export 'webview_platform.dart';
67
export 'webview_platform_callbacks_handler.dart';
78
export 'webview_platform_controller.dart';

packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:flutter/foundation.dart';
66
import 'package:flutter/gestures.dart';
77
import 'package:flutter/widgets.dart';
8+
import 'package:webview_flutter_platform_interface/src/platform_interface/javascript_channel_registry.dart';
89

910
import '../types/types.dart';
1011
import 'webview_platform_callbacks_handler.dart';
@@ -50,6 +51,7 @@ abstract class WebViewPlatform {
5051
// I'll followup with the conversion PR.
5152
required CreationParams creationParams,
5253
required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler,
54+
required JavascriptChannelRegistry javascriptChannelRegistry,
5355
WebViewPlatformCreatedCallback? onWebViewPlatformCreated,
5456
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
5557
});

packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform_callbacks_handler.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import '../types/types.dart';
1111
/// The webview plugin implements this class, and passes an instance to the [WebViewPlatformController].
1212
/// [WebViewPlatformController] is notifying this handler on events that happened on the platform's webview.
1313
abstract class WebViewPlatformCallbacksHandler {
14-
/// Invoked by [WebViewPlatformController] when a JavaScript channel message is received.
15-
void onJavaScriptChannelMessage(String channel, String message);
16-
1714
/// Invoked by [WebViewPlatformController] when a navigation request is pending.
1815
///
1916
/// If true is returned the navigation is allowed, otherwise it is blocked.

packages/webview_flutter/webview_flutter_platform_interface/test/src/method_channel/webview_method_channel_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ void main() {
1717
const MethodChannel channel =
1818
MethodChannel('plugins.flutter.io/webview_$channelId');
1919
final WebViewPlatformCallbacksHandler callbacksHandler =
20-
MockWebViewPlatformCallbacksHandler();
20+
MockWebViewPlatformCallbacksHandler();
21+
final JavascriptChannelRegistry javascriptChannelRegistry =
22+
MockJavascriptChannelRegistry();
2123

2224
final List<MethodCall> log = <MethodCall>[];
2325
channel.setMockMethodCallHandler((MethodCall methodCall) async {
@@ -46,6 +48,7 @@ void main() {
4648
MethodChannelWebViewPlatform(
4749
channelId,
4850
callbacksHandler,
51+
javascriptChannelRegistry,
4952
);
5053

5154
tearDown(() {
@@ -449,3 +452,6 @@ void main() {
449452

450453
class MockWebViewPlatformCallbacksHandler extends Mock
451454
implements WebViewPlatformCallbacksHandler {}
455+
456+
class MockJavascriptChannelRegistry extends Mock
457+
implements JavascriptChannelRegistry {}

0 commit comments

Comments
 (0)