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

Unified Diff: extensions/renderer/api_binding.cc

Issue 2891123002: [Extensions Bindings] Handle updating context permissions (Closed)
Patch Set: jbroman's Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/api_binding.h ('k') | extensions/renderer/api_binding_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_binding.cc
diff --git a/extensions/renderer/api_binding.cc b/extensions/renderer/api_binding.cc
index eff4316ea100991b4f6fb6e2e8df6f1161d5c2f5..ecdb4840ab17e319975abd70f554bec405dafb57 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::StringToV8(
+ 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;
« no previous file with comments | « extensions/renderer/api_binding.h ('k') | extensions/renderer/api_binding_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698