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> |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 199 } |
200 | 200 |
201 void SiteSettingsHandler::OnGetUsageInfo( | 201 void SiteSettingsHandler::OnGetUsageInfo( |
202 const storage::UsageInfoEntries& entries) { | 202 const storage::UsageInfoEntries& entries) { |
203 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 203 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
204 | 204 |
205 for (const auto& entry : entries) { | 205 for (const auto& entry : entries) { |
206 if (entry.usage <= 0) continue; | 206 if (entry.usage <= 0) continue; |
207 if (entry.host == usage_host_) { | 207 if (entry.host == usage_host_) { |
208 CallJavascriptFunction("settings.WebsiteUsagePrivateApi.returnUsageTotal", | 208 CallJavascriptFunction("settings.WebsiteUsagePrivateApi.returnUsageTotal", |
209 base::StringValue(entry.host), | 209 base::Value(entry.host), |
210 base::StringValue(ui::FormatBytes(entry.usage)), | 210 base::Value(ui::FormatBytes(entry.usage)), |
211 base::Value(entry.type)); | 211 base::Value(entry.type)); |
212 return; | 212 return; |
213 } | 213 } |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 void SiteSettingsHandler::OnUsageInfoCleared(storage::QuotaStatusCode code) { | 217 void SiteSettingsHandler::OnUsageInfoCleared(storage::QuotaStatusCode code) { |
218 if (code == storage::kQuotaStatusOk) { | 218 if (code == storage::kQuotaStatusOk) { |
219 CallJavascriptFunction("settings.WebsiteUsagePrivateApi.onUsageCleared", | 219 CallJavascriptFunction("settings.WebsiteUsagePrivateApi.onUsageCleared", |
220 base::StringValue(clearing_origin_)); | 220 base::Value(clearing_origin_)); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 void SiteSettingsHandler::OnContentSettingChanged( | 224 void SiteSettingsHandler::OnContentSettingChanged( |
225 const ContentSettingsPattern& primary_pattern, | 225 const ContentSettingsPattern& primary_pattern, |
226 const ContentSettingsPattern& secondary_pattern, | 226 const ContentSettingsPattern& secondary_pattern, |
227 ContentSettingsType content_type, | 227 ContentSettingsType content_type, |
228 std::string resource_identifier) { | 228 std::string resource_identifier) { |
229 if (!site_settings::HasRegisteredGroupName(content_type)) | 229 if (!site_settings::HasRegisteredGroupName(content_type)) |
230 return; | 230 return; |
231 | 231 |
232 if (primary_pattern.ToString().empty()) { | 232 if (primary_pattern.ToString().empty()) { |
233 CallJavascriptFunction( | 233 CallJavascriptFunction( |
234 "cr.webUIListenerCallback", | 234 "cr.webUIListenerCallback", |
235 base::StringValue("contentSettingCategoryChanged"), | 235 base::Value("contentSettingCategoryChanged"), |
236 base::StringValue(site_settings::ContentSettingsTypeToGroupName( | 236 base::Value( |
237 content_type))); | 237 site_settings::ContentSettingsTypeToGroupName(content_type))); |
238 } else { | 238 } else { |
239 CallJavascriptFunction( | 239 CallJavascriptFunction( |
240 "cr.webUIListenerCallback", | 240 "cr.webUIListenerCallback", |
241 base::StringValue("contentSettingSitePermissionChanged"), | 241 base::Value("contentSettingSitePermissionChanged"), |
242 base::StringValue(site_settings::ContentSettingsTypeToGroupName( | 242 base::Value( |
243 content_type)), | 243 site_settings::ContentSettingsTypeToGroupName(content_type)), |
244 base::StringValue(primary_pattern.ToString()), | 244 base::Value(primary_pattern.ToString()), |
245 base::StringValue( | 245 base::Value(secondary_pattern == ContentSettingsPattern::Wildcard() |
246 secondary_pattern == ContentSettingsPattern::Wildcard() ? | 246 ? "" |
247 "" : secondary_pattern.ToString())); | 247 : secondary_pattern.ToString())); |
248 } | 248 } |
249 } | 249 } |
250 | 250 |
251 void SiteSettingsHandler::Observe( | 251 void SiteSettingsHandler::Observe( |
252 int type, | 252 int type, |
253 const content::NotificationSource& source, | 253 const content::NotificationSource& source, |
254 const content::NotificationDetails& details) { | 254 const content::NotificationDetails& details) { |
255 switch (type) { | 255 switch (type) { |
256 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 256 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
257 Profile* profile = content::Source<Profile>(source).ptr(); | 257 Profile* profile = content::Source<Profile>(source).ptr(); |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 if (!IsJavascriptAllowed()) | 610 if (!IsJavascriptAllowed()) |
611 return; | 611 return; |
612 | 612 |
613 // When an incognito profile is destroyed, it sends out the destruction | 613 // When an incognito profile is destroyed, it sends out the destruction |
614 // message before destroying, so HasOffTheRecordProfile for profile_ won't | 614 // message before destroying, so HasOffTheRecordProfile for profile_ won't |
615 // return false until after the profile actually been destroyed. | 615 // return false until after the profile actually been destroyed. |
616 bool incognito_enabled = profile_->HasOffTheRecordProfile() && | 616 bool incognito_enabled = profile_->HasOffTheRecordProfile() && |
617 !(was_destroyed && profile == profile_->GetOffTheRecordProfile()); | 617 !(was_destroyed && profile == profile_->GetOffTheRecordProfile()); |
618 | 618 |
619 CallJavascriptFunction("cr.webUIListenerCallback", | 619 CallJavascriptFunction("cr.webUIListenerCallback", |
620 base::StringValue("onIncognitoStatusChanged"), | 620 base::Value("onIncognitoStatusChanged"), |
621 base::Value(incognito_enabled)); | 621 base::Value(incognito_enabled)); |
622 } | 622 } |
623 | 623 |
624 void SiteSettingsHandler::HandleFetchZoomLevels(const base::ListValue* args) { | 624 void SiteSettingsHandler::HandleFetchZoomLevels(const base::ListValue* args) { |
625 AllowJavascript(); | 625 AllowJavascript(); |
626 SendZoomLevels(); | 626 SendZoomLevels(); |
627 } | 627 } |
628 | 628 |
629 void SiteSettingsHandler::SendZoomLevels() { | 629 void SiteSettingsHandler::SendZoomLevels() { |
630 if (!IsJavascriptAllowed()) | 630 if (!IsJavascriptAllowed()) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 int zoom_percent = static_cast<int>( | 696 int zoom_percent = static_cast<int>( |
697 content::ZoomLevelToZoomFactor(zoom_level.zoom_level) * 100 + 0.5); | 697 content::ZoomLevelToZoomFactor(zoom_level.zoom_level) * 100 + 0.5); |
698 exception->SetString(kZoom, base::FormatPercent(zoom_percent)); | 698 exception->SetString(kZoom, base::FormatPercent(zoom_percent)); |
699 exception->SetString( | 699 exception->SetString( |
700 site_settings::kSource, site_settings::kPreferencesSource); | 700 site_settings::kSource, site_settings::kPreferencesSource); |
701 // Append the new entry to the list and map. | 701 // Append the new entry to the list and map. |
702 zoom_levels_exceptions.Append(std::move(exception)); | 702 zoom_levels_exceptions.Append(std::move(exception)); |
703 } | 703 } |
704 | 704 |
705 CallJavascriptFunction("cr.webUIListenerCallback", | 705 CallJavascriptFunction("cr.webUIListenerCallback", |
706 base::StringValue("onZoomLevelsChanged"), | 706 base::Value("onZoomLevelsChanged"), |
707 zoom_levels_exceptions); | 707 zoom_levels_exceptions); |
708 } | 708 } |
709 | 709 |
710 void SiteSettingsHandler::HandleRemoveZoomLevel(const base::ListValue* args) { | 710 void SiteSettingsHandler::HandleRemoveZoomLevel(const base::ListValue* args) { |
711 CHECK_EQ(1U, args->GetSize()); | 711 CHECK_EQ(1U, args->GetSize()); |
712 | 712 |
713 std::string origin; | 713 std::string origin; |
714 CHECK(args->GetString(0, &origin)); | 714 CHECK(args->GetString(0, &origin)); |
715 | 715 |
716 if (origin == | 716 if (origin == |
717 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL)) { | 717 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL)) { |
718 origin = content::kUnreachableWebDataURL; | 718 origin = content::kUnreachableWebDataURL; |
719 } | 719 } |
720 | 720 |
721 content::HostZoomMap* host_zoom_map; | 721 content::HostZoomMap* host_zoom_map; |
722 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); | 722 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); |
723 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 723 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
724 host_zoom_map->SetZoomLevelForHost(origin, default_level); | 724 host_zoom_map->SetZoomLevelForHost(origin, default_level); |
725 } | 725 } |
726 | 726 |
727 } // namespace settings | 727 } // namespace settings |
OLD | NEW |