Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 UIKit
import XCTest

@testable import webview_flutter_wkwebview

class ColorProxyAPITests: XCTestCase {
func testPigeonDefaultConstructor() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiUIColor(registrar)

let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(
pigeonApi: api, red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
XCTAssertNotNil(instance)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ class UIViewProxyAPITests: XCTestCase {
let api = registrar.apiDelegate.pigeonApiUIView(registrar)

let instance = UIView(frame: .zero)
let value = 0xFFF4_4336
let red = 0.5
let green = 0.5
let blue = 0.5
let alpha = 0.5
try? api.pigeonDelegate.setBackgroundColor(
pigeonApi: api, pigeonInstance: instance, value: Int64(value))

let red = CGFloat(Double((value >> 16 & 0xff)) / 255.0)
let green = CGFloat(Double(value >> 8 & 0xff) / 255.0)
let blue = CGFloat(Double(value & 0xff) / 255.0)
let alpha = CGFloat(Double(value >> 24 & 0xff) / 255.0)
pigeonApi: api, pigeonInstance: instance,
value: UIColor(red: red, green: green, blue: blue, alpha: alpha))

XCTAssertEqual(
instance.backgroundColor, UIColor(red: red, green: green, blue: blue, alpha: alpha))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 Foundation
import UIKit

/// ProxyApi implementation for `UIColor`.
///
/// This class may handle instantiating native object instances that are attached to a Dart instance
/// or handle method calls on the associated native class or an instance of that class.
class ColorProxyAPIDelegate: PigeonApiDelegateUIColor {
func pigeonDefaultConstructor(
pigeonApi: PigeonApiUIColor, red: Double, green: Double, blue: Double, alpha: Double
) throws -> UIColor {
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ open class ProxyAPIRegistrar: WebKitLibraryPigeonProxyApiRegistrar {

/// Handles calling a Flutter method on the main thread.
func dispatchOnMainThread(
execute work: @escaping (
_ onFailure: @escaping (_ methodName: String, _ error: PigeonError) -> Void
) -> Void
execute work:
@escaping (
_ onFailure: @escaping (_ methodName: String, _ error: PigeonError) -> Void
) -> Void
) {
DispatchQueue.main.async {
work { methodName, error in
Expand Down Expand Up @@ -301,4 +302,8 @@ class ProxyAPIDelegate: WebKitLibraryPigeonProxyApiDelegate {
return PigeonApiSecCertificate(
pigeonRegistrar: registrar, delegate: SecCertificateProxyAPIDelegate())
}

func pigeonApiUIColor(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiUIColor {
return PigeonApiUIColor(pigeonRegistrar: registrar, delegate: ColorProxyAPIDelegate())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
/// or handle method calls on the associated native class or an instance of that class.
class UIViewProxyAPIDelegate: PigeonApiDelegateUIView {
#if os(iOS)
func setBackgroundColor(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, value: Int64?)
func setBackgroundColor(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, value: UIColor?)
throws
{
if value == nil {
pigeonInstance.backgroundColor = nil
} else {
let red = CGFloat(Double((value! >> 16 & 0xff)) / 255.0)
let green = CGFloat(Double(value! >> 8 & 0xff) / 255.0)
let blue = CGFloat(Double(value! & 0xff) / 255.0)
let alpha = CGFloat(Double(value! >> 24 & 0xff) / 255.0)

pigeonInstance.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)
}
pigeonInstance.backgroundColor = value
}

func setOpaque(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, opaque: Bool) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ protocol WebKitLibraryPigeonProxyApiDelegate {
/// `SecCertificate` to the Dart `InstanceManager` and make calls to Dart.
func pigeonApiSecCertificate(_ registrar: WebKitLibraryPigeonProxyApiRegistrar)
-> PigeonApiSecCertificate
/// An implementation of [PigeonApiUIColor] used to add a new Dart instance of
/// `UIColor` to the Dart `InstanceManager` and make calls to Dart.
func pigeonApiUIColor(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiUIColor
}

extension WebKitLibraryPigeonProxyApiDelegate {
Expand Down Expand Up @@ -619,6 +622,8 @@ open class WebKitLibraryPigeonProxyApiRegistrar {
binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiSecTrust(self))
PigeonApiSecCertificate.setUpMessageHandlers(
binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiSecCertificate(self))
PigeonApiUIColor.setUpMessageHandlers(
binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiUIColor(self))
}
func tearDown() {
WebKitLibraryPigeonInstanceManagerApi.setUpMessageHandlers(
Expand Down Expand Up @@ -651,6 +656,7 @@ open class WebKitLibraryPigeonProxyApiRegistrar {
PigeonApiWKWebpagePreferences.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil)
PigeonApiSecTrust.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil)
PigeonApiSecCertificate.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil)
PigeonApiUIColor.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil)
}
}
private class WebKitLibraryPigeonInternalProxyApiCodecReaderWriter: FlutterStandardReaderWriter {
Expand Down Expand Up @@ -1095,6 +1101,19 @@ private class WebKitLibraryPigeonInternalProxyApiCodecReaderWriter: FlutterStand
return
}

#if !os(macOS)
if let instance = value as? UIColor {
pigeonRegistrar.apiDelegate.pigeonApiUIColor(pigeonRegistrar).pigeonNewInstance(
pigeonInstance: instance
) { _ in }
super.writeByte(128)
super.writeValue(
pigeonRegistrar.instanceManager.identifierWithStrongReference(
forInstance: instance as AnyObject)!)
return
}
#endif

if let instance = value as? NSObject {
pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar).pigeonNewInstance(
pigeonInstance: instance
Expand Down Expand Up @@ -2895,7 +2914,7 @@ final class PigeonApiWKWebsiteDataStore: PigeonApiProtocolWKWebsiteDataStore {
protocol PigeonApiDelegateUIView {
#if !os(macOS)
/// The view’s background color.
func setBackgroundColor(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, value: Int64?)
func setBackgroundColor(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, value: UIColor?)
throws
#endif
#if !os(macOS)
Expand Down Expand Up @@ -2934,7 +2953,7 @@ final class PigeonApiUIView: PigeonApiProtocolUIView {
setBackgroundColorChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonInstanceArg = args[0] as! UIView
let valueArg: Int64? = nilOrValue(args[1])
let valueArg: UIColor? = nilOrValue(args[1])
do {
try api.pigeonDelegate.setBackgroundColor(
pigeonApi: api, pigeonInstance: pigeonInstanceArg, value: valueArg)
Expand Down Expand Up @@ -7701,3 +7720,107 @@ final class PigeonApiSecCertificate: PigeonApiProtocolSecCertificate {
}
}
}
protocol PigeonApiDelegateUIColor {
#if !os(macOS)
/// Creates a color object using the specified opacity and RGB component
/// values.
///
/// The colors are specified in an extended color space, and the input value
/// is never clamped.
func pigeonDefaultConstructor(
pigeonApi: PigeonApiUIColor, red: Double, green: Double, blue: Double, alpha: Double
) throws -> UIColor
#endif
}

protocol PigeonApiProtocolUIColor {
}

final class PigeonApiUIColor: PigeonApiProtocolUIColor {
unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar
let pigeonDelegate: PigeonApiDelegateUIColor
///An implementation of [NSObject] used to access callback methods
var pigeonApiNSObject: PigeonApiNSObject {
return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar)
}

init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateUIColor) {
self.pigeonRegistrar = pigeonRegistrar
self.pigeonDelegate = delegate
}
static func setUpMessageHandlers(binaryMessenger: FlutterBinaryMessenger, api: PigeonApiUIColor?)
{
let codec: FlutterStandardMessageCodec =
api != nil
? FlutterStandardMessageCodec(
readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter(
pigeonRegistrar: api!.pigeonRegistrar))
: FlutterStandardMessageCodec.sharedInstance()
#if !os(macOS)
let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIColor.pigeon_defaultConstructor",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
pigeonDefaultConstructorChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonIdentifierArg = args[0] as! Int64
let redArg = args[1] as! Double
let greenArg = args[2] as! Double
let blueArg = args[3] as! Double
let alphaArg = args[4] as! Double
do {
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
try api.pigeonDelegate.pigeonDefaultConstructor(
pigeonApi: api, red: redArg, green: greenArg, blue: blueArg, alpha: alphaArg),
withIdentifier: pigeonIdentifierArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
pigeonDefaultConstructorChannel.setMessageHandler(nil)
}
#endif
}

#if !os(macOS)
///Creates a Dart instance of UIColor and attaches it to [pigeonInstance].
func pigeonNewInstance(
pigeonInstance: UIColor, completion: @escaping (Result<Void, PigeonError>) -> Void
) {
if pigeonRegistrar.ignoreCallsToDart {
completion(
.failure(
PigeonError(
code: "ignore-calls-error",
message: "Calls to Dart are being ignored.", details: "")))
} else if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) {
completion(.success(()))
} else {
let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(
pigeonInstance as AnyObject)
let binaryMessenger = pigeonRegistrar.binaryMessenger
let codec = pigeonRegistrar.codec
let channelName: String =
"dev.flutter.pigeon.webview_flutter_wkwebview.UIColor.pigeon_newInstance"
let channel = FlutterBasicMessageChannel(
name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else {
completion(.success(()))
}
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
33C8DADB2E8D711500A9B7CA /* TemporaryObjCStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C8DADA2E8D711500A9B7CA /* TemporaryObjCStub.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
8F0E23522EEB5D6B002AB342 /* ColorProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0E23512EEB5D6B002AB342 /* ColorProxyAPITests.swift */; };
8F0EDFD32E1F4967001938E6 /* ProxyAPIRegistrarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0EDFD22E1F4967001938E6 /* ProxyAPIRegistrarTests.swift */; };
8F1488E22D2DE27000191744 /* ScriptMessageHandlerProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488D02D2DE27000191744 /* ScriptMessageHandlerProxyAPITests.swift */; };
8F1488E32D2DE27000191744 /* TestProxyApiRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488D62D2DE27000191744 /* TestProxyApiRegistrar.swift */; };
Expand Down Expand Up @@ -102,6 +103,7 @@
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
8F0E23512EEB5D6B002AB342 /* ColorProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ColorProxyAPITests.swift; path = ../../darwin/Tests/ColorProxyAPITests.swift; sourceTree = SOURCE_ROOT; };
8F0EDFD22E1F4967001938E6 /* ProxyAPIRegistrarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ProxyAPIRegistrarTests.swift; path = ../../darwin/Tests/ProxyAPIRegistrarTests.swift; sourceTree = SOURCE_ROOT; };
8F1488C52D2DE27000191744 /* ErrorProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ErrorProxyAPITests.swift; path = ../../darwin/Tests/ErrorProxyAPITests.swift; sourceTree = SOURCE_ROOT; };
8F1488C62D2DE27000191744 /* FrameInfoProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FrameInfoProxyAPITests.swift; path = ../../darwin/Tests/FrameInfoProxyAPITests.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -183,6 +185,7 @@
68BDCAEA23C3F7CB00D9C032 /* RunnerTests */ = {
isa = PBXGroup;
children = (
8F0E23512EEB5D6B002AB342 /* ColorProxyAPITests.swift */,
33C8DAD92E8D711500A9B7CA /* TemporaryObjCStub.h */,
33C8DADA2E8D711500A9B7CA /* TemporaryObjCStub.m */,
8F0EDFD22E1F4967001938E6 /* ProxyAPIRegistrarTests.swift */,
Expand Down Expand Up @@ -562,6 +565,7 @@
8F1488E22D2DE27000191744 /* ScriptMessageHandlerProxyAPITests.swift in Sources */,
8F1488E32D2DE27000191744 /* TestProxyApiRegistrar.swift in Sources */,
8F1488E42D2DE27000191744 /* URLRequestProxyAPITests.swift in Sources */,
8F0E23522EEB5D6B002AB342 /* ColorProxyAPITests.swift in Sources */,
8F1488E52D2DE27000191744 /* TestBinaryMessenger.swift in Sources */,
8F1488E62D2DE27000191744 /* WebViewProxyAPITests.swift in Sources */,
8F1488E72D2DE27000191744 /* HTTPCookieStoreProxyAPITests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class PlatformWebView {
}

/// The view’s background color.
Future<void> setBackgroundColor(int? value) {
Future<void> setBackgroundColor(UIColor? value) {
final WKWebView webView = nativeWebView;
switch (webView) {
case UIViewWKWebView():
Expand Down
Loading