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

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

Issue 939803002: [Extensions] Update renderers when all-urls is granted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test Created 5 years, 10 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
« no previous file with comments | « chrome/browser/extensions/active_script_controller_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 &active_scriptable, 246 &active_scriptable,
247 &withheld_scriptable); 247 &withheld_scriptable);
248 248
249 URLPatternSet withheld_explicit = withheld->explicit_hosts(); 249 URLPatternSet withheld_explicit = withheld->explicit_hosts();
250 URLPatternSet active_explicit; 250 URLPatternSet active_explicit;
251 SegregateUrlPermissions(active->explicit_hosts(), 251 SegregateUrlPermissions(active->explicit_hosts(),
252 true, // withhold permissions 252 true, // withhold permissions
253 &active_explicit, 253 &active_explicit,
254 &withheld_explicit); 254 &withheld_explicit);
255 255
256 URLPatternSet delta_explicit;
257 URLPatternSet::CreateDifference(
258 active->explicit_hosts(), active_explicit, &delta_explicit);
259 URLPatternSet delta_scriptable;
260 URLPatternSet::CreateDifference(
261 active->scriptable_hosts(), active_scriptable, &delta_scriptable);
262
256 SetPermissions(extension, 263 SetPermissions(extension,
257 new PermissionSet(active->apis(), 264 new PermissionSet(active->apis(),
258 active->manifest_permissions(), 265 active->manifest_permissions(),
259 active_explicit, 266 active_explicit,
260 active_scriptable), 267 active_scriptable),
261 new PermissionSet(withheld->apis(), 268 new PermissionSet(withheld->apis(),
262 withheld->manifest_permissions(), 269 withheld->manifest_permissions(),
263 withheld_explicit, 270 withheld_explicit,
264 withheld_scriptable)); 271 withheld_scriptable));
265 // TODO(rdevlin.cronin) We should notify the observers/renderer. 272
273 scoped_refptr<const PermissionSet> delta(new PermissionSet(
274 APIPermissionSet(),
275 ManifestPermissionSet(),
276 delta_explicit,
277 delta_scriptable));
278 NotifyPermissionsUpdated(REMOVED, extension, delta.get());
266 } 279 }
267 280
268 void PermissionsUpdater::GrantWithheldImpliedAllHosts( 281 void PermissionsUpdater::GrantWithheldImpliedAllHosts(
269 const Extension* extension) { 282 const Extension* extension) {
270 scoped_refptr<const PermissionSet> active = 283 scoped_refptr<const PermissionSet> active =
271 extension->permissions_data()->active_permissions(); 284 extension->permissions_data()->active_permissions();
272 scoped_refptr<const PermissionSet> withheld = 285 scoped_refptr<const PermissionSet> withheld =
273 extension->permissions_data()->withheld_permissions(); 286 extension->permissions_data()->withheld_permissions();
274 287
275 // Move the all-hosts permission from withheld to active. 288 // Move the all-hosts permission from withheld to active.
276 // We can cheat a bit here since we know that the only host permission we 289 // We can cheat a bit here since we know that the only host permission we
277 // withhold is allhosts (or something similar enough to it), so we can just 290 // withhold is allhosts (or something similar enough to it), so we can just
278 // grant all withheld host permissions. 291 // grant all withheld host permissions.
279 URLPatternSet explicit_hosts; 292 URLPatternSet explicit_hosts;
280 URLPatternSet::CreateUnion( 293 URLPatternSet::CreateUnion(
281 active->explicit_hosts(), withheld->explicit_hosts(), &explicit_hosts); 294 active->explicit_hosts(), withheld->explicit_hosts(), &explicit_hosts);
282 URLPatternSet scriptable_hosts; 295 URLPatternSet scriptable_hosts;
283 URLPatternSet::CreateUnion(active->scriptable_hosts(), 296 URLPatternSet::CreateUnion(active->scriptable_hosts(),
284 withheld->scriptable_hosts(), 297 withheld->scriptable_hosts(),
285 &scriptable_hosts); 298 &scriptable_hosts);
286 299
300 URLPatternSet delta_explicit;
301 URLPatternSet::CreateDifference(
302 explicit_hosts, active->explicit_hosts(), &delta_explicit);
303 URLPatternSet delta_scriptable;
304 URLPatternSet::CreateDifference(
305 scriptable_hosts, active->scriptable_hosts(), &delta_scriptable);
306
287 // Since we only withhold host permissions (so far), we know that withheld 307 // Since we only withhold host permissions (so far), we know that withheld
288 // permissions will be empty. 308 // permissions will be empty.
289 SetPermissions(extension, 309 SetPermissions(extension,
290 new PermissionSet(active->apis(), 310 new PermissionSet(active->apis(),
291 active->manifest_permissions(), 311 active->manifest_permissions(),
292 explicit_hosts, 312 explicit_hosts,
293 scriptable_hosts), 313 scriptable_hosts),
294 new PermissionSet()); 314 new PermissionSet());
295 // TODO(rdevlin.cronin) We should notify the observers/renderer. 315
316 scoped_refptr<const PermissionSet> delta(new PermissionSet(
317 APIPermissionSet(),
318 ManifestPermissionSet(),
319 delta_explicit,
320 delta_scriptable));
321 NotifyPermissionsUpdated(ADDED, extension, delta.get());
296 } 322 }
297 323
298 void PermissionsUpdater::SetPermissions( 324 void PermissionsUpdater::SetPermissions(
299 const Extension* extension, 325 const Extension* extension,
300 const scoped_refptr<const PermissionSet>& active, 326 const scoped_refptr<const PermissionSet>& active,
301 scoped_refptr<const PermissionSet> withheld) { 327 scoped_refptr<const PermissionSet> withheld) {
302 withheld = withheld.get() ? withheld 328 withheld = withheld.get() ? withheld
303 : extension->permissions_data()->withheld_permissions(); 329 : extension->permissions_data()->withheld_permissions();
304 extension->permissions_data()->SetPermissions(active, withheld); 330 extension->permissions_data()->SetPermissions(active, withheld);
305 if ((init_flag_ & INIT_FLAG_TRANSIENT) == 0) { 331 if ((init_flag_ & INIT_FLAG_TRANSIENT) == 0) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 Profile::FromBrowserContext(host->GetBrowserContext()))) { 395 Profile::FromBrowserContext(host->GetBrowserContext()))) {
370 host->Send(new ExtensionMsg_UpdatePermissions(params)); 396 host->Send(new ExtensionMsg_UpdatePermissions(params));
371 } 397 }
372 } 398 }
373 399
374 // Trigger the onAdded and onRemoved events in the extension. 400 // Trigger the onAdded and onRemoved events in the extension.
375 DispatchEvent(extension->id(), event_name, changed); 401 DispatchEvent(extension->id(), event_name, changed);
376 } 402 }
377 403
378 } // namespace extensions 404 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/active_script_controller_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698