Skip to content

Commit 0ea6dad

Browse files
author
Selim Gurun
committed
Add websettings API for file origin policy.
Bug: 6212665 Add the API and change the default behavior for Jelly Bean+. Change-Id: I9a83f510675023c36e2e72c4a69ad082d8124a23
1 parent 3d275af commit 0ea6dad

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

api/current.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25470,10 +25470,12 @@ package android.webkit {
2547025470
method public void setMimeType(java.lang.String);
2547125471
}
2547225472

25473-
public class WebSettings {
25473+
public abstract class WebSettings {
2547425474
method public boolean enableSmoothTransition();
2547525475
method public boolean getAllowContentAccess();
2547625476
method public boolean getAllowFileAccess();
25477+
method public abstract boolean getAllowFileAccessFromFileURLs();
25478+
method public abstract boolean getAllowUniversalAccessFromFileURLs();
2547725479
method public synchronized boolean getBlockNetworkImage();
2547825480
method public synchronized boolean getBlockNetworkLoads();
2547925481
method public boolean getBuiltInZoomControls();
@@ -25515,6 +25517,8 @@ package android.webkit {
2551525517
method public synchronized java.lang.String getUserAgentString();
2551625518
method public void setAllowContentAccess(boolean);
2551725519
method public void setAllowFileAccess(boolean);
25520+
method public abstract void setAllowFileAccessFromFileURLs(boolean);
25521+
method public abstract void setAllowUniversalAccessFromFileURLs(boolean);
2551825522
method public synchronized void setAppCacheEnabled(boolean);
2551925523
method public synchronized void setAppCacheMaxSize(long);
2552025524
method public synchronized void setAppCachePath(java.lang.String);

core/java/android/webkit/WebSettings.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.webkit;
1818

1919
import android.os.Message;
20+
import android.os.Build;
2021

2122
/**
2223
* Manages settings state for a WebView. When a WebView is first created, it
@@ -29,7 +30,7 @@
2930
// This is (effectively) an abstract base class; concrete WebViewProviders must
3031
// create a class derived from this, and return an instance of it in the
3132
// WebViewProvider.getWebSettingsProvider() method implementation.
32-
public class WebSettings {
33+
public abstract class WebSettings {
3334
// TODO: Remove MustOverrideException and make all methods throwing it abstract instead;
3435
// needs API file update.
3536
private static class MustOverrideException extends RuntimeException {
@@ -749,6 +750,29 @@ public synchronized void setJavaScriptEnabled(boolean flag) {
749750
throw new MustOverrideException();
750751
}
751752

753+
/**
754+
* Configure scripting (such as XmlHttpRequest) access from file scheme URLs
755+
* to any origin. Note, calling this method with a true argument value also
756+
* implies calling setAllowFileAccessFromFileURLs with a true. The default
757+
* value is false for API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
758+
* and higher and true otherwise.
759+
*
760+
. * @param flag True if the WebView should allow scripting access from file
761+
* scheme URLs to any origin
762+
*/
763+
public abstract void setAllowUniversalAccessFromFileURLs(boolean flag);
764+
765+
/**
766+
* Configure scripting (such as XmlHttpRequest) access from file scheme URLs
767+
* to file origin. The default value is false for API level
768+
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and higher and true
769+
* otherwise.
770+
*
771+
* @param flag True if the WebView should allow scripting access from file
772+
* scheme URLs to file origin
773+
*/
774+
public abstract void setAllowFileAccessFromFileURLs(boolean flag);
775+
752776
/**
753777
* Tell the WebView to enable plugins.
754778
* @param flag True if the WebView should load plugins.
@@ -890,6 +914,26 @@ public synchronized boolean getJavaScriptEnabled() {
890914
throw new MustOverrideException();
891915
}
892916

917+
/**
918+
* Return true if scripting access {see @setAllowUniversalAccessFromFileURLs} from
919+
* file URLs to any origin is enabled. The default value is false for API level
920+
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and higher and true otherwise.
921+
*
922+
* @return True if the WebView allows scripting access from file scheme requests
923+
* to any origin
924+
*/
925+
public abstract boolean getAllowUniversalAccessFromFileURLs();
926+
927+
/**
928+
* Return true if scripting access {see @setAllowFileAccessFromFileURLs} from file
929+
* URLs to file origin is enabled. The default value is false for API level
930+
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and higher, and true otherwise.
931+
*
932+
* @return True if the WebView allows scripting access from file scheme requests
933+
* to file origin
934+
*/
935+
public abstract boolean getAllowFileAccessFromFileURLs();
936+
893937
/**
894938
* Return true if plugins are enabled.
895939
* @return True if plugins are enabled.

core/java/android/webkit/WebSettingsClassic.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public class WebSettingsClassic extends WebSettings {
7272
private boolean mBlockNetworkImage = false;
7373
private boolean mBlockNetworkLoads;
7474
private boolean mJavaScriptEnabled = false;
75+
private boolean mAllowUniversalAccessFromFileURLs = false;
76+
private boolean mAllowFileAccessFromFileURLs = false;
7577
private boolean mHardwareAccelSkia = false;
7678
private boolean mShowVisualIndicator = false;
7779
private PluginState mPluginState = PluginState.OFF;
@@ -286,6 +288,13 @@ private synchronized boolean sendMessage(Message msg) {
286288
mBlockNetworkLoads = mContext.checkPermission(
287289
"android.permission.INTERNET", android.os.Process.myPid(),
288290
android.os.Process.myUid()) != PackageManager.PERMISSION_GRANTED;
291+
292+
// SDK specific settings. See issue 6212665
293+
if (mContext.getApplicationInfo().targetSdkVersion <
294+
Build.VERSION_CODES.JELLY_BEAN) {
295+
mAllowUniversalAccessFromFileURLs = true;
296+
mAllowFileAccessFromFileURLs = true;
297+
}
289298
}
290299

291300
private static final String ACCEPT_LANG_FOR_US_LOCALE = "en-US";
@@ -1100,6 +1109,28 @@ public synchronized void setJavaScriptEnabled(boolean flag) {
11001109
}
11011110
}
11021111

1112+
/**
1113+
* @see android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs
1114+
*/
1115+
@Override
1116+
public synchronized void setAllowUniversalAccessFromFileURLs(boolean flag) {
1117+
if (mAllowUniversalAccessFromFileURLs != flag) {
1118+
mAllowUniversalAccessFromFileURLs = flag;
1119+
postSync();
1120+
}
1121+
}
1122+
1123+
/**
1124+
* @see android.webkit.WebSettings#setAllowFileAccessFromFileURLs
1125+
*/
1126+
@Override
1127+
public synchronized void setAllowFileAccessFromFileURLs(boolean flag) {
1128+
if (mAllowFileAccessFromFileURLs != flag) {
1129+
mAllowFileAccessFromFileURLs = flag;
1130+
postSync();
1131+
}
1132+
}
1133+
11031134
/**
11041135
* Tell the WebView to use Skia's hardware accelerated rendering path
11051136
* @param flag True if the WebView should use Skia's hw-accel path
@@ -1323,6 +1354,22 @@ public synchronized boolean getJavaScriptEnabled() {
13231354
return mJavaScriptEnabled;
13241355
}
13251356

1357+
/**
1358+
* @see android.webkit.WebSettings#getAllowUniversalFileAccessFromFileURLs
1359+
*/
1360+
@Override
1361+
public synchronized boolean getAllowUniversalAccessFromFileURLs() {
1362+
return mAllowUniversalAccessFromFileURLs;
1363+
}
1364+
1365+
/**
1366+
* @see android.webkit.WebSettings#getAllowFileAccessFromFileURLs
1367+
*/
1368+
@Override
1369+
public synchronized boolean getAllowFileAccessFromFileURLs() {
1370+
return mAllowFileAccessFromFileURLs;
1371+
}
1372+
13261373
/**
13271374
* @see android.webkit.WebSettings#getPluginsEnabled()
13281375
*/

0 commit comments

Comments
 (0)