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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__
6 #define CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__
10 #include "base/memory/ref_counted.h"
11 #include "extensions/browser/extension_event_histogram_value.h"
14 class DictionaryValue
;
21 namespace extensions
{
27 // Updates an Extension's active and granted permissions in persistent storage
28 // and notifies interested parties of the changes.
29 class PermissionsUpdater
{
33 INIT_FLAG_TRANSIENT
= 1 << 0,
41 explicit PermissionsUpdater(content::BrowserContext
* browser_context
);
42 PermissionsUpdater(content::BrowserContext
* browser_context
,
44 ~PermissionsUpdater();
46 // Adds the set of |permissions| to the |extension|'s active permission set
47 // and sends the relevant messages and notifications. This method assumes the
48 // user has already been prompted, if necessary, for the extra permissions.
49 void AddPermissions(const Extension
* extension
,
50 const PermissionSet
* permissions
);
52 // Removes the set of |permissions| from the |extension|'s active permission
53 // set and sends the relevant messages and notifications.
54 // If |remove_type| is REMOVE_HARD, this removes the permissions from the
55 // granted permissions in the prefs (meaning that the extension would have
56 // to prompt the user again for permission).
57 // You should use REMOVE_HARD to ensure the extension cannot silently regain
58 // the permission, which is the case when the permission is removed by the
59 // user. If it's the extension itself removing the permission, it is safe to
61 void RemovePermissions(const Extension
* extension
,
62 const PermissionSet
* permissions
,
63 RemoveType remove_type
);
65 // Removes the |permissions| from |extension| and makes no effort to determine
66 // if doing so is safe in the slightlest. This method shouldn't be used,
67 // except for removing permissions totally blacklisted by management.
68 void RemovePermissionsUnsafe(const Extension
* extension
,
69 const PermissionSet
* permissions
);
71 // Returns the set of revokable permissions.
72 scoped_refptr
<const PermissionSet
> GetRevokablePermissions(
73 const Extension
* extension
) const;
75 // Adds all permissions in the |extension|'s active permissions to its
76 // granted permission set.
77 void GrantActivePermissions(const Extension
* extension
);
79 // Initializes the |extension|'s active permission set to include only
80 // permissions currently requested by the extension and all the permissions
81 // required by the extension.
82 void InitializePermissions(const Extension
* extension
);
84 // Grants any withheld all-hosts (or all-hosts-like) permissions.
85 void GrantWithheldImpliedAllHosts(const Extension
* extension
);
87 // Revokes any requests all-hosts (or all-hosts-like) permissions.
88 void WithholdImpliedAllHosts(const Extension
* extension
);
96 // Sets the |extension|'s active permissions to |active| and records the
97 // change in the prefs. If |withheld| is non-null, also sets the extension's
98 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are
100 void SetPermissions(const Extension
* extension
,
101 const scoped_refptr
<const PermissionSet
>& active
,
102 scoped_refptr
<const PermissionSet
> withheld
);
104 // Dispatches specified event to the extension.
105 void DispatchEvent(const std::string
& extension_id
,
106 events::HistogramValue histogram_value
,
107 const char* event_name
,
108 const PermissionSet
* changed_permissions
);
110 // Issues the relevant events, messages and notifications when the
111 // |extension|'s permissions have |changed| (|changed| is the delta).
112 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification,
113 // the ExtensionMsg_UpdatePermissions IPC message, and fires the
114 // onAdded/onRemoved events in the extension.
115 void NotifyPermissionsUpdated(EventType event_type
,
116 const Extension
* extension
,
117 const PermissionSet
* changed
);
119 // The associated BrowserContext.
120 content::BrowserContext
* browser_context_
;
122 // Initialization flag that determines whether prefs is consulted about the
123 // extension. Transient extensions should not have entries in prefs.
127 } // namespace extensions
129 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__