Skip to content

Commit 2cbb703

Browse files
authored
Switch cronet_http to use jnigen (#1016)
1 parent de19214 commit 2cbb703

File tree

16 files changed

+4292
-541
lines changed

16 files changed

+4292
-541
lines changed

.github/workflows/cronet.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ jobs:
5555
java-version: '17'
5656
- uses: subosito/flutter-action@v2
5757
with:
58-
# TODO: Change to 'stable' when a release version of flutter
59-
# pins version 1.21.1 or later of 'package:test'
60-
channel: 'master'
58+
channel: 'stable'
6159
- name: Run tests
6260
uses: reactivecircus/android-emulator-runner@v2
6361
with:

pkgs/cronet_http/.gitattributes

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
# pigeon generated code
2-
lib/src/messages.dart linguist-generated
3-
android/src/main/java/io/flutter/plugins/cronet_http/Messages.java linguist-generated
4-
1+
# jnigen generated code
2+
lib/src/jni/jni_bindings.dart linguist-generated

pkgs/cronet_http/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.3.0-jni
2+
3+
* Switch to using `package:jnigen` for bindings to Cronet
4+
* Support for running in background isolates.
5+
* **Breaking Change:** `CronetEngine.build()` returns a `CronetEngine` rather
6+
than a `Future<CronetEngine>` and `CronetClient.fromCronetEngineFuture()`
7+
has been removed because it is no longer necessary.
8+
19
## 0.2.2
210

311
* Require Dart 3.0

pkgs/cronet_http/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ android {
3838

3939
sourceSets {
4040
main.java.srcDirs += 'src/main/kotlin'
41-
main.java.srcDirs += 'src/main/java'
4241
}
4342

4443
defaultConfig {

pkgs/cronet_http/android/src/main/kotlin/io/flutter/plugins/cronet_http/CronetHttpPlugin.kt

Lines changed: 0 additions & 239 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Cronet allows developers to manage HTTP requests by subclassing the
6+
// the abstract class `UrlRequest.Callback`.
7+
//
8+
// `package:jnigen` does not support the ability to subclass abstract Java
9+
// classes in Dart (see https://github.com/dart-lang/jnigen/issues/348).
10+
//
11+
// This file provides an interface `UrlRequestCallbackInterface`, which can
12+
// be implemented in Dart and a wrapper class `UrlRequestCallbackProxy`, which
13+
// can be passed to the Cronet API.
14+
15+
package io.flutter.plugins.cronet_http
16+
17+
import org.chromium.net.CronetException
18+
import org.chromium.net.UrlRequest
19+
import org.chromium.net.UrlResponseInfo
20+
import java.nio.ByteBuffer
21+
22+
23+
class UrlRequestCallbackProxy(val callback: UrlRequestCallbackInterface) : UrlRequest.Callback() {
24+
public interface UrlRequestCallbackInterface {
25+
fun onRedirectReceived(
26+
request: UrlRequest,
27+
info: UrlResponseInfo,
28+
newLocationUrl: String
29+
)
30+
31+
fun onResponseStarted(request: UrlRequest?, info: UrlResponseInfo)
32+
fun onReadCompleted(
33+
request: UrlRequest,
34+
info: UrlResponseInfo,
35+
byteBuffer: ByteBuffer
36+
)
37+
38+
fun onSucceeded(request: UrlRequest, info: UrlResponseInfo?)
39+
fun onFailed(
40+
request: UrlRequest,
41+
info: UrlResponseInfo?,
42+
error: CronetException
43+
)
44+
}
45+
46+
override fun onRedirectReceived(
47+
request: UrlRequest,
48+
info: UrlResponseInfo,
49+
newLocationUrl: String
50+
) {
51+
callback.onRedirectReceived(request, info, newLocationUrl);
52+
}
53+
54+
override fun onResponseStarted(request: UrlRequest?, info: UrlResponseInfo) {
55+
callback.onResponseStarted(request, info);
56+
}
57+
58+
override fun onReadCompleted(
59+
request: UrlRequest,
60+
info: UrlResponseInfo,
61+
byteBuffer: ByteBuffer
62+
) {
63+
callback.onReadCompleted(request, info, byteBuffer);
64+
}
65+
66+
override fun onSucceeded(request: UrlRequest, info: UrlResponseInfo?) {
67+
callback.onSucceeded(request, info);
68+
}
69+
70+
override fun onFailed(
71+
request: UrlRequest,
72+
info: UrlResponseInfo?,
73+
error: CronetException
74+
) {
75+
callback.onFailed(request, info, error);
76+
}
77+
}

0 commit comments

Comments
 (0)