Commit ced2f3a3 authored by mnaganov@chromium.org's avatar mnaganov@chromium.org

[Android] Implement WebSettings.{get|set}Allow{Content|File}Access.

This is as much as we can put upstream now.

Review URL: https://chromiumcodereview.appspot.com/10827380

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152318 0039d316-1c4b-4281-b951-d872f2087c98
parent 294d77c0
...@@ -7,15 +7,46 @@ package org.chromium.base.test; ...@@ -7,15 +7,46 @@ package org.chromium.base.test;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader; import java.io.Reader;
import java.io.Writer;
import java.util.Arrays; import java.util.Arrays;
/** /**
* Utility class for dealing with files for test. * Utility class for dealing with files for test.
*/ */
public class TestFileUtil { public class TestFileUtil {
public static void createNewHtmlFile(String name, String title, String body)
throws IOException {
File file = new File(name);
if (!file.createNewFile()) {
throw new IOException("File \"" + name + "\" already exists");
}
Writer writer = null;
try {
writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
writer.write("<html><meta charset=\"UTF-8\" />" +
"<head><title>" + title + "</title></head>" +
"<body>" +
(body != null ? body : "") +
"</body>" +
"</html>");
} finally {
if (writer != null) {
writer.close();
}
}
}
public static void deleteFile(String name) {
File file = new File(name);
file.delete();
}
/** /**
* @param fileName the file to read in. * @param fileName the file to read in.
* @param sizeLimit cap on the file size: will throw an exception if exceeded * @param sizeLimit cap on the file size: will throw an exception if exceeded
......
...@@ -74,6 +74,10 @@ struct ContentSettings::FieldIds { ...@@ -74,6 +74,10 @@ struct ContentSettings::FieldIds {
GetFieldID(env, clazz, "mJavaScriptCanOpenWindowsAutomatically", "Z"); GetFieldID(env, clazz, "mJavaScriptCanOpenWindowsAutomatically", "Z");
dom_storage_enabled = dom_storage_enabled =
GetFieldID(env, clazz, "mDomStorageEnabled", "Z"); GetFieldID(env, clazz, "mDomStorageEnabled", "Z");
allow_file_url_access =
GetFieldID(env, clazz, "mAllowFileUrlAccess", "Z");
allow_content_url_access =
GetFieldID(env, clazz, "mAllowContentUrlAccess", "Z");
} }
// Field ids // Field ids
...@@ -95,6 +99,8 @@ struct ContentSettings::FieldIds { ...@@ -95,6 +99,8 @@ struct ContentSettings::FieldIds {
jfieldID allow_file_access_from_file_urls; jfieldID allow_file_access_from_file_urls;
jfieldID java_script_can_open_windows_automatically; jfieldID java_script_can_open_windows_automatically;
jfieldID dom_storage_enabled; jfieldID dom_storage_enabled;
jfieldID allow_file_url_access;
jfieldID allow_content_url_access;
}; };
ContentSettings::ContentSettings(JNIEnv* env, ContentSettings::ContentSettings(JNIEnv* env,
......
...@@ -82,6 +82,8 @@ public class ContentSettings { ...@@ -82,6 +82,8 @@ public class ContentSettings {
private boolean mJavaScriptCanOpenWindowsAutomatically = false; private boolean mJavaScriptCanOpenWindowsAutomatically = false;
private PluginState mPluginState = PluginState.OFF; private PluginState mPluginState = PluginState.OFF;
private boolean mDomStorageEnabled = false; private boolean mDomStorageEnabled = false;
private boolean mAllowFileUrlAccess = true;
private boolean mAllowContentUrlAccess = true;
// Not accessed by the native side. // Not accessed by the native side.
private String mDefaultUserAgent = ""; private String mDefaultUserAgent = "";
...@@ -301,6 +303,51 @@ public class ContentSettings { ...@@ -301,6 +303,51 @@ public class ContentSettings {
return mDisplayZoomControls; return mDisplayZoomControls;
} }
/**
* Enables or disables file access within ContentView. File access is enabled by
* default. Note that this enables or disables file system access only.
* Assets and resources are still accessible using file:///android_asset and
* file:///android_res.
*/
public synchronized void setAllowFileAccess(boolean allow) {
assert mCanModifySettings;
if (mAllowFileUrlAccess != allow) {
mAllowFileUrlAccess = allow;
sendSyncMessage();
}
}
/**
* Gets whether this ContentView supports file access.
*
* @see #setAllowFileAccess
*/
public synchronized boolean getAllowFileAccess() {
return mAllowFileUrlAccess;
}
/**
* Enables or disables content URL access within ContentView. Content URL
* access allows ContentView to load content from a content provider installed
* in the system. The default is enabled.
*/
public synchronized void setAllowContentAccess(boolean allow) {
assert mCanModifySettings;
if (mAllowContentUrlAccess != allow) {
mAllowContentUrlAccess = allow;
sendSyncMessage();
}
}
/**
* Gets whether this ContentView supports content URL access.
*
* @see #setAllowContentAccess
*/
public synchronized boolean getAllowContentAccess() {
return mAllowContentUrlAccess;
}
boolean supportsMultiTouchZoom() { boolean supportsMultiTouchZoom() {
return mSupportZoom && mBuiltInZoomControls; return mSupportZoom && mBuiltInZoomControls;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment