Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1161)

Side by Side Diff: mojo/bindings/js/handle.h

Issue 686203004: Mojo JS Bindings: Simplify sharing services for content-provided JS applications (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // there's no way to prevent against accidental use. 58 // there's no way to prevent against accidental use.
59 // TODO(mpcomplete): define converters for all Handle subtypes. 59 // TODO(mpcomplete): define converters for all Handle subtypes.
60 template<> 60 template<>
61 struct Converter<mojo::Handle> { 61 struct Converter<mojo::Handle> {
62 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 62 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
63 const mojo::Handle& val); 63 const mojo::Handle& val);
64 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, 64 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
65 mojo::Handle* out); 65 mojo::Handle* out);
66 }; 66 };
67 67
68 template<>
69 struct Converter<mojo::MessagePipeHandle> {
70 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
71 mojo::MessagePipeHandle val);
72 static bool FromV8(v8::Isolate* isolate,
73 v8::Handle<v8::Value> val,
74 mojo::MessagePipeHandle* out);
75 };
76
68 // We need to specialize the normal gin::Handle converter in order to handle 77 // We need to specialize the normal gin::Handle converter in order to handle
69 // converting |null| to a wrapper for an empty mojo::Handle. 78 // converting |null| to a wrapper for an empty mojo::Handle.
70 template<> 79 template<>
71 struct Converter<gin::Handle<mojo::js::HandleWrapper> > { 80 struct Converter<gin::Handle<mojo::js::HandleWrapper> > {
72 static v8::Handle<v8::Value> ToV8( 81 static v8::Handle<v8::Value> ToV8(
73 v8::Isolate* isolate, const gin::Handle<mojo::js::HandleWrapper>& val) { 82 v8::Isolate* isolate, const gin::Handle<mojo::js::HandleWrapper>& val) {
74 return val.ToV8(); 83 return val.ToV8();
75 } 84 }
76 85
77 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, 86 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
78 gin::Handle<mojo::js::HandleWrapper>* out) { 87 gin::Handle<mojo::js::HandleWrapper>* out) {
79 if (val->IsNull()) { 88 if (val->IsNull()) {
80 *out = mojo::js::HandleWrapper::Create(isolate, MOJO_HANDLE_INVALID); 89 *out = mojo::js::HandleWrapper::Create(isolate, MOJO_HANDLE_INVALID);
81 return true; 90 return true;
82 } 91 }
83 92
84 mojo::js::HandleWrapper* object = NULL; 93 mojo::js::HandleWrapper* object = NULL;
85 if (!Converter<mojo::js::HandleWrapper*>::FromV8(isolate, val, &object)) { 94 if (!Converter<mojo::js::HandleWrapper*>::FromV8(isolate, val, &object)) {
86 return false; 95 return false;
87 } 96 }
88 *out = gin::Handle<mojo::js::HandleWrapper>(val, object); 97 *out = gin::Handle<mojo::js::HandleWrapper>(val, object);
89 return true; 98 return true;
90 } 99 }
91 }; 100 };
92 101
93 } // namespace gin 102 } // namespace gin
94 103
95 #endif // MOJO_BINDINGS_JS_HANDLE_H_ 104 #endif // MOJO_BINDINGS_JS_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698