| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // not the user, removed the permissions. This allows the extension to add | 129 // not the user, removed the permissions. This allows the extension to add |
| 130 // them again without prompting the user. | 130 // them again without prompting the user. |
| 131 if (remove_type == REMOVE_HARD) { | 131 if (remove_type == REMOVE_HARD) { |
| 132 ExtensionPrefs::Get(browser_context_) | 132 ExtensionPrefs::Get(browser_context_) |
| 133 ->RemoveGrantedPermissions(extension->id(), to_remove); | 133 ->RemoveGrantedPermissions(extension->id(), to_remove); |
| 134 } | 134 } |
| 135 | 135 |
| 136 NotifyPermissionsUpdated(REMOVED, extension, to_remove); | 136 NotifyPermissionsUpdated(REMOVED, extension, to_remove); |
| 137 } | 137 } |
| 138 | 138 |
| 139 |
| 140 void PermissionsUpdater::SetRuntimeBlockedAllowedHosts( |
| 141 const Extension* extension, |
| 142 const URLPatternSet& runtime_blocked_hosts, |
| 143 const URLPatternSet& runtime_allowed_hosts) { |
| 144 |
| 145 // Keep track of runtime blocked and hosts for this extension in the browser |
| 146 // process. We'll pull from here to populate when a new renderer is created. |
| 147 extension->permissions_data()->SetRuntimeBlockedAllowedHosts( |
| 148 std::move(runtime_blocked_hosts), |
| 149 std::move(runtime_allowed_hosts)); |
| 150 |
| 151 |
| 152 // Send notification to the currently running renderers of the runtime block |
| 153 // hosts settings. |
| 154 NotifyPolicyUpdated(extension, runtime_blocked_hosts, runtime_allowed_hosts); |
| 155 } |
| 156 |
| 139 void PermissionsUpdater::RemovePermissionsUnsafe( | 157 void PermissionsUpdater::RemovePermissionsUnsafe( |
| 140 const Extension* extension, | 158 const Extension* extension, |
| 141 const PermissionSet& to_remove) { | 159 const PermissionSet& to_remove) { |
| 142 const PermissionSet& active = | 160 const PermissionSet& active = |
| 143 extension->permissions_data()->active_permissions(); | 161 extension->permissions_data()->active_permissions(); |
| 144 std::unique_ptr<const PermissionSet> total = | 162 std::unique_ptr<const PermissionSet> total = |
| 145 PermissionSet::CreateDifference(active, to_remove); | 163 PermissionSet::CreateDifference(active, to_remove); |
| 146 // |successfully_removed| might not equal |to_remove| if |to_remove| contains | 164 // |successfully_removed| might not equal |to_remove| if |to_remove| contains |
| 147 // permissions the extension didn't have. | 165 // permissions the extension didn't have. |
| 148 std::unique_ptr<const PermissionSet> successfully_removed = | 166 std::unique_ptr<const PermissionSet> successfully_removed = |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (profile->IsSameProfile( | 303 if (profile->IsSameProfile( |
| 286 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 304 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| 287 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 305 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
| 288 } | 306 } |
| 289 } | 307 } |
| 290 | 308 |
| 291 // Trigger the onAdded and onRemoved events in the extension. | 309 // Trigger the onAdded and onRemoved events in the extension. |
| 292 DispatchEvent(extension->id(), histogram_value, event_name, changed); | 310 DispatchEvent(extension->id(), histogram_value, event_name, changed); |
| 293 } | 311 } |
| 294 | 312 |
| 313 |
| 314 |
| 315 // Notify the renderers that extension policy (runtime_blocked_hosts) is updated |
| 316 // and provide new set of hosts. |
| 317 void PermissionsUpdater::NotifyPolicyUpdated( |
| 318 const Extension* extension, |
| 319 const URLPatternSet& runtime_blocked_hosts, |
| 320 const URLPatternSet& runtime_allowed_hosts) { |
| 321 DCHECK((init_flag_ & INIT_FLAG_TRANSIENT) == 0); |
| 322 |
| 323 Profile* profile = Profile::FromBrowserContext(browser_context_); |
| 324 |
| 325 ExtensionMsg_UpdatePolicy_Params params; |
| 326 params.extension_id = extension->id(); |
| 327 params.runtime_blocked_hosts = runtime_blocked_hosts; |
| 328 params.runtime_allowed_hosts = runtime_allowed_hosts; |
| 329 |
| 330 // Send the new policy to the renderers. |
| 331 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 332 !i.IsAtEnd(); i.Advance()) { |
| 333 RenderProcessHost* host = i.GetCurrentValue(); |
| 334 if (profile->IsSameProfile( |
| 335 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| 336 host->Send(new ExtensionMsg_UpdatePolicy(params)); |
| 337 } |
| 338 } |
| 339 } |
| 340 |
| 295 } // namespace extensions | 341 } // namespace extensions |
| OLD | NEW |