Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1609)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java

Issue 2919113002: [TTS] Fix crash calling KitKat+ API without check. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
index 39f330c99f92492b1a48da8c719ef7f016b82c1a..e8b55e0754770d82955b7be825ce3e0538370b50 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.contextualsearch;
import android.annotation.SuppressLint;
+import android.os.Build;
import android.text.TextUtils;
import org.chromium.base.annotations.CalledByNative;
@@ -278,7 +279,7 @@ public abstract class ContextualSearchContext {
private int findWordStartOffset(String text, int initial) {
Theresa 2017/06/02 21:51:42 This is just used to generate a ranker signal for
Donn Denman 2017/06/02 22:00:42 Correct, so it's non-critical for the feature.
// Scan before, aborting if we hit any ideographic letter.
for (int offset = initial - 1; offset >= 0; offset--) {
- if (isIdeographicAtIndex(text, offset)) return INVALID_OFFSET;
+ if (isUnreliableWordBreakAtIndex(text, offset)) return INVALID_OFFSET;
if (isWordBreakAtIndex(text, offset)) {
// The start of the word is after this word break.
@@ -301,7 +302,7 @@ public abstract class ContextualSearchContext {
private int findWordEndOffset(String text, int initial) {
// Scan after, aborting if we hit any CJKN letter.
for (int offset = initial; offset < text.length(); offset++) {
- if (isIdeographicAtIndex(text, offset)) return INVALID_OFFSET;
+ if (isUnreliableWordBreakAtIndex(text, offset)) return INVALID_OFFSET;
if (isWordBreakAtIndex(text, offset)) {
// The end of the word is the offset of this word break.
@@ -312,12 +313,17 @@ public abstract class ContextualSearchContext {
}
/**
- * @return Whether the character at the given index in the text is "Ideographic" (as in CJKV
- * languages), which means there may not be reliable word breaks.
+ * @return Whether the character at the given index in the text might be in an alphabet that has
+ * unreliable word breaks, such as CKJV languages. Returns {@code true} on older
+ * platforms where we can't know for sure.
*/
@SuppressLint("NewApi")
- private boolean isIdeographicAtIndex(String text, int index) {
- return Character.isIdeographic(text.charAt(index));
+ private boolean isUnreliableWordBreakAtIndex(String text, int index) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ return Character.isIdeographic(text.charAt(index));
+ } else {
+ return true; // Assume the worst if we can't check.
+ }
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698