OLD | NEW |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 // Make sure the active permissions contain no more than optional + default. | 106 // Make sure the active permissions contain no more than optional + default. |
107 scoped_refptr<PermissionSet> adjusted_active = | 107 scoped_refptr<PermissionSet> adjusted_active = |
108 PermissionSet::CreateIntersection(total_permissions, active_permissions); | 108 PermissionSet::CreateIntersection(total_permissions, active_permissions); |
109 | 109 |
110 // Make sure the active permissions contain the default permissions. | 110 // Make sure the active permissions contain the default permissions. |
111 adjusted_active = PermissionSet::CreateUnion( | 111 adjusted_active = PermissionSet::CreateUnion( |
112 PermissionsParser::GetRequiredPermissions(extension), | 112 PermissionsParser::GetRequiredPermissions(extension), |
113 adjusted_active); | 113 adjusted_active); |
114 | 114 |
115 SetActivePermissions(extension, adjusted_active); | 115 extension->permissions_data()->InitializePermissions(adjusted_active, |
| 116 extension); |
| 117 // We record the active permissions after PermissionsData finishes |
| 118 // initializing, so that we properly record any withheld permissions. |
| 119 // TODO(rdevlin.cronin) This is badly factored. We should do all the |
| 120 // initialization in one place - either here, in PermissionsData, or in some |
| 121 // other object. |
| 122 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( |
| 123 extension->id(), extension->permissions_data()->active_permissions()); |
116 } | 124 } |
117 | 125 |
118 void PermissionsUpdater::SetActivePermissions( | 126 void PermissionsUpdater::SetActivePermissions( |
119 const Extension* extension, const PermissionSet* permissions) { | 127 const Extension* extension, const PermissionSet* permissions) { |
120 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( | 128 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( |
121 extension->id(), permissions); | 129 extension->id(), permissions); |
122 extension->permissions_data()->SetActivePermissions(permissions); | 130 extension->permissions_data()->SetPermissions( |
| 131 permissions, extension->permissions_data()->withheld_permissions()); |
123 } | 132 } |
124 | 133 |
125 void PermissionsUpdater::DispatchEvent( | 134 void PermissionsUpdater::DispatchEvent( |
126 const std::string& extension_id, | 135 const std::string& extension_id, |
127 const char* event_name, | 136 const char* event_name, |
128 const PermissionSet* changed_permissions) { | 137 const PermissionSet* changed_permissions) { |
129 EventRouter* event_router = EventRouter::Get(browser_context_); | 138 EventRouter* event_router = EventRouter::Get(browser_context_); |
130 if (!event_router) | 139 if (!event_router) |
131 return; | 140 return; |
132 | 141 |
(...skipping 28 matching lines...) Expand all Loading... |
161 // Notify other APIs or interested parties. | 170 // Notify other APIs or interested parties. |
162 UpdatedExtensionPermissionsInfo info = UpdatedExtensionPermissionsInfo( | 171 UpdatedExtensionPermissionsInfo info = UpdatedExtensionPermissionsInfo( |
163 extension, changed, reason); | 172 extension, changed, reason); |
164 Profile* profile = Profile::FromBrowserContext(browser_context_); | 173 Profile* profile = Profile::FromBrowserContext(browser_context_); |
165 content::NotificationService::current()->Notify( | 174 content::NotificationService::current()->Notify( |
166 chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, | 175 chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, |
167 content::Source<Profile>(profile), | 176 content::Source<Profile>(profile), |
168 content::Details<UpdatedExtensionPermissionsInfo>(&info)); | 177 content::Details<UpdatedExtensionPermissionsInfo>(&info)); |
169 | 178 |
170 ExtensionMsg_UpdatePermissions_Params params; | 179 ExtensionMsg_UpdatePermissions_Params params; |
171 params.reason_id = static_cast<int>(reason); | |
172 params.extension_id = extension->id(); | 180 params.extension_id = extension->id(); |
173 params.apis = changed->apis(); | 181 params.active_permissions = ExtensionMsg_PermissionSetStruct( |
174 params.manifest_permissions = changed->manifest_permissions(); | 182 extension->permissions_data()->active_permissions()); |
175 params.explicit_hosts = changed->explicit_hosts(); | 183 params.withheld_permissions = ExtensionMsg_PermissionSetStruct( |
176 params.scriptable_hosts = changed->scriptable_hosts(); | 184 extension->permissions_data()->withheld_permissions()); |
177 | 185 |
178 // Send the new permissions to the renderers. | 186 // Send the new permissions to the renderers. |
179 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 187 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
180 !i.IsAtEnd(); i.Advance()) { | 188 !i.IsAtEnd(); i.Advance()) { |
181 RenderProcessHost* host = i.GetCurrentValue(); | 189 RenderProcessHost* host = i.GetCurrentValue(); |
182 if (profile->IsSameProfile( | 190 if (profile->IsSameProfile( |
183 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 191 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
184 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 192 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
185 } | 193 } |
186 } | 194 } |
187 | 195 |
188 // Trigger the onAdded and onRemoved events in the extension. | 196 // Trigger the onAdded and onRemoved events in the extension. |
189 DispatchEvent(extension->id(), event_name, changed); | 197 DispatchEvent(extension->id(), event_name, changed); |
190 } | 198 } |
191 | 199 |
192 } // namespace extensions | 200 } // namespace extensions |
OLD | NEW |