Commit 19d639c8 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebLayer] Integrate HostContentSettingsMap

HostContentSettingsMap will shortly be required in WebLayer for reuse
of //chrome's SSLHostStateDelegate implementation. This CL enables that
by creating a BrowserContextKeyedServiceFactory implementation for
HostContentSettingsMap in //weblayer. The implementation is modeled
after that in //chrome but can be significantly simpler. Two relevant
differences (see discussion in comments on the CL for more details):

1. In WebLayer, we do not reply on the //chrome-level feature to
   determine whether to set
   migrate_requesting_and_top_level_origin_settings to true but simply
   set it to true. The feature has been enabled by default for 2+
   years and is shortly set to be cleaned up, so it is not worth
   componentizing.

2. We did not bring over the Android-specific code from //chrome's
   factory (which would need componentizing). The features in question
   are not currently supported in WebLayer.

HostContentSettingsMap requires a PrefRegistrySyncable in order to
register its prefs. To facilitate this, this CL changes //weblayer's
BrowserContextImpl to use a PrefRegistrySyncable (as //chrome's
ProfileImpl does), rather than its previous usage of a
PrefRegistrySimple. This change should have no meaningful behavioral
impact as WebLayer does not use sync.

Bug: 1030692
Change-Id: I86053d749141b7e223812b042949aaf7ff5ecee4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062342
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743599}
parent c28700ec
......@@ -114,6 +114,8 @@ jumbo_static_library("weblayer_lib") {
"browser/feature_list_creator.h",
"browser/file_select_helper.cc",
"browser/file_select_helper.h",
"browser/host_content_settings_map_factory.cc",
"browser/host_content_settings_map_factory.h",
"browser/i18n_util.cc",
"browser/i18n_util.h",
"browser/isolated_world_ids.h",
......@@ -231,6 +233,7 @@ jumbo_static_library("weblayer_lib") {
"//components/autofill/core/browser",
"//components/base32",
"//components/captive_portal/core:buildflags",
"//components/content_settings/core/browser",
"//components/crash/content/app",
"//components/crash/content/browser",
"//components/embedder_support",
......
include_rules = [
"+components/content_settings/core/browser",
"+components/omnibox/browser",
"+components/security_state/core/security_state.h",
"+third_party/metrics_proto/omnibox_input_type.pb.h",
]
\ No newline at end of file
]
......@@ -4,11 +4,12 @@
#include "weblayer/browser/browser_context_impl.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/download/public/common/in_progress_download_manager.h"
#include "components/embedder_support/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/in_memory_pref_store.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_service_factory.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
......@@ -195,7 +196,7 @@ content::ContentIndexProvider* BrowserContextImpl::GetContentIndexProvider() {
}
void BrowserContextImpl::CreateUserPrefService() {
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
auto pref_registry = base::MakeRefCounted<user_prefs::PrefRegistrySyncable>();
RegisterPrefs(pref_registry.get());
PrefServiceFactory pref_service_factory;
......@@ -207,13 +208,15 @@ void BrowserContextImpl::CreateUserPrefService() {
user_prefs::UserPrefs::Set(this, user_pref_service_.get());
}
void BrowserContextImpl::RegisterPrefs(PrefRegistrySimple* pref_registry) {
void BrowserContextImpl::RegisterPrefs(
user_prefs::PrefRegistrySyncable* pref_registry) {
// This pref is used by captive_portal::CaptivePortalService (as well as other
// potential use cases in the future, as it is used for various purposes
// through //chrome).
pref_registry->RegisterBooleanPref(
embedder_support::kAlternateErrorPagesEnabled, true);
HostContentSettingsMap::RegisterProfilePrefs(pref_registry);
safe_browsing::RegisterProfilePrefs(pref_registry);
}
......
......@@ -13,7 +13,9 @@
#include "weblayer/browser/ssl_host_state_delegate_impl.h"
#include "weblayer/public/profile.h"
class PrefRegistrySimple;
namespace user_prefs {
class PrefRegistrySyncable;
}
class PrefService;
namespace weblayer {
......@@ -65,7 +67,7 @@ class BrowserContextImpl : public content::BrowserContext {
void CreateUserPrefService();
// Registers the preferences that WebLayer accesses.
void RegisterPrefs(PrefRegistrySimple* pref_registry);
void RegisterPrefs(user_prefs::PrefRegistrySyncable* pref_registry);
ProfileImpl* const profile_impl_;
base::FilePath path_;
......
......@@ -23,6 +23,7 @@
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "weblayer/browser/browser_process.h"
#include "weblayer/browser/host_content_settings_map_factory.h"
#include "weblayer/browser/webui/web_ui_controller_factory.h"
#include "weblayer/public/main.h"
......@@ -59,6 +60,8 @@ namespace {
// especially important for services that should be created at profile
// creation time as compared to lazily on first access.
static void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
HostContentSettingsMapFactory::GetInstance();
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
CaptivePortalServiceFactory::GetInstance();
#endif
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "weblayer/browser/host_content_settings_map_factory.h"
#include <utility>
#include "base/feature_list.h"
#include "components/content_settings/core/browser/content_settings_pref_provider.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
namespace weblayer {
HostContentSettingsMapFactory::HostContentSettingsMapFactory()
: RefcountedBrowserContextKeyedServiceFactory(
"HostContentSettingsMap",
BrowserContextDependencyManager::GetInstance()) {}
HostContentSettingsMapFactory::~HostContentSettingsMapFactory() = default;
// static
HostContentSettingsMap* HostContentSettingsMapFactory::GetForBrowserContext(
content::BrowserContext* browser_context) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
return static_cast<HostContentSettingsMap*>(
GetInstance()->GetServiceForBrowserContext(browser_context, true).get());
}
// static
HostContentSettingsMapFactory* HostContentSettingsMapFactory::GetInstance() {
return base::Singleton<HostContentSettingsMapFactory>::get();
}
scoped_refptr<RefcountedKeyedService>
HostContentSettingsMapFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
scoped_refptr<HostContentSettingsMap> settings_map =
base::MakeRefCounted<HostContentSettingsMap>(
user_prefs::UserPrefs::Get(context), context->IsOffTheRecord(),
/*store_last_modified=*/true,
/*migrate_requesting_and_top_level_origin_settings=*/true);
return settings_map;
}
content::BrowserContext* HostContentSettingsMapFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return context;
}
} // namespace weblayer
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBLAYER_BROWSER_HOST_CONTENT_SETTINGS_MAP_FACTORY_H_
#define WEBLAYER_BROWSER_HOST_CONTENT_SETTINGS_MAP_FACTORY_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h"
class HostContentSettingsMap;
namespace weblayer {
class HostContentSettingsMapFactory
: public RefcountedBrowserContextKeyedServiceFactory {
public:
static HostContentSettingsMap* GetForBrowserContext(
content::BrowserContext* browser_context);
static HostContentSettingsMapFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<HostContentSettingsMapFactory>;
HostContentSettingsMapFactory();
~HostContentSettingsMapFactory() override;
// RefcountedBrowserContextKeyedServiceFactory methods:
scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMapFactory);
};
} // namespace weblayer
#endif // WEBLAYER_BROWSER_HOST_CONTENT_SETTINGS_MAP_FACTORY_H_
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