OLD | NEW |
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/apps/js/bindings/waiting_callback.h" | 5 #include "mojo/apps/js/bindings/waiting_callback.h" |
6 | 6 |
7 #include "gin/per_context_data.h" | 7 #include "gin/per_context_data.h" |
8 #include "gin/per_isolate_data.h" | 8 #include "gin/per_isolate_data.h" |
9 | 9 |
10 INIT_WRAPPABLE(mojo::js::WaitingCallback); | |
11 | |
12 namespace mojo { | 10 namespace mojo { |
13 namespace js { | 11 namespace js { |
14 | 12 |
15 namespace { | 13 namespace { |
16 | 14 |
17 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) { | 15 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) { |
18 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback"); | 16 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback"); |
19 } | 17 } |
20 | 18 |
21 } // namespace | 19 } // namespace |
22 | 20 |
| 21 gin::WrapperInfo WaitingCallback::kWrapperInfo = { gin::kEmbedderNativeGin }; |
| 22 |
23 WaitingCallback::WaitingCallback(v8::Isolate* isolate, | 23 WaitingCallback::WaitingCallback(v8::Isolate* isolate, |
24 v8::Handle<v8::Function> callback) | 24 v8::Handle<v8::Function> callback) |
25 : wait_id_() { | 25 : wait_id_() { |
26 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | 26 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
27 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); | 27 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); |
28 GetWrapper(isolate)->SetHiddenValue(GetHiddenPropertyName(isolate), callback); | 28 GetWrapper(isolate)->SetHiddenValue(GetHiddenPropertyName(isolate), callback); |
29 } | 29 } |
30 | 30 |
31 WaitingCallback::~WaitingCallback() { | 31 WaitingCallback::~WaitingCallback() { |
32 DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled."; | 32 DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled."; |
(...skipping 27 matching lines...) Expand all Loading... |
60 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate)); | 60 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate)); |
61 v8::Handle<v8::Function> callback; | 61 v8::Handle<v8::Function> callback; |
62 CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback)); | 62 CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback)); |
63 | 63 |
64 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) }; | 64 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) }; |
65 runner_->Call(callback, runner_->global(), 1, args); | 65 runner_->Call(callback, runner_->global(), 1, args); |
66 } | 66 } |
67 | 67 |
68 } // namespace js | 68 } // namespace js |
69 } // namespace mojo | 69 } // namespace mojo |
OLD | NEW |