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

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

Issue 91383002: Switch V8WindowCustom to the new-style ExceptionState (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Expectations. Created 7 years 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 | « LayoutTests/http/tests/security/xss-DENIED-method-with-iframe-proto-expected.txt ('k') | no next file » | 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 { 78 {
79 int argumentCount = info.Length(); 79 int argumentCount = info.Length();
80 80
81 if (argumentCount < 1) 81 if (argumentCount < 1)
82 return; 82 return;
83 83
84 DOMWindow* imp = V8Window::toNative(info.Holder()); 84 DOMWindow* imp = V8Window::toNative(info.Holder());
85 ExecutionContext* scriptContext = static_cast<ExecutionContext*>(imp->docume nt()); 85 ExecutionContext* scriptContext = static_cast<ExecutionContext*>(imp->docume nt());
86 86
87 if (!scriptContext) { 87 if (!scriptContext) {
88 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr or); 88 exceptionState.throwDOMException(InvalidAccessError, "No script context is available in which to execute the script.");
89 return; 89 return;
90 } 90 }
91 91
92 v8::Handle<v8::Value> function = info[0]; 92 v8::Handle<v8::Value> function = info[0];
93 String functionString; 93 String functionString;
94 if (!function->IsFunction()) { 94 if (!function->IsFunction()) {
95 if (function->IsString()) { 95 if (function->IsString()) {
96 functionString = toWebCoreString(function.As<v8::String>()); 96 functionString = toWebCoreString(function.As<v8::String>());
97 } else { 97 } else {
98 v8::Handle<v8::Value> v8String = function->ToString(); 98 v8::Handle<v8::Value> v8String = function->ToString();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 v8SetReturnValue(info, timerId); 154 v8SetReturnValue(info, timerId);
155 } 155 }
156 156
157 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val ue>& info) 157 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val ue>& info)
158 { 158 {
159 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) ); 159 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) );
160 if (holder.IsEmpty()) 160 if (holder.IsEmpty())
161 return; 161 return;
162 162
163 Frame* frame = V8Window::toNative(holder)->frame(); 163 Frame* frame = V8Window::toNative(holder)->frame();
164 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 164 ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Windo w", info.Holder(), info.GetIsolate());
165 if (!BindingSecurity::shouldAllowAccessToFrame(frame, exceptionState)) { 165 if (!BindingSecurity::shouldAllowAccessToFrame(frame, exceptionState)) {
166 exceptionState.throwIfNeeded(); 166 exceptionState.throwIfNeeded();
167 return; 167 return;
168 } 168 }
169 169
170 ASSERT(frame); 170 ASSERT(frame);
171 v8::Local<v8::Context> context = frame->script().currentWorldContext(); 171 v8::Local<v8::Context> context = frame->script().currentWorldContext();
172 if (context.IsEmpty()) 172 if (context.IsEmpty())
173 return; 173 return;
174 174
175 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso late()); 175 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso late());
176 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo l); 176 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo l);
177 if (jsEvent.IsEmpty()) 177 if (jsEvent.IsEmpty())
178 return; 178 return;
179 v8SetReturnValue(info, jsEvent); 179 v8SetReturnValue(info, jsEvent);
180 } 180 }
181 181
182 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8:: PropertyCallbackInfo<void>& info) 182 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8:: PropertyCallbackInfo<void>& info)
183 { 183 {
184 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) ); 184 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) );
185 if (holder.IsEmpty()) 185 if (holder.IsEmpty())
186 return; 186 return;
187 187
188 Frame* frame = V8Window::toNative(holder)->frame(); 188 Frame* frame = V8Window::toNative(holder)->frame();
189 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 189 ExceptionState exceptionState(ExceptionState::SetterContext, "event", "Windo w", info.Holder(), info.GetIsolate());
190 if (!BindingSecurity::shouldAllowAccessToFrame(frame, exceptionState)) { 190 if (!BindingSecurity::shouldAllowAccessToFrame(frame, exceptionState)) {
191 exceptionState.throwIfNeeded(); 191 exceptionState.throwIfNeeded();
192 return; 192 return;
193 } 193 }
194 194
195 ASSERT(frame); 195 ASSERT(frame);
196 v8::Local<v8::Context> context = frame->script().currentWorldContext(); 196 v8::Local<v8::Context> context = frame->script().currentWorldContext();
197 if (context.IsEmpty()) 197 if (context.IsEmpty())
198 return; 198 return;
199 199
200 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso late()); 200 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso late());
201 context->Global()->SetHiddenValue(eventSymbol, value); 201 context->Global()->SetHiddenValue(eventSymbol, value);
202 } 202 }
203 203
204 void V8Window::frameElementAttributeGetterCustom(const v8::PropertyCallbackInfo< v8::Value>& info) 204 void V8Window::frameElementAttributeGetterCustom(const v8::PropertyCallbackInfo< v8::Value>& info)
205 { 205 {
206 DOMWindow* imp = V8Window::toNative(info.Holder()); 206 DOMWindow* imp = V8Window::toNative(info.Holder());
207 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 207 ExceptionState exceptionState(ExceptionState::GetterContext, "frame", "Windo w", info.Holder(), info.GetIsolate());
208 if (!BindingSecurity::shouldAllowAccessToNode(imp->frameElement(), exception State)) { 208 if (!BindingSecurity::shouldAllowAccessToNode(imp->frameElement(), exception State)) {
209 v8SetReturnValueNull(info); 209 v8SetReturnValueNull(info);
210 exceptionState.throwIfNeeded(); 210 exceptionState.throwIfNeeded();
211 return; 211 return;
212 } 212 }
213 213
214 // The wrapper for an <iframe> should get its prototype from the context of the frame it's in, rather than its own frame. 214 // The wrapper for an <iframe> should get its prototype from the context of the frame it's in, rather than its own frame.
215 // So, use its containing document as the creation context when wrapping. 215 // So, use its containing document as the creation context when wrapping.
216 v8::Handle<v8::Value> creationContext = toV8(&imp->frameElement()->document( ), v8::Handle<v8::Object>(), info.GetIsolate()); 216 v8::Handle<v8::Value> creationContext = toV8(&imp->frameElement()->document( ), v8::Handle<v8::Object>(), info.GetIsolate());
217 RELEASE_ASSERT(!creationContext.IsEmpty()); 217 RELEASE_ASSERT(!creationContext.IsEmpty());
218 v8::Handle<v8::Value> wrapper = toV8(imp->frameElement(), v8::Handle<v8::Obj ect>::Cast(creationContext), info.GetIsolate()); 218 v8::Handle<v8::Value> wrapper = toV8(imp->frameElement(), v8::Handle<v8::Obj ect>::Cast(creationContext), info.GetIsolate());
219 v8SetReturnValue(info, wrapper); 219 v8SetReturnValue(info, wrapper);
220 } 220 }
221 221
222 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8: :PropertyCallbackInfo<void>& info) 222 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8: :PropertyCallbackInfo<void>& info)
223 { 223 {
224 DOMWindow* imp = V8Window::toNative(info.Holder()); 224 DOMWindow* imp = V8Window::toNative(info.Holder());
225 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 225 ExceptionState exceptionState(ExceptionState::SetterContext, "opener", "Wind ow", info.Holder(), info.GetIsolate());
226 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState) ) { 226 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState) ) {
227 exceptionState.throwIfNeeded(); 227 exceptionState.throwIfNeeded();
228 return; 228 return;
229 } 229 }
230 230
231 // Opener can be shadowed if it is in the same domain. 231 // Opener can be shadowed if it is in the same domain.
232 // Have a special handling of null value to behave 232 // Have a special handling of null value to behave
233 // like Firefox. See bug http://b/1224887 & http://b/791706. 233 // like Firefox. See bug http://b/1224887 & http://b/791706.
234 if (value->IsNull()) { 234 if (value->IsNull()) {
235 // imp->frame() cannot be null, 235 // imp->frame() cannot be null,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 289 }
290 } 290 }
291 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, targetOrigin, info[targetOriginArgIndex]); 291 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, targetOrigin, info[targetOriginArgIndex]);
292 292
293 bool didThrow = false; 293 bool didThrow = false;
294 RefPtr<SerializedScriptValue> message = 294 RefPtr<SerializedScriptValue> message =
295 SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, di dThrow, info.GetIsolate()); 295 SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, di dThrow, info.GetIsolate());
296 if (didThrow) 296 if (didThrow)
297 return; 297 return;
298 298
299 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 299 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", "Window", info.Holder(), info.GetIsolate());
300 window->postMessage(message.release(), &portArray, targetOrigin, source, exc eptionState); 300 window->postMessage(message.release(), &portArray, targetOrigin, source, exc eptionState);
301 exceptionState.throwIfNeeded(); 301 exceptionState.throwIfNeeded();
302 } 302 }
303 303
304 // FIXME(fqian): returning string is cheating, and we should 304 // FIXME(fqian): returning string is cheating, and we should
305 // fix this by calling toString function on the receiver. 305 // fix this by calling toString function on the receiver.
306 // However, V8 implements toString in JavaScript, which requires 306 // However, V8 implements toString in JavaScript, which requires
307 // switching context of receiver. I consider it is dangerous. 307 // switching context of receiver. I consider it is dangerous.
308 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo) 308 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo)
309 { 309 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 353 }
354 354
355 static void setUpDialog(DOMWindow* dialog, void* handler) 355 static void setUpDialog(DOMWindow* dialog, void* handler)
356 { 356 {
357 static_cast<DialogHandler*>(handler)->dialogCreated(dialog, v8::Isolate::Get Current()); 357 static_cast<DialogHandler*>(handler)->dialogCreated(dialog, v8::Isolate::Get Current());
358 } 358 }
359 359
360 void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Va lue>& info) 360 void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Va lue>& info)
361 { 361 {
362 DOMWindow* impl = V8Window::toNative(info.Holder()); 362 DOMWindow* impl = V8Window::toNative(info.Holder());
363 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 363 ExceptionState exceptionState(ExceptionState::ExecutionContext, "showModalDi alog", "Window", info.Holder(), info.GetIsolate());
364 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState )) { 364 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState )) {
365 exceptionState.throwIfNeeded(); 365 exceptionState.throwIfNeeded();
366 return; 366 return;
367 } 367 }
368 368
369 // FIXME: Handle exceptions properly. 369 // FIXME: Handle exceptions properly.
370 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]); 370 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]);
371 DialogHandler handler(info[1]); 371 DialogHandler handler(info[1]);
372 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(info[2 ]); 372 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(info[2 ]);
373 373
374 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi rstDOMWindow(), setUpDialog, &handler); 374 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi rstDOMWindow(), setUpDialog, &handler);
375 375
376 v8SetReturnValue(info, handler.returnValue(info.GetIsolate())); 376 v8SetReturnValue(info, handler.returnValue(info.GetIsolate()));
377 } 377 }
378 378
379 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) 379 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
380 { 380 {
381 DOMWindow* impl = V8Window::toNative(info.Holder()); 381 DOMWindow* impl = V8Window::toNative(info.Holder());
382 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 382 ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Win dow", info.Holder(), info.GetIsolate());
383 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState )) { 383 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState )) {
384 exceptionState.throwIfNeeded(); 384 exceptionState.throwIfNeeded();
385 return; 385 return;
386 } 386 }
387 387
388 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, urlString, info[0]); 388 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, urlString, info[0]);
389 AtomicString frameName; 389 AtomicString frameName;
390 if (info[1]->IsUndefined() || info[1]->IsNull()) { 390 if (info[1]->IsUndefined() || info[1]->IsNull()) {
391 frameName = "_blank"; 391 frameName = "_blank";
392 } else { 392 } else {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 v8SetReturnValueFast(info, items.release(), window); 440 v8SetReturnValueFast(info, items.release(), window);
441 return; 441 return;
442 } 442 }
443 } 443 }
444 } 444 }
445 } 445 }
446 446
447 447
448 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) 448 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
449 { 449 {
450 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 450 ExceptionState exceptionState(ExceptionState::ExecutionContext, "setTimeout" , "Window", info.Holder(), info.GetIsolate());
451 WindowSetTimeoutImpl(info, true, exceptionState); 451 WindowSetTimeoutImpl(info, true, exceptionState);
452 exceptionState.throwIfNeeded(); 452 exceptionState.throwIfNeeded();
453 } 453 }
454 454
455 455
456 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info) 456 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info)
457 { 457 {
458 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 458 ExceptionState exceptionState(ExceptionState::ExecutionContext, "setInterval ", "Window", info.Holder(), info.GetIsolate());
459 WindowSetTimeoutImpl(info, false, exceptionState); 459 WindowSetTimeoutImpl(info, false, exceptionState);
460 exceptionState.throwIfNeeded(); 460 exceptionState.throwIfNeeded();
461 } 461 }
462 462
463 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8 ::Value> key, v8::AccessType type, v8::Local<v8::Value>) 463 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8 ::Value> key, v8::AccessType type, v8::Local<v8::Value>)
464 { 464 {
465 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 465 v8::Isolate* isolate = v8::Isolate::GetCurrent();
466 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window: :GetTemplate(isolate, worldTypeInMainThread(isolate))); 466 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window: :GetTemplate(isolate, worldTypeInMainThread(isolate)));
467 if (window.IsEmpty()) 467 if (window.IsEmpty())
468 return false; // the frame is gone. 468 return false; // the frame is gone.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 v8::Handle<v8::Context> context = frame->script().currentWorldContext(); 566 v8::Handle<v8::Context> context = frame->script().currentWorldContext();
567 if (context.IsEmpty()) 567 if (context.IsEmpty())
568 return v8Undefined(); 568 return v8Undefined();
569 569
570 v8::Handle<v8::Object> global = context->Global(); 570 v8::Handle<v8::Object> global = context->Global();
571 ASSERT(!global.IsEmpty()); 571 ASSERT(!global.IsEmpty());
572 return global; 572 return global;
573 } 573 }
574 574
575 } // namespace WebCore 575 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/security/xss-DENIED-method-with-iframe-proto-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698