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,
36 explicit PermissionsUpdater(content::BrowserContext
* browser_context
);
37 PermissionsUpdater(content::BrowserContext
* browser_context
,
39 ~PermissionsUpdater();
41 // Adds the set of |permissions| to the |extension|'s active permission set
42 // and sends the relevant messages and notifications. This method assumes the
43 // user has already been prompted, if necessary, for the extra permissions.
44 void AddPermissions(const Extension
* extension
,
45 const PermissionSet
* permissions
);
47 // Removes the set of |permissions| from the |extension|'s active permission
48 // set and sends the relevant messages and notifications.
49 void RemovePermissions(const Extension
* extension
,
50 const PermissionSet
* permissions
);
52 // Adds all permissions in the |extension|'s active permissions to its
53 // granted permission set.
54 void GrantActivePermissions(const Extension
* extension
);
56 // Initializes the |extension|'s active permission set to include only
57 // permissions currently requested by the extension and all the permissions
58 // required by the extension.
59 void InitializePermissions(const Extension
* extension
);
61 // Grants any withheld all-hosts (or all-hosts-like) permissions.
62 void GrantWithheldImpliedAllHosts(const Extension
* extension
);
64 // Revokes any requests all-hosts (or all-hosts-like) permissions.
65 void WithholdImpliedAllHosts(const Extension
* extension
);
73 // Sets the |extension|'s active permissions to |active| and records the
74 // change in the prefs. If |withheld| is non-null, also sets the extension's
75 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are
77 void SetPermissions(const Extension
* extension
,
78 const scoped_refptr
<const PermissionSet
>& active
,
79 scoped_refptr
<const PermissionSet
> withheld
);
81 // Dispatches specified event to the extension.
82 void DispatchEvent(const std::string
& extension_id
,
83 events::HistogramValue histogram_value
,
84 const char* event_name
,
85 const PermissionSet
* changed_permissions
);
87 // Issues the relevant events, messages and notifications when the
88 // |extension|'s permissions have |changed| (|changed| is the delta).
89 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification,
90 // the ExtensionMsg_UpdatePermissions IPC message, and fires the
91 // onAdded/onRemoved events in the extension.
92 void NotifyPermissionsUpdated(EventType event_type
,
93 const Extension
* extension
,
94 const PermissionSet
* changed
);
96 // The associated BrowserContext.
97 content::BrowserContext
* browser_context_
;
99 // Initialization flag that determines whether prefs is consulted about the
100 // extension. Transient extensions should not have entries in prefs.
104 } // namespace extensions
106 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__