Commit 99bdc253 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Add utility function to convert C++ SuggestionAnswer to java.

This removes the duplicate parsing logic in Java.

BUG=

Change-Id: If43303f6a7bc708186601bdaca0e876c6c3ceee4
Reviewed-on: https://chromium-review.googlesource.com/c/1343080
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609774}
parent 346037e2
...@@ -270,6 +270,7 @@ android_library("chrome_java") { ...@@ -270,6 +270,7 @@ android_library("chrome_java") {
"//components/module_installer/android:module_installer_java", "//components/module_installer/android:module_installer_java",
"//components/navigation_interception/android:navigation_interception_java", "//components/navigation_interception/android:navigation_interception_java",
"//components/offline_items_collection/core:core_java", "//components/offline_items_collection/core:core_java",
"//components/omnibox/browser:browser_java",
"//components/payments/content/android:java", "//components/payments/content/android:java",
"//components/payments/mojom:mojom_java", "//components/payments/mojom:mojom_java",
"//components/policy/android:policy_java", "//components/policy/android:policy_java",
...@@ -367,8 +368,6 @@ android_library("chrome_java") { ...@@ -367,8 +368,6 @@ android_library("chrome_java") {
"//components/ntp_snippets:ntp_snippets_java_enums_srcjar", "//components/ntp_snippets:ntp_snippets_java_enums_srcjar",
"//components/ntp_tiles:ntp_tiles_enums_java", "//components/ntp_tiles:ntp_tiles_enums_java",
"//components/offline_pages/core:offline_page_model_enums_java", "//components/offline_pages/core:offline_page_model_enums_java",
"//components/omnibox/browser:autocomplete_match_javagen",
"//components/omnibox/browser:autocomplete_match_type_javagen",
"//components/search_engines:search_engine_type_java", "//components/search_engines:search_engine_type_java",
"//components/security_state/core:security_state_enums_java", "//components/security_state/core:security_state_enums_java",
"//components/signin/core/browser:investigated_scenario_java", "//components/signin/core/browser:investigated_scenario_java",
...@@ -663,6 +662,7 @@ android_library("chrome_test_java") { ...@@ -663,6 +662,7 @@ android_library("chrome_test_java") {
"//components/navigation_interception/android:navigation_interception_java", "//components/navigation_interception/android:navigation_interception_java",
"//components/offline_items_collection/core:core_java", "//components/offline_items_collection/core:core_java",
"//components/offline_pages/core/prefetch:offline_prefetch_proto_java", "//components/offline_pages/core/prefetch:offline_prefetch_proto_java",
"//components/omnibox/browser:browser_java",
"//components/payments/content/android:java", "//components/payments/content/android:java",
"//components/payments/mojom:mojom_java", "//components/payments/mojom:mojom_java",
"//components/policy/android:policy_java", "//components/policy/android:policy_java",
......
...@@ -15,6 +15,7 @@ include_rules = [ ...@@ -15,6 +15,7 @@ include_rules = [
"+components/module_installer/android/java/src/org/chromium/components/module_installer", "+components/module_installer/android/java/src/org/chromium/components/module_installer",
"+components/navigation_interception", "+components/navigation_interception",
"+components/offline_items_collection/core/android/java", "+components/offline_items_collection/core/android/java",
"+components/omnibox/browser/android/java",
"+components/payments/content/android/java/src/org/chromium/components/payments", "+components/payments/content/android/java/src/org/chromium/components/payments",
"+components/sync/android/java/src/org/chromium/components/sync", "+components/sync/android/java/src/org/chromium/components/sync",
"+components/web_restrictions", "+components/web_restrictions",
......
...@@ -18,6 +18,8 @@ import android.util.Log; ...@@ -18,6 +18,8 @@ import android.util.Log;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.components.omnibox.AnswerTextType;
import org.chromium.components.omnibox.SuggestionAnswer;
import java.util.List; import java.util.List;
...@@ -28,28 +30,6 @@ import java.util.List; ...@@ -28,28 +30,6 @@ import java.util.List;
class AnswerTextBuilder { class AnswerTextBuilder {
private static final String TAG = "AnswerTextBuilder"; private static final String TAG = "AnswerTextBuilder";
// Types, sizes and colors specified at http://goto.google.com/ais_api.
// Deprecated: ANSWERS_ANSWER_TEXT_TYPE = 1;
// Deprecated: ANSWERS_HEADLINE_TEXT_TYPE = 2;
private static final int ANSWERS_TOP_ALIGNED_TEXT_TYPE = 3;
// Deprecated: ANSWERS_DESCRIPTION_TEXT_TYPE = 4;
private static final int ANSWERS_DESCRIPTION_TEXT_NEGATIVE_TYPE = 5;
private static final int ANSWERS_DESCRIPTION_TEXT_POSITIVE_TYPE = 6;
// Deprecated: ANSWERS_MORE_INFO_TEXT_TYPE = 7;
private static final int ANSWERS_SUGGESTION_TEXT_TYPE = 8;
// Deprecated: ANSWERS_SUGGESTION_TEXT_POSITIVE_TYPE = 9;
// Deprecated: ANSWERS_SUGGESTION_TEXT_NEGATIVE_TYPE = 10;
// Deprecated: ANSWERS_SUGGESTION_LINK_COLOR_TYPE = 11;
// Deprecated: ANSWERS_STATUS_TEXT_TYPE = 12;
private static final int ANSWERS_PERSONALIZED_SUGGESTION_TEXT_TYPE = 13;
// Deprecated: ANSWERS_IMMERSIVE_DESCRIPTION_TEXT = 14;
// Deprecated: ANSWERS_DATE_TEXT = 15;
// Deprecated: ANSWERS_PREVIEW_TEXT = 16;
private static final int ANSWERS_ANSWER_TEXT_MEDIUM_TYPE = 17;
private static final int ANSWERS_ANSWER_TEXT_LARGE_TYPE = 18;
private static final int ANSWERS_SECONDARY_TEXT_SMALL_TYPE = 19;
private static final int ANSWERS_SECONDARY_TEXT_MEDIUM_TYPE = 20;
private static final int ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP = 12; private static final int ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP = 12;
private static final int ANSWERS_DESCRIPTION_TEXT_NEGATIVE_SIZE_SP = 16; private static final int ANSWERS_DESCRIPTION_TEXT_NEGATIVE_SIZE_SP = 16;
private static final int ANSWERS_DESCRIPTION_TEXT_POSITIVE_SIZE_SP = 16; private static final int ANSWERS_DESCRIPTION_TEXT_POSITIVE_SIZE_SP = 16;
...@@ -156,7 +136,7 @@ class AnswerTextBuilder { ...@@ -156,7 +136,7 @@ class AnswerTextBuilder {
ForegroundColorSpan colorSpan = new ForegroundColorSpan(getAnswerTextColor(type)); ForegroundColorSpan colorSpan = new ForegroundColorSpan(getAnswerTextColor(type));
builder.setSpan(colorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(colorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (type == ANSWERS_TOP_ALIGNED_TEXT_TYPE) { if (type == AnswerTextType.TOP_ALIGNED) {
TopAlignedSpan topAlignedSpan = TopAlignedSpan topAlignedSpan =
new TopAlignedSpan(ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP, maxTextHeightSp, density); new TopAlignedSpan(ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP, maxTextHeightSp, density);
builder.setSpan(topAlignedSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(topAlignedSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
...@@ -168,25 +148,25 @@ class AnswerTextBuilder { ...@@ -168,25 +148,25 @@ class AnswerTextBuilder {
* *
* @param type The answer type as specified at http://goto.google.com/ais_api. * @param type The answer type as specified at http://goto.google.com/ais_api.
*/ */
private static int getAnswerTextSizeSp(int type) { private static int getAnswerTextSizeSp(@AnswerTextType int type) {
switch (type) { switch (type) {
case ANSWERS_TOP_ALIGNED_TEXT_TYPE: case AnswerTextType.TOP_ALIGNED:
return ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP; return ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP;
case ANSWERS_DESCRIPTION_TEXT_NEGATIVE_TYPE: case AnswerTextType.DESCRIPTION_NEGATIVE:
return ANSWERS_DESCRIPTION_TEXT_NEGATIVE_SIZE_SP; return ANSWERS_DESCRIPTION_TEXT_NEGATIVE_SIZE_SP;
case ANSWERS_DESCRIPTION_TEXT_POSITIVE_TYPE: case AnswerTextType.DESCRIPTION_POSITIVE:
return ANSWERS_DESCRIPTION_TEXT_POSITIVE_SIZE_SP; return ANSWERS_DESCRIPTION_TEXT_POSITIVE_SIZE_SP;
case ANSWERS_SUGGESTION_TEXT_TYPE: case AnswerTextType.SUGGESTION:
return ANSWERS_SUGGESTION_TEXT_SIZE_SP; return ANSWERS_SUGGESTION_TEXT_SIZE_SP;
case ANSWERS_PERSONALIZED_SUGGESTION_TEXT_TYPE: case AnswerTextType.PERSONALIZED_SUGGESTION:
return ANSWERS_PERSONALIZED_SUGGESTION_TEXT_SIZE_SP; return ANSWERS_PERSONALIZED_SUGGESTION_TEXT_SIZE_SP;
case ANSWERS_ANSWER_TEXT_MEDIUM_TYPE: case AnswerTextType.ANSWER_TEXT_MEDIUM:
return ANSWERS_ANSWER_TEXT_MEDIUM_SIZE_SP; return ANSWERS_ANSWER_TEXT_MEDIUM_SIZE_SP;
case ANSWERS_ANSWER_TEXT_LARGE_TYPE: case AnswerTextType.ANSWER_TEXT_LARGE:
return ANSWERS_ANSWER_TEXT_LARGE_SIZE_SP; return ANSWERS_ANSWER_TEXT_LARGE_SIZE_SP;
case ANSWERS_SECONDARY_TEXT_SMALL_TYPE: case AnswerTextType.SUGGESTION_SECONDARY_TEXT_SMALL:
return ANSWERS_SECONDARY_TEXT_SMALL_SIZE_SP; return ANSWERS_SECONDARY_TEXT_SMALL_SIZE_SP;
case ANSWERS_SECONDARY_TEXT_MEDIUM_TYPE: case AnswerTextType.SUGGESTION_SECONDARY_TEXT_MEDIUM:
return ANSWERS_SECONDARY_TEXT_MEDIUM_SIZE_SP; return ANSWERS_SECONDARY_TEXT_MEDIUM_SIZE_SP;
default: default:
Log.w(TAG, "Unknown answer type: " + type); Log.w(TAG, "Unknown answer type: " + type);
...@@ -199,28 +179,28 @@ class AnswerTextBuilder { ...@@ -199,28 +179,28 @@ class AnswerTextBuilder {
* *
* @param type The answer type as specified at http://goto.google.com/ais_api. * @param type The answer type as specified at http://goto.google.com/ais_api.
*/ */
private static int getAnswerTextColor(int type) { private static int getAnswerTextColor(@AnswerTextType int type) {
Resources resources = ContextUtils.getApplicationContext().getResources(); Resources resources = ContextUtils.getApplicationContext().getResources();
switch (type) { switch (type) {
case ANSWERS_DESCRIPTION_TEXT_NEGATIVE_TYPE: case AnswerTextType.DESCRIPTION_NEGATIVE:
return ApiCompatibilityUtils.getColor( return ApiCompatibilityUtils.getColor(
resources, R.color.answers_description_text_negative); resources, R.color.answers_description_text_negative);
case ANSWERS_DESCRIPTION_TEXT_POSITIVE_TYPE: case AnswerTextType.DESCRIPTION_POSITIVE:
return ApiCompatibilityUtils.getColor( return ApiCompatibilityUtils.getColor(
resources, R.color.answers_description_text_positive); resources, R.color.answers_description_text_positive);
case ANSWERS_SUGGESTION_TEXT_TYPE: case AnswerTextType.SUGGESTION:
return ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text); return ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text);
case ANSWERS_PERSONALIZED_SUGGESTION_TEXT_TYPE: case AnswerTextType.PERSONALIZED_SUGGESTION:
return ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text); return ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text);
case ANSWERS_TOP_ALIGNED_TEXT_TYPE: case AnswerTextType.TOP_ALIGNED:
case ANSWERS_ANSWER_TEXT_MEDIUM_TYPE: case AnswerTextType.ANSWER_TEXT_MEDIUM:
case ANSWERS_ANSWER_TEXT_LARGE_TYPE: case AnswerTextType.ANSWER_TEXT_LARGE:
case ANSWERS_SECONDARY_TEXT_SMALL_TYPE: case AnswerTextType.SUGGESTION_SECONDARY_TEXT_SMALL:
case ANSWERS_SECONDARY_TEXT_MEDIUM_TYPE: case AnswerTextType.SUGGESTION_SECONDARY_TEXT_MEDIUM:
return ApiCompatibilityUtils.getColor(resources, R.color.answers_answer_text); return ApiCompatibilityUtils.getColor(resources, R.color.answers_answer_text);
default: default:
......
...@@ -16,6 +16,7 @@ import org.chromium.chrome.browser.omnibox.LocationBarVoiceRecognitionHandler.Vo ...@@ -16,6 +16,7 @@ import org.chromium.chrome.browser.omnibox.LocationBarVoiceRecognitionHandler.Vo
import org.chromium.chrome.browser.omnibox.OmniboxSuggestionType; import org.chromium.chrome.browser.omnibox.OmniboxSuggestionType;
import org.chromium.chrome.browser.omnibox.suggestions.OmniboxSuggestion.MatchClassification; import org.chromium.chrome.browser.omnibox.suggestions.OmniboxSuggestion.MatchClassification;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.omnibox.SuggestionAnswer;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -293,8 +294,8 @@ public class AutocompleteController { ...@@ -293,8 +294,8 @@ public class AutocompleteController {
int relevance, int transition, String contents, int[] contentClassificationOffsets, int relevance, int transition, String contents, int[] contentClassificationOffsets,
int[] contentClassificationStyles, String description, int[] contentClassificationStyles, String description,
int[] descriptionClassificationOffsets, int[] descriptionClassificationStyles, int[] descriptionClassificationOffsets, int[] descriptionClassificationStyles,
String answerContents, String answerType, String fillIntoEdit, String url, SuggestionAnswer answer, String fillIntoEdit, String url, boolean isStarred,
boolean isStarred, boolean isDeletable) { boolean isDeletable) {
assert contentClassificationOffsets.length == contentClassificationStyles.length; assert contentClassificationOffsets.length == contentClassificationStyles.length;
List<MatchClassification> contentClassifications = new ArrayList<>(); List<MatchClassification> contentClassifications = new ArrayList<>();
for (int i = 0; i < contentClassificationOffsets.length; i++) { for (int i = 0; i < contentClassificationOffsets.length; i++) {
...@@ -310,8 +311,8 @@ public class AutocompleteController { ...@@ -310,8 +311,8 @@ public class AutocompleteController {
} }
return new OmniboxSuggestion(nativeType, isSearchType, relevance, transition, contents, return new OmniboxSuggestion(nativeType, isSearchType, relevance, transition, contents,
contentClassifications, description, descriptionClassifications, answerContents, contentClassifications, description, descriptionClassifications, answer,
answerType, fillIntoEdit, url, isStarred, isDeletable); fillIntoEdit, url, isStarred, isDeletable);
} }
/** /**
......
...@@ -42,6 +42,7 @@ import org.chromium.chrome.browser.omnibox.suggestions.SuggestionViewProperties. ...@@ -42,6 +42,7 @@ import org.chromium.chrome.browser.omnibox.suggestions.SuggestionViewProperties.
import org.chromium.chrome.browser.omnibox.suggestions.SuggestionViewProperties.SuggestionTextContainer; import org.chromium.chrome.browser.omnibox.suggestions.SuggestionViewProperties.SuggestionTextContainer;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider; import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.components.omnibox.SuggestionAnswer;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
......
...@@ -6,11 +6,13 @@ package org.chromium.chrome.browser.omnibox.suggestions; ...@@ -6,11 +6,13 @@ package org.chromium.chrome.browser.omnibox.suggestions;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.support.v4.util.ObjectsCompat;
import android.text.TextUtils; import android.text.TextUtils;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.omnibox.MatchClassificationStyle; import org.chromium.chrome.browser.omnibox.MatchClassificationStyle;
import org.chromium.components.omnibox.SuggestionAnswer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -27,7 +29,8 @@ public class OmniboxSuggestion { ...@@ -27,7 +29,8 @@ public class OmniboxSuggestion {
private static final String KEY_PREFIX_ZERO_SUGGEST_NATIVE_TYPE = "zero_suggest_native_type"; private static final String KEY_PREFIX_ZERO_SUGGEST_NATIVE_TYPE = "zero_suggest_native_type";
private static final String KEY_PREFIX_ZERO_SUGGEST_IS_SEARCH_TYPE = "zero_suggest_is_search"; private static final String KEY_PREFIX_ZERO_SUGGEST_IS_SEARCH_TYPE = "zero_suggest_is_search";
private static final String KEY_PREFIX_ZERO_SUGGEST_ANSWER_TEXT = "zero_suggest_answer_text"; private static final String KEY_PREFIX_ZERO_SUGGEST_ANSWER_TEXT = "zero_suggest_answer_text";
private static final String KEY_PREFIX_ZERO_SUGGEST_ANSWER_TYPE = "zero_suggest_answer_type"; // Deprecated:
// private static final String KEY_PREFIX_ZERO_SUGGEST_ANSWER_TYPE = "zero_suggest_answer_type";
private static final String KEY_PREFIX_ZERO_SUGGEST_IS_DELETABLE = "zero_suggest_is_deletable"; private static final String KEY_PREFIX_ZERO_SUGGEST_IS_DELETABLE = "zero_suggest_is_deletable";
private static final String KEY_PREFIX_ZERO_SUGGEST_IS_STARRED = "zero_suggest_is_starred"; private static final String KEY_PREFIX_ZERO_SUGGEST_IS_STARRED = "zero_suggest_is_starred";
...@@ -60,8 +63,6 @@ public class OmniboxSuggestion { ...@@ -60,8 +63,6 @@ public class OmniboxSuggestion {
private final List<MatchClassification> mDisplayTextClassifications; private final List<MatchClassification> mDisplayTextClassifications;
private final String mDescription; private final String mDescription;
private final List<MatchClassification> mDescriptionClassifications; private final List<MatchClassification> mDescriptionClassifications;
private final String mAnswerContents;
private final String mAnswerType;
private final SuggestionAnswer mAnswer; private final SuggestionAnswer mAnswer;
private final String mFillIntoEdit; private final String mFillIntoEdit;
private final String mUrl; private final String mUrl;
...@@ -73,8 +74,8 @@ public class OmniboxSuggestion { ...@@ -73,8 +74,8 @@ public class OmniboxSuggestion {
public OmniboxSuggestion(int nativeType, boolean isSearchType, int relevance, int transition, public OmniboxSuggestion(int nativeType, boolean isSearchType, int relevance, int transition,
String displayText, List<MatchClassification> displayTextClassifications, String displayText, List<MatchClassification> displayTextClassifications,
String description, List<MatchClassification> descriptionClassifications, String description, List<MatchClassification> descriptionClassifications,
String answerContents, String answerType, String fillIntoEdit, String url, SuggestionAnswer answer, String fillIntoEdit, String url, boolean isStarred,
boolean isStarred, boolean isDeletable) { boolean isDeletable) {
mType = nativeType; mType = nativeType;
mIsSearchType = isSearchType; mIsSearchType = isSearchType;
mRelevance = relevance; mRelevance = relevance;
...@@ -83,20 +84,11 @@ public class OmniboxSuggestion { ...@@ -83,20 +84,11 @@ public class OmniboxSuggestion {
mDisplayTextClassifications = displayTextClassifications; mDisplayTextClassifications = displayTextClassifications;
mDescription = description; mDescription = description;
mDescriptionClassifications = descriptionClassifications; mDescriptionClassifications = descriptionClassifications;
mAnswerContents = answerContents; mAnswer = answer;
mAnswerType = answerType;
mFillIntoEdit = TextUtils.isEmpty(fillIntoEdit) ? displayText : fillIntoEdit; mFillIntoEdit = TextUtils.isEmpty(fillIntoEdit) ? displayText : fillIntoEdit;
mUrl = url; mUrl = url;
mIsStarred = isStarred; mIsStarred = isStarred;
mIsDeletable = isDeletable; mIsDeletable = isDeletable;
if (!TextUtils.isEmpty(mAnswerContents)) {
// If any errors are encountered parsing the answer contents, this will return null and
// hasAnswer will return false, just as if there were no answer contents at all.
mAnswer = SuggestionAnswer.parseAnswerContents(mAnswerContents);
} else {
mAnswer = null;
}
} }
public int getType() { public int getType() {
...@@ -123,14 +115,6 @@ public class OmniboxSuggestion { ...@@ -123,14 +115,6 @@ public class OmniboxSuggestion {
return mDescriptionClassifications; return mDescriptionClassifications;
} }
public String getAnswerContents() {
return mAnswerContents;
}
public String getAnswerType() {
return mAnswerType;
}
public SuggestionAnswer getAnswer() { public SuggestionAnswer getAnswer() {
return mAnswer; return mAnswer;
} }
...@@ -181,9 +165,7 @@ public class OmniboxSuggestion { ...@@ -181,9 +165,7 @@ public class OmniboxSuggestion {
public int hashCode() { public int hashCode() {
int hash = 37 * mType + mDisplayText.hashCode() + mFillIntoEdit.hashCode() int hash = 37 * mType + mDisplayText.hashCode() + mFillIntoEdit.hashCode()
+ (mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0); + (mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0);
if (mAnswerContents != null) { if (mAnswer != null) hash = hash + mAnswer.hashCode();
hash = hash + mAnswerContents.hashCode();
}
return hash; return hash;
} }
...@@ -194,13 +176,10 @@ public class OmniboxSuggestion { ...@@ -194,13 +176,10 @@ public class OmniboxSuggestion {
} }
OmniboxSuggestion suggestion = (OmniboxSuggestion) obj; OmniboxSuggestion suggestion = (OmniboxSuggestion) obj;
boolean answersAreEqual = (mAnswerContents == null && suggestion.mAnswerContents == null)
|| (mAnswerContents != null && suggestion.mAnswerContents != null
&& mAnswerContents.equals(suggestion.mAnswerContents));
return mType == suggestion.mType && mFillIntoEdit.equals(suggestion.mFillIntoEdit) return mType == suggestion.mType && mFillIntoEdit.equals(suggestion.mFillIntoEdit)
&& mDisplayText.equals(suggestion.mDisplayText) && answersAreEqual && mDisplayText.equals(suggestion.mDisplayText)
&& mIsStarred == suggestion.mIsStarred && mIsDeletable == suggestion.mIsDeletable; && mIsStarred == suggestion.mIsStarred && mIsDeletable == suggestion.mIsDeletable
&& ObjectsCompat.equals(mAnswer, suggestion.mAnswer);
} }
/** /**
...@@ -213,13 +192,12 @@ public class OmniboxSuggestion { ...@@ -213,13 +192,12 @@ public class OmniboxSuggestion {
editor.putInt(KEY_ZERO_SUGGEST_LIST_SIZE, suggestions.size()).apply(); editor.putInt(KEY_ZERO_SUGGEST_LIST_SIZE, suggestions.size()).apply();
for (int i = 0; i < suggestions.size(); i++) { for (int i = 0; i < suggestions.size(); i++) {
OmniboxSuggestion suggestion = suggestions.get(i); OmniboxSuggestion suggestion = suggestions.get(i);
if (suggestion.mAnswer != null) continue;
editor.putString(KEY_PREFIX_ZERO_SUGGEST_URL + i, suggestion.getUrl()) editor.putString(KEY_PREFIX_ZERO_SUGGEST_URL + i, suggestion.getUrl())
.putString( .putString(
KEY_PREFIX_ZERO_SUGGEST_DISPLAY_TEST + i, suggestion.getDisplayText()) KEY_PREFIX_ZERO_SUGGEST_DISPLAY_TEST + i, suggestion.getDisplayText())
.putString(KEY_PREFIX_ZERO_SUGGEST_DESCRIPTION + i, suggestion.getDescription()) .putString(KEY_PREFIX_ZERO_SUGGEST_DESCRIPTION + i, suggestion.getDescription())
.putString(
KEY_PREFIX_ZERO_SUGGEST_ANSWER_TEXT + i, suggestion.getAnswerContents())
.putString(KEY_PREFIX_ZERO_SUGGEST_ANSWER_TYPE + i, suggestion.getAnswerType())
.putInt(KEY_PREFIX_ZERO_SUGGEST_NATIVE_TYPE + i, suggestion.getType()) .putInt(KEY_PREFIX_ZERO_SUGGEST_NATIVE_TYPE + i, suggestion.getType())
.putBoolean(KEY_PREFIX_ZERO_SUGGEST_IS_SEARCH_TYPE + i, .putBoolean(KEY_PREFIX_ZERO_SUGGEST_IS_SEARCH_TYPE + i,
!suggestion.isUrlSuggestion()) !suggestion.isUrlSuggestion())
...@@ -241,11 +219,16 @@ public class OmniboxSuggestion { ...@@ -241,11 +219,16 @@ public class OmniboxSuggestion {
List<MatchClassification> classifications = new ArrayList<>(); List<MatchClassification> classifications = new ArrayList<>();
classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE)); classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE));
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// TODO(tedchoc): Answers in suggest were previously cached, but that could lead to
// stale or misleading answers for cases like weather. Ignore any
// previously cached answers for several releases while any previous
// results are cycled through.
String answerText = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_ANSWER_TEXT + i, "");
if (!TextUtils.isEmpty(answerText)) continue;
String url = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_URL + i, ""); String url = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_URL + i, "");
String displayText = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_DISPLAY_TEST + i, ""); String displayText = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_DISPLAY_TEST + i, "");
String description = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_DESCRIPTION + i, ""); String description = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_DESCRIPTION + i, "");
String answerText = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_ANSWER_TEXT + i, "");
String answerType = prefs.getString(KEY_PREFIX_ZERO_SUGGEST_ANSWER_TYPE + i, "");
int nativeType = prefs.getInt(KEY_PREFIX_ZERO_SUGGEST_NATIVE_TYPE + i, -1); int nativeType = prefs.getInt(KEY_PREFIX_ZERO_SUGGEST_NATIVE_TYPE + i, -1);
boolean isSearchType = boolean isSearchType =
prefs.getBoolean(KEY_PREFIX_ZERO_SUGGEST_IS_SEARCH_TYPE, true); prefs.getBoolean(KEY_PREFIX_ZERO_SUGGEST_IS_SEARCH_TYPE, true);
...@@ -253,8 +236,8 @@ public class OmniboxSuggestion { ...@@ -253,8 +236,8 @@ public class OmniboxSuggestion {
boolean isDeletable = boolean isDeletable =
prefs.getBoolean(KEY_PREFIX_ZERO_SUGGEST_IS_DELETABLE + i, false); prefs.getBoolean(KEY_PREFIX_ZERO_SUGGEST_IS_DELETABLE + i, false);
OmniboxSuggestion suggestion = new OmniboxSuggestion(nativeType, !isSearchType, 0, OmniboxSuggestion suggestion = new OmniboxSuggestion(nativeType, !isSearchType, 0,
0, displayText, classifications, description, classifications, answerText, 0, displayText, classifications, description, classifications, null, "",
answerType, "", url, isStarred, isDeletable); url, isStarred, isDeletable);
suggestions.add(suggestion); suggestions.add(suggestion);
} }
} }
......
...@@ -121,8 +121,8 @@ class VoiceSuggestionProvider { ...@@ -121,8 +121,8 @@ class VoiceSuggestionProvider {
List<MatchClassification> classifications = new ArrayList<>(); List<MatchClassification> classifications = new ArrayList<>();
classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE)); classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE));
suggestions.add(new OmniboxSuggestion(OmniboxSuggestionType.VOICE_SUGGEST, true, 0, 1, suggestions.add(new OmniboxSuggestion(OmniboxSuggestionType.VOICE_SUGGEST, true, 0, 1,
result.getMatch(), classifications, null, classifications, null, null, null, result.getMatch(), classifications, null, classifications, null, null, voiceUrl,
voiceUrl, false, false)); false, false));
} }
private boolean doesVoiceResultHaveMatch( private boolean doesVoiceResultHaveMatch(
......
...@@ -1128,7 +1128,6 @@ chrome_java_sources = [ ...@@ -1128,7 +1128,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/omnibox/suggestions/OmniboxResultsAdapter.java", "java/src/org/chromium/chrome/browser/omnibox/suggestions/OmniboxResultsAdapter.java",
"java/src/org/chromium/chrome/browser/omnibox/suggestions/OmniboxSuggestion.java", "java/src/org/chromium/chrome/browser/omnibox/suggestions/OmniboxSuggestion.java",
"java/src/org/chromium/chrome/browser/omnibox/suggestions/OmniboxSuggestionsList.java", "java/src/org/chromium/chrome/browser/omnibox/suggestions/OmniboxSuggestionsList.java",
"java/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionAnswer.java",
"java/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionListProperties.java", "java/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionListProperties.java",
"java/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionListViewBinder.java", "java/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionListViewBinder.java",
"java/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionView.java", "java/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionView.java",
...@@ -2056,7 +2055,6 @@ chrome_test_java_sources = [ ...@@ -2056,7 +2055,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/omnibox/OmniboxUrlEmphasizerTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/OmniboxUrlEmphasizerTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/suggestions/SuggestionAnswerTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/suggestions/VoiceSuggestionProviderTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/suggestions/VoiceSuggestionProviderTest.java",
"javatests/src/org/chromium/chrome/browser/page_info/ConnectionInfoPopupTest.java", "javatests/src/org/chromium/chrome/browser/page_info/ConnectionInfoPopupTest.java",
"javatests/src/org/chromium/chrome/browser/page_info/PageInfoControllerTest.java", "javatests/src/org/chromium/chrome/browser/page_info/PageInfoControllerTest.java",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.omnibox.suggestions;
import android.support.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner;
@RunWith(BaseJUnit4ClassRunner.class)
public class SuggestionAnswerTest {
@Test
@SmallTest
public void testMalformedJsonReturnsNull() {
String json = "} malformed json {";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
Assert.assertNull(answer);
}
@Test
@SmallTest
public void testEmpyJsonReturnsNull() {
String json = "";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
Assert.assertNull(answer);
}
@Test
@SmallTest
public void testOneLineReturnsNull() {
String json = "{ 'l': ["
+ " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
+ "] }";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
Assert.assertNull(answer);
}
@Test
@SmallTest
public void testTwoLinesDoesntReturnNull() {
String json = "{ 'l': ["
+ " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
+ " { 'il': { 't': [{ 't': 'other text', 'tt': 5 }] } }"
+ "] }";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
Assert.assertNotNull(answer);
}
@Test
@SmallTest
public void testThreeLinesReturnsNull() {
String json = "{ 'l': ["
+ " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
+ " { 'il': { 't': [{ 't': 'other text', 'tt': 5 }] } }"
+ " { 'il': { 't': [{ 't': 'yet more text', 'tt': 13 }] } }"
+ "] }";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
Assert.assertNull(answer);
}
@Test
@SmallTest
public void testFiveLinesReturnsNull() {
String json = "{ 'l': ["
+ " { 'il': { 't': [{ 't': 'line 1', 'tt': 0 }] } }, "
+ " { 'il': { 't': [{ 't': 'line 2', 'tt': 5 }] } }"
+ " { 'il': { 't': [{ 't': 'line 3', 'tt': 13 }] } }"
+ " { 'il': { 't': [{ 't': 'line 4', 'tt': 14 }] } }"
+ " { 'il': { 't': [{ 't': 'line 5', 'tt': 5 }] } }"
+ "] }";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
Assert.assertNull(answer);
}
@Test
@SmallTest
public void testPropertyPresence() {
String json = "{ 'l': ["
+ " { 'il': { 't': [{ 't': 'text', 'tt': 8 }, { 't': 'moar', 'tt': 0 }], "
+ " 'i': { 'd': 'http://example.com/foo.jpg' } } }, "
+ " { 'il': { 't': [{ 't': 'other text', 'tt': 5 }], "
+ " 'at': { 't': 'slatfotf', 'tt': 42 }, "
+ " 'st': { 't': 'oh hi, Mark', 'tt': 7666 } } } "
+ "] }";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
SuggestionAnswer.ImageLine firstLine = answer.getFirstLine();
Assert.assertEquals(2, firstLine.getTextFields().size());
Assert.assertFalse(firstLine.hasAdditionalText());
Assert.assertFalse(firstLine.hasStatusText());
Assert.assertTrue(firstLine.hasImage());
SuggestionAnswer.ImageLine secondLine = answer.getSecondLine();
Assert.assertEquals(1, secondLine.getTextFields().size());
Assert.assertTrue(secondLine.hasAdditionalText());
Assert.assertTrue(secondLine.hasStatusText());
Assert.assertFalse(secondLine.hasImage());
}
@Test
@SmallTest
public void testContents() {
String json = "{ 'l': ["
+ " { 'il': { 't': [{ 't': 'text', 'tt': 8 }, { 't': 'moar', 'tt': 0 }], "
+ " 'at': { 't': 'hi there', 'tt': 7 } } }, "
+ " { 'il': { 't': [{ 't': 'ftw', 'tt': 6006 }], "
+ " 'st': { 't': 'shop S-Mart', 'tt': 666 }, "
+ " 'i': { 'd': '//Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGlj' } } } "
+ "] }";
SuggestionAnswer answer = SuggestionAnswer.parseAnswerContents(json);
SuggestionAnswer.ImageLine firstLine = answer.getFirstLine();
Assert.assertEquals("text", firstLine.getTextFields().get(0).getText());
Assert.assertEquals(8, firstLine.getTextFields().get(0).getType());
Assert.assertEquals("moar", firstLine.getTextFields().get(1).getText());
Assert.assertEquals(0, firstLine.getTextFields().get(1).getType());
Assert.assertEquals("hi there", firstLine.getAdditionalText().getText());
Assert.assertEquals(7, firstLine.getAdditionalText().getType());
SuggestionAnswer.ImageLine secondLine = answer.getSecondLine();
Assert.assertEquals("ftw", secondLine.getTextFields().get(0).getText());
Assert.assertEquals(6006, secondLine.getTextFields().get(0).getType());
Assert.assertEquals("shop S-Mart", secondLine.getStatusText().getText());
Assert.assertEquals(666, secondLine.getStatusText().getType());
Assert.assertEquals(
"https://Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGlj", secondLine.getImage());
}
}
...@@ -40,8 +40,8 @@ public class VoiceSuggestionProviderTest { ...@@ -40,8 +40,8 @@ public class VoiceSuggestionProviderTest {
List<MatchClassification> classifications = new ArrayList<>(); List<MatchClassification> classifications = new ArrayList<>();
classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE)); classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE));
return new OmniboxSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, true, 0, 1, text, return new OmniboxSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, true, 0, 1, text,
classifications, null, classifications, null, null, "", "http://www.google.com", classifications, null, classifications, null, "", "http://www.google.com", false,
false, false); false);
} }
private static List<OmniboxSuggestion> createDummySuggestions(String... texts) { private static List<OmniboxSuggestion> createDummySuggestions(String... texts) {
......
...@@ -299,11 +299,11 @@ public class SearchActivityTest { ...@@ -299,11 +299,11 @@ public class SearchActivityTest {
List<MatchClassification> classifications = new ArrayList<>(); List<MatchClassification> classifications = new ArrayList<>();
classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE)); classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE));
OmniboxSuggestion mockSuggestion = new OmniboxSuggestion(0, true, 0, 0, OmniboxSuggestion mockSuggestion = new OmniboxSuggestion(0, true, 0, 0,
"https://google.com", classifications, "https://google.com", classifications, "", "https://google.com", classifications, "https://google.com", classifications, null,
"", "", "https://google.com", false, false); "", "https://google.com", false, false);
OmniboxSuggestion mockSuggestion2 = new OmniboxSuggestion(0, true, 0, 0, OmniboxSuggestion mockSuggestion2 = new OmniboxSuggestion(0, true, 0, 0,
"https://android.com", classifications, "https://android.com", classifications, "", "https://android.com", classifications, "https://android.com", classifications,
"", "", "https://android.com", false, false); null, "", "https://android.com", false, false);
List<OmniboxSuggestion> list = new ArrayList<>(); List<OmniboxSuggestion> list = new ArrayList<>();
list.add(mockSuggestion); list.add(mockSuggestion);
list.add(mockSuggestion2); list.add(mockSuggestion2);
......
...@@ -544,10 +544,9 @@ AutocompleteControllerAndroid::BuildOmniboxSuggestion( ...@@ -544,10 +544,9 @@ AutocompleteControllerAndroid::BuildOmniboxSuggestion(
description_class_styles.push_back(description_class.style); description_class_styles.push_back(description_class.style);
} }
ScopedJavaLocalRef<jstring> answer_contents = ScopedJavaLocalRef<jobject> janswer;
ConvertUTF16ToJavaString(env, match.answer_contents); if (match.answer)
ScopedJavaLocalRef<jstring> answer_type = janswer = match.answer->CreateJavaObject();
ConvertUTF16ToJavaString(env, match.answer_type);
ScopedJavaLocalRef<jstring> fill_into_edit = ScopedJavaLocalRef<jstring> fill_into_edit =
ConvertUTF16ToJavaString(env, match.fill_into_edit); ConvertUTF16ToJavaString(env, match.fill_into_edit);
ScopedJavaLocalRef<jstring> destination_url = ScopedJavaLocalRef<jstring> destination_url =
...@@ -560,8 +559,8 @@ AutocompleteControllerAndroid::BuildOmniboxSuggestion( ...@@ -560,8 +559,8 @@ AutocompleteControllerAndroid::BuildOmniboxSuggestion(
ToJavaIntArray(env, contents_class_offsets), ToJavaIntArray(env, contents_class_offsets),
ToJavaIntArray(env, contents_class_styles), description, ToJavaIntArray(env, contents_class_styles), description,
ToJavaIntArray(env, description_class_offsets), ToJavaIntArray(env, description_class_offsets),
ToJavaIntArray(env, description_class_styles), answer_contents, ToJavaIntArray(env, description_class_styles), janswer, fill_into_edit,
answer_type, fill_into_edit, destination_url, destination_url,
bookmark_model && bookmark_model->IsBookmarked(match.destination_url), bookmark_model && bookmark_model->IsBookmarked(match.destination_url),
match.SupportsDeletion()); match.SupportsDeletion());
} }
......
...@@ -78,6 +78,7 @@ android_library("chrome_java_test_support") { ...@@ -78,6 +78,7 @@ android_library("chrome_java_test_support") {
"//components/embedder_support/android:web_contents_delegate_java", "//components/embedder_support/android:web_contents_delegate_java",
"//components/invalidation/impl:java", "//components/invalidation/impl:java",
"//components/location/android:location_java", "//components/location/android:location_java",
"//components/omnibox/browser:browser_java",
"//components/policy/android:policy_java", "//components/policy/android:policy_java",
"//components/policy/android:policy_java_test_support", "//components/policy/android:policy_java_test_support",
"//components/signin/core/browser/android:java", "//components/signin/core/browser/android:java",
......
...@@ -76,9 +76,8 @@ public class OmniboxTestUtils { ...@@ -76,9 +76,8 @@ public class OmniboxTestUtils {
int type, String text, String url) { int type, String text, String url) {
List<MatchClassification> classifications = new ArrayList<>(); List<MatchClassification> classifications = new ArrayList<>();
classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE)); classifications.add(new MatchClassification(0, MatchClassificationStyle.NONE));
mSuggestions.add(new OmniboxSuggestion( mSuggestions.add(new OmniboxSuggestion(type, false, 0, 0, text, classifications, null,
type, false, 0, 0, text, classifications, null, classifications, classifications, null, "", url, false, false));
null, null, "", url, false, false));
return this; return this;
} }
......
...@@ -235,19 +235,39 @@ jumbo_static_library("browser") { ...@@ -235,19 +235,39 @@ jumbo_static_library("browser") {
if ((!is_android || enable_vr) && !is_ios) { if ((!is_android || enable_vr) && !is_ios) {
deps += [ ":vector_icons" ] deps += [ ":vector_icons" ]
} }
if (is_android) {
deps += [ ":jni_headers" ]
}
} }
if (is_android) { if (is_android) {
java_cpp_enum("autocomplete_match_javagen") { android_library("browser_java") {
java_files = [
"android/java/src/org/chromium/components/omnibox/SuggestionAnswer.java",
]
deps = [
"//base:base_java",
"//third_party/android_deps:android_support_compat_java",
]
srcjar_deps = [ ":browser_java_enums_srcjar" ]
}
java_cpp_enum("browser_java_enums_srcjar") {
sources = [ sources = [
"autocomplete_match.h", "autocomplete_match.h",
"autocomplete_match_type.h",
"suggestion_answer.h",
] ]
} }
java_cpp_enum("autocomplete_match_type_javagen") { generate_jni("jni_headers") {
sources = [ sources = [
"autocomplete_match_type.h", "android/java/src/org/chromium/components/omnibox/SuggestionAnswer.java",
] ]
jni_package = "components/omnibox/browser"
} }
} }
......
...@@ -24,6 +24,7 @@ include_rules = [ ...@@ -24,6 +24,7 @@ include_rules = [
"+components/variations", "+components/variations",
"+components/vector_icons", "+components/vector_icons",
"+extensions/common/constants.h", "+extensions/common/constants.h",
"+jni",
"+net", "+net",
"+services/network/public/cpp", "+services/network/public/cpp",
"+services/network/test", "+services/network/test",
......
...@@ -19,6 +19,13 @@ ...@@ -19,6 +19,13 @@
#include "net/base/escape.h" #include "net/base/escape.h"
#include "url/url_constants.h" #include "url/url_constants.h"
#ifdef OS_ANDROID
#include "base/android/jni_string.h"
#include "jni/SuggestionAnswer_jni.h"
using base::android::ScopedJavaLocalRef;
#endif
namespace { namespace {
// All of these are defined here (even though most are only used once each) so // All of these are defined here (even though most are only used once each) so
...@@ -341,3 +348,54 @@ void SuggestionAnswer::InterpretTextTypes() { ...@@ -341,3 +348,54 @@ void SuggestionAnswer::InterpretTextTypes() {
first_line_.SetTextStyles(0, TextStyle::NORMAL_DIM); first_line_.SetTextStyles(0, TextStyle::NORMAL_DIM);
second_line_.SetTextStyles(0, TextStyle::NORMAL); second_line_.SetTextStyles(0, TextStyle::NORMAL);
} }
#ifdef OS_ANDROID
namespace {
ScopedJavaLocalRef<jobject> CreateJavaTextField(
JNIEnv* env,
const SuggestionAnswer::TextField& text_field) {
return Java_SuggestionAnswer_createTextField(
env, text_field.type(),
base::android::ConvertUTF16ToJavaString(env, text_field.text()),
static_cast<int>(text_field.style()), text_field.num_lines());
}
ScopedJavaLocalRef<jobject> CreateJavaImageLine(
JNIEnv* env,
const SuggestionAnswer::ImageLine* image_line) {
ScopedJavaLocalRef<jobject> jtext_fields =
Java_SuggestionAnswer_createTextFieldList(env);
for (const SuggestionAnswer::TextField& text_field :
image_line->text_fields()) {
Java_SuggestionAnswer_addTextFieldToList(
env, jtext_fields, CreateJavaTextField(env, text_field));
}
ScopedJavaLocalRef<jobject> jadditional_text;
if (image_line->additional_text())
jadditional_text = CreateJavaTextField(env, *image_line->additional_text());
ScopedJavaLocalRef<jobject> jstatus_text;
if (image_line->status_text())
jstatus_text = CreateJavaTextField(env, *image_line->status_text());
ScopedJavaLocalRef<jstring> jimage_url;
if (image_line->image_url().is_valid()) {
jimage_url = base::android::ConvertUTF8ToJavaString(
env, image_line->image_url().spec());
}
return Java_SuggestionAnswer_createImageLine(
env, jtext_fields, jadditional_text, jstatus_text, jimage_url);
}
} // namespace
ScopedJavaLocalRef<jobject> SuggestionAnswer::CreateJavaObject() const {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_SuggestionAnswer_createSuggestionAnswer(
env, static_cast<int>(type_), CreateJavaImageLine(env, &first_line_),
CreateJavaImageLine(env, &second_line_));
}
#endif // OS_ANDROID
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "base/optional.h" #include "base/optional.h"
#include "url/gurl.h" #include "url/gurl.h"
#ifdef OS_ANDROID
#include "base/android/scoped_java_ref.h"
#endif
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
} }
...@@ -37,8 +41,11 @@ class SuggestionAnswer { ...@@ -37,8 +41,11 @@ class SuggestionAnswer {
// These values are based on the server-side type AnswerTriggererKey. Do not // These values are based on the server-side type AnswerTriggererKey. Do not
// remove values from this enum (or the client/server will become out of // remove values from this enum (or the client/server will become out of
// sync). // sync).
//
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.omnibox
enum AnswerType { enum AnswerType {
ANSWER_TYPE_INVALID, ANSWER_TYPE_INVALID = 0,
ANSWER_TYPE_DICTIONARY, ANSWER_TYPE_DICTIONARY,
ANSWER_TYPE_FINANCE, ANSWER_TYPE_FINANCE,
ANSWER_TYPE_KNOWLEDGE_GRAPH, ANSWER_TYPE_KNOWLEDGE_GRAPH,
...@@ -57,6 +64,10 @@ class SuggestionAnswer { ...@@ -57,6 +64,10 @@ class SuggestionAnswer {
// These values are named and numbered to match a specification at go/ais_api. // These values are named and numbered to match a specification at go/ais_api.
// The values are only used for answer results. // The values are only used for answer results.
//
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.omnibox
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: AnswerTextType
enum TextType { enum TextType {
// Deprecated: ANSWER = 1, // Deprecated: ANSWER = 1,
// Deprecated: HEADLINE = 2, // Deprecated: HEADLINE = 2,
...@@ -89,8 +100,12 @@ class SuggestionAnswer { ...@@ -89,8 +100,12 @@ class SuggestionAnswer {
// based on a finite set of text types instead of answer properties and rules. // based on a finite set of text types instead of answer properties and rules.
// Performance is also improved by doing this once at parse time instead of // Performance is also improved by doing this once at parse time instead of
// every time render text is invalidated. // every time render text is invalidated.
//
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.omnibox
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: AnswerTextStyle
enum class TextStyle { enum class TextStyle {
NONE, NONE = 0,
NORMAL, NORMAL,
NORMAL_DIM, NORMAL_DIM,
SECONDARY, SECONDARY,
...@@ -223,6 +238,10 @@ class SuggestionAnswer { ...@@ -223,6 +238,10 @@ class SuggestionAnswer {
// For new answers, replace old answer text types with appropriate new types. // For new answers, replace old answer text types with appropriate new types.
void InterpretTextTypes(); void InterpretTextTypes();
#ifdef OS_ANDROID
base::android::ScopedJavaLocalRef<jobject> CreateJavaObject() const;
#endif
private: private:
GURL image_url_; GURL image_url_;
ImageLine first_line_; ImageLine first_line_;
......
...@@ -65,6 +65,7 @@ to the classpath for downstream development. See "additional_entries" below. ...@@ -65,6 +65,7 @@ to the classpath for downstream development. See "additional_entries" below.
<classpathentry kind="src" path="components/navigation_interception/android/java/src"/> <classpathentry kind="src" path="components/navigation_interception/android/java/src"/>
<classpathentry kind="src" path="components/ntp_tiles/android/java/src"/> <classpathentry kind="src" path="components/ntp_tiles/android/java/src"/>
<classpathentry kind="src" path="components/offline_items_collection/core/android/java/src"/> <classpathentry kind="src" path="components/offline_items_collection/core/android/java/src"/>
<classpathentry kind="src" path="components/omnibox/browser/android/java/src"/>
<classpathentry kind="src" path="components/payments/content/android/java/src"/> <classpathentry kind="src" path="components/payments/content/android/java/src"/>
<classpathentry kind="src" path="components/policy/android/java/src"/> <classpathentry kind="src" path="components/policy/android/java/src"/>
<classpathentry kind="src" path="components/policy/android/javatests/src"/> <classpathentry kind="src" path="components/policy/android/javatests/src"/>
...@@ -267,6 +268,7 @@ to the classpath for downstream development. See "additional_entries" below. ...@@ -267,6 +268,7 @@ to the classpath for downstream development. See "additional_entries" below.
<classpathentry kind="lib" path="out/Debug/lib.java/components/invalidation/impl/java.jar"/> <classpathentry kind="lib" path="out/Debug/lib.java/components/invalidation/impl/java.jar"/>
<classpathentry kind="lib" path="out/Debug/lib.java/components/invalidation/impl/proto_java.jar"/> <classpathentry kind="lib" path="out/Debug/lib.java/components/invalidation/impl/proto_java.jar"/>
<classpathentry kind="lib" path="out/Debug/lib.java/components/navigation_interception/android/navigation_interception_java.jar"/> <classpathentry kind="lib" path="out/Debug/lib.java/components/navigation_interception/android/navigation_interception_java.jar"/>
<classpathentry kind="lib" path="out/Debug/lib.java/components/omnibox/browser/browser_java.jar"/>
<classpathentry kind="lib" path="out/Debug/lib.java/components/policy/android/policy_java.jar"/> <classpathentry kind="lib" path="out/Debug/lib.java/components/policy/android/policy_java.jar"/>
<classpathentry kind="lib" path="out/Debug/lib.java/components/payments/content/payment_request_java.jar"/> <classpathentry kind="lib" path="out/Debug/lib.java/components/payments/content/payment_request_java.jar"/>
<classpathentry kind="lib" path="out/Debug/lib.java/components/precache/android/precache_java.jar"/> <classpathentry kind="lib" path="out/Debug/lib.java/components/precache/android/precache_java.jar"/>
......
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