Move safe search utility to safe_search_api component.
The supervised user service, one of the main clients of SafeSearch APIs is migrating to components/ to allow cross-platform URL filtering support. Move relevant utilities to components to be able to use post migration. Bug: b/267471715 Change-Id: I4fc2bfaed72df8b1d214ed55b23084636717ee0c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4329546 Reviewed-by: Marc Treib <treib@chromium.org> Commit-Queue: Nohemi Fernandez <fernandex@chromium.org> Cr-Commit-Position: refs/heads/main@{#1116507}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
d813f77556
commit
05d59a2a09
chrome
browser
common
test
components/safe_search_api
@ -54,7 +54,6 @@
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
#include "chrome/common/chrome_features.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pdf_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "chrome/grit/generated_resources.h"
|
||||
@ -71,6 +70,7 @@
|
||||
#include "components/safe_browsing/content/browser/download/download_stats.h"
|
||||
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
|
||||
#include "components/safe_browsing/content/common/file_type_policies.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "components/services/quarantine/public/mojom/quarantine.mojom.h"
|
||||
#include "components/services/quarantine/quarantine_impl.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
@ -851,7 +851,7 @@ void ChromeDownloadManagerDelegate::SanitizeDownloadParameters(
|
||||
download::DownloadUrlParameters* params) {
|
||||
if (profile_->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch)) {
|
||||
GURL safe_url;
|
||||
safe_search_util::ForceGoogleSafeSearch(params->url(), &safe_url);
|
||||
safe_search_api::ForceGoogleSafeSearch(params->url(), &safe_url);
|
||||
if (!safe_url.is_empty())
|
||||
params->set_url(std::move(safe_url));
|
||||
}
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "chrome/common/chrome_features.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
||||
#include "chrome/test/base/testing_browser_process.h"
|
||||
@ -52,6 +51,7 @@
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/safe_browsing/buildflags.h"
|
||||
#include "components/safe_browsing/core/common/features.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "components/sync_preferences/testing_pref_service_syncable.h"
|
||||
#include "content/public/browser/download_item_utils.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
@ -1429,7 +1429,7 @@ TEST_F(ChromeDownloadManagerDelegateTest, SanitizeGoogleSearchLink) {
|
||||
delegate()->SanitizeDownloadParameters(¶ms);
|
||||
GURL expected_url = kGoogleSearchUrl;
|
||||
if (is_safe_search_enabled)
|
||||
safe_search_util::ForceGoogleSafeSearch(expected_url, &expected_url);
|
||||
safe_search_api::ForceGoogleSafeSearch(expected_url, &expected_url);
|
||||
EXPECT_EQ(params.url(), expected_url);
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +122,7 @@ source_set("test_support") {
|
||||
"//chrome/test:test_support",
|
||||
"//components/policy/core/common",
|
||||
"//components/policy/core/common:common_constants",
|
||||
"//components/safe_search_api",
|
||||
"//components/security_interstitials/content:security_interstitial_page",
|
||||
"//url:url",
|
||||
]
|
||||
|
@ -20,9 +20,9 @@
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "chrome/browser/lifetime/termination_notification.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "components/policy/core/browser/browser_policy_connector.h"
|
||||
#include "components/policy/policy_constants.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/network_service_util.h"
|
||||
|
@ -7,10 +7,10 @@
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_window.h"
|
||||
#include "chrome/browser/ui/location_bar/location_bar.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/test/base/ui_test_utils.h"
|
||||
#include "components/omnibox/browser/omnibox_edit_model.h"
|
||||
#include "components/policy/policy_constants.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "content/public/test/test_navigation_observer.h"
|
||||
|
||||
namespace policy {
|
||||
@ -38,8 +38,8 @@ GURL SafeSearchPolicyTest::GetExpectedSearchURL(bool expect_safe_search) {
|
||||
std::string expected_url("http://google.com/");
|
||||
if (expect_safe_search) {
|
||||
expected_url += "?" +
|
||||
std::string(safe_search_util::kSafeSearchSafeParameter) +
|
||||
"&" + safe_search_util::kSafeSearchSsuiParameter;
|
||||
std::string(safe_search_api::kSafeSearchSafeParameter) +
|
||||
"&" + safe_search_api::kSafeSearchSsuiParameter;
|
||||
}
|
||||
return GURL(expected_url);
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "chrome/browser/ui/browser_commands.h"
|
||||
#include "chrome/browser/ui/browser_window.h"
|
||||
#include "chrome/browser/ui/location_bar/location_bar.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "chrome/test/base/search_test_utils.h"
|
||||
#include "chrome/test/base/ui_test_utils.h"
|
||||
@ -25,6 +24,7 @@
|
||||
#include "components/policy/core/common/policy_types.h"
|
||||
#include "components/policy/policy_constants.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "components/search_engines/template_url.h"
|
||||
#include "components/search_engines/template_url_service.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
@ -10,13 +10,13 @@
|
||||
#include "chrome/browser/policy/safe_search_policy_test.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/policy/core/common/policy_map.h"
|
||||
#include "components/policy/core/common/policy_pref_names.h"
|
||||
#include "components/policy/core/common/policy_types.h"
|
||||
#include "components/policy/policy_constants.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "content/public/test/browser_test.h"
|
||||
#include "content/public/test/browser_test_utils.h"
|
||||
#include "content/public/test/url_loader_interceptor.h"
|
||||
@ -27,17 +27,17 @@
|
||||
namespace policy {
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(SafeSearchPolicyTest, LegacySafeSearch) {
|
||||
static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 &&
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 &&
|
||||
safe_search_util::YOUTUBE_RESTRICT_STRICT == 2 &&
|
||||
safe_search_util::YOUTUBE_RESTRICT_COUNT == 3,
|
||||
static_assert(safe_search_api::YOUTUBE_RESTRICT_OFF == 0 &&
|
||||
safe_search_api::YOUTUBE_RESTRICT_MODERATE == 1 &&
|
||||
safe_search_api::YOUTUBE_RESTRICT_STRICT == 2 &&
|
||||
safe_search_api::YOUTUBE_RESTRICT_COUNT == 3,
|
||||
"This test relies on mapping ints to enum values.");
|
||||
|
||||
// Go over all combinations of (undefined, true, false) for the policies
|
||||
// ForceSafeSearch, ForceGoogleSafeSearch and ForceYouTubeSafetyMode as well
|
||||
// as (undefined, off, moderate, strict) for ForceYouTubeRestrict and make
|
||||
// sure the prefs are set as expected.
|
||||
const int num_restrict_modes = 1 + safe_search_util::YOUTUBE_RESTRICT_COUNT;
|
||||
const int num_restrict_modes = 1 + safe_search_api::YOUTUBE_RESTRICT_COUNT;
|
||||
for (int i = 0; i < 3 * 3 * 3 * num_restrict_modes; i++) {
|
||||
int val = i;
|
||||
int legacy_safe_search = val % 3;
|
||||
@ -102,10 +102,10 @@ IN_PROC_BROWSER_TEST_F(SafeSearchPolicyTest, LegacySafeSearch) {
|
||||
prefs->GetInteger(prefs::kForceYouTubeRestrict));
|
||||
} else {
|
||||
// The legacy modes should result in MODERATE strictness, if enabled.
|
||||
safe_search_util::YouTubeRestrictMode expected_mode =
|
||||
safe_search_api::YouTubeRestrictMode expected_mode =
|
||||
legacy_safe_search_enabled || legacy_youtube_enabled
|
||||
? safe_search_util::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_util::YOUTUBE_RESTRICT_OFF;
|
||||
? safe_search_api::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_api::YOUTUBE_RESTRICT_OFF;
|
||||
EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict), expected_mode);
|
||||
}
|
||||
}
|
||||
|
@ -12,13 +12,13 @@
|
||||
#include "chrome/browser/policy/safe_search_policy_test.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/test/base/in_process_browser_test.h"
|
||||
#include "chrome/test/base/ui_test_utils.h"
|
||||
#include "components/google/core/common/google_switches.h"
|
||||
#include "components/network_session_configurator/common/network_switches.h"
|
||||
#include "components/policy/core/common/policy_map.h"
|
||||
#include "components/policy/policy_constants.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "content/public/test/browser_test.h"
|
||||
#include "content/public/test/browser_test_utils.h"
|
||||
#include "net/http/http_request_headers.h"
|
||||
@ -32,28 +32,27 @@ namespace policy {
|
||||
void CheckYouTubeRestricted(int youtube_restrict_mode,
|
||||
const net::HttpRequestHeaders& headers) {
|
||||
std::string header;
|
||||
headers.GetHeader(safe_search_util::kYouTubeRestrictHeaderName, &header);
|
||||
if (youtube_restrict_mode == safe_search_util::YOUTUBE_RESTRICT_OFF) {
|
||||
headers.GetHeader(safe_search_api::kYouTubeRestrictHeaderName, &header);
|
||||
if (youtube_restrict_mode == safe_search_api::YOUTUBE_RESTRICT_OFF) {
|
||||
EXPECT_TRUE(header.empty());
|
||||
} else if (youtube_restrict_mode ==
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE) {
|
||||
EXPECT_EQ(header, safe_search_util::kYouTubeRestrictHeaderValueModerate);
|
||||
safe_search_api::YOUTUBE_RESTRICT_MODERATE) {
|
||||
EXPECT_EQ(header, safe_search_api::kYouTubeRestrictHeaderValueModerate);
|
||||
} else if (youtube_restrict_mode ==
|
||||
safe_search_util::YOUTUBE_RESTRICT_STRICT) {
|
||||
EXPECT_EQ(header, safe_search_util::kYouTubeRestrictHeaderValueStrict);
|
||||
safe_search_api::YOUTUBE_RESTRICT_STRICT) {
|
||||
EXPECT_EQ(header, safe_search_api::kYouTubeRestrictHeaderValueStrict);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckAllowedDomainsHeader(const std::string& allowed_domain,
|
||||
const net::HttpRequestHeaders& headers) {
|
||||
if (allowed_domain.empty()) {
|
||||
EXPECT_TRUE(
|
||||
!headers.HasHeader(safe_search_util::kGoogleAppsAllowedDomains));
|
||||
EXPECT_TRUE(!headers.HasHeader(safe_search_api::kGoogleAppsAllowedDomains));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string header;
|
||||
headers.GetHeader(safe_search_util::kGoogleAppsAllowedDomains, &header);
|
||||
headers.GetHeader(safe_search_api::kGoogleAppsAllowedDomains, &header);
|
||||
EXPECT_EQ(header, allowed_domain);
|
||||
}
|
||||
|
||||
@ -136,8 +135,8 @@ IN_PROC_BROWSER_TEST_P(PolicyTestGoogle, ForceGoogleSafeSearch) {
|
||||
IN_PROC_BROWSER_TEST_P(PolicyTestGoogle, ForceYouTubeRestrict) {
|
||||
GURL youtube_url(https_server()->GetURL("youtube.com", "/empty.html"));
|
||||
GURL youtube_script(https_server()->GetURL("youtube.com", "/json2.js"));
|
||||
for (int youtube_restrict_mode = safe_search_util::YOUTUBE_RESTRICT_OFF;
|
||||
youtube_restrict_mode < safe_search_util::YOUTUBE_RESTRICT_COUNT;
|
||||
for (int youtube_restrict_mode = safe_search_api::YOUTUBE_RESTRICT_OFF;
|
||||
youtube_restrict_mode < safe_search_api::YOUTUBE_RESTRICT_COUNT;
|
||||
++youtube_restrict_mode) {
|
||||
ApplySafeSearchPolicy(absl::nullopt, // ForceSafeSearch (legacy)
|
||||
absl::nullopt, // ForceGoogleSafeSearch
|
||||
@ -160,18 +159,17 @@ IN_PROC_BROWSER_TEST_P(PolicyTestGoogle, ForceYouTubeRestrict) {
|
||||
urls_requested()[youtube_script.path()]);
|
||||
}
|
||||
|
||||
if (youtube_restrict_mode != safe_search_util::YOUTUBE_RESTRICT_OFF) {
|
||||
if (youtube_restrict_mode != safe_search_api::YOUTUBE_RESTRICT_OFF) {
|
||||
// If a restriction is active, disable it while the page is open to check
|
||||
// that renderer rules are properly updated when a renderer is running.
|
||||
ApplySafeSearchPolicy(
|
||||
absl::nullopt, // ForceSafeSearch (legacy)
|
||||
absl::nullopt, // ForceGoogleSafeSearch
|
||||
absl::nullopt, // ForceYouTubeSafetyMode (legacy)
|
||||
base::Value(safe_search_util::YOUTUBE_RESTRICT_OFF));
|
||||
ApplySafeSearchPolicy(absl::nullopt, // ForceSafeSearch (legacy)
|
||||
absl::nullopt, // ForceGoogleSafeSearch
|
||||
absl::nullopt, // ForceYouTubeSafetyMode (legacy)
|
||||
base::Value(safe_search_api::YOUTUBE_RESTRICT_OFF));
|
||||
FetchSubresource(GetBrowser()->tab_strip_model()->GetActiveWebContents(),
|
||||
youtube_script);
|
||||
|
||||
CheckYouTubeRestricted(safe_search_util::YOUTUBE_RESTRICT_OFF,
|
||||
CheckYouTubeRestricted(safe_search_api::YOUTUBE_RESTRICT_OFF,
|
||||
urls_requested()[youtube_script.path()]);
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include <memory>
|
||||
|
||||
#include "base/values.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/policy/core/common/policy_map.h"
|
||||
#include "components/policy/policy_constants.h"
|
||||
#include "components/prefs/pref_value_map.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
|
||||
namespace policy {
|
||||
|
||||
@ -47,8 +47,8 @@ void ForceSafeSearchPolicyHandler::ApplyPolicySettings(
|
||||
prefs->SetValue(
|
||||
prefs::kForceYouTubeRestrict,
|
||||
base::Value(value->GetBool()
|
||||
? safe_search_util::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_util::YOUTUBE_RESTRICT_OFF));
|
||||
? safe_search_api::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_api::YOUTUBE_RESTRICT_OFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include <memory>
|
||||
|
||||
#include "base/values.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/policy/core/common/policy_map.h"
|
||||
#include "components/policy/policy_constants.h"
|
||||
#include "components/prefs/pref_value_map.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
|
||||
namespace policy {
|
||||
|
||||
@ -33,11 +33,10 @@ void ForceYouTubeSafetyModePolicyHandler::ApplyPolicySettings(
|
||||
const base::Value* value =
|
||||
policies.GetValue(policy_name(), base::Value::Type::BOOLEAN);
|
||||
if (value) {
|
||||
prefs->SetValue(
|
||||
prefs::kForceYouTubeRestrict,
|
||||
base::Value(value->GetBool()
|
||||
? safe_search_util::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_util::YOUTUBE_RESTRICT_OFF));
|
||||
prefs->SetValue(prefs::kForceYouTubeRestrict,
|
||||
base::Value(value->GetBool()
|
||||
? safe_search_api::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_api::YOUTUBE_RESTRICT_OFF));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,6 @@
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/chrome_paths_internal.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "chrome/common/url_constants.h"
|
||||
#include "chrome/grit/chromium_strings.h"
|
||||
@ -146,6 +145,7 @@
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/prefs/scoped_user_pref_update.h"
|
||||
#include "components/profile_metrics/browser_profile_type.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "components/security_interstitials/content/stateful_ssl_host_state_delegate.h"
|
||||
#include "components/signin/public/base/signin_pref_names.h"
|
||||
#include "components/signin/public/identity_manager/identity_manager.h"
|
||||
@ -372,7 +372,7 @@ void ProfileImpl::RegisterProfilePrefs(
|
||||
registry->RegisterBooleanPref(prefs::kAllowDeletingBrowserHistory, true);
|
||||
registry->RegisterBooleanPref(prefs::kForceGoogleSafeSearch, false);
|
||||
registry->RegisterIntegerPref(prefs::kForceYouTubeRestrict,
|
||||
safe_search_util::YOUTUBE_RESTRICT_OFF);
|
||||
safe_search_api::YOUTUBE_RESTRICT_OFF);
|
||||
registry->RegisterStringPref(prefs::kAllowedDomainsForApps, std::string());
|
||||
|
||||
registry->RegisterIntegerPref(prefs::kProfileAvatarIndex, -1);
|
||||
|
@ -19,11 +19,11 @@
|
||||
#include "chrome/browser/chrome_notification_types.h"
|
||||
#include "chrome/browser/prefs/incognito_mode_prefs.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/autofill/core/common/autofill_prefs.h"
|
||||
#include "components/feed/core/shared_prefs/pref_names.h"
|
||||
#include "components/prefs/pref_value_map.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "components/signin/public/base/signin_pref_names.h"
|
||||
#include "components/signin/public/base/signin_switches.h"
|
||||
#include "components/supervised_user/core/browser/supervised_user_settings_service.h"
|
||||
@ -129,7 +129,7 @@ void SupervisedUserPrefStore::OnNewSettingsAvailable(
|
||||
supervised_user::SupervisedUserURLFilter::ALLOW);
|
||||
prefs_->SetBoolean(prefs::kForceGoogleSafeSearch, true);
|
||||
prefs_->SetInteger(prefs::kForceYouTubeRestrict,
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE);
|
||||
safe_search_api::YOUTUBE_RESTRICT_MODERATE);
|
||||
prefs_->SetBoolean(prefs::kHideWebStoreIcon, false);
|
||||
prefs_->SetBoolean(prefs::kSigninAllowed, false);
|
||||
prefs_->SetBoolean(feed::prefs::kEnableSnippets, false);
|
||||
@ -166,10 +166,10 @@ void SupervisedUserPrefStore::OnNewSettingsAvailable(
|
||||
// |prefs::kForceYouTubeRestrict| because it is an int, not a bool.
|
||||
bool force_safe_search =
|
||||
settings.FindBool(supervised_user::kForceSafeSearch).value_or(true);
|
||||
prefs_->SetInteger(
|
||||
prefs::kForceYouTubeRestrict,
|
||||
force_safe_search ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_util::YOUTUBE_RESTRICT_OFF);
|
||||
prefs_->SetInteger(prefs::kForceYouTubeRestrict,
|
||||
force_safe_search
|
||||
? safe_search_api::YOUTUBE_RESTRICT_MODERATE
|
||||
: safe_search_api::YOUTUBE_RESTRICT_OFF);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||
|
@ -11,10 +11,10 @@
|
||||
#include "base/values.h"
|
||||
#include "chrome/browser/prefs/incognito_mode_prefs.h"
|
||||
#include "chrome/browser/supervised_user/supervised_user_pref_store.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/autofill/core/common/autofill_prefs.h"
|
||||
#include "components/prefs/testing_pref_store.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "components/supervised_user/core/browser/supervised_user_settings_service.h"
|
||||
#include "components/supervised_user/core/common/buildflags.h"
|
||||
#include "components/supervised_user/core/common/features.h"
|
||||
@ -160,9 +160,8 @@ TEST_F(SupervisedUserPrefStoreTest, ConfigureSettings) {
|
||||
int force_youtube_restrict =
|
||||
fixture.changed_prefs()
|
||||
->FindIntByDottedPath(prefs::kForceYouTubeRestrict)
|
||||
.value_or(safe_search_util::YOUTUBE_RESTRICT_OFF);
|
||||
EXPECT_EQ(force_youtube_restrict,
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE);
|
||||
.value_or(safe_search_api::YOUTUBE_RESTRICT_OFF);
|
||||
EXPECT_EQ(force_youtube_restrict, safe_search_api::YOUTUBE_RESTRICT_MODERATE);
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
EXPECT_THAT(fixture.changed_prefs()->FindBoolByDottedPath(
|
||||
@ -209,8 +208,8 @@ TEST_F(SupervisedUserPrefStoreTest, ConfigureSettings) {
|
||||
force_youtube_restrict =
|
||||
fixture.changed_prefs()
|
||||
->FindIntByDottedPath(prefs::kForceYouTubeRestrict)
|
||||
.value_or(safe_search_util::YOUTUBE_RESTRICT_MODERATE);
|
||||
EXPECT_EQ(force_youtube_restrict, safe_search_util::YOUTUBE_RESTRICT_OFF);
|
||||
.value_or(safe_search_api::YOUTUBE_RESTRICT_MODERATE);
|
||||
EXPECT_EQ(force_youtube_restrict, safe_search_api::YOUTUBE_RESTRICT_OFF);
|
||||
|
||||
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||
// The custodian can allow sites and apps to request permissions.
|
||||
|
@ -27,9 +27,9 @@
|
||||
#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "components/supervised_user/core/browser/supervised_user_settings_service.h"
|
||||
#include "components/supervised_user/core/common/supervised_user_constants.h"
|
||||
#include "content/public/test/browser_test.h"
|
||||
@ -59,7 +59,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTest, LocalPolicies) {
|
||||
PrefService* prefs = profile->GetPrefs();
|
||||
EXPECT_FALSE(prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
|
||||
EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict),
|
||||
safe_search_util::YOUTUBE_RESTRICT_OFF);
|
||||
safe_search_api::YOUTUBE_RESTRICT_OFF);
|
||||
EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceGoogleSafeSearch));
|
||||
EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceYouTubeRestrict));
|
||||
}
|
||||
@ -84,7 +84,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTestSupervised, LocalPolicies) {
|
||||
PrefService* prefs = profile->GetPrefs();
|
||||
EXPECT_TRUE(prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
|
||||
EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict),
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE);
|
||||
safe_search_api::YOUTUBE_RESTRICT_MODERATE);
|
||||
EXPECT_FALSE(
|
||||
prefs->IsUserModifiablePreference(prefs::kForceGoogleSafeSearch));
|
||||
EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceYouTubeRestrict));
|
||||
|
@ -217,6 +217,7 @@ static_library("common_lib") {
|
||||
"//components/prefs",
|
||||
"//components/safe_browsing:buildflags",
|
||||
"//components/safe_browsing/core/common",
|
||||
"//components/safe_search_api",
|
||||
"//components/services/app_service/public/cpp:app_share_target",
|
||||
"//components/services/app_service/public/cpp:app_types",
|
||||
"//components/services/heap_profiling/public/cpp",
|
||||
|
@ -46,6 +46,7 @@ include_rules = [
|
||||
"+components/safe_browsing/buildflags.h",
|
||||
"+components/safe_browsing/core/common/web_ui_constants.h",
|
||||
"+components/safe_browsing/core/common/proto/csd.pb.h",
|
||||
"+components/safe_search_api",
|
||||
"+components/services/app_service/public/cpp/share_target.h",
|
||||
"+components/signin/public/base/signin_buildflags.h",
|
||||
"+components/strings/grit/components_strings.h",
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "base/metrics/histogram_functions.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/common/chrome_features.h"
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "components/google/core/common/google_util.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
#include "net/base/url_util.h"
|
||||
#include "services/network/public/cpp/resource_request.h"
|
||||
#include "services/network/public/mojom/url_response_head.mojom.h"
|
||||
@ -31,9 +31,9 @@ const char kCCTClientDataHeader[] = "X-CCT-Client-Data";
|
||||
void GoogleURLLoaderThrottle::UpdateCorsExemptHeader(
|
||||
network::mojom::NetworkContextParams* params) {
|
||||
params->cors_exempt_header_list.push_back(
|
||||
safe_search_util::kGoogleAppsAllowedDomains);
|
||||
safe_search_api::kGoogleAppsAllowedDomains);
|
||||
params->cors_exempt_header_list.push_back(
|
||||
safe_search_util::kYouTubeRestrictHeaderName);
|
||||
safe_search_api::kYouTubeRestrictHeaderName);
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
params->cors_exempt_header_list.push_back(kCCTClientDataHeader);
|
||||
#endif
|
||||
@ -60,27 +60,27 @@ void GoogleURLLoaderThrottle::WillStartRequest(
|
||||
bool* defer) {
|
||||
if (dynamic_params_.force_safe_search) {
|
||||
GURL new_url;
|
||||
safe_search_util::ForceGoogleSafeSearch(request->url, &new_url);
|
||||
safe_search_api::ForceGoogleSafeSearch(request->url, &new_url);
|
||||
if (!new_url.is_empty())
|
||||
request->url = new_url;
|
||||
}
|
||||
|
||||
static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0,
|
||||
static_assert(safe_search_api::YOUTUBE_RESTRICT_OFF == 0,
|
||||
"OFF must be first");
|
||||
if (dynamic_params_.youtube_restrict >
|
||||
safe_search_util::YOUTUBE_RESTRICT_OFF &&
|
||||
safe_search_api::YOUTUBE_RESTRICT_OFF &&
|
||||
dynamic_params_.youtube_restrict <
|
||||
safe_search_util::YOUTUBE_RESTRICT_COUNT) {
|
||||
safe_search_util::ForceYouTubeRestrict(
|
||||
safe_search_api::YOUTUBE_RESTRICT_COUNT) {
|
||||
safe_search_api::ForceYouTubeRestrict(
|
||||
request->url, &request->cors_exempt_headers,
|
||||
static_cast<safe_search_util::YouTubeRestrictMode>(
|
||||
static_cast<safe_search_api::YouTubeRestrictMode>(
|
||||
dynamic_params_.youtube_restrict));
|
||||
}
|
||||
|
||||
if (!dynamic_params_.allowed_domains_for_apps.empty() &&
|
||||
request->url.DomainIs("google.com")) {
|
||||
request->cors_exempt_headers.SetHeader(
|
||||
safe_search_util::kGoogleAppsAllowedDomains,
|
||||
safe_search_api::kGoogleAppsAllowedDomains,
|
||||
dynamic_params_.allowed_domains_for_apps);
|
||||
}
|
||||
|
||||
@ -104,24 +104,24 @@ void GoogleURLLoaderThrottle::WillRedirectRequest(
|
||||
// service is enabled. The non-network service path handles this in
|
||||
// ChromeNetworkDelegate.
|
||||
if (dynamic_params_.force_safe_search) {
|
||||
safe_search_util::ForceGoogleSafeSearch(redirect_info->new_url,
|
||||
&redirect_info->new_url);
|
||||
safe_search_api::ForceGoogleSafeSearch(redirect_info->new_url,
|
||||
&redirect_info->new_url);
|
||||
}
|
||||
|
||||
if (dynamic_params_.youtube_restrict >
|
||||
safe_search_util::YOUTUBE_RESTRICT_OFF &&
|
||||
safe_search_api::YOUTUBE_RESTRICT_OFF &&
|
||||
dynamic_params_.youtube_restrict <
|
||||
safe_search_util::YOUTUBE_RESTRICT_COUNT) {
|
||||
safe_search_util::ForceYouTubeRestrict(
|
||||
safe_search_api::YOUTUBE_RESTRICT_COUNT) {
|
||||
safe_search_api::ForceYouTubeRestrict(
|
||||
redirect_info->new_url, modified_cors_exempt_headers,
|
||||
static_cast<safe_search_util::YouTubeRestrictMode>(
|
||||
static_cast<safe_search_api::YouTubeRestrictMode>(
|
||||
dynamic_params_.youtube_restrict));
|
||||
}
|
||||
|
||||
if (!dynamic_params_.allowed_domains_for_apps.empty() &&
|
||||
redirect_info->new_url.DomainIs("google.com")) {
|
||||
modified_cors_exempt_headers->SetHeader(
|
||||
safe_search_util::kGoogleAppsAllowedDomains,
|
||||
safe_search_api::kGoogleAppsAllowedDomains,
|
||||
dynamic_params_.allowed_domains_for_apps);
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,6 @@ static_library("net") {
|
||||
sources = [
|
||||
"net_resource_provider.cc",
|
||||
"net_resource_provider.h",
|
||||
"safe_search_util.cc",
|
||||
"safe_search_util.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
|
@ -1164,7 +1164,7 @@ const char kAllowDeletingBrowserHistory[] = "history.deleting_enabled";
|
||||
const char kForceGoogleSafeSearch[] = "settings.force_google_safesearch";
|
||||
|
||||
// Integer controlling whether Restrict Mode (moderate/strict) is mandatory on
|
||||
// YouTube. See |safe_search_util::YouTubeRestrictMode| for possible values.
|
||||
// YouTube. See |safe_search_api::YouTubeRestrictMode| for possible values.
|
||||
const char kForceYouTubeRestrict[] = "settings.force_youtube_restrict";
|
||||
|
||||
// Comma separated list of domain names (e.g. "google.com,school.edu").
|
||||
|
@ -5775,7 +5775,6 @@ test("unit_tests") {
|
||||
"../common/chrome_paths_unittest.cc",
|
||||
"../common/crash_keys_unittest.cc",
|
||||
"../common/ini_parser_unittest.cc",
|
||||
"../common/net/safe_search_util_unittest.cc",
|
||||
"../common/pref_names_util_unittest.cc",
|
||||
"../renderer/cart/commerce_hint_agent_unittest.cc",
|
||||
"../renderer/chrome_content_renderer_client_unittest.cc",
|
||||
@ -6154,6 +6153,7 @@ test("unit_tests") {
|
||||
"//components/safe_browsing/core/browser/sync",
|
||||
"//components/safe_browsing/core/common",
|
||||
"//components/safe_browsing/core/common/proto:client_model_proto",
|
||||
"//components/safe_search_api",
|
||||
"//components/safe_search_api:test_support",
|
||||
"//components/saved_tab_groups:core",
|
||||
"//components/schema_org/common:improved_mojom",
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
source_set("safe_search_api") {
|
||||
sources = [
|
||||
"safe_search_util.cc",
|
||||
"safe_search_util.h",
|
||||
"url_checker.cc",
|
||||
"url_checker.h",
|
||||
"url_checker_client.h",
|
||||
@ -58,6 +60,7 @@ source_set("unit_tests") {
|
||||
testonly = true
|
||||
sources = [
|
||||
"safe_search/safe_search_url_checker_client_unittest.cc",
|
||||
"safe_search_util_unittest.cc",
|
||||
"url_checker_unittest.cc",
|
||||
]
|
||||
deps = [
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -39,8 +39,8 @@ bool HasSameParameterKey(base::StringPiece first_parameter,
|
||||
// return value is the |query| string modified such that SafeSearch is active.
|
||||
std::string AddSafeSearchParameters(const std::string& query) {
|
||||
std::vector<base::StringPiece> new_parameters;
|
||||
std::string safe_parameter = safe_search_util::kSafeSearchSafeParameter;
|
||||
std::string ssui_parameter = safe_search_util::kSafeSearchSsuiParameter;
|
||||
std::string safe_parameter = safe_search_api::kSafeSearchSafeParameter;
|
||||
std::string ssui_parameter = safe_search_api::kSafeSearchSsuiParameter;
|
||||
|
||||
for (const base::StringPiece& param : base::SplitStringPiece(
|
||||
query, "&", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
|
||||
@ -57,7 +57,7 @@ std::string AddSafeSearchParameters(const std::string& query) {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace safe_search_util {
|
||||
namespace safe_search_api {
|
||||
|
||||
const char kSafeSearchSafeParameter[] = "safe=active";
|
||||
const char kSafeSearchSsuiParameter[] = "ssui=on";
|
||||
@ -71,13 +71,15 @@ 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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string query = url.query();
|
||||
std::string new_query = AddSafeSearchParameters(query);
|
||||
if (query == new_query)
|
||||
if (query == new_query) {
|
||||
return;
|
||||
}
|
||||
|
||||
GURL::Replacements replacements;
|
||||
replacements.SetQueryStr(new_query);
|
||||
@ -89,8 +91,9 @@ void ForceYouTubeRestrict(const GURL& url,
|
||||
YouTubeRestrictMode mode) {
|
||||
if (!google_util::IsYoutubeDomainUrl(
|
||||
url, google_util::ALLOW_SUBDOMAIN,
|
||||
google_util::DISALLOW_NON_STANDARD_PORTS))
|
||||
google_util::DISALLOW_NON_STANDARD_PORTS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case YOUTUBE_RESTRICT_OFF:
|
||||
@ -110,4 +113,4 @@ void ForceYouTubeRestrict(const GURL& url,
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace safe_search_util
|
||||
} // namespace safe_search_api
|
@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROME_COMMON_NET_SAFE_SEARCH_UTIL_H_
|
||||
#define CHROME_COMMON_NET_SAFE_SEARCH_UTIL_H_
|
||||
#ifndef COMPONENTS_SAFE_SEARCH_API_SAFE_SEARCH_UTIL_H_
|
||||
#define COMPONENTS_SAFE_SEARCH_API_SAFE_SEARCH_UTIL_H_
|
||||
|
||||
class GURL;
|
||||
|
||||
@ -11,7 +11,7 @@ namespace net {
|
||||
class HttpRequestHeaders;
|
||||
}
|
||||
|
||||
namespace safe_search_util {
|
||||
namespace safe_search_api {
|
||||
|
||||
// Parameters that get appended to force SafeSearch.
|
||||
extern const char kSafeSearchSafeParameter[];
|
||||
@ -50,6 +50,6 @@ void ForceYouTubeRestrict(const GURL& url,
|
||||
net::HttpRequestHeaders* headers,
|
||||
YouTubeRestrictMode mode);
|
||||
|
||||
} // namespace safe_search_util
|
||||
} // namespace safe_search_api
|
||||
|
||||
#endif // CHROME_COMMON_NET_SAFE_SEARCH_UTIL_H_
|
||||
#endif // COMPONENTS_SAFE_SEARCH_API_SAFE_SEARCH_UTIL_H_
|
@ -2,10 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/common/net/safe_search_util.h"
|
||||
#include "components/safe_search_api/safe_search_util.h"
|
||||
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "chrome/common/url_constants.h"
|
||||
#include "net/http/http_request_headers.h"
|
||||
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -21,14 +20,14 @@ void CheckAddedParameters(const std::string& url_string,
|
||||
SCOPED_TRACE(url_string);
|
||||
|
||||
GURL result(url_string);
|
||||
safe_search_util::ForceGoogleSafeSearch(GURL(url_string), &result);
|
||||
safe_search_api::ForceGoogleSafeSearch(GURL(url_string), &result);
|
||||
|
||||
EXPECT_EQ(expected_query_parameters, result.query());
|
||||
}
|
||||
|
||||
TEST(SafeSearchUtilTest, AddGoogleSafeSearchParams) {
|
||||
const std::string kSafeParameter = safe_search_util::kSafeSearchSafeParameter;
|
||||
const std::string kSsuiParameter = safe_search_util::kSafeSearchSsuiParameter;
|
||||
const std::string kSafeParameter = safe_search_api::kSafeSearchSafeParameter;
|
||||
const std::string kSsuiParameter = safe_search_api::kSafeSearchSsuiParameter;
|
||||
const std::string kBothParameters = kSafeParameter + "&" + kSsuiParameter;
|
||||
|
||||
// Test the home page.
|
||||
@ -126,9 +125,9 @@ TEST(SafeSearchUtilTest, AddGoogleSafeSearchParams) {
|
||||
|
||||
TEST(SafeSearchUtilTest, SetYoutubeHeader) {
|
||||
net::HttpRequestHeaders headers;
|
||||
safe_search_util::ForceYouTubeRestrict(
|
||||
safe_search_api::ForceYouTubeRestrict(
|
||||
GURL("http://www.youtube.com"), &headers,
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE);
|
||||
safe_search_api::YOUTUBE_RESTRICT_MODERATE);
|
||||
std::string value;
|
||||
EXPECT_TRUE(headers.GetHeader("Youtube-Restrict", &value));
|
||||
EXPECT_EQ("Moderate", value);
|
||||
@ -137,9 +136,9 @@ TEST(SafeSearchUtilTest, SetYoutubeHeader) {
|
||||
TEST(SafeSearchUtilTest, OverrideYoutubeHeader) {
|
||||
net::HttpRequestHeaders headers;
|
||||
headers.SetHeader("Youtube-Restrict", "Off");
|
||||
safe_search_util::ForceYouTubeRestrict(
|
||||
safe_search_api::ForceYouTubeRestrict(
|
||||
GURL("http://www.youtube.com"), &headers,
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE);
|
||||
safe_search_api::YOUTUBE_RESTRICT_MODERATE);
|
||||
std::string value;
|
||||
EXPECT_TRUE(headers.GetHeader("Youtube-Restrict", &value));
|
||||
EXPECT_EQ("Moderate", value);
|
||||
@ -148,9 +147,9 @@ TEST(SafeSearchUtilTest, OverrideYoutubeHeader) {
|
||||
TEST(SafeSearchUtilTest, DoesntTouchNonYoutubeURL) {
|
||||
net::HttpRequestHeaders headers;
|
||||
headers.SetHeader("Youtube-Restrict", "Off");
|
||||
safe_search_util::ForceYouTubeRestrict(
|
||||
safe_search_api::ForceYouTubeRestrict(
|
||||
GURL("http://www.notyoutube.com"), &headers,
|
||||
safe_search_util::YOUTUBE_RESTRICT_MODERATE);
|
||||
safe_search_api::YOUTUBE_RESTRICT_MODERATE);
|
||||
std::string value;
|
||||
EXPECT_TRUE(headers.GetHeader("Youtube-Restrict", &value));
|
||||
EXPECT_EQ("Off", value);
|
Reference in New Issue
Block a user