| 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 #ifndef EXTENSIONS_RENDERER_BINDING_ACCESS_CHECKER_H_ | |
| 6 #define EXTENSIONS_RENDERER_BINDING_ACCESS_CHECKER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "v8/include/v8.h" | |
| 13 | |
| 14 namespace extensions { | |
| 15 | |
| 16 // A helper class to handle access-checking API features. | |
| 17 class BindingAccessChecker { | |
| 18 public: | |
| 19 // The callback for determining if a given API feature (specified by |name|) | |
| 20 // is available in the given context. | |
| 21 using AvailabilityCallback = | |
| 22 base::Callback<bool(v8::Local<v8::Context>, const std::string& name)>; | |
| 23 | |
| 24 BindingAccessChecker(const AvailabilityCallback& is_available); | |
| 25 ~BindingAccessChecker(); | |
| 26 | |
| 27 // Returns true if the feature specified by |full_name| is available to the | |
| 28 // given |context|. | |
| 29 bool HasAccess(v8::Local<v8::Context> context, | |
| 30 const std::string& full_name) const; | |
| 31 | |
| 32 // Same as HasAccess(), but throws an exception in the |context| if it doesn't | |
| 33 // have access. | |
| 34 bool HasAccessOrThrowError(v8::Local<v8::Context> context, | |
| 35 const std::string& full_name) const; | |
| 36 | |
| 37 private: | |
| 38 AvailabilityCallback is_available_; | |
| 39 | |
| 40 DISALLOW_COPY_AND_ASSIGN(BindingAccessChecker); | |
| 41 }; | |
| 42 | |
| 43 } // namespace extensions | |
| 44 | |
| 45 #endif // EXTENSIONS_RENDERER_BINDING_ACCESS_CHECKER_H_ | |
| OLD | NEW |