forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Has a binary messenger (flutter#9419)
Made the engine and the view controllers have BinaryMessengers, not be BinaryMessengers. This allows us to break retain cycles and makes the leaking channels we have not less dire.
- Loading branch information
Showing
14 changed files
with
212 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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 "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h" | ||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" | ||
|
||
#ifndef NDEBUG | ||
FLUTTER_EXPORT | ||
#endif | ||
@interface FlutterBinaryMessengerRelay : NSObject <FlutterBinaryMessenger> | ||
@property(nonatomic, assign) NSObject<FlutterBinaryMessenger>* parent; | ||
- (instancetype)initWithParent:(NSObject<FlutterBinaryMessenger>*)parent; | ||
@end |
47 changes: 47 additions & 0 deletions
47
shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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 "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h" | ||
|
||
#include "flutter/fml/logging.h" | ||
|
||
@implementation FlutterBinaryMessengerRelay | ||
#pragma mark - FlutterBinaryMessenger | ||
|
||
- (instancetype)initWithParent:(NSObject<FlutterBinaryMessenger>*)parent { | ||
self = [super init]; | ||
if (self != nil) { | ||
self.parent = parent; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)sendOnChannel:(NSString*)channel message:(NSData*)message { | ||
if (self.parent) { | ||
[self.parent sendOnChannel:channel message:message binaryReply:nil]; | ||
} else { | ||
FML_LOG(WARNING) << "Communicating on a dead channel."; | ||
} | ||
} | ||
|
||
- (void)sendOnChannel:(NSString*)channel | ||
message:(NSData*)message | ||
binaryReply:(FlutterBinaryReply)callback { | ||
if (self.parent) { | ||
[self.parent sendOnChannel:channel message:message binaryReply:callback]; | ||
} else { | ||
FML_LOG(WARNING) << "Communicating on a dead channel."; | ||
} | ||
} | ||
|
||
- (void)setMessageHandlerOnChannel:(NSString*)channel | ||
binaryMessageHandler:(FlutterBinaryMessageHandler)handler { | ||
if (self.parent) { | ||
[self.parent setMessageHandlerOnChannel:channel binaryMessageHandler:handler]; | ||
} else { | ||
FML_LOG(WARNING) << "Communicating on a dead channel."; | ||
} | ||
} | ||
|
||
@end |
58 changes: 58 additions & 0 deletions
58
shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelayTest.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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 <OCMock/OCMock.h> | ||
#import <XCTest/XCTest.h> | ||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h" | ||
|
||
#ifndef __has_feature | ||
#define __has_feature(x) 0 /* for non-clang compilers */ | ||
#endif | ||
|
||
#if !__has_feature(objc_arc) | ||
#error ARC must be enabled! | ||
#endif | ||
|
||
@interface FlutterBinaryMessengerRelayTest : XCTestCase | ||
@end | ||
|
||
@implementation FlutterBinaryMessengerRelayTest | ||
|
||
- (void)setUp { | ||
} | ||
|
||
- (void)tearDown { | ||
} | ||
|
||
- (void)testCreate { | ||
id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); | ||
FlutterBinaryMessengerRelay* relay = | ||
[[FlutterBinaryMessengerRelay alloc] initWithParent:messenger]; | ||
XCTAssertNotNil(relay); | ||
XCTAssertEqual(messenger, relay.parent); | ||
} | ||
|
||
- (void)testPassesCallOn { | ||
id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); | ||
FlutterBinaryMessengerRelay* relay = | ||
[[FlutterBinaryMessengerRelay alloc] initWithParent:messenger]; | ||
char messageData[] = {'a', 'a', 'r', 'o', 'n'}; | ||
NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)]; | ||
NSString* channel = @"foobar"; | ||
[relay sendOnChannel:channel message:message binaryReply:nil]; | ||
OCMVerify([messenger sendOnChannel:channel message:message binaryReply:nil]); | ||
} | ||
|
||
- (void)testDoesntPassCallOn { | ||
id messenger = OCMStrictProtocolMock(@protocol(FlutterBinaryMessenger)); | ||
FlutterBinaryMessengerRelay* relay = | ||
[[FlutterBinaryMessengerRelay alloc] initWithParent:messenger]; | ||
char messageData[] = {'a', 'a', 'r', 'o', 'n'}; | ||
NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)]; | ||
NSString* channel = @"foobar"; | ||
relay.parent = nil; | ||
[relay sendOnChannel:channel message:message binaryReply:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.