OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 5 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 default_zoom_level_dictionary->GetDouble(partition_key_, &default_zoom_level); | 83 default_zoom_level_dictionary->GetDouble(partition_key_, &default_zoom_level); |
84 return default_zoom_level; | 84 return default_zoom_level; |
85 } | 85 } |
86 | 86 |
87 std::unique_ptr<ChromeZoomLevelPrefs::DefaultZoomLevelSubscription> | 87 std::unique_ptr<ChromeZoomLevelPrefs::DefaultZoomLevelSubscription> |
88 ChromeZoomLevelPrefs::RegisterDefaultZoomLevelCallback( | 88 ChromeZoomLevelPrefs::RegisterDefaultZoomLevelCallback( |
89 const base::Closure& callback) { | 89 const base::Closure& callback) { |
90 return default_zoom_changed_callbacks_.Add(callback); | 90 return default_zoom_changed_callbacks_.Add(callback); |
91 } | 91 } |
92 | 92 |
93 void ChromeZoomLevelPrefs::SetIsOriginScopePref(bool default_per_origin) { | |
94 if (default_per_origin == GetIsOriginScopePref()) | |
95 return; | |
96 | |
97 DictionaryPrefUpdate update( | |
98 pref_service_, prefs::kPartitionDefaultZoomOriginScope); | |
99 update->SetBoolean(partition_key_, default_per_origin); | |
100 default_scope_changed_callbacks_.Notify(); | |
101 } | |
102 | |
103 bool ChromeZoomLevelPrefs::GetIsOriginScopePref() const { | |
104 bool default_per_origin = true; | |
wjmaclean
2017/01/19 21:09:05
Rename |default_per_origin| to something like |is_
Kevin McNee
2017/02/03 22:51:34
Done.
| |
105 | |
106 const base::DictionaryValue* default_zoom_origin_scope_dictionary = | |
107 pref_service_->GetDictionary(prefs::kPartitionDefaultZoomOriginScope); | |
108 // If no value has been previously set, |default_per_origin| will be untouched | |
109 // from the default value we've set above. | |
110 default_zoom_origin_scope_dictionary->GetBoolean(partition_key_, | |
111 &default_per_origin); | |
112 return default_per_origin; | |
113 } | |
114 | |
115 std::unique_ptr<ChromeZoomLevelPrefs::DefaultZoomScopeSubscription> | |
116 ChromeZoomLevelPrefs::RegisterDefaultZoomScopeCallback( | |
117 const base::Closure& callback) { | |
118 return default_scope_changed_callbacks_.Add(callback); | |
119 } | |
120 | |
93 void ChromeZoomLevelPrefs::OnZoomLevelChanged( | 121 void ChromeZoomLevelPrefs::OnZoomLevelChanged( |
94 const content::HostZoomMap::ZoomLevelChange& change) { | 122 const content::HostZoomMap::ZoomLevelChange& change) { |
95 // If there's a manager to aggregate ZoomLevelChanged events, pass this event | 123 // If there's a manager to aggregate ZoomLevelChanged events, pass this event |
96 // along. Since we already hold a subscription to our associated HostZoomMap, | 124 // along. Since we already hold a subscription to our associated HostZoomMap, |
97 // we don't need to create a separate subscription for this. | 125 // we don't need to create a separate subscription for this. |
98 if (zoom_event_manager_) | 126 if (zoom_event_manager_) |
99 zoom_event_manager_->OnZoomLevelChanged(change); | 127 zoom_event_manager_->OnZoomLevelChanged(change); |
100 | 128 |
101 if (change.mode != content::HostZoomMap::ZOOM_CHANGED_FOR_HOST) | 129 if (change.mode != content::HostZoomMap::ZOOM_CHANGED_FOR_HOST) |
102 return; | 130 return; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 &host_zoom_dictionary)) { | 224 &host_zoom_dictionary)) { |
197 // Since we're calling this before setting up zoom_subscription_ below we | 225 // Since we're calling this before setting up zoom_subscription_ below we |
198 // don't need to worry that host_zoom_dictionary is indirectly affected | 226 // don't need to worry that host_zoom_dictionary is indirectly affected |
199 // by calls to HostZoomMap::SetZoomLevelForHost(). | 227 // by calls to HostZoomMap::SetZoomLevelForHost(). |
200 ExtractPerHostZoomLevels(host_zoom_dictionary, | 228 ExtractPerHostZoomLevels(host_zoom_dictionary, |
201 true /* sanitize_partition_host_zoom_levels */); | 229 true /* sanitize_partition_host_zoom_levels */); |
202 } | 230 } |
203 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( | 231 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( |
204 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); | 232 &ChromeZoomLevelPrefs::OnZoomLevelChanged, base::Unretained(this))); |
205 } | 233 } |
OLD | NEW |