OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 #include "bindings/v8/ScheduledAction.h" | 35 #include "bindings/v8/ScheduledAction.h" |
36 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
37 #include "bindings/v8/V8Utilities.h" | 37 #include "bindings/v8/V8Utilities.h" |
38 #include "bindings/v8/V8WorkerGlobalScopeEventListener.h" | 38 #include "bindings/v8/V8WorkerGlobalScopeEventListener.h" |
39 #include "bindings/v8/WorkerScriptController.h" | 39 #include "bindings/v8/WorkerScriptController.h" |
40 #include "core/dom/ExceptionCode.h" | 40 #include "core/dom/ExceptionCode.h" |
41 #include "core/inspector/ScriptCallStack.h" | 41 #include "core/inspector/ScriptCallStack.h" |
42 #include "core/page/ContentSecurityPolicy.h" | 42 #include "core/page/ContentSecurityPolicy.h" |
43 #include "core/page/DOMTimer.h" | 43 #include "core/page/DOMTimer.h" |
| 44 #include "core/page/DOMWindowTimers.h" |
44 #include "core/workers/WorkerGlobalScope.h" | 45 #include "core/workers/WorkerGlobalScope.h" |
45 #include "modules/websockets/WebSocket.h" | 46 #include "modules/websockets/WebSocket.h" |
| 47 #include "wtf/OwnArrayPtr.h" |
46 | 48 |
47 namespace WebCore { | 49 namespace WebCore { |
48 | 50 |
49 void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, bool
singleShot) | 51 void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, bool
singleShot) |
50 { | 52 { |
51 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); | 53 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); |
52 | 54 |
53 int argumentCount = args.Length(); | 55 int argumentCount = args.Length(); |
54 if (argumentCount < 1) | 56 if (argumentCount < 1) |
55 return; | 57 return; |
56 | 58 |
57 v8::Handle<v8::Value> function = args[0]; | 59 v8::Handle<v8::Value> function = args[0]; |
58 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; | |
59 int timerId; | |
60 | 60 |
61 WorkerScriptController* script = workerGlobalScope->script(); | 61 WorkerScriptController* script = workerGlobalScope->script(); |
62 if (!script) | 62 if (!script) |
63 return; | 63 return; |
64 | 64 |
| 65 OwnPtr<ScheduledAction> action; |
65 v8::Handle<v8::Context> v8Context = script->context(); | 66 v8::Handle<v8::Context> v8Context = script->context(); |
66 if (function->IsString()) { | 67 if (function->IsString()) { |
67 if (ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPo
licy()) { | 68 if (ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPo
licy()) { |
68 if (!policy->allowEval()) { | 69 if (!policy->allowEval()) { |
69 v8SetReturnValue(args, 0); | 70 v8SetReturnValue(args, 0); |
70 return; | 71 return; |
71 } | 72 } |
72 } | 73 } |
73 WTF::String stringFunction = toWebCoreString(function); | 74 action = adoptPtr(new ScheduledAction(v8Context, toWebCoreString(functio
n), workerGlobalScope->url(), args.GetIsolate())); |
74 timerId = DOMTimer::install(workerGlobalScope, adoptPtr(new ScheduledAct
ion(v8Context, stringFunction, workerGlobalScope->url(), args.GetIsolate())), ti
meout, singleShot); | |
75 } else if (function->IsFunction()) { | 75 } else if (function->IsFunction()) { |
76 size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; | 76 size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; |
77 v8::Local<v8::Value>* params = 0; | 77 OwnArrayPtr<v8::Local<v8::Value> > params; |
78 if (paramCount > 0) { | 78 if (paramCount > 0) { |
79 params = new v8::Local<v8::Value>[paramCount]; | 79 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); |
80 for (size_t i = 0; i < paramCount; ++i) | 80 for (size_t i = 0; i < paramCount; ++i) |
81 params[i] = args[i+2]; | 81 params[i] = args[i+2]; |
82 } | 82 } |
83 // ScheduledAction takes ownership of actual params and releases them in
its destructor. | 83 // ScheduledAction takes ownership of actual params and releases them in
its destructor. |
84 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(v8Context,
v8::Handle<v8::Function>::Cast(function), paramCount, params, args.GetIsolate()
)); | 84 action = adoptPtr(new ScheduledAction(v8Context, v8::Handle<v8::Function
>::Cast(function), paramCount, params.get(), args.GetIsolate())); |
85 // FIXME: We should use a OwnArrayPtr for params. | |
86 delete [] params; | |
87 timerId = DOMTimer::install(workerGlobalScope, action.release(), timeout
, singleShot); | |
88 } else | 85 } else |
89 return; | 86 return; |
90 | 87 |
| 88 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; |
| 89 int timerId; |
| 90 if (singleShot) |
| 91 timerId = DOMWindowTimers::setTimeout(workerGlobalScope, action.release(
), timeout); |
| 92 else |
| 93 timerId = DOMWindowTimers::setInterval(workerGlobalScope, action.release
(), timeout); |
| 94 |
91 v8SetReturnValue(args, timerId); | 95 v8SetReturnValue(args, timerId); |
92 } | 96 } |
93 | 97 |
94 void V8WorkerGlobalScope::importScriptsMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& args) | 98 void V8WorkerGlobalScope::importScriptsMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& args) |
95 { | 99 { |
96 if (!args.Length()) | 100 if (!args.Length()) |
97 return; | 101 return; |
98 | 102 |
99 Vector<String> urls; | 103 Vector<String> urls; |
100 for (int i = 0; i < args.Length(); i++) { | 104 for (int i = 0; i < args.Length(); i++) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 ASSERT(!global.IsEmpty()); | 143 ASSERT(!global.IsEmpty()); |
140 return global; | 144 return global; |
141 } | 145 } |
142 | 146 |
143 v8::Handle<v8::Value> toV8ForMainWorld(WorkerGlobalScope* impl, v8::Handle<v8::O
bject> creationContext, v8::Isolate* isolate) | 147 v8::Handle<v8::Value> toV8ForMainWorld(WorkerGlobalScope* impl, v8::Handle<v8::O
bject> creationContext, v8::Isolate* isolate) |
144 { | 148 { |
145 return toV8(impl, creationContext, isolate); | 149 return toV8(impl, creationContext, isolate); |
146 } | 150 } |
147 | 151 |
148 } // namespace WebCore | 152 } // namespace WebCore |
OLD | NEW |