Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Implement Android WebView api with pigeon (Java portion) #4441

Merged
merged 6 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ android {
testImplementation 'androidx.test:core:1.3.0'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

testOptions {
unitTests.includeAndroidResources = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;

import android.webkit.DownloadListener;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerFlutterApi;

class DownloadListenerHostApiImpl implements GeneratedAndroidWebView.DownloadListenerHostApi {
private final InstanceManager instanceManager;
private final DownloadListenerCreator downloadListenerCreator;
private final GeneratedAndroidWebView.DownloadListenerFlutterApi downloadListenerFlutterApi;

static class DownloadListenerCreator {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creator inner classes are used to make it easier to test constructors

DownloadListener createDownloadListener(
Long instanceId, DownloadListenerFlutterApi downloadListenerFlutterApi) {
return (url, userAgent, contentDisposition, mimetype, contentLength) ->
downloadListenerFlutterApi.onDownloadStart(
instanceId, url, userAgent, contentDisposition, mimetype, contentLength, reply -> {});
}
}

DownloadListenerHostApiImpl(
InstanceManager instanceManager,
DownloadListenerCreator downloadListenerCreator,
DownloadListenerFlutterApi downloadListenerFlutterApi) {
this.instanceManager = instanceManager;
this.downloadListenerCreator = downloadListenerCreator;
this.downloadListenerFlutterApi = downloadListenerFlutterApi;
}

@Override
public void create(Long instanceId) {
final DownloadListener downloadListener =
downloadListenerCreator.createDownloadListener(instanceId, downloadListenerFlutterApi);
instanceManager.addInstance(downloadListener, instanceId);
}

@Override
public void dispose(Long instanceId) {
instanceManager.removeInstance(instanceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
// This version of shouldOverrideUrlLoading is only invoked by the webview on devices with
// webview versions earlier than 67(it is also invoked when hasNavigationDelegate is false).
// webview versions earlier than 67(it is also invoked when hasNavigationDelegate is false).
// On these devices we cannot tell whether the navigation is targeted to the main frame or not.
// We proceed assuming that the navigation is targeted to the main frame. If the page had any
// frames they will be loaded in the main frame instead.
Expand Down
Loading