| 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 168 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 |