Skip to content

Commit faed98a

Browse files
Selim GurunAndroid (Google) Code Review
authored andcommitted
Merge "Added annotations for injected accessibility objects" into jb-mr1-dev
2 parents ea4f446 + b743a23 commit faed98a

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

core/java/android/webkit/AccessibilityInjector.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import java.net.URI;
3636
import java.net.URISyntaxException;
37+
import java.util.HashMap;
3738
import java.util.Iterator;
3839
import java.util.List;
3940
import java.util.concurrent.atomic.AtomicInteger;
@@ -53,7 +54,7 @@ class AccessibilityInjector {
5354
private final WebView mWebView;
5455

5556
// The Java objects that are exposed to JavaScript.
56-
private TextToSpeech mTextToSpeech;
57+
private TextToSpeechWrapper mTextToSpeech;
5758
private CallbackHandler mCallback;
5859

5960
// Lazily loaded helper objects.
@@ -367,10 +368,7 @@ private void addTtsApis() {
367368
if (mTextToSpeech != null) {
368369
return;
369370
}
370-
371-
final String pkgName = mContext.getPackageName();
372-
373-
mTextToSpeech = new TextToSpeech(mContext, null, null, pkgName + ".**webview**", true);
371+
mTextToSpeech = new TextToSpeechWrapper(mContext);
374372
mWebView.addJavascriptInterface(mTextToSpeech, ALIAS_TTS_JS_INTERFACE);
375373
}
376374

@@ -525,6 +523,41 @@ private boolean sendActionToAndroidVox(int action, Bundle arguments) {
525523
return mCallback.performAction(mWebView, jsCode);
526524
}
527525

526+
/**
527+
* Used to protect the TextToSpeech class, only exposing the methods we want to expose.
528+
*/
529+
private static class TextToSpeechWrapper {
530+
private TextToSpeech mTextToSpeech;
531+
532+
public TextToSpeechWrapper(Context context) {
533+
final String pkgName = context.getPackageName();
534+
mTextToSpeech = new TextToSpeech(context, null, null, pkgName + ".**webview**", true);
535+
}
536+
537+
@JavascriptInterface
538+
@SuppressWarnings("unused")
539+
public boolean isSpeaking() {
540+
return mTextToSpeech.isSpeaking();
541+
}
542+
543+
@JavascriptInterface
544+
@SuppressWarnings("unused")
545+
public int speak(String text, int queueMode, HashMap<String, String> params) {
546+
return mTextToSpeech.speak(text, queueMode, params);
547+
}
548+
549+
@JavascriptInterface
550+
@SuppressWarnings("unused")
551+
public int stop() {
552+
return mTextToSpeech.stop();
553+
}
554+
555+
@SuppressWarnings("unused")
556+
protected void shutdown() {
557+
mTextToSpeech.shutdown();
558+
}
559+
}
560+
528561
/**
529562
* Exposes result interface to JavaScript.
530563
*/
@@ -621,6 +654,7 @@ private boolean waitForResultTimedLocked(int resultId) {
621654
* @param id The result id of the request as a {@link String}.
622655
* @param result The result of the request as a {@link String}.
623656
*/
657+
@JavascriptInterface
624658
@SuppressWarnings("unused")
625659
public void onResult(String id, String result) {
626660
final long resultId;

0 commit comments

Comments
 (0)