Skip to content

[webview_flutter_android] Expose allowFileAccessFromFileURLs and allowUniversalAccessFromFileURLs - #12330

Open
jackxuechen wants to merge 1 commit into
flutter:mainfrom
jackxuechen:add-android-file-url-access-settings
Open

[webview_flutter_android] Expose allowFileAccessFromFileURLs and allowUniversalAccessFromFileURLs#12330
jackxuechen wants to merge 1 commit into
flutter:mainfrom
jackxuechen:add-android-file-url-access-settings

Conversation

@jackxuechen

@jackxuechen jackxuechen commented Jul 31, 2026

Copy link
Copy Markdown

This PR exposes Android WebView file URL access settings through AndroidWebViewController.

The following Android WebSettings APIs are added:

  • setAllowFileAccessFromFileURLs
  • setAllowUniversalAccessFromFileURLs

These settings allow applications loading local web content using file:// URLs to explicitly configure whether local resources and resources from other origins can be accessed.

This is useful for applications embedding local HTML assets that need to load additional local files or communicate with remote web services.

The APIs are only available on Android and do not affect other WebView implementations.

Issues

N/A

This is an API enhancement request to expose existing Android WebSettings functionality.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@google-cla

google-cla Bot commented Jul 31, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for configuring file URL access permissions (setAllowFileAccessFromFileURLs and setAllowUniversalAccessFromFileURLs) in the Android WebView plugin. This includes updates to Pigeon definitions, generated Kotlin and Dart bindings, the controller implementation, and corresponding unit tests. The review feedback suggests replacing @NotNull with @NonNull in WebSettingsProxyApi.java to maintain consistency with the rest of the codebase.

@jackxuechen
jackxuechen force-pushed the add-android-file-url-access-settings branch from aeb03e5 to a478ace Compare July 31, 2026 10:44
@stuartmorgan-g stuartmorgan-g added the triage-android Should be looked at in Android triage label Aug 3, 2026
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! You’ve checked boxes in the PR checklist above that are not reflected in this PR, so I’m assuming this is a work in progress and am marking it as a Draft. Please review the checklist, updating the PR as appropriate, and when the state of the PR as posted reflects the checklist please feel free to mark it as ready for review.

@stuartmorgan-g
stuartmorgan-g marked this pull request as draft August 3, 2026 16:01
@jackxuechen
jackxuechen force-pushed the add-android-file-url-access-settings branch from a478ace to bc3cfd9 Compare August 4, 2026 02:25
@jackxuechen

Copy link
Copy Markdown
Author

I have updated the PR checklist and made the necessary changes to CHANGELOG.md and pubspec.yaml.

@jackxuechen
jackxuechen marked this pull request as ready for review August 4, 2026 02:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for configuring file URL access permissions in webview_flutter_android by introducing setAllowFileAccessFromFileURLs and setAllowUniversalAccessFromFileURLs to AndroidWebViewController and its underlying Pigeon bindings. The review feedback suggests documenting that these settings are deprecated and have no effect starting from Android API level 30 (Android 11) in the Dart doc comments, and adding @SuppressWarnings("deprecation") to the Java implementation to suppress compiler warnings.

Comment on lines +623 to +628
/// Sets the file URL access to other file URLs permission for the web view.
///
/// The default value is true for apps targeting API 15 and below, and false
/// when targeting API 16 and above.
Future<void> setAllowFileAccessFromFileURLs(bool enabled) =>
_webView.settings.setAllowFileAccessFromFileURLs(enabled);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This setting is deprecated starting from Android API level 30 (Android 11) and has no effect on those versions. It is highly recommended to document this limitation in the Dart doc comments so that developers are aware of it.

Suggested change
/// Sets the file URL access to other file URLs permission for the web view.
///
/// The default value is true for apps targeting API 15 and below, and false
/// when targeting API 16 and above.
Future<void> setAllowFileAccessFromFileURLs(bool enabled) =>
_webView.settings.setAllowFileAccessFromFileURLs(enabled);
/// Sets the file URL access to other file URLs permission for the web view.
///
/// The default value is true for apps targeting API 15 and below, and false
/// when targeting API 16 and above.
///
/// Note that starting from Android API level 30 (Android 11), this setting is
/// not supported and has no effect.
Future<void> setAllowFileAccessFromFileURLs(bool enabled) =>
_webView.settings.setAllowFileAccessFromFileURLs(enabled);

Comment on lines +630 to +635
/// Sets the universal cross-origin access from file URLs permission for the web view.
///
/// The default value is true for apps targeting API 15 and below, and false
/// when targeting API 16 and above.
Future<void> setAllowUniversalAccessFromFileURLs(bool enabled) =>
_webView.settings.setAllowUniversalAccessFromFileURLs(enabled);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This setting is deprecated starting from Android API level 30 (Android 11) and has no effect on those versions. It is highly recommended to document this limitation in the Dart doc comments so that developers are aware of it.

Suggested change
/// Sets the universal cross-origin access from file URLs permission for the web view.
///
/// The default value is true for apps targeting API 15 and below, and false
/// when targeting API 16 and above.
Future<void> setAllowUniversalAccessFromFileURLs(bool enabled) =>
_webView.settings.setAllowUniversalAccessFromFileURLs(enabled);
/// Sets the universal cross-origin access from file URLs permission for the web view.
///
/// The default value is true for apps targeting API 15 and below, and false
/// when targeting API 16 and above.
///
/// Note that starting from Android API level 30 (Android 11), this setting is
/// not supported and has no effect.
Future<void> setAllowUniversalAccessFromFileURLs(bool enabled) =>
_webView.settings.setAllowUniversalAccessFromFileURLs(enabled);

Comment on lines +89 to +99
@Override
public void setAllowFileAccessFromFileURLs(
@NonNull WebSettings pigeon_instance, boolean enabled) {
pigeon_instance.setAllowFileAccessFromFileURLs(enabled);
}

@Override
public void setAllowUniversalAccessFromFileURLs(
@NonNull WebSettings pigeon_instance, boolean enabled) {
pigeon_instance.setAllowUniversalAccessFromFileURLs(enabled);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since setAllowFileAccessFromFileURLs and setAllowUniversalAccessFromFileURLs are deprecated in Android (since API level 30), calling them can trigger compiler warnings. Adding @SuppressWarnings("deprecation") prevents these warnings from cluttering the build output or causing build failures if warnings are treated as errors.

Suggested change
@Override
public void setAllowFileAccessFromFileURLs(
@NonNull WebSettings pigeon_instance, boolean enabled) {
pigeon_instance.setAllowFileAccessFromFileURLs(enabled);
}
@Override
public void setAllowUniversalAccessFromFileURLs(
@NonNull WebSettings pigeon_instance, boolean enabled) {
pigeon_instance.setAllowUniversalAccessFromFileURLs(enabled);
}
@SuppressWarnings("deprecation")
@Override
public void setAllowFileAccessFromFileURLs(
@NonNull WebSettings pigeon_instance, boolean enabled) {
pigeon_instance.setAllowFileAccessFromFileURLs(enabled);
}
@SuppressWarnings("deprecation")
@Override
public void setAllowUniversalAccessFromFileURLs(
@NonNull WebSettings pigeon_instance, boolean enabled) {
pigeon_instance.setAllowUniversalAccessFromFileURLs(enabled);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: webview_flutter platform-android triage-android Should be looked at in Android triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants