Chromium Code Reviews| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 if (!Manifest::IsUnpackedLocation(extension->location()) && | 157 if (!Manifest::IsUnpackedLocation(extension->location()) && |
| 158 extension->location() != Manifest::INTERNAL) | 158 extension->location() != Manifest::INTERNAL) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( | 161 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( |
| 162 extension->id(), | 162 extension->id(), |
| 163 extension->permissions_data()->active_permissions().get()); | 163 extension->permissions_data()->active_permissions().get()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void PermissionsUpdater::InitializePermissions(const Extension* extension) { | 166 void PermissionsUpdater::InitializePermissions(const Extension* extension) { |
| 167 scoped_refptr<const PermissionSet> active_permissions = | 167 InitializePermissions(extension, INIT_FLAG_NONE); |
| 168 ExtensionPrefs::Get(browser_context_) | 168 } |
| 169 ->GetActivePermissions(extension->id()); | 169 |
| 170 scoped_refptr<const PermissionSet> bounded_active = | 170 void PermissionsUpdater::InitializePermissions(const Extension* extension, |
| 171 GetBoundedActivePermissions(extension, active_permissions); | 171 InitFlag init_flag) { |
| 172 scoped_refptr<const PermissionSet> active_permissions(NULL); | |
| 173 scoped_refptr<const PermissionSet> bounded_active(NULL); | |
| 174 // If |extension| is a transient dummy extension, we do not want to look for | |
| 175 // it in preferences. | |
| 176 if (init_flag & INIT_FLAG_TRANSIENT) { | |
| 177 bounded_active = active_permissions = | |
| 178 extension->permissions_data()->active_permissions(); | |
| 179 } else { | |
| 180 active_permissions = ExtensionPrefs::Get(browser_context_) | |
| 181 ->GetActivePermissions(extension->id()); | |
| 182 bounded_active = GetBoundedActivePermissions(extension, active_permissions); | |
| 183 } | |
| 172 | 184 |
| 173 // Withhold permissions only if the switch applies to this extension and the | 185 // Withhold permissions only if the switch applies to this extension and the |
| 174 // extension doesn't have the preference to allow scripting on all urls. | 186 // extension doesn't have the preference to allow scripting on all urls. |
| 175 bool should_withhold_permissions = | 187 bool should_withhold_permissions = |
| 176 util::ScriptsMayRequireActionForExtension(extension) && | 188 util::ScriptsMayRequireActionForExtension(extension) && |
| 177 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); | 189 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); |
| 178 | 190 |
| 179 URLPatternSet granted_explicit_hosts; | 191 URLPatternSet granted_explicit_hosts; |
| 180 URLPatternSet withheld_explicit_hosts; | 192 URLPatternSet withheld_explicit_hosts; |
| 181 SegregateUrlPermissions(bounded_active->explicit_hosts(), | 193 SegregateUrlPermissions(bounded_active->explicit_hosts(), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 // TODO(rdevlin.cronin) We should notify the observers/renderer. | 291 // TODO(rdevlin.cronin) We should notify the observers/renderer. |
| 280 } | 292 } |
| 281 | 293 |
| 282 void PermissionsUpdater::SetPermissions( | 294 void PermissionsUpdater::SetPermissions( |
| 283 const Extension* extension, | 295 const Extension* extension, |
| 284 const scoped_refptr<const PermissionSet>& active, | 296 const scoped_refptr<const PermissionSet>& active, |
| 285 scoped_refptr<const PermissionSet> withheld) { | 297 scoped_refptr<const PermissionSet> withheld) { |
| 286 withheld = withheld.get() ? withheld | 298 withheld = withheld.get() ? withheld |
| 287 : extension->permissions_data()->withheld_permissions(); | 299 : extension->permissions_data()->withheld_permissions(); |
| 288 extension->permissions_data()->SetPermissions(active, withheld); | 300 extension->permissions_data()->SetPermissions(active, withheld); |
| 289 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( | 301 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( |
|
Devlin
2014/09/08 16:09:22
I'm worried about the fact that SetPermissions (wh
gpdavis
2014/09/08 20:07:05
If we don't make the SetPermissions call for a tra
Devlin
2014/09/09 15:53:21
Right, so I would suggest either
a) make two metho
gpdavis
2014/09/09 17:32:41
How does my implementation in patch set 12 look?
Devlin
2014/09/09 17:46:22
I don't feel super-strongly either way, but my big
| |
| 290 extension->id(), active.get()); | 302 extension->id(), active.get()); |
| 291 } | 303 } |
| 292 | 304 |
| 293 void PermissionsUpdater::DispatchEvent( | 305 void PermissionsUpdater::DispatchEvent( |
| 294 const std::string& extension_id, | 306 const std::string& extension_id, |
| 295 const char* event_name, | 307 const char* event_name, |
| 296 const PermissionSet* changed_permissions) { | 308 const PermissionSet* changed_permissions) { |
| 297 EventRouter* event_router = EventRouter::Get(browser_context_); | 309 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 298 if (!event_router) | 310 if (!event_router) |
| 299 return; | 311 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 362 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| 351 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 363 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
| 352 } | 364 } |
| 353 } | 365 } |
| 354 | 366 |
| 355 // Trigger the onAdded and onRemoved events in the extension. | 367 // Trigger the onAdded and onRemoved events in the extension. |
| 356 DispatchEvent(extension->id(), event_name, changed); | 368 DispatchEvent(extension->id(), event_name, changed); |
| 357 } | 369 } |
| 358 | 370 |
| 359 } // namespace extensions | 371 } // namespace extensions |
| OLD | NEW |