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

Side by Side Diff: chrome/browser/permissions/chooser_context_base.cc

Issue 1427433017: Add a "guard" content settings type for chooser permissions. Base URL: https://chromium.googlesource.com/chromium/src.git@permission_store
Patch Set: Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 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 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/permissions/chooser_context_base.h" 5 #include "chrome/browser/permissions/chooser_context_base.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.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" 11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 12
13 using ObjectList = ScopedVector<base::DictionaryValue>; 13 using ObjectList = ScopedVector<base::DictionaryValue>;
14 14
15 const char kObjectListKey[] = "chosen-objects"; 15 const char kObjectListKey[] = "chosen-objects";
16 16
17 ChooserContextBase::ChooserContextBase( 17 ChooserContextBase::ChooserContextBase(
18 Profile* profile, 18 Profile* profile,
19 const ContentSettingsType guard_content_settings_type,
19 const ContentSettingsType data_content_settings_type) 20 const ContentSettingsType data_content_settings_type)
20 : host_content_settings_map_( 21 : host_content_settings_map_(
21 HostContentSettingsMapFactory::GetForProfile(profile)), 22 HostContentSettingsMapFactory::GetForProfile(profile)),
23 guard_content_settings_type_(guard_content_settings_type),
22 data_content_settings_type_(data_content_settings_type) { 24 data_content_settings_type_(data_content_settings_type) {
23 DCHECK(host_content_settings_map_); 25 DCHECK(host_content_settings_map_);
24 } 26 }
25 27
26 ChooserContextBase::~ChooserContextBase() {} 28 ChooserContextBase::~ChooserContextBase() {}
27 29
30 bool ChooserContextBase::CanRequestObjectPermission(
31 const GURL& requesting_origin,
32 const GURL& embedding_origin) {
33 ContentSetting content_setting =
34 host_content_settings_map_->GetContentSetting(
35 requesting_origin, embedding_origin, guard_content_settings_type_,
36 std::string());
37 return content_setting == CONTENT_SETTING_ALLOW;
38 }
39
28 ObjectList ChooserContextBase::GetGrantedObjects(const GURL& requesting_origin, 40 ObjectList ChooserContextBase::GetGrantedObjects(const GURL& requesting_origin,
29 const GURL& embedding_origin) { 41 const GURL& embedding_origin) {
42 if (!CanRequestObjectPermission(requesting_origin, embedding_origin))
43 return ObjectList();
44
30 scoped_ptr<base::DictionaryValue> setting = 45 scoped_ptr<base::DictionaryValue> setting =
31 GetWebsiteSetting(requesting_origin, embedding_origin); 46 GetWebsiteSetting(requesting_origin, embedding_origin);
32 scoped_ptr<base::Value> objects; 47 scoped_ptr<base::Value> objects;
33 if (!setting->Remove(kObjectListKey, &objects)) 48 if (!setting->Remove(kObjectListKey, &objects))
34 return ObjectList(); 49 return ObjectList();
35 50
36 scoped_ptr<base::ListValue> object_list = 51 scoped_ptr<base::ListValue> object_list =
37 base::ListValue::From(objects.Pass()); 52 base::ListValue::From(objects.Pass());
38 if (!object_list) 53 if (!object_list)
39 return ObjectList(); 54 return ObjectList();
(...skipping 10 matching lines...) Expand all
50 if (object_dict && IsValidObject(*object_dict)) 65 if (object_dict && IsValidObject(*object_dict))
51 results.push_back(object_dict.Pass()); 66 results.push_back(object_dict.Pass());
52 } 67 }
53 return results.Pass(); 68 return results.Pass();
54 } 69 }
55 70
56 void ChooserContextBase::GrantObjectPermission( 71 void ChooserContextBase::GrantObjectPermission(
57 const GURL& requesting_origin, 72 const GURL& requesting_origin,
58 const GURL& embedding_origin, 73 const GURL& embedding_origin,
59 scoped_ptr<base::DictionaryValue> object) { 74 scoped_ptr<base::DictionaryValue> object) {
60 DCHECK(object && IsValidObject(*object)); 75 DCHECK(object);
76 DCHECK(IsValidObject(*object));
77 DCHECK(CanRequestObjectPermission(requesting_origin, embedding_origin));
61 scoped_ptr<base::DictionaryValue> setting = 78 scoped_ptr<base::DictionaryValue> setting =
62 GetWebsiteSetting(requesting_origin, embedding_origin); 79 GetWebsiteSetting(requesting_origin, embedding_origin);
63 base::ListValue* object_list; 80 base::ListValue* object_list;
64 if (!setting->GetList(kObjectListKey, &object_list)) { 81 if (!setting->GetList(kObjectListKey, &object_list)) {
65 object_list = new base::ListValue(); 82 object_list = new base::ListValue();
66 setting->Set(kObjectListKey, object_list); 83 setting->Set(kObjectListKey, object_list);
67 } 84 }
68 object_list->AppendIfNotPresent(object.release()); 85 object_list->AppendIfNotPresent(object.release());
69 SetWebsiteSetting(requesting_origin, embedding_origin, setting.Pass()); 86 SetWebsiteSetting(requesting_origin, embedding_origin, setting.Pass());
70 } 87 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 ContentSettingsPattern::FromURLNoWildcard(requesting_origin)); 120 ContentSettingsPattern::FromURLNoWildcard(requesting_origin));
104 ContentSettingsPattern secondary_pattern( 121 ContentSettingsPattern secondary_pattern(
105 ContentSettingsPattern::FromURLNoWildcard(embedding_origin)); 122 ContentSettingsPattern::FromURLNoWildcard(embedding_origin));
106 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) 123 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid())
107 return; 124 return;
108 125
109 host_content_settings_map_->SetWebsiteSetting( 126 host_content_settings_map_->SetWebsiteSetting(
110 primary_pattern, secondary_pattern, data_content_settings_type_, 127 primary_pattern, secondary_pattern, data_content_settings_type_,
111 std::string(), value.release()); 128 std::string(), value.release());
112 } 129 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/chooser_context_base.h ('k') | chrome/browser/usb/usb_chooser_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698