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

Side by Side Diff: chrome/browser/ui/webui/settings/site_settings_handler.cc

Issue 1698093007: Convert SiteSettingsCategory to use the HostContentSettingsMap instead of (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 9 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "components/content_settings/core/browser/host_content_settings_map.h"
11 #include "components/content_settings/core/common/content_settings_types.h" 13 #include "components/content_settings/core/common/content_settings_types.h"
12 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_ui.h" 15 #include "content/public/browser/web_ui.h"
14 #include "ui/base/text/bytes_formatting.h" 16 #include "ui/base/text/bytes_formatting.h"
15 17
16 namespace settings { 18 namespace settings {
17 19
18 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) 20 SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
19 : profile_(profile) { 21 : profile_(profile) {
20 } 22 }
21 23
22 SiteSettingsHandler::~SiteSettingsHandler() { 24 SiteSettingsHandler::~SiteSettingsHandler() {
23 } 25 }
24 26
25 void SiteSettingsHandler::RegisterMessages() { 27 void SiteSettingsHandler::RegisterMessages() {
26 web_ui()->RegisterMessageCallback( 28 web_ui()->RegisterMessageCallback(
27 "fetchUsageTotal", 29 "fetchUsageTotal",
28 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal, 30 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal,
29 base::Unretained(this))); 31 base::Unretained(this)));
30 web_ui()->RegisterMessageCallback( 32 web_ui()->RegisterMessageCallback(
31 "clearUsage", 33 "clearUsage",
32 base::Bind(&SiteSettingsHandler::HandleClearUsage, 34 base::Bind(&SiteSettingsHandler::HandleClearUsage,
33 base::Unretained(this))); 35 base::Unretained(this)));
36 web_ui()->RegisterMessageCallback(
37 "setDefaultValueForContentType",
38 base::Bind(&SiteSettingsHandler::HandleSetDefaultValueForContentType,
39 base::Unretained(this)));
40 web_ui()->RegisterMessageCallback(
41 "getDefaultValueForContentType",
42 base::Bind(&SiteSettingsHandler::HandleGetDefaultValueForContentType,
43 base::Unretained(this)));
34 } 44 }
35 45
36 void SiteSettingsHandler::OnGetUsageInfo( 46 void SiteSettingsHandler::OnGetUsageInfo(
37 const storage::UsageInfoEntries& entries) { 47 const storage::UsageInfoEntries& entries) {
38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
39 49
40 for (const auto& entry : entries) { 50 for (const auto& entry : entries) {
41 if (entry.usage <= 0) continue; 51 if (entry.usage <= 0) continue;
42 if (entry.host == usage_host_) { 52 if (entry.host == usage_host_) {
43 web_ui()->CallJavascriptFunction( 53 web_ui()->CallJavascriptFunction(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared, 102 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared,
93 base::Unretained(this))); 103 base::Unretained(this)));
94 104
95 // Also clear the *local* storage data. 105 // Also clear the *local* storage data.
96 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = 106 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper =
97 new BrowsingDataLocalStorageHelper(profile_); 107 new BrowsingDataLocalStorageHelper(profile_);
98 local_storage_helper->DeleteOrigin(url); 108 local_storage_helper->DeleteOrigin(url);
99 } 109 }
100 } 110 }
101 111
112 void SiteSettingsHandler::HandleSetDefaultValueForContentType(
tommycli 2016/02/17 18:18:06 What was the motivation for changing this from usi
Finnur 2016/02/18 20:38:18 That's in the email I referred to but in short: pr
tommycli 2016/02/18 22:15:18 finnur: I brain farted and neglected to read the e
Finnur 2016/02/19 10:18:13 No harm, no foul. :)
113 const base::ListValue* args) {
114 CHECK_EQ(2U, args->GetSize());
115 int content_type;
116 CHECK(args->GetInteger(0, &content_type));
117 int default_setting;
118 CHECK(args->GetInteger(1, &default_setting));
119
120 HostContentSettingsMap* map =
121 HostContentSettingsMapFactory::GetForProfile(profile_);
122 map->SetDefaultContentSetting(static_cast<ContentSettingsType>(content_type),
123 static_cast<ContentSetting>(default_setting));
124 }
125
126 void SiteSettingsHandler::HandleGetDefaultValueForContentType(
127 const base::ListValue* args) {
128 CHECK_EQ(2U, args->GetSize());
129 const base::Value* callback_id;
130 CHECK(args->Get(0, &callback_id));
131 int type;
132 CHECK(args->GetInteger(1, &type));
133
134 ContentSettingsType content_type = static_cast<ContentSettingsType>(type);
135 HostContentSettingsMap* map =
136 HostContentSettingsMapFactory::GetForProfile(profile_);
137 ContentSetting setting = map->GetDefaultContentSetting(content_type, nullptr);
138
139 // FullScreen is Allow vs. Ask.
140 bool enabled;
141 if (content_type == CONTENT_SETTINGS_TYPE_FULLSCREEN)
142 enabled = setting != CONTENT_SETTING_ASK;
143 else
144 enabled = setting != CONTENT_SETTING_BLOCK;
145
146 CallJavascriptCallback(*callback_id, base::FundamentalValue(enabled));
147 }
148
102 } // namespace settings 149 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698