Chromium Code Reviews| OLD | NEW |
|---|---|
| (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. | |
|
Mihai Parparita -not on Chrome
2011/07/20 22:03:43
Add a comment that it's assumed the user has alrea
jstritar
2011/07/22 19:21:55
Done.
| |
| 31 void AddPermissions(const Extension* extension, | |
| 32 const ExtensionPermissionSet* permissions); | |
| 33 | |
| 34 // Removes the set of |permissions| from the |extension|'s active permission | |
| 35 // set and sends the relevant messages and notifications. | |
| 36 void RemovePermissions(const Extension* extension, | |
| 37 const ExtensionPermissionSet* permissions); | |
| 38 | |
| 39 // Returns the list of API permissions that are supported by the optional | |
| 40 // permissions API. | |
| 41 const ExtensionPermissionSet& white_list() const { return *white_list_; } | |
|
Mihai Parparita -not on Chrome
2011/07/20 22:03:43
"whitelist" (no dash/underscore) seems to be the p
jstritar
2011/07/22 19:21:55
Done.
| |
| 42 | |
| 43 private: | |
| 44 enum EventType { | |
| 45 ADDED, | |
| 46 REMOVED, | |
| 47 }; | |
| 48 | |
| 49 // Dispatches specified event to the extension. | |
| 50 void DispatchEvent(const std::string& extension_id, | |
| 51 const char* event_name, | |
| 52 const ExtensionPermissionSet* permissions); | |
| 53 | |
| 54 // Issues the relevant events, messages and notifications when the permissions | |
| 55 // have changed for the |extension| (|changed| is the permission delta, while | |
| 56 // |active| is the new permission set). Specifically, this sends the | |
| 57 // EXTENSION_PERMISSIONS_UPDATED notification, the | |
| 58 // ExtensionMsg_UpdatePermissions IPC message, and fires the onAdded/onRemoved | |
| 59 // events in the extension. | |
| 60 void NotifyPermissionsUpdated(const Extension* extension, | |
| 61 const ExtensionPermissionSet* active, | |
| 62 const ExtensionPermissionSet* changed, | |
| 63 EventType event_type); | |
| 64 | |
| 65 // Registers the list of APIs supported by the optional permissions API. | |
| 66 void RegisterWhiteList(); | |
| 67 | |
| 68 ExtensionService* extension_service_; | |
| 69 scoped_ptr<ExtensionPermissionSet> white_list_; | |
| 70 }; | |
| 71 | |
| 72 | |
| 73 // chrome.permissions.contains | |
| 74 class ContainsPermissionsFunction : public SyncExtensionFunction { | |
| 75 virtual ~ContainsPermissionsFunction() {} | |
| 76 virtual bool RunImpl(); | |
|
Mihai Parparita -not on Chrome
2011/07/20 22:03:43
Add OVERRIDE to all the RunImpls.
jstritar
2011/07/22 19:21:55
Done.
| |
| 77 DECLARE_EXTENSION_FUNCTION_NAME("permissions.contains") | |
| 78 }; | |
| 79 | |
| 80 // chrome.permissions.getAll | |
| 81 class GetAllPermissionsFunction : public SyncExtensionFunction { | |
| 82 virtual ~GetAllPermissionsFunction() {} | |
| 83 virtual bool RunImpl(); | |
| 84 DECLARE_EXTENSION_FUNCTION_NAME("permissions.getAll") | |
| 85 }; | |
| 86 | |
| 87 // chrome.permissions.remove | |
| 88 class RemovePermissionsFunction : public SyncExtensionFunction { | |
| 89 virtual ~RemovePermissionsFunction() {} | |
| 90 virtual bool RunImpl(); | |
| 91 DECLARE_EXTENSION_FUNCTION_NAME("permissions.remove") | |
| 92 }; | |
| 93 | |
| 94 // chrome.permissions.request | |
| 95 class RequestPermissionsFunction : public AsyncExtensionFunction, | |
| 96 public ExtensionInstallUI::Delegate { | |
| 97 public: | |
| 98 // FOR TESTS ONLY to by pass the confirmation UI. | |
|
Mihai Parparita -not on Chrome
2011/07/20 22:03:43
"bypass" is one word.
jstritar
2011/07/22 19:21:55
Done.
| |
| 99 static void SetAutoConfirmForTests(bool should_proceed); | |
| 100 | |
| 101 // Implementing ExtensionInstallUI::Delegate interface. | |
| 102 virtual void InstallUIProceed() OVERRIDE; | |
| 103 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | |
| 104 | |
| 105 protected: | |
| 106 virtual ~RequestPermissionsFunction() {} | |
| 107 virtual bool RunImpl(); | |
| 108 | |
| 109 private: | |
| 110 scoped_ptr<ExtensionInstallUI> install_ui_; | |
| 111 scoped_ptr<ExtensionPermissionSet> requested_permissions_; | |
| 112 const Extension* extension_; | |
| 113 DECLARE_EXTENSION_FUNCTION_NAME("permissions.request") | |
| 114 }; | |
| 115 | |
| 116 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PERMISSIONS_API_H__ | |
| OLD | NEW |