Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: chrome/browser/ui/webui/options/website_settings_handler.cc

Issue 829333004: Add DictionaryValue::Set and ::SetWithoutPathExpansion fns (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/values_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/webui/options/website_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/website_settings_handler.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_iterator.h" 10 #include "chrome/browser/ui/browser_iterator.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 if (it->setting != cam_setting) 375 if (it->setting != cam_setting)
376 continue; 376 continue;
377 } 377 }
378 378
379 if (origin.find(last_filter_) == base::string16::npos) 379 if (origin.find(last_filter_) == base::string16::npos)
380 continue; 380 continue;
381 381
382 base::Time last_usage = settings->GetLastUsageByPattern( 382 base::Time last_usage = settings->GetLastUsageByPattern(
383 it->primary_pattern, it->secondary_pattern, last_setting); 383 it->primary_pattern, it->secondary_pattern, last_setting);
384 384
385 base::DictionaryValue* origin_entry = new base::DictionaryValue(); 385 scoped_ptr<base::DictionaryValue> origin_entry(new base::DictionaryValue());
386 origin_entry->SetDoubleWithoutPathExpansion("usage", 386 origin_entry->SetDoubleWithoutPathExpansion("usage",
387 last_usage.ToDoubleT()); 387 last_usage.ToDoubleT());
388 base::string16 usage_string; 388 base::string16 usage_string;
389 if (last_usage.ToDoubleT()) { 389 if (last_usage.ToDoubleT()) {
390 usage_string = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, 390 usage_string = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED,
391 ui::TimeFormat::LENGTH_SHORT, 391 ui::TimeFormat::LENGTH_SHORT,
392 base::Time::Now() - last_usage); 392 base::Time::Now() - last_usage);
393 } 393 }
394 origin_entry->SetStringWithoutPathExpansion("usageString", usage_string); 394 origin_entry->SetStringWithoutPathExpansion("usageString", usage_string);
395 origin_entry->SetStringWithoutPathExpansion("readableName", 395 origin_entry->SetStringWithoutPathExpansion("readableName",
396 GetReadableName(origin_url)); 396 GetReadableName(origin_url));
397 397
398 if (it->setting == CONTENT_SETTING_BLOCK) 398 if (it->setting == CONTENT_SETTING_BLOCK)
399 blocked_origins.SetWithoutPathExpansion(origin, origin_entry); 399 blocked_origins.SetWithoutPathExpansion(origin, origin_entry.Pass());
400 else 400 else
401 allowed_origins.SetWithoutPathExpansion(origin, origin_entry); 401 allowed_origins.SetWithoutPathExpansion(origin, origin_entry.Pass());
402 } 402 }
403 403
404 bool is_globally_allowed = settings->GetContentSettingOverride(last_setting); 404 bool is_globally_allowed = settings->GetContentSettingOverride(last_setting);
405 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", 405 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins",
406 allowed_origins, 406 allowed_origins,
407 blocked_origins, 407 blocked_origins,
408 base::FundamentalValue(is_globally_allowed)); 408 base::FundamentalValue(is_globally_allowed));
409 } 409 }
410 410
411 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { 411 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 624
625 int battery = 0; 625 int battery = 0;
626 battery = OriginPowerMapFactory::GetForBrowserContext( 626 battery = OriginPowerMapFactory::GetForBrowserContext(
627 GetProfile())->GetPowerForOrigin(site_url); 627 GetProfile())->GetPowerForOrigin(site_url);
628 628
629 base::DictionaryValue* permissions = new base::DictionaryValue; 629 base::DictionaryValue* permissions = new base::DictionaryValue;
630 for (size_t i = 0; i < arraysize(kValidTypes); ++i) { 630 for (size_t i = 0; i < arraysize(kValidTypes); ++i) {
631 ContentSettingsType permission_type = kValidTypes[i]; 631 ContentSettingsType permission_type = kValidTypes[i];
632 632
633 // Append the possible settings. 633 // Append the possible settings.
634 base::ListValue* options = new base::ListValue; 634 scoped_ptr<base::ListValue> options(new base::ListValue());
635 ContentSetting default_value = 635 ContentSetting default_value =
636 map->GetDefaultContentSetting(permission_type, NULL); 636 map->GetDefaultContentSetting(permission_type, NULL);
637 if (default_value != CONTENT_SETTING_ALLOW && 637 if (default_value != CONTENT_SETTING_ALLOW &&
638 default_value != CONTENT_SETTING_BLOCK) { 638 default_value != CONTENT_SETTING_BLOCK) {
639 options->AppendString( 639 options->AppendString(
640 content_settings::ContentSettingToString(default_value)); 640 content_settings::ContentSettingToString(default_value));
641 } 641 }
642 options->AppendString( 642 options->AppendString(
643 content_settings::ContentSettingToString(CONTENT_SETTING_ALLOW)); 643 content_settings::ContentSettingToString(CONTENT_SETTING_ALLOW));
644 options->AppendString( 644 options->AppendString(
(...skipping 23 matching lines...) Expand all
668 if (mic_setting != cam_setting) 668 if (mic_setting != cam_setting)
669 permission = CONTENT_SETTING_ASK; 669 permission = CONTENT_SETTING_ASK;
670 else 670 else
671 permission = mic_setting; 671 permission = mic_setting;
672 } else { 672 } else {
673 scoped_ptr<base::Value> v(map->GetWebsiteSettingWithoutOverride( 673 scoped_ptr<base::Value> v(map->GetWebsiteSettingWithoutOverride(
674 site_url, site_url, permission_type, std::string(), &info)); 674 site_url, site_url, permission_type, std::string(), &info));
675 permission = content_settings::ValueToContentSetting(v.get()); 675 permission = content_settings::ValueToContentSetting(v.get());
676 } 676 }
677 677
678 base::DictionaryValue* permission_info = new base::DictionaryValue; 678 scoped_ptr<base::DictionaryValue>
679 permission_info(new base::DictionaryValue());
679 permission_info->SetStringWithoutPathExpansion( 680 permission_info->SetStringWithoutPathExpansion(
680 "setting", content_settings::ContentSettingToString(permission)); 681 "setting", content_settings::ContentSettingToString(permission));
681 permission_info->SetWithoutPathExpansion("options", options); 682 permission_info->SetWithoutPathExpansion("options", options.Pass());
682 permission_info->SetBooleanWithoutPathExpansion( 683 permission_info->SetBooleanWithoutPathExpansion(
683 "editable", info.source == content_settings::SETTING_SOURCE_USER); 684 "editable", info.source == content_settings::SETTING_SOURCE_USER);
684 permissions->SetWithoutPathExpansion( 685 permissions->SetWithoutPathExpansion(
685 content_settings::GetTypeName(permission_type), permission_info); 686 content_settings::GetTypeName(permission_type), permission_info.Pass());
686 } 687 }
687 688
688 base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16( 689 base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16(
689 IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage))); 690 IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage)));
690 base::Value* battery_used = 691 base::Value* battery_used =
691 new base::StringValue(l10n_util::GetStringFUTF16Int( 692 new base::StringValue(l10n_util::GetStringFUTF16Int(
692 IDS_WEBSITE_SETTINGS_BATTERY_USED, battery)); 693 IDS_WEBSITE_SETTINGS_BATTERY_USED, battery));
693 694
694 web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.populateOrigin", 695 web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.populateOrigin",
695 *storage_used, 696 *storage_used,
696 *battery_used, 697 *battery_used,
697 *permissions, 698 *permissions,
698 base::FundamentalValue(show_page)); 699 base::FundamentalValue(show_page));
699 } 700 }
700 701
701 void WebsiteSettingsHandler::UpdateLocalStorage() { 702 void WebsiteSettingsHandler::UpdateLocalStorage() {
702 base::DictionaryValue local_storage_map; 703 base::DictionaryValue local_storage_map;
703 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); 704 for (LocalStorageList::const_iterator it = local_storage_list_.begin();
704 it != local_storage_list_.end(); 705 it != local_storage_list_.end();
705 it++) { 706 it++) {
706 std::string origin = it->origin_url.spec(); 707 std::string origin = it->origin_url.spec();
707 708
708 if (origin.find(last_filter_) == base::string16::npos) 709 if (origin.find(last_filter_) == base::string16::npos)
709 continue; 710 continue;
710 711
711 base::DictionaryValue* origin_entry = new base::DictionaryValue(); 712 scoped_ptr<base::DictionaryValue> origin_entry(new base::DictionaryValue());
712 origin_entry->SetWithoutPathExpansion( 713 origin_entry->SetDoubleWithoutPathExpansion(
713 "usage", new base::FundamentalValue(static_cast<double>(it->size))); 714 "usage", static_cast<double>(it->size));
714 origin_entry->SetWithoutPathExpansion( 715 origin_entry->SetStringWithoutPathExpansion(
715 "usageString", new base::StringValue(ui::FormatBytes(it->size))); 716 "usageString", ui::FormatBytes(it->size));
716 origin_entry->SetStringWithoutPathExpansion( 717 origin_entry->SetStringWithoutPathExpansion(
717 "readableName", GetReadableName(it->origin_url)); 718 "readableName", GetReadableName(it->origin_url));
718 local_storage_map.SetWithoutPathExpansion(origin, origin_entry); 719 local_storage_map.SetWithoutPathExpansion(origin, origin_entry.Pass());
719 } 720 }
720 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", 721 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins",
721 local_storage_map); 722 local_storage_map);
722 } 723 }
723 724
724 void WebsiteSettingsHandler::UpdateBatteryUsage() { 725 void WebsiteSettingsHandler::UpdateBatteryUsage() {
725 base::DictionaryValue power_map; 726 base::DictionaryValue power_map;
726 OriginPowerMap* origins = 727 OriginPowerMap* origins =
727 OriginPowerMapFactory::GetForBrowserContext(GetProfile()); 728 OriginPowerMapFactory::GetForBrowserContext(GetProfile());
728 OriginPowerMap::PercentOriginMap percent_map = origins->GetPercentOriginMap(); 729 OriginPowerMap::PercentOriginMap percent_map = origins->GetPercentOriginMap();
729 for (std::map<GURL, int>::iterator it = percent_map.begin(); 730 for (std::map<GURL, int>::iterator it = percent_map.begin();
730 it != percent_map.end(); 731 it != percent_map.end();
731 ++it) { 732 ++it) {
732 std::string origin = it->first.spec(); 733 std::string origin = it->first.spec();
733 734
734 if (origin.find(last_filter_) == base::string16::npos) 735 if (origin.find(last_filter_) == base::string16::npos)
735 continue; 736 continue;
736 737
737 base::DictionaryValue* origin_entry = new base::DictionaryValue(); 738 scoped_ptr<base::DictionaryValue> origin_entry(new base::DictionaryValue());
738 origin_entry->SetInteger("usage", it->second); 739 origin_entry->SetInteger("usage", it->second);
739 if (it->second == 0) { 740 if (it->second == 0) {
740 origin_entry->SetString( 741 origin_entry->SetString(
741 "usageString", 742 "usageString",
742 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_BATTERY_ZERO_PERCENT)); 743 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_BATTERY_ZERO_PERCENT));
743 } else { 744 } else {
744 origin_entry->SetString( 745 origin_entry->SetString(
745 "usageString", 746 "usageString",
746 l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT, 747 l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT,
747 it->second)); 748 it->second));
748 } 749 }
749 origin_entry->SetStringWithoutPathExpansion("readableName", 750 origin_entry->SetStringWithoutPathExpansion("readableName",
750 GetReadableName(it->first)); 751 GetReadableName(it->first));
751 power_map.SetWithoutPathExpansion(origin, origin_entry); 752 power_map.SetWithoutPathExpansion(origin, origin_entry.Pass());
752 } 753 }
753 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", 754 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins",
754 power_map); 755 power_map);
755 } 756 }
756 757
757 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { 758 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) {
758 Profile* profile = GetProfile(); 759 Profile* profile = GetProfile();
759 if (site_url.SchemeIs(extensions::kExtensionScheme)) { 760 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
760 const extensions::Extension* extension = 761 const extensions::Extension* extension =
761 extensions::ExtensionRegistry::Get(profile) 762 extensions::ExtensionRegistry::Get(profile)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 #if defined(OS_CHROMEOS) 824 #if defined(OS_CHROMEOS)
824 // Chrome OS special case: in Guest mode settings are opened in Incognito 825 // Chrome OS special case: in Guest mode settings are opened in Incognito
825 // mode, so we need original profile to actually modify settings. 826 // mode, so we need original profile to actually modify settings.
826 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) 827 if (user_manager::UserManager::Get()->IsLoggedInAsGuest())
827 profile = profile->GetOriginalProfile(); 828 profile = profile->GetOriginalProfile();
828 #endif 829 #endif
829 return profile; 830 return profile;
830 } 831 }
831 832
832 } // namespace options 833 } // namespace options
OLDNEW
« no previous file with comments | « base/values_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698