OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/webui/settings/site_settings_handler.h" | 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/i18n/number_formatting.h" | 13 #include "base/i18n/number_formatting.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
19 #include "chrome/browser/permissions/chooser_context_base.h" | 19 #include "chrome/browser/permissions/chooser_context_base.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/webui/site_settings_helper.h" | 21 #include "chrome/browser/ui/webui/site_settings_helper.h" |
| 22 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 23 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 25 #include "components/content_settings/core/browser/host_content_settings_map.h" |
25 #include "components/content_settings/core/common/content_settings_types.h" | 26 #include "components/content_settings/core/common/content_settings_types.h" |
26 #include "components/crx_file/id_util.h" | 27 #include "components/crx_file/id_util.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
30 #include "content/public/common/page_zoom.h" | 31 #include "content/public/common/page_zoom.h" |
31 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 base::Unretained(this))); | 150 base::Unretained(this))); |
150 web_ui()->RegisterMessageCallback( | 151 web_ui()->RegisterMessageCallback( |
151 "isPatternValid", | 152 "isPatternValid", |
152 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, | 153 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, |
153 base::Unretained(this))); | 154 base::Unretained(this))); |
154 web_ui()->RegisterMessageCallback( | 155 web_ui()->RegisterMessageCallback( |
155 "updateIncognitoStatus", | 156 "updateIncognitoStatus", |
156 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, | 157 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, |
157 base::Unretained(this))); | 158 base::Unretained(this))); |
158 web_ui()->RegisterMessageCallback( | 159 web_ui()->RegisterMessageCallback( |
| 160 "fetchZoomScope", base::Bind(&SiteSettingsHandler::HandleFetchZoomScope, |
| 161 base::Unretained(this))); |
| 162 web_ui()->RegisterMessageCallback( |
159 "fetchZoomLevels", | 163 "fetchZoomLevels", |
160 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, | 164 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, |
161 base::Unretained(this))); | 165 base::Unretained(this))); |
162 web_ui()->RegisterMessageCallback( | 166 web_ui()->RegisterMessageCallback( |
| 167 "setZoomScopeIsPerOrigin", |
| 168 base::Bind(&SiteSettingsHandler::HandleSetZoomScopeIsPerOrigin, |
| 169 base::Unretained(this))); |
| 170 web_ui()->RegisterMessageCallback( |
163 "removeZoomLevel", | 171 "removeZoomLevel", |
164 base::Bind(&SiteSettingsHandler::HandleRemoveZoomLevel, | 172 base::Bind(&SiteSettingsHandler::HandleRemoveZoomLevel, |
165 base::Unretained(this))); | 173 base::Unretained(this))); |
166 } | 174 } |
167 | 175 |
168 void SiteSettingsHandler::OnJavascriptAllowed() { | 176 void SiteSettingsHandler::OnJavascriptAllowed() { |
169 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile_)); | 177 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile_)); |
170 if (profile_->HasOffTheRecordProfile()) { | 178 if (profile_->HasOffTheRecordProfile()) { |
171 auto* map = HostContentSettingsMapFactory::GetForProfile( | 179 auto* map = HostContentSettingsMapFactory::GetForProfile( |
172 profile_->GetOffTheRecordProfile()); | 180 profile_->GetOffTheRecordProfile()); |
(...skipping 10 matching lines...) Expand all Loading... |
183 | 191 |
184 // Here we only subscribe to the HostZoomMap for the default storage partition | 192 // Here we only subscribe to the HostZoomMap for the default storage partition |
185 // since we don't allow the user to manage the zoom levels for apps. | 193 // since we don't allow the user to manage the zoom levels for apps. |
186 // We're only interested in zoom-levels that are persisted, since the user | 194 // We're only interested in zoom-levels that are persisted, since the user |
187 // is given the opportunity to view/delete these in the content-settings page. | 195 // is given the opportunity to view/delete these in the content-settings page. |
188 host_zoom_map_subscription_ = | 196 host_zoom_map_subscription_ = |
189 content::HostZoomMap::GetDefaultForBrowserContext(profile_) | 197 content::HostZoomMap::GetDefaultForBrowserContext(profile_) |
190 ->AddZoomLevelChangedCallback( | 198 ->AddZoomLevelChangedCallback( |
191 base::Bind(&SiteSettingsHandler::OnZoomLevelChanged, | 199 base::Bind(&SiteSettingsHandler::OnZoomLevelChanged, |
192 base::Unretained(this))); | 200 base::Unretained(this))); |
| 201 // We subscribe to the ChromeZoomLevelPrefs to get updates to the default |
| 202 // zoom scope. As with the HostZoomMap, we only allow the user to modify |
| 203 // the default zoom scope for the default storage partition. |
| 204 ChromeZoomLevelPrefs* zoom_level_prefs = profile_->GetZoomLevelPrefs(); |
| 205 // Only regular profiles can change the default zoom scope, so only require |
| 206 // a |zoom_level_prefs| in this case. |
| 207 DCHECK(zoom_level_prefs || |
| 208 profile_->GetProfileType() != Profile::REGULAR_PROFILE); |
| 209 if (zoom_level_prefs) |
| 210 default_zoom_scope_subscription_ = |
| 211 zoom_level_prefs->RegisterDefaultZoomScopeCallback(base::Bind( |
| 212 &SiteSettingsHandler::OnZoomScopeChanged, base::Unretained(this))); |
193 } | 213 } |
194 | 214 |
195 void SiteSettingsHandler::OnJavascriptDisallowed() { | 215 void SiteSettingsHandler::OnJavascriptDisallowed() { |
196 observer_.RemoveAll(); | 216 observer_.RemoveAll(); |
197 notification_registrar_.RemoveAll(); | 217 notification_registrar_.RemoveAll(); |
198 host_zoom_map_subscription_.reset(); | 218 host_zoom_map_subscription_.reset(); |
| 219 default_zoom_scope_subscription_.reset(); |
199 } | 220 } |
200 | 221 |
201 void SiteSettingsHandler::OnGetUsageInfo( | 222 void SiteSettingsHandler::OnGetUsageInfo( |
202 const storage::UsageInfoEntries& entries) { | 223 const storage::UsageInfoEntries& entries) { |
203 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 224 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
204 | 225 |
205 for (const auto& entry : entries) { | 226 for (const auto& entry : entries) { |
206 if (entry.usage <= 0) continue; | 227 if (entry.usage <= 0) continue; |
207 if (entry.host == usage_host_) { | 228 if (entry.host == usage_host_) { |
208 CallJavascriptFunction("settings.WebsiteUsagePrivateApi.returnUsageTotal", | 229 CallJavascriptFunction("settings.WebsiteUsagePrivateApi.returnUsageTotal", |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 if (!profile_->IsSameProfile(profile)) | 295 if (!profile_->IsSameProfile(profile)) |
275 break; | 296 break; |
276 SendIncognitoStatus(profile, /*was_destroyed=*/ false); | 297 SendIncognitoStatus(profile, /*was_destroyed=*/ false); |
277 | 298 |
278 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile)); | 299 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile)); |
279 break; | 300 break; |
280 } | 301 } |
281 } | 302 } |
282 } | 303 } |
283 | 304 |
| 305 void SiteSettingsHandler::OnZoomScopeChanged() { |
| 306 SendZoomScope(); |
| 307 } |
| 308 |
284 void SiteSettingsHandler::OnZoomLevelChanged( | 309 void SiteSettingsHandler::OnZoomLevelChanged( |
285 const content::HostZoomMap::ZoomLevelChange& change) { | 310 const content::HostZoomMap::ZoomLevelChange& change) { |
286 SendZoomLevels(); | 311 SendZoomLevels(); |
287 } | 312 } |
288 | 313 |
289 void SiteSettingsHandler::HandleFetchUsageTotal( | 314 void SiteSettingsHandler::HandleFetchUsageTotal( |
290 const base::ListValue* args) { | 315 const base::ListValue* args) { |
291 AllowJavascript(); | 316 AllowJavascript(); |
292 | 317 |
293 CHECK_EQ(1U, args->GetSize()); | 318 CHECK_EQ(1U, args->GetSize()); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 // message before destroying, so HasOffTheRecordProfile for profile_ won't | 640 // message before destroying, so HasOffTheRecordProfile for profile_ won't |
616 // return false until after the profile actually been destroyed. | 641 // return false until after the profile actually been destroyed. |
617 bool incognito_enabled = profile_->HasOffTheRecordProfile() && | 642 bool incognito_enabled = profile_->HasOffTheRecordProfile() && |
618 !(was_destroyed && profile == profile_->GetOffTheRecordProfile()); | 643 !(was_destroyed && profile == profile_->GetOffTheRecordProfile()); |
619 | 644 |
620 CallJavascriptFunction("cr.webUIListenerCallback", | 645 CallJavascriptFunction("cr.webUIListenerCallback", |
621 base::StringValue("onIncognitoStatusChanged"), | 646 base::StringValue("onIncognitoStatusChanged"), |
622 base::FundamentalValue(incognito_enabled)); | 647 base::FundamentalValue(incognito_enabled)); |
623 } | 648 } |
624 | 649 |
| 650 void SiteSettingsHandler::HandleFetchZoomScope(const base::ListValue* args) { |
| 651 AllowJavascript(); |
| 652 SendZoomScope(); |
| 653 } |
| 654 |
625 void SiteSettingsHandler::HandleFetchZoomLevels(const base::ListValue* args) { | 655 void SiteSettingsHandler::HandleFetchZoomLevels(const base::ListValue* args) { |
626 AllowJavascript(); | 656 AllowJavascript(); |
627 SendZoomLevels(); | 657 SendZoomLevels(); |
628 } | 658 } |
629 | 659 |
| 660 void SiteSettingsHandler::SendZoomScope() { |
| 661 if (!IsJavascriptAllowed()) |
| 662 return; |
| 663 |
| 664 ChromeZoomLevelPrefs* zoom_level_prefs = profile_->GetZoomLevelPrefs(); |
| 665 bool is_per_origin = zoom_level_prefs |
| 666 ? zoom_level_prefs->GetZoomScopeIsPerOriginPref() |
| 667 : ChromeZoomLevelPrefs::kZoomScopeSettingDefault; |
| 668 CallJavascriptFunction("cr.webUIListenerCallback", |
| 669 base::StringValue("onZoomScopeChanged"), |
| 670 base::FundamentalValue(is_per_origin)); |
| 671 } |
| 672 |
630 void SiteSettingsHandler::SendZoomLevels() { | 673 void SiteSettingsHandler::SendZoomLevels() { |
631 if (!IsJavascriptAllowed()) | 674 if (!IsJavascriptAllowed()) |
632 return; | 675 return; |
633 | 676 |
634 base::ListValue zoom_levels_exceptions; | 677 base::ListValue zoom_levels_exceptions; |
635 | 678 |
636 content::HostZoomMap* host_zoom_map = | 679 content::HostZoomMap* host_zoom_map = |
637 content::HostZoomMap::GetDefaultForBrowserContext(profile_); | 680 content::HostZoomMap::GetDefaultForBrowserContext(profile_); |
638 content::HostZoomMap::ZoomLevelVector zoom_levels( | 681 content::HostZoomMap::ZoomLevelVector zoom_levels( |
639 host_zoom_map->GetAllZoomLevels()); | 682 host_zoom_map->GetAllZoomLevels()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 site_settings::kSource, site_settings::kPreferencesSource); | 744 site_settings::kSource, site_settings::kPreferencesSource); |
702 // Append the new entry to the list and map. | 745 // Append the new entry to the list and map. |
703 zoom_levels_exceptions.Append(std::move(exception)); | 746 zoom_levels_exceptions.Append(std::move(exception)); |
704 } | 747 } |
705 | 748 |
706 CallJavascriptFunction("cr.webUIListenerCallback", | 749 CallJavascriptFunction("cr.webUIListenerCallback", |
707 base::StringValue("onZoomLevelsChanged"), | 750 base::StringValue("onZoomLevelsChanged"), |
708 zoom_levels_exceptions); | 751 zoom_levels_exceptions); |
709 } | 752 } |
710 | 753 |
| 754 void SiteSettingsHandler::HandleSetZoomScopeIsPerOrigin( |
| 755 const base::ListValue* args) { |
| 756 CHECK_EQ(1U, args->GetSize()); |
| 757 |
| 758 bool is_per_origin; |
| 759 CHECK(args->GetBoolean(0, &is_per_origin)); |
| 760 |
| 761 ChromeZoomLevelPrefs* zoom_level_prefs = profile_->GetZoomLevelPrefs(); |
| 762 DCHECK(zoom_level_prefs); |
| 763 zoom_level_prefs->SetZoomScopeIsPerOriginPref(is_per_origin); |
| 764 } |
| 765 |
711 void SiteSettingsHandler::HandleRemoveZoomLevel(const base::ListValue* args) { | 766 void SiteSettingsHandler::HandleRemoveZoomLevel(const base::ListValue* args) { |
712 CHECK_EQ(1U, args->GetSize()); | 767 CHECK_EQ(1U, args->GetSize()); |
713 | 768 |
714 std::string origin; | 769 std::string origin; |
715 CHECK(args->GetString(0, &origin)); | 770 CHECK(args->GetString(0, &origin)); |
716 | 771 |
717 if (origin == | 772 if (origin == |
718 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL)) { | 773 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL)) { |
719 origin = content::kUnreachableWebDataURL; | 774 origin = content::kUnreachableWebDataURL; |
720 } | 775 } |
721 | 776 |
722 content::HostZoomMap* host_zoom_map; | 777 content::HostZoomMap* host_zoom_map; |
723 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); | 778 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); |
724 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 779 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
725 host_zoom_map->SetZoomLevelForHost(origin, default_level); | 780 host_zoom_map->SetZoomLevelForHost(origin, default_level); |
726 } | 781 } |
727 | 782 |
728 } // namespace settings | 783 } // namespace settings |
OLD | NEW |