Skip to content

Commit

Permalink
Switch cronet_http to use jnigen (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan authored Sep 12, 2023
1 parent de19214 commit 2cbb703
Show file tree
Hide file tree
Showing 16 changed files with 4,292 additions and 541 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/cronet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ jobs:
java-version: '17'
- uses: subosito/flutter-action@v2
with:
# TODO: Change to 'stable' when a release version of flutter
# pins version 1.21.1 or later of 'package:test'
channel: 'master'
channel: 'stable'
- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
with:
Expand Down
6 changes: 2 additions & 4 deletions pkgs/cronet_http/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# pigeon generated code
lib/src/messages.dart linguist-generated
android/src/main/java/io/flutter/plugins/cronet_http/Messages.java linguist-generated

# jnigen generated code
lib/src/jni/jni_bindings.dart linguist-generated
8 changes: 8 additions & 0 deletions pkgs/cronet_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.3.0-jni

* Switch to using `package:jnigen` for bindings to Cronet
* Support for running in background isolates.
* **Breaking Change:** `CronetEngine.build()` returns a `CronetEngine` rather
than a `Future<CronetEngine>` and `CronetClient.fromCronetEngineFuture()`
has been removed because it is no longer necessary.

## 0.2.2

* Require Dart 3.0
Expand Down
1 change: 0 additions & 1 deletion pkgs/cronet_http/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ android {

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/java'
}

defaultConfig {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Cronet allows developers to manage HTTP requests by subclassing the
// the abstract class `UrlRequest.Callback`.
//
// `package:jnigen` does not support the ability to subclass abstract Java
// classes in Dart (see https://github.com/dart-lang/jnigen/issues/348).
//
// This file provides an interface `UrlRequestCallbackInterface`, which can
// be implemented in Dart and a wrapper class `UrlRequestCallbackProxy`, which
// can be passed to the Cronet API.

package io.flutter.plugins.cronet_http

import org.chromium.net.CronetException
import org.chromium.net.UrlRequest
import org.chromium.net.UrlResponseInfo
import java.nio.ByteBuffer


class UrlRequestCallbackProxy(val callback: UrlRequestCallbackInterface) : UrlRequest.Callback() {
public interface UrlRequestCallbackInterface {
fun onRedirectReceived(
request: UrlRequest,
info: UrlResponseInfo,
newLocationUrl: String
)

fun onResponseStarted(request: UrlRequest?, info: UrlResponseInfo)
fun onReadCompleted(
request: UrlRequest,
info: UrlResponseInfo,
byteBuffer: ByteBuffer
)

fun onSucceeded(request: UrlRequest, info: UrlResponseInfo?)
fun onFailed(
request: UrlRequest,
info: UrlResponseInfo?,
error: CronetException
)
}

override fun onRedirectReceived(
request: UrlRequest,
info: UrlResponseInfo,
newLocationUrl: String
) {
callback.onRedirectReceived(request, info, newLocationUrl);
}

override fun onResponseStarted(request: UrlRequest?, info: UrlResponseInfo) {
callback.onResponseStarted(request, info);
}

override fun onReadCompleted(
request: UrlRequest,
info: UrlResponseInfo,
byteBuffer: ByteBuffer
) {
callback.onReadCompleted(request, info, byteBuffer);
}

override fun onSucceeded(request: UrlRequest, info: UrlResponseInfo?) {
callback.onSucceeded(request, info);
}

override fun onFailed(
request: UrlRequest,
info: UrlResponseInfo?,
error: CronetException
) {
callback.onFailed(request, info, error);
}
}
Loading

0 comments on commit 2cbb703

Please sign in to comment.