| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.search_engines; | 5 package org.chromium.chrome.browser.search_engines; |
| 6 | 6 |
| 7 import android.support.annotation.IntDef; | 7 import android.support.annotation.IntDef; |
| 8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
| 9 | 9 |
| 10 import org.chromium.base.ObserverList; | 10 import org.chromium.base.ObserverList; |
| 11 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
| 12 import org.chromium.base.VisibleForTesting; |
| 12 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
| 13 | 14 |
| 14 import java.lang.annotation.Retention; | 15 import java.lang.annotation.Retention; |
| 15 import java.lang.annotation.RetentionPolicy; | 16 import java.lang.annotation.RetentionPolicy; |
| 16 import java.util.ArrayList; | 17 import java.util.ArrayList; |
| 17 import java.util.List; | 18 import java.util.List; |
| 18 import java.util.regex.Matcher; | 19 import java.util.regex.Matcher; |
| 19 import java.util.regex.Pattern; | 20 import java.util.regex.Pattern; |
| 20 | 21 |
| 21 /** | 22 /** |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 367 |
| 367 /** | 368 /** |
| 368 * Finds the URL for the search engine at the given index. | 369 * Finds the URL for the search engine at the given index. |
| 369 * @param index The templateUrl index to look up. | 370 * @param index The templateUrl index to look up. |
| 370 * @return A {@link String} that contains the url of the specified sear
ch engine. | 371 * @return A {@link String} that contains the url of the specified sear
ch engine. |
| 371 */ | 372 */ |
| 372 public String getSearchEngineUrlFromTemplateUrl(String keyword) { | 373 public String getSearchEngineUrlFromTemplateUrl(String keyword) { |
| 373 return nativeGetSearchEngineUrlFromTemplateUrl(mNativeTemplateUrlService
Android, keyword); | 374 return nativeGetSearchEngineUrlFromTemplateUrl(mNativeTemplateUrlService
Android, keyword); |
| 374 } | 375 } |
| 375 | 376 |
| 377 @VisibleForTesting |
| 378 public String addSearchEngineForTesting(String keyword, int offset) { |
| 379 return nativeAddSearchEngineForTesting(mNativeTemplateUrlServiceAndroid,
keyword, offset); |
| 380 } |
| 381 |
| 382 @VisibleForTesting |
| 383 public String updateLastVisitedForTesting(String keyword) { |
| 384 return nativeUpdateLastVisitedForTesting(mNativeTemplateUrlServiceAndroi
d, keyword); |
| 385 } |
| 386 |
| 376 private native long nativeInit(); | 387 private native long nativeInit(); |
| 377 private native void nativeLoad(long nativeTemplateUrlServiceAndroid); | 388 private native void nativeLoad(long nativeTemplateUrlServiceAndroid); |
| 378 private native boolean nativeIsLoaded(long nativeTemplateUrlServiceAndroid); | 389 private native boolean nativeIsLoaded(long nativeTemplateUrlServiceAndroid); |
| 379 private native int nativeGetTemplateUrlCount(long nativeTemplateUrlServiceAn
droid); | 390 private native int nativeGetTemplateUrlCount(long nativeTemplateUrlServiceAn
droid); |
| 380 private native TemplateUrl nativeGetTemplateUrlAt(long nativeTemplateUrlServ
iceAndroid, int i); | 391 private native TemplateUrl nativeGetTemplateUrlAt(long nativeTemplateUrlServ
iceAndroid, int i); |
| 381 private native void nativeSetUserSelectedDefaultSearchProvider( | 392 private native void nativeSetUserSelectedDefaultSearchProvider( |
| 382 long nativeTemplateUrlServiceAndroid, String selectedKeyword); | 393 long nativeTemplateUrlServiceAndroid, String selectedKeyword); |
| 383 private native int nativeGetDefaultSearchProviderIndex(long nativeTemplateUr
lServiceAndroid); | 394 private native int nativeGetDefaultSearchProviderIndex(long nativeTemplateUr
lServiceAndroid); |
| 384 private native boolean nativeIsSearchProviderManaged(long nativeTemplateUrlS
erviceAndroid); | 395 private native boolean nativeIsSearchProviderManaged(long nativeTemplateUrlS
erviceAndroid); |
| 385 private native boolean nativeIsSearchByImageAvailable(long nativeTemplateUrl
ServiceAndroid); | 396 private native boolean nativeIsSearchByImageAvailable(long nativeTemplateUrl
ServiceAndroid); |
| 386 private native boolean nativeIsDefaultSearchEngineGoogle(long nativeTemplate
UrlServiceAndroid); | 397 private native boolean nativeIsDefaultSearchEngineGoogle(long nativeTemplate
UrlServiceAndroid); |
| 387 private native String nativeGetUrlForSearchQuery(long nativeTemplateUrlServi
ceAndroid, | 398 private native String nativeGetUrlForSearchQuery(long nativeTemplateUrlServi
ceAndroid, |
| 388 String query); | 399 String query); |
| 389 private native String nativeGetUrlForVoiceSearchQuery(long nativeTemplateUrl
ServiceAndroid, | 400 private native String nativeGetUrlForVoiceSearchQuery(long nativeTemplateUrl
ServiceAndroid, |
| 390 String query); | 401 String query); |
| 391 private native String nativeReplaceSearchTermsInUrl(long nativeTemplateUrlSe
rviceAndroid, | 402 private native String nativeReplaceSearchTermsInUrl(long nativeTemplateUrlSe
rviceAndroid, |
| 392 String query, String currentUrl); | 403 String query, String currentUrl); |
| 393 private native String nativeGetUrlForContextualSearchQuery(long nativeTempla
teUrlServiceAndroid, | 404 private native String nativeGetUrlForContextualSearchQuery(long nativeTempla
teUrlServiceAndroid, |
| 394 String query, String alternateTerm, boolean shouldPrefetch, String p
rotocolVersion); | 405 String query, String alternateTerm, boolean shouldPrefetch, String p
rotocolVersion); |
| 395 private native String nativeGetSearchEngineUrlFromTemplateUrl( | 406 private native String nativeGetSearchEngineUrlFromTemplateUrl( |
| 396 long nativeTemplateUrlServiceAndroid, String keyword); | 407 long nativeTemplateUrlServiceAndroid, String keyword); |
| 408 private native String nativeAddSearchEngineForTesting( |
| 409 long nativeTemplateUrlServiceAndroid, String keyword, int offset); |
| 410 private native String nativeUpdateLastVisitedForTesting( |
| 411 long nativeTemplateUrlServiceAndroid, String keyword); |
| 397 } | 412 } |
| OLD | NEW |