AndroidNavigationDelegate constructor

AndroidNavigationDelegate(
  1. PlatformNavigationDelegateCreationParams params
)

Creates a new AndroidNavigationDelegate.

Implementation

AndroidNavigationDelegate(PlatformNavigationDelegateCreationParams params)
    : super.implementation(params is AndroidNavigationDelegateCreationParams
          ? params
          : AndroidNavigationDelegateCreationParams
              .fromPlatformNavigationDelegateCreationParams(params)) {
  final WeakReference<AndroidNavigationDelegate> weakThis =
      WeakReference<AndroidNavigationDelegate>(this);

  _webViewClient = (this.params as AndroidNavigationDelegateCreationParams)
      .androidWebViewProxy
      .createAndroidWebViewClient(
    onPageFinished: (android_webview.WebView webView, String url) {
      final PageEventCallback? callback = weakThis.target?._onPageFinished;
      if (callback != null) {
        callback(url);
      }
    },
    onPageStarted: (android_webview.WebView webView, String url) {
      final PageEventCallback? callback = weakThis.target?._onPageStarted;
      if (callback != null) {
        callback(url);
      }
    },
    onReceivedHttpError: (
      android_webview.WebView webView,
      android_webview.WebResourceRequest request,
      android_webview.WebResourceResponse response,
    ) {
      if (weakThis.target?._onHttpError != null) {
        weakThis.target!._onHttpError!(
          HttpResponseError(
            request: WebResourceRequest(
              uri: Uri.parse(request.url),
            ),
            response: WebResourceResponse(
              uri: null,
              statusCode: response.statusCode,
            ),
          ),
        );
      }
    },
    onReceivedRequestError: (
      android_webview.WebView webView,
      android_webview.WebResourceRequest request,
      android_webview.WebResourceError error,
    ) {
      final WebResourceErrorCallback? callback =
          weakThis.target?._onWebResourceError;
      if (callback != null) {
        callback(AndroidWebResourceError._(
          errorCode: error.errorCode,
          description: error.description,
          url: request.url,
          isForMainFrame: request.isForMainFrame,
        ));
      }
    },
    onReceivedError: (
      android_webview.WebView webView,
      int errorCode,
      String description,
      String failingUrl,
    ) {
      final WebResourceErrorCallback? callback =
          weakThis.target?._onWebResourceError;
      if (callback != null) {
        callback(AndroidWebResourceError._(
          errorCode: errorCode,
          description: description,
          url: failingUrl,
          isForMainFrame: true,
        ));
      }
    },
    requestLoading: (
      android_webview.WebView webView,
      android_webview.WebResourceRequest request,
    ) {
      weakThis.target?._handleNavigation(
        request.url,
        headers: request.requestHeaders,
        isForMainFrame: request.isForMainFrame,
      );
    },
    urlLoading: (android_webview.WebView webView, String url) {
      weakThis.target?._handleNavigation(url, isForMainFrame: true);
    },
    doUpdateVisitedHistory: (
      android_webview.WebView webView,
      String url,
      bool isReload,
    ) {
      final UrlChangeCallback? callback = weakThis.target?._onUrlChange;
      if (callback != null) {
        callback(AndroidUrlChange(url: url, isReload: isReload));
      }
    },
    onReceivedHttpAuthRequest: (
      android_webview.WebView webView,
      android_webview.HttpAuthHandler httpAuthHandler,
      String host,
      String realm,
    ) {
      final void Function(HttpAuthRequest)? callback =
          weakThis.target?._onHttpAuthRequest;
      if (callback != null) {
        callback(
          HttpAuthRequest(
            onProceed: (WebViewCredential credential) {
              httpAuthHandler.proceed(credential.user, credential.password);
            },
            onCancel: () {
              httpAuthHandler.cancel();
            },
            host: host,
            realm: realm,
          ),
        );
      } else {
        httpAuthHandler.cancel();
      }
    },
  );

  _downloadListener = (this.params as AndroidNavigationDelegateCreationParams)
      .androidWebViewProxy
      .createDownloadListener(
    onDownloadStart: (
      String url,
      String userAgent,
      String contentDisposition,
      String mimetype,
      int contentLength,
    ) {
      if (weakThis.target != null) {
        weakThis.target?._handleNavigation(url, isForMainFrame: true);
      }
    },
  );
}