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

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

Issue 7432006: Add an experimental permissions API for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_EXTENSION_PERMISSIONS_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PERMISSIONS_API_H__
7 #pragma once
8
9 #include "chrome/browser/extensions/extension_function.h"
10 #include "chrome/browser/extensions/extension_install_ui.h"
11 #include "chrome/common/extensions/extension_permission_set.h"
12 #include "chrome/common/chrome_notification_types.h"
13 #include "content/browser/renderer_host/render_process_host.h"
14 #include "content/common/notification_service.h"
15
16 namespace base {
17 class DictionaryValue;
18 }
19 class Extension;
20 class ExtensionPermissionSet;
21 class ExtensionService;
22 class Profile;
23
24 class ExtensionPermissionsManager {
25 public:
26 explicit ExtensionPermissionsManager(ExtensionService* extension_service);
27 ~ExtensionPermissionsManager();
28
29 // Adds the set of |permissions| to the |extension|'s active permission set
30 // and sends the relevant messages and notifications. This method assumes the
31 // user has already been prompted, if necessary, for the extra permissions.
32 void AddPermissions(const Extension* extension,
33 const ExtensionPermissionSet* permissions);
34
35 // Removes the set of |permissions| from the |extension|'s active permission
36 // set and sends the relevant messages and notifications.
37 void RemovePermissions(const Extension* extension,
38 const ExtensionPermissionSet* permissions);
39
40 // Returns the list of API permissions that are supported by the optional
41 // permissions API.
42 const ExtensionPermissionSet& whitelist() const { return *whitelist_; }
43
44 private:
45 enum EventType {
46 ADDED,
47 REMOVED,
48 };
49
50 // Dispatches specified event to the extension.
51 void DispatchEvent(const std::string& extension_id,
52 const char* event_name,
53 const ExtensionPermissionSet* changed_permissions);
54
55 // Issues the relevant events, messages and notifications when the permissions
56 // have changed for the |extension| (|changed| is the permission delta, while
57 // |active| is the new permission set). Specifically, this sends the
58 // EXTENSION_PERMISSIONS_UPDATED notification, the
59 // ExtensionMsg_UpdatePermissions IPC message, and fires the onAdded/onRemoved
60 // events in the extension.
61 void NotifyPermissionsUpdated(const Extension* extension,
62 const ExtensionPermissionSet* active,
63 const ExtensionPermissionSet* changed,
64 EventType event_type);
65
66 // Registers the list of APIs supported by the optional permissions API.
67 void RegisterWhitelist();
68
69 ExtensionService* extension_service_;
70 scoped_refptr<ExtensionPermissionSet> whitelist_;
71 };
72
73
74 // chrome.permissions.contains
75 class ContainsPermissionsFunction : public SyncExtensionFunction {
76 virtual ~ContainsPermissionsFunction() {}
77 virtual bool RunImpl() OVERRIDE;
78 DECLARE_EXTENSION_FUNCTION_NAME("experimental.permissions.contains")
79 };
80
81 // chrome.permissions.getAll
82 class GetAllPermissionsFunction : public SyncExtensionFunction {
83 virtual ~GetAllPermissionsFunction() {}
84 virtual bool RunImpl() OVERRIDE;
85 DECLARE_EXTENSION_FUNCTION_NAME("experimental.permissions.getAll")
86 };
87
88 // chrome.permissions.remove
89 class RemovePermissionsFunction : public SyncExtensionFunction {
90 virtual ~RemovePermissionsFunction() {}
91 virtual bool RunImpl() OVERRIDE;
92 DECLARE_EXTENSION_FUNCTION_NAME("experimental.permissions.remove")
93 };
94
95 // chrome.permissions.request
96 class RequestPermissionsFunction : public AsyncExtensionFunction,
97 public ExtensionInstallUI::Delegate {
98 public:
99 // FOR TESTS ONLY to bypass the confirmation UI.
100 static void SetAutoConfirmForTests(bool should_proceed);
101
102 RequestPermissionsFunction();
103
104 // Implementing ExtensionInstallUI::Delegate interface.
105 virtual void InstallUIProceed() OVERRIDE;
106 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
107
108 protected:
109 virtual ~RequestPermissionsFunction();
110 virtual bool RunImpl() OVERRIDE;
111
112 private:
113 scoped_ptr<ExtensionInstallUI> install_ui_;
114 scoped_refptr<ExtensionPermissionSet> requested_permissions_;
115 const Extension* extension_;
116 DECLARE_EXTENSION_FUNCTION_NAME("experimental.permissions.request")
117 };
118
119 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PERMISSIONS_API_H__
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_api.cc ('k') | chrome/browser/extensions/extension_permissions_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698