1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/bindings/js/handle.h"
7 #include "mojo/bindings/js/handle_close_observer.h"
12 gin::WrapperInfo
HandleWrapper::kWrapperInfo
= { gin::kEmbedderNativeGin
};
14 HandleWrapper::HandleWrapper(MojoHandle handle
)
15 : handle_(mojo::Handle(handle
)) {
18 HandleWrapper::~HandleWrapper() {
19 NotifyCloseObservers();
22 void HandleWrapper::Close() {
23 NotifyCloseObservers();
27 void HandleWrapper::AddCloseObserver(HandleCloseObserver
* observer
) {
28 close_observers_
.AddObserver(observer
);
31 void HandleWrapper::RemoveCloseObserver(HandleCloseObserver
* observer
) {
32 close_observers_
.RemoveObserver(observer
);
35 void HandleWrapper::NotifyCloseObservers() {
36 if (!handle_
.is_valid())
39 FOR_EACH_OBSERVER(HandleCloseObserver
, close_observers_
, OnWillCloseHandle());
47 v8::Handle
<v8::Value
> Converter
<mojo::Handle
>::ToV8(v8::Isolate
* isolate
,
48 const mojo::Handle
& val
) {
50 return v8::Null(isolate
);
51 return mojo::js::HandleWrapper::Create(isolate
, val
.value()).ToV8();
54 bool Converter
<mojo::Handle
>::FromV8(v8::Isolate
* isolate
,
55 v8::Handle
<v8::Value
> val
,
58 *out
= mojo::Handle();
62 gin::Handle
<mojo::js::HandleWrapper
> handle
;
63 if (!Converter
<gin::Handle
<mojo::js::HandleWrapper
> >::FromV8(
64 isolate
, val
, &handle
))