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

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

Issue 314113010: Remove deprecated permissions functions from Extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 18 matching lines...) Expand all
29 namespace permissions = api::permissions; 29 namespace permissions = api::permissions;
30 30
31 PermissionsUpdater::PermissionsUpdater(Profile* profile) 31 PermissionsUpdater::PermissionsUpdater(Profile* profile)
32 : profile_(profile) {} 32 : profile_(profile) {}
33 33
34 PermissionsUpdater::~PermissionsUpdater() {} 34 PermissionsUpdater::~PermissionsUpdater() {}
35 35
36 void PermissionsUpdater::AddPermissions( 36 void PermissionsUpdater::AddPermissions(
37 const Extension* extension, const PermissionSet* permissions) { 37 const Extension* extension, const PermissionSet* permissions) {
38 scoped_refptr<const PermissionSet> existing( 38 scoped_refptr<const PermissionSet> existing(
39 extension->GetActivePermissions()); 39 extension->permissions_data()->active_permissions());
40 scoped_refptr<PermissionSet> total( 40 scoped_refptr<PermissionSet> total(
41 PermissionSet::CreateUnion(existing.get(), permissions)); 41 PermissionSet::CreateUnion(existing.get(), permissions));
42 scoped_refptr<PermissionSet> added( 42 scoped_refptr<PermissionSet> added(
43 PermissionSet::CreateDifference(total.get(), existing.get())); 43 PermissionSet::CreateDifference(total.get(), existing.get()));
44 44
45 UpdateActivePermissions(extension, total.get()); 45 UpdateActivePermissions(extension, total.get());
46 46
47 // Update the granted permissions so we don't auto-disable the extension. 47 // Update the granted permissions so we don't auto-disable the extension.
48 GrantActivePermissions(extension); 48 GrantActivePermissions(extension);
49 49
50 NotifyPermissionsUpdated(ADDED, extension, added.get()); 50 NotifyPermissionsUpdated(ADDED, extension, added.get());
51 } 51 }
52 52
53 void PermissionsUpdater::RemovePermissions( 53 void PermissionsUpdater::RemovePermissions(
54 const Extension* extension, const PermissionSet* permissions) { 54 const Extension* extension, const PermissionSet* permissions) {
55 scoped_refptr<const PermissionSet> existing( 55 scoped_refptr<const PermissionSet> existing(
56 extension->GetActivePermissions()); 56 extension->permissions_data()->active_permissions());
57 scoped_refptr<PermissionSet> total( 57 scoped_refptr<PermissionSet> total(
58 PermissionSet::CreateDifference(existing.get(), permissions)); 58 PermissionSet::CreateDifference(existing.get(), permissions));
59 scoped_refptr<PermissionSet> removed( 59 scoped_refptr<PermissionSet> removed(
60 PermissionSet::CreateDifference(existing.get(), total.get())); 60 PermissionSet::CreateDifference(existing.get(), total.get()));
61 61
62 // We update the active permissions, and not the granted permissions, because 62 // We update the active permissions, and not the granted permissions, because
63 // the extension, not the user, removed the permissions. This allows the 63 // the extension, not the user, removed the permissions. This allows the
64 // extension to add them again without prompting the user. 64 // extension to add them again without prompting the user.
65 UpdateActivePermissions(extension, total.get()); 65 UpdateActivePermissions(extension, total.get());
66 66
67 NotifyPermissionsUpdated(REMOVED, extension, removed.get()); 67 NotifyPermissionsUpdated(REMOVED, extension, removed.get());
68 } 68 }
69 69
70 void PermissionsUpdater::GrantActivePermissions(const Extension* extension) { 70 void PermissionsUpdater::GrantActivePermissions(const Extension* extension) {
71 CHECK(extension); 71 CHECK(extension);
72 72
73 // We only maintain the granted permissions prefs for INTERNAL and LOAD 73 // We only maintain the granted permissions prefs for INTERNAL and LOAD
74 // extensions. 74 // extensions.
75 if (!Manifest::IsUnpackedLocation(extension->location()) && 75 if (!Manifest::IsUnpackedLocation(extension->location()) &&
76 extension->location() != Manifest::INTERNAL) 76 extension->location() != Manifest::INTERNAL)
77 return; 77 return;
78 78
79 ExtensionPrefs::Get(profile_)->AddGrantedPermissions( 79 ExtensionPrefs::Get(profile_)->AddGrantedPermissions(
80 extension->id(), extension->GetActivePermissions().get()); 80 extension->id(),
81 extension->permissions_data()->active_permissions().get());
81 } 82 }
82 83
83 void PermissionsUpdater::UpdateActivePermissions( 84 void PermissionsUpdater::UpdateActivePermissions(
84 const Extension* extension, const PermissionSet* permissions) { 85 const Extension* extension, const PermissionSet* permissions) {
85 ExtensionPrefs::Get(profile_)->SetActivePermissions( 86 ExtensionPrefs::Get(profile_)->SetActivePermissions(
86 extension->id(), permissions); 87 extension->id(), permissions);
87 extension->permissions_data()->SetActivePermissions(permissions); 88 extension->permissions_data()->SetActivePermissions(permissions);
88 } 89 }
89 90
90 void PermissionsUpdater::DispatchEvent( 91 void PermissionsUpdater::DispatchEvent(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 info.scriptable_hosts = changed->scriptable_hosts(); 147 info.scriptable_hosts = changed->scriptable_hosts();
147 host->Send(new ExtensionMsg_UpdatePermissions(info)); 148 host->Send(new ExtensionMsg_UpdatePermissions(info));
148 } 149 }
149 } 150 }
150 151
151 // Trigger the onAdded and onRemoved events in the extension. 152 // Trigger the onAdded and onRemoved events in the extension.
152 DispatchEvent(extension->id(), event_name, changed); 153 DispatchEvent(extension->id(), event_name, changed);
153 } 154 }
154 155
155 } // namespace extensions 156 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_util.cc ('k') | chrome/browser/extensions/permissions_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698