Chromium Code Reviews| 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 #include <sstream> | |
| 7 #include "mojo/bindings/js/handle_close_observer.h" | 8 #include "mojo/bindings/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 << " " << std::hex << this; | |
|
abarth-chromium
2014/10/24 17:13:27
I don't think you want to leak the address of |thi
hansmuller
2014/10/24 18:14:02
OK, I've removed that.
| |
| 31 oss << "]"; | |
| 32 return oss.str(); | |
| 33 } | |
| 34 | |
| 35 gin::ObjectTemplateBuilder HandleWrapper::GetObjectTemplateBuilder( | |
| 36 v8::Isolate* isolate) { | |
| 37 return Wrappable<HandleWrapper>::GetObjectTemplateBuilder(isolate) | |
| 38 .SetMethod("toString", &HandleWrapper::ToString); | |
| 39 } | |
| 40 | |
| 22 void HandleWrapper::Close() { | 41 void HandleWrapper::Close() { |
| 23 NotifyCloseObservers(); | 42 NotifyCloseObservers(); |
| 24 handle_.reset(); | 43 handle_.reset(); |
| 25 } | 44 } |
| 26 | 45 |
| 27 void HandleWrapper::AddCloseObserver(HandleCloseObserver* observer) { | 46 void HandleWrapper::AddCloseObserver(HandleCloseObserver* observer) { |
| 28 close_observers_.AddObserver(observer); | 47 close_observers_.AddObserver(observer); |
| 29 } | 48 } |
| 30 | 49 |
| 31 void HandleWrapper::RemoveCloseObserver(HandleCloseObserver* observer) { | 50 void HandleWrapper::RemoveCloseObserver(HandleCloseObserver* observer) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 62 gin::Handle<mojo::js::HandleWrapper> handle; | 81 gin::Handle<mojo::js::HandleWrapper> handle; |
| 63 if (!Converter<gin::Handle<mojo::js::HandleWrapper> >::FromV8( | 82 if (!Converter<gin::Handle<mojo::js::HandleWrapper> >::FromV8( |
| 64 isolate, val, &handle)) | 83 isolate, val, &handle)) |
| 65 return false; | 84 return false; |
| 66 | 85 |
| 67 *out = handle->get(); | 86 *out = handle->get(); |
| 68 return true; | 87 return true; |
| 69 } | 88 } |
| 70 | 89 |
| 71 } // namespace gin | 90 } // namespace gin |
| OLD | NEW |