OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2011 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. | 71 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. |
72 // We should refactor this. | 72 // We should refactor this. |
73 void windowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& info, bool
singleShot, ExceptionState& exceptionState) | 73 void windowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& info, bool
singleShot, ExceptionState& exceptionState) |
74 { | 74 { |
75 int argumentCount = info.Length(); | 75 int argumentCount = info.Length(); |
76 | 76 |
77 if (argumentCount < 1) | 77 if (argumentCount < 1) |
78 return; | 78 return; |
79 | 79 |
80 DOMWindow* imp = V8Window::toNative(info.Holder()); | 80 DOMWindow* impl = V8Window::toNative(info.Holder()); |
81 if (!imp->frame() || !imp->document()) { | 81 if (!impl->frame() || !impl->document()) { |
82 exceptionState.throwDOMException(InvalidAccessError, "No script context
is available in which to execute the script."); | 82 exceptionState.throwDOMException(InvalidAccessError, "No script context
is available in which to execute the script."); |
83 return; | 83 return; |
84 } | 84 } |
85 v8::Handle<v8::Context> context = toV8Context(info.GetIsolate(), imp->frame(
), DOMWrapperWorld::current(info.GetIsolate())); | 85 v8::Handle<v8::Context> context = toV8Context(info.GetIsolate(), impl->frame
(), DOMWrapperWorld::current(info.GetIsolate())); |
86 if (context.IsEmpty()) { | 86 if (context.IsEmpty()) { |
87 exceptionState.throwDOMException(InvalidAccessError, "No script context
is available in which to execute the script."); | 87 exceptionState.throwDOMException(InvalidAccessError, "No script context
is available in which to execute the script."); |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 v8::Handle<v8::Value> function = info[0]; | 91 v8::Handle<v8::Value> function = info[0]; |
92 String functionString; | 92 String functionString; |
93 if (!function->IsFunction()) { | 93 if (!function->IsFunction()) { |
94 if (function->IsString()) { | 94 if (function->IsString()) { |
95 functionString = toCoreString(function.As<v8::String>()); | 95 functionString = toCoreString(function.As<v8::String>()); |
96 } else { | 96 } else { |
97 v8::Handle<v8::String> v8String = function->ToString(); | 97 v8::Handle<v8::String> v8String = function->ToString(); |
98 | 98 |
99 // Bail out if string conversion failed. | 99 // Bail out if string conversion failed. |
100 if (v8String.IsEmpty()) | 100 if (v8String.IsEmpty()) |
101 return; | 101 return; |
102 | 102 |
103 functionString = toCoreString(v8String); | 103 functionString = toCoreString(v8String); |
104 } | 104 } |
105 | 105 |
106 // Don't allow setting timeouts to run empty functions! | 106 // Don't allow setting timeouts to run empty functions! |
107 // (Bug 1009597) | 107 // (Bug 1009597) |
108 if (!functionString.length()) | 108 if (!functionString.length()) |
109 return; | 109 return; |
110 } | 110 } |
111 | 111 |
112 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame
(), exceptionState)) | 112 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) |
113 return; | 113 return; |
114 | 114 |
115 OwnPtr<ScheduledAction> action; | 115 OwnPtr<ScheduledAction> action; |
116 if (function->IsFunction()) { | 116 if (function->IsFunction()) { |
117 int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; | 117 int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; |
118 OwnPtr<v8::Local<v8::Value>[]> params; | 118 OwnPtr<v8::Local<v8::Value>[]> params; |
119 if (paramCount > 0) { | 119 if (paramCount > 0) { |
120 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); | 120 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); |
121 for (int i = 0; i < paramCount; i++) { | 121 for (int i = 0; i < paramCount; i++) { |
122 // parameters must be globalized | 122 // parameters must be globalized |
123 params[i] = info[i+2]; | 123 params[i] = info[i+2]; |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 // params is passed to action, and released in action's destructor | 127 // params is passed to action, and released in action's destructor |
128 ASSERT(imp->frame()); | 128 ASSERT(impl->frame()); |
129 action = adoptPtr(new ScheduledAction(context, v8::Handle<v8::Function>:
:Cast(function), paramCount, params.get(), info.GetIsolate())); | 129 action = adoptPtr(new ScheduledAction(context, v8::Handle<v8::Function>:
:Cast(function), paramCount, params.get(), info.GetIsolate())); |
130 } else { | 130 } else { |
131 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE
val()) { | 131 if (impl->document() && !impl->document()->contentSecurityPolicy()->allo
wEval()) { |
132 v8SetReturnValue(info, 0); | 132 v8SetReturnValue(info, 0); |
133 return; | 133 return; |
134 } | 134 } |
135 ASSERT(imp->frame()); | 135 ASSERT(impl->frame()); |
136 action = adoptPtr(new ScheduledAction(context, functionString, KURL(), i
nfo.GetIsolate())); | 136 action = adoptPtr(new ScheduledAction(context, functionString, KURL(), i
nfo.GetIsolate())); |
137 } | 137 } |
138 | 138 |
139 int32_t timeout = argumentCount >= 2 ? info[1]->Int32Value() : 0; | 139 int32_t timeout = argumentCount >= 2 ? info[1]->Int32Value() : 0; |
140 int timerId; | 140 int timerId; |
141 if (singleShot) | 141 if (singleShot) |
142 timerId = DOMWindowTimers::setTimeout(*imp, action.release(), timeout); | 142 timerId = DOMWindowTimers::setTimeout(*impl, action.release(), timeout); |
143 else | 143 else |
144 timerId = DOMWindowTimers::setInterval(*imp, action.release(), timeout); | 144 timerId = DOMWindowTimers::setInterval(*impl, action.release(), timeout)
; |
145 | 145 |
146 // Try to do the idle notification before the timeout expires to get better | 146 // Try to do the idle notification before the timeout expires to get better |
147 // use of any idle time. Aim for the middle of the interval for simplicity. | 147 // use of any idle time. Aim for the middle of the interval for simplicity. |
148 if (timeout >= 0) { | 148 if (timeout >= 0) { |
149 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; | 149 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; |
150 V8GCForContextDispose::instanceTemplate().notifyIdleSooner(maximumFireIn
terval); | 150 V8GCForContextDispose::instanceTemplate().notifyIdleSooner(maximumFireIn
terval); |
151 } | 151 } |
152 | 152 |
153 v8SetReturnValue(info, timerId); | 153 v8SetReturnValue(info, timerId); |
154 } | 154 } |
(...skipping 30 matching lines...) Expand all Loading... |
185 ASSERT(frame); | 185 ASSERT(frame); |
186 v8::Local<v8::Context> context = toV8Context(info.GetIsolate(), frame, DOMWr
apperWorld::current(info.GetIsolate())); | 186 v8::Local<v8::Context> context = toV8Context(info.GetIsolate(), frame, DOMWr
apperWorld::current(info.GetIsolate())); |
187 if (context.IsEmpty()) | 187 if (context.IsEmpty()) |
188 return; | 188 return; |
189 | 189 |
190 V8HiddenValue::setHiddenValue(info.GetIsolate(), context->Global(), V8Hidden
Value::event(info.GetIsolate()), value); | 190 V8HiddenValue::setHiddenValue(info.GetIsolate(), context->Global(), V8Hidden
Value::event(info.GetIsolate()), value); |
191 } | 191 } |
192 | 192 |
193 void V8Window::frameElementAttributeGetterCustom(const v8::PropertyCallbackInfo<
v8::Value>& info) | 193 void V8Window::frameElementAttributeGetterCustom(const v8::PropertyCallbackInfo<
v8::Value>& info) |
194 { | 194 { |
195 DOMWindow* imp = V8Window::toNative(info.Holder()); | 195 DOMWindow* impl = V8Window::toNative(info.Holder()); |
196 ExceptionState exceptionState(ExceptionState::GetterContext, "frame", "Windo
w", info.Holder(), info.GetIsolate()); | 196 ExceptionState exceptionState(ExceptionState::GetterContext, "frame", "Windo
w", info.Holder(), info.GetIsolate()); |
197 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), imp->frameE
lement(), exceptionState)) { | 197 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->frame
Element(), exceptionState)) { |
198 v8SetReturnValueNull(info); | 198 v8SetReturnValueNull(info); |
199 exceptionState.throwIfNeeded(); | 199 exceptionState.throwIfNeeded(); |
200 return; | 200 return; |
201 } | 201 } |
202 | 202 |
203 // The wrapper for an <iframe> should get its prototype from the context of
the frame it's in, rather than its own frame. | 203 // The wrapper for an <iframe> should get its prototype from the context of
the frame it's in, rather than its own frame. |
204 // So, use its containing document as the creation context when wrapping. | 204 // So, use its containing document as the creation context when wrapping. |
205 v8::Handle<v8::Value> creationContext = toV8(&imp->frameElement()->document(
), v8::Handle<v8::Object>(), info.GetIsolate()); | 205 v8::Handle<v8::Value> creationContext = toV8(&impl->frameElement()->document
(), v8::Handle<v8::Object>(), info.GetIsolate()); |
206 RELEASE_ASSERT(!creationContext.IsEmpty()); | 206 RELEASE_ASSERT(!creationContext.IsEmpty()); |
207 v8::Handle<v8::Value> wrapper = toV8(imp->frameElement(), v8::Handle<v8::Obj
ect>::Cast(creationContext), info.GetIsolate()); | 207 v8::Handle<v8::Value> wrapper = toV8(impl->frameElement(), v8::Handle<v8::Ob
ject>::Cast(creationContext), info.GetIsolate()); |
208 v8SetReturnValue(info, wrapper); | 208 v8SetReturnValue(info, wrapper); |
209 } | 209 } |
210 | 210 |
211 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8:
:PropertyCallbackInfo<void>& info) | 211 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8:
:PropertyCallbackInfo<void>& info) |
212 { | 212 { |
213 DOMWindow* imp = V8Window::toNative(info.Holder()); | 213 DOMWindow* impl = V8Window::toNative(info.Holder()); |
214 ExceptionState exceptionState(ExceptionState::SetterContext, "opener", "Wind
ow", info.Holder(), info.GetIsolate()); | 214 ExceptionState exceptionState(ExceptionState::SetterContext, "opener", "Wind
ow", info.Holder(), info.GetIsolate()); |
215 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame
(), exceptionState)) { | 215 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { |
216 exceptionState.throwIfNeeded(); | 216 exceptionState.throwIfNeeded(); |
217 return; | 217 return; |
218 } | 218 } |
219 | 219 |
220 // Opener can be shadowed if it is in the same domain. | 220 // Opener can be shadowed if it is in the same domain. |
221 // Have a special handling of null value to behave | 221 // Have a special handling of null value to behave |
222 // like Firefox. See bug http://b/1224887 & http://b/791706. | 222 // like Firefox. See bug http://b/1224887 & http://b/791706. |
223 if (value->IsNull()) { | 223 if (value->IsNull()) { |
224 // imp->frame() cannot be null, | 224 // impl->frame() cannot be null, |
225 // otherwise, SameOrigin check would have failed. | 225 // otherwise, SameOrigin check would have failed. |
226 ASSERT(imp->frame()); | 226 ASSERT(impl->frame()); |
227 imp->frame()->loader().setOpener(0); | 227 impl->frame()->loader().setOpener(0); |
228 } | 228 } |
229 | 229 |
230 // Delete the accessor from this object. | 230 // Delete the accessor from this object. |
231 info.Holder()->Delete(v8AtomicString(info.GetIsolate(), "opener")); | 231 info.Holder()->Delete(v8AtomicString(info.GetIsolate(), "opener")); |
232 | 232 |
233 // Put property on the front (this) object. | 233 // Put property on the front (this) object. |
234 info.This()->Set(v8AtomicString(info.GetIsolate(), "opener"), value); | 234 info.This()->Set(v8AtomicString(info.GetIsolate(), "opener"), value); |
235 } | 235 } |
236 | 236 |
237 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value) | 237 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value) |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 v8::Handle<v8::Context> context = toV8Context(isolate, frame, DOMWrapperWorl
d::current(isolate)); | 553 v8::Handle<v8::Context> context = toV8Context(isolate, frame, DOMWrapperWorl
d::current(isolate)); |
554 if (context.IsEmpty()) | 554 if (context.IsEmpty()) |
555 return v8Undefined(); | 555 return v8Undefined(); |
556 | 556 |
557 v8::Handle<v8::Object> global = context->Global(); | 557 v8::Handle<v8::Object> global = context->Global(); |
558 ASSERT(!global.IsEmpty()); | 558 ASSERT(!global.IsEmpty()); |
559 return global; | 559 return global; |
560 } | 560 } |
561 | 561 |
562 } // namespace WebCore | 562 } // namespace WebCore |
OLD | NEW |