|
Lines 38-57
a/Source/WebKit/UIProcess/WebAuthentication/Mock/MockNfcService.mm_sec1
|
| 38 |
|
38 |
|
| 39 |
#import "NearFieldSoftLink.h" |
39 |
#import "NearFieldSoftLink.h" |
| 40 |
|
40 |
|
|
|
41 |
namespace { |
| 42 |
uint8_t tagID1[] = { 0x01 }; |
| 43 |
uint8_t tagID2[] = { 0x02 }; |
| 44 |
} |
| 45 |
|
| 41 |
#if HAVE(NEAR_FIELD) |
46 |
#if HAVE(NEAR_FIELD) |
| 42 |
|
47 |
|
| 43 |
@interface WKMockNFTag : NSObject <NFTag> |
48 |
@interface WKMockNFTag : NSObject <NFTag> |
| 44 |
|
49 |
|
| 45 |
- (instancetype)initWithType:(NFTagType)type; |
50 |
- (instancetype)initWithType:(NFTagType)type; |
|
|
51 |
- (instancetype)initWithType:(NFTagType)type tagID:(NSData *)tagID; |
| 46 |
|
52 |
|
| 47 |
@end |
53 |
@end |
| 48 |
|
54 |
|
| 49 |
@implementation WKMockNFTag { |
55 |
@implementation WKMockNFTag { |
| 50 |
NFTagType _type; |
56 |
NFTagType _type; |
|
|
57 |
RetainPtr<NSData> _tagID; |
| 51 |
} |
58 |
} |
| 52 |
|
59 |
|
| 53 |
@synthesize technology=_technology; |
60 |
@synthesize technology=_technology; |
| 54 |
@synthesize tagID=_tagID; |
|
|
| 55 |
@synthesize AppData=_AppData; |
61 |
@synthesize AppData=_AppData; |
| 56 |
@synthesize UID=_UID; |
62 |
@synthesize UID=_UID; |
| 57 |
@synthesize ndefAvailability=_ndefAvailability; |
63 |
@synthesize ndefAvailability=_ndefAvailability; |
|
Lines 66-82
- (NFTagType)type
a/Source/WebKit/UIProcess/WebAuthentication/Mock/MockNfcService.mm_sec2
|
| 66 |
return _type; |
72 |
return _type; |
| 67 |
} |
73 |
} |
| 68 |
|
74 |
|
|
|
75 |
- (NSData *)tagID |
| 76 |
{ |
| 77 |
return _tagID.get(); |
| 78 |
} |
| 79 |
|
| 69 |
- (instancetype)initWithNFTag:(id<NFTag>)tag |
80 |
- (instancetype)initWithNFTag:(id<NFTag>)tag |
| 70 |
{ |
81 |
{ |
| 71 |
if ((self = [super init])) |
82 |
if ((self = [super init])) { |
| 72 |
_type = tag.type; |
83 |
_type = tag.type; |
|
|
84 |
_tagID = tag.tagID; |
| 85 |
} |
| 73 |
return self; |
86 |
return self; |
| 74 |
} |
87 |
} |
| 75 |
|
88 |
|
| 76 |
- (void)dealloc |
89 |
- (void)dealloc |
| 77 |
{ |
90 |
{ |
| 78 |
[_tagID release]; |
|
|
| 79 |
_tagID = nil; |
| 80 |
[_AppData release]; |
91 |
[_AppData release]; |
| 81 |
_AppData = nil; |
92 |
_AppData = nil; |
| 82 |
[_UID release]; |
93 |
[_UID release]; |
|
Lines 97-104
- (BOOL)isEqualToNFTag:(id<NFTag>)tag
a/Source/WebKit/UIProcess/WebAuthentication/Mock/MockNfcService.mm_sec3
|
| 97 |
|
108 |
|
| 98 |
- (instancetype)initWithType:(NFTagType)type |
109 |
- (instancetype)initWithType:(NFTagType)type |
| 99 |
{ |
110 |
{ |
| 100 |
if ((self = [super init])) |
111 |
return [self initWithType:type tagID:adoptNS([[NSData alloc] initWithBytes:tagID1 length:sizeof(tagID1)]).get()]; |
|
|
112 |
} |
| 113 |
|
| 114 |
- (instancetype)initWithType:(NFTagType)type tagID:(NSData *)tagID |
| 115 |
{ |
| 116 |
if ((self = [super init])) { |
| 101 |
_type = type; |
117 |
_type = type; |
|
|
118 |
_tagID = tagID; |
| 119 |
} |
| 102 |
return self; |
120 |
return self; |
| 103 |
} |
121 |
} |
| 104 |
|
122 |
|
|
Lines 132-137
static BOOL NFReaderSessionConnectTag(id, SEL, NFTag *)
a/Source/WebKit/UIProcess/WebAuthentication/Mock/MockNfcService.mm_sec4
|
| 132 |
return YES; |
150 |
return YES; |
| 133 |
} |
151 |
} |
| 134 |
|
152 |
|
|
|
153 |
static BOOL NFReaderSessionStopPolling(id, SEL) |
| 154 |
{ |
| 155 |
if (!globalNfcService) |
| 156 |
return NO; |
| 157 |
globalNfcService->receiveStopPolling(); |
| 158 |
return YES; |
| 159 |
} |
| 160 |
|
| 161 |
static BOOL NFReaderSessionStartPollingWithError(id, SEL, NSError **) |
| 162 |
{ |
| 163 |
if (!globalNfcService) |
| 164 |
return NO; |
| 165 |
globalNfcService->receiveStartPolling(); |
| 166 |
return YES; |
| 167 |
} |
| 168 |
|
| 135 |
static NSData* NFReaderSessionTransceive(id, SEL, NSData *) |
169 |
static NSData* NFReaderSessionTransceive(id, SEL, NSData *) |
| 136 |
{ |
170 |
{ |
| 137 |
if (!globalNfcService) |
171 |
if (!globalNfcService) |
|
Lines 159-164
NSData* MockNfcService::transceive()
a/Source/WebKit/UIProcess/WebAuthentication/Mock/MockNfcService.mm_sec5
|
| 159 |
return [result autorelease]; |
193 |
return [result autorelease]; |
| 160 |
} |
194 |
} |
| 161 |
|
195 |
|
|
|
196 |
void MockNfcService::receiveStopPolling() |
| 197 |
{ |
| 198 |
// For purpose of restart polling. |
| 199 |
m_configuration.nfc->multiplePhysicalTags = false; |
| 200 |
} |
| 201 |
|
| 202 |
void MockNfcService::receiveStartPolling() |
| 203 |
{ |
| 204 |
RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] { |
| 205 |
if (!weakThis) |
| 206 |
return; |
| 207 |
weakThis->detectTags(); |
| 208 |
}); |
| 209 |
} |
| 210 |
|
| 162 |
void MockNfcService::platformStartDiscovery() |
211 |
void MockNfcService::platformStartDiscovery() |
| 163 |
{ |
212 |
{ |
| 164 |
#if HAVE(NEAR_FIELD) |
213 |
#if HAVE(NEAR_FIELD) |
|
Lines 177-197
void MockNfcService::platformStartDiscovery()
a/Source/WebKit/UIProcess/WebAuthentication/Mock/MockNfcService.mm_sec6
|
| 177 |
Method methodToSwizzle3 = class_getInstanceMethod(getNFReaderSessionClass(), @selector(transceive:)); |
226 |
Method methodToSwizzle3 = class_getInstanceMethod(getNFReaderSessionClass(), @selector(transceive:)); |
| 178 |
method_setImplementation(methodToSwizzle3, (IMP)NFReaderSessionTransceive); |
227 |
method_setImplementation(methodToSwizzle3, (IMP)NFReaderSessionTransceive); |
| 179 |
|
228 |
|
| 180 |
auto readerSession = adoptNS([allocNFReaderSessionInstance() init]); |
229 |
Method methodToSwizzle4 = class_getInstanceMethod(getNFReaderSessionClass(), @selector(stopPolling)); |
| 181 |
setDriver(WTF::makeUnique<CtapNfcDriver>(makeUniqueRef<NfcConnection>(readerSession.get(), *this))); |
230 |
method_setImplementation(methodToSwizzle4, (IMP)NFReaderSessionStopPolling); |
| 182 |
|
231 |
|
| 183 |
RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] { |
232 |
Method methodToSwizzle5 = class_getInstanceMethod(getNFReaderSessionClass(), @selector(startPollingWithError:)); |
| 184 |
if (!weakThis) |
233 |
method_setImplementation(methodToSwizzle5, (IMP)NFReaderSessionStartPollingWithError); |
| 185 |
return; |
234 |
|
| 186 |
weakThis->detectTags(); |
235 |
auto readerSession = adoptNS([allocNFReaderSessionInstance() init]); |
| 187 |
}); |
236 |
setConnection(NfcConnection::create(readerSession.get(), *this)); |
| 188 |
return; |
|
|
| 189 |
} |
237 |
} |
| 190 |
LOG_ERROR("No nfc authenticators is available."); |
238 |
LOG_ERROR("No nfc authenticators is available."); |
| 191 |
#endif // HAVE(NEAR_FIELD) |
239 |
#endif // HAVE(NEAR_FIELD) |
| 192 |
} |
240 |
} |
| 193 |
|
241 |
|
| 194 |
void MockNfcService::detectTags() const |
242 |
void MockNfcService::detectTags() |
| 195 |
{ |
243 |
{ |
| 196 |
#if HAVE(NEAR_FIELD) |
244 |
#if HAVE(NEAR_FIELD) |
| 197 |
if (m_configuration.nfc->error == Mock::NfcError::NoTags) |
245 |
if (m_configuration.nfc->error == Mock::NfcError::NoTags) |
|
Lines 207-212
void MockNfcService::detectTags() const
a/Source/WebKit/UIProcess/WebAuthentication/Mock/MockNfcService.mm_sec7
|
| 207 |
if (configuration.nfc->multipleTags) |
255 |
if (configuration.nfc->multipleTags) |
| 208 |
[tags addObject:adoptNS([[WKMockNFTag alloc] initWithType:NFTagTypeGeneric4A]).get()]; |
256 |
[tags addObject:adoptNS([[WKMockNFTag alloc] initWithType:NFTagTypeGeneric4A]).get()]; |
| 209 |
|
257 |
|
|
|
258 |
if (configuration.nfc->multiplePhysicalTags) |
| 259 |
[tags addObject:adoptNS([[WKMockNFTag alloc] initWithType:NFTagTypeGeneric4A tagID:adoptNS([[NSData alloc] initWithBytes:tagID2 length:sizeof(tagID2)]).get()]).get()]; |
| 260 |
|
| 210 |
[globalNFReaderSessionDelegate readerSession:nil didDetectTags:tags.get()]; |
261 |
[globalNFReaderSessionDelegate readerSession:nil didDetectTags:tags.get()]; |
| 211 |
}); |
262 |
}); |
| 212 |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), callback.get()); |
263 |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), callback.get()); |