Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a9b6fa2
java portion
bparrishMines Oct 21, 2021
a4e919c
add instance manager
bparrishMines Oct 21, 2021
2fbd130
change method name
bparrishMines Oct 25, 2021
8fe8aa6
add longsparsearray cheat
bparrishMines Oct 25, 2021
0086300
add web chrome client
bparrishMines Oct 26, 2021
f5815bb
Merge branch 'master' of github.com:flutter/plugins into webview_pige…
bparrishMines Oct 27, 2021
06d8d46
update java
bparrishMines Oct 29, 2021
4abc6f8
Merge branch 'master' of github.com:flutter/plugins into webview_pige…
bparrishMines Oct 29, 2021
2d8f7df
remove callback classes from instance manager
bparrishMines Oct 29, 2021
7dd43a3
start of public comments work
bparrishMines Nov 7, 2021
8078642
format and fixed tests
bparrishMines Nov 8, 2021
3ecfb59
more documentation
bparrishMines Nov 8, 2021
3943f51
more docs
bparrishMines Nov 8, 2021
b5b59fd
take a containerview
bparrishMines Nov 8, 2021
d876c54
fix tests
bparrishMines Nov 8, 2021
bf9368a
added releasable chlide
bparrishMines Nov 8, 2021
5b49180
add releasable child
bparrishMines Nov 8, 2021
f9f1e63
formatting
bparrishMines Nov 8, 2021
7100a27
Merge branch 'master' of github.com:flutter/plugins into webview_pige…
bparrishMines Nov 8, 2021
89b3701
Merge branch 'master' of github.com:flutter/plugins into webview_pige…
bparrishMines Nov 9, 2021
a353461
update pigeon version
bparrishMines Nov 10, 2021
8da326b
handle release automatically
bparrishMines Nov 10, 2021
533a9ec
releasablevalue extends releaseable
bparrishMines Nov 10, 2021
08eebce
release a channel that was overriden
bparrishMines Nov 10, 2021
38e02ad
Merge branch 'master' of github.com:flutter/plugins into webview_pige…
bparrishMines Nov 11, 2021
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
@@ -0,0 +1,64 @@
// 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.plugin.common.BinaryMessenger;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerFlutterApi;

/**
* Flutter Api implementation for {@link DownloadListener}.
*
* <p>Passes arguments of callbacks methods from a {@link DownloadListener} to Dart.
*/
public class DownloadListenerFlutterApiImpl extends DownloadListenerFlutterApi {
private final InstanceManager instanceManager;

/**
* Creates a Flutter api that sends messages to Dart.
*
* @param binaryMessenger handles sending messages to Dart
* @param instanceManager maintains instances stored to communicate with Dart objects
*/
public DownloadListenerFlutterApiImpl(
BinaryMessenger binaryMessenger, InstanceManager instanceManager) {
super(binaryMessenger);
this.instanceManager = instanceManager;
}

/** Passes arguments from {@link DownloadListener#onDownloadStart} to Dart. */
public void onDownloadStart(
DownloadListener downloadListener,
String url,
String userAgent,
String contentDisposition,
String mimetype,
long contentLength,
Reply<Void> callback) {
onDownloadStart(
instanceManager.getInstanceId(downloadListener),
url,
userAgent,
contentDisposition,
mimetype,
contentLength,
callback);
}

/**
* Communicates to Dart that the reference to a {@link DownloadListener} was removed.
*
* @param downloadListener the instance whose reference will be removed
* @param callback reply callback with return value from Dart
*/
public void dispose(DownloadListener downloadListener, Reply<Void> callback) {
final Long instanceId = instanceManager.removeInstance(downloadListener);
if (instanceId != null) {
dispose(instanceId, callback);
} else {
callback.reply(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,92 @@
package io.flutter.plugins.webviewflutter;

import android.webkit.DownloadListener;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerFlutterApi;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerHostApi;

class DownloadListenerHostApiImpl implements GeneratedAndroidWebView.DownloadListenerHostApi {
/**
* Host api implementation for {@link DownloadListener}.
*
* <p>Handles creating {@link DownloadListener}s that intercommunicate with a paired Dart object.
*/
public class DownloadListenerHostApiImpl implements 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 -> {});
private final DownloadListenerFlutterApiImpl flutterApi;

/**
* Implementation of {@link DownloadListener} that passes arguments of callback methods to Dart.
*
* <p>No messages are sent to Dart after {@link DownloadListenerImpl#release} is called.
*/
public static class DownloadListenerImpl implements DownloadListener, Releasable {
@Nullable private DownloadListenerFlutterApiImpl flutterApi;

/**
* Creates a {@link DownloadListenerImpl} that passes arguments of callbacks methods to Dart.
*
* @param flutterApi handles sending messages to Dart
*/
public DownloadListenerImpl(@NonNull DownloadListenerFlutterApiImpl flutterApi) {
this.flutterApi = flutterApi;
}

@Override
public void onDownloadStart(
String url,
String userAgent,
String contentDisposition,
String mimetype,
long contentLength) {
if (flutterApi != null) {
flutterApi.onDownloadStart(
this, url, userAgent, contentDisposition, mimetype, contentLength, reply -> {});
}
}

@Override
public void release() {
if (flutterApi != null) {
flutterApi.dispose(this, reply -> {});
}
flutterApi = null;
}
}

DownloadListenerHostApiImpl(
/** Handles creating {@link DownloadListenerImpl}s for a {@link DownloadListenerHostApiImpl}. */
public static class DownloadListenerCreator {
/**
* Creates a {@link DownloadListenerImpl}.
*
* @param flutterApi handles sending messages to Dart
* @return the created {@link DownloadListenerImpl}
*/
public DownloadListenerImpl createDownloadListener(DownloadListenerFlutterApiImpl flutterApi) {
return new DownloadListenerImpl(flutterApi);
}
}

/**
* Creates a host API that handles creating {@link DownloadListener}s.
*
* @param instanceManager maintains instances stored to communicate with Dart objects
* @param downloadListenerCreator handles creating {@link DownloadListenerImpl}s
* @param flutterApi handles sending messages to Dart
*/
public DownloadListenerHostApiImpl(
InstanceManager instanceManager,
DownloadListenerCreator downloadListenerCreator,
DownloadListenerFlutterApi downloadListenerFlutterApi) {
DownloadListenerFlutterApiImpl flutterApi) {
this.instanceManager = instanceManager;
this.downloadListenerCreator = downloadListenerCreator;
this.downloadListenerFlutterApi = downloadListenerFlutterApi;
this.flutterApi = flutterApi;
}

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

@Override
public void dispose(Long instanceId) {
instanceManager.removeInstance(instanceId);
}
}
Loading