|
8 | 8 | #include "node_external_reference.h" |
9 | 9 | #include "node_file.h" |
10 | 10 |
|
| 11 | +#include "permission/permission_base.h" |
11 | 12 | #include "v8-template.h" |
12 | 13 | #include "v8.h" |
13 | 14 |
|
@@ -261,31 +262,30 @@ void Permission::EnableWarningOnly() { |
261 | 262 | bool Permission::is_scope_granted(Environment* env, |
262 | 263 | const PermissionScope permission, |
263 | 264 | const std::string_view& res) const { |
| 265 | + CHECK(permission != PermissionScope::kPermissionsRoot && |
| 266 | + permission != PermissionScope::kPermissionsCount); |
264 | 267 | auto perm_node = nodes_.find(permission); |
265 | 268 | bool result = false; |
266 | 269 | if (perm_node != nodes_.end()) { |
267 | 270 | result = perm_node->second->is_granted(env, permission, res); |
268 | 271 | } |
269 | 272 |
|
270 | 273 | if (!result && !publishing_) { |
271 | | - auto channel_name = GetDiagnosticsChannelName(permission); |
272 | | - if (!channel_name.empty()) { |
273 | | - auto ch = GetOrCreateChannel(env, permission); |
274 | | - if (ch && ch->HasSubscribers()) { |
275 | | - publishing_ = true; |
276 | | - v8::Isolate* isolate = env->isolate(); |
277 | | - v8::HandleScope handle_scope(isolate); |
278 | | - v8::Local<v8::Context> context = env->context(); |
279 | | - v8::MaybeLocal<v8::Value> values[] = { |
280 | | - PermissionToString(env, permission), |
281 | | - ToV8Value(context, res), |
282 | | - Undefined(isolate), |
283 | | - }; |
284 | | - ch->Publish( |
285 | | - env, |
286 | | - GetPermissionDiagnosicsTemplate(env)->NewInstance(context, values)); |
287 | | - publishing_ = false; |
288 | | - } |
| 274 | + auto ch = GetOrCreateChannel(env, permission); |
| 275 | + if (ch && ch->HasSubscribers()) { |
| 276 | + publishing_ = true; |
| 277 | + v8::Isolate* isolate = env->isolate(); |
| 278 | + v8::HandleScope handle_scope(isolate); |
| 279 | + v8::Local<v8::Context> context = env->context(); |
| 280 | + v8::MaybeLocal<v8::Value> values[] = { |
| 281 | + PermissionToString(env, permission), |
| 282 | + ToV8Value(context, res), |
| 283 | + Undefined(isolate), |
| 284 | + }; |
| 285 | + ch->Publish( |
| 286 | + env, |
| 287 | + GetPermissionDiagnosicsTemplate(env)->NewInstance(context, values)); |
| 288 | + publishing_ = false; |
289 | 289 | } |
290 | 290 | } |
291 | 291 |
|
@@ -294,6 +294,8 @@ bool Permission::is_scope_granted(Environment* env, |
294 | 294 |
|
295 | 295 | BaseObjectPtr<diagnostics_channel::Channel> Permission::GetOrCreateChannel( |
296 | 296 | Environment* env, PermissionScope scope) const { |
| 297 | + CHECK(scope != PermissionScope::kPermissionsRoot && |
| 298 | + scope != PermissionScope::kPermissionsCount); |
297 | 299 | auto it = channels_.find(scope); |
298 | 300 | if (it != channels_.end()) { |
299 | 301 | // Promote weak ref to strong for the duration of this call. |
@@ -324,14 +326,15 @@ void Permission::Apply(Environment* env, |
324 | 326 | void Permission::Drop(Environment* env, |
325 | 327 | PermissionScope scope, |
326 | 328 | const std::string_view& param) { |
| 329 | + CHECK(scope != PermissionScope::kPermissionsRoot && |
| 330 | + scope != PermissionScope::kPermissionsCount); |
327 | 331 | auto permission = nodes_.find(scope); |
328 | 332 | if (permission != nodes_.end()) { |
329 | 333 | permission->second->Drop(env, scope, param); |
330 | 334 | } |
331 | 335 |
|
332 | 336 | // Publish to diagnostics channel so observers can track drops |
333 | | - auto channel_name = GetDiagnosticsChannelName(scope); |
334 | | - if (!channel_name.empty() && !publishing_) { |
| 337 | + if (!publishing_) { |
335 | 338 | auto ch = GetOrCreateChannel(env, scope); |
336 | 339 | if (ch && ch->HasSubscribers()) { |
337 | 340 | publishing_ = true; |
|