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

Side by Side Diff: chrome/browser/extensions/permissions_updater.cc

Issue 2794803003: PS - Remove Clipboard Read permission from extensions in Public Sessions (except for whitelisted on… (Closed)
Patch Set: Updated comment Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/permissions_updater.h" 5 #include "chrome/browser/extensions/permissions_updater.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 PermissionSet::CreateIntersection(*total_permissions, 62 PermissionSet::CreateIntersection(*total_permissions,
63 *active_permissions); 63 *active_permissions);
64 64
65 // Make sure the active permissions contain the default permissions. 65 // Make sure the active permissions contain the default permissions.
66 adjusted_active = 66 adjusted_active =
67 PermissionSet::CreateUnion(required_permissions, *adjusted_active); 67 PermissionSet::CreateUnion(required_permissions, *adjusted_active);
68 68
69 return adjusted_active; 69 return adjusted_active;
70 } 70 }
71 71
72 PermissionsUpdater::Delegate* g_delegate = nullptr;
73
72 } // namespace 74 } // namespace
73 75
74 PermissionsUpdater::PermissionsUpdater(content::BrowserContext* browser_context) 76 PermissionsUpdater::PermissionsUpdater(content::BrowserContext* browser_context)
75 : browser_context_(browser_context), init_flag_(INIT_FLAG_NONE) { 77 : browser_context_(browser_context), init_flag_(INIT_FLAG_NONE) {
76 } 78 }
77 79
78 PermissionsUpdater::PermissionsUpdater(content::BrowserContext* browser_context, 80 PermissionsUpdater::PermissionsUpdater(content::BrowserContext* browser_context,
79 InitFlag init_flag) 81 InitFlag init_flag)
80 : browser_context_(browser_context), init_flag_(init_flag) { 82 : browser_context_(browser_context), init_flag_(init_flag) {
81 } 83 }
82 84
83 PermissionsUpdater::~PermissionsUpdater() {} 85 PermissionsUpdater::~PermissionsUpdater() {}
84 86
87 // static
88 void PermissionsUpdater::SetPlatformDelegate(Delegate* delegate) {
89 // Make sure we're setting it only once (allow setting to nullptr, but then
90 // take special care of actually freeing it).
91 CHECK(!g_delegate || !delegate);
92 g_delegate = delegate;
93 }
94
85 void PermissionsUpdater::AddPermissions(const Extension* extension, 95 void PermissionsUpdater::AddPermissions(const Extension* extension,
86 const PermissionSet& permissions) { 96 const PermissionSet& permissions) {
87 const PermissionSet& active = 97 const PermissionSet& active =
88 extension->permissions_data()->active_permissions(); 98 extension->permissions_data()->active_permissions();
89 std::unique_ptr<const PermissionSet> total = 99 std::unique_ptr<const PermissionSet> total =
90 PermissionSet::CreateUnion(active, permissions); 100 PermissionSet::CreateUnion(active, permissions);
91 std::unique_ptr<const PermissionSet> added = 101 std::unique_ptr<const PermissionSet> added =
92 PermissionSet::CreateDifference(*total, active); 102 PermissionSet::CreateDifference(*total, active);
93 103
94 std::unique_ptr<const PermissionSet> new_withheld = 104 std::unique_ptr<const PermissionSet> new_withheld =
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 bounded_active = bounded_wrapper.get(); 200 bounded_active = bounded_wrapper.get();
191 } 201 }
192 202
193 std::unique_ptr<const PermissionSet> granted_permissions; 203 std::unique_ptr<const PermissionSet> granted_permissions;
194 std::unique_ptr<const PermissionSet> withheld_permissions; 204 std::unique_ptr<const PermissionSet> withheld_permissions;
195 ScriptingPermissionsModifier(browser_context_, make_scoped_refptr(extension)) 205 ScriptingPermissionsModifier(browser_context_, make_scoped_refptr(extension))
196 .WithholdPermissions(*bounded_active, &granted_permissions, 206 .WithholdPermissions(*bounded_active, &granted_permissions,
197 &withheld_permissions, 207 &withheld_permissions,
198 (init_flag_ & INIT_FLAG_TRANSIENT) != 0); 208 (init_flag_ & INIT_FLAG_TRANSIENT) != 0);
199 209
210 if (g_delegate)
211 g_delegate->InitializePermissions(extension, &granted_permissions);
212
200 SetPermissions(extension, std::move(granted_permissions), 213 SetPermissions(extension, std::move(granted_permissions),
201 std::move(withheld_permissions)); 214 std::move(withheld_permissions));
202 } 215 }
203 216
204 void PermissionsUpdater::SetPermissions( 217 void PermissionsUpdater::SetPermissions(
205 const Extension* extension, 218 const Extension* extension,
206 std::unique_ptr<const PermissionSet> active, 219 std::unique_ptr<const PermissionSet> active,
207 std::unique_ptr<const PermissionSet> withheld) { 220 std::unique_ptr<const PermissionSet> withheld) {
208 DCHECK(active); 221 DCHECK(active);
209 const PermissionSet& active_weak = *active; 222 const PermissionSet& active_weak = *active;
(...skipping 26 matching lines...) Expand all
236 std::unique_ptr<Event> event( 249 std::unique_ptr<Event> event(
237 new Event(histogram_value, event_name, std::move(value))); 250 new Event(histogram_value, event_name, std::move(value)));
238 event->restrict_to_browser_context = browser_context_; 251 event->restrict_to_browser_context = browser_context_;
239 event_router->DispatchEventToExtension(extension_id, std::move(event)); 252 event_router->DispatchEventToExtension(extension_id, std::move(event));
240 } 253 }
241 254
242 void PermissionsUpdater::NotifyPermissionsUpdated( 255 void PermissionsUpdater::NotifyPermissionsUpdated(
243 EventType event_type, 256 EventType event_type,
244 const Extension* extension, 257 const Extension* extension,
245 const PermissionSet& changed) { 258 const PermissionSet& changed) {
246 DCHECK((init_flag_ & INIT_FLAG_TRANSIENT) == 0); 259 DCHECK_EQ(0, init_flag_ & INIT_FLAG_TRANSIENT);
247 if (changed.IsEmpty()) 260 if (changed.IsEmpty())
248 return; 261 return;
249 262
250 UpdatedExtensionPermissionsInfo::Reason reason; 263 UpdatedExtensionPermissionsInfo::Reason reason;
251 events::HistogramValue histogram_value; 264 events::HistogramValue histogram_value;
252 const char* event_name = NULL; 265 const char* event_name = NULL;
253 266
254 if (event_type == REMOVED) { 267 if (event_type == REMOVED) {
255 reason = UpdatedExtensionPermissionsInfo::REMOVED; 268 reason = UpdatedExtensionPermissionsInfo::REMOVED;
256 histogram_value = events::PERMISSIONS_ON_REMOVED; 269 histogram_value = events::PERMISSIONS_ON_REMOVED;
(...skipping 29 matching lines...) Expand all
286 Profile::FromBrowserContext(host->GetBrowserContext()))) { 299 Profile::FromBrowserContext(host->GetBrowserContext()))) {
287 host->Send(new ExtensionMsg_UpdatePermissions(params)); 300 host->Send(new ExtensionMsg_UpdatePermissions(params));
288 } 301 }
289 } 302 }
290 303
291 // Trigger the onAdded and onRemoved events in the extension. 304 // Trigger the onAdded and onRemoved events in the extension.
292 DispatchEvent(extension->id(), histogram_value, event_name, changed); 305 DispatchEvent(extension->id(), histogram_value, event_name, changed);
293 } 306 }
294 307
295 } // namespace extensions 308 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/permissions_updater.h ('k') | chrome/browser/extensions/permissions_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698