Skip to content

Commit

Permalink
feat: android Ti.UI.WebView support allowFileAccess (#13229)
Browse files Browse the repository at this point in the history
* feat: android Ti.UI.WebView support allowFileAccess

This is needed so that local files can be loaded into a WebView.

* feat: update WebView.yml

added new property: allowFileAccess to API docs

* Update apidoc/Titanium/UI/WebView.yml

Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>

---------

Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
  • Loading branch information
2 people authored and hansemannn committed Apr 18, 2023
1 parent 74f9296 commit 29ed703
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,23 @@ public void setZoomLevel(float value)
}
}

@Kroll.setProperty
public void setAllowFileAccess(boolean enabled)
{
setPropertyAndFire(TiC.PROPERTY_ALLOW_FILE_ACCESS, enabled);
}

@Kroll.getProperty
public boolean getAllowFileAccess()
{
boolean enabled = true;

if (hasProperty(TiC.PROPERTY_ALLOW_FILE_ACCESS)) {
enabled = TiConvert.toBoolean(getProperty(TiC.PROPERTY_ALLOW_FILE_ACCESS));
}
return enabled;
}

@Kroll.getProperty
public double getProgress()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ public TiUIWebView(TiViewProxy proxy)
}
}

boolean allowFileAccess = false; //file access should be false by default: https://developer.android.com/reference/android/webkit/WebSettings#setAllowFileAccess(boolean)
if (proxy.hasProperty(TiC.PROPERTY_ALLOW_FILE_ACCESS)) {
allowFileAccess = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ALLOW_FILE_ACCESS), false);
}

settings.setAllowFileAccess(allowFileAccess);

// enable zoom controls by default
boolean enableZoom = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public class TiC
public static final String PROPERTY_ADD = "add";
public static final String PROPERTY_ADDRESS = "address";
public static final String PROPERTY_ALLOW_BACKGROUND = "allowBackground";
public static final String PROPERTY_ALLOW_FILE_ACCESS = "allowFileAccess";
public static final String PROPERTY_ALLOW_MULTIPLE = "allowMultiple";
public static final String PROPERTY_ALLOWS_SELECTION_DURING_EDITING = "allowsSelectionDuringEditing";
public static final String PROPERTY_ALLOWS_MULTIPLE_SELECTION_DURING_EDITING
Expand Down
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,16 @@ events:
type: String

properties:

- name: allowFileAccess
summary: A Boolean value indicating file access within WebView.
description: |
Set to `true` to enable access to local files for examples images stored in <Titanium.Filesystem.applicationDataDirectory>. If false resources are still accessible using `file:///android_asset` and `file:///android_res`. Do not enable this if your app accepts arbitrary URLs from external sources.
type: Boolean
default: false
platforms: [android]
since: {android: "12.1.0"}

- name: allowsLinkPreview
summary: |
A Boolean value that determines whether pressing on a link displays a preview of the
Expand Down

0 comments on commit 29ed703

Please sign in to comment.