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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "V8WorkerContext.h" | 33 #include "V8WorkerGlobalScope.h" |
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/V8WorkerContextEventListener.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/workers/WorkerContext.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, bool
singleShot) |
50 { | 50 { |
51 WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); | 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 = workerContext->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 = workerContext->contentSecurityPolicy
()) { | 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(workerContext, adoptPtr(new ScheduledAction(
v8Context, stringFunction, workerContext->url(), args.GetIsolate())), timeout, s
ingleShot); | 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 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(workerContext, action.release(), timeout, si
ngleShot); | 87 timerId = DOMTimer::install(workerGlobalScope, action.release(), timeout
, singleShot); |
88 } else | 88 } else |
89 return; | 89 return; |
90 | 90 |
91 v8SetReturnValue(args, timerId); | 91 v8SetReturnValue(args, timerId); |
92 } | 92 } |
93 | 93 |
94 void V8WorkerContext::importScriptsMethodCustom(const v8::FunctionCallbackInfo<v
8::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; |
98 | 98 |
99 Vector<String> urls; | 99 Vector<String> urls; |
100 for (int i = 0; i < args.Length(); i++) { | 100 for (int i = 0; i < args.Length(); i++) { |
101 V8TRYCATCH_VOID(v8::Handle<v8::String>, scriptUrl, args[i]->ToString()); | 101 V8TRYCATCH_VOID(v8::Handle<v8::String>, scriptUrl, args[i]->ToString()); |
102 if (scriptUrl.IsEmpty()) | 102 if (scriptUrl.IsEmpty()) |
103 return; | 103 return; |
104 urls.append(toWebCoreString(scriptUrl)); | 104 urls.append(toWebCoreString(scriptUrl)); |
105 } | 105 } |
106 | 106 |
107 WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); | 107 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Ho
lder()); |
108 | 108 |
109 ExceptionCode ec = 0; | 109 ExceptionCode ec = 0; |
110 workerContext->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 V8WorkerContext::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, true); |
120 } | 120 } |
121 | 121 |
122 void V8WorkerContext::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, false); |
125 } | 125 } |
126 | 126 |
127 v8::Handle<v8::Value> toV8(WorkerContext* impl, v8::Handle<v8::Object> creationC
ontext, 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 WorkerContex
t 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(WorkerContext* impl, v8::Handle<v8::Objec
t> 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 |