Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Side by Side Diff: chrome/browser/extensions/permissions_updater.cc

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: URLPatternSets use shared memory for IPC. Default scope patterns sent once per renderer. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void PermissionsUpdater::SetRuntimeBlockedAllowedHosts(
140 const Extension* extension,
141 const URLPatternSet& runtime_blocked_hosts,
142 const URLPatternSet& runtime_allowed_hosts,
143 bool is_default) {
144 // Keep track of runtime blocked and hosts for this extension in the browser
145 // process. We'll pull from here to populate when a new renderer is created.
146 extension->permissions_data()->SetRuntimeBlockedAllowedHosts(
147 std::move(runtime_blocked_hosts), std::move(runtime_allowed_hosts),
148 is_default);
149
150 // Send notification to the currently running renderers of the runtime block
151 // hosts settings.
152 NotifyRuntimeBlockedAllowedHostsUpdated(extension, runtime_blocked_hosts,
153 runtime_allowed_hosts, is_default);
154 }
155
156 void PermissionsUpdater::SetDefaultRuntimeBlockedAllowedHosts(
157 const URLPatternSet& default_runtime_blocked_hosts,
158 const URLPatternSet& default_runtime_allowed_hosts) {
159 // Keep track of runtime blocked and hosts for this extension in the browser
160 // process. We'll pull from here to populate when a new renderer is created.
161 PermissionsData::SetDefaultRuntimeBlockedAllowedHosts(
162 std::move(default_runtime_blocked_hosts),
163 std::move(default_runtime_allowed_hosts));
164
165 // Send notification to the currently running renderers of the runtime block
166 // hosts settings.
167 NotifyDefaultRuntimeBlockedAllowedHostsUpdated(default_runtime_blocked_hosts,
168 default_runtime_allowed_hosts);
169 }
170
139 void PermissionsUpdater::RemovePermissionsUnsafe( 171 void PermissionsUpdater::RemovePermissionsUnsafe(
140 const Extension* extension, 172 const Extension* extension,
141 const PermissionSet& to_remove) { 173 const PermissionSet& to_remove) {
142 const PermissionSet& active = 174 const PermissionSet& active =
143 extension->permissions_data()->active_permissions(); 175 extension->permissions_data()->active_permissions();
144 std::unique_ptr<const PermissionSet> total = 176 std::unique_ptr<const PermissionSet> total =
145 PermissionSet::CreateDifference(active, to_remove); 177 PermissionSet::CreateDifference(active, to_remove);
146 // |successfully_removed| might not equal |to_remove| if |to_remove| contains 178 // |successfully_removed| might not equal |to_remove| if |to_remove| contains
147 // permissions the extension didn't have. 179 // permissions the extension didn't have.
148 std::unique_ptr<const PermissionSet> successfully_removed = 180 std::unique_ptr<const PermissionSet> successfully_removed =
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (profile->IsSameProfile( 317 if (profile->IsSameProfile(
286 Profile::FromBrowserContext(host->GetBrowserContext()))) { 318 Profile::FromBrowserContext(host->GetBrowserContext()))) {
287 host->Send(new ExtensionMsg_UpdatePermissions(params)); 319 host->Send(new ExtensionMsg_UpdatePermissions(params));
288 } 320 }
289 } 321 }
290 322
291 // Trigger the onAdded and onRemoved events in the extension. 323 // Trigger the onAdded and onRemoved events in the extension.
292 DispatchEvent(extension->id(), histogram_value, event_name, changed); 324 DispatchEvent(extension->id(), histogram_value, event_name, changed);
293 } 325 }
294 326
327 // Notify the renderers that extension policy (runtime_blocked_hosts) is updated
328 // and provide new set of hosts.
329 void PermissionsUpdater::NotifyRuntimeBlockedAllowedHostsUpdated(
330 const Extension* extension,
331 const URLPatternSet& runtime_blocked_hosts,
332 const URLPatternSet& runtime_allowed_hosts,
333 bool is_default) {
334 DCHECK((init_flag_ & INIT_FLAG_TRANSIENT) == 0);
335
336 Profile* profile = Profile::FromBrowserContext(browser_context_);
337
338 // Send the new policy to the renderers.
339 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
340 !i.IsAtEnd(); i.Advance()) {
341 RenderProcessHost* host = i.GetCurrentValue();
342 if (profile->IsSameProfile(
343 Profile::FromBrowserContext(host->GetBrowserContext()))) {
344 ExtensionMsg_UpdateAllowedAndBlockedHosts_Params params;
345 params.extension_id = extension->id();
346 ExtensionMsg_RuntimeBlockedAllowedHostsStruct hosts(
347 runtime_blocked_hosts, runtime_allowed_hosts, host->GetHandle());
348 params.hosts = hosts;
349 params.is_default = is_default;
350 host->Send(new ExtensionMsg_UpdateAllowedAndBlockedHosts(params));
351 }
352 }
353 }
354
355 // Notify the renderers that extension policy (runtime_blocked_hosts) is updated
356 // and provide new set of hosts.
357 void PermissionsUpdater::NotifyDefaultRuntimeBlockedAllowedHostsUpdated(
358 const URLPatternSet& default_runtime_blocked_hosts,
359 const URLPatternSet& default_runtime_allowed_hosts) {
360 DCHECK((init_flag_ & INIT_FLAG_TRANSIENT) == 0);
361
362 Profile* profile = Profile::FromBrowserContext(browser_context_);
363
364 // Send the new policy to the renderers.
365 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.
366 !i.IsAtEnd(); i.Advance()) {
367 RenderProcessHost* host = i.GetCurrentValue();
368 if (profile->IsSameProfile(
369 Profile::FromBrowserContext(host->GetBrowserContext()))) {
370 ExtensionMsg_RuntimeBlockedAllowedHostsStruct params(
371 default_runtime_blocked_hosts, default_runtime_allowed_hosts,
372 host->GetHandle());
373
374 host->Send(new ExtensionMsg_UpdateDefaultAllowedAndBlockedHosts(params));
375 }
376 }
377 }
378
295 } // namespace extensions 379 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698