[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 5 | #include "extensions/renderer/messaging_bindings.h" |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 6 | |
avi | 2d124c0 | 2015-12-23 06:36:42 | [diff] [blame] | 7 | #include <stdint.h> |
8 | |||||
[email protected] | 09e9d64 | 2013-03-14 17:00:10 | [diff] [blame] | 9 | #include "base/bind.h" |
kalman | 70c00e24 | 2015-05-15 23:42:27 | [diff] [blame] | 10 | #include "base/callback.h" |
rdevlin.cronin | dbbe69e7 | 2016-09-10 00:48:02 | [diff] [blame] | 11 | #include "base/callback_helpers.h" |
kalman | 32d7af2 | 2015-07-24 05:10:59 | [diff] [blame] | 12 | #include "extensions/renderer/gc_callback.h" |
[email protected] | bcd9580f | 2014-04-17 19:17:59 | [diff] [blame] | 13 | #include "extensions/renderer/script_context.h" |
[email protected] | 82fc0f5 | 2011-09-06 23:39:22 | [diff] [blame] | 14 | #include "v8/include/v8.h" |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 15 | |
[email protected] | eb7ef5f | 2014-02-06 09:59:19 | [diff] [blame] | 16 | namespace extensions { |
17 | |||||
rdevlin.cronin | 4012b3b | 2016-08-31 18:36:47 | [diff] [blame] | 18 | MessagingBindings::MessagingBindings(ScriptContext* context) |
Devlin Cronin | 8448a19 | 2019-03-15 01:03:16 | [diff] [blame] | 19 | : ObjectBackedNativeHandler(context) {} |
rob | d1db9f6 | 2016-05-25 11:03:10 | [diff] [blame] | 20 | |
Devlin Cronin | 8448a19 | 2019-03-15 01:03:16 | [diff] [blame] | 21 | MessagingBindings::~MessagingBindings() {} |
rdevlin.cronin | 4012b3b | 2016-08-31 18:36:47 | [diff] [blame] | 22 | |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 23 | void MessagingBindings::AddRoutes() { |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 24 | // TODO(fsamuel, kalman): Move BindToGC out of messaging natives. |
Devlin Cronin | cc02a0c | 2019-01-03 22:15:07 | [diff] [blame] | 25 | RouteHandlerFunction("BindToGC", |
26 | base::BindRepeating(&MessagingBindings::BindToGC, | ||||
27 | base::Unretained(this))); | ||||
rdevlin.cronin | 4012b3b | 2016-08-31 18:36:47 | [diff] [blame] | 28 | } |
29 | |||||
30 | void MessagingBindings::BindToGC( | ||||
31 | const v8::FunctionCallbackInfo<v8::Value>& args) { | ||||
rdevlin.cronin | dbbe69e7 | 2016-09-10 00:48:02 | [diff] [blame] | 32 | CHECK(args.Length() == 3); |
33 | CHECK(args[0]->IsObject()); | ||||
34 | CHECK(args[1]->IsFunction()); | ||||
35 | CHECK(args[2]->IsInt32()); | ||||
Devlin Cronin | 8448a19 | 2019-03-15 01:03:16 | [diff] [blame] | 36 | // TODO(devlin): Update callers to not pass a port ID. |
37 | // int js_port_id = args[2].As<v8::Int32>()->Value(); | ||||
Peter Kasting | 341e1fb | 2018-02-24 00:03:01 | [diff] [blame] | 38 | base::Closure fallback = base::DoNothing(); |
rdevlin.cronin | 4012b3b | 2016-08-31 18:36:47 | [diff] [blame] | 39 | // Destroys itself when the object is GC'd or context is invalidated. |
40 | new GCCallback(context(), args[0].As<v8::Object>(), | ||||
41 | args[1].As<v8::Function>(), fallback); | ||||
42 | } | ||||
43 | |||||
[email protected] | 8fe74bf | 2012-08-07 21:08:42 | [diff] [blame] | 44 | } // namespace extensions |