- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / permissions_updater.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__
6 #define CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11
12 class Profile;
13
14 namespace base {
15 class DictionaryValue;
16 }
17
18 namespace extensions {
19
20 class Extension;
21 class ExtensionPrefs;
22 class PermissionSet;
23
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();
30
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);
36
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);
41
42   // Adds all permissions in the |extension|'s active permissions to its
43   // granted permission set.
44   void GrantActivePermissions(const Extension* extension);
45
46   // Sets the |extension|'s active permissions to |permissions|.
47   void UpdateActivePermissions(const Extension* extension,
48                                const PermissionSet* permissions);
49
50  private:
51   enum EventType {
52     ADDED,
53     REMOVED,
54   };
55
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);
60
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);
69
70   // Gets the ExtensionPrefs for the associated profile.
71   ExtensionPrefs* GetExtensionPrefs();
72
73   Profile* profile_;
74 };
75
76 }  // namespace extensions
77
78 #endif  // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__