| 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 28 matching lines...) Expand all Loading... |
| 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/workers/WorkerGlobalScope.h" | 44 #include "core/workers/WorkerGlobalScope.h" |
| 45 #include "modules/websockets/WebSocket.h" | 45 #include "modules/websockets/WebSocket.h" |
| 46 | 46 |
| 47 namespace WebCore { | 47 namespace WebCore { |
| 48 | 48 |
| 49 void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, bool
singleShot) | 49 void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, DOMTi
mer::TimerType timerType) |
| 50 { | 50 { |
| 51 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); | 51 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); |
| 52 | 52 |
| 53 int argumentCount = args.Length(); | 53 int argumentCount = args.Length(); |
| 54 if (argumentCount < 1) | 54 if (argumentCount < 1) |
| 55 return; | 55 return; |
| 56 | 56 |
| 57 v8::Handle<v8::Value> function = args[0]; | 57 v8::Handle<v8::Value> function = args[0]; |
| 58 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; | 58 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; |
| 59 int timerId; | 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 v8::Handle<v8::Context> v8Context = script->context(); | 65 v8::Handle<v8::Context> v8Context = script->context(); |
| 66 if (function->IsString()) { | 66 if (function->IsString()) { |
| 67 if (ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPo
licy()) { | 67 if (ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPo
licy()) { |
| 68 if (!policy->allowEval()) { | 68 if (!policy->allowEval()) { |
| 69 v8SetReturnValue(args, 0); | 69 v8SetReturnValue(args, 0); |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 WTF::String stringFunction = toWebCoreString(function); | 73 WTF::String stringFunction = toWebCoreString(function); |
| 74 timerId = DOMTimer::install(workerGlobalScope, adoptPtr(new ScheduledAct
ion(v8Context, stringFunction, workerGlobalScope->url(), args.GetIsolate())), ti
meout, singleShot); | 74 timerId = DOMTimer::install(workerGlobalScope, timerType, adoptPtr(new S
cheduledAction(v8Context, stringFunction, workerGlobalScope->url(), args.GetIsol
ate())), timeout); |
| 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 v8::Local<v8::Value>* params = 0; |
| 78 if (paramCount > 0) { | 78 if (paramCount > 0) { |
| 79 params = new v8::Local<v8::Value>[paramCount]; | 79 params = 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 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(v8Context,
v8::Handle<v8::Function>::Cast(function), paramCount, params, args.GetIsolate()
)); |
| 85 // FIXME: We should use a OwnArrayPtr for params. | 85 // FIXME: We should use a OwnArrayPtr for params. |
| 86 delete [] params; | 86 delete [] params; |
| 87 timerId = DOMTimer::install(workerGlobalScope, action.release(), timeout
, singleShot); | 87 timerId = DOMTimer::install(workerGlobalScope, timerType, action.release
(), timeout); |
| 88 } else | 88 } else |
| 89 return; | 89 return; |
| 90 | 90 |
| 91 v8SetReturnValue(args, timerId); | 91 v8SetReturnValue(args, timerId); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void V8WorkerGlobalScope::importScriptsMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& args) | 94 void V8WorkerGlobalScope::importScriptsMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& args) |
| 95 { | 95 { |
| 96 if (!args.Length()) | 96 if (!args.Length()) |
| 97 return; | 97 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 109 ExceptionCode ec = 0; | 109 ExceptionCode ec = 0; |
| 110 workerGlobalScope->importScripts(urls, ec); | 110 workerGlobalScope->importScripts(urls, ec); |
| 111 | 111 |
| 112 if (!ec) | 112 if (!ec) |
| 113 return; | 113 return; |
| 114 setDOMException(ec, args.GetIsolate()); | 114 setDOMException(ec, args.GetIsolate()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void V8WorkerGlobalScope::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& args) | 117 void V8WorkerGlobalScope::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& args) |
| 118 { | 118 { |
| 119 return SetTimeoutOrInterval(args, true); | 119 return SetTimeoutOrInterval(args, DOMTimer::TimerTypeTimeout); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void V8WorkerGlobalScope::setIntervalMethodCustom(const v8::FunctionCallbackInfo
<v8::Value>& args) | 122 void V8WorkerGlobalScope::setIntervalMethodCustom(const v8::FunctionCallbackInfo
<v8::Value>& args) |
| 123 { | 123 { |
| 124 return SetTimeoutOrInterval(args, false); | 124 return SetTimeoutOrInterval(args, DOMTimer::TimerTypeInterval); |
| 125 } | 125 } |
| 126 | 126 |
| 127 v8::Handle<v8::Value> toV8(WorkerGlobalScope* impl, v8::Handle<v8::Object> creat
ionContext, v8::Isolate* isolate) | 127 v8::Handle<v8::Value> toV8(WorkerGlobalScope* impl, v8::Handle<v8::Object> creat
ionContext, v8::Isolate* isolate) |
| 128 { | 128 { |
| 129 // Notice that we explicitly ignore creationContext because the WorkerGlobal
Scope is its own creationContext. | 129 // Notice that we explicitly ignore creationContext because the WorkerGlobal
Scope is its own creationContext. |
| 130 | 130 |
| 131 if (!impl) | 131 if (!impl) |
| 132 return v8NullWithCheck(isolate); | 132 return v8NullWithCheck(isolate); |
| 133 | 133 |
| 134 WorkerScriptController* script = impl->script(); | 134 WorkerScriptController* script = impl->script(); |
| 135 if (!script) | 135 if (!script) |
| 136 return v8NullWithCheck(isolate); | 136 return v8NullWithCheck(isolate); |
| 137 | 137 |
| 138 v8::Handle<v8::Object> global = script->context()->Global(); | 138 v8::Handle<v8::Object> global = script->context()->Global(); |
| 139 ASSERT(!global.IsEmpty()); | 139 ASSERT(!global.IsEmpty()); |
| 140 return global; | 140 return global; |
| 141 } | 141 } |
| 142 | 142 |
| 143 v8::Handle<v8::Value> toV8ForMainWorld(WorkerGlobalScope* impl, v8::Handle<v8::O
bject> creationContext, v8::Isolate* isolate) | 143 v8::Handle<v8::Value> toV8ForMainWorld(WorkerGlobalScope* impl, v8::Handle<v8::O
bject> creationContext, v8::Isolate* isolate) |
| 144 { | 144 { |
| 145 return toV8(impl, creationContext, isolate); | 145 return toV8(impl, creationContext, isolate); |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace WebCore | 148 } // namespace WebCore |
| OLD | NEW |