handleMethod method

Future handleMethod(
  1. MethodCall call
)

Implementation

Future<dynamic> handleMethod(MethodCall call) async {
  if (WebView.debugLoggingSettings.enabled &&
      call.method != "onCallJsHandler") {
    _debugLog(call.method, call.arguments);
  }

  switch (call.method) {
    case "onLoadStart":
      _injectedScriptsFromURL.clear();
      if ((_webview != null && _webview!.onLoadStart != null) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        WebUri? uri = url != null ? WebUri(url) : null;
        if (_webview != null && _webview!.onLoadStart != null)
          _webview!.onLoadStart!(this, uri);
        else
          _inAppBrowser!.onLoadStart(uri);
      }
      break;
    case "onLoadStop":
      if ((_webview != null && _webview!.onLoadStop != null) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        WebUri? uri = url != null ? WebUri(url) : null;
        if (_webview != null && _webview!.onLoadStop != null)
          _webview!.onLoadStop!(this, uri);
        else
          _inAppBrowser!.onLoadStop(uri);
      }
      break;
    case "onReceivedError":
      if ((_webview != null &&
              (_webview!.onReceivedError != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.onLoadError != null)) ||
          _inAppBrowser != null) {
        WebResourceRequest request = WebResourceRequest.fromMap(
            call.arguments["request"].cast<String, dynamic>())!;
        WebResourceError error = WebResourceError.fromMap(
            call.arguments["error"].cast<String, dynamic>())!;
        var isForMainFrame = request.isForMainFrame ?? false;

        if (_webview != null) {
          if (_webview!.onReceivedError != null)
            _webview!.onReceivedError!(this, request, error);
          else if (isForMainFrame) {
            // ignore: deprecated_member_use_from_same_package
            _webview!.onLoadError!(this, request.url,
                error.type.toNativeValue() ?? -1, error.description);
          }
        } else {
          if (isForMainFrame) {
            _inAppBrowser!
                // ignore: deprecated_member_use_from_same_package
                .onLoadError(request.url, error.type.toNativeValue() ?? -1,
                    error.description);
          }
          _inAppBrowser!.onReceivedError(request, error);
        }
      }
      break;
    case "onReceivedHttpError":
      if ((_webview != null &&
              (_webview!.onReceivedHttpError != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.onLoadHttpError != null)) ||
          _inAppBrowser != null) {
        WebResourceRequest request = WebResourceRequest.fromMap(
            call.arguments["request"].cast<String, dynamic>())!;
        WebResourceResponse errorResponse = WebResourceResponse.fromMap(
            call.arguments["errorResponse"].cast<String, dynamic>())!;
        var isForMainFrame = request.isForMainFrame ?? false;

        if (_webview != null) {
          if (_webview!.onReceivedHttpError != null)
            _webview!.onReceivedHttpError!(this, request, errorResponse);
          else if (isForMainFrame) {
            // ignore: deprecated_member_use_from_same_package
            _webview!.onLoadHttpError!(
                this,
                request.url,
                errorResponse.statusCode ?? -1,
                errorResponse.reasonPhrase ?? '');
          }
        } else {
          if (isForMainFrame) {
            _inAppBrowser!
                // ignore: deprecated_member_use_from_same_package
                .onLoadHttpError(request.url, errorResponse.statusCode ?? -1,
                    errorResponse.reasonPhrase ?? '');
          }
          _inAppBrowser!.onReceivedHttpError(request, errorResponse);
        }
      }
      break;
    case "onProgressChanged":
      if ((_webview != null && _webview!.onProgressChanged != null) ||
          _inAppBrowser != null) {
        int progress = call.arguments["progress"];
        if (_webview != null && _webview!.onProgressChanged != null)
          _webview!.onProgressChanged!(this, progress);
        else
          _inAppBrowser!.onProgressChanged(progress);
      }
      break;
    case "shouldOverrideUrlLoading":
      if ((_webview != null && _webview!.shouldOverrideUrlLoading != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        NavigationAction navigationAction =
            NavigationAction.fromMap(arguments)!;

        if (_webview != null && _webview!.shouldOverrideUrlLoading != null)
          return (await _webview!.shouldOverrideUrlLoading!(
                  this, navigationAction))
              ?.toNativeValue();
        return (await _inAppBrowser!
                .shouldOverrideUrlLoading(navigationAction))
            ?.toNativeValue();
      }
      break;
    case "onConsoleMessage":
      if ((_webview != null && _webview!.onConsoleMessage != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        ConsoleMessage consoleMessage = ConsoleMessage.fromMap(arguments)!;
        if (_webview != null && _webview!.onConsoleMessage != null)
          _webview!.onConsoleMessage!(this, consoleMessage);
        else
          _inAppBrowser!.onConsoleMessage(consoleMessage);
      }
      break;
    case "onScrollChanged":
      if ((_webview != null && _webview!.onScrollChanged != null) ||
          _inAppBrowser != null) {
        int x = call.arguments["x"];
        int y = call.arguments["y"];
        if (_webview != null && _webview!.onScrollChanged != null)
          _webview!.onScrollChanged!(this, x, y);
        else
          _inAppBrowser!.onScrollChanged(x, y);
      }
      break;
    case "onDownloadStartRequest":
      if ((_webview != null &&
              // ignore: deprecated_member_use_from_same_package
              (_webview!.onDownloadStart != null ||
                  _webview!.onDownloadStartRequest != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        DownloadStartRequest downloadStartRequest =
            DownloadStartRequest.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.onDownloadStartRequest != null)
            _webview!.onDownloadStartRequest!(this, downloadStartRequest);
          else {
            // ignore: deprecated_member_use_from_same_package
            _webview!.onDownloadStart!(this, downloadStartRequest.url);
          }
        } else {
          // ignore: deprecated_member_use_from_same_package
          _inAppBrowser!.onDownloadStart(downloadStartRequest.url);
          _inAppBrowser!.onDownloadStartRequest(downloadStartRequest);
        }
      }
      break;
    case "onLoadResourceWithCustomScheme":
      if ((_webview != null &&
              (_webview!.onLoadResourceWithCustomScheme != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.onLoadResourceCustomScheme != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> requestMap =
            call.arguments["request"].cast<String, dynamic>();
        WebResourceRequest request = WebResourceRequest.fromMap(requestMap)!;

        if (_webview != null) {
          if (_webview!.onLoadResourceWithCustomScheme != null)
            return (await _webview!.onLoadResourceWithCustomScheme!(
                    this, request))
                ?.toMap();
          else {
            return (await _webview!
                    // ignore: deprecated_member_use_from_same_package
                    .onLoadResourceCustomScheme!(this, request.url))
                ?.toMap();
          }
        } else {
          return ((await _inAppBrowser!
                      .onLoadResourceWithCustomScheme(request)) ??
                  (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .onLoadResourceCustomScheme(request.url)))
              ?.toMap();
        }
      }
      break;
    case "onCreateWindow":
      if ((_webview != null && _webview!.onCreateWindow != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        CreateWindowAction createWindowAction =
            CreateWindowAction.fromMap(arguments)!;

        if (_webview != null && _webview!.onCreateWindow != null)
          return await _webview!.onCreateWindow!(this, createWindowAction);
        else
          return await _inAppBrowser!.onCreateWindow(createWindowAction);
      }
      break;
    case "onCloseWindow":
      if (_webview != null && _webview!.onCloseWindow != null)
        _webview!.onCloseWindow!(this);
      else if (_inAppBrowser != null) _inAppBrowser!.onCloseWindow();
      break;
    case "onTitleChanged":
      if ((_webview != null && _webview!.onTitleChanged != null) ||
          _inAppBrowser != null) {
        String? title = call.arguments["title"];
        if (_webview != null && _webview!.onTitleChanged != null)
          _webview!.onTitleChanged!(this, title);
        else
          _inAppBrowser!.onTitleChanged(title);
      }
      break;
    case "onGeolocationPermissionsShowPrompt":
      if ((_webview != null &&
              (_webview!.onGeolocationPermissionsShowPrompt != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnGeolocationPermissionsShowPrompt !=
                      null)) ||
          _inAppBrowser != null) {
        String origin = call.arguments["origin"];

        if (_webview != null) {
          if (_webview!.onGeolocationPermissionsShowPrompt != null)
            return (await _webview!.onGeolocationPermissionsShowPrompt!(
                    this, origin))
                ?.toMap();
          else {
            return (await _webview!
                    // ignore: deprecated_member_use_from_same_package
                    .androidOnGeolocationPermissionsShowPrompt!(this, origin))
                ?.toMap();
          }
        } else {
          return ((await _inAppBrowser!
                      .onGeolocationPermissionsShowPrompt(origin)) ??
                  (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .androidOnGeolocationPermissionsShowPrompt(origin)))
              ?.toMap();
        }
      }
      break;
    case "onGeolocationPermissionsHidePrompt":
      if (_webview != null &&
          (_webview!.onGeolocationPermissionsHidePrompt != null ||
              // ignore: deprecated_member_use_from_same_package
              _webview!.androidOnGeolocationPermissionsHidePrompt != null)) {
        if (_webview!.onGeolocationPermissionsHidePrompt != null)
          _webview!.onGeolocationPermissionsHidePrompt!(this);
        else {
          // ignore: deprecated_member_use_from_same_package
          _webview!.androidOnGeolocationPermissionsHidePrompt!(this);
        }
      } else if (_inAppBrowser != null) {
        _inAppBrowser!.onGeolocationPermissionsHidePrompt();
        // ignore: deprecated_member_use_from_same_package
        _inAppBrowser!.androidOnGeolocationPermissionsHidePrompt();
      }
      break;
    case "shouldInterceptRequest":
      if ((_webview != null &&
              (_webview!.shouldInterceptRequest != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidShouldInterceptRequest != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        WebResourceRequest request = WebResourceRequest.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.shouldInterceptRequest != null)
            return (await _webview!.shouldInterceptRequest!(this, request))
                ?.toMap();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.androidShouldInterceptRequest!(
                    this, request))
                ?.toMap();
          }
        } else {
          return ((await _inAppBrowser!.shouldInterceptRequest(request)) ??
                  (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .androidShouldInterceptRequest(request)))
              ?.toMap();
        }
      }
      break;
    case "onRenderProcessUnresponsive":
      if ((_webview != null &&
              (_webview!.onRenderProcessUnresponsive != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnRenderProcessUnresponsive != null)) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        WebUri? uri = url != null ? WebUri(url) : null;

        if (_webview != null) {
          if (_webview!.onRenderProcessUnresponsive != null)
            return (await _webview!.onRenderProcessUnresponsive!(this, uri))
                ?.toNativeValue();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.androidOnRenderProcessUnresponsive!(
                    this, uri))
                ?.toNativeValue();
          }
        } else {
          return ((await _inAppBrowser!.onRenderProcessUnresponsive(uri)) ??
                  (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .androidOnRenderProcessUnresponsive(uri)))
              ?.toNativeValue();
        }
      }
      break;
    case "onRenderProcessResponsive":
      if ((_webview != null &&
              (_webview!.onRenderProcessResponsive != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnRenderProcessResponsive != null)) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        WebUri? uri = url != null ? WebUri(url) : null;

        if (_webview != null) {
          if (_webview!.onRenderProcessResponsive != null)
            return (await _webview!.onRenderProcessResponsive!(this, uri))
                ?.toNativeValue();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.androidOnRenderProcessResponsive!(
                    this, uri))
                ?.toNativeValue();
          }
        } else {
          return ((await _inAppBrowser!.onRenderProcessResponsive(uri)) ??
                  (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .androidOnRenderProcessResponsive(uri)))
              ?.toNativeValue();
        }
      }
      break;
    case "onRenderProcessGone":
      if ((_webview != null &&
              (_webview!.onRenderProcessGone != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnRenderProcessGone != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        RenderProcessGoneDetail detail =
            RenderProcessGoneDetail.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.onRenderProcessGone != null)
            _webview!.onRenderProcessGone!(this, detail);
          else {
            // ignore: deprecated_member_use_from_same_package
            _webview!.androidOnRenderProcessGone!(this, detail);
          }
        } else if (_inAppBrowser != null) {
          _inAppBrowser!.onRenderProcessGone(detail);
          // ignore: deprecated_member_use_from_same_package
          _inAppBrowser!.androidOnRenderProcessGone(detail);
        }
      }
      break;
    case "onFormResubmission":
      if ((_webview != null &&
              (_webview!.onFormResubmission != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnFormResubmission != null)) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        WebUri? uri = url != null ? WebUri(url) : null;

        if (_webview != null) {
          if (_webview!.onFormResubmission != null)
            return (await _webview!.onFormResubmission!(this, uri))
                ?.toNativeValue();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.androidOnFormResubmission!(this, uri))
                ?.toNativeValue();
          }
        } else {
          return ((await _inAppBrowser!.onFormResubmission(uri)) ??
                  // ignore: deprecated_member_use_from_same_package
                  (await _inAppBrowser!.androidOnFormResubmission(uri)))
              ?.toNativeValue();
        }
      }
      break;
    case "onZoomScaleChanged":
      if ((_webview != null &&
              // ignore: deprecated_member_use_from_same_package
              (_webview!.androidOnScaleChanged != null ||
                  _webview!.onZoomScaleChanged != null)) ||
          _inAppBrowser != null) {
        double oldScale = call.arguments["oldScale"];
        double newScale = call.arguments["newScale"];

        if (_webview != null) {
          if (_webview!.onZoomScaleChanged != null)
            _webview!.onZoomScaleChanged!(this, oldScale, newScale);
          else {
            // ignore: deprecated_member_use_from_same_package
            _webview!.androidOnScaleChanged!(this, oldScale, newScale);
          }
        } else {
          _inAppBrowser!.onZoomScaleChanged(oldScale, newScale);
          // ignore: deprecated_member_use_from_same_package
          _inAppBrowser!.androidOnScaleChanged(oldScale, newScale);
        }
      }
      break;
    case "onReceivedIcon":
      if ((_webview != null &&
              (_webview!.onReceivedIcon != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnReceivedIcon != null)) ||
          _inAppBrowser != null) {
        Uint8List icon =
            Uint8List.fromList(call.arguments["icon"].cast<int>());

        if (_webview != null) {
          if (_webview!.onReceivedIcon != null)
            _webview!.onReceivedIcon!(this, icon);
          else {
            // ignore: deprecated_member_use_from_same_package
            _webview!.androidOnReceivedIcon!(this, icon);
          }
        } else {
          _inAppBrowser!.onReceivedIcon(icon);
          // ignore: deprecated_member_use_from_same_package
          _inAppBrowser!.androidOnReceivedIcon(icon);
        }
      }
      break;
    case "onReceivedTouchIconUrl":
      if ((_webview != null &&
              (_webview!.onReceivedTouchIconUrl != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnReceivedTouchIconUrl != null)) ||
          _inAppBrowser != null) {
        String url = call.arguments["url"];
        bool precomposed = call.arguments["precomposed"];
        WebUri uri = WebUri(url);

        if (_webview != null) {
          if (_webview!.onReceivedTouchIconUrl != null)
            _webview!.onReceivedTouchIconUrl!(this, uri, precomposed);
          else {
            // ignore: deprecated_member_use_from_same_package
            _webview!.androidOnReceivedTouchIconUrl!(this, uri, precomposed);
          }
        } else {
          _inAppBrowser!.onReceivedTouchIconUrl(uri, precomposed);
          // ignore: deprecated_member_use_from_same_package
          _inAppBrowser!.androidOnReceivedTouchIconUrl(uri, precomposed);
        }
      }
      break;
    case "onJsAlert":
      if ((_webview != null && _webview!.onJsAlert != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        JsAlertRequest jsAlertRequest = JsAlertRequest.fromMap(arguments)!;

        if (_webview != null && _webview!.onJsAlert != null)
          return (await _webview!.onJsAlert!(this, jsAlertRequest))?.toMap();
        else
          return (await _inAppBrowser!.onJsAlert(jsAlertRequest))?.toMap();
      }
      break;
    case "onJsConfirm":
      if ((_webview != null && _webview!.onJsConfirm != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        JsConfirmRequest jsConfirmRequest =
            JsConfirmRequest.fromMap(arguments)!;

        if (_webview != null && _webview!.onJsConfirm != null)
          return (await _webview!.onJsConfirm!(this, jsConfirmRequest))
              ?.toMap();
        else
          return (await _inAppBrowser!.onJsConfirm(jsConfirmRequest))
              ?.toMap();
      }
      break;
    case "onJsPrompt":
      if ((_webview != null && _webview!.onJsPrompt != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        JsPromptRequest jsPromptRequest = JsPromptRequest.fromMap(arguments)!;

        if (_webview != null && _webview!.onJsPrompt != null)
          return (await _webview!.onJsPrompt!(this, jsPromptRequest))
              ?.toMap();
        else
          return (await _inAppBrowser!.onJsPrompt(jsPromptRequest))?.toMap();
      }
      break;
    case "onJsBeforeUnload":
      if ((_webview != null &&
              (_webview!.onJsBeforeUnload != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnJsBeforeUnload != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        JsBeforeUnloadRequest jsBeforeUnloadRequest =
            JsBeforeUnloadRequest.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.onJsBeforeUnload != null)
            return (await _webview!.onJsBeforeUnload!(
                    this, jsBeforeUnloadRequest))
                ?.toMap();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.androidOnJsBeforeUnload!(
                    this, jsBeforeUnloadRequest))
                ?.toMap();
          }
        } else {
          return ((await _inAppBrowser!
                      .onJsBeforeUnload(jsBeforeUnloadRequest)) ??
                  (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .androidOnJsBeforeUnload(jsBeforeUnloadRequest)))
              ?.toMap();
        }
      }
      break;
    case "onSafeBrowsingHit":
      if ((_webview != null &&
              (_webview!.onSafeBrowsingHit != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnSafeBrowsingHit != null)) ||
          _inAppBrowser != null) {
        String url = call.arguments["url"];
        SafeBrowsingThreat? threatType =
            SafeBrowsingThreat.fromNativeValue(call.arguments["threatType"]);
        WebUri uri = WebUri(url);

        if (_webview != null) {
          if (_webview!.onSafeBrowsingHit != null)
            return (await _webview!.onSafeBrowsingHit!(this, uri, threatType))
                ?.toMap();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.androidOnSafeBrowsingHit!(
                    this, uri, threatType))
                ?.toMap();
          }
        } else {
          return ((await _inAppBrowser!.onSafeBrowsingHit(uri, threatType)) ??
                  (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .androidOnSafeBrowsingHit(uri, threatType)))
              ?.toMap();
        }
      }
      break;
    case "onReceivedLoginRequest":
      if ((_webview != null &&
              (_webview!.onReceivedLoginRequest != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnReceivedLoginRequest != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        LoginRequest loginRequest = LoginRequest.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.onReceivedLoginRequest != null)
            _webview!.onReceivedLoginRequest!(this, loginRequest);
          else {
            // ignore: deprecated_member_use_from_same_package
            _webview!.androidOnReceivedLoginRequest!(this, loginRequest);
          }
        } else {
          _inAppBrowser!.onReceivedLoginRequest(loginRequest);
          // ignore: deprecated_member_use_from_same_package
          _inAppBrowser!.androidOnReceivedLoginRequest(loginRequest);
        }
      }
      break;
    case "onPermissionRequestCanceled":
      if ((_webview != null &&
              _webview!.onPermissionRequestCanceled != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        PermissionRequest permissionRequest =
            PermissionRequest.fromMap(arguments)!;

        if (_webview != null && _webview!.onPermissionRequestCanceled != null)
          _webview!.onPermissionRequestCanceled!(this, permissionRequest);
        else
          _inAppBrowser!.onPermissionRequestCanceled(permissionRequest);
      }
      break;
    case "onRequestFocus":
      if ((_webview != null && _webview!.onRequestFocus != null) ||
          _inAppBrowser != null) {
        if (_webview != null && _webview!.onRequestFocus != null)
          _webview!.onRequestFocus!(this);
        else
          _inAppBrowser!.onRequestFocus();
      }
      break;
    case "onReceivedHttpAuthRequest":
      if ((_webview != null && _webview!.onReceivedHttpAuthRequest != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        HttpAuthenticationChallenge challenge =
            HttpAuthenticationChallenge.fromMap(arguments)!;

        if (_webview != null && _webview!.onReceivedHttpAuthRequest != null)
          return (await _webview!.onReceivedHttpAuthRequest!(this, challenge))
              ?.toMap();
        else
          return (await _inAppBrowser!.onReceivedHttpAuthRequest(challenge))
              ?.toMap();
      }
      break;
    case "onReceivedServerTrustAuthRequest":
      if ((_webview != null &&
              _webview!.onReceivedServerTrustAuthRequest != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        ServerTrustChallenge challenge =
            ServerTrustChallenge.fromMap(arguments)!;

        if (_webview != null &&
            _webview!.onReceivedServerTrustAuthRequest != null)
          return (await _webview!.onReceivedServerTrustAuthRequest!(
                  this, challenge))
              ?.toMap();
        else
          return (await _inAppBrowser!
                  .onReceivedServerTrustAuthRequest(challenge))
              ?.toMap();
      }
      break;
    case "onReceivedClientCertRequest":
      if ((_webview != null &&
              _webview!.onReceivedClientCertRequest != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        ClientCertChallenge challenge =
            ClientCertChallenge.fromMap(arguments)!;

        if (_webview != null && _webview!.onReceivedClientCertRequest != null)
          return (await _webview!.onReceivedClientCertRequest!(
                  this, challenge))
              ?.toMap();
        else
          return (await _inAppBrowser!.onReceivedClientCertRequest(challenge))
              ?.toMap();
      }
      break;
    case "onFindResultReceived":
      if ((_webview != null &&
              (_webview!.onFindResultReceived != null ||
                  (_webview!.findInteractionController != null &&
                      _webview!.findInteractionController!
                              .onFindResultReceived !=
                          null))) ||
          _inAppBrowser != null) {
        int activeMatchOrdinal = call.arguments["activeMatchOrdinal"];
        int numberOfMatches = call.arguments["numberOfMatches"];
        bool isDoneCounting = call.arguments["isDoneCounting"];
        if (_webview != null) {
          if (_webview!.findInteractionController != null &&
              _webview!.findInteractionController!.onFindResultReceived !=
                  null)
            _webview!.findInteractionController!.onFindResultReceived!(
                _webview!.findInteractionController!,
                activeMatchOrdinal,
                numberOfMatches,
                isDoneCounting);
          else
            _webview!.onFindResultReceived!(
                this, activeMatchOrdinal, numberOfMatches, isDoneCounting);
        } else {
          if (_inAppBrowser!.findInteractionController != null &&
              _inAppBrowser!
                      .findInteractionController!.onFindResultReceived !=
                  null)
            _inAppBrowser!.findInteractionController!.onFindResultReceived!(
                _webview!.findInteractionController!,
                activeMatchOrdinal,
                numberOfMatches,
                isDoneCounting);
          else
            _inAppBrowser!.onFindResultReceived(
                activeMatchOrdinal, numberOfMatches, isDoneCounting);
        }
      }
      break;
    case "onPermissionRequest":
      if ((_webview != null &&
              (_webview!.onPermissionRequest != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.androidOnPermissionRequest != null)) ||
          _inAppBrowser != null) {
        String origin = call.arguments["origin"];
        List<String> resources = call.arguments["resources"].cast<String>();

        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        PermissionRequest permissionRequest =
            PermissionRequest.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.onPermissionRequest != null)
            return (await _webview!.onPermissionRequest!(
                    this, permissionRequest))
                ?.toMap();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.androidOnPermissionRequest!(
                    this, origin, resources))
                ?.toMap();
          }
        } else {
          return (await _inAppBrowser!.onPermissionRequest(permissionRequest))
                  ?.toMap() ??
              (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .androidOnPermissionRequest(origin, resources))
                  ?.toMap();
        }
      }
      break;
    case "onUpdateVisitedHistory":
      if ((_webview != null && _webview!.onUpdateVisitedHistory != null) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        bool? isReload = call.arguments["isReload"];
        WebUri? uri = url != null ? WebUri(url) : null;
        if (_webview != null && _webview!.onUpdateVisitedHistory != null)
          _webview!.onUpdateVisitedHistory!(this, uri, isReload);
        else
          _inAppBrowser!.onUpdateVisitedHistory(uri, isReload);
      }
      break;
    case "onWebContentProcessDidTerminate":
      if (_webview != null &&
          (_webview!.onWebContentProcessDidTerminate != null ||
              // ignore: deprecated_member_use_from_same_package
              _webview!.iosOnWebContentProcessDidTerminate != null)) {
        if (_webview!.onWebContentProcessDidTerminate != null)
          _webview!.onWebContentProcessDidTerminate!(this);
        else {
          // ignore: deprecated_member_use_from_same_package
          _webview!.iosOnWebContentProcessDidTerminate!(this);
        }
      } else if (_inAppBrowser != null) {
        _inAppBrowser!.onWebContentProcessDidTerminate();
        // ignore: deprecated_member_use_from_same_package
        _inAppBrowser!.iosOnWebContentProcessDidTerminate();
      }
      break;
    case "onPageCommitVisible":
      if ((_webview != null && _webview!.onPageCommitVisible != null) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        WebUri? uri = url != null ? WebUri(url) : null;
        if (_webview != null && _webview!.onPageCommitVisible != null)
          _webview!.onPageCommitVisible!(this, uri);
        else
          _inAppBrowser!.onPageCommitVisible(uri);
      }
      break;
    case "onDidReceiveServerRedirectForProvisionalNavigation":
      if (_webview != null &&
          (_webview!.onDidReceiveServerRedirectForProvisionalNavigation !=
                  null ||
              _webview!
                      // ignore: deprecated_member_use_from_same_package
                      .iosOnDidReceiveServerRedirectForProvisionalNavigation !=
                  null)) {
        if (_webview!.onDidReceiveServerRedirectForProvisionalNavigation !=
            null)
          _webview!.onDidReceiveServerRedirectForProvisionalNavigation!(this);
        else {
          _webview!
              // ignore: deprecated_member_use_from_same_package
              .iosOnDidReceiveServerRedirectForProvisionalNavigation!(this);
        }
      } else if (_inAppBrowser != null) {
        _inAppBrowser!.onDidReceiveServerRedirectForProvisionalNavigation();
        _inAppBrowser!
            // ignore: deprecated_member_use_from_same_package
            .iosOnDidReceiveServerRedirectForProvisionalNavigation();
      }
      break;
    case "onNavigationResponse":
      if ((_webview != null &&
              (_webview!.onNavigationResponse != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.iosOnNavigationResponse != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        // ignore: deprecated_member_use_from_same_package
        IOSWKNavigationResponse iosOnNavigationResponse =
            // ignore: deprecated_member_use_from_same_package
            IOSWKNavigationResponse.fromMap(arguments)!;

        NavigationResponse navigationResponse =
            NavigationResponse.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.onNavigationResponse != null)
            return (await _webview!.onNavigationResponse!(
                    this, navigationResponse))
                ?.toNativeValue();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.iosOnNavigationResponse!(
                    this, iosOnNavigationResponse))
                ?.toNativeValue();
          }
        } else {
          return (await _inAppBrowser!
                      .onNavigationResponse(navigationResponse))
                  ?.toNativeValue() ??
              (await _inAppBrowser!
                      // ignore: deprecated_member_use_from_same_package
                      .iosOnNavigationResponse(iosOnNavigationResponse))
                  ?.toNativeValue();
        }
      }
      break;
    case "shouldAllowDeprecatedTLS":
      if ((_webview != null &&
              (_webview!.shouldAllowDeprecatedTLS != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.iosShouldAllowDeprecatedTLS != null)) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        URLAuthenticationChallenge challenge =
            URLAuthenticationChallenge.fromMap(arguments)!;

        if (_webview != null) {
          if (_webview!.shouldAllowDeprecatedTLS != null)
            return (await _webview!.shouldAllowDeprecatedTLS!(
                    this, challenge))
                ?.toNativeValue();
          else {
            // ignore: deprecated_member_use_from_same_package
            return (await _webview!.iosShouldAllowDeprecatedTLS!(
                    this, challenge))
                ?.toNativeValue();
          }
        } else {
          return (await _inAppBrowser!.shouldAllowDeprecatedTLS(challenge))
                  ?.toNativeValue() ??
              // ignore: deprecated_member_use_from_same_package
              (await _inAppBrowser!.iosShouldAllowDeprecatedTLS(challenge))
                  ?.toNativeValue();
        }
      }
      break;
    case "onLongPressHitTestResult":
      if ((_webview != null && _webview!.onLongPressHitTestResult != null) ||
          _inAppBrowser != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        InAppWebViewHitTestResult hitTestResult =
            InAppWebViewHitTestResult.fromMap(arguments)!;

        if (_webview != null && _webview!.onLongPressHitTestResult != null)
          _webview!.onLongPressHitTestResult!(this, hitTestResult);
        else
          _inAppBrowser!.onLongPressHitTestResult(hitTestResult);
      }
      break;
    case "onCreateContextMenu":
      ContextMenu? contextMenu;
      if (_webview != null && _webview!.contextMenu != null) {
        contextMenu = _webview!.contextMenu;
      } else if (_inAppBrowser != null &&
          _inAppBrowser!.contextMenu != null) {
        contextMenu = _inAppBrowser!.contextMenu;
      }

      if (contextMenu != null && contextMenu.onCreateContextMenu != null) {
        Map<String, dynamic> arguments =
            call.arguments.cast<String, dynamic>();
        InAppWebViewHitTestResult hitTestResult =
            InAppWebViewHitTestResult.fromMap(arguments)!;

        contextMenu.onCreateContextMenu!(hitTestResult);
      }
      break;
    case "onHideContextMenu":
      ContextMenu? contextMenu;
      if (_webview != null && _webview!.contextMenu != null) {
        contextMenu = _webview!.contextMenu;
      } else if (_inAppBrowser != null &&
          _inAppBrowser!.contextMenu != null) {
        contextMenu = _inAppBrowser!.contextMenu;
      }

      if (contextMenu != null && contextMenu.onHideContextMenu != null) {
        contextMenu.onHideContextMenu!();
      }
      break;
    case "onContextMenuActionItemClicked":
      ContextMenu? contextMenu;
      if (_webview != null && _webview!.contextMenu != null) {
        contextMenu = _webview!.contextMenu;
      } else if (_inAppBrowser != null &&
          _inAppBrowser!.contextMenu != null) {
        contextMenu = _inAppBrowser!.contextMenu;
      }

      if (contextMenu != null) {
        int? androidId = call.arguments["androidId"];
        String? iosId = call.arguments["iosId"];
        dynamic id = call.arguments["id"];
        String title = call.arguments["title"];

        ContextMenuItem menuItemClicked = ContextMenuItem(
            id: id,
            // ignore: deprecated_member_use_from_same_package
            androidId: androidId,
            // ignore: deprecated_member_use_from_same_package
            iosId: iosId,
            title: title,
            action: null);

        for (var menuItem in contextMenu.menuItems) {
          if (menuItem.id == id) {
            menuItemClicked = menuItem;
            if (menuItem.action != null) {
              menuItem.action!();
            }
            break;
          }
        }

        if (contextMenu.onContextMenuActionItemClicked != null) {
          contextMenu.onContextMenuActionItemClicked!(menuItemClicked);
        }
      }
      break;
    case "onEnterFullscreen":
      if (_webview != null && _webview!.onEnterFullscreen != null)
        _webview!.onEnterFullscreen!(this);
      else if (_inAppBrowser != null) _inAppBrowser!.onEnterFullscreen();
      break;
    case "onExitFullscreen":
      if (_webview != null && _webview!.onExitFullscreen != null)
        _webview!.onExitFullscreen!(this);
      else if (_inAppBrowser != null) _inAppBrowser!.onExitFullscreen();
      break;
    case "onOverScrolled":
      if ((_webview != null && _webview!.onOverScrolled != null) ||
          _inAppBrowser != null) {
        int x = call.arguments["x"];
        int y = call.arguments["y"];
        bool clampedX = call.arguments["clampedX"];
        bool clampedY = call.arguments["clampedY"];

        if (_webview != null && _webview!.onOverScrolled != null)
          _webview!.onOverScrolled!(this, x, y, clampedX, clampedY);
        else
          _inAppBrowser!.onOverScrolled(x, y, clampedX, clampedY);
      }
      break;
    case "onWindowFocus":
      if (_webview != null && _webview!.onWindowFocus != null)
        _webview!.onWindowFocus!(this);
      else if (_inAppBrowser != null) _inAppBrowser!.onWindowFocus();
      break;
    case "onWindowBlur":
      if (_webview != null && _webview!.onWindowBlur != null)
        _webview!.onWindowBlur!(this);
      else if (_inAppBrowser != null) _inAppBrowser!.onWindowBlur();
      break;
    case "onPrintRequest":
      if ((_webview != null &&
              (_webview!.onPrintRequest != null ||
                  // ignore: deprecated_member_use_from_same_package
                  _webview!.onPrint != null)) ||
          _inAppBrowser != null) {
        String? url = call.arguments["url"];
        String? printJobId = call.arguments["printJobId"];
        WebUri? uri = url != null ? WebUri(url) : null;
        PrintJobController? printJob =
            printJobId != null ? PrintJobController(id: printJobId) : null;

        if (_webview != null) {
          if (_webview!.onPrintRequest != null)
            return await _webview!.onPrintRequest!(this, uri, printJob);
          else {
            // ignore: deprecated_member_use_from_same_package
            _webview!.onPrint!(this, uri);
            return false;
          }
        } else {
          // ignore: deprecated_member_use_from_same_package
          _inAppBrowser!.onPrint(uri);
          return await _inAppBrowser!.onPrintRequest(uri, printJob);
        }
      }
      break;
    case "onInjectedScriptLoaded":
      String id = call.arguments[0];
      var onLoadCallback = _injectedScriptsFromURL[id]?.onLoad;
      if ((_webview != null || _inAppBrowser != null) &&
          onLoadCallback != null) {
        onLoadCallback();
      }
      break;
    case "onInjectedScriptError":
      String id = call.arguments[0];
      var onErrorCallback = _injectedScriptsFromURL[id]?.onError;
      if ((_webview != null || _inAppBrowser != null) &&
          onErrorCallback != null) {
        onErrorCallback();
      }
      break;
    case "onCameraCaptureStateChanged":
      if ((_webview != null &&
              _webview!.onCameraCaptureStateChanged != null) ||
          _inAppBrowser != null) {
        var oldState =
            MediaCaptureState.fromNativeValue(call.arguments["oldState"]);
        var newState =
            MediaCaptureState.fromNativeValue(call.arguments["newState"]);

        if (_webview != null && _webview!.onCameraCaptureStateChanged != null)
          _webview!.onCameraCaptureStateChanged!(this, oldState, newState);
        else
          _inAppBrowser!.onCameraCaptureStateChanged(oldState, newState);
      }
      break;
    case "onMicrophoneCaptureStateChanged":
      if ((_webview != null &&
              _webview!.onMicrophoneCaptureStateChanged != null) ||
          _inAppBrowser != null) {
        var oldState =
            MediaCaptureState.fromNativeValue(call.arguments["oldState"]);
        var newState =
            MediaCaptureState.fromNativeValue(call.arguments["newState"]);

        if (_webview != null &&
            _webview!.onMicrophoneCaptureStateChanged != null)
          _webview!.onMicrophoneCaptureStateChanged!(
              this, oldState, newState);
        else
          _inAppBrowser!.onMicrophoneCaptureStateChanged(oldState, newState);
      }
      break;
    case "onContentSizeChanged":
      if ((_webview != null && _webview!.onContentSizeChanged != null) ||
          _inAppBrowser != null) {
        var oldContentSize = MapSize.fromMap(
            call.arguments["oldContentSize"]?.cast<String, dynamic>())!;
        var newContentSize = MapSize.fromMap(
            call.arguments["newContentSize"]?.cast<String, dynamic>())!;

        if (_webview != null && _webview!.onContentSizeChanged != null)
          _webview!.onContentSizeChanged!(
              this, oldContentSize, newContentSize);
        else
          _inAppBrowser!.onContentSizeChanged(oldContentSize, newContentSize);
      }
      break;
    case "onCallJsHandler":
      String handlerName = call.arguments["handlerName"];
      // decode args to json
      List<dynamic> args = jsonDecode(call.arguments["args"]);

      _debugLog(handlerName, args);

      switch (handlerName) {
        case "onLoadResource":
          if ((_webview != null && _webview!.onLoadResource != null) ||
              _inAppBrowser != null) {
            Map<String, dynamic> arguments = args[0].cast<String, dynamic>();
            arguments["startTime"] = arguments["startTime"] is int
                ? arguments["startTime"].toDouble()
                : arguments["startTime"];
            arguments["duration"] = arguments["duration"] is int
                ? arguments["duration"].toDouble()
                : arguments["duration"];

            var response = LoadedResource.fromMap(arguments)!;

            if (_webview != null && _webview!.onLoadResource != null)
              _webview!.onLoadResource!(this, response);
            else
              _inAppBrowser!.onLoadResource(response);
          }
          return null;
        case "shouldInterceptAjaxRequest":
          if ((_webview != null &&
                  _webview!.shouldInterceptAjaxRequest != null) ||
              _inAppBrowser != null) {
            Map<String, dynamic> arguments = args[0].cast<String, dynamic>();
            AjaxRequest request = AjaxRequest.fromMap(arguments)!;

            if (_webview != null &&
                _webview!.shouldInterceptAjaxRequest != null)
              return jsonEncode(
                  await _webview!.shouldInterceptAjaxRequest!(this, request));
            else
              return jsonEncode(
                  await _inAppBrowser!.shouldInterceptAjaxRequest(request));
          }
          return null;
        case "onAjaxReadyStateChange":
          if ((_webview != null &&
                  _webview!.onAjaxReadyStateChange != null) ||
              _inAppBrowser != null) {
            Map<String, dynamic> arguments = args[0].cast<String, dynamic>();
            AjaxRequest request = AjaxRequest.fromMap(arguments)!;

            if (_webview != null && _webview!.onAjaxReadyStateChange != null)
              return (await _webview!.onAjaxReadyStateChange!(this, request))
                  ?.toNativeValue();
            else
              return (await _inAppBrowser!.onAjaxReadyStateChange(request))
                  ?.toNativeValue();
          }
          return null;
        case "onAjaxProgress":
          if ((_webview != null && _webview!.onAjaxProgress != null) ||
              _inAppBrowser != null) {
            Map<String, dynamic> arguments = args[0].cast<String, dynamic>();
            AjaxRequest request = AjaxRequest.fromMap(arguments)!;

            if (_webview != null && _webview!.onAjaxProgress != null)
              return (await _webview!.onAjaxProgress!(this, request))
                  ?.toNativeValue();
            else
              return (await _inAppBrowser!.onAjaxProgress(request))
                  ?.toNativeValue();
          }
          return null;
        case "shouldInterceptFetchRequest":
          if ((_webview != null &&
                  _webview!.shouldInterceptFetchRequest != null) ||
              _inAppBrowser != null) {
            Map<String, dynamic> arguments = args[0].cast<String, dynamic>();
            FetchRequest request = FetchRequest.fromMap(arguments)!;

            if (_webview != null &&
                _webview!.shouldInterceptFetchRequest != null)
              return jsonEncode(await _webview!.shouldInterceptFetchRequest!(
                  this, request));
            else
              return jsonEncode(
                  await _inAppBrowser!.shouldInterceptFetchRequest(request));
          }
          return null;
        case "onWindowFocus":
          if (_webview != null && _webview!.onWindowFocus != null)
            _webview!.onWindowFocus!(this);
          else if (_inAppBrowser != null) _inAppBrowser!.onWindowFocus();
          return null;
        case "onWindowBlur":
          if (_webview != null && _webview!.onWindowBlur != null)
            _webview!.onWindowBlur!(this);
          else if (_inAppBrowser != null) _inAppBrowser!.onWindowBlur();
          return null;
        case "onInjectedScriptLoaded":
          String id = args[0];
          var onLoadCallback = _injectedScriptsFromURL[id]?.onLoad;
          if ((_webview != null || _inAppBrowser != null) &&
              onLoadCallback != null) {
            onLoadCallback();
          }
          return null;
        case "onInjectedScriptError":
          String id = args[0];
          var onErrorCallback = _injectedScriptsFromURL[id]?.onError;
          if ((_webview != null || _inAppBrowser != null) &&
              onErrorCallback != null) {
            onErrorCallback();
          }
          return null;
      }

      if (javaScriptHandlersMap.containsKey(handlerName)) {
        // convert result to json
        try {
          return jsonEncode(await javaScriptHandlersMap[handlerName]!(args));
        } catch (error, stacktrace) {
          developer.log(error.toString() + '\n' + stacktrace.toString(),
              name: 'JavaScript Handler "$handlerName"');
          throw Exception(error.toString().replaceFirst('Exception: ', ''));
        }
      }
      break;
    default:
      throw UnimplementedError("Unimplemented ${call.method} method");
  }
  return null;
}