From 7a14016f1b8383230ca7130bcba3af49b4383985 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 16 May 2019 10:49:23 -0700 Subject: [PATCH] add observatoryUrl property to FlutterEngine --- .../darwin/ios/framework/Headers/FlutterEngine.h | 9 +++++++++ .../darwin/ios/framework/Source/FlutterEngine.mm | 4 ++++ .../framework/Source/FlutterObservatoryPublisher.h | 2 ++ .../Source/FlutterObservatoryPublisher.mm | 14 +++++++++----- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index bf1e757687695..992a1c83055bd 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -228,6 +228,15 @@ FLUTTER_EXPORT */ @property(nonatomic, readonly) FlutterBasicMessageChannel* settingsChannel; +/** + * The `NSURL` of the observatory for the service isolate. + * + * This is only set in debug and profile runtime modes, and only after the + * observatory service is ready. In release mode or before the observatory has + * started, it returns `nil`. + */ +@property(nonatomic, readonly) NSURL* observatoryUrl; + @end #endif // FLUTTER_FLUTTERENGINE_H_ diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 50208e65a08d4..f99c346ea1632 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -207,6 +207,10 @@ - (FlutterBasicMessageChannel*)settingsChannel { return _settingsChannel.get(); } +- (NSURL*)observatoryUrl { + return [_publisher.get() url]; +} + - (void)resetChannels { _localizationChannel.reset(); _navigationChannel.reset(); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h index 68f97c6b6698e..387176f76e25e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h @@ -9,6 +9,8 @@ @interface FlutterObservatoryPublisher : NSObject +@property(nonatomic, readonly) NSURL* url; + @end #endif // FLUTTER_FLUTTEROBSERVATORYPUBLISHER_H_ diff --git a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm index 38c92fa1ce287..67b961da37fac 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm @@ -36,6 +36,7 @@ @interface FlutterObservatoryPublisher () @end @implementation FlutterObservatoryPublisher { + fml::scoped_nsobject _url; #if TARGET_IPHONE_SIMULATOR DNSServiceRef _dnsServiceRef; #else // TARGET_IPHONE_SIMULATOR @@ -46,6 +47,10 @@ @implementation FlutterObservatoryPublisher { std::unique_ptr> _weakFactory; } +- (NSURL*)url { + return _url.get(); +} + - (instancetype)init { self = [super init]; NSAssert(self, @"Super must not return null on init."); @@ -92,15 +97,14 @@ - (void)publishServiceProtocolPort:(std::string)uri { } // uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port // number. - NSURL* url = - [[[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]] autorelease]; + _url.reset([[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]]); NSString* serviceName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]; // Check to see if there's an authentication code. If there is, we'll provide // it as a txt record so flutter tools can establish a connection. - auto path = std::string{[[url path] UTF8String]}; + auto path = std::string{[[_url path] UTF8String]}; if (!path.empty()) { // Remove leading "/" path = path.substr(1); @@ -116,7 +120,7 @@ - (void)publishServiceProtocolPort:(std::string)uri { uint32_t interfaceIndex = if_nametoindex("lo0"); const char* registrationType = "_dartobservatory._tcp"; const char* domain = "local."; // default domain - uint16_t port = [[url port] intValue]; + uint16_t port = [[_url port] intValue]; int err = DNSServiceRegister(&_dnsServiceRef, flags, interfaceIndex, [serviceName UTF8String], registrationType, domain, NULL, htons(port), txtData.length, @@ -131,7 +135,7 @@ - (void)publishServiceProtocolPort:(std::string)uri { NSNetService* netServiceTmp = [[NSNetService alloc] initWithDomain:@"local." type:@"_dartobservatory._tcp." name:serviceName - port:[[url port] intValue]]; + port:[[_url port] intValue]]; [netServiceTmp setTXTRecordData:txtData]; _netService.reset(netServiceTmp); [_netService.get() setDelegate:self];