Skip to content

Commit caf7f3d

Browse files
Selim GurunAndroid (Google) Code Review
authored andcommitted
Merge "Add websettings API for file origin policy."
2 parents f0c4c65 + 0ea6dad commit caf7f3d

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
@@ -26033,10 +26033,12 @@ package android.webkit {
2603326033
method public void setMimeType(java.lang.String);
2603426034
}
2603526035

26036-
public class WebSettings {
26036+
public abstract class WebSettings {
2603726037
method public boolean enableSmoothTransition();
2603826038
method public boolean getAllowContentAccess();
2603926039
method public boolean getAllowFileAccess();
26040+
method public abstract boolean getAllowFileAccessFromFileURLs();
26041+
method public abstract boolean getAllowUniversalAccessFromFileURLs();
2604026042
method public synchronized boolean getBlockNetworkImage();
2604126043
method public synchronized boolean getBlockNetworkLoads();
2604226044
method public boolean getBuiltInZoomControls();
@@ -26078,6 +26080,8 @@ package android.webkit {
2607826080
method public synchronized java.lang.String getUserAgentString();
2607926081
method public void setAllowContentAccess(boolean);
2608026082
method public void setAllowFileAccess(boolean);
26083+
method public abstract void setAllowFileAccessFromFileURLs(boolean);
26084+
method public abstract void setAllowUniversalAccessFromFileURLs(boolean);
2608126085
method public synchronized void setAppCacheEnabled(boolean);
2608226086
method public synchronized void setAppCacheMaxSize(long);
2608326087
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 {
@@ -770,6 +771,29 @@ public synchronized void setJavaScriptEnabled(boolean flag) {
770771
throw new MustOverrideException();
771772
}
772773

774+
/**
775+
* Configure scripting (such as XmlHttpRequest) access from file scheme URLs
776+
* to any origin. Note, calling this method with a true argument value also
777+
* implies calling setAllowFileAccessFromFileURLs with a true. The default
778+
* value is false for API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
779+
* and higher and true otherwise.
780+
*
781+
. * @param flag True if the WebView should allow scripting access from file
782+
* scheme URLs to any origin
783+
*/
784+
public abstract void setAllowUniversalAccessFromFileURLs(boolean flag);
785+
786+
/**
787+
* Configure scripting (such as XmlHttpRequest) access from file scheme URLs
788+
* to file origin. The default value is false for API level
789+
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and higher and true
790+
* otherwise.
791+
*
792+
* @param flag True if the WebView should allow scripting access from file
793+
* scheme URLs to file origin
794+
*/
795+
public abstract void setAllowFileAccessFromFileURLs(boolean flag);
796+
773797
/**
774798
* Tell the WebView to enable plugins.
775799
* @param flag True if the WebView should load plugins.
@@ -911,6 +935,26 @@ public synchronized boolean getJavaScriptEnabled() {
911935
throw new MustOverrideException();
912936
}
913937

938+
/**
939+
* Return true if scripting access {see @setAllowUniversalAccessFromFileURLs} from
940+
* file URLs to any origin is enabled. The default value is false for API level
941+
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and higher and true otherwise.
942+
*
943+
* @return True if the WebView allows scripting access from file scheme requests
944+
* to any origin
945+
*/
946+
public abstract boolean getAllowUniversalAccessFromFileURLs();
947+
948+
/**
949+
* Return true if scripting access {see @setAllowFileAccessFromFileURLs} from file
950+
* URLs to file origin is enabled. The default value is false for API level
951+
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and higher, and true otherwise.
952+
*
953+
* @return True if the WebView allows scripting access from file scheme requests
954+
* to file origin
955+
*/
956+
public abstract boolean getAllowFileAccessFromFileURLs();
957+
914958
/**
915959
* Return true if plugins are enabled.
916960
* @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)