Upstream AutocompleteController and related classes.

Upstreams AutocompleteController and OmniboxSuggestion on java side.
Upstreams autocomplete_bridge.cc and renames it to
autocomplete_controller_android.cc.

BUG=222130

Review URL: https://codereview.chromium.org/285633002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270861 0039d316-1c4b-4281-b951-d872f2087c98
parent 414dc0cd
// 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;
import android.text.TextUtils;
import com.google.common.annotations.VisibleForTesting;
/**
* Container class with information about each omnibox suggestion item.
*/
@VisibleForTesting
public class OmniboxSuggestion {
private final Type mType;
private final String mDisplayText;
private final String mDescription;
private final String mFillIntoEdit;
private final String mUrl;
private final String mFormattedUrl;
private final int mRelevance;
private final int mTransition;
private final boolean mIsStarred;
private final boolean mIsDeletable;
/**
* This should be kept in sync with AutocompleteMatch::Type
* (see chrome/common/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_INFINITE (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,
String text, String description, String fillIntoEdit, String url,
String formattedUrl, boolean isStarred, boolean isDeletable) {
mType = Type.getTypeFromNativeType(nativeType);
mRelevance = relevance;
mTransition = transition;
mDisplayText = text;
mDescription = description;
mFillIntoEdit = TextUtils.isEmpty(fillIntoEdit) ? text : fillIntoEdit;
mUrl = url;
mFormattedUrl = formattedUrl;
mIsStarred = isStarred;
mIsDeletable = isDeletable;
}
public Type getType() {
return mType;
}
public int getTransition() {
return mTransition;
}
public String getDisplayText() {
return mDisplayText;
}
public String getDescription() {
return mDescription;
}
public String getFillIntoEdit() {
return mFillIntoEdit;
}
public String getUrl() {
return mUrl;
}
public String getFormattedUrl() {
return mFormattedUrl;
}
public boolean isUrlSuggestion() {
return mType.isUrl();
}
/**
* @return Whether this suggestion represents a starred/bookmarked URL.
*/
public boolean isStarred() {
return mIsStarred;
}
public boolean isDeletable() {
return mIsDeletable;
}
@Override
public String toString() {
return mType + " relevance=" + mRelevance + " \"" + mDisplayText + "\" -> " + mUrl;
}
@Override
public int hashCode() {
return 37 * mType.mNativeType + mDisplayText.hashCode() + mFillIntoEdit.hashCode() +
(mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof OmniboxSuggestion)) {
return false;
}
OmniboxSuggestion suggestion = (OmniboxSuggestion) obj;
return mType == suggestion.mType
&& mFillIntoEdit.equals(suggestion.mFillIntoEdit)
&& mDisplayText.equals(suggestion.mDisplayText)
&& mIsStarred == suggestion.mIsStarred
&& mIsDeletable == suggestion.mIsDeletable;
}
}
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/android/logo_bridge.h" #include "chrome/browser/android/logo_bridge.h"
#include "chrome/browser/android/most_visited_sites.h" #include "chrome/browser/android/most_visited_sites.h"
#include "chrome/browser/android/new_tab_page_prefs.h" #include "chrome/browser/android/new_tab_page_prefs.h"
#include "chrome/browser/android/omnibox/autocomplete_controller_android.h"
#include "chrome/browser/android/omnibox/omnibox_prerender.h" #include "chrome/browser/android/omnibox/omnibox_prerender.h"
#include "chrome/browser/android/password_authentication_manager.h" #include "chrome/browser/android/password_authentication_manager.h"
#include "chrome/browser/android/password_ui_view_android.h" #include "chrome/browser/android/password_ui_view_android.h"
...@@ -96,6 +97,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = { ...@@ -96,6 +97,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
AndroidProfileOAuth2TokenService::Register }, AndroidProfileOAuth2TokenService::Register },
{ "AppBannerManager", banners::RegisterAppBannerManager }, { "AppBannerManager", banners::RegisterAppBannerManager },
{ "ApplicationLifetime", RegisterApplicationLifetimeAndroid }, { "ApplicationLifetime", RegisterApplicationLifetimeAndroid },
{ "AutocompleteControllerAndroid", RegisterAutocompleteControllerAndroid },
{ "AutofillDialogControllerAndroid", { "AutofillDialogControllerAndroid",
autofill::AutofillDialogControllerAndroid:: autofill::AutofillDialogControllerAndroid::
RegisterAutofillDialogControllerAndroid }, RegisterAutofillDialogControllerAndroid },
......
// 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.
#ifndef CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_
#define CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_
#include <string>
#include "base/android/jni_weak_ref.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
class AutocompleteController;
struct AutocompleteMatch;
class AutocompleteResult;
class Profile;
class Tab;
// The native part of the Java AutocompleteController class.
class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
public KeyedService {
public:
explicit AutocompleteControllerAndroid(Profile* profile);
// Methods that forward to AutocompleteController:
void Start(JNIEnv* env,
jobject obj,
jstring j_text,
jstring j_desired_tld,
jstring j_current_url,
bool prevent_inline_autocomplete,
bool prefer_keyword,
bool allow_exact_keyword_match,
bool best_match_only);
base::android::ScopedJavaLocalRef<jobject> Classify(JNIEnv* env,
jobject obj,
jstring j_text);
void StartZeroSuggest(JNIEnv* env,
jobject obj,
jstring j_omnibox_text,
jstring j_current_url,
jboolean is_query_in_omnibox,
jboolean focused_from_fakebox);
void Stop(JNIEnv* env, jobject obj, bool clear_result);
void ResetSession(JNIEnv* env, jobject obj);
void OnSuggestionSelected(JNIEnv* env,
jobject obj,
jint selected_index,
jstring j_current_url,
jboolean is_query_in_omnibox,
jboolean focused_from_fakebox,
jlong elapsed_time_since_first_modified,
jobject j_web_contents);
void DeleteSuggestion(JNIEnv* env, jobject obj, int selected_index);
base::android::ScopedJavaLocalRef<jstring> UpdateMatchDestinationURL(
JNIEnv* env,
jobject obj,
jint selected_index,
jlong elapsed_time_since_input_change);
// KeyedService:
virtual void Shutdown() OVERRIDE;
class Factory : public BrowserContextKeyedServiceFactory {
public:
static AutocompleteControllerAndroid* GetForProfile(Profile* profile,
JNIEnv* env,
jobject obj);
static Factory* GetInstance();
protected:
virtual content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const OVERRIDE;
private:
friend struct DefaultSingletonTraits<Factory>;
Factory();
virtual ~Factory();
// BrowserContextKeyedServiceFactory
virtual KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const OVERRIDE;
};
private:
virtual ~AutocompleteControllerAndroid();
void InitJNI(JNIEnv* env, jobject obj);
// AutocompleteControllerDelegate implementation.
virtual void OnResultChanged(bool default_match_changed) OVERRIDE;
// Notifies the Java AutocompleteController that suggestions were received
// based on the text the user typed in last.
void NotifySuggestionsReceived(
const AutocompleteResult& autocomplete_result);
// Classifies the type of page we are on.
AutocompleteInput::PageClassification ClassifyPage(
const GURL& gurl,
bool is_query_in_omnibox,
bool focused_from_fakebox) const;
base::android::ScopedJavaLocalRef<jobject> BuildOmniboxSuggestion(
JNIEnv* env, const AutocompleteMatch& match);
// Converts destination_url (which is in its canonical form or punycode) to a
// user-friendly URL by looking up accept languages of the current profile.
// e.g. http://xn--6q8b.kr/ --> 한.kr
base::string16 FormatURLUsingAcceptLanguages(GURL url);
scoped_ptr<AutocompleteController> autocomplete_controller_;
// Last input we sent to the autocomplete controller.
AutocompleteInput input_;
// Whether we're currently inside a call to Classify().
bool inside_classify_;
JavaObjectWeakGlobalRef weak_java_autocomplete_controller_android_;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(AutocompleteControllerAndroid);
};
// Registers the LocationBar native method.
bool RegisterAutocompleteControllerAndroid(JNIEnv* env);
#endif // CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_
...@@ -173,6 +173,8 @@ ...@@ -173,6 +173,8 @@
'browser/android/intercept_download_resource_throttle.h', 'browser/android/intercept_download_resource_throttle.h',
'browser/android/most_visited_sites.cc', 'browser/android/most_visited_sites.cc',
'browser/android/most_visited_sites.h', 'browser/android/most_visited_sites.h',
'browser/android/omnibox/autocomplete_controller_android.cc',
'browser/android/omnibox/autocomplete_controller_android.h',
'browser/android/omnibox/omnibox_prerender.cc', 'browser/android/omnibox/omnibox_prerender.cc',
'browser/android/omnibox/omnibox_prerender.h', 'browser/android/omnibox/omnibox_prerender.h',
'browser/android/password_authentication_manager.cc', 'browser/android/password_authentication_manager.cc',
...@@ -3600,6 +3602,7 @@ ...@@ -3600,6 +3602,7 @@
'android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java', 'android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java',
'android/java/src/org/chromium/chrome/browser/NavigationPopup.java', 'android/java/src/org/chromium/chrome/browser/NavigationPopup.java',
'android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java', 'android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java',
'android/java/src/org/chromium/chrome/browser/omnibox/AutocompleteController.java',
'android/java/src/org/chromium/chrome/browser/omnibox/OmniboxPrerender.java', 'android/java/src/org/chromium/chrome/browser/omnibox/OmniboxPrerender.java',
'android/java/src/org/chromium/chrome/browser/password_manager/PasswordAuthenticationManager.java', 'android/java/src/org/chromium/chrome/browser/password_manager/PasswordAuthenticationManager.java',
'android/java/src/org/chromium/chrome/browser/PasswordUIView.java', 'android/java/src/org/chromium/chrome/browser/PasswordUIView.java',
......
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