OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 | 12 |
13 class ExtensionPermissionSet; | |
14 class ExtensionPrefs; | 13 class ExtensionPrefs; |
15 class Profile; | 14 class Profile; |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class DictionaryValue; | 17 class DictionaryValue; |
19 } | 18 } |
20 | 19 |
21 namespace extensions { | 20 namespace extensions { |
22 | 21 |
23 class Extension; | 22 class Extension; |
| 23 class PermissionSet; |
24 | 24 |
25 // Updates an Extension's active and granted permissions in persistent storage | 25 // Updates an Extension's active and granted permissions in persistent storage |
26 // and notifies interested parties of the changes. | 26 // and notifies interested parties of the changes. |
27 class PermissionsUpdater { | 27 class PermissionsUpdater { |
28 public: | 28 public: |
29 explicit PermissionsUpdater(Profile* profile); | 29 explicit PermissionsUpdater(Profile* profile); |
30 ~PermissionsUpdater(); | 30 ~PermissionsUpdater(); |
31 | 31 |
32 // Adds the set of |permissions| to the |extension|'s active permission set | 32 // Adds the set of |permissions| to the |extension|'s active permission set |
33 // and sends the relevant messages and notifications. This method assumes the | 33 // and sends the relevant messages and notifications. This method assumes the |
34 // user has already been prompted, if necessary, for the extra permissions. | 34 // user has already been prompted, if necessary, for the extra permissions. |
35 void AddPermissions(const Extension* extension, | 35 void AddPermissions(const Extension* extension, |
36 const ExtensionPermissionSet* permissions); | 36 const PermissionSet* permissions); |
37 | 37 |
38 // Removes the set of |permissions| from the |extension|'s active permission | 38 // Removes the set of |permissions| from the |extension|'s active permission |
39 // set and sends the relevant messages and notifications. | 39 // set and sends the relevant messages and notifications. |
40 void RemovePermissions(const Extension* extension, | 40 void RemovePermissions(const Extension* extension, |
41 const ExtensionPermissionSet* permissions); | 41 const PermissionSet* permissions); |
42 | 42 |
43 // Adds all permissions in the |extension|'s active permissions to its | 43 // Adds all permissions in the |extension|'s active permissions to its |
44 // granted permission set. | 44 // granted permission set. |
45 void GrantActivePermissions(const Extension* extension); | 45 void GrantActivePermissions(const Extension* extension); |
46 | 46 |
47 // Sets the |extension|'s active permissions to |permissions|. | 47 // Sets the |extension|'s active permissions to |permissions|. |
48 void UpdateActivePermissions(const Extension* extension, | 48 void UpdateActivePermissions(const Extension* extension, |
49 const ExtensionPermissionSet* permissions); | 49 const PermissionSet* permissions); |
50 | 50 |
51 private: | 51 private: |
52 enum EventType { | 52 enum EventType { |
53 ADDED, | 53 ADDED, |
54 REMOVED, | 54 REMOVED, |
55 }; | 55 }; |
56 | 56 |
57 // Dispatches specified event to the extension. | 57 // Dispatches specified event to the extension. |
58 void DispatchEvent(const std::string& extension_id, | 58 void DispatchEvent(const std::string& extension_id, |
59 const char* event_name, | 59 const char* event_name, |
60 const ExtensionPermissionSet* changed_permissions); | 60 const PermissionSet* changed_permissions); |
61 | 61 |
62 // Issues the relevant events, messages and notifications when the | 62 // Issues the relevant events, messages and notifications when the |
63 // |extension|'s permissions have |changed| (|changed| is the delta). | 63 // |extension|'s permissions have |changed| (|changed| is the delta). |
64 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification, | 64 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification, |
65 // the ExtensionMsg_UpdatePermissions IPC message, and fires the | 65 // the ExtensionMsg_UpdatePermissions IPC message, and fires the |
66 // onAdded/onRemoved events in the extension. | 66 // onAdded/onRemoved events in the extension. |
67 void NotifyPermissionsUpdated(EventType event_type, | 67 void NotifyPermissionsUpdated(EventType event_type, |
68 const Extension* extension, | 68 const Extension* extension, |
69 const ExtensionPermissionSet* changed); | 69 const PermissionSet* changed); |
70 | 70 |
71 // Gets the ExtensionPrefs for the associated profile. | 71 // Gets the ExtensionPrefs for the associated profile. |
72 ExtensionPrefs* GetExtensionPrefs(); | 72 ExtensionPrefs* GetExtensionPrefs(); |
73 | 73 |
74 Profile* profile_; | 74 Profile* profile_; |
75 }; | 75 }; |
76 | 76 |
77 } // namespace extensions | 77 } // namespace extensions |
78 | 78 |
79 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ | 79 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ |
OLD | NEW |