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

Side by Side Diff: extensions/renderer/binding_access_checker.cc

Issue 2947843004: [Extensions Bindings] Introduce BindingAccessChecker (Closed)
Patch Set: lazyboy's Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "extensions/renderer/binding_access_checker.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "gin/converter.h"
9
10 namespace extensions {
11
12 BindingAccessChecker::BindingAccessChecker(
13 const AvailabilityCallback& is_available)
14 : is_available_(is_available) {}
15 BindingAccessChecker::~BindingAccessChecker() {}
16
17 bool BindingAccessChecker::HasAccess(v8::Local<v8::Context> context,
18 const std::string& full_name) const {
19 return is_available_.Run(context, full_name);
20 }
21
22 bool BindingAccessChecker::HasAccessOrThrowError(
23 v8::Local<v8::Context> context,
24 const std::string& full_name) const {
25 if (!HasAccess(context, full_name)) {
26 context->GetIsolate()->ThrowException(v8::Exception::Error(gin::StringToV8(
27 context->GetIsolate(),
28 base::StringPrintf("'%s' is not available in this context.",
29 full_name.c_str()))));
30 return false;
31 }
32
33 return true;
34 }
35
36 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/binding_access_checker.h ('k') | extensions/renderer/binding_access_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698