blob: b27595059aed89248b0c28940553cf91fb4f701e [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/js/js_app_bridge_module.h"
#include "gin/arguments.h"
#include "gin/converter.h"
#include "gin/object_template_builder.h"
#include "gin/per_isolate_data.h"
#include "mojo/edk/js/handle.h"
#include "services/js/js_app.h"
namespace js {
namespace {
gin::WrapperInfo g_wrapper_info = {gin::kEmbedderNativeGin};
} // namespace
const char AppBridge::kModuleName[] = "services/js/app_bridge";
v8::Local<v8::Value> AppBridge::GetModule(JSApp* js_app, v8::Isolate* isolate) {
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
v8::Local<v8::ObjectTemplate> templ =
data->GetObjectTemplate(&g_wrapper_info);
if (templ.IsEmpty()) {
templ = gin::ObjectTemplateBuilder(isolate)
.SetMethod("quit",
base::Bind(&JSApp::Quit, base::Unretained(js_app)))
.Build();
data->SetObjectTemplate(&g_wrapper_info, templ);
}
return templ->NewInstance();
}
} // namespace js