9
9
import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
10
10
import io .flutter .plugin .common .MethodChannel .Result ;
11
11
import io .flutter .plugin .platform .PlatformView ;
12
- import java .util .List ;
13
12
import java .util .Map ;
14
13
15
14
public class FlutterWebView implements PlatformView , MethodCallHandler {
16
- private static final String JS_CHANNEL_NAMES_FIELD = "javascriptChannelNames" ;
17
15
private final WebView webView ;
18
16
private final MethodChannel methodChannel ;
19
17
20
18
@ SuppressWarnings ("unchecked" )
21
19
FlutterWebView (Context context , BinaryMessenger messenger , int id , Map <String , Object > params ) {
22
20
webView = new WebView (context );
23
-
24
- methodChannel = new MethodChannel (messenger , "plugins.flutter.io/webview_" + id );
25
- methodChannel .setMethodCallHandler (this );
26
-
27
- applySettings ((Map <String , Object >) params .get ("settings" ));
28
-
29
- if (params .containsKey (JS_CHANNEL_NAMES_FIELD )) {
30
- registerJavaScriptChannelNames ((List <String >) params .get (JS_CHANNEL_NAMES_FIELD ));
31
- }
32
-
33
21
if (params .containsKey ("initialUrl" )) {
34
22
String url = (String ) params .get ("initialUrl" );
35
23
webView .loadUrl (url );
36
24
}
25
+ applySettings ((Map <String , Object >) params .get ("settings" ));
26
+ methodChannel = new MethodChannel (messenger , "plugins.flutter.io/webview_" + id );
27
+ methodChannel .setMethodCallHandler (this );
37
28
}
38
29
39
30
@ Override
@@ -71,12 +62,6 @@ public void onMethodCall(MethodCall methodCall, Result result) {
71
62
case "evaluateJavascript" :
72
63
evaluateJavaScript (methodCall , result );
73
64
break ;
74
- case "addJavascriptChannels" :
75
- addJavaScriptChannels (methodCall , result );
76
- break ;
77
- case "removeJavascriptChannels" :
78
- removeJavaScriptChannels (methodCall , result );
79
- break ;
80
65
default :
81
66
result .notImplemented ();
82
67
}
@@ -140,22 +125,6 @@ public void onReceiveValue(String value) {
140
125
});
141
126
}
142
127
143
- @ SuppressWarnings ("unchecked" )
144
- private void addJavaScriptChannels (MethodCall methodCall , Result result ) {
145
- List <String > channelNames = (List <String >) methodCall .arguments ;
146
- registerJavaScriptChannelNames (channelNames );
147
- result .success (null );
148
- }
149
-
150
- @ SuppressWarnings ("unchecked" )
151
- private void removeJavaScriptChannels (MethodCall methodCall , Result result ) {
152
- List <String > channelNames = (List <String >) methodCall .arguments ;
153
- for (String channelName : channelNames ) {
154
- webView .removeJavascriptInterface (channelName );
155
- }
156
- result .success (null );
157
- }
158
-
159
128
private void applySettings (Map <String , Object > settings ) {
160
129
for (String key : settings .keySet ()) {
161
130
switch (key ) {
@@ -181,13 +150,6 @@ private void updateJsMode(int mode) {
181
150
}
182
151
}
183
152
184
- private void registerJavaScriptChannelNames (List <String > channelNames ) {
185
- for (String channelName : channelNames ) {
186
- webView .addJavascriptInterface (
187
- new JavaScriptChannel (methodChannel , channelName ), channelName );
188
- }
189
- }
190
-
191
153
@ Override
192
154
public void dispose () {}
193
155
}
0 commit comments