Skip to content

Commit 310fa0c

Browse files
committed
updates
1 parent f0beaab commit 310fa0c

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

flutter_inappwebview_web/lib/web/in_app_web_view_web_element.dart

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import 'js_bridge.dart';
1313

1414
extension on HTMLIFrameElement {
1515
// 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;
1718
}
1819

1920
class InAppWebViewWebElement implements Disposable {
@@ -29,7 +30,7 @@ class InAppWebViewWebElement implements Disposable {
2930
String? headlessWebViewId;
3031

3132
InAppWebViewSettings? settings;
32-
JSWebView? webViewJS;
33+
JSWebView? jsWebView;
3334
bool isLoading = false;
3435

3536
InAppWebViewWebElement(
@@ -63,7 +64,7 @@ class InAppWebViewWebElement implements Disposable {
6364
}
6465
});
6566

66-
webViewJS = flutterInAppWebView?.createFlutterInAppWebView(_viewId, iframe, iframeContainer);
67+
jsWebView = flutterInAppWebView?.createFlutterInAppWebView(_viewId, iframe, iframeContainer);
6768
}
6869

6970
/// Handles method calls over the MethodChannel of this plugin.
@@ -205,7 +206,7 @@ class InAppWebViewWebElement implements Disposable {
205206
initialData = webView.initialData;
206207
initialFile = webView.initialFile;
207208

208-
webViewJS = flutterInAppWebView?.createFlutterInAppWebView(_viewId, iframe, iframeContainer);
209+
jsWebView = flutterInAppWebView?.createFlutterInAppWebView(_viewId, iframe, iframeContainer);
209210
}
210211
}
211212
}
@@ -226,7 +227,7 @@ class InAppWebViewWebElement implements Disposable {
226227
iframe.referrerPolicy = settings!.iframeReferrerPolicy?.toNativeValue() ??
227228
iframe.referrerPolicy;
228229
iframe.name = settings!.iframeName ?? iframe.name;
229-
iframe.csp = settings?.iframeCsp?.toJS ?? iframe.csp;
230+
iframe.csp = settings!.iframeCsp ?? iframe.csp;
230231

231232
if (settings!.iframeSandbox != null &&
232233
settings!.iframeSandbox != Sandbox.ALLOW_ALL) {
@@ -241,7 +242,7 @@ class InAppWebViewWebElement implements Disposable {
241242
}
242243
}
243244

244-
webViewJS?.prepare(settings?.toMap().jsify());
245+
jsWebView?.prepare(settings?.toMap().jsify());
245246
}
246247

247248
void makeInitialLoad() async {
@@ -309,39 +310,39 @@ class InAppWebViewWebElement implements Disposable {
309310
}
310311

311312
Future<void> reload() async {
312-
webViewJS?.reload();
313+
jsWebView?.reload();
313314
}
314315

315316
Future<void> goBack() async {
316-
webViewJS?.goBack();
317+
jsWebView?.goBack();
317318
}
318319

319320
Future<void> goForward() async {
320-
webViewJS?.goForward();
321+
jsWebView?.goForward();
321322
}
322323

323324
Future<void> goBackOrForward({required int steps}) async {
324-
webViewJS?.goBackOrForward(steps.toJS);
325+
jsWebView?.goBackOrForward(steps.toJS);
325326
}
326327

327328
Future<dynamic> evaluateJavascript({required String source}) async {
328-
webViewJS?.evaluateJavascript(source.toJS);
329+
jsWebView?.evaluateJavascript(source.toJS);
329330
}
330331

331332
Future<void> stopLoading() async {
332-
webViewJS?.stopLoading();
333+
jsWebView?.stopLoading();
333334
}
334335

335336
Future<String?> getUrl() async {
336-
String? url = webViewJS?.getUrl()?.toDart;
337+
String? url = jsWebView?.getUrl()?.toDart;
337338
if (url == null || url.isEmpty || url == 'about:blank') {
338339
url = iframe.src;
339340
}
340341
return url;
341342
}
342343

343344
Future<String?> getTitle() async {
344-
return webViewJS?.getTitle()?.toDart;
345+
return jsWebView?.getTitle()?.toDart;
345346
}
346347

347348
Future<void> postUrl(
@@ -354,71 +355,71 @@ class InAppWebViewWebElement implements Disposable {
354355
Future<void> injectJavascriptFileFromUrl(
355356
{required String urlFile,
356357
Map<String, dynamic>? scriptHtmlTagAttributes}) async {
357-
webViewJS?.injectJavascriptFileFromUrl(urlFile.toJS, scriptHtmlTagAttributes?.jsify());
358+
jsWebView?.injectJavascriptFileFromUrl(urlFile.toJS, scriptHtmlTagAttributes?.jsify());
358359
}
359360

360361
Future<void> injectCSSCode({required String source}) async {
361-
webViewJS?.injectCSSCode(source.toJS);
362+
jsWebView?.injectCSSCode(source.toJS);
362363
}
363364

364365
Future<void> injectCSSFileFromUrl(
365366
{required String urlFile,
366367
Map<String, dynamic>? cssLinkHtmlTagAttributes}) async {
367-
webViewJS?.injectCSSFileFromUrl(urlFile.toJS, cssLinkHtmlTagAttributes?.jsify());
368+
jsWebView?.injectCSSFileFromUrl(urlFile.toJS, cssLinkHtmlTagAttributes?.jsify());
368369
}
369370

370371
Future<void> scrollTo(
371372
{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);
373374
}
374375

375376
Future<void> scrollBy(
376377
{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);
378379
}
379380

380381
Future<void> printCurrentPage() async {
381-
webViewJS?.printCurrentPage();
382+
jsWebView?.printCurrentPage();
382383
}
383384

384385
Future<int?> getContentHeight() async {
385-
return webViewJS?.getContentHeight()?.toDartInt;
386+
return jsWebView?.getContentHeight()?.toDartInt;
386387
}
387388

388389
Future<int?> getContentWidth() async {
389-
return webViewJS?.getContentWidth()?.toDartInt;
390+
return jsWebView?.getContentWidth()?.toDartInt;
390391
}
391392

392393
Future<String?> getOriginalUrl() async {
393394
return iframe.src;
394395
}
395396

396397
Future<String?> getSelectedText() async {
397-
final jsPromise = webViewJS?.getSelectedText();
398+
final jsPromise = jsWebView?.getSelectedText();
398399
if (jsPromise != null) {
399400
return jsPromise.toDart.then((value) => value?.toDart);
400401
}
401402
return null;
402403
}
403404

404405
Future<int?> getScrollX() async {
405-
return webViewJS?.getScrollX()?.toDartInt;
406+
return jsWebView?.getScrollX()?.toDartInt;
406407
}
407408

408409
Future<int?> getScrollY() async {
409-
return webViewJS?.getScrollY()?.toDartInt;
410+
return jsWebView?.getScrollY()?.toDartInt;
410411
}
411412

412413
Future<bool> isSecureContext() async {
413-
return webViewJS?.isSecureContext().toDart ?? false;
414+
return jsWebView?.isSecureContext().toDart ?? false;
414415
}
415416

416417
Future<bool> canScrollVertically() async {
417-
return webViewJS?.canScrollVertically().toDart ?? false;
418+
return jsWebView?.canScrollVertically().toDart ?? false;
418419
}
419420

420421
Future<bool> canScrollHorizontally() async {
421-
return webViewJS?.canScrollHorizontally().toDart ?? false;
422+
return jsWebView?.canScrollHorizontally().toDart ?? false;
422423
}
423424

424425
Set<Sandbox> getSandbox() {
@@ -436,7 +437,7 @@ class InAppWebViewWebElement implements Disposable {
436437
}
437438

438439
Size getSize() {
439-
var size = webViewJS?.getSize();
440+
var size = jsWebView?.getSize();
440441
return Size(size!.width!.toDartDouble, size.height!.toDartDouble);
441442
}
442443

@@ -465,7 +466,7 @@ class InAppWebViewWebElement implements Disposable {
465466
iframe.name = newSettings.iframeName ?? '';
466467
}
467468
if (settings!.iframeCsp != newSettings.iframeCsp) {
468-
iframe.csp = newSettings.iframeCsp?.toJS;
469+
iframe.csp = newSettings.iframeCsp;
469470
}
470471

471472
if (settings!.iframeSandbox != newSettings.iframeSandbox) {
@@ -482,7 +483,7 @@ class InAppWebViewWebElement implements Disposable {
482483
}
483484
newSettings.iframeSandbox = sandbox;
484485

485-
webViewJS?.setSettings(newSettings.toMap().jsify());
486+
jsWebView?.setSettings(newSettings.toMap().jsify());
486487

487488
settings = newSettings;
488489
}

0 commit comments

Comments
 (0)