Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-28406
Browse files Browse the repository at this point in the history
  • Loading branch information
lokeshchdhry committed Apr 8, 2021
2 parents eb5042e + fe3dedd commit 15907ac
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 39 deletions.
94 changes: 64 additions & 30 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -348,47 +348,74 @@ - (void)didStartNewContext:(KrollContext *)kroll
// Load ti.kernel.js (kroll.js equivalent)
NSURL *bootstrapURL = [TiHost resourceBasedURL:@"ti.kernel.js" baseURL:NULL];
NSString *source = [AssetsModule readURL:bootstrapURL];

JSValue *bootstrapFunc = [objcJSContext evaluateScript:source withSourceURL:bootstrapURL];
if (objcJSContext.exception != nil) {
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
}
[bootstrapFunc callWithArguments:@[ global, [[KrollModule alloc] init] ]];
if (objcJSContext.exception != nil) {
if (source == nil || source.length == 0) {
NSLog(@"[ERROR] Error reading ti.kernel.js, source is nil/empty. Most likely due to failure to decrypt via remote policy and device offline.");
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
// Don't put up a dialog, as the most likely cause here is remote policy encryption/decryption failing to decrypt due to being offline.
// And if we have a dialog up, the security violation dialog won't appear
} else {
JSValue *bootstrapFunc = [objcJSContext evaluateScript:source withSourceURL:bootstrapURL];
if (objcJSContext.exception != nil) {
NSLog(@"[ERROR] Error eval'ing ti.kernel.js bootstrap script. Please contact Titanium developers and file a bug report.");
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
} else if (bootstrapFunc == nil || [bootstrapFunc isUndefined]) {
// it didn't export a bootstrap function! Most likely reason is we hosed the file
NSLog(@"[ERROR] Error eval'ing ti.kernel.js, bootstrap function is undefined/nil. Please contact Titanium developers and file a bug report.");
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
} else {
// ti.kernel.js eval'd OK, so now let's run the exported bootstrap function
[bootstrapFunc callWithArguments:@[ global, [[KrollModule alloc] init] ]];
if (objcJSContext.exception != nil) {
NSLog(@"[ERROR] Error calling ti.kernel.js' exported bootstrap function. Please contact Titanium developers and file a bug report.");
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
}
}
}

JSValue *titanium = global[@"Ti"];
TopTiModule *module = [titanium toObject];
if ([[TiSharedConfig defaultConfig] isAnalyticsEnabled]) {
APSAnalytics *sharedAnalytics = [APSAnalytics sharedInstance];
NSString *buildType = [[TiSharedConfig defaultConfig] applicationBuildType];
NSString *deployType = [[TiSharedConfig defaultConfig] applicationDeployType];
NSString *guid = [[TiSharedConfig defaultConfig] applicationGUID];
JSValue *titanium = global[@"Ti"]; // This may be nil/undefined it we couldn't load ti.kernel.js or the bootstrapping failed
if (TiSharedConfig.defaultConfig.isAnalyticsEnabled) {
APSAnalytics *sharedAnalytics = APSAnalytics.sharedInstance;
NSString *buildType = TiSharedConfig.defaultConfig.applicationBuildType;
if (buildType != nil || buildType.length > 0) {
[sharedAnalytics performSelector:@selector(setBuildType:) withObject:buildType];
[sharedAnalytics setBuildType:buildType];
}
TopTiModule *module;
if (titanium != nil && ![titanium isUndefined]) {
module = [titanium toObject];
} else {
// Uh-oh, something went really wrong! For analytics sake, let's just create the module
module = [[TopTiModule alloc] init];
global[@"Ti"] = module;
global[@"Titanium"] = module;
}
[sharedAnalytics performSelector:@selector(setSDKVersion:) withObject:[module performSelector:@selector(version)]];
[sharedAnalytics setSDKVersion:module.version];
NSString *deployType = TiSharedConfig.defaultConfig.applicationDeployType;
NSString *guid = TiSharedConfig.defaultConfig.applicationGUID;
[sharedAnalytics enableWithAppKey:guid andDeployType:deployType];
}

NSURL *startURL = nil;
//if we have a preload dictionary, register those static key/values into our namespace
if (preload != nil) {
for (NSString *name in preload) {
JSValue *moduleJSObject = titanium[name];
KrollObject *ti = (KrollObject *)JSObjectGetPrivate(JSValueToObject(jsContext, moduleJSObject.JSValueRef, NULL));
NSDictionary *values = preload[name];
for (id key in values) {
id target = values[key];
KrollObject *ko = [self krollObjectForProxy:target];
if (ko == nil) {
ko = [self registerProxy:target];
// Guard for top level Titanium object being unassigned. likley means we had issues
// setting up ti.kernel.js, so we likely need to skip most everything here.
if (titanium != nil && ![titanium isUndefined]) {
for (NSString *name in preload) {
JSValue *moduleJSObject = titanium[name];
KrollObject *ti = (KrollObject *)JSObjectGetPrivate(JSValueToObject(jsContext, moduleJSObject.JSValueRef, NULL));
NSDictionary *values = preload[name];
for (id key in values) {
id target = values[key];
KrollObject *ko = [self krollObjectForProxy:target];
if (ko == nil) {
ko = [self registerProxy:target];
}
[ti noteKrollObject:ko forKey:key];
[ti setStaticValue:ko forKey:key purgable:NO];
}
[ti noteKrollObject:ko forKey:key];
[ti setStaticValue:ko forKey:key purgable:NO];
}
}
startURL = [url copy]; // should be the entry point of the background service js file
Expand All @@ -398,7 +425,14 @@ - (void)didStartNewContext:(KrollContext *)kroll

// We need to run this before the entry js file, which means it has to be here.
TiBindingRunLoopAnnounceStart(kroll);
[self evalFile:[startURL absoluteString] callback:self selector:@selector(booted)];
if (!evaluationError) {
[self evalFile:[startURL absoluteString] callback:self selector:@selector(booted)];
} else {
NSLog(@"[ERROR] Error loading/executing ti.kernel.js bootstrap code, refusing to launch app main file.");
// DO NOT POP AN ERROR DIALOG! The most likley scenario here is that the app is remotely encrypted
// and the decryption failed because the device is offline
// If we pop a dialog here, it will block the "Security Violation" error dialog that would show in that case
}

if (TiUtils.isHyperloopAvailable) {
Class cls = NSClassFromString(@"Hyperloop");
Expand Down
4 changes: 3 additions & 1 deletion iphone/TitaniumKit/TitaniumKit/Sources/API/TiProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,11 @@ - (void)fireEvent:(NSString *)type withObject:(id)obj withSource:(id)source prop
NSThread.isMainThread);
}

- (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues
- (void)setValuesForKeysWithDictionary:(NSDictionary *)dictionary
{
//It's possible that the 'setvalueforkey' has its own plans of what should be in the JS object,
//so we should do this first as to not overwrite the subclass's setter.
NSDictionary *keyedValues = [dictionary copy];
if ((bridgeCount == 1) && (pageKrollObject != nil)) {
for (NSString *currentKey in keyedValues) {
id currentValue = [keyedValues objectForKey:currentKey];
Expand Down Expand Up @@ -991,6 +992,7 @@ - (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues
}
[self setValue:thisValue forKey:thisKey];
}
RELEASE_TO_NIL(keyedValues);
}

DEFINE_EXCEPTIONS
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"commander": "^7.2.0",
"commitizen": "^4.2.3",
"conventional-changelog-cli": "^2.1.1",
"core-js": "^3.10.0",
"core-js": "^3.10.1",
"cz-conventional-changelog": "^3.3.0",
"danger": "^10.6.4",
"dateformat": "^4.5.1",
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions tests/Resources/ti.media.videoplayer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,27 @@ describe.androidARM64Broken('Titanium.Media.VideoPlayer', () => {
player.addEventListener('playing', () => finish());
win.open();
});

it.ios('App should not crash when setting url after video player creation (TIMOB-28217)', function (finish) {
this.timeout(10000);

win = Ti.UI.createWindow();
player = Ti.Media.createVideoPlayer({
top: 120,
autoplay: false,
backgroundColor: 'blue',
height: 300,
width: 300,
mediaControlStyle: Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode: Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
showsControls: true,
});
player.url = '/movie.mp4';
win.add(player);
win.addEventListener('open', () => {
finish();
});

win.open();
});
});

0 comments on commit 15907ac

Please sign in to comment.