| 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 #ifndef MOJO_BINDINGS_JS_HANDLE_H_ | 5 #ifndef MOJO_BINDINGS_JS_HANDLE_H_ |
| 6 #define MOJO_BINDINGS_JS_HANDLE_H_ | 6 #define MOJO_BINDINGS_JS_HANDLE_H_ |
| 7 | 7 |
| 8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
| 9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
| 10 #include "gin/handle.h" | 10 #include "gin/handle.h" |
| 11 #include "gin/object_template_builder.h" |
| 11 #include "gin/wrappable.h" | 12 #include "gin/wrappable.h" |
| 12 #include "mojo/public/cpp/system/core.h" | 13 #include "mojo/public/cpp/system/core.h" |
| 13 | 14 |
| 14 namespace mojo { | 15 namespace mojo { |
| 15 namespace js { | 16 namespace js { |
| 16 class HandleCloseObserver; | 17 class HandleCloseObserver; |
| 17 | 18 |
| 18 // Wrapper for mojo Handles exposed to JavaScript. This ensures the Handle | 19 // Wrapper for mojo Handles exposed to JavaScript. This ensures the Handle |
| 19 // is Closed when its JS object is garbage collected. | 20 // is Closed when its JS object is garbage collected. |
| 20 class HandleWrapper : public gin::Wrappable<HandleWrapper> { | 21 class HandleWrapper : public gin::Wrappable<HandleWrapper> { |
| 21 public: | 22 public: |
| 22 static gin::WrapperInfo kWrapperInfo; | 23 static gin::WrapperInfo kWrapperInfo; |
| 23 | 24 |
| 24 static gin::Handle<HandleWrapper> Create(v8::Isolate* isolate, | 25 static gin::Handle<HandleWrapper> Create(v8::Isolate* isolate, |
| 25 MojoHandle handle) { | 26 MojoHandle handle) { |
| 26 return gin::CreateHandle(isolate, new HandleWrapper(handle)); | 27 return gin::CreateHandle(isolate, new HandleWrapper(handle)); |
| 27 } | 28 } |
| 28 | 29 |
| 30 std::string ToString(); |
| 31 |
| 32 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate) |
| 33 override; |
| 34 |
| 29 mojo::Handle get() const { return handle_.get(); } | 35 mojo::Handle get() const { return handle_.get(); } |
| 30 mojo::Handle release() { return handle_.release(); } | 36 mojo::Handle release() { return handle_.release(); } |
| 31 void Close(); | 37 void Close(); |
| 32 | 38 |
| 33 void AddCloseObserver(HandleCloseObserver* observer); | 39 void AddCloseObserver(HandleCloseObserver* observer); |
| 34 void RemoveCloseObserver(HandleCloseObserver* observer); | 40 void RemoveCloseObserver(HandleCloseObserver* observer); |
| 35 | 41 |
| 36 protected: | 42 protected: |
| 37 HandleWrapper(MojoHandle handle); | 43 HandleWrapper(MojoHandle handle); |
| 38 ~HandleWrapper() override; | 44 ~HandleWrapper() override; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return false; | 86 return false; |
| 81 } | 87 } |
| 82 *out = gin::Handle<mojo::js::HandleWrapper>(val, object); | 88 *out = gin::Handle<mojo::js::HandleWrapper>(val, object); |
| 83 return true; | 89 return true; |
| 84 } | 90 } |
| 85 }; | 91 }; |
| 86 | 92 |
| 87 } // namespace gin | 93 } // namespace gin |
| 88 | 94 |
| 89 #endif // MOJO_BINDINGS_JS_HANDLE_H_ | 95 #endif // MOJO_BINDINGS_JS_HANDLE_H_ |
| OLD | NEW |