Skip to content

Commit

Permalink
[webview_flutter_wkwebview] Updates the internal wrapper to use `@Pro…
Browse files Browse the repository at this point in the history
…xyApi` from pigeon (#8311)

Also fixes flutter/flutter#152352
  • Loading branch information
bparrishMines authored Jan 28, 2025
1 parent 040f805 commit d6705de
Show file tree
Hide file tree
Showing 187 changed files with 24,976 additions and 27,676 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.18.0

* Updates internal API wrapper to use ProxyApis.

## 3.17.0

* Adds a change listener for the `canGoBack` property. See
Expand Down
54 changes: 54 additions & 0 deletions packages/webview_flutter/webview_flutter_wkwebview/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Contributing to `webview_flutter_wkwebview`

Please start by taking a look at the general guide to contributing to the `flutter/packages` repo:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md

## Package Structure

This plugin serves as a platform implementation plugin as outlined in [federated plugins](https://docs.flutter.dev/packages-and-plugins/developing-packages#federated-plugins).
The sections below will provide an overview of how this plugin implements this portion with iOS and
macOS.

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).

### Quick Overview

This plugin implements the platform interface provided by `webview_flutter_platform_interface` using
the native WebKit APIs for WKWebView APIs.

#### SDK Wrappers

To access native APIS, this plugins uses Dart wrappers of the native library. The native library is
wrapped using using the `ProxyApi` feature from the `pigeon` package.

The wrappers for the native library can be updated and modified by changing `pigeons/web_kit.dart`.

The generated files are located:
* `lib/src/common/web_kit.g.dart`
* `darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebKitLibrary.g.swift`

To update the wrapper, follow the steps below:

##### 1. Make changes to the respective pigeon file that matches the native SDK

* WebKit Dependency: https://developer.apple.com/documentation/webkit
* Pigeon file to update: `pigeons/web_kit.dart`

##### 2. Run the code generator from the terminal

Run: `dart run pigeon --input pigeons/web_kit.dart`

##### 3. Update the generated APIs in native code

Running the `flutter build` command from step 1 again should provide build errors and indicate what
needs to be done. Alternatively, it can be easier to update native code with the platform's specific
IDE:

Open `example/ios/` or `example/macos/` in Xcode.

##### 4. Write API tests

Assuming a non-static method or constructor was added to the native wrapper, a native test will need
to be added.

Tests location: `darwin/Tests`
4 changes: 4 additions & 0 deletions packages/webview_flutter/webview_flutter_wkwebview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ Objective-C:

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

## Contributing

For information on contributing to this plugin, see [`CONTRIBUTING.md`](CONTRIBUTING.md).

[1]: https://pub.dev/packages/webview_flutter
[2]: https://flutter.dev/to/endorsed-federated-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

import XCTest

@testable import webview_flutter_wkwebview

class AuthenticationChallengeResponseProxyAPITests: XCTestCase {
func testPigeonDefaultConstructor() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar)

let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(
pigeonApi: api, disposition: UrlSessionAuthChallengeDisposition.useCredential,
credential: URLCredential())
XCTAssertNotNil(instance)
}

func testDisposition() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar)

let instance = AuthenticationChallengeResponse(
disposition: .useCredential, credential: URLCredential())
let value = try? api.pigeonDelegate.disposition(pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value, UrlSessionAuthChallengeDisposition.useCredential)
}

func testCredential() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar)

let instance = AuthenticationChallengeResponse(
disposition: .useCredential, credential: URLCredential())
let value = try? api.pigeonDelegate.credential(pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value, instance.credential)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.

import XCTest

@testable import webview_flutter_wkwebview

class ErrorProxyAPITests: XCTestCase {
func testCode() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiNSError(registrar)

let code = 0
let instance = NSError(domain: "", code: code)
let value = try? api.pigeonDelegate.code(pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value, Int64(code))
}

func testDomain() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiNSError(registrar)

let domain = "domain"
let instance = NSError(domain: domain, code: 0)
let value = try? api.pigeonDelegate.domain(pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value, domain)
}

func testUserInfo() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiNSError(registrar)

let userInfo: [String: String?] = ["some": "info"]
let instance = NSError(domain: "", code: 0, userInfo: userInfo as [String: Any])
let value = try? api.pigeonDelegate.userInfo(pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value as! [String: String?], userInfo)
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit d6705de

Please sign in to comment.