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

Unified 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: . 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_permissions_api.h
diff --git a/chrome/browser/extensions/extension_permissions_api.h b/chrome/browser/extensions/extension_permissions_api.h
new file mode 100644
index 0000000000000000000000000000000000000000..3eb60e57bf7a1d8d9c5358d92ffc0d2335538d0d
--- /dev/null
+++ b/chrome/browser/extensions/extension_permissions_api.h
@@ -0,0 +1,116 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PERMISSIONS_API_H__
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PERMISSIONS_API_H__
+#pragma once
+
+#include "chrome/browser/extensions/extension_function.h"
+#include "chrome/browser/extensions/extension_install_ui.h"
+#include "chrome/common/extensions/extension_permission_set.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/browser/renderer_host/render_process_host.h"
+#include "content/common/notification_service.h"
+
+namespace base {
+class DictionaryValue;
+}
+class Extension;
+class ExtensionPermissionSet;
+class ExtensionService;
+class Profile;
+
+class ExtensionPermissionsManager {
+ public:
+ explicit ExtensionPermissionsManager(ExtensionService* extension_service);
+ ~ExtensionPermissionsManager();
+
+ // Adds the set of |permissions| to the |extension|'s active permission set
+ // 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.
+ void AddPermissions(const Extension* extension,
+ const ExtensionPermissionSet* permissions);
+
+ // Removes the set of |permissions| from the |extension|'s active permission
+ // set and sends the relevant messages and notifications.
+ void RemovePermissions(const Extension* extension,
+ const ExtensionPermissionSet* permissions);
+
+ // Returns the list of API permissions that are supported by the optional
+ // permissions API.
+ 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.
+
+ private:
+ enum EventType {
+ ADDED,
+ REMOVED,
+ };
+
+ // Dispatches specified event to the extension.
+ void DispatchEvent(const std::string& extension_id,
+ const char* event_name,
+ const ExtensionPermissionSet* permissions);
+
+ // Issues the relevant events, messages and notifications when the permissions
+ // have changed for the |extension| (|changed| is the permission delta, while
+ // |active| is the new permission set). Specifically, this sends the
+ // EXTENSION_PERMISSIONS_UPDATED notification, the
+ // ExtensionMsg_UpdatePermissions IPC message, and fires the onAdded/onRemoved
+ // events in the extension.
+ void NotifyPermissionsUpdated(const Extension* extension,
+ const ExtensionPermissionSet* active,
+ const ExtensionPermissionSet* changed,
+ EventType event_type);
+
+ // Registers the list of APIs supported by the optional permissions API.
+ void RegisterWhiteList();
+
+ ExtensionService* extension_service_;
+ scoped_ptr<ExtensionPermissionSet> white_list_;
+};
+
+
+// chrome.permissions.contains
+class ContainsPermissionsFunction : public SyncExtensionFunction {
+ virtual ~ContainsPermissionsFunction() {}
+ 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.
+ DECLARE_EXTENSION_FUNCTION_NAME("permissions.contains")
+};
+
+// chrome.permissions.getAll
+class GetAllPermissionsFunction : public SyncExtensionFunction {
+ virtual ~GetAllPermissionsFunction() {}
+ virtual bool RunImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("permissions.getAll")
+};
+
+// chrome.permissions.remove
+class RemovePermissionsFunction : public SyncExtensionFunction {
+ virtual ~RemovePermissionsFunction() {}
+ virtual bool RunImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("permissions.remove")
+};
+
+// chrome.permissions.request
+class RequestPermissionsFunction : public AsyncExtensionFunction,
+ public ExtensionInstallUI::Delegate {
+ public:
+ // 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.
+ static void SetAutoConfirmForTests(bool should_proceed);
+
+ // Implementing ExtensionInstallUI::Delegate interface.
+ virtual void InstallUIProceed() OVERRIDE;
+ virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
+
+ protected:
+ virtual ~RequestPermissionsFunction() {}
+ virtual bool RunImpl();
+
+ private:
+ scoped_ptr<ExtensionInstallUI> install_ui_;
+ scoped_ptr<ExtensionPermissionSet> requested_permissions_;
+ const Extension* extension_;
+ DECLARE_EXTENSION_FUNCTION_NAME("permissions.request")
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PERMISSIONS_API_H__

Powered by Google App Engine
This is Rietveld 408576698