Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/permissions/chooser_permission_context_base.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
| 11 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 12 | |
| 13 namespace { | |
| 14 const char* const kObjectListKey = "chosen-objects"; | |
| 15 } | |
| 16 | |
| 17 ChooserPermissionContextBase::ChooserPermissionContextBase( | |
| 18 Profile* profile, | |
| 19 const ContentSettingsType permission_type) | |
| 20 : PermissionContextBase(profile, permission_type) {} | |
| 21 | |
| 22 ChooserPermissionContextBase::~ChooserPermissionContextBase() {} | |
| 23 | |
| 24 scoped_ptr<base::ListValue> ChooserPermissionContextBase::GetChosenObjects( | |
| 25 const GURL& origin) { | |
|
raymes
2015/10/06 05:28:20
I think this is probably where we want to check th
Reilly Grant (use Gerrit)
2015/10/06 20:45:30
If this class is created for CONTENT_SETTING_TYPE_
| |
| 26 scoped_ptr<base::DictionaryValue> setting = GetWebsiteSetting(origin); | |
| 27 scoped_ptr<base::Value> object_list; | |
| 28 if (!setting->Remove(kObjectListKey, &object_list)) | |
| 29 return make_scoped_ptr(new base::ListValue()); | |
| 30 | |
| 31 if (object_list->GetType() != base::Value::TYPE_LIST) | |
| 32 return make_scoped_ptr(new base::ListValue()); | |
| 33 return base::ListValue::From(object_list.Pass()); | |
| 34 } | |
| 35 | |
| 36 void ChooserPermissionContextBase::GrantObjectPermission( | |
| 37 const GURL& origin, | |
| 38 scoped_ptr<base::Value> object) { | |
| 39 scoped_ptr<base::DictionaryValue> setting = GetWebsiteSetting(origin); | |
| 40 base::ListValue* object_list; | |
| 41 if (!setting->GetList(kObjectListKey, &object_list)) { | |
| 42 object_list = new base::ListValue(); | |
| 43 setting->Set(kObjectListKey, object_list); | |
| 44 } | |
| 45 object_list->Append(object.Pass()); | |
| 46 SetWebsiteSetting(origin, setting.Pass()); | |
| 47 } | |
| 48 | |
| 49 void ChooserPermissionContextBase::RevokeObjectPermission( | |
| 50 const GURL& origin, | |
| 51 const base::Value& object) { | |
| 52 scoped_ptr<base::DictionaryValue> setting = GetWebsiteSetting(origin); | |
| 53 base::ListValue* object_list; | |
| 54 if (!setting->GetList(kObjectListKey, &object_list)) | |
| 55 return; | |
| 56 object_list->Remove(object, nullptr); | |
| 57 SetWebsiteSetting(origin, setting.Pass()); | |
| 58 } | |
| 59 | |
| 60 scoped_ptr<base::DictionaryValue> | |
| 61 ChooserPermissionContextBase::GetWebsiteSetting(const GURL& origin) { | |
| 62 HostContentSettingsMap* settings = | |
| 63 HostContentSettingsMapFactory::GetForProfile(profile()); | |
| 64 DCHECK(settings); | |
| 65 | |
| 66 scoped_ptr<base::DictionaryValue> value = | |
| 67 base::DictionaryValue::From(settings->GetWebsiteSetting( | |
| 68 origin, origin, type(), std::string(), nullptr)); | |
| 69 if (!value) | |
| 70 return make_scoped_ptr(new base::DictionaryValue()); | |
| 71 | |
| 72 return value.Pass(); | |
| 73 } | |
| 74 | |
| 75 void ChooserPermissionContextBase::SetWebsiteSetting( | |
| 76 const GURL& origin, | |
| 77 scoped_ptr<base::Value> value) { | |
| 78 HostContentSettingsMap* settings = | |
| 79 HostContentSettingsMapFactory::GetForProfile(profile()); | |
| 80 DCHECK(settings); | |
| 81 | |
| 82 ContentSettingsPattern pattern( | |
| 83 ContentSettingsPattern::FromURLNoWildcard(origin)); | |
| 84 if (!pattern.IsValid()) | |
| 85 return; | |
| 86 | |
| 87 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | |
| 88 type(), std::string(), value.release()); | |
| 89 } | |
| OLD | NEW |