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

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 comments 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 g_delegate = delegate;
Andrew T Wilson (Slow) 2017/04/11 11:32:54 I think we should CHECK(!g_delegate) here to make
Ivan Šandrk 2017/04/11 13:37:27 Done.
90 }
91
85 void PermissionsUpdater::AddPermissions(const Extension* extension, 92 void PermissionsUpdater::AddPermissions(const Extension* extension,
86 const PermissionSet& permissions) { 93 const PermissionSet& permissions) {
87 const PermissionSet& active = 94 const PermissionSet& active =
88 extension->permissions_data()->active_permissions(); 95 extension->permissions_data()->active_permissions();
89 std::unique_ptr<const PermissionSet> total = 96 std::unique_ptr<const PermissionSet> total =
90 PermissionSet::CreateUnion(active, permissions); 97 PermissionSet::CreateUnion(active, permissions);
91 std::unique_ptr<const PermissionSet> added = 98 std::unique_ptr<const PermissionSet> added =
92 PermissionSet::CreateDifference(*total, active); 99 PermissionSet::CreateDifference(*total, active);
93 100
94 std::unique_ptr<const PermissionSet> new_withheld = 101 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(); 197 bounded_active = bounded_wrapper.get();
191 } 198 }
192 199
193 std::unique_ptr<const PermissionSet> granted_permissions; 200 std::unique_ptr<const PermissionSet> granted_permissions;
194 std::unique_ptr<const PermissionSet> withheld_permissions; 201 std::unique_ptr<const PermissionSet> withheld_permissions;
195 ScriptingPermissionsModifier(browser_context_, make_scoped_refptr(extension)) 202 ScriptingPermissionsModifier(browser_context_, make_scoped_refptr(extension))
196 .WithholdPermissions(*bounded_active, &granted_permissions, 203 .WithholdPermissions(*bounded_active, &granted_permissions,
197 &withheld_permissions, 204 &withheld_permissions,
198 (init_flag_ & INIT_FLAG_TRANSIENT) != 0); 205 (init_flag_ & INIT_FLAG_TRANSIENT) != 0);
199 206
207 if (g_delegate)
208 g_delegate->InitializePermissions(extension, &granted_permissions);
209
200 SetPermissions(extension, std::move(granted_permissions), 210 SetPermissions(extension, std::move(granted_permissions),
201 std::move(withheld_permissions)); 211 std::move(withheld_permissions));
202 } 212 }
203 213
204 void PermissionsUpdater::SetPermissions( 214 void PermissionsUpdater::SetPermissions(
205 const Extension* extension, 215 const Extension* extension,
206 std::unique_ptr<const PermissionSet> active, 216 std::unique_ptr<const PermissionSet> active,
207 std::unique_ptr<const PermissionSet> withheld) { 217 std::unique_ptr<const PermissionSet> withheld) {
208 DCHECK(active); 218 DCHECK(active);
209 const PermissionSet& active_weak = *active; 219 const PermissionSet& active_weak = *active;
(...skipping 26 matching lines...) Expand all
236 std::unique_ptr<Event> event( 246 std::unique_ptr<Event> event(
237 new Event(histogram_value, event_name, std::move(value))); 247 new Event(histogram_value, event_name, std::move(value)));
238 event->restrict_to_browser_context = browser_context_; 248 event->restrict_to_browser_context = browser_context_;
239 event_router->DispatchEventToExtension(extension_id, std::move(event)); 249 event_router->DispatchEventToExtension(extension_id, std::move(event));
240 } 250 }
241 251
242 void PermissionsUpdater::NotifyPermissionsUpdated( 252 void PermissionsUpdater::NotifyPermissionsUpdated(
243 EventType event_type, 253 EventType event_type,
244 const Extension* extension, 254 const Extension* extension,
245 const PermissionSet& changed) { 255 const PermissionSet& changed) {
246 DCHECK((init_flag_ & INIT_FLAG_TRANSIENT) == 0); 256 DCHECK_EQ(0, init_flag_ & INIT_FLAG_TRANSIENT);
247 if (changed.IsEmpty()) 257 if (changed.IsEmpty())
248 return; 258 return;
249 259
250 UpdatedExtensionPermissionsInfo::Reason reason; 260 UpdatedExtensionPermissionsInfo::Reason reason;
251 events::HistogramValue histogram_value; 261 events::HistogramValue histogram_value;
252 const char* event_name = NULL; 262 const char* event_name = NULL;
253 263
254 if (event_type == REMOVED) { 264 if (event_type == REMOVED) {
255 reason = UpdatedExtensionPermissionsInfo::REMOVED; 265 reason = UpdatedExtensionPermissionsInfo::REMOVED;
256 histogram_value = events::PERMISSIONS_ON_REMOVED; 266 histogram_value = events::PERMISSIONS_ON_REMOVED;
(...skipping 29 matching lines...) Expand all
286 Profile::FromBrowserContext(host->GetBrowserContext()))) { 296 Profile::FromBrowserContext(host->GetBrowserContext()))) {
287 host->Send(new ExtensionMsg_UpdatePermissions(params)); 297 host->Send(new ExtensionMsg_UpdatePermissions(params));
288 } 298 }
289 } 299 }
290 300
291 // Trigger the onAdded and onRemoved events in the extension. 301 // Trigger the onAdded and onRemoved events in the extension.
292 DispatchEvent(extension->id(), histogram_value, event_name, changed); 302 DispatchEvent(extension->id(), histogram_value, event_name, changed);
293 } 303 }
294 304
295 } // namespace extensions 305 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698