| OLD | NEW |
| (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 |
| OLD | NEW |