Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): add script message handler for local files only (8_1_X) #11086

Merged
merged 4 commits into from
Aug 20, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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