Skip to content

Commit 8e911ec

Browse files
Selim Gurungcondra
authored andcommitted
DO NOT MERGE Add API for file origin policy.
Bug: 6212665 Add hidden websettings api for configuring file origin policy. Change-Id: I261ba6369fe606ca76f87c6a00d1168b44bcf1ab
1 parent 9e22d9c commit 8e911ec

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

core/java/android/webkit/WebSettings.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public enum PluginState {
181181
private boolean mBlockNetworkImage = false;
182182
private boolean mBlockNetworkLoads;
183183
private boolean mJavaScriptEnabled = false;
184+
private boolean mAllowUniversalAccessFromFileURLs = true;
185+
private boolean mAllowFileAccessFromFileURLs = true;
184186
private boolean mHardwareAccelSkia = false;
185187
private boolean mShowVisualIndicator = false;
186188
private PluginState mPluginState = PluginState.OFF;
@@ -1263,6 +1265,47 @@ public synchronized void setJavaScriptEnabled(boolean flag) {
12631265
}
12641266
}
12651267

1268+
/**
1269+
* Sets whether JavaScript running in the context of a file scheme URL
1270+
* should be allowed to access content from any origin. This includes
1271+
* access to content from other file scheme URLs. See
1272+
* {@link #setAllowFileAccessFromFileURLs}. To enable the most restrictive,
1273+
* and therefore secure policy, this setting should be disabled.
1274+
* <p>
1275+
* The default value is true.
1276+
*
1277+
* @param flag whether JavaScript running in the context of a file scheme
1278+
* URL should be allowed to access content from any origin
1279+
* @hide
1280+
*/
1281+
public synchronized void setAllowUniversalAccessFromFileURLs(boolean flag) {
1282+
if (mAllowUniversalAccessFromFileURLs != flag) {
1283+
mAllowUniversalAccessFromFileURLs = flag;
1284+
postSync();
1285+
}
1286+
}
1287+
1288+
/**
1289+
* Sets whether JavaScript running in the context of a file scheme URL
1290+
* should be allowed to access content from other file scheme URLs. To
1291+
* enable the most restrictive, and therefore secure policy, this setting
1292+
* should be disabled. Note that the value of this setting is ignored if
1293+
* the value of {@link #getAllowUniversalAccessFromFileURLs} is true.
1294+
* <p>
1295+
* The default value is true.
1296+
*
1297+
* @param flag whether JavaScript running in the context of a file scheme
1298+
* URL should be allowed to access content from other file
1299+
* scheme URLs
1300+
* @hide
1301+
*/
1302+
public synchronized void setAllowFileAccessFromFileURLs(boolean flag) {
1303+
if (mAllowFileAccessFromFileURLs != flag) {
1304+
mAllowFileAccessFromFileURLs = flag;
1305+
postSync();
1306+
}
1307+
}
1308+
12661309
/**
12671310
* Tell the WebView to use Skia's hardware accelerated rendering path
12681311
* @param flag True if the WebView should use Skia's hw-accel path
@@ -1499,6 +1542,33 @@ public synchronized boolean getJavaScriptEnabled() {
14991542
return mJavaScriptEnabled;
15001543
}
15011544

1545+
/**
1546+
* Gets whether JavaScript running in the context of a file scheme URL can
1547+
* access content from any origin. This includes access to content from
1548+
* other file scheme URLs.
1549+
*
1550+
* @return whether JavaScript running in the context of a file scheme URL
1551+
* can access content from any origin
1552+
* @see #setAllowUniversalAccessFromFileURLs
1553+
* @hide
1554+
*/
1555+
public synchronized boolean getAllowUniversalAccessFromFileURLs() {
1556+
return mAllowUniversalAccessFromFileURLs;
1557+
}
1558+
1559+
/**
1560+
* Gets whether JavaScript running in the context of a file scheme URL can
1561+
* access content from other file scheme URLs.
1562+
*
1563+
* @return whether JavaScript running in the context of a file scheme URL
1564+
* can access content from other file scheme URLs
1565+
* @see #setAllowFileAccessFromFileURLs
1566+
* @hide
1567+
*/
1568+
public synchronized boolean getAllowFileAccessFromFileURLs() {
1569+
return mAllowFileAccessFromFileURLs;
1570+
}
1571+
15021572
/**
15031573
* Return true if plugins are enabled.
15041574
* @return True if plugins are enabled.

0 commit comments

Comments
 (0)