| Index: chrome/browser/extensions/permissions_updater.cc
|
| diff --git a/chrome/browser/extensions/permissions_updater.cc b/chrome/browser/extensions/permissions_updater.cc
|
| index 814c5b387f01cb1c911433ea36eec4c55a35b7f7..04311faf2f3a0ad19f84c2c53fefb0726bd06cba 100644
|
| --- a/chrome/browser/extensions/permissions_updater.cc
|
| +++ b/chrome/browser/extensions/permissions_updater.cc
|
| @@ -19,6 +19,8 @@
|
| #include "extensions/browser/extension_prefs.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/extension_messages.h"
|
| +#include "extensions/common/manifest_handlers/permissions_parser.h"
|
| +#include "extensions/common/permissions/permission_set.h"
|
| #include "extensions/common/permissions/permissions_data.h"
|
|
|
| using content::RenderProcessHost;
|
| @@ -28,8 +30,9 @@ namespace extensions {
|
|
|
| namespace permissions = api::permissions;
|
|
|
| -PermissionsUpdater::PermissionsUpdater(Profile* profile)
|
| - : profile_(profile) {}
|
| +PermissionsUpdater::PermissionsUpdater(content::BrowserContext* browser_context)
|
| + : browser_context_(browser_context) {
|
| +}
|
|
|
| PermissionsUpdater::~PermissionsUpdater() {}
|
|
|
| @@ -42,7 +45,7 @@ void PermissionsUpdater::AddPermissions(
|
| scoped_refptr<PermissionSet> added(
|
| PermissionSet::CreateDifference(total.get(), existing.get()));
|
|
|
| - UpdateActivePermissions(extension, total.get());
|
| + SetActivePermissions(extension, total.get());
|
|
|
| // Update the granted permissions so we don't auto-disable the extension.
|
| GrantActivePermissions(extension);
|
| @@ -62,7 +65,7 @@ void PermissionsUpdater::RemovePermissions(
|
| // We update the active permissions, and not the granted permissions, because
|
| // the extension, not the user, removed the permissions. This allows the
|
| // extension to add them again without prompting the user.
|
| - UpdateActivePermissions(extension, total.get());
|
| + SetActivePermissions(extension, total.get());
|
|
|
| NotifyPermissionsUpdated(REMOVED, extension, removed.get());
|
| }
|
| @@ -76,14 +79,44 @@ void PermissionsUpdater::GrantActivePermissions(const Extension* extension) {
|
| extension->location() != Manifest::INTERNAL)
|
| return;
|
|
|
| - ExtensionPrefs::Get(profile_)->AddGrantedPermissions(
|
| + ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions(
|
| extension->id(),
|
| extension->permissions_data()->active_permissions().get());
|
| }
|
|
|
| -void PermissionsUpdater::UpdateActivePermissions(
|
| +void PermissionsUpdater::UpdateActivePermissions(const Extension* extension) {
|
| + // If the extension has used the optional permissions API, it will have a
|
| + // custom set of active permissions defined in the extension prefs. Here,
|
| + // we update the extension's active permissions based on the prefs.
|
| + scoped_refptr<PermissionSet> active_permissions =
|
| + ExtensionPrefs::Get(browser_context_)->GetActivePermissions(
|
| + extension->id());
|
| + if (!active_permissions)
|
| + return;
|
| +
|
| + // We restrict the active permissions to be within the bounds defined in the
|
| + // extension's manifest.
|
| + // a) active permissions must be a subset of optional + default permissions
|
| + // b) active permissions must contains all default permissions
|
| + scoped_refptr<PermissionSet> total_permissions = PermissionSet::CreateUnion(
|
| + PermissionsParser::GetRequiredPermissions(extension),
|
| + PermissionsParser::GetOptionalPermissions(extension));
|
| +
|
| + // Make sure the active permissions contain no more than optional + default.
|
| + scoped_refptr<PermissionSet> adjusted_active =
|
| + PermissionSet::CreateIntersection(total_permissions, active_permissions);
|
| +
|
| + // Make sure the active permissions contain the default permissions.
|
| + adjusted_active = PermissionSet::CreateUnion(
|
| + PermissionsParser::GetRequiredPermissions(extension),
|
| + adjusted_active);
|
| +
|
| + SetActivePermissions(extension, adjusted_active);
|
| +}
|
| +
|
| +void PermissionsUpdater::SetActivePermissions(
|
| const Extension* extension, const PermissionSet* permissions) {
|
| - ExtensionPrefs::Get(profile_)->SetActivePermissions(
|
| + ExtensionPrefs::Get(browser_context_)->SetActivePermissions(
|
| extension->id(), permissions);
|
| extension->permissions_data()->SetActivePermissions(permissions);
|
| }
|
| @@ -92,7 +125,8 @@ void PermissionsUpdater::DispatchEvent(
|
| const std::string& extension_id,
|
| const char* event_name,
|
| const PermissionSet* changed_permissions) {
|
| - if (!profile_ || !EventRouter::Get(profile_))
|
| + EventRouter* event_router = EventRouter::Get(browser_context_);
|
| + if (!event_router)
|
| return;
|
|
|
| scoped_ptr<base::ListValue> value(new base::ListValue());
|
| @@ -100,9 +134,8 @@ void PermissionsUpdater::DispatchEvent(
|
| PackPermissionSet(changed_permissions);
|
| value->Append(permissions->ToValue().release());
|
| scoped_ptr<Event> event(new Event(event_name, value.Pass()));
|
| - event->restrict_to_browser_context = profile_;
|
| - EventRouter::Get(profile_)
|
| - ->DispatchEventToExtension(extension_id, event.Pass());
|
| + event->restrict_to_browser_context = browser_context_;
|
| + event_router->DispatchEventToExtension(extension_id, event.Pass());
|
| }
|
|
|
| void PermissionsUpdater::NotifyPermissionsUpdated(
|
| @@ -127,25 +160,27 @@ void PermissionsUpdater::NotifyPermissionsUpdated(
|
| // Notify other APIs or interested parties.
|
| UpdatedExtensionPermissionsInfo info = UpdatedExtensionPermissionsInfo(
|
| extension, changed, reason);
|
| + Profile* profile = Profile::FromBrowserContext(browser_context_);
|
| content::NotificationService::current()->Notify(
|
| chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED,
|
| - content::Source<Profile>(profile_),
|
| + content::Source<Profile>(profile),
|
| content::Details<UpdatedExtensionPermissionsInfo>(&info));
|
|
|
| + ExtensionMsg_UpdatePermissions_Params params;
|
| + params.reason_id = static_cast<int>(reason);
|
| + params.extension_id = extension->id();
|
| + params.apis = changed->apis();
|
| + params.manifest_permissions = changed->manifest_permissions();
|
| + params.explicit_hosts = changed->explicit_hosts();
|
| + params.scriptable_hosts = changed->scriptable_hosts();
|
| +
|
| // Send the new permissions to the renderers.
|
| for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
|
| !i.IsAtEnd(); i.Advance()) {
|
| RenderProcessHost* host = i.GetCurrentValue();
|
| - Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
|
| - if (profile_->IsSameProfile(profile)) {
|
| - ExtensionMsg_UpdatePermissions_Params info;
|
| - info.reason_id = static_cast<int>(reason);
|
| - info.extension_id = extension->id();
|
| - info.apis = changed->apis();
|
| - info.manifest_permissions = changed->manifest_permissions();
|
| - info.explicit_hosts = changed->explicit_hosts();
|
| - info.scriptable_hosts = changed->scriptable_hosts();
|
| - host->Send(new ExtensionMsg_UpdatePermissions(info));
|
| + if (profile->IsSameProfile(
|
| + Profile::FromBrowserContext(host->GetBrowserContext()))) {
|
| + host->Send(new ExtensionMsg_UpdatePermissions(params));
|
| }
|
| }
|
|
|
|
|