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): allow changing WebView read access when loading local file #10976
Conversation
Tests:
|
apidoc/Titanium/UI/WebView.yml
Outdated
@@ -170,6 +170,22 @@ methods: | |||
since: {android: "8.1.0", iphone: "2.0.0", ipad: "2.0.0"} | |||
platforms: [android, iphone, ipad] | |||
|
|||
- name: loadFile |
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.
Is this for loading html files? Or for other resources?
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.
Both.
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.
All html files should be handled via "url" which is already pretty smart handling different types of urls. In additions, assets should be loaded through the bridge between the WKWebView and the web-view handler.
@vijaysingh-axway does this need parity with Android? |
Android do not have anything similar. @jquick-axway has mentioned in comment of this ticket. |
When setting this to a local HTML file, wouldn't everyone want to set I don't see anyone ever setting it to a different directory. That doesn't seem practical. Also, I can seeing this being as a non-stop tech-support issue for us. We would end up telling everyone to call the I'm leaning toward us automatically setting Is there any reason not to set this automatically? |
@jquick-axway The ticket author mentioned it would be nice to change However, i think it would be best to copy the local CSS files to the cache dir and then set |
So my 2 cents here: I really don't like the idea of adding some epochal extra method to web view that is both iOS-specific *and specific to a particular use case of files in the app cache. As @jquick-axway @hansemannn and @janvennemann are alluding to, we should try and "do the right thing" under the hood in our existing APIs (like the url property). |
Agreed. What if I modify the setUrl to take extra optional parameter 'readAccessUrl' similar to setHtml |
The default handling of all other If a developer wants the base directory to be different, then we already have an existing solution. They can call the |
I'd extend the |
Guys. We're waaayyy over thinking this. Also, if you look at the ticket's attached sample code (Resources.zip), you'll see that the HTML file is loading the CSS file via a relative path like this "../css/test.css". Meaning that the HTML is assuming that the base directory is the same location as the HTML file. We just need to restore the old behavior. We've never offered the ability to set the base directory to something different than the HTML file's directory before. So, we're losing nothing. Let's not waste time implementing a new feature that no one is going to use. |
@jquick-axway As we discussed, when there is any directory structure like ../Cache/html/example.html , ../Cache/css/test.css if we use default access directory ../Cache/html/, it will not whitelist ../Cache/css/test.css for webkit. For whitelisting ../Cache/css/test.css we have to whitelist ../Cache/ directory. I agree with Hans's proposal to make iOS specific property. |
I think this is a good middle ground solution between getting parity of Android and iOS and having too much platform specific APIs. With this change loading local resources that are in the same directory or in a sub directory as the html works out of the box on both platforms. Referring resources from parent directories like the @vijaysingh-axway I think we should add a few notes to the docs explaining when the |
apidoc/Titanium/UI/WebView.yml
Outdated
@@ -657,6 +657,15 @@ properties: | |||
since: "3.0.0" | |||
default: false | |||
|
|||
- name: assetsDirectory | |||
summary: Path of file or directory to allow read access. |
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.
summary: Path of file or directory to allow read access. | |
summary: Path of file or directory to allow read access by the WebView. |
apidoc/Titanium/UI/WebView.yml
Outdated
- name: assetsDirectory | ||
summary: Path of file or directory to allow read access. | ||
description: | | ||
If assetsDirectory references a single file, only that file may be loaded. If assetsDirectory references a directory, |
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.
If assetsDirectory references a single file, only that file may be loaded. If assetsDirectory references a directory, | |
Use this to change the resources the web view has access to when loading the content of a local file. By default | |
the web view only has access to files inside the same directory as the loaded file. To reference resources from | |
other directories (e.g. a parent directory) change this property accordingly. | |
If assetsDirectory references a single file, only that file may be loaded. If assetsDirectory references a | |
directory, files inside that directory may be loaded. |
apidoc/Titanium/UI/WebView.yml
Outdated
summary: Path of file or directory to allow read access. | ||
description: | | ||
If assetsDirectory references a single file, only that file may be loaded. If assetsDirectory references a directory, | ||
files inside that directory may be loaded. This property should be set with [url](Titanium.UI.WebView.url) property or before it. |
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.
files inside that directory may be loaded. This property should be set with [url](Titanium.UI.WebView.url) property or before it. | |
This property needs to be set before [url](Titanium.UI.WebView.url) is assigned to a local file. |
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.
LGTM!
@vijaysingh-axway Please add a unit test for the new property, thanks! |
hello, can you please review and confirm is it related to same ? file stored under applicationDataDirectory not loading into webview |
FR passed. WebView works as expected .loading HTML files . Waiting for 8.1.0 GA to merge. Test Environment: |
@vijaysingh-axway can you please add the missing unit tests before this gets merged? Also there seems to be a related issue with |
@vijaysingh-axway This is repeatedly failing some of the WebView unit tests due to a timeout. I don't think we can merge this until that is resolved. |
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.
4 WebView tests are timing out with this PR. They need to be working for this to be ready to merge.
Looks like iOS 13 broken WKWebView's API - (nullable WKNavigation *)loadFileURL:(NSURL *)URL allowingReadAccessToURL:(NSURL *)readAccessURL. https://forums.developer.apple.com/thread/120566 |
Closing in favor of PR #11431 . |
https://jira.appcelerator.org/browse/TIMOB-27159