diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn index e5ff588a68c4cb..2cc0f56acf364e 100644 --- a/chrome/android/BUILD.gn +++ b/chrome/android/BUILD.gn @@ -169,6 +169,7 @@ android_library("chrome_java") { "//chrome:content_settings_type_javagen", "//components/enhanced_bookmarks:enhanced_bookmarks_java_enums_srcjar", "//components/offline_pages:offline_pages_enums_java", + "//components/omnibox/browser:autocomplete_match_type_javagen", ] DEPRECATED_java_in_dir = "java/src" diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java index ee0ebd7594ab94..b0a3e8b80886ba 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java @@ -230,11 +230,11 @@ private void notifyNativeDestroyed() { * modifying text in the omnibox and selecting a suggestion. * @param webContents The web contents for the tab where the selected suggestion will be shown. */ - public void onSuggestionSelected(int selectedIndex, OmniboxSuggestion.Type type, + public void onSuggestionSelected(int selectedIndex, int type, String currentPageUrl, boolean isQueryInOmnibox, boolean focusedFromFakebox, long elapsedTimeSinceModified, WebContents webContents) { // Don't natively log voice suggestion results as we add them in Java. - if (type == OmniboxSuggestion.Type.VOICE_SUGGEST) return; + if (type == OmniboxSuggestionType.VOICE_SUGGEST) return; nativeOnSuggestionSelected(mNativeAutocompleteControllerAndroid, selectedIndex, currentPageUrl, isQueryInOmnibox, focusedFromFakebox, elapsedTimeSinceModified, webContents); @@ -264,12 +264,12 @@ private static void addOmniboxSuggestionToList(List suggestio } @CalledByNative - private static OmniboxSuggestion buildOmniboxSuggestion(int nativeType, int relevance, - int transition, String text, String description, String answerContents, + private static OmniboxSuggestion buildOmniboxSuggestion(int nativeType, boolean isSearchType, + int relevance, int transition, String text, String description, String answerContents, String answerType, String fillIntoEdit, String url, String formattedUrl, boolean isStarred, boolean isDeletable) { - return new OmniboxSuggestion(nativeType, relevance, transition, text, description, - answerContents, answerType, fillIntoEdit, url, formattedUrl, isStarred, + return new OmniboxSuggestion(nativeType, isSearchType, relevance, transition, text, + description, answerContents, answerType, fillIntoEdit, url, formattedUrl, isStarred, isDeletable); } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java index 89b0d178ecd9e1..3181d7ccda0384 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java @@ -74,7 +74,6 @@ import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsReceivedListener; import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxResultItem; import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxSuggestionDelegate; -import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.Type; import org.chromium.chrome.browser.omnibox.VoiceSuggestionProvider.VoiceResult; import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; import org.chromium.chrome.browser.omnibox.geo.GeolocationSnackbarController; @@ -450,7 +449,7 @@ private void findMatchAndLoadUrl(String urlText) { // up saving generated URLs as typed URLs, which would then pollute the subsequent // omnibox results. There is one special case where the suggestion text was pasted, // where we want the transition type to be LINK. - int transition = suggestionMatch.getType() == OmniboxSuggestion.Type.URL_WHAT_YOU_TYPED + int transition = suggestionMatch.getType() == OmniboxSuggestionType.URL_WHAT_YOU_TYPED && mUrlBar.isPastedText() ? PageTransition.LINK : suggestionMatch.getTransition(); @@ -1123,29 +1122,11 @@ protected ToolbarDataProvider getToolbarDataProvider() { } private static NavigationButtonType suggestionTypeToNavigationButtonType( - OmniboxSuggestion.Type suggestionType) { - switch (suggestionType) { - case NAVSUGGEST: - case HISTORY_URL: - case URL_WHAT_YOU_TYPED: - case HISTORY_TITLE: - case HISTORY_BODY: - case HISTORY_KEYWORD: - return NavigationButtonType.PAGE; - case SEARCH_WHAT_YOU_TYPED: - case SEARCH_HISTORY: - case SEARCH_SUGGEST: - case SEARCH_SUGGEST_ENTITY: - case SEARCH_SUGGEST_TAIL: - case SEARCH_SUGGEST_PERSONALIZED: - case SEARCH_SUGGEST_PROFILE: - case VOICE_SUGGEST: - case SEARCH_OTHER_ENGINE: - case OPEN_HISTORY_PAGE: - return NavigationButtonType.MAGNIFIER; - default: - assert false; - return NavigationButtonType.MAGNIFIER; + OmniboxSuggestion suggestion) { + if (suggestion.isUrlSuggestion()) { + return NavigationButtonType.PAGE; + } else { + return NavigationButtonType.MAGNIFIER; } } @@ -1156,7 +1137,7 @@ private void updateNavigationButton() { if (isTablet && !mSuggestionItems.isEmpty()) { // If there are suggestions showing, show the icon for the default suggestion. type = suggestionTypeToNavigationButtonType( - mSuggestionItems.get(0).getSuggestion().getType()); + mSuggestionItems.get(0).getSuggestion()); } else if (mQueryInTheOmnibox) { type = NavigationButtonType.MAGNIFIER; } else if (isTablet) { @@ -1570,7 +1551,7 @@ private String updateSuggestionUrlIfNeeded(OmniboxSuggestion suggestion, int sel updatedUrl = TemplateUrlService.getInstance().replaceSearchTermsInUrl( query, currentTab.getUrl()); } - } else if (suggestion.getType() != Type.VOICE_SUGGEST) { + } else if (suggestion.getType() != OmniboxSuggestionType.VOICE_SUGGEST) { // TODO(mariakhomenko): Ideally we want to update match destination URL with new aqs // for query in the omnibox and voice suggestions, but it's currently difficult to do. long elapsedTimeSinceInputChange = mNewOmniboxEditSessionTimestamp > 0 @@ -1808,7 +1789,7 @@ public void onSuggestionsReceived(List newSuggestions, // Determine whether the suggestions have changed. If not, save some time by not // redrawing the suggestions UI. if (suggestion.equals(newSuggestion) - && suggestion.getType() != OmniboxSuggestion.Type.SEARCH_SUGGEST_TAIL) { + && suggestion.getType() != OmniboxSuggestionType.SEARCH_SUGGEST_TAIL) { if (suggestionItem.getMatchedQuery().equals(userText)) { continue; } else if (!suggestion.getDisplayText().startsWith(userText) @@ -2019,8 +2000,7 @@ public void setIgnoreURLBarModification(boolean value) { mIgnoreURLBarModification = value; } - private void loadUrlFromOmniboxMatch(String url, int transition, int matchPosition, - OmniboxSuggestion.Type type) { + private void loadUrlFromOmniboxMatch(String url, int transition, int matchPosition, int type) { // loadUrl modifies AutocompleteController's state clearing the native // AutocompleteResults needed by onSuggestionsSelected. Therefore, // loadUrl should should be invoked last. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/OmniboxSuggestion.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/OmniboxSuggestion.java index e5cbcdfff7c710..00e701fc1b4cda 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/OmniboxSuggestion.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/OmniboxSuggestion.java @@ -14,7 +14,8 @@ @VisibleForTesting public class OmniboxSuggestion { - private final Type mType; + private final int mType; + private final boolean mIsSearchType; private final String mDisplayText; private final String mDescription; private final String mAnswerContents; @@ -28,71 +29,12 @@ public class OmniboxSuggestion { private final boolean mIsStarred; private final boolean mIsDeletable; - /** - * This should be kept in sync with AutocompleteMatch::Type - * (see components/omnibox/autocomplete_match_type.h). - * Negative types are specific to Chrome on Android front-end. - */ - public static enum Type { - VOICE_SUGGEST (-100), // A suggested search from the voice recognizer. - - URL_WHAT_YOU_TYPED (0), // The input as a URL. - HISTORY_URL (1), // A past page whose URL contains the input. - HISTORY_TITLE (2), // A past page whose title contains the input. - HISTORY_BODY (3), // A past page whose body contains the input. - HISTORY_KEYWORD (4), // A past page whose keyword contains the input. - NAVSUGGEST (5), // A suggested URL. - SEARCH_WHAT_YOU_TYPED (6), // The input as a search query (with the default - // engine). - SEARCH_HISTORY (7), // A past search (with the default engine) - // containing the input. - SEARCH_SUGGEST (8), // A suggested search (with the default engine). - SEARCH_SUGGEST_ENTITY (9), // A suggested search for an entity. - SEARCH_SUGGEST_TAIL (10), // A suggested search (with the default engine) - // to complete the tail part of the input. - SEARCH_SUGGEST_PERSONALIZED (11), // A personalized suggested search. - SEARCH_SUGGEST_PROFILE (12), // A personalized suggested search for a - // Google+ profile. - SEARCH_OTHER_ENGINE (13), // A search with a non-default engine. - OPEN_HISTORY_PAGE (17); // A synthetic result that opens the history page - // to search for the input. - - private final int mNativeType; - - Type(int nativeType) { - mNativeType = nativeType; - } - - static Type getTypeFromNativeType(int nativeType) { - for (Type t : Type.values()) { - if (t.mNativeType == nativeType) return t; - } - - return URL_WHAT_YOU_TYPED; - } - - public boolean isHistoryUrl() { - return this == HISTORY_URL || this == HISTORY_TITLE - || this == HISTORY_BODY || this == HISTORY_KEYWORD; - } - - public boolean isUrl() { - return this == URL_WHAT_YOU_TYPED || this.isHistoryUrl() || this == NAVSUGGEST; - } - - /** - * @return The ID of the type used by the native code. - */ - public int nativeType() { - return mNativeType; - } - } - - public OmniboxSuggestion(int nativeType, int relevance, int transition, + public OmniboxSuggestion(int nativeType, boolean isSearchType, int relevance, int transition, String text, String description, String answerContents, String answerType, String fillIntoEdit, String url, String formattedUrl, boolean isStarred, boolean isDeletable) { - mType = Type.getTypeFromNativeType(nativeType); + mType = nativeType; + mIsSearchType = isSearchType; mRelevance = relevance; mTransition = transition; mDisplayText = text; @@ -114,7 +56,7 @@ public OmniboxSuggestion(int nativeType, int relevance, int transition, } } - public Type getType() { + public int getType() { return mType; } @@ -158,8 +100,11 @@ public String getFormattedUrl() { return mFormattedUrl; } + /** + * @return Whether the suggestion is a URL. + */ public boolean isUrlSuggestion() { - return mType.isUrl(); + return !mIsSearchType; } /** @@ -187,7 +132,7 @@ public String toString() { @Override public int hashCode() { - int hash = 37 * mType.mNativeType + mDisplayText.hashCode() + mFillIntoEdit.hashCode() + int hash = 37 * mType + mDisplayText.hashCode() + mFillIntoEdit.hashCode() + (mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0); if (mAnswerContents != null) { hash = hash + mAnswerContents.hashCode(); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java index 65664987d92f7a..23c3189bfdf066 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java @@ -4,8 +4,6 @@ package org.chromium.chrome.browser.omnibox; -import static org.chromium.chrome.browser.omnibox.OmniboxSuggestion.Type.HISTORY_URL; - import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; @@ -35,7 +33,6 @@ import org.chromium.chrome.R; import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxResultItem; import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxSuggestionDelegate; -import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.Type; import org.chromium.chrome.browser.widget.TintedDrawable; import org.chromium.ui.base.DeviceFormFactor; @@ -185,7 +182,7 @@ protected void drawableStateChanged() { protected void onLayout(boolean changed, int left, int top, int right, int bottom) { if (getMeasuredWidth() == 0) return; - if (mSuggestion.getType() != Type.SEARCH_SUGGEST_TAIL) { + if (mSuggestion.getType() != OmniboxSuggestionType.SEARCH_SUGGEST_TAIL) { mContentsView.resetTextWidths(); } @@ -297,64 +294,44 @@ public void init(OmniboxResultItem suggestionItem, boolean sameAsTyped = suggestionItem.getMatchedQuery().equalsIgnoreCase(mSuggestion.getDisplayText()); - Type suggestionType = mSuggestion.getType(); - switch (suggestionType) { - case HISTORY_URL: - case URL_WHAT_YOU_TYPED: - case NAVSUGGEST: - case HISTORY_TITLE: - case HISTORY_BODY: - case HISTORY_KEYWORD: - case OPEN_HISTORY_PAGE: - if (mSuggestion.isStarred()) { - mContentsView.setSuggestionIcon(SuggestionIconType.BOOKMARK, colorsChanged); - } else if (suggestionType == HISTORY_URL) { - mContentsView.setSuggestionIcon(SuggestionIconType.HISTORY, colorsChanged); - } else { - mContentsView.setSuggestionIcon(SuggestionIconType.GLOBE, colorsChanged); - } - boolean urlShown = !TextUtils.isEmpty(mSuggestion.getUrl()); - boolean urlHighlighted = false; - if (urlShown) { - urlHighlighted = setUrlText(suggestionItem); - } else { - mContentsView.mTextLine2.setVisibility(INVISIBLE); - } - setSuggestedQuery(suggestionItem, true, urlShown, urlHighlighted); - setRefinable(!sameAsTyped); - break; - case SEARCH_WHAT_YOU_TYPED: - case SEARCH_HISTORY: - case SEARCH_SUGGEST: - case SEARCH_OTHER_ENGINE: - case SEARCH_SUGGEST_ENTITY: - case SEARCH_SUGGEST_TAIL: - case SEARCH_SUGGEST_PERSONALIZED: - case SEARCH_SUGGEST_PROFILE: - case VOICE_SUGGEST: - SuggestionIconType suggestionIcon = SuggestionIconType.MAGNIFIER; - if (suggestionType == Type.VOICE_SUGGEST) { - suggestionIcon = SuggestionIconType.VOICE; - } else if ((suggestionType == Type.SEARCH_SUGGEST_PERSONALIZED) - || (suggestionType == Type.SEARCH_HISTORY)) { - // Show history icon for suggestions based on user queries. - suggestionIcon = SuggestionIconType.HISTORY; - } - mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged); - setRefinable(!sameAsTyped); - setSuggestedQuery(suggestionItem, false, false, false); - if ((suggestionType == Type.SEARCH_SUGGEST_ENTITY) - || (suggestionType == Type.SEARCH_SUGGEST_PROFILE)) { - showDescriptionLine( - SpannableString.valueOf(mSuggestion.getDescription()), - getStandardFontColor()); - } else { - mContentsView.mTextLine2.setVisibility(INVISIBLE); - } - break; - default: - assert false : "Suggestion type (" + mSuggestion.getType() + ") is not handled"; - break; + int suggestionType = mSuggestion.getType(); + if (mSuggestion.isUrlSuggestion()) { + if (mSuggestion.isStarred()) { + mContentsView.setSuggestionIcon(SuggestionIconType.BOOKMARK, colorsChanged); + } else if (suggestionType == OmniboxSuggestionType.HISTORY_URL) { + mContentsView.setSuggestionIcon(SuggestionIconType.HISTORY, colorsChanged); + } else { + mContentsView.setSuggestionIcon(SuggestionIconType.GLOBE, colorsChanged); + } + boolean urlShown = !TextUtils.isEmpty(mSuggestion.getUrl()); + boolean urlHighlighted = false; + if (urlShown) { + urlHighlighted = setUrlText(suggestionItem); + } else { + mContentsView.mTextLine2.setVisibility(INVISIBLE); + } + setSuggestedQuery(suggestionItem, true, urlShown, urlHighlighted); + setRefinable(!sameAsTyped); + } else { + SuggestionIconType suggestionIcon = SuggestionIconType.MAGNIFIER; + if (suggestionType == OmniboxSuggestionType.VOICE_SUGGEST) { + suggestionIcon = SuggestionIconType.VOICE; + } else if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_PERSONALIZED) + || (suggestionType == OmniboxSuggestionType.SEARCH_HISTORY)) { + // Show history icon for suggestions based on user queries. + suggestionIcon = SuggestionIconType.HISTORY; + } + mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged); + setRefinable(!sameAsTyped); + setSuggestedQuery(suggestionItem, false, false, false); + if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_ENTITY) + || (suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_PROFILE)) { + showDescriptionLine( + SpannableString.valueOf(mSuggestion.getDescription()), + getStandardFontColor()); + } else { + mContentsView.mTextLine2.setVisibility(INVISIBLE); + } } } @@ -467,7 +444,7 @@ private void setSuggestedQuery( suggestedQuery = suggestion.getFormattedUrl(); } - if (mSuggestion.getType() == Type.SEARCH_SUGGEST_TAIL) { + if (mSuggestion.getType() == OmniboxSuggestionType.SEARCH_SUGGEST_TAIL) { String fillIntoEdit = mSuggestion.getFillIntoEdit(); // Data sanity checks. if (fillIntoEdit.startsWith(userQuery) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProvider.java index 21c7ceb92a1fca..25d0cdf9e61470 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProvider.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProvider.java @@ -141,7 +141,8 @@ private void addVoiceResultToOmniboxSuggestions(List suggesti String voiceUrl = TemplateUrlService.getInstance().getUrlForVoiceSearchQuery( result.getMatch()); suggestions.add(new OmniboxSuggestion( - OmniboxSuggestion.Type.VOICE_SUGGEST.nativeType(), + OmniboxSuggestionType.VOICE_SUGGEST, + true, 0, 1, result.getMatch(), diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/OmniboxTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/OmniboxTest.java index 192b119cef0ee2..be88d60f4c58e4 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/OmniboxTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/OmniboxTest.java @@ -28,7 +28,6 @@ import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsReceivedListener; import org.chromium.chrome.browser.omnibox.LocationBarLayout.OmniboxSuggestionsList; -import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.Type; import org.chromium.chrome.test.ChromeActivityTestCaseBase; import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.OmniboxTestUtils; @@ -316,23 +315,29 @@ private void doTestAutoCompleteAndCorrectionForOrientation( new TestSuggestionResultsBuilder() .setTextShownFor("wiki") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "wikipedia", null) - .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "wiki", null) - .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "wikileaks", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, + "wikipedia", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, + "wiki", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, + "wikileaks", null) .setAutocompleteText("pedia")), new TestSuggestionResultsBuilder() .setTextShownFor("onomatop") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "onomatopoeia", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, + "onomatopoeia", null) .addGeneratedSuggestion( - Type.SEARCH_SUGGEST, "onomatopoeia foo", null) + OmniboxSuggestionType.SEARCH_SUGGEST, + "onomatopoeia foo", null) .setAutocompleteText("oeia")), new TestSuggestionResultsBuilder() .setTextShownFor("mispellled") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_SUGGEST, "misspelled", null) - .addGeneratedSuggestion( - Type.SEARCH_SUGGEST, "misspelled words", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, + "misspelled", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, + "misspelled words", null) .setAutocompleteText("")) ); checkAutocompleteText(suggestionsMap, "wiki", "wikipedia", 4, 9); @@ -382,16 +387,22 @@ public void testDuplicateAutocompleteTextResults() new TestSuggestionResultsBuilder() .setTextShownFor("test") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testing", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testing", null) .setAutocompleteText("ing")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testz", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testz", null) .setAutocompleteText("ing")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testblarg", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testblarg", null) .setAutocompleteText("ing"))); checkAutocompleteText(suggestionsMap, "test", "testing", 4, 7); } @@ -404,16 +415,22 @@ public void testGrowingAutocompleteTextResults() new TestSuggestionResultsBuilder() .setTextShownFor("test") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testing", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testing", null) .setAutocompleteText("i")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testz", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testz", null) .setAutocompleteText("in")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testblarg", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testblarg", null) .setAutocompleteText("ing for the win"))); checkAutocompleteText(suggestionsMap, "test", "testing for the win", 4, 19); } @@ -426,16 +443,22 @@ public void testShrinkingAutocompleteTextResults() new TestSuggestionResultsBuilder() .setTextShownFor("test") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testing", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testing", null) .setAutocompleteText("ing is awesome")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testz", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testz", null) .setAutocompleteText("ing is hard")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "test", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "testblarg", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "test", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "testblarg", null) .setAutocompleteText("ingz"))); checkAutocompleteText(suggestionsMap, "test", "testingz", 4, 8); } @@ -659,19 +682,26 @@ public void run() { new TestSuggestionResultsBuilder() .setTextShownFor("ل") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "للك", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "www.test.com", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "للكتا", null)), + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "للك", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "www.test.com", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "للكتا", null)), new TestSuggestionResultsBuilder() .setTextShownFor("للك") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "للكتاب", null)), + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "للكتاب", null)), new TestSuggestionResultsBuilder() .setTextShownFor("f") .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "f", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "fa", null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, "fac", null))); + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "f", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "fa", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + "fac", null))); final TestAutocompleteController controller = new TestAutocompleteController( locationBar, locationBar, suggestionsMap); diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/QueryInOmniboxTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/QueryInOmniboxTest.java index 86496b8c5ec1a3..e4382d23148fe8 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/QueryInOmniboxTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/QueryInOmniboxTest.java @@ -22,7 +22,6 @@ import org.chromium.chrome.browser.ntp.NewTabPage; import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsReceivedListener; import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxResultItem; -import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.Type; import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.toolbar.ToolbarDataProvider; import org.chromium.chrome.test.ChromeActivityTestCaseBase; @@ -208,16 +207,22 @@ private void setupAutocompleteSuggestions(final String term) throws InterruptedE new TestSuggestionResultsBuilder() .setTextShownFor(suggestionFor) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, term , null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, term + "ng", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + term , null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + term + "ng", null) .setAutocompleteText("ng is awesome")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, term, null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, term + "z", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + term, null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + term + "z", null) .setAutocompleteText("ng is hard")) .addSuggestions(new SuggestionsResultBuilder() - .addGeneratedSuggestion(Type.SEARCH_HISTORY, term, null) - .addGeneratedSuggestion(Type.SEARCH_HISTORY, term + "blarg", null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + term, null) + .addGeneratedSuggestion(OmniboxSuggestionType.SEARCH_HISTORY, + term + "blarg", null) .setAutocompleteText("ngz"))); final Object suggestionsProcessedSignal = new Object(); diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProviderTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProviderTest.java index a9095592d438d5..6482e32cda3a69 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProviderTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/VoiceSuggestionProviderTest.java @@ -31,7 +31,8 @@ public void setUp() throws Exception { } private static OmniboxSuggestion createDummySuggestion(String text) { - return new OmniboxSuggestion(OmniboxSuggestion.Type.SEARCH_SUGGEST.nativeType(), + return new OmniboxSuggestion(OmniboxSuggestionType.SEARCH_SUGGEST, + true, 0, 1, text, @@ -77,7 +78,7 @@ private static void assertVoiceResultsAreEqual(List results, String } private static boolean assertSuggestionMatchesVoiceResult(OmniboxSuggestion a, VoiceResult b) { - return a.getType() == OmniboxSuggestion.Type.VOICE_SUGGEST && !a.isStarred() + return a.getType() == OmniboxSuggestionType.VOICE_SUGGEST && !a.isStarred() && TextUtils.equals(a.getDisplayText(), b.getMatch()); } diff --git a/chrome/browser/android/omnibox/autocomplete_controller_android.cc b/chrome/browser/android/omnibox/autocomplete_controller_android.cc index b2f554ae95c94b..1987375169f784 100644 --- a/chrome/browser/android/omnibox/autocomplete_controller_android.cc +++ b/chrome/browser/android/omnibox/autocomplete_controller_android.cc @@ -455,6 +455,7 @@ AutocompleteControllerAndroid::BuildOmniboxSuggestion( return Java_AutocompleteController_buildOmniboxSuggestion( env, match.type, + AutocompleteMatch::IsSearchType(match.type), match.relevance, match.transition, contents.obj(), diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 43a2b7371df8a6..ceb0fcf17fe6d5 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -545,6 +545,7 @@ 'shortcut_source_java', '../base/base.gyp:base', '../chrome/android/chrome_apk.gyp:custom_tabs_service_aidl', + '../components/components.gyp:autocomplete_match_type_java', '../components/components.gyp:bookmarks_java', '../components/components.gyp:dom_distiller_core_java', '../components/components.gyp:enhanced_bookmarks_java_enums_srcjar', diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java index 83b74d1ec34c8e..11ef4629053aa6 100644 --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java @@ -669,7 +669,7 @@ public void run() { * @throws InterruptedException */ protected OmniboxSuggestion findOmniboxSuggestion(String inputText, String displayText, - String url, OmniboxSuggestion.Type type) throws InterruptedException { + String url, int type) throws InterruptedException { long endTime = System.currentTimeMillis() + OMNIBOX_FIND_SUGGESTION_TIMEOUT_MS; // Multiple suggestion events may occur before the one we're interested in is received. @@ -729,7 +729,7 @@ public boolean isSatisfied() { for (int i = 0; i < count; i++) { popupItem = (OmniboxResultItem) suggestionListView.getItemAtPosition(i); suggestion = popupItem.getSuggestion(); - if (type != null && suggestion.getType() != type) { + if (suggestion.getType() != type) { continue; } if (displayText != null && !suggestion.getDisplayText().equals(displayText)) { diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/OmniboxTestUtils.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/OmniboxTestUtils.java index 3829241d1227af..690d432d3777d7 100644 --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/OmniboxTestUtils.java +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/OmniboxTestUtils.java @@ -70,9 +70,9 @@ public static class SuggestionsResultBuilder { private String mAutocompleteText; public SuggestionsResultBuilder addGeneratedSuggestion( - OmniboxSuggestion.Type type, String text, String url) { + int type, String text, String url) { mSuggestions.add(new OmniboxSuggestion( - type.nativeType(), 0, 0, text, null, null, null, "", url, url, false, false)); + type, false, 0, 0, text, null, null, null, "", url, url, false, false)); return this; } diff --git a/components/omnibox.gypi b/components/omnibox.gypi index de4558ea00a211..8b2841dc43f4a1 100644 --- a/components/omnibox.gypi +++ b/components/omnibox.gypi @@ -189,4 +189,19 @@ ], }, ], + 'conditions': [ + ['OS == "android"', { + 'targets': [ + { + # GN: //components/omnibox:autocomplete_match_type_javagen + 'target_name': 'autocomplete_match_type_java', + 'type': 'none', + 'variables': { + 'source_file': 'omnibox/browser/autocomplete_match_type.h', + }, + 'includes': [ '../build/android/java_cpp_enum.gypi' ], + }, + ], + }], + ], } diff --git a/components/omnibox/browser/BUILD.gn b/components/omnibox/browser/BUILD.gn index 21320322ac6635..0457a09d076453 100644 --- a/components/omnibox/browser/BUILD.gn +++ b/components/omnibox/browser/BUILD.gn @@ -4,6 +4,10 @@ import("//third_party/protobuf/proto_library.gni") +if (is_android) { + import("//build/config/android/rules.gni") +} + source_set("browser") { sources = [ "answers_cache.cc", @@ -135,6 +139,18 @@ source_set("browser") { ] } +if (is_android) { + # GYP: //component/omnibox.gypi:autocomplete_match_type_java + java_cpp_enum("autocomplete_match_type_javagen") { + sources = [ + "autocomplete_match_type.h", + ] + outputs = [ + "org/chromium/chrome/browser/omnibox/OmniboxSuggestionType.java", + ] + } +} + proto_library("in_memory_url_index_cache_proto") { sources = [ "in_memory_url_index_cache.proto", diff --git a/components/omnibox/browser/autocomplete_match.cc b/components/omnibox/browser/autocomplete_match.cc index aaa475634bdb3a..a980c319f80cd8 100644 --- a/components/omnibox/browser/autocomplete_match.cc +++ b/components/omnibox/browser/autocomplete_match.cc @@ -190,6 +190,7 @@ int AutocompleteMatch::TypeToIcon(Type type) { IDR_OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED IDR_OMNIBOX_CALCULATOR, // CALCULATOR IDR_OMNIBOX_HTTP, // CLIPBOARD + IDR_OMNIBOX_SEARCH, // VOICE_SEARCH }; #else static const int kIcons[] = { @@ -213,6 +214,7 @@ int AutocompleteMatch::TypeToIcon(Type type) { IDR_OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED IDR_OMNIBOX_CALCULATOR, // CALCULATOR IDR_OMNIBOX_HTTP, // CLIPBOARD + IDR_OMNIBOX_SEARCH, // VOICE_SEARCH }; #endif static_assert(arraysize(kIcons) == AutocompleteMatchType::NUM_TYPES, @@ -244,6 +246,7 @@ gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) { gfx::VectorIconId::OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED gfx::VectorIconId::OMNIBOX_CALCULATOR, // CALCULATOR gfx::VectorIconId::OMNIBOX_HTTP, // CLIPBOARD + gfx::VectorIconId::OMNIBOX_SEARCH, // VOICE_SEARCH }; static_assert(arraysize(kIcons) == AutocompleteMatchType::NUM_TYPES, "icons array must have NUM_TYPES elements"); @@ -427,6 +430,7 @@ bool AutocompleteMatch::IsSearchType(Type type) { type == AutocompleteMatchType::SEARCH_SUGGEST || type == AutocompleteMatchType::SEARCH_OTHER_ENGINE || type == AutocompleteMatchType::CALCULATOR || + type == AutocompleteMatchType::VOICE_SUGGEST || IsSpecializedSearchType(type); } diff --git a/components/omnibox/browser/autocomplete_match_type.cc b/components/omnibox/browser/autocomplete_match_type.cc index da361433717b27..597c872013fcae 100644 --- a/components/omnibox/browser/autocomplete_match_type.cc +++ b/components/omnibox/browser/autocomplete_match_type.cc @@ -29,6 +29,7 @@ std::string AutocompleteMatchType::ToString(AutocompleteMatchType::Type type) { "navsuggest-personalized", "search-calculator-answer", "url-from-clipboard", + "voice-suggest" }; static_assert(arraysize(strings) == AutocompleteMatchType::NUM_TYPES, "strings array must have NUM_TYPES elements"); diff --git a/components/omnibox/browser/autocomplete_match_type.h b/components/omnibox/browser/autocomplete_match_type.h index 1116a0ffcdd9f9..2a2464368ee2f4 100644 --- a/components/omnibox/browser/autocomplete_match_type.h +++ b/components/omnibox/browser/autocomplete_match_type.h @@ -13,6 +13,10 @@ struct AutocompleteMatchType { // // These values are stored in ShortcutsDatabase and in GetDemotionsByType() // and cannot be renumbered. + // + // Automatically generate a corresponding Java enum: + // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.omnibox + // GENERATED_JAVA_CLASS_NAME_OVERRIDE: OmniboxSuggestionType enum Type { URL_WHAT_YOU_TYPED = 0, // The input as a URL. HISTORY_URL = 1, // A past page whose URL contains the input. @@ -44,6 +48,9 @@ struct AutocompleteMatchType { NAVSUGGEST_PERSONALIZED = 17, // A personalized suggestion URL. CALCULATOR = 18, // A calculator result. CLIPBOARD = 19, // A URL based on the clipboard. + VOICE_SUGGEST = 20, // An Android-specific type which + // indicates a search from voice + // recognizer. NUM_TYPES, }; diff --git a/components/omnibox/browser/omnibox_metrics_provider.cc b/components/omnibox/browser/omnibox_metrics_provider.cc index 0ceaf9f38734b7..619ea4d69898bd 100644 --- a/components/omnibox/browser/omnibox_metrics_provider.cc +++ b/components/omnibox/browser/omnibox_metrics_provider.cc @@ -64,6 +64,9 @@ OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( return OmniboxEventProto::Suggestion::NAVSUGGEST_PERSONALIZED; case AutocompleteMatchType::CLIPBOARD: return OmniboxEventProto::Suggestion::CLIPBOARD; + case AutocompleteMatchType::VOICE_SUGGEST: + // VOICE_SUGGEST matches are only used in Java and are not logged, + // so we should never reach this case. case AutocompleteMatchType::CONTACT_DEPRECATED: case AutocompleteMatchType::NUM_TYPES: break; diff --git a/tools/android/eclipse/.classpath b/tools/android/eclipse/.classpath index 4e2050e72083bc..61d050124b7b84 100644 --- a/tools/android/eclipse/.classpath +++ b/tools/android/eclipse/.classpath @@ -98,6 +98,7 @@ to the classpath for downstream development. See "additional_entries" below. +