Commit 72af9100 authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

[TTS] Enable displaying non-search pages for TTS.

Enables showing Google pages in the Contextual Search Overlay panel
that are not Google Search pages.  The canonical example is to show
a maps page when a location is detected.

Also add UrlUtilities.isGoogleSubdomainUrl.

BUG=939460

Change-Id: I7c7b8f1095c421821e7fa810cba2ee55f0a47160
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574780
Commit-Queue: Donn Denman <donnd@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652567}
parent 9f88460d
......@@ -30,6 +30,7 @@ class ContextualSearchRequest {
private boolean mIsTranslationForced;
private boolean mIsFullSearchUrlProvided;
private static final String GWS_NORMAL_PRIORITY_SEARCH_PATH = "search";
private static final String GWS_LOW_PRIORITY_SEARCH_PATH = "s";
private static final String GWS_SEARCH_NO_SUGGESTIONS_PARAM = "sns";
private static final String GWS_SEARCH_NO_SUGGESTIONS_PARAM_VALUE = "1";
......@@ -233,13 +234,18 @@ class ContextualSearchRequest {
*/
@VisibleForTesting
boolean isGoogleUrl(@Nullable String someUrl) {
return !TextUtils.isEmpty(someUrl) && UrlUtilities.nativeIsGoogleDomainUrl(someUrl, true);
return !TextUtils.isEmpty(someUrl) && UrlUtilities.nativeIsGoogleSubDomainUrl(someUrl);
}
/**
* @return a low-priority {@code Uri} from the given base {@code Uri}.
*/
private Uri makeLowPriorityUri(Uri baseUri) {
if (baseUri.getPath() == null
|| !baseUri.getPath().contains(GWS_NORMAL_PRIORITY_SEARCH_PATH)) {
return baseUri;
}
return baseUri.buildUpon()
.path(GWS_LOW_PRIORITY_SEARCH_PATH)
.appendQueryParameter(
......
......@@ -368,9 +368,15 @@ public class UrlUtilities {
boolean includePrivateRegistries);
private static native String nativeGetDomainAndRegistry(String url,
boolean includePrivateRegistries);
/** Returns whether the given URL uses the Google.com domain. */
public static native boolean nativeIsGoogleDomainUrl(String url, boolean allowNonStandardPort);
/** Returns whether the given URL is a Google.com domain or sub-domain. */
public static native boolean nativeIsGoogleSubDomainUrl(String url);
/** Returns whether the given URL is a Google.com Search URL. */
public static native boolean nativeIsGoogleSearchUrl(String url);
/** Returns whether the given URL is the Google Web Search URL. */
public static native boolean nativeIsGoogleHomePageUrl(String url);
private static native boolean nativeIsUrlWithinScope(String url, String scopeUrl);
private static native boolean nativeUrlsMatchIgnoringFragments(String url, String url2);
private static native boolean nativeUrlsFragmentsDiffer(String url, String url2);
......
......@@ -55,6 +55,8 @@ net::registry_controlled_domains::PrivateRegistryFilter GetRegistryFilter(
} // namespace
// Returns whether the given URLs have the same domain or host.
// See net::registry_controlled_domains::SameDomainOrHost for details.
static jboolean JNI_UrlUtilities_SameDomainOrHost(
JNIEnv* env,
const JavaParamRef<jstring>& url_1_str,
......@@ -71,6 +73,8 @@ static jboolean JNI_UrlUtilities_SameDomainOrHost(
filter);
}
// Returns the Domain and Registry of the given URL.
// See net::registry_controlled_domains::GetDomainAndRegistry for details.
static ScopedJavaLocalRef<jstring> JNI_UrlUtilities_GetDomainAndRegistry(
JNIEnv* env,
const JavaParamRef<jstring>& url,
......@@ -88,6 +92,8 @@ static ScopedJavaLocalRef<jstring> JNI_UrlUtilities_GetDomainAndRegistry(
net::registry_controlled_domains::GetDomainAndRegistry(gurl, filter));
}
// Return whether the given URL uses the Google.com domain.
// See google_util::IsGoogleDomainUrl for details.
static jboolean JNI_UrlUtilities_IsGoogleDomainUrl(
JNIEnv* env,
const JavaParamRef<jstring>& url,
......@@ -102,6 +108,21 @@ static jboolean JNI_UrlUtilities_IsGoogleDomainUrl(
: google_util::DISALLOW_NON_STANDARD_PORTS);
}
// Returns whether the given URL is a Google.com domain or sub-domain.
// See google_util::IsGoogleDomainUrl for details.
static jboolean JNI_UrlUtilities_IsGoogleSubDomainUrl(
JNIEnv* env,
const JavaParamRef<jstring>& url) {
GURL gurl = JNI_UrlUtilities_ConvertJavaStringToGURL(env, url);
if (gurl.is_empty())
return false;
return google_util::IsGoogleDomainUrl(
gurl, google_util::ALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS);
}
// Returns whether the given URL is a Google.com Search URL.
// See google_util::IsGoogleSearchUrl for details.
static jboolean JNI_UrlUtilities_IsGoogleSearchUrl(
JNIEnv* env,
const JavaParamRef<jstring>& url) {
......@@ -111,6 +132,8 @@ static jboolean JNI_UrlUtilities_IsGoogleSearchUrl(
return google_util::IsGoogleSearchUrl(gurl);
}
// Returns whether the given URL is the Google Web Search URL.
// See google_util::IsGoogleHomePageUrl for details.
static jboolean JNI_UrlUtilities_IsGoogleHomePageUrl(
JNIEnv* env,
const JavaParamRef<jstring>& url) {
......@@ -131,6 +154,8 @@ static jboolean JNI_UrlUtilities_IsUrlWithinScope(
base::CompareCase::SENSITIVE);
}
// Returns whether the given URLs match, ignoring the fragment portions of the
// URLs.
static jboolean JNI_UrlUtilities_UrlsMatchIgnoringFragments(
JNIEnv* env,
const JavaParamRef<jstring>& url,
......@@ -148,6 +173,7 @@ static jboolean JNI_UrlUtilities_UrlsMatchIgnoringFragments(
gurl2.ReplaceComponents(replacements);
}
// Returns whether the given URLs have fragments that differ.
static jboolean JNI_UrlUtilities_UrlsFragmentsDiffer(
JNIEnv* env,
const JavaParamRef<jstring>& url,
......
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