OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/bindings/js/handle.h" | 5 #include "mojo/bindings/js/handle.h" |
6 | 6 |
7 namespace gin { | 7 namespace gin { |
8 | 8 |
9 gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin }; | 9 gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin }; |
10 | 10 |
11 HandleWrapper::HandleWrapper(MojoHandle handle) | 11 HandleWrapper::HandleWrapper(MojoHandle handle) |
12 : handle_(mojo::Handle(handle)) { | 12 : handle_(mojo::Handle(handle)) { |
13 } | 13 } |
14 | 14 |
15 HandleWrapper::~HandleWrapper() { | 15 HandleWrapper::~HandleWrapper() { |
16 NotifyCloseObservers(); | |
17 } | |
18 | |
19 void HandleWrapper::Close() { | |
20 NotifyCloseObservers(); | |
21 handle_.reset(); | |
22 } | |
23 | |
24 void HandleWrapper::AddCloseObserver(CloseObserver* observer) { | |
25 close_observers_.AddObserver(observer); | |
26 } | |
27 | |
28 void HandleWrapper::RemoveCloseObserver(CloseObserver* observer) { | |
29 close_observers_.RemoveObserver(observer); | |
30 } | |
31 | |
32 void HandleWrapper::NotifyCloseObservers() { | |
33 FOR_EACH_OBSERVER(CloseObserver, close_observers_, OnHandleClosed()); | |
sky
2014/09/03 15:47:04
Should we only notify the observers if the handle
Sam McNally
2014/09/08 04:31:52
Done.
| |
16 } | 34 } |
17 | 35 |
18 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate, | 36 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate, |
19 const mojo::Handle& val) { | 37 const mojo::Handle& val) { |
20 if (!val.is_valid()) | 38 if (!val.is_valid()) |
21 return v8::Null(isolate); | 39 return v8::Null(isolate); |
22 return HandleWrapper::Create(isolate, val.value()).ToV8(); | 40 return HandleWrapper::Create(isolate, val.value()).ToV8(); |
23 } | 41 } |
24 | 42 |
25 bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate, | 43 bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate, |
26 v8::Handle<v8::Value> val, | 44 v8::Handle<v8::Value> val, |
27 mojo::Handle* out) { | 45 mojo::Handle* out) { |
28 if (val->IsNull()) { | 46 if (val->IsNull()) { |
29 *out = mojo::Handle(); | 47 *out = mojo::Handle(); |
30 return true; | 48 return true; |
31 } | 49 } |
32 | 50 |
33 gin::Handle<HandleWrapper> handle; | 51 gin::Handle<HandleWrapper> handle; |
34 if (!Converter<gin::Handle<HandleWrapper> >::FromV8(isolate, val, &handle)) | 52 if (!Converter<gin::Handle<HandleWrapper> >::FromV8(isolate, val, &handle)) |
35 return false; | 53 return false; |
36 | 54 |
37 *out = handle->get(); | 55 *out = handle->get(); |
38 return true; | 56 return true; |
39 } | 57 } |
40 | 58 |
41 } // namespace gin | 59 } // namespace gin |
OLD | NEW |