Merge "Make the URL for the JavaScript based screen-reader used by WebView configurable."

This commit is contained in:
Svetoslav Ganov
2011-12-07 14:38:05 -08:00
committed by Android (Google) Code Review
4 changed files with 60 additions and 9 deletions

View File

@@ -2779,10 +2779,10 @@ public final class Settings {
public static final String ACCESSIBILITY_SPEAK_PASSWORD = "speak_password"; public static final String ACCESSIBILITY_SPEAK_PASSWORD = "speak_password";
/** /**
* If injection of accessibility enhancing JavaScript scripts * If injection of accessibility enhancing JavaScript screen-reader
* is enabled. * is enabled.
* <p> * <p>
* Note: Accessibility injecting scripts are served by the * Note: The JavaScript based screen-reader is served by the
* Google infrastructure and enable users with disabilities to * Google infrastructure and enable users with disabilities to
* efficiantly navigate in and explore web content. * efficiantly navigate in and explore web content.
* </p> * </p>
@@ -2794,6 +2794,22 @@ public final class Settings {
public static final String ACCESSIBILITY_SCRIPT_INJECTION = public static final String ACCESSIBILITY_SCRIPT_INJECTION =
"accessibility_script_injection"; "accessibility_script_injection";
/**
* The URL for the injected JavaScript based screen-reader used
* for providing accessiblity of content in WebView.
* <p>
* Note: The JavaScript based screen-reader is served by the
* Google infrastructure and enable users with disabilities to
* efficiently navigate in and explore web content.
* </p>
* <p>
* This property represents a string value.
* </p>
* @hide
*/
public static final String ACCESSIBILITY_SCREEN_READER_URL =
"accessibility_script_injection_url";
/** /**
* Key bindings for navigation in built-in accessibility support for web content. * Key bindings for navigation in built-in accessibility support for web content.
* <p> * <p>

View File

@@ -59,6 +59,7 @@ import android.os.Message;
import android.os.StrictMode; import android.os.StrictMode;
import android.provider.Settings; import android.provider.Settings;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.EventLog; import android.util.EventLog;
import android.util.Log; import android.util.Log;
@@ -849,13 +850,12 @@ public class WebView extends AbsoluteLayout
// the alias via which accessibility JavaScript interface is exposed // the alias via which accessibility JavaScript interface is exposed
private static final String ALIAS_ACCESSIBILITY_JS_INTERFACE = "accessibility"; private static final String ALIAS_ACCESSIBILITY_JS_INTERFACE = "accessibility";
// JavaScript to inject the script chooser which will // Template for JavaScript that injects a screen-reader.
// pick the right script for the current URL private static final String ACCESSIBILITY_SCREEN_READER_JAVASCRIPT_TEMPLATE =
private static final String ACCESSIBILITY_SCRIPT_CHOOSER_JAVASCRIPT =
"javascript:(function() {" + "javascript:(function() {" +
" var chooser = document.createElement('script');" + " var chooser = document.createElement('script');" +
" chooser.type = 'text/javascript';" + " chooser.type = 'text/javascript';" +
" chooser.src = 'https://ssl.gstatic.com/accessibility/javascript/android/AndroidScriptChooser.user.js';" + " chooser.src = '%1s';" +
" document.getElementsByTagName('head')[0].appendChild(chooser);" + " document.getElementsByTagName('head')[0].appendChild(chooser);" +
" })();"; " })();";
@@ -3818,7 +3818,7 @@ public class WebView extends AbsoluteLayout
if (onDeviceScriptInjectionEnabled) { if (onDeviceScriptInjectionEnabled) {
ensureAccessibilityScriptInjectorInstance(false); ensureAccessibilityScriptInjectorInstance(false);
// neither script injected nor script injection opted out => we inject // neither script injected nor script injection opted out => we inject
loadUrl(ACCESSIBILITY_SCRIPT_CHOOSER_JAVASCRIPT); loadUrl(getScreenReaderInjectingJs());
// TODO: Set this flag after successfull script injection. Maybe upon injection // TODO: Set this flag after successfull script injection. Maybe upon injection
// the chooser should update the meta tag and we check it to declare success // the chooser should update the meta tag and we check it to declare success
mAccessibilityScriptInjected = true; mAccessibilityScriptInjected = true;
@@ -3832,7 +3832,7 @@ public class WebView extends AbsoluteLayout
} else if (axsParameterValue == ACCESSIBILITY_SCRIPT_INJECTION_PROVIDED) { } else if (axsParameterValue == ACCESSIBILITY_SCRIPT_INJECTION_PROVIDED) {
ensureAccessibilityScriptInjectorInstance(false); ensureAccessibilityScriptInjectorInstance(false);
// the URL provides accessibility but we still need to add our generic script // the URL provides accessibility but we still need to add our generic script
loadUrl(ACCESSIBILITY_SCRIPT_CHOOSER_JAVASCRIPT); loadUrl(getScreenReaderInjectingJs());
} else { } else {
Log.e(LOGTAG, "Unknown URL value for the \"axs\" URL parameter: " + axsParameterValue); Log.e(LOGTAG, "Unknown URL value for the \"axs\" URL parameter: " + axsParameterValue);
} }
@@ -3853,6 +3853,17 @@ public class WebView extends AbsoluteLayout
} }
} }
/**
* Gets JavaScript that injects a screen-reader.
*
* @return The JavaScript snippet.
*/
private String getScreenReaderInjectingJs() {
String screenReaderUrl = Settings.Secure.getString(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL);
return String.format(ACCESSIBILITY_SCREEN_READER_JAVASCRIPT_TEMPLATE, screenReaderUrl);
}
/** /**
* Gets the "axs" URL parameter value. * Gets the "axs" URL parameter value.
* *

View File

@@ -115,6 +115,11 @@
0x200000038=0x03000701:0x03010701:0x03020701; 0x200000038=0x03000701:0x03010701:0x03020701;
</string> </string>
<!-- Default for Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION_URL -->
<string name="def_accessibility_screen_reader_url" translatable="false">
https://ssl.gstatic.com/accessibility/javascript/android/AndroidScriptChooser.user.js
</string>
<!-- Default for Settings.Secure.TOUCH_EXPLORATION_ENABLED --> <!-- Default for Settings.Secure.TOUCH_EXPLORATION_ENABLED -->
<bool name="def_touch_exploration_enabled">false</bool> <bool name="def_touch_exploration_enabled">false</bool>

View File

@@ -63,7 +63,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
// database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
// is properly propagated through your change. Not doing so will result in a loss of user // is properly propagated through your change. Not doing so will result in a loss of user
// settings. // settings.
private static final int DATABASE_VERSION = 73; private static final int DATABASE_VERSION = 74;
private Context mContext; private Context mContext;
@@ -986,6 +986,22 @@ public class DatabaseHelper extends SQLiteOpenHelper {
upgradeVersion = 73; upgradeVersion = 73;
} }
if (upgradeVersion == 73) {
// URL from which WebView loads a JavaScript based screen-reader.
db.beginTransaction();
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
R.string.def_accessibility_screen_reader_url);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (stmt != null) stmt.close();
}
upgradeVersion = 74;
}
// *** Remember to update DATABASE_VERSION above! // *** Remember to update DATABASE_VERSION above!
if (upgradeVersion != currentVersion) { if (upgradeVersion != currentVersion) {
@@ -1526,6 +1542,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
R.bool.def_accessibility_speak_password); R.bool.def_accessibility_speak_password);
loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
R.string.def_accessibility_screen_reader_url);
} finally { } finally {
if (stmt != null) stmt.close(); if (stmt != null) stmt.close();
} }