Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / permissions_updater.h
blobbbd7200a77301270d9e4f18aef8f0b105913e61b
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__
8 #include <string>
10 #include "base/memory/ref_counted.h"
12 class Profile;
14 namespace base {
15 class DictionaryValue;
18 namespace extensions {
20 class Extension;
21 class ExtensionPrefs;
22 class PermissionSet;
24 // Updates an Extension's active and granted permissions in persistent storage
25 // and notifies interested parties of the changes.
26 class PermissionsUpdater {
27 public:
28 explicit PermissionsUpdater(Profile* profile);
29 ~PermissionsUpdater();
31 // Adds the set of |permissions| to the |extension|'s active permission set
32 // and sends the relevant messages and notifications. This method assumes the
33 // user has already been prompted, if necessary, for the extra permissions.
34 void AddPermissions(const Extension* extension,
35 const PermissionSet* permissions);
37 // Removes the set of |permissions| from the |extension|'s active permission
38 // set and sends the relevant messages and notifications.
39 void RemovePermissions(const Extension* extension,
40 const PermissionSet* permissions);
42 // Adds all permissions in the |extension|'s active permissions to its
43 // granted permission set.
44 void GrantActivePermissions(const Extension* extension);
46 // Sets the |extension|'s active permissions to |permissions|.
47 void UpdateActivePermissions(const Extension* extension,
48 const PermissionSet* permissions);
50 private:
51 enum EventType {
52 ADDED,
53 REMOVED,
56 // Dispatches specified event to the extension.
57 void DispatchEvent(const std::string& extension_id,
58 const char* event_name,
59 const PermissionSet* changed_permissions);
61 // Issues the relevant events, messages and notifications when the
62 // |extension|'s permissions have |changed| (|changed| is the delta).
63 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification,
64 // the ExtensionMsg_UpdatePermissions IPC message, and fires the
65 // onAdded/onRemoved events in the extension.
66 void NotifyPermissionsUpdated(EventType event_type,
67 const Extension* extension,
68 const PermissionSet* changed);
70 // Gets the ExtensionPrefs for the associated profile.
71 ExtensionPrefs* GetExtensionPrefs();
73 Profile* profile_;
76 } // namespace extensions
78 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__