OLD | NEW |
---|---|
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 #include "chrome/common/extensions/permissions/api_permission.h" | 5 #include "chrome/common/extensions/permissions/api_permission.h" |
6 | 6 |
7 #include "chrome/common/extensions/permissions/permissions_info.h" | 7 #include "chrome/common/extensions/permissions/permissions_info.h" |
8 #include "grit/generated_resources.h" | 8 #include "grit/generated_resources.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 using extensions::APIPermission; | |
14 using extensions::APIPermissionDetail; | |
15 | |
13 const char kOldUnlimitedStoragePermission[] = "unlimited_storage"; | 16 const char kOldUnlimitedStoragePermission[] = "unlimited_storage"; |
14 const char kWindowsPermission[] = "windows"; | 17 const char kWindowsPermission[] = "windows"; |
15 const char kTemporaryBackgroundAlias[] = "background_alias_do_not_use"; | 18 const char kTemporaryBackgroundAlias[] = "background_alias_do_not_use"; |
16 | 19 |
20 class SimpleDetail : public APIPermissionDetail { | |
21 public: | |
22 SimpleDetail(const APIPermission* permission) | |
23 : APIPermissionDetail(permission) { } | |
24 | |
25 virtual bool FromValue(const base::Value* value) OVERRIDE { | |
26 return true; | |
27 } | |
28 | |
29 virtual void ToValue(base::Value** value) const OVERRIDE { | |
30 } | |
31 | |
32 virtual bool Check( | |
33 const APIPermissionDetail::DetailParam* detail) const OVERRIDE { | |
34 return !detail; | |
35 } | |
36 | |
37 virtual bool Equal(const APIPermissionDetail* detail) const OVERRIDE { | |
38 if (this == detail) | |
39 return true; | |
40 CHECK(permission() == detail->permission()); | |
41 return true; | |
42 } | |
43 | |
44 virtual APIPermissionDetail* Clone() const OVERRIDE { | |
45 return new SimpleDetail(permission()); | |
46 } | |
47 | |
48 virtual APIPermissionDetail* Diff( | |
49 const APIPermissionDetail* detail) const OVERRIDE { | |
50 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
| |
51 return NULL; | |
52 } | |
53 | |
54 virtual APIPermissionDetail* Union( | |
55 const APIPermissionDetail* detail) const OVERRIDE { | |
56 CHECK(permission() == detail->permission()); | |
57 return new SimpleDetail(permission()); | |
58 } | |
59 | |
60 virtual APIPermissionDetail* Intersect( | |
61 const APIPermissionDetail* detail) const OVERRIDE { | |
62 CHECK(permission() == detail->permission()); | |
63 return new SimpleDetail(permission()); | |
64 } | |
65 | |
66 virtual bool Contains(const APIPermissionDetail* detail) const OVERRIDE { | |
67 CHECK(permission() == detail->permission()); | |
68 return true; | |
69 } | |
70 | |
71 virtual void Write(IPC::Message *m) const OVERRIDE { | |
72 } | |
73 | |
74 virtual bool Read(const IPC::Message *m, PickleIterator *iter) OVERRIDE { | |
75 return true; | |
76 } | |
77 | |
78 virtual void Log(std::string *l) const OVERRIDE { } | |
79 | |
80 protected: | |
81 friend extensions::APIPermissionDetail; | |
82 virtual ~SimpleDetail() {} | |
83 }; | |
84 | |
17 } // namespace | 85 } // namespace |
18 | 86 |
19 namespace extensions { | 87 namespace extensions { |
20 | 88 |
21 // | 89 // |
22 // APIPermission | 90 // APIPermission |
23 // | 91 // |
24 | 92 |
25 APIPermission::~APIPermission() {} | 93 APIPermission::~APIPermission() {} |
26 | 94 |
95 scoped_refptr<APIPermissionDetail> APIPermission::CreateDetail() const { | |
96 scoped_refptr<APIPermissionDetail> p; | |
97 if (!detail_constructor_.is_null()) | |
98 p = detail_constructor_.Run(); | |
99 if (!p.get()) | |
100 p = new SimpleDetail(this); | |
101 return p; | |
102 } | |
103 | |
27 PermissionMessage APIPermission::GetMessage_() const { | 104 PermissionMessage APIPermission::GetMessage_() const { |
28 return PermissionMessage( | 105 return PermissionMessage( |
29 message_id_, l10n_util::GetStringUTF16(l10n_message_id_)); | 106 message_id_, l10n_util::GetStringUTF16(l10n_message_id_)); |
30 } | 107 } |
31 | 108 |
32 APIPermission::APIPermission( | 109 APIPermission::APIPermission( |
33 ID id, | 110 ID id, |
34 const char* name, | 111 const char* name, |
35 int l10n_message_id, | 112 int l10n_message_id, |
36 PermissionMessage::ID message_id, | 113 PermissionMessage::ID message_id, |
37 int flags) | 114 int flags, |
115 const DetailConstructor &detail_constructor) | |
miket_OOO
2012/07/31 18:18:37
whitespace
Peng
2012/07/31 19:32:28
Done.
| |
38 : id_(id), | 116 : id_(id), |
39 name_(name), | 117 name_(name), |
40 flags_(flags), | 118 flags_(flags), |
41 l10n_message_id_(l10n_message_id), | 119 l10n_message_id_(l10n_message_id), |
42 message_id_(message_id) {} | 120 message_id_(message_id), |
121 detail_constructor_(detail_constructor) {} | |
43 | 122 |
44 // static | 123 // static |
45 void APIPermission::RegisterAllPermissions( | 124 void APIPermission::RegisterAllPermissions( |
46 PermissionsInfo* info) { | 125 PermissionsInfo* info) { |
47 | 126 |
48 struct PermissionRegistration { | 127 struct PermissionRegistration { |
49 APIPermission::ID id; | 128 APIPermission::ID id; |
50 const char* name; | 129 const char* name; |
51 int flags; | 130 int flags; |
52 int l10n_message_id; | 131 int l10n_message_id; |
53 PermissionMessage::ID message_id; | 132 PermissionMessage::ID message_id; |
133 DetailConstructor detail_constructor; | |
54 } PermissionsToRegister[] = { | 134 } PermissionsToRegister[] = { |
55 // Register permissions for all extension types. | 135 // Register permissions for all extension types. |
56 { kBackground, "background" }, | 136 { kBackground, "background" }, |
57 { kClipboardRead, "clipboardRead", kFlagNone, | 137 { kClipboardRead, "clipboardRead", kFlagNone, |
58 IDS_EXTENSION_PROMPT_WARNING_CLIPBOARD, | 138 IDS_EXTENSION_PROMPT_WARNING_CLIPBOARD, |
59 PermissionMessage::kClipboard }, | 139 PermissionMessage::kClipboard }, |
60 { kClipboardWrite, "clipboardWrite" }, | 140 { kClipboardWrite, "clipboardWrite" }, |
61 { kDeclarative, "declarative" }, | 141 { kDeclarative, "declarative" }, |
62 { kDeclarativeWebRequest, "declarativeWebRequest" }, | 142 { kDeclarativeWebRequest, "declarativeWebRequest" }, |
63 { kDownloads, "downloads", kFlagNone, | 143 { kDownloads, "downloads", kFlagNone, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 kFlagCannotBeOptional, | 254 kFlagCannotBeOptional, |
175 IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_ALL_GALLERIES, | 255 IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_ALL_GALLERIES, |
176 PermissionMessage::kMediaGalleriesAllGalleries }, | 256 PermissionMessage::kMediaGalleriesAllGalleries }, |
177 }; | 257 }; |
178 | 258 |
179 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(PermissionsToRegister); ++i) { | 259 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(PermissionsToRegister); ++i) { |
180 const PermissionRegistration& pr = PermissionsToRegister[i]; | 260 const PermissionRegistration& pr = PermissionsToRegister[i]; |
181 info->RegisterPermission( | 261 info->RegisterPermission( |
182 pr.id, pr.name, pr.l10n_message_id, | 262 pr.id, pr.name, pr.l10n_message_id, |
183 pr.message_id ? pr.message_id : PermissionMessage::kNone, | 263 pr.message_id ? pr.message_id : PermissionMessage::kNone, |
184 pr.flags); | 264 pr.flags, |
265 pr.detail_constructor); | |
185 } | 266 } |
186 | 267 |
187 // Register aliases. | 268 // Register aliases. |
188 info->RegisterAlias("unlimitedStorage", kOldUnlimitedStoragePermission); | 269 info->RegisterAlias("unlimitedStorage", kOldUnlimitedStoragePermission); |
189 info->RegisterAlias("tabs", kWindowsPermission); | 270 info->RegisterAlias("tabs", kWindowsPermission); |
190 // TODO(mihaip): Should be removed for the M20 branch, see | 271 // TODO(mihaip): Should be removed for the M20 branch, see |
191 // http://crbug.com/120447 for more details. | 272 // http://crbug.com/120447 for more details. |
192 info->RegisterAlias("background", kTemporaryBackgroundAlias); | 273 info->RegisterAlias("background", kTemporaryBackgroundAlias); |
193 } | 274 } |
194 | 275 |
276 APIPermissionDetail::~APIPermissionDetail() { | |
277 } | |
278 | |
195 } // namespace extensions | 279 } // namespace extensions |
OLD | NEW |