[Mojo] Fix the namespace for HandleWrapper
[chromium-blink-merge.git] / mojo / bindings / js / handle.cc
blobbaa1baea3a2eb92788fe72d03816b225012cb554
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"
9 namespace mojo {
10 namespace js {
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();
24 handle_.reset();
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())
37 return;
39 FOR_EACH_OBSERVER(HandleCloseObserver, close_observers_, OnWillCloseHandle());
42 } // namespace js
43 } // namespace mojo
45 namespace gin {
47 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate,
48 const mojo::Handle& val) {
49 if (!val.is_valid())
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,
56 mojo::Handle* out) {
57 if (val->IsNull()) {
58 *out = mojo::Handle();
59 return true;
62 gin::Handle<mojo::js::HandleWrapper> handle;
63 if (!Converter<gin::Handle<mojo::js::HandleWrapper> >::FromV8(
64 isolate, val, &handle))
65 return false;
67 *out = handle->get();
68 return true;
71 } // namespace gin