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 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
6 #include "sky/engine/bindings/builtin_natives.h" | 6 #include "sky/engine/bindings/builtin_natives.h" |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/time/time.h" |
15 #include "dart/runtime/include/dart_api.h" | 16 #include "dart/runtime/include/dart_api.h" |
16 #include "sky/engine/bindings/builtin.h" | 17 #include "sky/engine/bindings/builtin.h" |
17 #include "sky/engine/core/dom/Microtask.h" | 18 #include "sky/engine/core/dom/Microtask.h" |
18 #include "sky/engine/core/script/dom_dart_state.h" | 19 #include "sky/engine/core/script/dom_dart_state.h" |
19 #include "sky/engine/tonic/dart_api_scope.h" | 20 #include "sky/engine/tonic/dart_api_scope.h" |
20 #include "sky/engine/tonic/dart_builtin.h" | 21 #include "sky/engine/tonic/dart_builtin.h" |
21 #include "sky/engine/tonic/dart_error.h" | 22 #include "sky/engine/tonic/dart_error.h" |
22 #include "sky/engine/tonic/dart_invoke.h" | 23 #include "sky/engine/tonic/dart_invoke.h" |
23 #include "sky/engine/tonic/dart_isolate_scope.h" | 24 #include "sky/engine/tonic/dart_isolate_scope.h" |
24 #include "sky/engine/tonic/dart_state.h" | 25 #include "sky/engine/tonic/dart_state.h" |
| 26 #include "sky/engine/tonic/dart_timer_heap.h" |
25 #include "sky/engine/tonic/dart_value.h" | 27 #include "sky/engine/tonic/dart_value.h" |
26 #include "sky/engine/wtf/text/WTFString.h" | 28 #include "sky/engine/wtf/text/WTFString.h" |
27 | 29 |
28 namespace blink { | 30 namespace blink { |
29 | 31 |
30 #define REGISTER_FUNCTION(name, count) \ | 32 #define REGISTER_FUNCTION(name, count) \ |
31 { "" #name, name, count }, | 33 { "" #name, name, count }, |
32 #define DECLARE_FUNCTION(name, count) \ | 34 #define DECLARE_FUNCTION(name, count) \ |
33 extern void name(Dart_NativeArguments args); | 35 extern void name(Dart_NativeArguments args); |
34 | 36 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 Dart_Handle closure = Dart_GetNativeArgument(args, 0); | 185 Dart_Handle closure = Dart_GetNativeArgument(args, 0); |
184 if (LogIfError(closure) || !Dart_IsClosure(closure)) | 186 if (LogIfError(closure) || !Dart_IsClosure(closure)) |
185 return; | 187 return; |
186 DartState* dart_state = DartState::Current(); | 188 DartState* dart_state = DartState::Current(); |
187 CHECK(dart_state); | 189 CHECK(dart_state); |
188 Microtask::enqueueMicrotask(base::Bind(&ExecuteMicrotask, | 190 Microtask::enqueueMicrotask(base::Bind(&ExecuteMicrotask, |
189 dart_state->GetWeakPtr(), DartValue::Create(dart_state, closure))); | 191 dart_state->GetWeakPtr(), DartValue::Create(dart_state, closure))); |
190 } | 192 } |
191 | 193 |
192 void GetBaseURLString(Dart_NativeArguments args) { | 194 void GetBaseURLString(Dart_NativeArguments args) { |
193 String url = DOMDartState::CurrentDocument()->url().string(); | 195 String url; |
| 196 if (Document* document = DOMDartState::CurrentDocument()) |
| 197 url = document->url().string(); |
194 Dart_SetReturnValue(args, StringToDart(DartState::Current(), url)); | 198 Dart_SetReturnValue(args, StringToDart(DartState::Current(), url)); |
195 } | 199 } |
196 | 200 |
197 void Timer_create(Dart_NativeArguments args) { | 201 void Timer_create(Dart_NativeArguments args) { |
198 int64_t milliseconds = 0; | 202 int64_t milliseconds = 0; |
199 DART_CHECK_VALID(Dart_GetNativeIntegerArgument(args, 0, &milliseconds)); | 203 DART_CHECK_VALID(Dart_GetNativeIntegerArgument(args, 0, &milliseconds)); |
200 Dart_Handle closure = Dart_GetNativeArgument(args, 1); | 204 Dart_Handle closure = Dart_GetNativeArgument(args, 1); |
201 DART_CHECK_VALID(closure); | 205 DART_CHECK_VALID(closure); |
202 CHECK(Dart_IsClosure(closure)); | 206 CHECK(Dart_IsClosure(closure)); |
203 bool repeating = false; | 207 bool repeating = false; |
204 DART_CHECK_VALID(Dart_GetNativeBooleanArgument(args, 2, &repeating)); | 208 DART_CHECK_VALID(Dart_GetNativeBooleanArgument(args, 2, &repeating)); |
205 | 209 |
206 DOMDartState* state = DOMDartState::Current(); | 210 DartState* state = DartState::Current(); |
207 CHECK(state); | 211 CHECK(state); |
208 int timer_id = DOMTimer::install(state->document(), | 212 |
209 ScheduledAction::Create(state, closure), | 213 OwnPtr<DartTimerHeap::Task> task = adoptPtr(new DartTimerHeap::Task); |
210 milliseconds, | 214 task->closure.Set(state, closure); |
211 !repeating); | 215 task->delay = base::TimeDelta::FromMilliseconds(milliseconds); |
| 216 task->repeating = repeating; |
| 217 |
| 218 int timer_id = state->timer_heap().Add(task.release()); |
212 Dart_SetIntegerReturnValue(args, timer_id); | 219 Dart_SetIntegerReturnValue(args, timer_id); |
213 } | 220 } |
214 | 221 |
215 void Timer_cancel(Dart_NativeArguments args) { | 222 void Timer_cancel(Dart_NativeArguments args) { |
216 int64_t timer_id = 0; | 223 int64_t timer_id = 0; |
217 DART_CHECK_VALID(Dart_GetNativeIntegerArgument(args, 0, &timer_id)); | 224 DART_CHECK_VALID(Dart_GetNativeIntegerArgument(args, 0, &timer_id)); |
218 | 225 |
219 DOMDartState* state = DOMDartState::Current(); | 226 DartState* state = DartState::Current(); |
220 CHECK(state); | 227 CHECK(state); |
221 DOMTimer::removeByID(state->document(), timer_id); | 228 state->timer_heap().Remove(timer_id); |
222 } | 229 } |
223 | 230 |
224 } // namespace blink | 231 } // namespace blink |
OLD | NEW |