blob: 3ff07982958b91127ad2bc81d04f0f4599067050 [file] [log] [blame]
[email protected]e6893672014-05-01 17:29:131// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]0aa477bd2009-03-23 22:21:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e6893672014-05-01 17:29:135#include "extensions/renderer/messaging_bindings.h"
[email protected]0aa477bd2009-03-23 22:21:436
avi2d124c02015-12-23 06:36:427#include <stdint.h>
8
[email protected]09e9d642013-03-14 17:00:109#include "base/bind.h"
kalman70c00e242015-05-15 23:42:2710#include "base/callback.h"
rdevlin.cronindbbe69e72016-09-10 00:48:0211#include "base/callback_helpers.h"
kalman32d7af22015-07-24 05:10:5912#include "extensions/renderer/gc_callback.h"
[email protected]bcd9580f2014-04-17 19:17:5913#include "extensions/renderer/script_context.h"
[email protected]82fc0f52011-09-06 23:39:2214#include "v8/include/v8.h"
[email protected]0aa477bd2009-03-23 22:21:4315
[email protected]eb7ef5f2014-02-06 09:59:1916namespace extensions {
17
rdevlin.cronin4012b3b2016-08-31 18:36:4718MessagingBindings::MessagingBindings(ScriptContext* context)
Devlin Cronin8448a192019-03-15 01:03:1619 : ObjectBackedNativeHandler(context) {}
robd1db9f62016-05-25 11:03:1020
Devlin Cronin8448a192019-03-15 01:03:1621MessagingBindings::~MessagingBindings() {}
rdevlin.cronin4012b3b2016-08-31 18:36:4722
Devlin Cronind9ea8342018-01-27 06:00:0423void MessagingBindings::AddRoutes() {
Devlin Cronind9ea8342018-01-27 06:00:0424 // TODO(fsamuel, kalman): Move BindToGC out of messaging natives.
Devlin Cronincc02a0c2019-01-03 22:15:0725 RouteHandlerFunction("BindToGC",
26 base::BindRepeating(&MessagingBindings::BindToGC,
27 base::Unretained(this)));
rdevlin.cronin4012b3b2016-08-31 18:36:4728}
29
30void MessagingBindings::BindToGC(
31 const v8::FunctionCallbackInfo<v8::Value>& args) {
rdevlin.cronindbbe69e72016-09-10 00:48:0232 CHECK(args.Length() == 3);
33 CHECK(args[0]->IsObject());
34 CHECK(args[1]->IsFunction());
35 CHECK(args[2]->IsInt32());
Devlin Cronin8448a192019-03-15 01:03:1636 // TODO(devlin): Update callers to not pass a port ID.
37 // int js_port_id = args[2].As<v8::Int32>()->Value();
Peter Kasting341e1fb2018-02-24 00:03:0138 base::Closure fallback = base::DoNothing();
rdevlin.cronin4012b3b2016-08-31 18:36:4739 // 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]8fe74bf2012-08-07 21:08:4244} // namespace extensions