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

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

Issue 2237823003: Site Settings Desktop: Implement USB devices section. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync'ed Created 4 years, 4 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 "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 8 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/permissions/chooser_context_base.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/site_settings_helper.h" 12 #include "chrome/browser/ui/webui/site_settings_helper.h"
12 #include "components/content_settings/core/browser/host_content_settings_map.h" 13 #include "components/content_settings/core/browser/host_content_settings_map.h"
13 #include "components/content_settings/core/common/content_settings_types.h" 14 #include "components/content_settings/core/common/content_settings_types.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_ui.h" 16 #include "content/public/browser/web_ui.h"
16 #include "storage/browser/quota/quota_manager.h" 17 #include "storage/browser/quota/quota_manager.h"
17 #include "storage/common/quota/quota_status_code.h" 18 #include "storage/common/quota/quota_status_code.h"
18 #include "ui/base/text/bytes_formatting.h" 19 #include "ui/base/text/bytes_formatting.h"
19 20
20 namespace settings { 21 namespace settings {
21 22
22 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) 23 SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
23 : profile_(profile), observer_(this) { 24 : profile_(profile), observer_(this) {
24 } 25 }
25 26
26 SiteSettingsHandler::~SiteSettingsHandler() { 27 SiteSettingsHandler::~SiteSettingsHandler() {
27 } 28 }
28 29
29 void SiteSettingsHandler::RegisterMessages() { 30 void SiteSettingsHandler::RegisterMessages() {
30 web_ui()->RegisterMessageCallback( 31 web_ui()->RegisterMessageCallback(
31 "fetchUsageTotal", 32 "fetchUsageTotal",
32 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal, 33 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal,
33 base::Unretained(this))); 34 base::Unretained(this)));
34 web_ui()->RegisterMessageCallback( 35 web_ui()->RegisterMessageCallback(
35 "clearUsage", 36 "clearUsage",
36 base::Bind(&SiteSettingsHandler::HandleClearUsage, 37 base::Bind(&SiteSettingsHandler::HandleClearUsage,
37 base::Unretained(this))); 38 base::Unretained(this)));
38 web_ui()->RegisterMessageCallback( 39 web_ui()->RegisterMessageCallback(
40 "fetchUsbDevices",
41 base::Bind(&SiteSettingsHandler::HandleFetchUsbDevices,
42 base::Unretained(this)));
43 web_ui()->RegisterMessageCallback(
44 "removeUsbDevice",
45 base::Bind(&SiteSettingsHandler::HandleRemoveUsbDevice,
46 base::Unretained(this)));
47 web_ui()->RegisterMessageCallback(
39 "setDefaultValueForContentType", 48 "setDefaultValueForContentType",
40 base::Bind(&SiteSettingsHandler::HandleSetDefaultValueForContentType, 49 base::Bind(&SiteSettingsHandler::HandleSetDefaultValueForContentType,
41 base::Unretained(this))); 50 base::Unretained(this)));
42 web_ui()->RegisterMessageCallback( 51 web_ui()->RegisterMessageCallback(
43 "getDefaultValueForContentType", 52 "getDefaultValueForContentType",
44 base::Bind(&SiteSettingsHandler::HandleGetDefaultValueForContentType, 53 base::Bind(&SiteSettingsHandler::HandleGetDefaultValueForContentType,
45 base::Unretained(this))); 54 base::Unretained(this)));
46 web_ui()->RegisterMessageCallback( 55 web_ui()->RegisterMessageCallback(
47 "getExceptionList", 56 "getExceptionList",
48 base::Bind(&SiteSettingsHandler::HandleGetExceptionList, 57 base::Bind(&SiteSettingsHandler::HandleGetExceptionList,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared, 168 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared,
160 base::Unretained(this))); 169 base::Unretained(this)));
161 170
162 // Also clear the *local* storage data. 171 // Also clear the *local* storage data.
163 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = 172 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper =
164 new BrowsingDataLocalStorageHelper(profile_); 173 new BrowsingDataLocalStorageHelper(profile_);
165 local_storage_helper->DeleteOrigin(url); 174 local_storage_helper->DeleteOrigin(url);
166 } 175 }
167 } 176 }
168 177
178 void SiteSettingsHandler::HandleFetchUsbDevices(const base::ListValue* args) {
179 AllowJavascript();
180
181 CHECK_EQ(1U, args->GetSize());
182 const base::Value* callback_id;
183 CHECK(args->Get(0, &callback_id));
184
185 base::ListValue exceptions;
186 const site_settings::ChooserTypeNameEntry* chooser_type =
187 site_settings::ChooserTypeFromGroupName(site_settings::kGroupTypeUsb);
188 // TODO(finnur): Figure out whether incognito permissions are also needed.
189 site_settings::GetChooserExceptionsFromProfile(
190 profile_, false, *chooser_type, &exceptions);
191 ResolveJavascriptCallback(*callback_id, exceptions);
192 }
193
194 void SiteSettingsHandler::HandleRemoveUsbDevice(const base::ListValue* args) {
195 CHECK_EQ(3U, args->GetSize());
196
197 std::string origin_string;
198 CHECK(args->GetString(0, &origin_string));
199 GURL requesting_origin(origin_string);
200 CHECK(requesting_origin.is_valid());
201
202 std::string embedding_origin_string;
203 CHECK(args->GetString(1, &embedding_origin_string));
204 GURL embedding_origin(embedding_origin_string);
205 CHECK(embedding_origin.is_valid());
206
207 const base::DictionaryValue* object = nullptr;
208 CHECK(args->GetDictionary(2, &object));
209
210 const site_settings::ChooserTypeNameEntry* chooser_type =
211 site_settings::ChooserTypeFromGroupName(site_settings::kGroupTypeUsb);
212 ChooserContextBase* chooser_context = chooser_type->get_context(profile_);
213 chooser_context->RevokeObjectPermission(requesting_origin, embedding_origin,
214 *object);
215 }
216
169 void SiteSettingsHandler::HandleSetDefaultValueForContentType( 217 void SiteSettingsHandler::HandleSetDefaultValueForContentType(
170 const base::ListValue* args) { 218 const base::ListValue* args) {
171 CHECK_EQ(2U, args->GetSize()); 219 CHECK_EQ(2U, args->GetSize());
172 std::string content_type; 220 std::string content_type;
173 CHECK(args->GetString(0, &content_type)); 221 CHECK(args->GetString(0, &content_type));
174 std::string setting; 222 std::string setting;
175 CHECK(args->GetString(1, &setting)); 223 CHECK(args->GetString(1, &setting));
176 ContentSetting default_setting; 224 ContentSetting default_setting;
177 CHECK(content_settings::ContentSettingFromString(setting, &default_setting)); 225 CHECK(content_settings::ContentSettingFromString(setting, &default_setting));
178 226
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 std::string pattern_string; 339 std::string pattern_string;
292 CHECK(args->GetString(1, &pattern_string)); 340 CHECK(args->GetString(1, &pattern_string));
293 341
294 ContentSettingsPattern pattern = 342 ContentSettingsPattern pattern =
295 ContentSettingsPattern::FromString(pattern_string); 343 ContentSettingsPattern::FromString(pattern_string);
296 ResolveJavascriptCallback( 344 ResolveJavascriptCallback(
297 *callback_id, base::FundamentalValue(pattern.IsValid())); 345 *callback_id, base::FundamentalValue(pattern.IsValid()));
298 } 346 }
299 347
300 } // namespace settings 348 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698