Skip to content

Commit d6705de

Browse files
[webview_flutter_wkwebview] Updates the internal wrapper to use @ProxyApi from pigeon (flutter#8311)
Also fixes flutter/flutter#152352
1 parent 040f805 commit d6705de

File tree

187 files changed

+24976
-27676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+24976
-27676
lines changed

packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.18.0
2+
3+
* Updates internal API wrapper to use ProxyApis.
4+
15
## 3.17.0
26

37
* Adds a change listener for the `canGoBack` property. See
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Contributing to `webview_flutter_wkwebview`
2+
3+
Please start by taking a look at the general guide to contributing to the `flutter/packages` repo:
4+
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
5+
6+
## Package Structure
7+
8+
This plugin serves as a platform implementation plugin as outlined in [federated plugins](https://docs.flutter.dev/packages-and-plugins/developing-packages#federated-plugins).
9+
The sections below will provide an overview of how this plugin implements this portion with iOS and
10+
macOS.
11+
12+
For making changes to this package, please take a look at [changing federated plugins](https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins).
13+
14+
### Quick Overview
15+
16+
This plugin implements the platform interface provided by `webview_flutter_platform_interface` using
17+
the native WebKit APIs for WKWebView APIs.
18+
19+
#### SDK Wrappers
20+
21+
To access native APIS, this plugins uses Dart wrappers of the native library. The native library is
22+
wrapped using using the `ProxyApi` feature from the `pigeon` package.
23+
24+
The wrappers for the native library can be updated and modified by changing `pigeons/web_kit.dart`.
25+
26+
The generated files are located:
27+
* `lib/src/common/web_kit.g.dart`
28+
* `darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebKitLibrary.g.swift`
29+
30+
To update the wrapper, follow the steps below:
31+
32+
##### 1. Make changes to the respective pigeon file that matches the native SDK
33+
34+
* WebKit Dependency: https://developer.apple.com/documentation/webkit
35+
* Pigeon file to update: `pigeons/web_kit.dart`
36+
37+
##### 2. Run the code generator from the terminal
38+
39+
Run: `dart run pigeon --input pigeons/web_kit.dart`
40+
41+
##### 3. Update the generated APIs in native code
42+
43+
Running the `flutter build` command from step 1 again should provide build errors and indicate what
44+
needs to be done. Alternatively, it can be easier to update native code with the platform's specific
45+
IDE:
46+
47+
Open `example/ios/` or `example/macos/` in Xcode.
48+
49+
##### 4. Write API tests
50+
51+
Assuming a non-static method or constructor was added to the native wrapper, a native test will need
52+
to be added.
53+
54+
Tests location: `darwin/Tests`

packages/webview_flutter/webview_flutter_wkwebview/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ Objective-C:
2929

3030
Then you will have access to the native class `FWFWebViewFlutterWKWebViewExternalAPI`.
3131

32+
## Contributing
33+
34+
For information on contributing to this plugin, see [`CONTRIBUTING.md`](CONTRIBUTING.md).
35+
3236
[1]: https://pub.dev/packages/webview_flutter
3337
[2]: https://flutter.dev/to/endorsed-federated-plugin
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import XCTest
6+
7+
@testable import webview_flutter_wkwebview
8+
9+
class AuthenticationChallengeResponseProxyAPITests: XCTestCase {
10+
func testPigeonDefaultConstructor() {
11+
let registrar = TestProxyApiRegistrar()
12+
let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar)
13+
14+
let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(
15+
pigeonApi: api, disposition: UrlSessionAuthChallengeDisposition.useCredential,
16+
credential: URLCredential())
17+
XCTAssertNotNil(instance)
18+
}
19+
20+
func testDisposition() {
21+
let registrar = TestProxyApiRegistrar()
22+
let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar)
23+
24+
let instance = AuthenticationChallengeResponse(
25+
disposition: .useCredential, credential: URLCredential())
26+
let value = try? api.pigeonDelegate.disposition(pigeonApi: api, pigeonInstance: instance)
27+
28+
XCTAssertEqual(value, UrlSessionAuthChallengeDisposition.useCredential)
29+
}
30+
31+
func testCredential() {
32+
let registrar = TestProxyApiRegistrar()
33+
let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar)
34+
35+
let instance = AuthenticationChallengeResponse(
36+
disposition: .useCredential, credential: URLCredential())
37+
let value = try? api.pigeonDelegate.credential(pigeonApi: api, pigeonInstance: instance)
38+
39+
XCTAssertEqual(value, instance.credential)
40+
}
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import XCTest
6+
7+
@testable import webview_flutter_wkwebview
8+
9+
class ErrorProxyAPITests: XCTestCase {
10+
func testCode() {
11+
let registrar = TestProxyApiRegistrar()
12+
let api = registrar.apiDelegate.pigeonApiNSError(registrar)
13+
14+
let code = 0
15+
let instance = NSError(domain: "", code: code)
16+
let value = try? api.pigeonDelegate.code(pigeonApi: api, pigeonInstance: instance)
17+
18+
XCTAssertEqual(value, Int64(code))
19+
}
20+
21+
func testDomain() {
22+
let registrar = TestProxyApiRegistrar()
23+
let api = registrar.apiDelegate.pigeonApiNSError(registrar)
24+
25+
let domain = "domain"
26+
let instance = NSError(domain: domain, code: 0)
27+
let value = try? api.pigeonDelegate.domain(pigeonApi: api, pigeonInstance: instance)
28+
29+
XCTAssertEqual(value, domain)
30+
}
31+
32+
func testUserInfo() {
33+
let registrar = TestProxyApiRegistrar()
34+
let api = registrar.apiDelegate.pigeonApiNSError(registrar)
35+
36+
let userInfo: [String: String?] = ["some": "info"]
37+
let instance = NSError(domain: "", code: 0, userInfo: userInfo as [String: Any])
38+
let value = try? api.pigeonDelegate.userInfo(pigeonApi: api, pigeonInstance: instance)
39+
40+
XCTAssertEqual(value as! [String: String?], userInfo)
41+
}
42+
}

packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFDataConvertersTests.m

Lines changed: 0 additions & 209 deletions
This file was deleted.

packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFErrorTests.m

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)