Skip to content

Commit

Permalink
fix(ios): add script message handler for local files only (#11086)
Browse files Browse the repository at this point in the history
Fixes TIMOB-27253
  • Loading branch information
vijaysingh-axway authored and sgtcoolguy committed Aug 20, 2019
1 parent 710083a commit 6e46ed3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ - (WKWebView *)webView
WKUserContentController *controller = [[[WKUserContentController alloc] init] autorelease];

[controller addUserScript:[self userScriptTitaniumInjectionForAppEvent]];
[controller addScriptMessageHandler:self name:@"_Ti_"];

[config setUserContentController:controller];

Expand Down Expand Up @@ -184,7 +183,10 @@ - (void)setUrl_:(id)value

NSURL *url = [TiUtils toURL:value proxy:self.proxy];

[_webView.configuration.userContentController removeScriptMessageHandlerForName:@"_Ti_"];

if ([[self class] isLocalURL:url]) {
[_webView.configuration.userContentController addScriptMessageHandler:self name:@"_Ti_"];
[self loadLocalURL:url];
} else {
[self loadRequestWithURL:[NSURL URLWithString:[TiUtils stringValue:value]]];
Expand Down Expand Up @@ -220,6 +222,9 @@ - (void)setData_:(id)value
NSLog(@"[ERROR] Ti.UI.WebView.data can only be a TiBlob or TiFile object, was %@", [(TiProxy *)value apiName]);
}

[_webView.configuration.userContentController removeScriptMessageHandlerForName:@"_Ti_"];
[_webView.configuration.userContentController addScriptMessageHandler:self name:@"_Ti_"];

[[self webView] loadData:data
MIMEType:[self mimeTypeForData:data]
characterEncodingName:@"UTF-8"
Expand Down Expand Up @@ -259,6 +264,9 @@ - (void)setHtml_:(id)args
[[self webView] stopLoading];
}

[_webView.configuration.userContentController removeScriptMessageHandlerForName:@"_Ti_"];
[_webView.configuration.userContentController addScriptMessageHandler:self name:@"_Ti_"];

// No options, default load behavior
if (options == nil) {
[[self webView] loadHTMLString:content baseURL:[NSURL fileURLWithPath:[TiHost resourcePath]]];
Expand Down

0 comments on commit 6e46ed3

Please sign in to comment.