Skip to content
This repository was archived by the owner on Feb 11, 2024. It is now read-only.

Migrate Essentials v0.0.1: Implement Client with openUrl method #2

Merged
merged 42 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d96f235
adding dependencies, generated_bindings and android support
unsuitable001 Jun 11, 2021
4d3bb12
refactor: third_party APIs (cronet) seperated from wrapper.h
unsuitable001 Jun 12, 2021
e3ca8a8
initial implementation: essential APIs of http client, request & resp…
unsuitable001 Jun 12, 2021
b2253a3
refactor: comments & readme
unsuitable001 Jun 13, 2021
30cfbe6
refactor: docs, analysis, license, tests
unsuitable001 Jun 13, 2021
1ba712d
api change: registerCallback's future resolves `bool` and readDataCal…
unsuitable001 Jun 14, 2021
a218ac4
tests & bug fix: http response callback api
unsuitable001 Jun 15, 2021
d99c7c3
tests: automatic port selection
unsuitable001 Jun 15, 2021
c3da375
tests: add license and enforce 80char
unsuitable001 Jun 16, 2021
ea156b1
remove: flutter support boilerplate
unsuitable001 Jun 17, 2021
382be13
hint user to get binaries and relocate prepare_cronet
unsuitable001 Jun 17, 2021
82b296a
refactor: native code lib/src/native -> src and 3rd_party -> third_party
unsuitable001 Jun 18, 2021
a667deb
rewrite build.sh in dart
unsuitable001 Jun 18, 2021
7df5522
add build_cronet executable for user customization
unsuitable001 Jun 18, 2021
9e7836a
tar -> package:archive and cronet binary detection improvements
unsuitable001 Jun 19, 2021
5b921cf
info: display command to get cronet library when wrapper can't load it
unsuitable001 Jun 19, 2021
0303b71
test: remove unused imports
unsuitable001 Jun 19, 2021
5d4c698
refactor: wrapper.cc & improve: destroying unused requests
unsuitable001 Jun 20, 2021
088b9fb
include: cronet c++ sample
unsuitable001 Jun 21, 2021
c88867e
refactoring, added new tests and api comparisons
unsuitable001 Jun 23, 2021
f6ae319
move find_resource.dart -> third_party and fix readme
unsuitable001 Jun 24, 2021
5eba348
remove: alternate callback based API
unsuitable001 Jun 24, 2021
dd2490f
refactor: remove part directives
unsuitable001 Jun 24, 2021
f4cbd24
merge quic & http2 options into protocol using enum HttpProtocol
unsuitable001 Jun 25, 2021
12499c3
initial splitting of cronet and wrapper bindings
unsuitable001 Jun 25, 2021
783a6ce
spliting wrapper and cronet bindings
unsuitable001 Jun 27, 2021
96636e8
locate binaries to .dart_tool
unsuitable001 Jun 27, 2021
d3e4d84
formatting and sanity checks
unsuitable001 Jun 28, 2021
5958aad
add licence & minor refactors
unsuitable001 Jun 29, 2021
7533e4b
void* -> real type def for cronet fn & test: add regex
unsuitable001 Jun 29, 2021
f9a1e1e
setup script, cmake based build & set dylibs as global
unsuitable001 Jun 30, 2021
1d51146
analyzer: removed unused show from tool/build_wrapper.dart
unsuitable001 Jun 30, 2021
2f93cd3
ci: change ci setup command
unsuitable001 Jun 30, 2021
31de14b
CronetNativeException -> Error and enum to string mapping
unsuitable001 Jun 30, 2021
2ce6957
add verify option to cronet:setup, fix setup halting
unsuitable001 Jun 30, 2021
0beef32
C API for SampleExecutor
unsuitable001 Jul 1, 2021
4452dbe
tool: update tarballs. setup verify: delete verifier after done.
unsuitable001 Jul 1, 2021
1dcb370
readme: setup command, add: ffigen issue reference
unsuitable001 Jul 2, 2021
c50d7b3
readme: typo fix
unsuitable001 Jul 2, 2021
f222aa4
readme: supported platforms
unsuitable001 Jul 2, 2021
3de3374
readme
unsuitable001 Jul 2, 2021
ec2efb0
update: binary download url
unsuitable001 Jul 2, 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
3 changes: 3 additions & 0 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ jobs:
- id: install
name: Install dependencies
run: dart pub get
- id: get_binaries
name: Download Cronet Binaries
run: pub run cronet linux64
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
build/
pubspec.lock

# wrapper build directory
lib/src/native/wrapper/out

# Directory created by dartdoc.
doc/api/

Expand Down Expand Up @@ -33,3 +36,30 @@ compile_commands.json

# Mac
.DS_Store

# Cronet pre-built binaries
cronet_binaries/

# Generated shared libraries.
*.so
*.so.*
*.dylib
*.dll

# AOT compiled files.
*.exe

*.jar
*.cxx

*.flutter-plugins
*.flutter-plugins-dependencies

*.idea

# Directory for quick experiments.
experiments/

# Files generated by tests for debugging purposes.
test/debug_generated/*
!test/debug_generated/readme.md
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 1d9032c7e1d867f071f2277eb1673e8f9b0274e3
channel: stable

project_type: plugin
55 changes: 55 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# See https://dart.dev/guides/libraries/private-files

# Files and directories created by pub.
.dart_tool/
.packages
pubspec.lock

# IDE and debugger files.
.clangd
.gdb_history
.history
.vscode
compile_commands.json

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map

# Cronet pre-built binaries
cronet_binaries/

# Generated shared libraries.
*.so
*.so.*
*.dylib
*.dll

# AOT compiled files.
*.exe

*.jar
*.cxx

# Jar dependencies should be published to pub
!android/libs/*

# Cronet binaries for android should be published to pub
!android/src/main/jniLibs/**

*.flutter-plugins
*.flutter-plugins-dependencies

*.idea

# Directory for quick experiments.
experiments/

# Files generated by tests for debugging purposes.
test/debug_generated/*
!test/debug_generated/readme.md
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
# Name/Organization <email address>

Google LLC

Soumyadip Mondal <[email protected]>
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 0.0.1

* HttpClient with QUIC, HTTP2, brotli support.
* HttpClient with a customizable user agent string.
* HttpClient close method (without force close).
* Implemented open, openUrl & other associated methods.
* Response is consumable using 2 styles of APIs. dart:io style and callback based style.
* Different types of Exceptions are implemented.

**Breaking Changes:**

* Custom `SecurityContext` is no longer handled by the client. Users have to handle it in other ways. (To be documented later).
* `userAgent` property is now read-only. Custom userAgent should be passed as a constructor argument.
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,89 @@
This package binds to Cronet's [native API](https://chromium.googlesource.com/chromium/src/+/master/components/cronet/native/test_instructions.md) to expose them in Dart.

This is a [GSoC 2021 project](https://summerofcode.withgoogle.com/projects/#4757095741652992).

## Usage

1. Add package as a dependency in your `pubspec.yaml`.

2. Run this from the `root` of your project.

**Dart CLI**

```bash
dart pub get
dart run cronet <platform> # Downloads the cronet binaries.
```

**Flutter**

```bash
flutter pub get
flutter run cronet <platform> # Downloads the cronet binaries.
```

Supported platforms: `linux64` and `windows64`.

3. Import

```dart
import 'package:cronet/cronet.dart';
```

**Note:** Internet connection is required to download cronet binaries.

## Example

### `dart:io` style API

```dart
final client = HttpClient();
client
.getUrl(Uri.parse('http://info.cern.ch/'))
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
response.transform(utf8.decoder).listen((contents) {
print(contents);
},
onDone: () => print(
'Done!'));
});
```

### Alternate API

```dart
final client = HttpClient();
client
.getUrl(Uri.parse('http://info.cern.ch/'))
.then((HttpClientRequest request) {
request.registerCallbacks((data, bytesRead, responseCode) {
print(utf8.decoder.convert(data));
print('Status: $responseCode');
},
onSuccess: (responseCode) =>
print('Done with status: $responseCode')).catchError(
(Object e) {print(e);});
});
```

## Run Example

```bash
cd example_dart
dart run cronet <platform> # Downloads the cronet binaries.
dart run
```

Replace `<platform>` with `linux64` or `windows64`.

## Run Tests

```bash
dart pub get
dart run cronet <platform> # Downloads the cronet binaries.
Copy link
Member

Choose a reason for hiding this comment

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

dart run cronet:setup

dart test --platform vm
```

**Wrapper & Cronet binaries build guide**: [BUILD.md](lib/src/native/wrapper/BUILD.md)
5 changes: 5 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
# BSD-style license that can be found in the LICENSE file.

include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
8 changes: 8 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
40 changes: 40 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
group 'com.example.cronet'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30

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

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
5 changes: 5 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'cronet'
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cronet">
</manifest>
36 changes: 36 additions & 0 deletions android/src/main/kotlin/com/example/cronet/CronetPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.cronet

import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar

/** CronetPlugin */
class CronetPlugin: FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "cronet")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}
14 changes: 14 additions & 0 deletions bin/cronet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2021, 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.

import 'package:cronet/src/prepare_cronet.dart';

Future<void> main(List<String> platforms) async {
for (final platform in platforms) {
if (platform.startsWith('linux')) {
buildWrapper();
}
await downloadCronetBinaries(platform);
}
}
19 changes: 19 additions & 0 deletions cronet.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>
Loading