Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7c363fd
dart side of implementation
bparrishMines May 11, 2022
2e55266
objc side of callback impl
bparrishMines May 12, 2022
4a12eaa
documentation and a test messenger
bparrishMines May 12, 2022
6bc048b
dart side update
bparrishMines May 16, 2022
4efa9a1
objc side
bparrishMines May 16, 2022
f9d54e2
formatting
bparrishMines May 16, 2022
2f73074
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines May 16, 2022
ddfde5c
handles
bparrishMines May 17, 2022
96c21ae
some fixes for PR comments
bparrishMines May 18, 2022
f2a3504
new instance manager
bparrishMines May 19, 2022
77da52f
bunch of work
bparrishMines May 19, 2022
e388090
instance manager tests
bparrishMines May 19, 2022
ac3a2de
fix foundation tests
bparrishMines May 19, 2022
696c25c
dart touchups
bparrishMines May 19, 2022
88816c9
finish dart standardization and support earlier versions
bparrishMines May 19, 2022
9d25ab1
fix dart instance manager
bparrishMines May 19, 2022
4d7ebc4
instance manager ish
bparrishMines May 19, 2022
81b201f
most tests passing
bparrishMines May 19, 2022
62581ba
instance manager tests
bparrishMines May 20, 2022
f0d2498
formatting and one last test
bparrishMines May 20, 2022
4bd6d2a
formatting
bparrishMines May 20, 2022
7974d56
naming
bparrishMines May 20, 2022
ad9b4e6
better comment
bparrishMines May 20, 2022
d8b720e
update comment with info about platform/flutter
bparrishMines May 23, 2022
3c98004
fix bug from instance manager identifier
bparrishMines May 24, 2022
368fb30
limits on identifiers
bparrishMines May 25, 2022
a6980c5
use removeReference name instead
bparrishMines May 25, 2022
179f109
maybe an even better name?
bparrishMines May 25, 2022
e966816
use init constructor
bparrishMines May 25, 2022
3897535
version bump
bparrishMines May 25, 2022
312825a
update name
bparrishMines May 25, 2022
36fa0a0
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines May 25, 2022
2b7a9af
undo changes to webview_flutter
bparrishMines May 25, 2022
86b193a
add api impls
bparrishMines May 25, 2022
61d5f8a
undo changes to create methods
bparrishMines May 25, 2022
29e8ad0
changes and stuff
bparrishMines May 25, 2022
2be09aa
some updates
bparrishMines May 26, 2022
e212aa4
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines May 26, 2022
ea0fe93
method names
bparrishMines May 26, 2022
9e47dda
more docs, yay
bparrishMines May 26, 2022
8076bed
spelling and docs
bparrishMines May 31, 2022
0fa7a14
pr comments
bparrishMines Jun 2, 2022
797d448
format and issue
bparrishMines Jun 2, 2022
ba8161a
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines Jun 2, 2022
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
Prev Previous commit
Next Next commit
some fixes for PR comments
  • Loading branch information
bparrishMines committed May 18, 2022
commit 96c21aec47ea6bd62272f7f6a03595370d9e0b98
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Used to test that a FlutterBinaryMessenger with a strong reference to a host api won't
// lead to a circular reference.
@interface FWFTestMessenger : NSObject <FlutterBinaryMessenger>
@property(strong, nullable) id hostApi;
@property(strong, nullable) id hostAPI;
@end

@implementation FWFTestMessenger
Expand Down Expand Up @@ -39,12 +39,12 @@ @interface FWFNavigationDelegateHostApiTests : XCTestCase
@implementation FWFNavigationDelegateHostApiTests
- (void)testCreateWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFNavigationDelegateHostApiImpl *hostApi = [[FWFNavigationDelegateHostApiImpl alloc]
FWFNavigationDelegateHostApiImpl *hostAPI = [[FWFNavigationDelegateHostApiImpl alloc]
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger))
instanceManager:instanceManager];

FlutterError *error;
[hostApi createWithIdentifier:@0 error:&error];
[hostAPI createWithIdentifier:@0 error:&error];
FWFNavigationDelegate *navigationDelegate =
(FWFNavigationDelegate *)[instanceManager instanceForIdentifier:0];

Expand All @@ -54,12 +54,12 @@ - (void)testCreateWithIdentifier {

- (void)testDidFinishNavigation {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFNavigationDelegateHostApiImpl *hostApi = [[FWFNavigationDelegateHostApiImpl alloc]
FWFNavigationDelegateHostApiImpl *hostAPI = [[FWFNavigationDelegateHostApiImpl alloc]
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger))
instanceManager:instanceManager];

FlutterError *error;
[hostApi createWithIdentifier:@0 error:&error];
[hostAPI createWithIdentifier:@0 error:&error];
FWFNavigationDelegate *navigationDelegate =
(FWFNavigationDelegate *)[instanceManager instanceForIdentifier:0];
id mockDelegate = OCMPartialMock(navigationDelegate);
Expand All @@ -85,14 +85,14 @@ - (void)testDidFinishNavigation {
- (void)testInstanceCanBeReleasedWhenInstanceManagerIsReleased {
FWFTestMessenger *testMessenger = [[FWFTestMessenger alloc] init];
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFNavigationDelegateHostApiImpl *hostApi =
FWFNavigationDelegateHostApiImpl *hostAPI =
[[FWFNavigationDelegateHostApiImpl alloc] initWithBinaryMessenger:testMessenger
instanceManager:instanceManager];

testMessenger.hostApi = hostApi;
testMessenger.hostAPI = hostAPI;

FlutterError *error;
[hostApi createWithIdentifier:@0 error:&error];
[hostAPI createWithIdentifier:@0 error:&error];
FWFNavigationDelegate __weak *navigationDelegate =
(FWFNavigationDelegate *)[instanceManager instanceForIdentifier:0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

/// Maintains instances stored to communicate with Objective-C objects.
class InstanceManager {
final Map<int, Object> _instanceIdsToInstances = <int, Object>{};
final Expando<Object> _instancesToInstanceIds = Expando<Object>();
// Instances that the manager wants to maintain a strong reference to.
final Map<int, Object> _strongInstances = <int, Object>{};
// Expando is used because it doesn't prevent its keys from becoming
// inaccessible. This allows the manager to efficiently retrieve an instance
// id of an object without holding a strong reference to the object.
//
// It also doesn't use `==` to search for instance ids, which would lead to an
// infinite loop when comparing an object to its copy. (i.e. which is caused
// by calling instanceManager.getInstanceId() inside of `==` while this was a
// HashMap).
final Expando<int> _instanceIds = Expando<int>();

int _nextInstanceId = 0;

Expand All @@ -22,15 +31,15 @@ class InstanceManager {
}

final int instanceId = _nextInstanceId++;
_instancesToInstanceIds[instance] = instanceId;
_instanceIdsToInstances[instanceId] = instance;
_instanceIds[instance] = instanceId;
_strongInstances[instanceId] = instance;
return instanceId;
}

/// Store a copy of an instance with the same instance id.
void addCopy(Object original, Object copy) {
assert(original.runtimeType == copy.runtimeType);
_instancesToInstanceIds[copy] = _instancesToInstanceIds[original];
_instanceIds[copy] = _instanceIds[original];
assert(original == copy);
}

Expand All @@ -39,21 +48,21 @@ class InstanceManager {
/// Returns null if the instance is removed. Otherwise, return the instanceId
/// of the removed instance.
int? removeInstance<T extends Object>(T instance) {
final int? instanceId = _instancesToInstanceIds[instance] as int?;
final int? instanceId = _instanceIds[instance];
if (instanceId != null) {
_instancesToInstanceIds[instance] = null;
_instanceIdsToInstances.remove(instanceId);
_instanceIds[instance] = null;
_strongInstances.remove(instanceId);
}
return instanceId;
}

/// Retrieve the Object paired with instanceId.
T? getInstance<T extends Object>(int instanceId) {
return _instanceIdsToInstances[instanceId] as T?;
return _strongInstances[instanceId] as T?;
}

/// Retrieve the instanceId paired with instance.
int? getInstanceId(Object instance) {
return _instancesToInstanceIds[instance] as int?;
return _instanceIds[instance];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,9 @@ class WKNavigationDelegateFlutterApiImpl
int webViewInstanceId,
String? url,
) {
_getDelegate(instanceId).didFinishNavigation!(
instanceManager.getInstance(webViewInstanceId)!,
url,
);
final void Function(WKWebView, String?)? function =
_getDelegate(instanceId).didFinishNavigation;
function?.call(instanceManager.getInstance(webViewInstanceId)!, url);
}
}

Expand Down