diff --git a/framework/ios/base/bridge/HippyBridge.h b/framework/ios/base/bridge/HippyBridge.h index addcc0193e9..784e1ff3e71 100644 --- a/framework/ios/base/bridge/HippyBridge.h +++ b/framework/ios/base/bridge/HippyBridge.h @@ -214,7 +214,7 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass); @property (nonatomic, copy, readonly) NSArray *bundleURLs; /// Path of sandbox directory -@property (nonatomic, strong) NSString *sandboxDirectory; +@property (nonatomic, copy) NSString *sandboxDirectory; /// Shared data between different rootViews on same bridge. /// Set by HippyRootView when runHippyApplication. diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index 22e30951d91..62e8de82d4a 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -192,6 +192,7 @@ @interface HippyBridge() { @implementation HippyBridge +@synthesize sandboxDirectory = _sandboxDirectory; @synthesize imageLoader = _imageLoader; @synthesize imageProviders = _imageProviders; @synthesize startTime = _startTime; @@ -1218,11 +1219,19 @@ - (void)registerModuleForFrameUpdates:(id)module withModuleDa [_displayLink registerModuleForFrameUpdates:module withModuleData:moduleData]; } +- (NSString *)sandboxDirectory { + @synchronized (self) { + return _sandboxDirectory; + } +} + - (void)setSandboxDirectory:(NSString *)sandboxDirectory { - if (![_sandboxDirectory isEqual:sandboxDirectory]) { - _sandboxDirectory = sandboxDirectory; - if (sandboxDirectory) { - [self.javaScriptExecutor setSandboxDirectory:sandboxDirectory]; + @synchronized (self) { + if (![_sandboxDirectory isEqual:sandboxDirectory]) { + _sandboxDirectory = sandboxDirectory; + if (sandboxDirectory) { + [self.javaScriptExecutor setSandboxDirectory:sandboxDirectory]; + } } } } diff --git a/modules/vfs/ios/HippyFileHandler.h b/modules/vfs/ios/HippyFileHandler.h index 5d306bc7f1b..3ca65ee4356 100644 --- a/modules/vfs/ios/HippyFileHandler.h +++ b/modules/vfs/ios/HippyFileHandler.h @@ -43,8 +43,8 @@ class HippyFileHandler : public VFSUriHandler { /// Convert relative addresses(such as hpfile://) to absolute paths /// - Parameters: /// - hippyFileUrl: file url - /// - hippySandboxDirectory: sandbox directory of hippy app - static NSURL *AbsoluteURLFromHippyFileURL(NSURL *hippyFileUrl, NSURL *hippySandboxDirectory); + /// - bridge: HippyBridge, use to get sandbox url + static NSURL *AbsoluteURLFromHippyFileURL(NSURL *hippyFileUrl, HippyBridge *bridge); virtual void RequestUntrustedContent(NSURLRequest *request, NSDictionary *extraInfo, diff --git a/modules/vfs/ios/HippyFileHandler.mm b/modules/vfs/ios/HippyFileHandler.mm index f74be7b4218..cd308b70c49 100644 --- a/modules/vfs/ios/HippyFileHandler.mm +++ b/modules/vfs/ios/HippyFileHandler.mm @@ -41,7 +41,7 @@ FOOTSTONE_UNIMPLEMENTED(); } -NSURL *HippyFileHandler::AbsoluteURLFromHippyFileURL(NSURL *fileUrl, NSURL *hippySandboxDirectory) { +NSURL *HippyFileHandler::AbsoluteURLFromHippyFileURL(NSURL *fileUrl, HippyBridge *bridge) { static NSString *defaultHippyLocalFileURLPrefix = @"hpfile://"; static NSString *hippyLocalRelativeFilePathPrefix = @"./"; static NSString *hippyLocalAppBundleFilePathPrefix = @"appbundle/"; @@ -55,6 +55,7 @@ if ([path hasPrefix:hippyLocalRelativeFilePathPrefix]) { // Hippy Sandbox Relative Path NSString *relativePath = [path substringFromIndex:hippyLocalRelativeFilePathPrefix.length]; + NSURL *hippySandboxDirectory = [NSURL URLWithString:bridge.sandboxDirectory]; absoluteURL = [NSURL fileURLWithPath:relativePath relativeToURL:hippySandboxDirectory]; } else if ([path hasPrefix:hippyLocalAppBundleFilePathPrefix]) { // App Bundle Path @@ -90,7 +91,7 @@ return; } - NSURL *absoluteURL = AbsoluteURLFromHippyFileURL(url, [NSURL URLWithString:bridge.sandboxDirectory]); + NSURL *absoluteURL = AbsoluteURLFromHippyFileURL(url, bridge); if ([absoluteURL isFileURL] || [absoluteURL isFileReferenceURL]) { void (^opBlock)() = ^{ NSError *error;