@@ -13,7 +13,8 @@ import 'js_bridge.dart';
13
13
14
14
extension on HTMLIFrameElement {
15
15
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/csp
16
- external JSString ? csp;
16
+ external set csp (String ? value);
17
+ external String ? get csp;
17
18
}
18
19
19
20
class InAppWebViewWebElement implements Disposable {
@@ -29,7 +30,7 @@ class InAppWebViewWebElement implements Disposable {
29
30
String ? headlessWebViewId;
30
31
31
32
InAppWebViewSettings ? settings;
32
- JSWebView ? webViewJS ;
33
+ JSWebView ? jsWebView ;
33
34
bool isLoading = false ;
34
35
35
36
InAppWebViewWebElement (
@@ -63,7 +64,7 @@ class InAppWebViewWebElement implements Disposable {
63
64
}
64
65
});
65
66
66
- webViewJS = flutterInAppWebView? .createFlutterInAppWebView (_viewId, iframe, iframeContainer);
67
+ jsWebView = flutterInAppWebView? .createFlutterInAppWebView (_viewId, iframe, iframeContainer);
67
68
}
68
69
69
70
/// Handles method calls over the MethodChannel of this plugin.
@@ -205,7 +206,7 @@ class InAppWebViewWebElement implements Disposable {
205
206
initialData = webView.initialData;
206
207
initialFile = webView.initialFile;
207
208
208
- webViewJS = flutterInAppWebView? .createFlutterInAppWebView (_viewId, iframe, iframeContainer);
209
+ jsWebView = flutterInAppWebView? .createFlutterInAppWebView (_viewId, iframe, iframeContainer);
209
210
}
210
211
}
211
212
}
@@ -226,7 +227,7 @@ class InAppWebViewWebElement implements Disposable {
226
227
iframe.referrerPolicy = settings! .iframeReferrerPolicy? .toNativeValue () ??
227
228
iframe.referrerPolicy;
228
229
iframe.name = settings! .iframeName ?? iframe.name;
229
- iframe.csp = settings? .iframeCsp? .toJS ?? iframe.csp;
230
+ iframe.csp = settings! .iframeCsp ?? iframe.csp;
230
231
231
232
if (settings! .iframeSandbox != null &&
232
233
settings! .iframeSandbox != Sandbox .ALLOW_ALL ) {
@@ -241,7 +242,7 @@ class InAppWebViewWebElement implements Disposable {
241
242
}
242
243
}
243
244
244
- webViewJS ? .prepare (settings? .toMap ().jsify ());
245
+ jsWebView ? .prepare (settings? .toMap ().jsify ());
245
246
}
246
247
247
248
void makeInitialLoad () async {
@@ -309,39 +310,39 @@ class InAppWebViewWebElement implements Disposable {
309
310
}
310
311
311
312
Future <void > reload () async {
312
- webViewJS ? .reload ();
313
+ jsWebView ? .reload ();
313
314
}
314
315
315
316
Future <void > goBack () async {
316
- webViewJS ? .goBack ();
317
+ jsWebView ? .goBack ();
317
318
}
318
319
319
320
Future <void > goForward () async {
320
- webViewJS ? .goForward ();
321
+ jsWebView ? .goForward ();
321
322
}
322
323
323
324
Future <void > goBackOrForward ({required int steps}) async {
324
- webViewJS ? .goBackOrForward (steps.toJS);
325
+ jsWebView ? .goBackOrForward (steps.toJS);
325
326
}
326
327
327
328
Future <dynamic > evaluateJavascript ({required String source}) async {
328
- webViewJS ? .evaluateJavascript (source.toJS);
329
+ jsWebView ? .evaluateJavascript (source.toJS);
329
330
}
330
331
331
332
Future <void > stopLoading () async {
332
- webViewJS ? .stopLoading ();
333
+ jsWebView ? .stopLoading ();
333
334
}
334
335
335
336
Future <String ?> getUrl () async {
336
- String ? url = webViewJS ? .getUrl ()? .toDart;
337
+ String ? url = jsWebView ? .getUrl ()? .toDart;
337
338
if (url == null || url.isEmpty || url == 'about:blank' ) {
338
339
url = iframe.src;
339
340
}
340
341
return url;
341
342
}
342
343
343
344
Future <String ?> getTitle () async {
344
- return webViewJS ? .getTitle ()? .toDart;
345
+ return jsWebView ? .getTitle ()? .toDart;
345
346
}
346
347
347
348
Future <void > postUrl (
@@ -354,71 +355,71 @@ class InAppWebViewWebElement implements Disposable {
354
355
Future <void > injectJavascriptFileFromUrl (
355
356
{required String urlFile,
356
357
Map <String , dynamic >? scriptHtmlTagAttributes}) async {
357
- webViewJS ? .injectJavascriptFileFromUrl (urlFile.toJS, scriptHtmlTagAttributes? .jsify ());
358
+ jsWebView ? .injectJavascriptFileFromUrl (urlFile.toJS, scriptHtmlTagAttributes? .jsify ());
358
359
}
359
360
360
361
Future <void > injectCSSCode ({required String source}) async {
361
- webViewJS ? .injectCSSCode (source.toJS);
362
+ jsWebView ? .injectCSSCode (source.toJS);
362
363
}
363
364
364
365
Future <void > injectCSSFileFromUrl (
365
366
{required String urlFile,
366
367
Map <String , dynamic >? cssLinkHtmlTagAttributes}) async {
367
- webViewJS ? .injectCSSFileFromUrl (urlFile.toJS, cssLinkHtmlTagAttributes? .jsify ());
368
+ jsWebView ? .injectCSSFileFromUrl (urlFile.toJS, cssLinkHtmlTagAttributes? .jsify ());
368
369
}
369
370
370
371
Future <void > scrollTo (
371
372
{required int x, required int y, bool animated = false }) async {
372
- webViewJS ? .scrollTo (x.toJS, y.toJS, animated.toJS);
373
+ jsWebView ? .scrollTo (x.toJS, y.toJS, animated.toJS);
373
374
}
374
375
375
376
Future <void > scrollBy (
376
377
{required int x, required int y, bool animated = false }) async {
377
- webViewJS ? .scrollBy (x.toJS, y.toJS, animated.toJS);
378
+ jsWebView ? .scrollBy (x.toJS, y.toJS, animated.toJS);
378
379
}
379
380
380
381
Future <void > printCurrentPage () async {
381
- webViewJS ? .printCurrentPage ();
382
+ jsWebView ? .printCurrentPage ();
382
383
}
383
384
384
385
Future <int ?> getContentHeight () async {
385
- return webViewJS ? .getContentHeight ()? .toDartInt;
386
+ return jsWebView ? .getContentHeight ()? .toDartInt;
386
387
}
387
388
388
389
Future <int ?> getContentWidth () async {
389
- return webViewJS ? .getContentWidth ()? .toDartInt;
390
+ return jsWebView ? .getContentWidth ()? .toDartInt;
390
391
}
391
392
392
393
Future <String ?> getOriginalUrl () async {
393
394
return iframe.src;
394
395
}
395
396
396
397
Future <String ?> getSelectedText () async {
397
- final jsPromise = webViewJS ? .getSelectedText ();
398
+ final jsPromise = jsWebView ? .getSelectedText ();
398
399
if (jsPromise != null ) {
399
400
return jsPromise.toDart.then ((value) => value? .toDart);
400
401
}
401
402
return null ;
402
403
}
403
404
404
405
Future <int ?> getScrollX () async {
405
- return webViewJS ? .getScrollX ()? .toDartInt;
406
+ return jsWebView ? .getScrollX ()? .toDartInt;
406
407
}
407
408
408
409
Future <int ?> getScrollY () async {
409
- return webViewJS ? .getScrollY ()? .toDartInt;
410
+ return jsWebView ? .getScrollY ()? .toDartInt;
410
411
}
411
412
412
413
Future <bool > isSecureContext () async {
413
- return webViewJS ? .isSecureContext ().toDart ?? false ;
414
+ return jsWebView ? .isSecureContext ().toDart ?? false ;
414
415
}
415
416
416
417
Future <bool > canScrollVertically () async {
417
- return webViewJS ? .canScrollVertically ().toDart ?? false ;
418
+ return jsWebView ? .canScrollVertically ().toDart ?? false ;
418
419
}
419
420
420
421
Future <bool > canScrollHorizontally () async {
421
- return webViewJS ? .canScrollHorizontally ().toDart ?? false ;
422
+ return jsWebView ? .canScrollHorizontally ().toDart ?? false ;
422
423
}
423
424
424
425
Set <Sandbox > getSandbox () {
@@ -436,7 +437,7 @@ class InAppWebViewWebElement implements Disposable {
436
437
}
437
438
438
439
Size getSize () {
439
- var size = webViewJS ? .getSize ();
440
+ var size = jsWebView ? .getSize ();
440
441
return Size (size! .width! .toDartDouble, size.height! .toDartDouble);
441
442
}
442
443
@@ -465,7 +466,7 @@ class InAppWebViewWebElement implements Disposable {
465
466
iframe.name = newSettings.iframeName ?? '' ;
466
467
}
467
468
if (settings! .iframeCsp != newSettings.iframeCsp) {
468
- iframe.csp = newSettings.iframeCsp? .toJS ;
469
+ iframe.csp = newSettings.iframeCsp;
469
470
}
470
471
471
472
if (settings! .iframeSandbox != newSettings.iframeSandbox) {
@@ -482,7 +483,7 @@ class InAppWebViewWebElement implements Disposable {
482
483
}
483
484
newSettings.iframeSandbox = sandbox;
484
485
485
- webViewJS ? .setSettings (newSettings.toMap ().jsify ());
486
+ jsWebView ? .setSettings (newSettings.toMap ().jsify ());
486
487
487
488
settings = newSettings;
488
489
}
0 commit comments