Chromium Code Reviews| Index: chrome/common/extensions/permissions/api_permission.cc |
| diff --git a/chrome/common/extensions/permissions/api_permission.cc b/chrome/common/extensions/permissions/api_permission.cc |
| index fd2cc180214220dfcf9738b5b6d1103535e0e223..33e2f2ae893f3a207309f90c486daf2b8812da27 100644 |
| --- a/chrome/common/extensions/permissions/api_permission.cc |
| +++ b/chrome/common/extensions/permissions/api_permission.cc |
| @@ -10,10 +10,78 @@ |
| namespace { |
| +using extensions::APIPermission; |
| +using extensions::APIPermissionDetail; |
| + |
| const char kOldUnlimitedStoragePermission[] = "unlimited_storage"; |
| const char kWindowsPermission[] = "windows"; |
| const char kTemporaryBackgroundAlias[] = "background_alias_do_not_use"; |
| +class SimpleDetail : public APIPermissionDetail { |
| + public: |
| + SimpleDetail(const APIPermission* permission) |
| + : APIPermissionDetail(permission) { } |
| + |
| + virtual bool FromValue(const base::Value* value) OVERRIDE { |
| + return true; |
| + } |
| + |
| + virtual void ToValue(base::Value** value) const OVERRIDE { |
| + } |
| + |
| + virtual bool Check( |
| + const APIPermissionDetail::DetailParam* detail) const OVERRIDE { |
| + return !detail; |
| + } |
| + |
| + virtual bool Equal(const APIPermissionDetail* detail) const OVERRIDE { |
| + if (this == detail) |
| + return true; |
| + CHECK(permission() == detail->permission()); |
| + return true; |
| + } |
| + |
| + virtual APIPermissionDetail* Clone() const OVERRIDE { |
| + return new SimpleDetail(permission()); |
| + } |
| + |
| + virtual APIPermissionDetail* Diff( |
| + const APIPermissionDetail* detail) const OVERRIDE { |
| + CHECK(permission() == detail->permission()); |
|
miket_OOO
2012/07/31 18:18:37
Is this right? Do we really want to crash?
Same w
Peng
2012/07/31 19:32:28
Diff, Union, Intersect can only be used on same AP
|
| + return NULL; |
| + } |
| + |
| + virtual APIPermissionDetail* Union( |
| + const APIPermissionDetail* detail) const OVERRIDE { |
| + CHECK(permission() == detail->permission()); |
| + return new SimpleDetail(permission()); |
| + } |
| + |
| + virtual APIPermissionDetail* Intersect( |
| + const APIPermissionDetail* detail) const OVERRIDE { |
| + CHECK(permission() == detail->permission()); |
| + return new SimpleDetail(permission()); |
| + } |
| + |
| + virtual bool Contains(const APIPermissionDetail* detail) const OVERRIDE { |
| + CHECK(permission() == detail->permission()); |
| + return true; |
| + } |
| + |
| + virtual void Write(IPC::Message *m) const OVERRIDE { |
| + } |
| + |
| + virtual bool Read(const IPC::Message *m, PickleIterator *iter) OVERRIDE { |
| + return true; |
| + } |
| + |
| + virtual void Log(std::string *l) const OVERRIDE { } |
| + |
| + protected: |
| + friend extensions::APIPermissionDetail; |
| + virtual ~SimpleDetail() {} |
| +}; |
| + |
| } // namespace |
| namespace extensions { |
| @@ -24,6 +92,15 @@ namespace extensions { |
| APIPermission::~APIPermission() {} |
| +scoped_refptr<APIPermissionDetail> APIPermission::CreateDetail() const { |
| + scoped_refptr<APIPermissionDetail> p; |
| + if (!detail_constructor_.is_null()) |
| + p = detail_constructor_.Run(); |
| + if (!p.get()) |
| + p = new SimpleDetail(this); |
| + return p; |
| +} |
| + |
| PermissionMessage APIPermission::GetMessage_() const { |
| return PermissionMessage( |
| message_id_, l10n_util::GetStringUTF16(l10n_message_id_)); |
| @@ -34,12 +111,14 @@ APIPermission::APIPermission( |
| const char* name, |
| int l10n_message_id, |
| PermissionMessage::ID message_id, |
| - int flags) |
| + int flags, |
| + const DetailConstructor &detail_constructor) |
|
miket_OOO
2012/07/31 18:18:37
whitespace
Peng
2012/07/31 19:32:28
Done.
|
| : id_(id), |
| name_(name), |
| flags_(flags), |
| l10n_message_id_(l10n_message_id), |
| - message_id_(message_id) {} |
| + message_id_(message_id), |
| + detail_constructor_(detail_constructor) {} |
| // static |
| void APIPermission::RegisterAllPermissions( |
| @@ -51,6 +130,7 @@ void APIPermission::RegisterAllPermissions( |
| int flags; |
| int l10n_message_id; |
| PermissionMessage::ID message_id; |
| + DetailConstructor detail_constructor; |
| } PermissionsToRegister[] = { |
| // Register permissions for all extension types. |
| { kBackground, "background" }, |
| @@ -181,7 +261,8 @@ void APIPermission::RegisterAllPermissions( |
| info->RegisterPermission( |
| pr.id, pr.name, pr.l10n_message_id, |
| pr.message_id ? pr.message_id : PermissionMessage::kNone, |
| - pr.flags); |
| + pr.flags, |
| + pr.detail_constructor); |
| } |
| // Register aliases. |
| @@ -192,4 +273,7 @@ void APIPermission::RegisterAllPermissions( |
| info->RegisterAlias("background", kTemporaryBackgroundAlias); |
| } |
| +APIPermissionDetail::~APIPermissionDetail() { |
| +} |
| + |
| } // namespace extensions |