Commit 27a94038 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: improve locale for getSafeBrowsingPrivacyPolicyUrl

This API returns a URL containing the locale as a query parameter. The
Google help center uses this to decide in which language to display the
page. The old method for obtaining the locale would sometimes return a
locale in a format the help center didn't recognize (e.g., "cs-CZ").
Instead, use the UIManager to fetch the locale, to stay consistent with
how we generate the URL for actual interstitial pages.

This new approach seems more consistent with the help center's
expectations (e.g., "cs" instead of "cs-CZ").

the API, observe the page displays in the proper language

Bug: 820694
Test: manual - Put device in Czech (cs/cs-CZ) and visit the url returned
Change-Id: I72606a2eee00f5b1890f703593267e93fdd645ff
Reviewed-on: https://chromium-review.googlesource.com/958229Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542610}
parent 71b147d2
......@@ -358,7 +358,6 @@ AwBrowserContext::GetWebRestrictionProvider() {
}
AwSafeBrowsingUIManager* AwBrowserContext::GetSafeBrowsingUIManager() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
return safe_browsing_ui_manager_.get();
}
......
......@@ -58,10 +58,13 @@ ScopedJavaLocalRef<jstring>
JNI_AwContentsStatics_GetSafeBrowsingPrivacyPolicyUrl(
JNIEnv* env,
const JavaParamRef<jclass>&) {
// TODO(ntfschr): limit this to only the UI thread.
GURL privacy_policy_url(
security_interstitials::kSafeBrowsingPrivacyPolicyUrl);
privacy_policy_url = google_util::AppendGoogleLocaleParam(
privacy_policy_url, AwContents::GetLocale());
std::string locale =
AwBrowserContext::GetDefault()->GetSafeBrowsingUIManager()->app_locale();
privacy_policy_url =
google_util::AppendGoogleLocaleParam(privacy_policy_url, locale);
return base::android::ConvertUTF8ToJavaString(env, privacy_policy_url.spec());
}
......
......@@ -92,6 +92,9 @@ public class SafeBrowsingTest {
// Used to check which thread a callback is invoked on.
private volatile boolean mOnUiThread;
// Used to verify the getSafeBrowsingPrivacyPolicyUrl() API.
private volatile Uri mPrivacyPolicyUrl;
// These colors correspond to the body.background attribute in GREEN_HTML_PATH, SAFE_HTML_PATH,
// MALWARE_HTML_PATH, IFRAME_HTML_PATH, etc. They should only be changed if those values are
// changed as well
......@@ -1118,7 +1121,9 @@ public class SafeBrowsingTest {
.appendQueryParameter("hl", LocaleUtils.getDefaultLocaleString())
.fragment("safe-browsing-policies")
.build();
Assert.assertEquals(privacyPolicyUrl, AwContentsStatics.getSafeBrowsingPrivacyPolicyUrl());
Assert.assertNotNull(AwContentsStatics.getSafeBrowsingPrivacyPolicyUrl());
ThreadUtils.runOnUiThreadBlocking(
() -> { mPrivacyPolicyUrl = AwContentsStatics.getSafeBrowsingPrivacyPolicyUrl(); });
Assert.assertEquals(privacyPolicyUrl, this.mPrivacyPolicyUrl);
Assert.assertNotNull(this.mPrivacyPolicyUrl);
}
}
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