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

Side by Side Diff: extensions/renderer/native_extension_bindings_system.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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/native_extension_bindings_system.h" 5 #include "extensions/renderer/native_extension_bindings_system.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "content/public/common/console_message_level.h" 9 #include "content/public/common/console_message_level.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 188 }
189 189
190 // Returns the API schema indicated by |api_name|. 190 // Returns the API schema indicated by |api_name|.
191 const base::DictionaryValue& GetAPISchema(const std::string& api_name) { 191 const base::DictionaryValue& GetAPISchema(const std::string& api_name) {
192 const base::DictionaryValue* schema = 192 const base::DictionaryValue* schema =
193 ExtensionAPI::GetSharedInstance()->GetSchema(api_name); 193 ExtensionAPI::GetSharedInstance()->GetSchema(api_name);
194 CHECK(schema) << api_name; 194 CHECK(schema) << api_name;
195 return *schema; 195 return *schema;
196 } 196 }
197 197
198 // Returns true if the method specified by |method_name| is available to the 198 // Returns true if the feature specified by |name| is available to the given
199 // given |context|. 199 // |context|.
200 bool IsAPIMethodAvailable(ScriptContext* context, 200 bool IsAPIFeatureAvailable(v8::Local<v8::Context> context,
201 const std::string& method_name) { 201 const std::string& name) {
202 return context->GetAvailability(method_name).is_available(); 202 ScriptContext* script_context =
203 ScriptContextSet::GetContextByV8Context(context);
204 DCHECK(script_context);
205 return script_context->GetAvailability(name).is_available();
203 } 206 }
204 207
205 // Instantiates the binding object for the given |name|. |name| must specify a 208 // Instantiates the binding object for the given |name|. |name| must specify a
206 // specific feature. 209 // specific feature.
207 v8::Local<v8::Object> CreateRootBinding(v8::Local<v8::Context> context, 210 v8::Local<v8::Object> CreateRootBinding(v8::Local<v8::Context> context,
208 ScriptContext* script_context, 211 ScriptContext* script_context,
209 const std::string& name, 212 const std::string& name,
210 APIBindingsSystem* bindings_system) { 213 APIBindingsSystem* bindings_system) {
211 APIBindingHooks* hooks = nullptr; 214 APIBindingHooks* hooks = nullptr;
212 v8::Local<v8::Object> binding_object = bindings_system->CreateAPIInstance( 215 v8::Local<v8::Object> binding_object =
213 name, context, base::Bind(&IsAPIMethodAvailable, script_context), &hooks); 216 bindings_system->CreateAPIInstance(name, context, &hooks);
214 217
215 gin::Handle<APIBindingBridge> bridge_handle = gin::CreateHandle( 218 gin::Handle<APIBindingBridge> bridge_handle = gin::CreateHandle(
216 context->GetIsolate(), 219 context->GetIsolate(),
217 new APIBindingBridge(hooks, context, binding_object, 220 new APIBindingBridge(hooks, context, binding_object,
218 script_context->GetExtensionID(), 221 script_context->GetExtensionID(),
219 script_context->GetContextTypeDescription(), 222 script_context->GetContextTypeDescription(),
220 base::Bind(&CallJsFunction))); 223 base::Bind(&CallJsFunction)));
221 v8::Local<v8::Value> native_api_bridge = bridge_handle.ToV8(); 224 v8::Local<v8::Value> native_api_bridge = bridge_handle.ToV8();
222 script_context->module_system()->OnNativeBindingCreated(name, 225 script_context->module_system()->OnNativeBindingCreated(name,
223 native_api_bridge); 226 native_api_bridge);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 349
347 NativeExtensionBindingsSystem::NativeExtensionBindingsSystem( 350 NativeExtensionBindingsSystem::NativeExtensionBindingsSystem(
348 const SendRequestIPCMethod& send_request_ipc, 351 const SendRequestIPCMethod& send_request_ipc,
349 const SendEventListenerIPCMethod& send_event_listener_ipc) 352 const SendEventListenerIPCMethod& send_event_listener_ipc)
350 : send_request_ipc_(send_request_ipc), 353 : send_request_ipc_(send_request_ipc),
351 send_event_listener_ipc_(send_event_listener_ipc), 354 send_event_listener_ipc_(send_event_listener_ipc),
352 api_system_( 355 api_system_(
353 base::Bind(&CallJsFunction), 356 base::Bind(&CallJsFunction),
354 base::Bind(&CallJsFunctionSync), 357 base::Bind(&CallJsFunctionSync),
355 base::Bind(&GetAPISchema), 358 base::Bind(&GetAPISchema),
359 base::Bind(&IsAPIFeatureAvailable),
356 base::Bind(&NativeExtensionBindingsSystem::SendRequest, 360 base::Bind(&NativeExtensionBindingsSystem::SendRequest,
357 base::Unretained(this)), 361 base::Unretained(this)),
358 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, 362 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged,
359 base::Unretained(this)), 363 base::Unretained(this)),
360 APILastError(base::Bind(&GetRuntime), base::Bind(&AddConsoleError))), 364 APILastError(base::Bind(&GetRuntime), base::Bind(&AddConsoleError))),
361 weak_factory_(this) { 365 weak_factory_(this) {
362 api_system_.RegisterCustomType("storage.StorageArea", 366 api_system_.RegisterCustomType("storage.StorageArea",
363 base::Bind(&StorageArea::CreateStorageArea)); 367 base::Bind(&StorageArea::CreateStorageArea));
364 api_system_.RegisterCustomType("types.ChromeSetting", 368 api_system_.RegisterCustomType("types.ChromeSetting",
365 base::Bind(&ChromeSetting::Create)); 369 base::Bind(&ChromeSetting::Create));
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 v8::Local<v8::Value>* binding_util_out) { 689 v8::Local<v8::Value>* binding_util_out) {
686 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( 690 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle(
687 context->GetIsolate(), 691 context->GetIsolate(),
688 new APIBindingJSUtil( 692 new APIBindingJSUtil(
689 api_system_.type_reference_map(), api_system_.request_handler(), 693 api_system_.type_reference_map(), api_system_.request_handler(),
690 api_system_.event_handler(), base::Bind(&CallJsFunction))); 694 api_system_.event_handler(), base::Bind(&CallJsFunction)));
691 *binding_util_out = handle.ToV8(); 695 *binding_util_out = handle.ToV8();
692 } 696 }
693 697
694 } // namespace extensions 698 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/declarative_event_unittest.cc ('k') | extensions/renderer/native_extension_bindings_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698