Index: extensions/renderer/api_binding.cc |
diff --git a/extensions/renderer/api_binding.cc b/extensions/renderer/api_binding.cc |
index eff4316ea100991b4f6fb6e2e8df6f1161d5c2f5..25a6b8ec399dbbe52a18ba1aabbf44f1ebc96048 100644 |
--- a/extensions/renderer/api_binding.cc |
+++ b/extensions/renderer/api_binding.cc |
@@ -164,6 +164,7 @@ APIBinding::APIBinding(const std::string& api_name, |
const base::ListValue* event_definitions, |
const base::DictionaryValue* property_definitions, |
const CreateCustomType& create_custom_type, |
+ const AvailabilityCallback& is_available, |
std::unique_ptr<APIBindingHooks> binding_hooks, |
APITypeReferenceMap* type_refs, |
APIRequestHandler* request_handler, |
@@ -171,6 +172,7 @@ APIBinding::APIBinding(const std::string& api_name, |
: api_name_(api_name), |
property_definitions_(property_definitions), |
create_custom_type_(create_custom_type), |
+ is_available_(is_available), |
binding_hooks_(std::move(binding_hooks)), |
type_refs_(type_refs), |
request_handler_(request_handler), |
@@ -297,8 +299,7 @@ APIBinding::APIBinding(const std::string& api_name, |
APIBinding::~APIBinding() {} |
v8::Local<v8::Object> APIBinding::CreateInstance( |
- v8::Local<v8::Context> context, |
- const AvailabilityCallback& is_available) { |
+ v8::Local<v8::Context> context) { |
DCHECK(IsContextValid(context)); |
v8::Isolate* isolate = context->GetIsolate(); |
if (object_template_.IsEmpty()) |
@@ -314,10 +315,8 @@ v8::Local<v8::Object> APIBinding::CreateInstance( |
// TODO(devlin): Ideally, we'd only do this check on the methods that are |
// conditionally exposed. Or, we could have multiple templates for different |
// configurations, assuming there are a small number of possibilities. |
- // TODO(devlin): enums should always be exposed, but there may be events that |
- // are restricted. Investigate. |
for (const auto& key_value : methods_) { |
- if (!is_available.Run(key_value.second->full_name)) { |
+ if (!is_available_.Run(context, key_value.second->full_name)) { |
v8::Maybe<bool> success = object->Delete( |
context, gin::StringToSymbol(isolate, key_value.first)); |
CHECK(success.IsJust()); |
@@ -325,7 +324,7 @@ v8::Local<v8::Object> APIBinding::CreateInstance( |
} |
} |
for (const auto& event : events_) { |
- if (!is_available.Run(event->full_name)) { |
+ if (!is_available_.Run(context, event->full_name)) { |
v8::Maybe<bool> success = object->Delete( |
context, gin::StringToSymbol(isolate, event->exposed_name)); |
CHECK(success.IsJust()); |
@@ -512,6 +511,15 @@ void APIBinding::HandleCall(const std::string& name, |
// GetCurrentContext() should always be correct. |
v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
+ if (!is_available_.Run(context, name)) { |
+ // TODO(devlin): Do we need handle this for events as well? I'm not sure the |
+ // currrent system does (though perhaps it should). Investigate. |
+ isolate->ThrowException(v8::Exception::Error(gin::StringToSymbol( |
jbroman
2017/05/24 18:09:47
super-nit: maybe StringToV8? (this doesn't seem li
Devlin
2017/05/24 19:10:08
Done.
|
+ isolate, base::StringPrintf("'%s' is not available in this context.", |
+ name.c_str())))); |
+ return; |
+ } |
+ |
std::vector<v8::Local<v8::Value>> argument_list = arguments->GetAll(); |
bool invalid_invocation = false; |