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/edk/js/handle.h" | 5 #include "mojo/edk/js/handle.h" |
6 | 6 |
| 7 #include <sstream> |
7 #include "mojo/edk/js/handle_close_observer.h" | 8 #include "mojo/edk/js/handle_close_observer.h" |
8 | 9 |
9 namespace mojo { | 10 namespace mojo { |
10 namespace js { | 11 namespace js { |
11 | 12 |
12 gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin }; | 13 gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin }; |
13 | 14 |
14 HandleWrapper::HandleWrapper(MojoHandle handle) | 15 HandleWrapper::HandleWrapper(MojoHandle handle) |
15 : handle_(mojo::Handle(handle)) { | 16 : handle_(mojo::Handle(handle)) { |
16 } | 17 } |
17 | 18 |
18 HandleWrapper::~HandleWrapper() { | 19 HandleWrapper::~HandleWrapper() { |
19 NotifyCloseObservers(); | 20 NotifyCloseObservers(); |
20 } | 21 } |
21 | 22 |
| 23 std::string HandleWrapper::ToString() { |
| 24 std::ostringstream oss; |
| 25 oss << "[mojo::Handle "; |
| 26 if (handle_.is_valid()) |
| 27 oss << handle_.get().value(); |
| 28 else |
| 29 oss << "null"; |
| 30 oss << "]"; |
| 31 return oss.str(); |
| 32 } |
| 33 |
| 34 gin::ObjectTemplateBuilder HandleWrapper::GetObjectTemplateBuilder( |
| 35 v8::Isolate* isolate) { |
| 36 return Wrappable<HandleWrapper>::GetObjectTemplateBuilder(isolate) |
| 37 .SetMethod("toString", &HandleWrapper::ToString); |
| 38 } |
| 39 |
22 void HandleWrapper::Close() { | 40 void HandleWrapper::Close() { |
23 NotifyCloseObservers(); | 41 NotifyCloseObservers(); |
24 handle_.reset(); | 42 handle_.reset(); |
25 } | 43 } |
26 | 44 |
27 void HandleWrapper::AddCloseObserver(HandleCloseObserver* observer) { | 45 void HandleWrapper::AddCloseObserver(HandleCloseObserver* observer) { |
28 close_observers_.AddObserver(observer); | 46 close_observers_.AddObserver(observer); |
29 } | 47 } |
30 | 48 |
31 void HandleWrapper::RemoveCloseObserver(HandleCloseObserver* observer) { | 49 void HandleWrapper::RemoveCloseObserver(HandleCloseObserver* observer) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 92 } |
75 | 93 |
76 bool Converter<mojo::MessagePipeHandle>::FromV8(v8::Isolate* isolate, | 94 bool Converter<mojo::MessagePipeHandle>::FromV8(v8::Isolate* isolate, |
77 v8::Handle<v8::Value> val, | 95 v8::Handle<v8::Value> val, |
78 mojo::MessagePipeHandle* out) { | 96 mojo::MessagePipeHandle* out) { |
79 return Converter<mojo::Handle>::FromV8(isolate, val, out); | 97 return Converter<mojo::Handle>::FromV8(isolate, val, out); |
80 } | 98 } |
81 | 99 |
82 | 100 |
83 } // namespace gin | 101 } // namespace gin |
OLD | NEW |