Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Side by Side Diff: chrome/browser/extensions/permissions_updater.h

Issue 501273002: Update extension install prompt to reflect withheld permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Permissions helper method, init flag changes in updater Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 11
12 namespace base { 12 namespace base {
13 class DictionaryValue; 13 class DictionaryValue;
14 } 14 }
15 15
16 namespace content { 16 namespace content {
17 class BrowserContext; 17 class BrowserContext;
18 } 18 }
19 19
20 namespace extensions { 20 namespace extensions {
21 21
22 class Extension; 22 class Extension;
23 class ExtensionPrefs; 23 class ExtensionPrefs;
24 class PermissionSet; 24 class PermissionSet;
25 25
26 // Updates an Extension's active and granted permissions in persistent storage 26 // Updates an Extension's active and granted permissions in persistent storage
27 // and notifies interested parties of the changes. 27 // and notifies interested parties of the changes.
28 class PermissionsUpdater { 28 class PermissionsUpdater {
29 public: 29 public:
30 enum InitFlag {
31 INIT_FLAG_NONE = 0,
32 INIT_FLAG_TRANSIENT = 1 << 0,
33 };
34
30 explicit PermissionsUpdater(content::BrowserContext* browser_context); 35 explicit PermissionsUpdater(content::BrowserContext* browser_context);
31 ~PermissionsUpdater(); 36 ~PermissionsUpdater();
32 37
33 // Adds the set of |permissions| to the |extension|'s active permission set 38 // Adds the set of |permissions| to the |extension|'s active permission set
34 // and sends the relevant messages and notifications. This method assumes the 39 // and sends the relevant messages and notifications. This method assumes the
35 // user has already been prompted, if necessary, for the extra permissions. 40 // user has already been prompted, if necessary, for the extra permissions.
36 void AddPermissions(const Extension* extension, 41 void AddPermissions(const Extension* extension,
37 const PermissionSet* permissions); 42 const PermissionSet* permissions);
38 43
39 // Removes the set of |permissions| from the |extension|'s active permission 44 // Removes the set of |permissions| from the |extension|'s active permission
40 // set and sends the relevant messages and notifications. 45 // set and sends the relevant messages and notifications.
41 void RemovePermissions(const Extension* extension, 46 void RemovePermissions(const Extension* extension,
42 const PermissionSet* permissions); 47 const PermissionSet* permissions);
43 48
44 // Adds all permissions in the |extension|'s active permissions to its 49 // Adds all permissions in the |extension|'s active permissions to its
45 // granted permission set. 50 // granted permission set.
46 void GrantActivePermissions(const Extension* extension); 51 void GrantActivePermissions(const Extension* extension);
47 52
48 // Initializes the |extension|'s active permission set to include only 53 // Initializes the |extension|'s active permission set to include only
49 // permissions currently requested by the extension and all the permissions 54 // permissions currently requested by the extension and all the permissions
50 // required by the extension. 55 // required by the extension.
51 void InitializePermissions(const Extension* extension); 56 void InitializePermissions(const Extension* extension);
57 void InitializePermissions(const Extension* extension, InitFlag init_flag);
52 58
53 // Grants any withheld all-hosts (or all-hosts-like) permissions. 59 // Grants any withheld all-hosts (or all-hosts-like) permissions.
54 void GrantWithheldImpliedAllHosts(const Extension* extension); 60 void GrantWithheldImpliedAllHosts(const Extension* extension);
55 61
56 // Revokes any requests all-hosts (or all-hosts-like) permissions. 62 // Revokes any requests all-hosts (or all-hosts-like) permissions.
57 void WithholdImpliedAllHosts(const Extension* extension); 63 void WithholdImpliedAllHosts(const Extension* extension);
58 64
59 private: 65 private:
60 enum EventType { 66 enum EventType {
61 ADDED, 67 ADDED,
62 REMOVED, 68 REMOVED,
63 }; 69 };
64 70
65 // Sets the |extension|'s active permissions to |active| and records the 71 // Sets the |extension|'s active permissions to |active| and records the
66 // change in the prefs. If |withheld| is non-null, also sets the extension's 72 // change in the prefs. If |withheld| is non-null, also sets the extension's
67 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are 73 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are
68 // not changed. 74 // not changed.
69 void SetPermissions(const Extension* extension, 75 void SetPermissions(const Extension* extension,
70 const scoped_refptr<const PermissionSet>& active, 76 const scoped_refptr<const PermissionSet>& active,
71 scoped_refptr<const PermissionSet> withheld); 77 scoped_refptr<const PermissionSet> withheld);
72 78
79 void SetPermissionsWithoutPrefs(
80 const Extension* extension,
81 const scoped_refptr<const PermissionSet>& active,
82 scoped_refptr<const PermissionSet> withheld);
83
73 // Dispatches specified event to the extension. 84 // Dispatches specified event to the extension.
74 void DispatchEvent(const std::string& extension_id, 85 void DispatchEvent(const std::string& extension_id,
75 const char* event_name, 86 const char* event_name,
76 const PermissionSet* changed_permissions); 87 const PermissionSet* changed_permissions);
77 88
78 // Issues the relevant events, messages and notifications when the 89 // Issues the relevant events, messages and notifications when the
79 // |extension|'s permissions have |changed| (|changed| is the delta). 90 // |extension|'s permissions have |changed| (|changed| is the delta).
80 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification, 91 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification,
81 // the ExtensionMsg_UpdatePermissions IPC message, and fires the 92 // the ExtensionMsg_UpdatePermissions IPC message, and fires the
82 // onAdded/onRemoved events in the extension. 93 // onAdded/onRemoved events in the extension.
83 void NotifyPermissionsUpdated(EventType event_type, 94 void NotifyPermissionsUpdated(EventType event_type,
84 const Extension* extension, 95 const Extension* extension,
85 const PermissionSet* changed); 96 const PermissionSet* changed);
86 97
87 // The associated BrowserContext. 98 // The associated BrowserContext.
88 content::BrowserContext* browser_context_; 99 content::BrowserContext* browser_context_;
100
101 InitFlag init_flag_;
89 }; 102 };
90 103
91 } // namespace extensions 104 } // namespace extensions
92 105
93 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ 106 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698