0

Append the safe search parameter to the safe search settings page

When accessing the safe searching setting page google.com/safesearch,
automatically append the parameter if safe searching is forced by policy
so that the page will also be disabled.

Bug: 1485831
Change-Id: I782e1729f40e57c7fe725edce6828cbe17f34b10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4969035
Reviewed-by: Marc Treib <treib@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1214233}
This commit is contained in:
Owen Min
2023-10-24 15:56:53 +00:00
committed by Chromium LUCI CQ
parent 4c57b52798
commit 990ba76965
2 changed files with 23 additions and 1 deletions

@ -55,6 +55,16 @@ std::string AddSafeSearchParameters(const std::string& query) {
return base::JoinString(new_parameters, "&");
}
bool IsSafeSearchSettingUrl(const GURL& url) {
if (!google_util::IsGoogleDomainUrl(
url, google_util::ALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS)) {
return false;
}
return url.path_piece() == "/safesearch";
}
} // namespace
namespace safe_search_api {
@ -71,7 +81,7 @@ const char kGoogleAppsAllowedDomains[] = "X-GoogApps-Allowed-Domains";
// Sets the query part of |new_url| with the new value of the parameters.
void ForceGoogleSafeSearch(const GURL& url, GURL* new_url) {
if (!google_util::IsGoogleSearchUrl(url) &&
!google_util::IsGoogleHomePageUrl(url)) {
!google_util::IsGoogleHomePageUrl(url) && !IsSafeSearchSettingUrl(url)) {
return;
}

@ -123,6 +123,18 @@ TEST(SafeSearchUtilTest, AddGoogleSafeSearchParams) {
"imgurl=https://image&" + kBothParameters);
}
TEST(SafeSearchUtilTest, SafeSearchSettingsPage) {
const std::string kBothParameters =
std::string(safe_search_api::kSafeSearchSafeParameter) + "&" +
safe_search_api::kSafeSearchSsuiParameter;
CheckAddedParameters("https://www.google.com/safesearch", kBothParameters);
CheckAddedParameters("https://google.ca/safesearch", kBothParameters);
CheckAddedParameters("https://ipv4.google.com/safesearch", kBothParameters);
CheckAddedParameters("https://ipv4.google.com/safesearch?safe=off",
kBothParameters);
}
TEST(SafeSearchUtilTest, SetYoutubeHeader) {
net::HttpRequestHeaders headers;
safe_search_api::ForceYouTubeRestrict(