-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Implementations of loadFile and loadHtmlString for WKWebView
#4486
Changes from 1 commit
8e05ac2
c1dc83a
f1343c2
0351601
b945839
5218c0a
d5cf9f9
98eb236
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,6 +206,17 @@ - (void)onLoadFile:(FlutterMethodCall*)call result:(FlutterResult)result { | |
| } | ||
|
|
||
| NSURL* url = [NSURL fileURLWithPath:[call arguments] isDirectory:NO]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should validate that this is non-nil before passing it below (returning an error if it is nil) in case someone passes a garbage string that doesn't parse as a path.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added additional check to ensure the |
||
|
|
||
| if (!url) { | ||
| NSString* errorDetails = [NSString stringWithFormat:@"Initializing NSURL with the supplied " | ||
| @"'%@' path resulted in a nil value.", | ||
| [call arguments]]; | ||
| result([FlutterError errorWithCode:@"loadFile_failed" | ||
| message:@"Failed parsing file path." | ||
| details:errorDetails]); | ||
| return; | ||
| } | ||
|
|
||
| NSURL* baseUrl = [url URLByDeletingLastPathComponent]; | ||
|
|
||
| [_webView loadFileURL:url allowingReadAccessToURL:baseUrl]; | ||
|
|
@@ -214,7 +225,7 @@ - (void)onLoadFile:(FlutterMethodCall*)call result:(FlutterResult)result { | |
|
|
||
| - (void)onLoadHtmlString:(FlutterMethodCall*)call result:(FlutterResult)result { | ||
| NSDictionary* arguments = [call arguments]; | ||
| if (!arguments || ![arguments isKindOfClass:NSDictionary.class]) { | ||
| if (![arguments isKindOfClass:NSDictionary.class]) { | ||
| result([FlutterError | ||
| errorWithCode:@"loadHtmlString_failed" | ||
| message:@"Failed parsing arguments." | ||
|
|
@@ -603,6 +614,14 @@ - (void)updateUserAgent:(NSString*)userAgent { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validates if the given `argument` is a non-null non-empty string. | ||
| * | ||
| * @param argument The argument that should be validated. | ||
| * @param errorDetails An optional NSString variable which will contain a detailed error message in | ||
| * case the supplied argument is not valid. | ||
| * @return `true` if the given `argument` is a valid non-null, non-empty string; otherwise `false`. | ||
|
||
| */ | ||
| + (bool)isValidStringArgument:(id)argument withErrorMessage:(NSString**)errorDetails { | ||
|
||
| if (!argument) { | ||
| if (errorDetails) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you still want the non-emtpy assert here and below?