Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: Source/bindings/v8/custom/V8WindowCustom.cpp

Issue 17031006: Rename DOMWindow interface to Window (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/custom/V8SVGPathSegCustom.cpp ('k') | Source/core/core.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
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 #include "V8DOMWindow.h" 32 #include "V8Window.h"
33 33
34 #include "V8HTMLCollection.h" 34 #include "V8HTMLCollection.h"
35 #include "V8Node.h" 35 #include "V8Node.h"
36 #include "bindings/v8/BindingSecurity.h" 36 #include "bindings/v8/BindingSecurity.h"
37 #include "bindings/v8/ScheduledAction.h" 37 #include "bindings/v8/ScheduledAction.h"
38 #include "bindings/v8/ScriptController.h" 38 #include "bindings/v8/ScriptController.h"
39 #include "bindings/v8/ScriptSourceCode.h" 39 #include "bindings/v8/ScriptSourceCode.h"
40 #include "bindings/v8/SerializedScriptValue.h" 40 #include "bindings/v8/SerializedScriptValue.h"
41 #include "bindings/v8/V8Binding.h" 41 #include "bindings/v8/V8Binding.h"
42 #include "bindings/v8/V8EventListener.h" 42 #include "bindings/v8/V8EventListener.h"
(...skipping 26 matching lines...) Expand all
69 69
70 namespace WebCore { 70 namespace WebCore {
71 71
72 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool singleShot) 72 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool singleShot)
73 { 73 {
74 int argumentCount = args.Length(); 74 int argumentCount = args.Length();
75 75
76 if (argumentCount < 1) 76 if (argumentCount < 1)
77 return; 77 return;
78 78
79 DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); 79 DOMWindow* imp = V8Window::toNative(args.Holder());
80 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*> (imp->document()); 80 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*> (imp->document());
81 81
82 if (!scriptContext) { 82 if (!scriptContext) {
83 setDOMException(INVALID_ACCESS_ERR, args.GetIsolate()); 83 setDOMException(INVALID_ACCESS_ERR, args.GetIsolate());
84 return; 84 return;
85 } 85 }
86 86
87 v8::Handle<v8::Value> function = args[0]; 87 v8::Handle<v8::Value> function = args[0];
88 WTF::String functionString; 88 WTF::String functionString;
89 if (!function->IsFunction()) { 89 if (!function->IsFunction()) {
90 if (function->IsString()) 90 if (function->IsString()) {
91 functionString = toWebCoreString(function); 91 functionString = toWebCoreString(function);
92 else { 92 } else {
93 v8::Handle<v8::Value> v8String = function->ToString(); 93 v8::Handle<v8::Value> v8String = function->ToString();
94 94
95 // Bail out if string conversion failed. 95 // Bail out if string conversion failed.
96 if (v8String.IsEmpty()) 96 if (v8String.IsEmpty())
97 return; 97 return;
98 98
99 functionString = toWebCoreString(v8String); 99 functionString = toWebCoreString(v8String);
100 } 100 }
101 101
102 // Don't allow setting timeouts to run empty functions! 102 // Don't allow setting timeouts to run empty functions!
103 // (Bug 1009597) 103 // (Bug 1009597)
104 if (functionString.length() == 0) 104 if (!functionString.length())
105 return; 105 return;
106 } 106 }
107 107
108 int32_t timeout = 0; 108 int32_t timeout = 0;
109 if (argumentCount >= 2) 109 if (argumentCount >= 2)
110 timeout = args[1]->Int32Value(); 110 timeout = args[1]->Int32Value();
111 111
112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
113 return; 113 return;
114 114
115 int id; 115 int id;
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 v8::Local<v8::Value>* params = 0; 118 v8::Local<v8::Value>* params = 0;
119 if (paramCount > 0) { 119 if (paramCount > 0) {
120 params = new v8::Local<v8::Value>[paramCount]; 120 params = 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] = args[i+2]; 123 params[i] = args[i+2];
124 }
124 } 125 }
125 126
126 // params is passed to action, and released in action's destructor 127 // params is passed to action, and released in action's destructor
127 ASSERT(imp->frame()); 128 ASSERT(imp->frame());
128 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(imp->frame ()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), p aramCount, params, args.GetIsolate())); 129 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(imp->frame ()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), p aramCount, params, args.GetIsolate()));
129 130
130 // FIXME: We should use OwnArrayPtr for params. 131 // FIXME: We should use OwnArrayPtr for params.
131 delete[] params; 132 delete[] params;
132 133
133 id = DOMTimer::install(scriptContext, action.release(), timeout, singleS hot); 134 id = DOMTimer::install(scriptContext, action.release(), timeout, singleS hot);
134 } else { 135 } else {
135 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE val()) { 136 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE val()) {
136 v8SetReturnValue(args, 0); 137 v8SetReturnValue(args, 0);
137 return; 138 return;
138 } 139 }
139 ASSERT(imp->frame()); 140 ASSERT(imp->frame());
140 id = DOMTimer::install(scriptContext, adoptPtr(new ScheduledAction(imp-> frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolat e())), timeout, singleShot); 141 id = DOMTimer::install(scriptContext, adoptPtr(new ScheduledAction(imp-> frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolat e())), timeout, singleShot);
141 } 142 }
142 143
143 // Try to do the idle notification before the timeout expires to get better 144 // Try to do the idle notification before the timeout expires to get better
144 // use of any idle time. Aim for the middle of the interval for simplicity. 145 // use of any idle time. Aim for the middle of the interval for simplicity.
145 if (timeout >= 0) { 146 if (timeout >= 0) {
146 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; 147 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2;
147 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); 148 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval);
148 } 149 }
149 150
150 v8SetReturnValue(args, id); 151 v8SetReturnValue(args, id);
151 } 152 }
152 153
153 void V8DOMWindow::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::Pr opertyCallbackInfo<v8::Value>& info) 154 void V8Window::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::Prope rtyCallbackInfo<v8::Value>& info)
154 { 155 {
155 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 DOMWindow::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate( )))); 156 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) );
156 if (holder.IsEmpty()) 157 if (holder.IsEmpty())
157 return; 158 return;
158 159
159 Frame* frame = V8DOMWindow::toNative(holder)->frame(); 160 Frame* frame = V8Window::toNative(holder)->frame();
160 if (!BindingSecurity::shouldAllowAccessToFrame(frame)) 161 if (!BindingSecurity::shouldAllowAccessToFrame(frame))
161 return; 162 return;
162 163
163 ASSERT(frame); 164 ASSERT(frame);
164 v8::Local<v8::Context> context = frame->script()->currentWorldContext(); 165 v8::Local<v8::Context> context = frame->script()->currentWorldContext();
165 if (context.IsEmpty()) 166 if (context.IsEmpty())
166 return; 167 return;
167 168
168 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(); 169 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event();
169 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo l); 170 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo l);
170 if (jsEvent.IsEmpty()) 171 if (jsEvent.IsEmpty())
171 return; 172 return;
172 v8SetReturnValue(info, jsEvent); 173 v8SetReturnValue(info, jsEvent);
173 } 174 }
174 175
175 void V8DOMWindow::eventAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8 ::Value> value, const v8::PropertyCallbackInfo<void>& info) 176 void V8Window::eventAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::V alue> value, const v8::PropertyCallbackInfo<void>& info)
176 { 177 {
177 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 DOMWindow::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate( )))); 178 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) );
178 if (holder.IsEmpty()) 179 if (holder.IsEmpty())
179 return; 180 return;
180 181
181 Frame* frame = V8DOMWindow::toNative(holder)->frame(); 182 Frame* frame = V8Window::toNative(holder)->frame();
182 if (!BindingSecurity::shouldAllowAccessToFrame(frame)) 183 if (!BindingSecurity::shouldAllowAccessToFrame(frame))
183 return; 184 return;
184 185
185 ASSERT(frame); 186 ASSERT(frame);
186 v8::Local<v8::Context> context = frame->script()->currentWorldContext(); 187 v8::Local<v8::Context> context = frame->script()->currentWorldContext();
187 if (context.IsEmpty()) 188 if (context.IsEmpty())
188 return; 189 return;
189 190
190 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(); 191 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event();
191 context->Global()->SetHiddenValue(eventSymbol, value); 192 context->Global()->SetHiddenValue(eventSymbol, value);
192 } 193 }
193 194
194 void V8DOMWindow::locationAttrSetterCustom(v8::Local<v8::String> name, v8::Local <v8::Value> value, const v8::PropertyCallbackInfo<void>& info) 195 void V8Window::locationAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8 ::Value> value, const v8::PropertyCallbackInfo<void>& info)
195 { 196 {
196 DOMWindow* imp = V8DOMWindow::toNative(info.Holder()); 197 DOMWindow* imp = V8Window::toNative(info.Holder());
197 198
198 DOMWindow* active = activeDOMWindow(); 199 DOMWindow* active = activeDOMWindow();
199 if (!active) 200 if (!active)
200 return; 201 return;
201 202
202 DOMWindow* first = firstDOMWindow(); 203 DOMWindow* first = firstDOMWindow();
203 if (!first) 204 if (!first)
204 return; 205 return;
205 206
206 if (Location* location = imp->location()) 207 if (Location* location = imp->location())
207 location->setHref(active, first, toWebCoreString(value)); 208 location->setHref(active, first, toWebCoreString(value));
208 } 209 }
209 210
210 void V8DOMWindow::openerAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v 8::Value> value, const v8::PropertyCallbackInfo<void>& info) 211 void V8Window::openerAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8:: Value> value, const v8::PropertyCallbackInfo<void>& info)
211 { 212 {
212 DOMWindow* imp = V8DOMWindow::toNative(info.Holder()); 213 DOMWindow* imp = V8Window::toNative(info.Holder());
213 214
214 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 215 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
215 return; 216 return;
216 217
217 // Opener can be shadowed if it is in the same domain. 218 // Opener can be shadowed if it is in the same domain.
218 // Have a special handling of null value to behave 219 // Have a special handling of null value to behave
219 // like Firefox. See bug http://b/1224887 & http://b/791706. 220 // like Firefox. See bug http://b/1224887 & http://b/791706.
220 if (value->IsNull()) { 221 if (value->IsNull()) {
221 // imp->frame() cannot be null, 222 // imp->frame() cannot be null,
222 // otherwise, SameOrigin check would have failed. 223 // otherwise, SameOrigin check would have failed.
223 ASSERT(imp->frame()); 224 ASSERT(imp->frame());
224 imp->frame()->loader()->setOpener(0); 225 imp->frame()->loader()->setOpener(0);
225 } 226 }
226 227
227 // Delete the accessor from this object. 228 // Delete the accessor from this object.
228 info.Holder()->Delete(name); 229 info.Holder()->Delete(name);
229 230
230 // Put property on the front (this) object. 231 // Put property on the front (this) object.
231 info.This()->Set(name, value); 232 info.This()->Set(name, value);
232 } 233 }
233 234
234 void V8DOMWindow::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<v8 ::Value>& args) 235 void V8Window::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<v8::V alue>& args)
235 { 236 {
236 String eventType = toWebCoreString(args[0]); 237 String eventType = toWebCoreString(args[0]);
237 bool useCapture = args[2]->BooleanValue(); 238 bool useCapture = args[2]->BooleanValue();
238 239
239 DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); 240 DOMWindow* imp = V8Window::toNative(args.Holder());
240 241
241 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 242 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
242 return; 243 return;
243 244
244 Document* doc = imp->document(); 245 Document* doc = imp->document();
245 246
246 if (!doc) 247 if (!doc)
247 return; 248 return;
248 249
249 // FIXME: Check if there is not enough arguments 250 // FIXME: Check if there is not enough arguments
250 if (!imp->frame()) 251 if (!imp->frame())
251 return; 252 return;
252 253
253 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOrCreate); 254 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOrCreate);
254 255
255 if (listener) { 256 if (listener) {
256 imp->addEventListener(eventType, listener, useCapture); 257 imp->addEventListener(eventType, listener, useCapture);
257 createHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate()); 258 createHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate());
258 } 259 }
259 } 260 }
260 261
261 262
262 void V8DOMWindow::removeEventListenerMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& args) 263 void V8Window::removeEventListenerMethodCustom(const v8::FunctionCallbackInfo<v8 ::Value>& args)
263 { 264 {
264 String eventType = toWebCoreString(args[0]); 265 String eventType = toWebCoreString(args[0]);
265 bool useCapture = args[2]->BooleanValue(); 266 bool useCapture = args[2]->BooleanValue();
266 267
267 DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); 268 DOMWindow* imp = V8Window::toNative(args.Holder());
268 269
269 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 270 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
270 return; 271 return;
271 272
272 Document* doc = imp->document(); 273 Document* doc = imp->document();
273 274
274 if (!doc) 275 if (!doc)
275 return; 276 return;
276 277
277 if (!imp->frame()) 278 if (!imp->frame())
278 return; 279 return;
279 280
280 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOnly); 281 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOnly);
281 282
282 if (listener) { 283 if (listener) {
283 imp->removeEventListener(eventType, listener.get(), useCapture); 284 imp->removeEventListener(eventType, listener.get(), useCapture);
284 removeHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate()); 285 removeHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate());
285 } 286 }
286 } 287 }
287 288
288 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value) 289 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value)
289 { 290 {
290 if (value->IsString() || value->IsStringObject()) 291 if (value->IsString() || value->IsStringObject())
291 return true; 292 return true;
292 return false; 293 return false;
293 } 294 }
294 295
295 296
296 void V8DOMWindow::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Val ue>& args) 297 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args)
297 { 298 {
298 // None of these need to be RefPtr because args and context are guaranteed 299 // None of these need to be RefPtr because args and context are guaranteed
299 // to hold on to them. 300 // to hold on to them.
300 DOMWindow* window = V8DOMWindow::toNative(args.Holder()); 301 DOMWindow* window = V8Window::toNative(args.Holder());
301 DOMWindow* source = activeDOMWindow(); 302 DOMWindow* source = activeDOMWindow();
302 303
303 // If called directly by WebCore we don't have a calling context. 304 // If called directly by WebCore we don't have a calling context.
304 if (!source) { 305 if (!source) {
305 throwTypeError(0, args.GetIsolate()); 306 throwTypeError(0, args.GetIsolate());
306 return; 307 return;
307 } 308 }
308 309
309 // This function has variable arguments and can be: 310 // This function has variable arguments and can be:
310 // Per current spec: 311 // Per current spec:
(...skipping 10 matching lines...) Expand all
321 targetOriginArgIndex = 2; 322 targetOriginArgIndex = 2;
322 transferablesArgIndex = 1; 323 transferablesArgIndex = 1;
323 } 324 }
324 if (!extractTransferables(args[transferablesArgIndex], portArray, arrayB ufferArray, args.GetIsolate())) 325 if (!extractTransferables(args[transferablesArgIndex], portArray, arrayB ufferArray, args.GetIsolate()))
325 return; 326 return;
326 } 327 }
327 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, targetOrigin, args[targetOriginArgIndex]); 328 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, targetOrigin, args[targetOriginArgIndex]);
328 329
329 bool didThrow = false; 330 bool didThrow = false;
330 RefPtr<SerializedScriptValue> message = 331 RefPtr<SerializedScriptValue> message =
331 SerializedScriptValue::create(args[0], 332 SerializedScriptValue::create(args[0], &portArray, &arrayBufferArray, di dThrow, args.GetIsolate());
332 &portArray,
333 &arrayBufferArray,
334 didThrow,
335 args.GetIsolate());
336 if (didThrow) 333 if (didThrow)
337 return; 334 return;
338 335
339 ExceptionCode ec = 0; 336 ExceptionCode ec = 0;
340 window->postMessage(message.release(), &portArray, targetOrigin, source, ec) ; 337 window->postMessage(message.release(), &portArray, targetOrigin, source, ec) ;
341 setDOMException(ec, args.GetIsolate()); 338 setDOMException(ec, args.GetIsolate());
342 } 339 }
343 340
344 // FIXME(fqian): returning string is cheating, and we should 341 // FIXME(fqian): returning string is cheating, and we should
345 // fix this by calling toString function on the receiver. 342 // fix this by calling toString function on the receiver.
346 // However, V8 implements toString in JavaScript, which requires 343 // However, V8 implements toString in JavaScript, which requires
347 // switching context of receiver. I consider it is dangerous. 344 // switching context of receiver. I consider it is dangerous.
348 void V8DOMWindow::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args) 345 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& a rgs)
349 { 346 {
350 v8::Handle<v8::Object> domWrapper = args.This()->FindInstanceInPrototypeChai n(V8DOMWindow::GetTemplate(args.GetIsolate(), worldTypeInMainThread(args.GetIsol ate()))); 347 v8::Handle<v8::Object> domWrapper = args.This()->FindInstanceInPrototypeChai n(V8Window::GetTemplate(args.GetIsolate(), worldTypeInMainThread(args.GetIsolate ())));
351 if (domWrapper.IsEmpty()) { 348 if (domWrapper.IsEmpty()) {
352 v8SetReturnValue(args, args.This()->ObjectProtoToString()); 349 v8SetReturnValue(args, args.This()->ObjectProtoToString());
353 return; 350 return;
354 } 351 }
355 v8SetReturnValue(args, domWrapper->ObjectProtoToString()); 352 v8SetReturnValue(args, domWrapper->ObjectProtoToString());
356 } 353 }
357 354
358 class DialogHandler { 355 class DialogHandler {
359 public: 356 public:
360 explicit DialogHandler(v8::Handle<v8::Value> dialogArguments) 357 explicit DialogHandler(v8::Handle<v8::Value> dialogArguments)
(...skipping 29 matching lines...) Expand all
390 if (returnValue.IsEmpty()) 387 if (returnValue.IsEmpty())
391 return v8::Undefined(); 388 return v8::Undefined();
392 return returnValue; 389 return returnValue;
393 } 390 }
394 391
395 static void setUpDialog(DOMWindow* dialog, void* handler) 392 static void setUpDialog(DOMWindow* dialog, void* handler)
396 { 393 {
397 static_cast<DialogHandler*>(handler)->dialogCreated(dialog); 394 static_cast<DialogHandler*>(handler)->dialogCreated(dialog);
398 } 395 }
399 396
400 void V8DOMWindow::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8: :Value>& args) 397 void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Va lue>& args)
401 { 398 {
402 DOMWindow* impl = V8DOMWindow::toNative(args.Holder()); 399 DOMWindow* impl = V8Window::toNative(args.Holder());
403 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame())) 400 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame()))
404 return; 401 return;
405 402
406 // FIXME: Handle exceptions properly. 403 // FIXME: Handle exceptions properly.
407 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); 404 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]);
408 DialogHandler handler(args[1]); 405 DialogHandler handler(args[1]);
409 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]); 406 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]);
410 407
411 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi rstDOMWindow(), setUpDialog, &handler); 408 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi rstDOMWindow(), setUpDialog, &handler);
412 409
413 v8SetReturnValue(args, handler.returnValue()); 410 v8SetReturnValue(args, handler.returnValue());
414 } 411 }
415 412
416 void V8DOMWindow::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& ar gs) 413 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
417 { 414 {
418 DOMWindow* impl = V8DOMWindow::toNative(args.Holder()); 415 DOMWindow* impl = V8Window::toNative(args.Holder());
419 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame())) 416 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame()))
420 return; 417 return;
421 418
422 // FIXME: Handle exceptions properly. 419 // FIXME: Handle exceptions properly.
423 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); 420 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]);
424 AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_b lank" : AtomicString(toWebCoreString(args[1])); 421 AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_b lank" : AtomicString(toWebCoreString(args[1]));
425 String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]); 422 String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]);
426 423
427 RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeat uresString, activeDOMWindow(), firstDOMWindow()); 424 RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeat uresString, activeDOMWindow(), firstDOMWindow());
428 if (!openedWindow) 425 if (!openedWindow)
429 return; 426 return;
430 427
431 v8SetReturnValue(args, toV8Fast(openedWindow.release(), args, impl)); 428 v8SetReturnValue(args, toV8Fast(openedWindow.release(), args, impl));
432 } 429 }
433 430
434 void V8DOMWindow::namedPropertyGetter(v8::Local<v8::String> name, const v8::Prop ertyCallbackInfo<v8::Value>& info) 431 void V8Window::namedPropertyGetter(v8::Local<v8::String> name, const v8::Propert yCallbackInfo<v8::Value>& info)
435 { 432 {
436 433
437 DOMWindow* window = V8DOMWindow::toNative(info.Holder()); 434 DOMWindow* window = V8Window::toNative(info.Holder());
438 if (!window) 435 if (!window)
439 return; 436 return;
440 437
441 Frame* frame = window->frame(); 438 Frame* frame = window->frame();
442 // window is detached from a frame. 439 // window is detached from a frame.
443 if (!frame) 440 if (!frame)
444 return; 441 return;
445 442
446 // Search sub-frames. 443 // Search sub-frames.
447 AtomicString propName = toWebCoreAtomicString(name); 444 AtomicString propName = toWebCoreAtomicString(name);
(...skipping 19 matching lines...) Expand all
467 return; 464 return;
468 } 465 }
469 v8SetReturnValue(info, toV8Fast(items.release(), info, window)); 466 v8SetReturnValue(info, toV8Fast(items.release(), info, window));
470 return; 467 return;
471 } 468 }
472 } 469 }
473 } 470 }
474 } 471 }
475 472
476 473
477 void V8DOMWindow::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Valu e>& args) 474 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
478 { 475 {
479 WindowSetTimeoutImpl(args, true); 476 WindowSetTimeoutImpl(args, true);
480 } 477 }
481 478
482 479
483 void V8DOMWindow::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Val ue>& args) 480 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args)
484 { 481 {
485 WindowSetTimeoutImpl(args, false); 482 WindowSetTimeoutImpl(args, false);
486 } 483 }
487 484
488 bool V8DOMWindow::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local <v8::Value> key, v8::AccessType type, v8::Local<v8::Value>) 485 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8 ::Value> key, v8::AccessType type, v8::Local<v8::Value>)
489 { 486 {
490 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 487 v8::Isolate* isolate = v8::Isolate::GetCurrent();
491 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8DOMWind ow::GetTemplate(isolate, worldTypeInMainThread(isolate))); 488 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window: :GetTemplate(isolate, worldTypeInMainThread(isolate)));
492 if (window.IsEmpty()) 489 if (window.IsEmpty())
493 return false; // the frame is gone. 490 return false; // the frame is gone.
494 491
495 DOMWindow* targetWindow = V8DOMWindow::toNative(window); 492 DOMWindow* targetWindow = V8Window::toNative(window);
496 493
497 ASSERT(targetWindow); 494 ASSERT(targetWindow);
498 495
499 Frame* target = targetWindow->frame(); 496 Frame* target = targetWindow->frame();
500 if (!target) 497 if (!target)
501 return false; 498 return false;
502 499
503 // Notify the loader's client if the initial document has been accessed. 500 // Notify the loader's client if the initial document has been accessed.
504 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument()) 501 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument())
505 target->loader()->didAccessInitialDocument(); 502 target->loader()->didAccessInitialDocument();
(...skipping 15 matching lines...) Expand all
521 && childFrame 518 && childFrame
522 && !host->HasRealNamedProperty(keyString) 519 && !host->HasRealNamedProperty(keyString)
523 && !window->HasRealNamedProperty(keyString) 520 && !window->HasRealNamedProperty(keyString)
524 && name != nameOfProtoProperty) 521 && name != nameOfProtoProperty)
525 return true; 522 return true;
526 } 523 }
527 524
528 return BindingSecurity::shouldAllowAccessToFrame(target, DoNotReportSecurity Error); 525 return BindingSecurity::shouldAllowAccessToFrame(target, DoNotReportSecurity Error);
529 } 526 }
530 527
531 bool V8DOMWindow::indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_ t index, v8::AccessType type, v8::Local<v8::Value>) 528 bool V8Window::indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_t i ndex, v8::AccessType type, v8::Local<v8::Value>)
532 { 529 {
533 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 530 v8::Isolate* isolate = v8::Isolate::GetCurrent();
534 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8DOMWind ow::GetTemplate(isolate, worldTypeInMainThread(isolate))); 531 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window: :GetTemplate(isolate, worldTypeInMainThread(isolate)));
535 if (window.IsEmpty()) 532 if (window.IsEmpty())
536 return false; 533 return false;
537 534
538 DOMWindow* targetWindow = V8DOMWindow::toNative(window); 535 DOMWindow* targetWindow = V8Window::toNative(window);
539 536
540 ASSERT(targetWindow); 537 ASSERT(targetWindow);
541 538
542 Frame* target = targetWindow->frame(); 539 Frame* target = targetWindow->frame();
543 if (!target) 540 if (!target)
544 return false; 541 return false;
545 Frame* childFrame = target->tree()->scopedChild(index); 542 Frame* childFrame = target->tree()->scopedChild(index);
546 543
547 // Notify the loader's client if the initial document has been accessed. 544 // Notify the loader's client if the initial document has been accessed.
548 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument()) 545 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument())
(...skipping 21 matching lines...) Expand all
570 if (!frame) 567 if (!frame)
571 return v8Undefined(); 568 return v8Undefined();
572 569
573 // Special case: Because of executeScriptInIsolatedWorld() one DOMWindow can have 570 // Special case: Because of executeScriptInIsolatedWorld() one DOMWindow can have
574 // multiple contexts and multiple global objects associated with it. When 571 // multiple contexts and multiple global objects associated with it. When
575 // code running in one of those contexts accesses the window object, we 572 // code running in one of those contexts accesses the window object, we
576 // want to return the global object associated with that context, not 573 // want to return the global object associated with that context, not
577 // necessarily the first global object associated with that DOMWindow. 574 // necessarily the first global object associated with that DOMWindow.
578 v8::Handle<v8::Context> currentContext = v8::Context::GetCurrent(); 575 v8::Handle<v8::Context> currentContext = v8::Context::GetCurrent();
579 v8::Handle<v8::Object> currentGlobal = currentContext->Global(); 576 v8::Handle<v8::Object> currentGlobal = currentContext->Global();
580 v8::Handle<v8::Object> windowWrapper = currentGlobal->FindInstanceInPrototyp eChain(V8DOMWindow::GetTemplate(isolate, worldTypeInMainThread(isolate))); 577 v8::Handle<v8::Object> windowWrapper = currentGlobal->FindInstanceInPrototyp eChain(V8Window::GetTemplate(isolate, worldTypeInMainThread(isolate)));
581 if (!windowWrapper.IsEmpty()) { 578 if (!windowWrapper.IsEmpty()) {
582 if (V8DOMWindow::toNative(windowWrapper) == window) 579 if (V8Window::toNative(windowWrapper) == window)
583 return currentGlobal; 580 return currentGlobal;
584 } 581 }
585 582
586 // Otherwise, return the global object associated with this frame. 583 // Otherwise, return the global object associated with this frame.
587 v8::Handle<v8::Context> context = frame->script()->currentWorldContext(); 584 v8::Handle<v8::Context> context = frame->script()->currentWorldContext();
588 if (context.IsEmpty()) 585 if (context.IsEmpty())
589 return v8Undefined(); 586 return v8Undefined();
590 587
591 v8::Handle<v8::Object> global = context->Global(); 588 v8::Handle<v8::Object> global = context->Global();
592 ASSERT(!global.IsEmpty()); 589 ASSERT(!global.IsEmpty());
593 return global; 590 return global;
594 } 591 }
595 592
596 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 593 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
597 { 594 {
598 return toV8(window, creationContext, isolate); 595 return toV8(window, creationContext, isolate);
599 } 596 }
600 597
601 } // namespace WebCore 598 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8SVGPathSegCustom.cpp ('k') | Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698