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

Side by Side Diff: mojo/public/bindings/js/support.cc

Issue 93813002: Implement gin::ObjectTemplateBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asdf Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/js/core.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/public/bindings/js/support.h" 5 #include "mojo/public/bindings/js/support.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "gin/arguments.h" 8 #include "gin/arguments.h"
9 #include "gin/converter.h" 9 #include "gin/converter.h"
10 #include "gin/function_template.h" 10 #include "gin/function_template.h"
11 #include "gin/object_template_builder.h"
11 #include "gin/per_isolate_data.h" 12 #include "gin/per_isolate_data.h"
12 #include "gin/public/wrapper_info.h" 13 #include "gin/public/wrapper_info.h"
13 #include "gin/wrappable.h" 14 #include "gin/wrappable.h"
14 #include "mojo/public/bindings/js/handle.h" 15 #include "mojo/public/bindings/js/handle.h"
15 #include "mojo/public/bindings/js/waiting_callback.h" 16 #include "mojo/public/bindings/js/waiting_callback.h"
16 #include "mojo/public/bindings/lib/bindings_support.h" 17 #include "mojo/public/bindings/lib/bindings_support.h"
17 18
18 namespace mojo { 19 namespace mojo {
19 namespace js { 20 namespace js {
20 21
21 namespace { 22 namespace {
22 23
23 void AsyncWait(const v8::FunctionCallbackInfo<v8::Value>& info) { 24 WaitingCallback* AsyncWait(const gin::Arguments& args, mojo::Handle handle,
24 gin::Arguments args(info); 25 MojoWaitFlags flags,
25 26 v8::Handle<v8::Function> callback) {
26 mojo::Handle handle;
27 MojoWaitFlags flags = MOJO_WAIT_FLAG_NONE;
28 v8::Handle<v8::Function> callback;
29
30 if (!args.GetNext(&handle) ||
31 !args.GetNext(&flags) ||
32 !args.GetNext(&callback))
33 return args.ThrowError();
34
35 scoped_refptr<WaitingCallback> waiting_callback = 27 scoped_refptr<WaitingCallback> waiting_callback =
36 WaitingCallback::Create(args.isolate(), callback); 28 WaitingCallback::Create(args.isolate(), callback);
37 29
38 BindingsSupport::AsyncWaitID wait_id = BindingsSupport::Get()->AsyncWait( 30 BindingsSupport::AsyncWaitID wait_id = BindingsSupport::Get()->AsyncWait(
39 handle, flags, waiting_callback.get()); 31 handle, flags, waiting_callback.get());
40 32
41 waiting_callback->set_wait_id(wait_id); 33 waiting_callback->set_wait_id(wait_id);
42 34
43 args.Return(waiting_callback.get()); 35 return waiting_callback.get();
44 } 36 }
45 37
46 void CancelWait(WaitingCallback* waiting_callback) { 38 void CancelWait(WaitingCallback* waiting_callback) {
47 if (!waiting_callback->wait_id()) 39 if (!waiting_callback->wait_id())
48 return; 40 return;
49 BindingsSupport::Get()->CancelWait(waiting_callback->wait_id()); 41 BindingsSupport::Get()->CancelWait(waiting_callback->wait_id());
50 waiting_callback->set_wait_id(NULL); 42 waiting_callback->set_wait_id(NULL);
51 } 43 }
52 44
53 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; 45 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
54 46
55 } // namespace 47 } // namespace
56 48
57 const char Support::kModuleName[] = "mojo/public/bindings/js/support"; 49 const char Support::kModuleName[] = "mojo/public/bindings/js/support";
58 50
59 v8::Local<v8::ObjectTemplate> Support::GetTemplate(v8::Isolate* isolate) { 51 v8::Local<v8::ObjectTemplate> Support::GetTemplate(v8::Isolate* isolate) {
60 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); 52 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
61 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( 53 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
62 &g_wrapper_info); 54 &g_wrapper_info);
63 55
64 if (templ.IsEmpty()) { 56 if (templ.IsEmpty()) {
65 WaitingCallback::EnsureRegistered(isolate); 57 WaitingCallback::EnsureRegistered(isolate);
66 58
67 templ = v8::ObjectTemplate::New(isolate); 59 templ = gin::ObjectTemplateBuilder(isolate)
68 60 .SetMethod("asyncWait", AsyncWait)
69 templ->Set(gin::StringToSymbol(isolate, "asyncWait"), 61 .SetMethod("cancelWait", CancelWait)
70 v8::FunctionTemplate::New(isolate, AsyncWait)); 62 .Build();
71 templ->Set(gin::StringToSymbol(isolate, "cancelWait"),
72 gin::CreateFunctionTemplate(isolate, base::Bind(CancelWait)));
73 63
74 data->SetObjectTemplate(&g_wrapper_info, templ); 64 data->SetObjectTemplate(&g_wrapper_info, templ);
75 } 65 }
76 66
77 return templ; 67 return templ;
78 } 68 }
79 69
80 } // namespace js 70 } // namespace js
81 } // namespace mojo 71 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/bindings/js/core.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698