Skip to content

Commit

Permalink
Implement Android WebView api with pigeon (Java portion) (flutter#4441)
Browse files Browse the repository at this point in the history
  • Loading branch information
bparrishMines authored and amantoux committed Dec 11, 2021
1 parent 342b455 commit 444188d
Show file tree
Hide file tree
Showing 20 changed files with 3,302 additions and 4 deletions.
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 {
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

0 comments on commit 444188d

Please sign in to comment.