diff options
author | wjmaclean <wjmaclean@chromium.org> | 2014-11-12 08:42:11 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-12 16:42:27 +0000 |
commit | caa7d6d94e81c92083a3eb8d18913e33c74baf66 (patch) | |
tree | af7a8d058b5de890314e4fbf861ab769e3b73b2e | |
parent | a7fda04bfe6b643227baf95c9f6e2450cc5daf56 (diff) | |
download | chromium_src-caa7d6d94e81c92083a3eb8d18913e33c74baf66.zip chromium_src-caa7d6d94e81c92083a3eb8d18913e33c74baf66.tar.gz chromium_src-caa7d6d94e81c92083a3eb8d18913e33c74baf66.tar.bz2 |
Migrate HostZoomMap to live in StoragePartition.
This CL changes the persistence of host zoom levels to be on
a per-storage-partition basis, as opposed to (the current)
per-profile basis. This is needed to allow WebView content
(withing apps) to keep their zoom levels independent of those
in the main browser window.
BUG=335317
Review URL: https://codereview.chromium.org/393133002
Cr-Commit-Position: refs/heads/master@{#303841}
52 files changed, 507 insertions, 379 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index c386ad5..32148fc 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -222,6 +222,12 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() { } } +scoped_ptr<content::ZoomLevelDelegate> +AwBrowserContext::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + return nullptr; +} + base::FilePath AwBrowserContext::GetPath() const { return context_storage_path_; } diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h index 3f49765..0f2f278 100644 --- a/android_webview/browser/aw_browser_context.h +++ b/android_webview/browser/aw_browser_context.h @@ -93,6 +93,8 @@ class AwBrowserContext : public content::BrowserContext, void CreateUserPrefServiceIfNecessary(); // content::BrowserContext implementation. + scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; virtual base::FilePath GetPath() const override; virtual bool IsOffTheRecord() const override; virtual net::URLRequestContextGetter* GetRequestContext() override; diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc index e8b895d..4a15378 100644 --- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc +++ b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc @@ -152,6 +152,12 @@ class TestStoragePartition : public StoragePartition { } content::GeofencingManager* GetGeofencingManager() override { return NULL; } + content::HostZoomMap* GetHostZoomMap() override { return NULL; } + content::HostZoomLevelContext* GetHostZoomLevelContext() override { + return NULL; + } + content::ZoomLevelDelegate* GetZoomLevelDelegate() override { return NULL; } + void ClearDataForOrigin(uint32 remove_mask, uint32 quota_storage_remove_mask, const GURL& storage_origin, diff --git a/chrome/browser/profiles/host_zoom_map_browsertest.cc b/chrome/browser/profiles/host_zoom_map_browsertest.cc index 15c32ce..cdb5bd6 100644 --- a/chrome/browser/profiles/host_zoom_map_browsertest.cc +++ b/chrome/browser/profiles/host_zoom_map_browsertest.cc @@ -19,6 +19,7 @@ #include "base/values.h" #include "chrome/browser/chrome_page_zoom.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_impl.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" @@ -35,6 +36,8 @@ #include "testing/gmock/include/gmock/gmock.h" #include "url/gurl.h" +using content::HostZoomMap; + namespace { class ZoomLevelChangeObserver { @@ -341,3 +344,58 @@ IN_PROC_BROWSER_TEST_F(HostZoomMapMigrationBrowserTest, EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kDefaultZoomLevelDeprecated)); } +// Test four things: +// 1. Host zoom maps of parent profile and child profile are different. +// 2. Child host zoom map inherits zoom level at construction. +// 3. Change of zoom level doesn't propagate from child to parent. +// 4. Change of zoom level propagates from parent to child. +IN_PROC_BROWSER_TEST_F(HostZoomMapBrowserTest, + OffTheRecordProfileHostZoomMap) { + // Constants for test case. + const std::string host("example.com"); + const double zoom_level_25 = 2.5; + const double zoom_level_30 = 3.0; + const double zoom_level_40 = 4.0; + + Profile* parent_profile = browser()->profile(); + Profile* child_profile = + static_cast<ProfileImpl*>(parent_profile)->GetOffTheRecordProfile(); + HostZoomMap* parent_zoom_map = + HostZoomMap::GetDefaultForBrowserContext(parent_profile); + ASSERT_TRUE(parent_zoom_map); + + parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25); + ASSERT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), + zoom_level_25); + + // Prepare child host zoom map. + HostZoomMap* child_zoom_map = + HostZoomMap::GetDefaultForBrowserContext(child_profile); + ASSERT_TRUE(child_zoom_map); + + // Verify. + EXPECT_NE(parent_zoom_map, child_zoom_map); + + EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), + child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << + "Child must inherit from parent."; + + child_zoom_map->SetZoomLevelForHost(host, zoom_level_30); + ASSERT_EQ( + child_zoom_map->GetZoomLevelForHostAndScheme("http", host), + zoom_level_30); + + EXPECT_NE(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), + child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << + "Child change must not propagate to parent."; + + parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); + ASSERT_EQ( + parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), + zoom_level_40); + + EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), + child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << + "Parent change should propagate to child."; + base::RunLoop().RunUntilIdle(); +} diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index 3e6d872..fd0a7f9 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -142,7 +142,7 @@ void OffTheRecordProfileImpl::Init() { GetRequestContext(); #endif // defined(OS_CHROMEOS) - InitHostZoomMap(); + TrackZoomLevelsFromParent(); #if defined(ENABLE_PLUGINS) ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( @@ -198,15 +198,20 @@ void OffTheRecordProfileImpl::InitIoData() { io_data_.reset(new OffTheRecordProfileIOData::Handle(this)); } -void OffTheRecordProfileImpl::InitHostZoomMap() { +void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() { + DCHECK_NE(INCOGNITO_PROFILE, profile_->GetProfileType()); + + // Here we only want to use zoom levels stored in the main-context's default + // storage partition. We're not interested in zoom levels in special + // partitions, e.g. those used by WebViewGuests. HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); HostZoomMap* parent_host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(profile_); host_zoom_map->CopyFrom(parent_host_zoom_map); - // Observe parent's HZM change for propagating change of parent's - // change to this HZM. - zoom_subscription_ = parent_host_zoom_map->AddZoomLevelChangedCallback( - base::Bind(&OffTheRecordProfileImpl::OnZoomLevelChanged, + // Observe parent profile's HostZoomMap changes so they can also be applied + // to this profile's HostZoomMap. + track_zoom_subscription_ = parent_host_zoom_map->AddZoomLevelChangedCallback( + base::Bind(&OffTheRecordProfileImpl::OnParentZoomLevelChanged, base::Unretained(this))); } @@ -227,6 +232,12 @@ base::FilePath OffTheRecordProfileImpl::GetPath() const { return profile_->GetPath(); } +scoped_ptr<content::ZoomLevelDelegate> +OffTheRecordProfileImpl::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + return nullptr; +} + scoped_refptr<base::SequencedTaskRunner> OffTheRecordProfileImpl::GetIOTaskRunner() { return profile_->GetIOTaskRunner(); @@ -513,7 +524,7 @@ Profile* Profile::CreateOffTheRecordProfile() { return profile; } -void OffTheRecordProfileImpl::OnZoomLevelChanged( +void OffTheRecordProfileImpl::OnParentZoomLevelChanged( const HostZoomMap::ZoomLevelChange& change) { HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); switch (change.mode) { diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index 53e0621..fd7e778 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -84,6 +84,8 @@ class OffTheRecordProfileImpl : public Profile { // content::BrowserContext implementation: base::FilePath GetPath() const override; + scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override; bool IsOffTheRecord() const override; content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; @@ -103,16 +105,19 @@ class OffTheRecordProfileImpl : public Profile { content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; private: - FRIEND_TEST_ALL_PREFIXES(OffTheRecordProfileImplTest, GetHostZoomMap); void InitIoData(); - void InitHostZoomMap(); + + // Allows a profile to track changes in zoom levels in its parent profile. + void TrackZoomLevelsFromParent(); #if defined(OS_ANDROID) || defined(OS_IOS) void UseSystemProxy(); #endif // defined(OS_ANDROID) || defined(OS_IOS) - void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); PrefProxyConfigTracker* CreateProxyConfigTracker(); + // Callback function for tracking parent's zoom level changes. + void OnParentZoomLevelChanged( + const content::HostZoomMap::ZoomLevelChange& change); // The real underlying profile. Profile* profile_; @@ -120,6 +125,7 @@ class OffTheRecordProfileImpl : public Profile { // Weak pointer owned by |profile_|. PrefServiceSyncable* prefs_; + scoped_ptr<content::HostZoomMap::Subscription> track_zoom_subscription_; scoped_ptr<OffTheRecordProfileIOData::Handle> io_data_; // We use a non-persistent content settings map for OTR. @@ -132,8 +138,6 @@ class OffTheRecordProfileImpl : public Profile { scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; - scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; - DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); }; diff --git a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc deleted file mode 100644 index 86184c2..0000000 --- a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright (c) 2012 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 "chrome/browser/profiles/off_the_record_profile_impl.h" - -#include "base/prefs/pref_registry_simple.h" -#include "base/prefs/pref_service.h" -#include "base/prefs/scoped_user_pref_update.h" -#include "base/run_loop.h" -#include "chrome/browser/prefs/browser_prefs.h" -#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/base/browser_with_test_window_test.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_io_thread_state.h" -#include "chrome/test/base/testing_pref_service_syncable.h" -#include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/testing_profile_manager.h" -#include "content/public/browser/host_zoom_map.h" -#include "content/public/common/page_zoom.h" -#include "net/dns/mock_host_resolver.h" - -using content::HostZoomMap; - -namespace { - -class TestingProfileWithHostZoomMap : public TestingProfile { - public: - TestingProfileWithHostZoomMap() { - HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); - zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( - base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, - base::Unretained(this))); - zoom_level_prefs_.reset( - new chrome::ChromeZoomLevelPrefs(GetPrefs(), GetPath())); - zoom_level_prefs_->InitPrefsAndCopyToHostZoomMap(GetPath(), host_zoom_map); - } - - ~TestingProfileWithHostZoomMap() override {} - - // Profile overrides: - PrefService* GetOffTheRecordPrefs() override { return GetPrefs(); } - - private: - void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { - - if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) - return; - - HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); - - double level = change.zoom_level; - std::string per_host_zoom_levels(prefs::kPartitionPerHostZoomLevels); - per_host_zoom_levels.append(".0"); - DictionaryPrefUpdate update(GetPrefs(), - prefs::kPartitionPerHostZoomLevels); - base::DictionaryValue* host_zoom_dictionary = update.Get(); - if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) { - host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); - } else { - host_zoom_dictionary->SetWithoutPathExpansion( - change.host, new base::FundamentalValue(level)); - } - } - - scoped_ptr<HostZoomMap::Subscription> zoom_subscription_; - scoped_ptr<chrome::ChromeZoomLevelPrefs> zoom_level_prefs_; - - DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); -}; - -} // namespace - -// We need to have a BrowserProcess in g_browser_process variable, since -// OffTheRecordProfileImpl ctor uses it in -// ProfileIOData::InitializeProfileParams. -class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest { - protected: - OffTheRecordProfileImplTest() {} - - ~OffTheRecordProfileImplTest() override {} - - // testing::Test overrides: - void SetUp() override { - profile_manager_.reset(new TestingProfileManager(browser_process())); - ASSERT_TRUE(profile_manager_->SetUp()); - - testing_io_thread_state_.reset(new chrome::TestingIOThreadState()); - testing_io_thread_state_->io_thread_state()->globals()->host_resolver.reset( - new net::MockHostResolver()); - - BrowserWithTestWindowTest::SetUp(); - } - - void TearDown() override { - BrowserWithTestWindowTest::TearDown(); - - testing_io_thread_state_.reset(); - - profile_manager_.reset(); - } - - // BrowserWithTestWindowTest overrides: - TestingProfile* CreateProfile() override { - return new TestingProfileWithHostZoomMap; - } - - private: - TestingBrowserProcess* browser_process() { - return TestingBrowserProcess::GetGlobal(); - } - - scoped_ptr<TestingProfileManager> profile_manager_; - scoped_ptr<chrome::TestingIOThreadState> testing_io_thread_state_; - - DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImplTest); -}; - -// Test four things: -// 1. Host zoom maps of parent profile and child profile are different. -// 2. Child host zoom map inherites zoom level at construction. -// 3. Change of zoom level doesn't propagate from child to parent. -// 4. Change of zoom level propagate from parent to child. -TEST_F(OffTheRecordProfileImplTest, GetHostZoomMap) { - // Constants for test case. - const std::string host("example.com"); - const double zoom_level_25 = 2.5; - const double zoom_level_30 = 3.0; - const double zoom_level_40 = 4.0; - - // The TestingProfile from CreateProfile above is the parent. - TestingProfile* parent_profile = GetProfile(); - ASSERT_TRUE(parent_profile); - ASSERT_TRUE(parent_profile->GetPrefs()); - ASSERT_TRUE(parent_profile->GetOffTheRecordPrefs()); - - // Prepare parent host zoom map. - HostZoomMap* parent_zoom_map = - HostZoomMap::GetDefaultForBrowserContext(parent_profile); - ASSERT_TRUE(parent_zoom_map); - - parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25); - ASSERT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), - zoom_level_25); - - // TODO(yosin) We need to wait ProfileImpl::Observe done for - // OnZoomLevelChanged. - - // Prepare an off the record profile owned by the parent profile. - parent_profile->SetOffTheRecordProfile( - scoped_ptr<Profile>(new OffTheRecordProfileImpl(parent_profile))); - OffTheRecordProfileImpl* child_profile = - static_cast<OffTheRecordProfileImpl*>( - parent_profile->GetOffTheRecordProfile()); - child_profile->InitIoData(); - child_profile->InitHostZoomMap(); - - // Prepare child host zoom map. - HostZoomMap* child_zoom_map = - HostZoomMap::GetDefaultForBrowserContext(child_profile); - ASSERT_TRUE(child_zoom_map); - - // Verify. - EXPECT_NE(parent_zoom_map, child_zoom_map); - - EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), - child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << - "Child must inherit from parent."; - - child_zoom_map->SetZoomLevelForHost(host, zoom_level_30); - ASSERT_EQ( - child_zoom_map->GetZoomLevelForHostAndScheme("http", host), - zoom_level_30); - - EXPECT_NE(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), - child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << - "Child change must not propagate to parent."; - - parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); - ASSERT_EQ( - parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), - zoom_level_40); - - EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), - child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << - "Parent change should propagate to child."; - base::RunLoop().RunUntilIdle(); -} diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index f57decd..ebe8fbb 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -17,8 +17,10 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" #include "components/pref_registry/pref_registry_syncable.h" #include "components/sync_driver/sync_prefs.h" +#include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" @@ -267,3 +269,9 @@ bool ProfileCompare::operator()(Profile* a, Profile* b) const { return false; return a->GetOriginalProfile() < b->GetOriginalProfile(); } + +double Profile::GetDefaultZoomLevelForProfile() { + return GetDefaultStoragePartition(this) + ->GetHostZoomMap() + ->GetDefaultZoomLevel(); +} diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index dd74492..dfeb21c 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -395,6 +395,10 @@ class Profile : public content::BrowserContext { // Creates an OffTheRecordProfile which points to this Profile. Profile* CreateOffTheRecordProfile(); + // Convenience method to retrieve the default zoom level for the default + // storage partition. + double GetDefaultZoomLevelForProfile(); + private: bool restored_last_session_; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 7425274..2c9c98e 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -95,7 +95,6 @@ #include "components/user_prefs/user_prefs.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/dom_storage_context.h" -#include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/storage_partition.h" @@ -156,7 +155,6 @@ using base::TimeDelta; using base::UserMetricsAction; using content::BrowserThread; using content::DownloadManagerDelegate; -using content::HostZoomMap; namespace { @@ -632,8 +630,6 @@ void ProfileImpl::DoFinalInit() { session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; } - InitHostZoomMap(); - base::Callback<void(bool)> data_reduction_proxy_unavailable; scoped_ptr<data_reduction_proxy::DataReductionProxyParams> data_reduction_proxy_params; @@ -716,6 +712,9 @@ void ProfileImpl::DoFinalInit() { content::BrowserContext::GetDefaultStoragePartition(this)-> GetDOMStorageContext()->SetSaveSessionStorageOnDisk(); + // TODO(wjmaclean): Remove this. crbug.com/420643 + chrome::MigrateProfileZoomLevelPrefs(this); + // The DomDistillerViewerSource is not a normal WebUI so it must be registered // as a URLDataSource early. RegisterDomDistillerViewerSource(this); @@ -757,17 +756,6 @@ void ProfileImpl::DoFinalInit() { #endif } -void ProfileImpl::InitHostZoomMap() { - HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); - DCHECK(!zoom_level_prefs_); - zoom_level_prefs_.reset( - new chrome::ChromeZoomLevelPrefs(prefs_.get(), GetPath())); - zoom_level_prefs_->InitPrefsAndCopyToHostZoomMap(GetPath(), host_zoom_map); - - // TODO(wjmaclean): Remove this. crbug.com/420643 - chrome::MigrateProfileZoomLevelPrefs(this); -} - base::FilePath ProfileImpl::last_selected_directory() { return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); } @@ -830,6 +818,12 @@ Profile::ProfileType ProfileImpl::GetProfileType() const { return REGULAR_PROFILE; } +scoped_ptr<content::ZoomLevelDelegate> +ProfileImpl::CreateZoomLevelDelegate(const base::FilePath& partition_path) { + return make_scoped_ptr( + new chrome::ChromeZoomLevelPrefs(GetPrefs(), GetPath(), partition_path)); +} + base::FilePath ProfileImpl::GetPath() const { return path_; } @@ -987,7 +981,8 @@ PrefService* ProfileImpl::GetPrefs() { } chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { - return zoom_level_prefs_.get(); + return static_cast<chrome::ChromeZoomLevelPrefs*>( + GetDefaultStoragePartition(this)->GetZoomLevelDelegate()); } PrefService* ProfileImpl::GetOffTheRecordPrefs() { diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 2ff686e..eca569e 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -76,6 +76,8 @@ class ProfileImpl : public Profile { static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); // content::BrowserContext implementation: + scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; base::FilePath GetPath() const override; content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; net::URLRequestContextGetter* GetRequestContext() override; @@ -169,10 +171,6 @@ class ProfileImpl : public Profile { // Does final initialization. Should be called after prefs were loaded. void DoFinalInit(); - // TODO(wjmaclean): Delete this once the HostZoomMap moves to - // StoragePartition. - void InitHostZoomMap(); - // Does final prefs initialization and calls Init(). void OnPrefsLoaded(bool success); @@ -235,10 +233,6 @@ class ProfileImpl : public Profile { scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; scoped_ptr<PrefServiceSyncable> prefs_; scoped_ptr<PrefServiceSyncable> otr_prefs_; - // TODO(wjmaclean): This is only here temporarily until HostZoomMap moves - // into StoragePartition, after which it will also move to StoragePartition. - // Must declare this here so it is destroyed before the profile prefs service. - scoped_ptr<chrome::ChromeZoomLevelPrefs> zoom_level_prefs_; ProfileImplIOData::Handle io_data_; #if defined(ENABLE_EXTENSIONS) scoped_refptr<ExtensionSpecialStoragePolicy> diff --git a/chrome/browser/ui/app_list/test/fake_profile.cc b/chrome/browser/ui/app_list/test/fake_profile.cc index 91f9e3e..98aa668 100644 --- a/chrome/browser/ui/app_list/test/fake_profile.cc +++ b/chrome/browser/ui/app_list/test/fake_profile.cc @@ -25,6 +25,11 @@ base::FilePath FakeProfile::GetPath() const { return path_; } +scoped_ptr<content::ZoomLevelDelegate> FakeProfile::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + return nullptr; +} + bool FakeProfile::IsOffTheRecord() const { return false; } diff --git a/chrome/browser/ui/app_list/test/fake_profile.h b/chrome/browser/ui/app_list/test/fake_profile.h index 5053451..083cf6e 100644 --- a/chrome/browser/ui/app_list/test/fake_profile.h +++ b/chrome/browser/ui/app_list/test/fake_profile.h @@ -22,6 +22,7 @@ namespace content { class DownloadManagerDelegate; class ResourceContext; class SSLHostStateDelegate; +class ZoomLevelDelegate; } class FakeProfile : public Profile { @@ -33,6 +34,8 @@ class FakeProfile : public Profile { std::string GetProfileName() override; ProfileType GetProfileType() const override; base::FilePath GetPath() const override; + scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; bool IsOffTheRecord() const override; content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; net::URLRequestContextGetter* GetRequestContextForRenderProcess( diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index 4057b53..27f91c3 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -283,6 +283,9 @@ WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, Build(); UpdateZoomControls(); + // By asking for the HostZoomMap via the BrowserContext, we get the map + // associated with the default storage partition, and not the one related + // to any specialized storage partitions, e.g. those used by WebViewGuests. content_zoom_subscription_ = content::HostZoomMap::GetDefaultForBrowserContext(browser->profile()) ->AddZoomLevelChangedCallback(base::Bind( diff --git a/chrome/browser/ui/views/toolbar/wrench_menu.cc b/chrome/browser/ui/views/toolbar/wrench_menu.cc index 8c1d8d2..0af66b1 100644 --- a/chrome/browser/ui/views/toolbar/wrench_menu.cc +++ b/chrome/browser/ui/views/toolbar/wrench_menu.cc @@ -61,7 +61,6 @@ #include "ui/views/widget/widget.h" using base::UserMetricsAction; -using content::HostZoomMap; using content::WebContents; using ui::MenuModel; using views::CustomButton; @@ -494,10 +493,12 @@ class WrenchMenu::ZoomView : public WrenchMenuView { decrement_button_(NULL), fullscreen_button_(NULL), zoom_label_width_(0) { - content_zoom_subscription_ = HostZoomMap::GetDefaultForBrowserContext( - menu->browser_->profile())->AddZoomLevelChangedCallback( - base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, - base::Unretained(this))); + content_zoom_subscription_ = + content::HostZoomMap::GetDefaultForBrowserContext( + menu->browser_->profile()) + ->AddZoomLevelChangedCallback( + base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, + base::Unretained(this))); browser_zoom_subscription_ = ZoomEventManager::GetForBrowserContext( menu->browser_->profile())->AddZoomLevelChangedCallback( @@ -634,7 +635,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView { void WrenchMenuDestroyed() override { WrenchMenuView::WrenchMenuDestroyed(); } private: - void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { + void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { UpdateZoomControls(); } diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc index b4ef36b..b073fb3 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.cc +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc @@ -490,12 +490,15 @@ void ContentSettingsHandler::InitializeHandler() { &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, base::Unretained(this))); - content::HostZoomMap* host_zoom_map = - content::HostZoomMap::GetDefaultForBrowserContext(context); + // Here we only subscribe to the HostZoomMap for the default storage partition + // since we don't allow the user to manage the zoom levels for apps. + // We're only interested in zoom-levels that are persisted, since the user + // is given the opportunity to view/delete these in the content-settings page. host_zoom_map_subscription_ = - host_zoom_map->AddZoomLevelChangedCallback( - base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, - base::Unretained(this))); + content::HostZoomMap::GetDefaultForBrowserContext(context) + ->AddZoomLevelChangedCallback( + base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, + base::Unretained(this))); flash_settings_manager_.reset(new PepperFlashSettingsManager(this, context)); diff --git a/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc b/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc index 4125794..28c1bdd 100644 --- a/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc +++ b/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc @@ -34,51 +34,24 @@ std::string GetHash( namespace chrome { ChromeZoomLevelPrefs::ChromeZoomLevelPrefs(PrefService* pref_service, - const base::FilePath& profile_path) + const base::FilePath& profile_path, + const base::FilePath& partition_path) : pref_service_(pref_service), - profile_path_(profile_path), host_zoom_map_(nullptr) { DCHECK(pref_service_); -} - -ChromeZoomLevelPrefs::~ChromeZoomLevelPrefs() { -} -void ChromeZoomLevelPrefs::InitPrefsAndCopyToHostZoomMap( - const base::FilePath& partition_path, - content::HostZoomMap* host_zoom_map) { DCHECK(!partition_path.empty()); - DCHECK((partition_path == profile_path_) || - profile_path_.IsParent(partition_path)); - // This init function must be called only once. - DCHECK(!host_zoom_map_); - DCHECK(host_zoom_map); - host_zoom_map_ = host_zoom_map; - + DCHECK((partition_path == profile_path) || + profile_path.IsParent(partition_path)); // Create a partition_key string with no '.'s in it. For the default // StoragePartition, this string will always be "0". base::FilePath partition_relative_path; - profile_path_.AppendRelativePath(partition_path, &partition_relative_path); + profile_path.AppendRelativePath(partition_path, &partition_relative_path); partition_key_ = GetHash(partition_relative_path); - // Initialize the default zoom level. - host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref()); +} - // Initialize the HostZoomMap with per-host zoom levels from the persisted - // zoom-level preference values. - const base::DictionaryValue* host_zoom_dictionaries = - pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels); - const base::DictionaryValue* host_zoom_dictionary = nullptr; - if (host_zoom_dictionaries->GetDictionary(partition_key_, - &host_zoom_dictionary)) { - // Since we're calling this before setting up zoom_subscription_ below we - // don't need to worry that host_zoom_dictionary is indirectly affected - // by calls to HostZoomMap::SetZoomLevelForHost(). - ExtractPerHostZoomLevels(host_zoom_dictionary, - true /* sanitize_partition_host_zoom_levels */); - } - zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( - &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); +ChromeZoomLevelPrefs::~ChromeZoomLevelPrefs() { } std::string ChromeZoomLevelPrefs::GetHashForTesting( @@ -196,4 +169,31 @@ void ChromeZoomLevelPrefs::ExtractPerHostZoomLevels( } } +void ChromeZoomLevelPrefs::InitHostZoomMap( + content::HostZoomMap* host_zoom_map) { + // This init function must be called only once. + DCHECK(!host_zoom_map_); + DCHECK(host_zoom_map); + host_zoom_map_ = host_zoom_map; + + // Initialize the default zoom level. + host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref()); + + // Initialize the HostZoomMap with per-host zoom levels from the persisted + // zoom-level preference values. + const base::DictionaryValue* host_zoom_dictionaries = + pref_service_->GetDictionary(prefs::kPartitionPerHostZoomLevels); + const base::DictionaryValue* host_zoom_dictionary = nullptr; + if (host_zoom_dictionaries->GetDictionary(partition_key_, + &host_zoom_dictionary)) { + // Since we're calling this before setting up zoom_subscription_ below we + // don't need to worry that host_zoom_dictionary is indirectly affected + // by calls to HostZoomMap::SetZoomLevelForHost(). + ExtractPerHostZoomLevels(host_zoom_dictionary, + true /* sanitize_partition_host_zoom_levels */); + } + zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( + &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); +} + } // namespace chrome diff --git a/chrome/browser/ui/zoom/chrome_zoom_level_prefs.h b/chrome/browser/ui/zoom/chrome_zoom_level_prefs.h index ff0eb84..e08aa63 100644 --- a/chrome/browser/ui/zoom/chrome_zoom_level_prefs.h +++ b/chrome/browser/ui/zoom/chrome_zoom_level_prefs.h @@ -15,6 +15,7 @@ #include "base/prefs/pref_service.h" #include "base/prefs/pref_store.h" #include "content/public/browser/host_zoom_map.h" +#include "content/public/browser/zoom_level_delegate.h" namespace base { class DictionaryValue; @@ -28,25 +29,22 @@ namespace chrome { // to the per-partition default zoom levels from chrome/ flow through this // class. Any changes to per-host levels are updated when HostZoomMap calls // OnZoomLevelChanged. -class ChromeZoomLevelPrefs { +class ChromeZoomLevelPrefs : public content::ZoomLevelDelegate { public: typedef base::CallbackList<void(void)>::Subscription DefaultZoomLevelSubscription; - // Initialize the pref_service and the profile_path via the constructor, + // Initialize the pref_service and the partition_key via the constructor, // as these concepts won't be available in the content base class - // (to be added later) which will define the InitPrefsAndCopyToHostZoomMap - // interface. |pref_service_| must outlive this class. + // ZoomLevelDelegate, which will define the InitHostZoomMap interface. + // |pref_service_| must outlive this class. ChromeZoomLevelPrefs(PrefService* pref_service, - const base::FilePath& profile_path); + const base::FilePath& profile_path, + const base::FilePath& partition_path); virtual ~ChromeZoomLevelPrefs(); static std::string GetHashForTesting(const base::FilePath& relative_path); - virtual void InitPrefsAndCopyToHostZoomMap( - const base::FilePath& partition_path, - content::HostZoomMap* host_zoom_map); - void SetDefaultZoomLevelPref(double level); double GetDefaultZoomLevelPref() const; scoped_ptr<DefaultZoomLevelSubscription> RegisterDefaultZoomLevelCallback( @@ -56,6 +54,9 @@ class ChromeZoomLevelPrefs { const base::DictionaryValue* host_zoom_dictionary, bool sanitize_partition_host_zoom_levels); + // content::ZoomLevelDelegate + void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override; + private: // This is a callback function that receives notifications from HostZoomMap // when per-host zoom levels change. It is used to update the per-host @@ -63,7 +64,6 @@ class ChromeZoomLevelPrefs { void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); PrefService* pref_service_; - const base::FilePath profile_path_; content::HostZoomMap* host_zoom_map_; scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; std::string partition_key_; diff --git a/chrome/browser/ui/zoom/zoom_controller.cc b/chrome/browser/ui/zoom/zoom_controller.cc index a9b7029..1918ce5 100644 --- a/chrome/browser/ui/zoom/zoom_controller.cc +++ b/chrome/browser/ui/zoom/zoom_controller.cc @@ -27,10 +27,8 @@ ZoomController::ZoomController(content::WebContents* web_contents) zoom_mode_(ZOOM_MODE_DEFAULT), zoom_level_(1.0), browser_context_(web_contents->GetBrowserContext()) { - // TODO(wjmaclean) Make calls to HostZoomMap::GetDefaultForBrowserContext() - // refer to the webcontents-specific HostZoomMap when that becomes available. content::HostZoomMap* host_zoom_map = - content::HostZoomMap::GetDefaultForBrowserContext(browser_context_); + content::HostZoomMap::GetForWebContents(web_contents); zoom_level_ = host_zoom_map->GetDefaultZoomLevel(); zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( @@ -118,7 +116,7 @@ bool ZoomController::SetZoomLevelByExtension( } content::HostZoomMap* zoom_map = - content::HostZoomMap::GetDefaultForBrowserContext(browser_context_); + content::HostZoomMap::GetForWebContents(web_contents()); DCHECK(zoom_map); DCHECK(!event_data_); event_data_.reset(new ZoomChangedEventData(web_contents(), @@ -152,7 +150,7 @@ void ZoomController::SetZoomMode(ZoomMode new_mode) { return; content::HostZoomMap* zoom_map = - content::HostZoomMap::GetDefaultForBrowserContext(browser_context_); + content::HostZoomMap::GetForWebContents(web_contents()); DCHECK(zoom_map); int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); diff --git a/chrome/browser/ui/zoom/zoom_controller.h b/chrome/browser/ui/zoom/zoom_controller.h index db771ee..7dad4ad 100644 --- a/chrome/browser/ui/zoom/zoom_controller.h +++ b/chrome/browser/ui/zoom/zoom_controller.h @@ -73,10 +73,8 @@ class ZoomController : public content::WebContentsObserver, // Convenience method to get default zoom level. Implemented here for // inlining. double GetDefaultZoomLevel() const { - // TODO(wjmaclean) Make this refer to the webcontents-specific HostZoomMap - // when that becomes available. - return content::HostZoomMap::GetDefaultForBrowserContext(browser_context_)-> - GetDefaultZoomLevel(); + return content::HostZoomMap::GetForWebContents(web_contents()) + ->GetDefaultZoomLevel(); } // Convenience method to quickly check if the tab's at default zoom. diff --git a/chrome/browser/ui/zoom/zoom_controller_browsertest.cc b/chrome/browser/ui/zoom/zoom_controller_browsertest.cc index 36a2114..4d0ffd5 100644 --- a/chrome/browser/ui/zoom/zoom_controller_browsertest.cc +++ b/chrome/browser/ui/zoom/zoom_controller_browsertest.cc @@ -20,8 +20,6 @@ #include "content/public/test/browser_test_utils.h" #include "testing/gmock/include/gmock/gmock.h" -typedef InProcessBrowserTest ZoomControllerBrowserTest; - bool operator==(const ZoomController::ZoomChangedEventData& lhs, const ZoomController::ZoomChangedEventData& rhs) { return lhs.web_contents == rhs.web_contents && @@ -59,7 +57,17 @@ class ZoomChangedWatcher : public ZoomObserver { DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); }; -// TODO(wjmaclean): Enable this on Android when we can kill the process there. +class TestZoomObserver : public ZoomObserver { + public: + MOCK_METHOD1(OnZoomChanged, + void(const ZoomController::ZoomChangedEventData&)); +}; + +class ZoomControllerBrowserTest: public InProcessBrowserTest { + protected: + TestZoomObserver zoom_observer_; +}; + #if defined(OS_ANDROID) #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom #else @@ -133,3 +141,28 @@ IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, ErrorPagesCanZoom) { zoom_controller->SetZoomLevel(new_zoom_level); EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); } + +IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, Observe) { + content::WebContents* web_contents = + browser()->tab_strip_model()->GetActiveWebContents(); + ZoomController* zoom_controller = + ZoomController::FromWebContents(web_contents); + zoom_controller->AddObserver(&zoom_observer_); + + double new_zoom_level = 1.0; + // When the event is initiated from HostZoomMap, the old zoom level is not + // available. + ZoomController::ZoomChangedEventData zoom_change_data( + web_contents, + new_zoom_level, + new_zoom_level, + ZoomController::ZOOM_MODE_DEFAULT, + true); // We have a non-empty host, so this will be 'true'. + EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data)).Times(1); + + content::HostZoomMap* host_zoom_map = + content::HostZoomMap::GetDefaultForBrowserContext( + web_contents->GetBrowserContext()); + + host_zoom_map->SetZoomLevelForHost("about:blank", new_zoom_level); +} diff --git a/chrome/browser/ui/zoom/zoom_controller_unittest.cc b/chrome/browser/ui/zoom/zoom_controller_unittest.cc index 1d468f9..2db242f 100644 --- a/chrome/browser/ui/zoom/zoom_controller_unittest.cc +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc @@ -70,25 +70,6 @@ TEST_F(ZoomControllerTest, DidNavigateMainFrame) { content::FrameNavigateParams()); } -TEST_F(ZoomControllerTest, Observe) { - double new_zoom_level = 110.0; - // When the event is initiated from HostZoomMap, the old zoom level is not - // available. - ZoomController::ZoomChangedEventData zoom_change_data( - web_contents(), - new_zoom_level, - new_zoom_level, - ZoomController::ZOOM_MODE_DEFAULT, - false); - EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data)).Times(1); - - content::HostZoomMap* host_zoom_map = - content::HostZoomMap::GetDefaultForBrowserContext( - web_contents()->GetBrowserContext()); - - host_zoom_map->SetZoomLevelForHost(std::string(), new_zoom_level); -} - TEST_F(ZoomControllerTest, Observe_ZoomController) { double old_zoom_level = zoom_controller_->GetZoomLevel(); double new_zoom_level = 110.0; diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 643f404..07e776e 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -628,7 +628,6 @@ 'browser/profiles/file_path_verifier_win_unittest.cc', 'browser/profiles/gaia_info_update_service_unittest.cc', 'browser/profiles/incognito_mode_policy_handler_unittest.cc', - 'browser/profiles/off_the_record_profile_impl_unittest.cc', 'browser/profiles/profile_downloader_unittest.cc', 'browser/profiles/profile_info_cache_unittest.cc', 'browser/profiles/profile_info_cache_unittest.h', @@ -2587,7 +2586,6 @@ 'browser/font_family_cache_unittest.cc', 'browser/policy/policy_path_parser_unittest.cc', 'browser/process_singleton_posix_unittest.cc', - 'browser/profiles/off_the_record_profile_impl_unittest.cc', 'browser/profiles/profile_list_desktop_unittest.cc', 'browser/power/process_power_collector_unittest.cc', 'browser/renderer_context_menu/render_view_context_menu_unittest.cc', diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 5588f656..2f540ca 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -634,6 +634,11 @@ base::FilePath TestingProfile::GetPath() const { return profile_path_; } +scoped_ptr<content::ZoomLevelDelegate> TestingProfile::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + return nullptr; +} + scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() { return base::MessageLoop::current()->message_loop_proxy(); } diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index df2c135..274f6c42 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -17,6 +17,7 @@ namespace content { class MockResourceContext; class SSLHostStateDelegate; +class ZoomLevelDelegate; } namespace history { @@ -221,6 +222,8 @@ class TestingProfile : public Profile { // content::BrowserContext base::FilePath GetPath() const override; + scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override; bool IsOffTheRecord() const override; content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc index 0c5eb52..fc43b2c 100644 --- a/content/browser/download/download_manager_impl_unittest.cc +++ b/content/browser/download/download_manager_impl_unittest.cc @@ -28,6 +28,7 @@ #include "content/public/browser/download_interrupt_reasons.h" #include "content/public/browser/download_item.h" #include "content/public/browser/download_manager_delegate.h" +#include "content/public/browser/zoom_level_delegate.h" #include "content/public/test/mock_download_item.h" #include "content/public/test/test_browser_context.h" #include "content/public/test/test_browser_thread.h" @@ -53,6 +54,16 @@ ACTION_TEMPLATE(RunCallback, return ::std::tr1::get<k>(args).Run(p0); } +// Create a specialization so we can mock an override for +// scoped_ptr<content::ZoomLevelDelegate> +// BrowserContext::CreateZoomLevelDelegate(const base::FilePath&). +template<> +class scoped_ptr<content::ZoomLevelDelegate> { + public: + scoped_ptr() {} + ~scoped_ptr() {} +}; + namespace content { class ByteStreamReader; @@ -401,6 +412,8 @@ class MockBrowserContext : public BrowserContext { ~MockBrowserContext() {} MOCK_CONST_METHOD0(GetPath, base::FilePath()); + MOCK_METHOD1(CreateZoomLevelDelegate, + scoped_ptr<ZoomLevelDelegate>(const base::FilePath&)); MOCK_CONST_METHOD0(IsOffTheRecord, bool()); MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); MOCK_METHOD1(GetRequestContextForRenderProcess, diff --git a/content/browser/host_zoom_level_context.cc b/content/browser/host_zoom_level_context.cc new file mode 100644 index 0000000..02ddcf5 --- /dev/null +++ b/content/browser/host_zoom_level_context.cc @@ -0,0 +1,32 @@ +// Copyright 2014 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 "content/browser/host_zoom_level_context.h" + +#include "base/files/file_path.h" +#include "content/browser/host_zoom_map_impl.h" +#include "content/public/browser/browser_thread.h" + +namespace content { + +HostZoomLevelContext::HostZoomLevelContext( + scoped_ptr<ZoomLevelDelegate> zoom_level_delegate) + : host_zoom_map_impl_(new HostZoomMapImpl()), + zoom_level_delegate_(zoom_level_delegate.Pass()) { + if (zoom_level_delegate_) + zoom_level_delegate_->InitHostZoomMap(host_zoom_map_impl_.get()); +} + +HostZoomLevelContext::~HostZoomLevelContext() {} + +void HostZoomLevelContext::DeleteOnCorrectThread() const { + if (BrowserThread::IsMessageLoopValid(BrowserThread::UI) && + !BrowserThread::CurrentlyOn(BrowserThread::UI)) { + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); + return; + } + delete this; +} + +} // namespace content diff --git a/content/browser/host_zoom_level_context.h b/content/browser/host_zoom_level_context.h new file mode 100644 index 0000000..e45222f --- /dev/null +++ b/content/browser/host_zoom_level_context.h @@ -0,0 +1,61 @@ +// Copyright 2014 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 CONTENT_BROWSER_HOST_ZOOM_LEVEL_CONTEXT_H_ +#define CONTENT_BROWSER_HOST_ZOOM_LEVEL_CONTEXT_H_ + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "content/browser/host_zoom_map_impl.h" +#include "content/public/browser/zoom_level_delegate.h" + +class PrefService; + +namespace content { +struct HostZoomLevelContextDeleter; + +// This class manages a HostZoomMap and associates it with a ZoomLevelDelegate, +// if one is provided. It also serves to keep the zoom level machinery details +// separate from the owning StoragePartitionImpl. +class HostZoomLevelContext + : public base::RefCountedThreadSafe<HostZoomLevelContext, + HostZoomLevelContextDeleter> { + public: + explicit HostZoomLevelContext( + scoped_ptr<ZoomLevelDelegate> zoom_level_delegate); + + HostZoomMap* GetHostZoomMap() const { return host_zoom_map_impl_.get(); } + ZoomLevelDelegate* GetZoomLevelDelegate() const { + return zoom_level_delegate_.get(); + } + + protected: + virtual ~HostZoomLevelContext(); + + private: + friend class base::DeleteHelper<HostZoomLevelContext>; + friend class base::RefCountedThreadSafe<HostZoomLevelContext, + HostZoomLevelContextDeleter>; + friend struct HostZoomLevelContextDeleter; + + void DeleteOnCorrectThread() const; + + scoped_ptr<HostZoomMapImpl> host_zoom_map_impl_; + // Release the delegate before the HostZoomMap, in case it is carrying + // any HostZoomMap::Subscription pointers. + scoped_ptr<ZoomLevelDelegate> zoom_level_delegate_; + + DISALLOW_COPY_AND_ASSIGN(HostZoomLevelContext); +}; + +struct HostZoomLevelContextDeleter { + static void Destruct(const HostZoomLevelContext* context) { + context->DeleteOnCorrectThread(); + } +}; + +} // namespace content + +#endif // CONTENT_BROWSER_HOST_ZOOM_LEVEL_CONTEXT_H_ diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc index 81f8182..b6595b9 100644 --- a/content/browser/host_zoom_map_impl.cc +++ b/content/browser/host_zoom_map_impl.cc @@ -20,6 +20,8 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/resource_context.h" +#include "content/public/browser/site_instance.h" +#include "content/public/browser/storage_partition.h" #include "content/public/common/page_zoom.h" #include "content/public/common/url_constants.h" #include "net/base/net_util.h" @@ -28,8 +30,6 @@ namespace content { namespace { -const char kHostZoomMapKeyName[] = "content_host_zoom_map"; - std::string GetHostFromProcessView(int render_process_id, int render_view_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); RenderViewHost* render_view_host = @@ -61,29 +61,39 @@ GURL HostZoomMap::GetURLFromEntry(const NavigationEntry* entry) { } HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) { - HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>( - context->GetUserData(kHostZoomMapKeyName)); - if (!rv) { - rv = new HostZoomMapImpl(); - context->SetUserData(kHostZoomMapKeyName, rv); - } - return rv; + StoragePartition* partition = + BrowserContext::GetDefaultStoragePartition(context); + DCHECK(partition); + return partition->GetHostZoomMap(); +} + +HostZoomMap* HostZoomMap::Get(SiteInstance* instance) { + StoragePartition* partition = BrowserContext::GetStoragePartition( + instance->GetBrowserContext(), instance); + DCHECK(partition); + return partition->GetHostZoomMap(); +} + +HostZoomMap* HostZoomMap::GetForWebContents(const WebContents* contents) { + StoragePartition* partition = + BrowserContext::GetStoragePartition(contents->GetBrowserContext(), + contents->GetSiteInstance()); + DCHECK(partition); + return partition->GetHostZoomMap(); } // Helper function for setting/getting zoom levels for WebContents without // having to import HostZoomMapImpl everywhere. double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { - HostZoomMapImpl* host_zoom_map = - static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( - web_contents->GetBrowserContext())); + HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( + HostZoomMap::GetForWebContents(web_contents)); return host_zoom_map->GetZoomLevelForWebContents( *static_cast<const WebContentsImpl*>(web_contents)); } void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { - HostZoomMapImpl* host_zoom_map = - static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( - web_contents->GetBrowserContext())); + HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( + HostZoomMap::GetForWebContents(web_contents)); host_zoom_map->SetZoomLevelForWebContents( *static_cast<const WebContentsImpl*>(web_contents), level); } @@ -243,10 +253,12 @@ void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, } double HostZoomMapImpl::GetDefaultZoomLevel() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); return default_zoom_level_; } void HostZoomMapImpl::SetDefaultZoomLevel(double level) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); default_zoom_level_ = level; } @@ -396,8 +408,10 @@ void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); !i.IsAtEnd(); i.Advance()) { RenderProcessHost* render_process_host = i.GetCurrentValue(); - if (HostZoomMap::GetDefaultForBrowserContext( - render_process_host->GetBrowserContext()) == this) { + // TODO(wjmaclean) This will need to be cleaned up when + // RenderProcessHost::GetStoragePartition() goes away. Perhaps have + // RenderProcessHost expose a GetHostZoomMap() function? + if (render_process_host->GetStoragePartition()->GetHostZoomMap() == this) { render_process_host->Send( new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); } @@ -413,6 +427,7 @@ void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { } HostZoomMapImpl::~HostZoomMapImpl() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } } // namespace content diff --git a/content/browser/host_zoom_map_impl.h b/content/browser/host_zoom_map_impl.h index 78d643d..f900287 100644 --- a/content/browser/host_zoom_map_impl.h +++ b/content/browser/host_zoom_map_impl.h @@ -11,7 +11,6 @@ #include "base/compiler_specific.h" #include "base/sequenced_task_runner_helpers.h" -#include "base/supports_user_data.h" #include "base/synchronization/lock.h" #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_observer.h" @@ -24,8 +23,7 @@ class WebContentsImpl; // HostZoomMap needs to be deleted on the UI thread because it listens // to notifications on there (and holds a NotificationRegistrar). class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), - public NotificationObserver, - public base::SupportsUserData::Data { + public NotificationObserver { public: HostZoomMapImpl(); ~HostZoomMapImpl() override; diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc index 5125bec..51b0a744 100644 --- a/content/browser/loader/async_resource_handler.cc +++ b/content/browser/loader/async_resource_handler.cc @@ -193,8 +193,7 @@ bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response, DevToolsNetLogObserver::PopulateResponseInfo(request(), response); - HostZoomMap* host_zoom_map = - GetHostZoomMapForResourceContext(info->GetContext()); + const HostZoomMap* host_zoom_map = info->filter()->GetHostZoomMap(); if (info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME && host_zoom_map) { const GURL& request_url = request()->url(); diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc index d18facd..3017086 100644 --- a/content/browser/loader/resource_dispatcher_host_unittest.cc +++ b/content/browser/loader/resource_dispatcher_host_unittest.cc @@ -210,7 +210,7 @@ class TestFilter : public ResourceMessageFilter { explicit TestFilter(ResourceContext* resource_context) : ResourceMessageFilter( ChildProcessHostImpl::GenerateChildProcessUniqueId(), - PROCESS_TYPE_RENDERER, NULL, NULL, NULL, NULL, + PROCESS_TYPE_RENDERER, NULL, NULL, NULL, NULL, NULL, base::Bind(&TestFilter::GetContexts, base::Unretained(this))), resource_context_(resource_context), canceled_(false), diff --git a/content/browser/loader/resource_message_filter.cc b/content/browser/loader/resource_message_filter.cc index 9ffa29f..4a20d9a 100644 --- a/content/browser/loader/resource_message_filter.cc +++ b/content/browser/loader/resource_message_filter.cc @@ -6,6 +6,7 @@ #include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/fileapi/chrome_blob_storage_context.h" +#include "content/browser/host_zoom_level_context.h" #include "content/browser/loader/resource_dispatcher_host_impl.h" #include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/common/resource_messages.h" @@ -21,6 +22,7 @@ ResourceMessageFilter::ResourceMessageFilter( ChromeBlobStorageContext* blob_storage_context, storage::FileSystemContext* file_system_context, ServiceWorkerContextWrapper* service_worker_context, + HostZoomLevelContext* host_zoom_level_context, const GetContextsCallback& get_contexts_callback) : BrowserMessageFilter(ResourceMsgStart), child_id_(child_id), @@ -29,6 +31,7 @@ ResourceMessageFilter::ResourceMessageFilter( blob_storage_context_(blob_storage_context), file_system_context_(file_system_context), service_worker_context_(service_worker_context), + host_zoom_level_context_(host_zoom_level_context), get_contexts_callback_(get_contexts_callback), weak_ptr_factory_(this) { } @@ -53,6 +56,12 @@ void ResourceMessageFilter::GetContexts( return get_contexts_callback_.Run(request, resource_context, request_context); } +const HostZoomMap* ResourceMessageFilter::GetHostZoomMap() const { + if (host_zoom_level_context_.get()) + return host_zoom_level_context_->GetHostZoomMap(); + return NULL; +} + base::WeakPtr<ResourceMessageFilter> ResourceMessageFilter::GetWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } diff --git a/content/browser/loader/resource_message_filter.h b/content/browser/loader/resource_message_filter.h index 3b52a77..1240cb4 100644 --- a/content/browser/loader/resource_message_filter.h +++ b/content/browser/loader/resource_message_filter.h @@ -26,6 +26,8 @@ class URLRequestContext; namespace content { class ChromeAppCacheService; class ChromeBlobStorageContext; +class HostZoomLevelContext; +class HostZoomMap; class ResourceContext; class ServiceWorkerContextWrapper; @@ -48,6 +50,7 @@ class CONTENT_EXPORT ResourceMessageFilter : public BrowserMessageFilter { ChromeBlobStorageContext* blob_storage_context, storage::FileSystemContext* file_system_context, ServiceWorkerContextWrapper* service_worker_context, + HostZoomLevelContext* host_zoom_level_context, const GetContextsCallback& get_contexts_callback); // BrowserMessageFilter implementation. @@ -77,6 +80,10 @@ class CONTENT_EXPORT ResourceMessageFilter : public BrowserMessageFilter { return service_worker_context_.get(); } + // Returns a raw pointer to the HostZoomLevelContext's associated HostZoomMap, + // or NULL if no context is present. + const HostZoomMap* GetHostZoomMap() const; + int child_id() const { return child_id_; } int process_type() const { return process_type_; } @@ -96,6 +103,7 @@ class CONTENT_EXPORT ResourceMessageFilter : public BrowserMessageFilter { scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; scoped_refptr<storage::FileSystemContext> file_system_context_; scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; + scoped_refptr<HostZoomLevelContext> host_zoom_level_context_; GetContextsCallback get_contexts_callback_; diff --git a/content/browser/loader/resource_scheduler_unittest.cc b/content/browser/loader/resource_scheduler_unittest.cc index 2d1b0fe..fb54951 100644 --- a/content/browser/loader/resource_scheduler_unittest.cc +++ b/content/browser/loader/resource_scheduler_unittest.cc @@ -120,6 +120,7 @@ class FakeResourceMessageFilter : public ResourceMessageFilter { NULL /* blob_storage_context */, NULL /* file_system_context */, NULL /* service_worker_context */, + NULL /* host_zoom_level_context */, base::Bind(&FakeResourceMessageFilter::GetContexts, base::Unretained(this))) { } diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc index dd969d3e..88b42ad 100644 --- a/content/browser/plugin_process_host.cc +++ b/content/browser/plugin_process_host.cc @@ -262,10 +262,11 @@ bool PluginProcessHost::Init(const WebPluginInfo& info) { base::Bind(&PluginProcessHost::GetContexts, base::Unretained(this))); - // TODO(jam): right now we're passing NULL for appcache, blob storage, and - // file system. If NPAPI plugins actually use this, we'll have to plumb them. + // TODO(jam): right now we're passing NULL for appcache, blob storage, file + // system and host zoom level context. If NPAPI plugins actually use this, + // we'll have to plumb them. ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( - process_->GetData().id, PROCESS_TYPE_PLUGIN, NULL, NULL, NULL, NULL, + process_->GetData().id, PROCESS_TYPE_PLUGIN, NULL, NULL, NULL, NULL, NULL, get_contexts_callback); process_->AddFilter(resource_message_filter); return true; diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 84a31ba8..079f6e9dd 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -716,6 +716,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { ChromeBlobStorageContext::GetFor(browser_context), storage_partition_impl_->GetFileSystemContext(), storage_partition_impl_->GetServiceWorkerContext(), + storage_partition_impl_->GetHostZoomLevelContext(), get_contexts_callback); AddFilter(resource_message_filter); diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 8bafdab..e704fb6 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -1104,8 +1104,7 @@ void RenderViewHostImpl::OnDocumentAvailableInMainFrame( return; HostZoomMapImpl* host_zoom_map = - static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( - GetProcess()->GetBrowserContext())); + static_cast<HostZoomMapImpl*>(HostZoomMap::Get(GetSiteInstance())); host_zoom_map->SetTemporaryZoomLevel(GetProcess()->GetID(), GetRoutingID(), host_zoom_map->GetDefaultZoomLevel()); @@ -1420,8 +1419,7 @@ void RenderViewHostImpl::NotifyMoveOrResizeStarted() { void RenderViewHostImpl::OnDidZoomURL(double zoom_level, const GURL& url) { HostZoomMapImpl* host_zoom_map = - static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( - GetProcess()->GetBrowserContext())); + static_cast<HostZoomMapImpl*>(HostZoomMap::Get(GetSiteInstance())); host_zoom_map->SetZoomLevelForView(GetProcess()->GetID(), GetRoutingID(), diff --git a/content/browser/resource_context_impl.cc b/content/browser/resource_context_impl.cc index f9f3bc8..e7e4d0a 100644 --- a/content/browser/resource_context_impl.cc +++ b/content/browser/resource_context_impl.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "content/browser/fileapi/chrome_blob_storage_context.h" -#include "content/browser/host_zoom_map_impl.h" #include "content/browser/loader/resource_dispatcher_host_impl.h" #include "content/browser/loader/resource_request_info_impl.h" #include "content/browser/streams/stream_context.h" @@ -24,19 +23,9 @@ namespace { // Key names on ResourceContext. const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; -const char kHostZoomMapKeyName[] = "content_host_zoom_map"; const char kStreamContextKeyName[] = "content_stream_context"; const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; -class NonOwningZoomData : public base::SupportsUserData::Data { - public: - explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {} - HostZoomMap* host_zoom_map() { return host_zoom_map_; } - - private: - HostZoomMap* host_zoom_map_; -}; - // Used by the default implementation of GetMediaDeviceIDSalt, below. std::string ReturnEmptySalt() { return std::string(); @@ -92,15 +81,6 @@ StreamContext* GetStreamContextForResourceContext( resource_context, kStreamContextKeyName); } -HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - NonOwningZoomData* result = static_cast<NonOwningZoomData*>( - context->GetUserData(kHostZoomMapKeyName)); - if (!result) - return NULL; - return result->host_zoom_map(); -} - URLDataManagerBackend* GetURLDataManagerForResourceContext( ResourceContext* context) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -114,7 +94,6 @@ URLDataManagerBackend* GetURLDataManagerForResourceContext( void InitializeResourceContext(BrowserContext* browser_context) { ResourceContext* resource_context = browser_context->GetResourceContext(); - DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName)); resource_context->SetUserData( kBlobStorageContextKeyName, @@ -126,13 +105,6 @@ void InitializeResourceContext(BrowserContext* browser_context) { new UserDataAdapter<StreamContext>( StreamContext::GetFor(browser_context))); - // This object is owned by the BrowserContext and not ResourceContext, so - // store a non-owning pointer here. - resource_context->SetUserData( - kHostZoomMapKeyName, - new NonOwningZoomData( - HostZoomMap::GetDefaultForBrowserContext(browser_context))); - resource_context->DetachUserDataThread(); } diff --git a/content/browser/resource_context_impl.h b/content/browser/resource_context_impl.h index ed4de4d..d783484 100644 --- a/content/browser/resource_context_impl.h +++ b/content/browser/resource_context_impl.h @@ -12,7 +12,6 @@ namespace content { class ChromeBlobStorageContext; class StreamContext; class BrowserContext; -class HostZoomMap; class URLDataManagerBackend; // Getters for objects that are part of BrowserContext which are also used on @@ -25,8 +24,6 @@ ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( StreamContext* GetStreamContextForResourceContext( ResourceContext* resource_context); -HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context); - URLDataManagerBackend* GetURLDataManagerForResourceContext( ResourceContext* context); diff --git a/content/browser/storage_partition_impl.cc b/content/browser/storage_partition_impl.cc index d4e49f6..d5b83bc 100644 --- a/content/browser/storage_partition_impl.cc +++ b/content/browser/storage_partition_impl.cc @@ -10,6 +10,7 @@ #include "content/browser/fileapi/browser_file_system_helper.h" #include "content/browser/geofencing/geofencing_manager.h" #include "content/browser/gpu/shader_disk_cache.h" +#include "content/browser/host_zoom_map_impl.h" #include "content/common/dom_storage/dom_storage_types.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" @@ -368,7 +369,8 @@ StoragePartitionImpl::StoragePartitionImpl( ServiceWorkerContextWrapper* service_worker_context, WebRTCIdentityStore* webrtc_identity_store, storage::SpecialStoragePolicy* special_storage_policy, - GeofencingManager* geofencing_manager) + GeofencingManager* geofencing_manager, + HostZoomLevelContext* host_zoom_level_context) : partition_path_(partition_path), quota_manager_(quota_manager), appcache_service_(appcache_service), @@ -379,7 +381,8 @@ StoragePartitionImpl::StoragePartitionImpl( service_worker_context_(service_worker_context), webrtc_identity_store_(webrtc_identity_store), special_storage_policy_(special_storage_policy), - geofencing_manager_(geofencing_manager) { + geofencing_manager_(geofencing_manager), + host_zoom_level_context_(host_zoom_level_context) { } StoragePartitionImpl::~StoragePartitionImpl() { @@ -478,6 +481,10 @@ StoragePartitionImpl* StoragePartitionImpl::Create( new GeofencingManager(service_worker_context); geofencing_manager->Init(); + scoped_refptr<HostZoomLevelContext> host_zoom_level_context( + new HostZoomLevelContext( + context->CreateZoomLevelDelegate(partition_path))); + return new StoragePartitionImpl(partition_path, quota_manager.get(), appcache_service.get(), @@ -488,7 +495,8 @@ StoragePartitionImpl* StoragePartitionImpl::Create( service_worker_context.get(), webrtc_identity_store.get(), special_storage_policy.get(), - geofencing_manager.get()); + geofencing_manager.get(), + host_zoom_level_context.get()); } base::FilePath StoragePartitionImpl::GetPath() { @@ -536,6 +544,20 @@ GeofencingManager* StoragePartitionImpl::GetGeofencingManager() { return geofencing_manager_.get(); } +HostZoomMap* StoragePartitionImpl::GetHostZoomMap() { + DCHECK(host_zoom_level_context_.get()); + return host_zoom_level_context_->GetHostZoomMap(); +} + +HostZoomLevelContext* StoragePartitionImpl::GetHostZoomLevelContext() { + return host_zoom_level_context_.get(); +} + +ZoomLevelDelegate* StoragePartitionImpl::GetZoomLevelDelegate() { + DCHECK(host_zoom_level_context_.get()); + return host_zoom_level_context_->GetZoomLevelDelegate(); +} + void StoragePartitionImpl::ClearDataImpl( uint32 remove_mask, uint32 quota_storage_remove_mask, diff --git a/content/browser/storage_partition_impl.h b/content/browser/storage_partition_impl.h index 3037739..bde83ad 100644 --- a/content/browser/storage_partition_impl.h +++ b/content/browser/storage_partition_impl.h @@ -10,6 +10,7 @@ #include "base/memory/ref_counted.h" #include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/dom_storage/dom_storage_context_wrapper.h" +#include "content/browser/host_zoom_level_context.h" #include "content/browser/indexed_db/indexed_db_context_impl.h" #include "content/browser/media/webrtc_identity_store.h" #include "content/browser/service_worker/service_worker_context_wrapper.h" @@ -44,6 +45,9 @@ class StoragePartitionImpl : public StoragePartition { IndexedDBContextImpl* GetIndexedDBContext() override; ServiceWorkerContextWrapper* GetServiceWorkerContext() override; GeofencingManager* GetGeofencingManager() override; + HostZoomMap* GetHostZoomMap() override; + HostZoomLevelContext* GetHostZoomLevelContext() override; + ZoomLevelDelegate* GetZoomLevelDelegate() override; void ClearDataForOrigin(uint32 remove_mask, uint32 quota_storage_remove_mask, @@ -118,7 +122,8 @@ class StoragePartitionImpl : public StoragePartition { ServiceWorkerContextWrapper* service_worker_context, WebRTCIdentityStore* webrtc_identity_store, storage::SpecialStoragePolicy* special_storage_policy, - GeofencingManager* geofencing_manager); + GeofencingManager* geofencing_manager, + HostZoomLevelContext* host_zoom_level_context); void ClearDataImpl(uint32 remove_mask, uint32 quota_storage_remove_mask, @@ -159,6 +164,7 @@ class StoragePartitionImpl : public StoragePartition { scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_; scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; scoped_refptr<GeofencingManager> geofencing_manager_; + scoped_refptr<HostZoomLevelContext> host_zoom_level_context_; DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl); }; diff --git a/content/content_browser.gypi b/content/content_browser.gypi index df70129..b43ec6e 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -239,6 +239,7 @@ 'public/browser/web_ui_message_handler.h', 'public/browser/worker_service.h', 'public/browser/worker_service_observer.h', + 'public/browser/zoom_level_delegate.h', 'public/browser/zygote_host_linux.h', ], 'private_browser_sources': [ @@ -743,6 +744,8 @@ 'browser/histogram_subscriber.h', 'browser/histogram_synchronizer.cc', 'browser/histogram_synchronizer.h', + 'browser/host_zoom_level_context.cc', + 'browser/host_zoom_level_context.h', 'browser/host_zoom_map_impl.cc', 'browser/host_zoom_map_impl.h', 'browser/indexed_db/indexed_db.h', diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index fec68dc..02b83e7 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/supports_user_data.h" #include "content/common/content_export.h" +#include "content/public/browser/zoom_level_delegate.h" #include "content/public/common/push_messaging_status.h" class GURL; @@ -111,6 +112,11 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { ~BrowserContext() override; + // Creates a delegate to initialize a HostZoomMap and persist its information. + // This is called during creation of each StoragePartition. + virtual scoped_ptr<ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) = 0; + // Returns the path of the directory where this context's data is stored. virtual base::FilePath GetPath() const = 0; diff --git a/content/public/browser/host_zoom_map.h b/content/public/browser/host_zoom_map.h index e9e523e..653d248 100644 --- a/content/public/browser/host_zoom_map.h +++ b/content/public/browser/host_zoom_map.h @@ -20,6 +20,7 @@ namespace content { class NavigationEntry; class BrowserContext; class ResourceContext; +class SiteInstance; class WebContents; // Maps hostnames to custom zoom levels. Written on the UI thread and read on @@ -61,6 +62,17 @@ class HostZoomMap { CONTENT_EXPORT static HostZoomMap* GetDefaultForBrowserContext( BrowserContext* browser_context); + // Returns the HostZoomMap associated with this SiteInstance. The SiteInstance + // may serve multiple WebContents, and the HostZoomMap is the same for all of + // these WebContents. + CONTENT_EXPORT static HostZoomMap* Get(SiteInstance* instance); + + // Returns the HostZoomMap associated with this WebContent's main frame. If + // multiple WebContents share the same SiteInstance, then they share a single + // HostZoomMap. + CONTENT_EXPORT static HostZoomMap* GetForWebContents( + const WebContents* contents); + // Returns the current zoom level for the specified WebContents. May be // temporary or host-specific. CONTENT_EXPORT static double GetZoomLevel(const WebContents* web_contents); diff --git a/content/public/browser/storage_partition.h b/content/public/browser/storage_partition.h index c16e5e6..8335c05 100644 --- a/content/public/browser/storage_partition.h +++ b/content/public/browser/storage_partition.h @@ -40,10 +40,13 @@ namespace content { class AppCacheService; class BrowserContext; +class HostZoomLevelContext; +class HostZoomMap; class DOMStorageContext; class GeofencingManager; class IndexedDBContext; class ServiceWorkerContext; +class ZoomLevelDelegate; // Defines what persistent state a child process can access. // @@ -64,6 +67,9 @@ class CONTENT_EXPORT StoragePartition { virtual IndexedDBContext* GetIndexedDBContext() = 0; virtual ServiceWorkerContext* GetServiceWorkerContext() = 0; virtual GeofencingManager* GetGeofencingManager() = 0; + virtual HostZoomMap* GetHostZoomMap() = 0; + virtual HostZoomLevelContext* GetHostZoomLevelContext() = 0; + virtual ZoomLevelDelegate* GetZoomLevelDelegate() = 0; static const uint32 REMOVE_DATA_MASK_APPCACHE = 1 << 0; static const uint32 REMOVE_DATA_MASK_COOKIES = 1 << 1; diff --git a/content/public/browser/zoom_level_delegate.h b/content/public/browser/zoom_level_delegate.h new file mode 100644 index 0000000..e6a93bd --- /dev/null +++ b/content/public/browser/zoom_level_delegate.h @@ -0,0 +1,21 @@ +// Copyright 2014 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 CONTENT_PUBLIC_BROWSER_ZOOM_LEVEL_DELEGATE_H_ +#define CONTENT_PUBLIC_BROWSER_ZOOM_LEVEL_DELEGATE_H_ + +namespace content { + +class HostZoomMap; + +// An interface to allow the client to initialize the HostZoomMap. +class ZoomLevelDelegate { + public: + virtual void InitHostZoomMap(HostZoomMap* host_zoom_map) = 0; + virtual ~ZoomLevelDelegate() {} +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_ZOOM_LEVEL_DELEGATE_H_ diff --git a/content/public/test/mock_render_process_host.cc b/content/public/test/mock_render_process_host.cc index 7b30a6f9..d98f6e8 100644 --- a/content/public/test/mock_render_process_host.cc +++ b/content/public/test/mock_render_process_host.cc @@ -13,6 +13,7 @@ #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/common/child_process_host_impl.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/global_request_id.h" #include "content/public/browser/render_widget_host_iterator.h" #include "content/public/browser/storage_partition.h" @@ -100,7 +101,7 @@ bool MockRenderProcessHost::IsIsolatedGuest() const { } StoragePartition* MockRenderProcessHost::GetStoragePartition() const { - return NULL; + return BrowserContext::GetDefaultStoragePartition(browser_context_); } void MockRenderProcessHost::AddWord(const base::string16& word) { diff --git a/content/public/test/test_browser_context.cc b/content/public/test/test_browser_context.cc index 2aab983..9c22851 100644 --- a/content/public/test/test_browser_context.cc +++ b/content/public/test/test_browser_context.cc @@ -59,6 +59,11 @@ base::FilePath TestBrowserContext::GetPath() const { return browser_context_dir_.path(); } +scoped_ptr<ZoomLevelDelegate> TestBrowserContext::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + return scoped_ptr<ZoomLevelDelegate>(); +} + bool TestBrowserContext::IsOffTheRecord() const { return false; } diff --git a/content/public/test/test_browser_context.h b/content/public/test/test_browser_context.h index a736cb9..1310187 100644 --- a/content/public/test/test_browser_context.h +++ b/content/public/test/test_browser_context.h @@ -15,6 +15,7 @@ namespace content { class MockResourceContext; +class ZoomLevelDelegate; class TestBrowserContext : public BrowserContext { public: @@ -28,6 +29,8 @@ class TestBrowserContext : public BrowserContext { void SetSpecialStoragePolicy(storage::SpecialStoragePolicy* policy); base::FilePath GetPath() const override; + scoped_ptr<ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; bool IsOffTheRecord() const override; DownloadManagerDelegate* GetDownloadManagerDelegate() override; net::URLRequestContextGetter* GetRequestContext() override; diff --git a/content/shell/browser/shell_browser_context.cc b/content/shell/browser/shell_browser_context.cc index 8a97911..9f83562 100644 --- a/content/shell/browser/shell_browser_context.cc +++ b/content/shell/browser/shell_browser_context.cc @@ -95,6 +95,11 @@ void ShellBrowserContext::InitWhileIOAllowed() { base::CreateDirectory(path_); } +scoped_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate( + const base::FilePath&) { + return scoped_ptr<ZoomLevelDelegate>(); +} + base::FilePath ShellBrowserContext::GetPath() const { return path_; } diff --git a/content/shell/browser/shell_browser_context.h b/content/shell/browser/shell_browser_context.h index d4e146f..2162ea0 100644 --- a/content/shell/browser/shell_browser_context.h +++ b/content/shell/browser/shell_browser_context.h @@ -23,6 +23,7 @@ namespace content { class DownloadManagerDelegate; class ShellDownloadManagerDelegate; +class ZoomLevelDelegate; class ShellBrowserContext : public BrowserContext { public: @@ -36,6 +37,8 @@ class ShellBrowserContext : public BrowserContext { // BrowserContext implementation. base::FilePath GetPath() const override; + scoped_ptr<ZoomLevelDelegate> CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; bool IsOffTheRecord() const override; DownloadManagerDelegate* GetDownloadManagerDelegate() override; net::URLRequestContextGetter* GetRequestContext() override; |