Chromium Code Reviews| Index: chrome/browser/extensions/permissions_updater.cc |
| diff --git a/chrome/browser/extensions/permissions_updater.cc b/chrome/browser/extensions/permissions_updater.cc |
| index 26730a999aaa4510a01500c6c3bab92db4b18f12..3a1378fc3f2bd7df25cbe5f2bdd6850264157e9c 100644 |
| --- a/chrome/browser/extensions/permissions_updater.cc |
| +++ b/chrome/browser/extensions/permissions_updater.cc |
| @@ -136,6 +136,38 @@ void PermissionsUpdater::RemovePermissions(const Extension* extension, |
| NotifyPermissionsUpdated(REMOVED, extension, to_remove); |
| } |
| +void PermissionsUpdater::SetRuntimeBlockedAllowedHosts( |
| + const Extension* extension, |
| + const URLPatternSet& runtime_blocked_hosts, |
| + const URLPatternSet& runtime_allowed_hosts, |
| + bool is_default) { |
| + // Keep track of runtime blocked and hosts for this extension in the browser |
| + // process. We'll pull from here to populate when a new renderer is created. |
| + extension->permissions_data()->SetRuntimeBlockedAllowedHosts( |
| + std::move(runtime_blocked_hosts), std::move(runtime_allowed_hosts), |
| + is_default); |
| + |
| + // Send notification to the currently running renderers of the runtime block |
| + // hosts settings. |
| + NotifyRuntimeBlockedAllowedHostsUpdated(extension, runtime_blocked_hosts, |
| + runtime_allowed_hosts, is_default); |
| +} |
| + |
| +void PermissionsUpdater::SetDefaultRuntimeBlockedAllowedHosts( |
| + const URLPatternSet& default_runtime_blocked_hosts, |
| + const URLPatternSet& default_runtime_allowed_hosts) { |
| + // Keep track of runtime blocked and hosts for this extension in the browser |
| + // process. We'll pull from here to populate when a new renderer is created. |
| + PermissionsData::SetDefaultRuntimeBlockedAllowedHosts( |
| + std::move(default_runtime_blocked_hosts), |
| + std::move(default_runtime_allowed_hosts)); |
| + |
| + // Send notification to the currently running renderers of the runtime block |
| + // hosts settings. |
| + NotifyDefaultRuntimeBlockedAllowedHostsUpdated(default_runtime_blocked_hosts, |
| + default_runtime_allowed_hosts); |
| +} |
| + |
| void PermissionsUpdater::RemovePermissionsUnsafe( |
| const Extension* extension, |
| const PermissionSet& to_remove) { |
| @@ -292,4 +324,56 @@ void PermissionsUpdater::NotifyPermissionsUpdated( |
| DispatchEvent(extension->id(), histogram_value, event_name, changed); |
| } |
| +// Notify the renderers that extension policy (runtime_blocked_hosts) is updated |
| +// and provide new set of hosts. |
| +void PermissionsUpdater::NotifyRuntimeBlockedAllowedHostsUpdated( |
| + const Extension* extension, |
| + const URLPatternSet& runtime_blocked_hosts, |
| + const URLPatternSet& runtime_allowed_hosts, |
| + bool is_default) { |
| + DCHECK((init_flag_ & INIT_FLAG_TRANSIENT) == 0); |
| + |
| + Profile* profile = Profile::FromBrowserContext(browser_context_); |
| + |
| + // Send the new policy to the renderers. |
| + for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| + !i.IsAtEnd(); i.Advance()) { |
| + RenderProcessHost* host = i.GetCurrentValue(); |
| + if (profile->IsSameProfile( |
| + Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| + ExtensionMsg_UpdateAllowedAndBlockedHosts_Params params; |
| + params.extension_id = extension->id(); |
| + ExtensionMsg_RuntimeBlockedAllowedHostsStruct hosts( |
| + runtime_blocked_hosts, runtime_allowed_hosts, host->GetHandle()); |
| + params.hosts = hosts; |
| + params.is_default = is_default; |
| + host->Send(new ExtensionMsg_UpdateAllowedAndBlockedHosts(params)); |
| + } |
| + } |
| +} |
| + |
| +// Notify the renderers that extension policy (runtime_blocked_hosts) is updated |
| +// and provide new set of hosts. |
| +void PermissionsUpdater::NotifyDefaultRuntimeBlockedAllowedHostsUpdated( |
| + const URLPatternSet& default_runtime_blocked_hosts, |
| + const URLPatternSet& default_runtime_allowed_hosts) { |
| + DCHECK((init_flag_ & INIT_FLAG_TRANSIENT) == 0); |
| + |
| + Profile* profile = Profile::FromBrowserContext(browser_context_); |
| + |
| + // Send the new policy to the renderers. |
| + for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
|
zmin
2016/12/22 22:15:39
Can we use "host_iterator" or some other meaningfu
nrpeter
2017/01/19 01:50:45
Done.
|
| + !i.IsAtEnd(); i.Advance()) { |
| + RenderProcessHost* host = i.GetCurrentValue(); |
| + if (profile->IsSameProfile( |
| + Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| + ExtensionMsg_RuntimeBlockedAllowedHostsStruct params( |
| + default_runtime_blocked_hosts, default_runtime_allowed_hosts, |
| + host->GetHandle()); |
| + |
| + host->Send(new ExtensionMsg_UpdateDefaultAllowedAndBlockedHosts(params)); |
| + } |
| + } |
| +} |
| + |
| } // namespace extensions |