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