| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #include "core/platform/graphics/MediaPlayer.h" | 66 #include "core/platform/graphics/MediaPlayer.h" |
| 67 #include "core/storage/Storage.h" | 67 #include "core/storage/Storage.h" |
| 68 #include "core/workers/SharedWorkerRepository.h" | 68 #include "core/workers/SharedWorkerRepository.h" |
| 69 #include "wtf/ArrayBuffer.h" | 69 #include "wtf/ArrayBuffer.h" |
| 70 #include "wtf/OwnArrayPtr.h" | 70 #include "wtf/OwnArrayPtr.h" |
| 71 | 71 |
| 72 namespace WebCore { | 72 namespace WebCore { |
| 73 | 73 |
| 74 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. | 74 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. |
| 75 // We should refactor this. | 75 // We should refactor this. |
| 76 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool
singleShot) | 76 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, DOMTi
mer::Type timerType) |
| 77 { | 77 { |
| 78 int argumentCount = args.Length(); | 78 int argumentCount = args.Length(); |
| 79 | 79 |
| 80 if (argumentCount < 1) | 80 if (argumentCount < 1) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 DOMWindow* imp = V8Window::toNative(args.Holder()); | 83 DOMWindow* imp = V8Window::toNative(args.Holder()); |
| 84 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*>
(imp->document()); | 84 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*>
(imp->document()); |
| 85 | 85 |
| 86 if (!scriptContext) { | 86 if (!scriptContext) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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(imp->frame())) | 112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 ASSERT(imp->frame()); |
| 116 |
| 115 OwnPtr<ScheduledAction> action; | 117 OwnPtr<ScheduledAction> action; |
| 116 if (function->IsFunction()) { | 118 if (function->IsFunction()) { |
| 117 int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; | 119 int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; |
| 118 OwnArrayPtr<v8::Local<v8::Value> > params; | 120 OwnArrayPtr<v8::Local<v8::Value> > params; |
| 119 if (paramCount > 0) { | 121 if (paramCount > 0) { |
| 120 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); | 122 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); |
| 121 for (int i = 0; i < paramCount; i++) { | 123 for (int i = 0; i < paramCount; i++) { |
| 122 // parameters must be globalized | 124 // parameters must be globalized |
| 123 params[i] = args[i+2]; | 125 params[i] = args[i+2]; |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 | 128 |
| 127 // params is passed to action, and released in action's destructor | 129 // params is passed to action, and released in action's destructor |
| 128 ASSERT(imp->frame()); | |
| 129 action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWor
ldContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params.get(),
args.GetIsolate())); | 130 action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWor
ldContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params.get(),
args.GetIsolate())); |
| 130 } else { | 131 } else { |
| 131 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE
val()) { | 132 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE
val()) { |
| 132 v8SetReturnValue(args, 0); | 133 v8SetReturnValue(args, 0); |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 ASSERT(imp->frame()); | |
| 136 action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWor
ldContext(), functionString, KURL(), args.GetIsolate())); | 136 action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWor
ldContext(), functionString, KURL(), args.GetIsolate())); |
| 137 } | 137 } |
| 138 | 138 |
| 139 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; | 139 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; |
| 140 int timerId; | 140 int timerId; |
| 141 if (singleShot) | 141 switch (timerType) { |
| 142 case DOMTimer::TimeoutType: |
| 142 timerId = DOMWindowTimers::setTimeout(imp, action.release(), timeout); | 143 timerId = DOMWindowTimers::setTimeout(imp, action.release(), timeout); |
| 143 else | 144 break; |
| 145 case DOMTimer::IntervalType: |
| 144 timerId = DOMWindowTimers::setInterval(imp, action.release(), timeout); | 146 timerId = DOMWindowTimers::setInterval(imp, action.release(), timeout); |
| 147 break; |
| 148 } |
| 145 | 149 |
| 146 // Try to do the idle notification before the timeout expires to get better | 150 // 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. | 151 // use of any idle time. Aim for the middle of the interval for simplicity. |
| 148 if (timeout >= 0) { | 152 if (timeout >= 0) { |
| 149 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; | 153 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; |
| 150 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); | 154 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); |
| 151 } | 155 } |
| 152 | 156 |
| 153 v8SetReturnValue(args, timerId); | 157 v8SetReturnValue(args, timerId); |
| 154 } | 158 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 v8SetReturnValue(info, toV8Fast(items.release(), info, window)); | 418 v8SetReturnValue(info, toV8Fast(items.release(), info, window)); |
| 415 return; | 419 return; |
| 416 } | 420 } |
| 417 } | 421 } |
| 418 } | 422 } |
| 419 } | 423 } |
| 420 | 424 |
| 421 | 425 |
| 422 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
args) | 426 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
args) |
| 423 { | 427 { |
| 424 WindowSetTimeoutImpl(args, true); | 428 WindowSetTimeoutImpl(args, DOMTimer::TimeoutType); |
| 425 } | 429 } |
| 426 | 430 |
| 427 | 431 |
| 428 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& args) | 432 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& args) |
| 429 { | 433 { |
| 430 WindowSetTimeoutImpl(args, false); | 434 WindowSetTimeoutImpl(args, DOMTimer::IntervalType); |
| 431 } | 435 } |
| 432 | 436 |
| 433 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) | 437 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) |
| 434 { | 438 { |
| 435 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 439 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 436 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window:
:GetTemplate(isolate, worldTypeInMainThread(isolate))); | 440 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window:
:GetTemplate(isolate, worldTypeInMainThread(isolate))); |
| 437 if (window.IsEmpty()) | 441 if (window.IsEmpty()) |
| 438 return false; // the frame is gone. | 442 return false; // the frame is gone. |
| 439 | 443 |
| 440 DOMWindow* targetWindow = V8Window::toNative(window); | 444 DOMWindow* targetWindow = V8Window::toNative(window); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 ASSERT(!global.IsEmpty()); | 545 ASSERT(!global.IsEmpty()); |
| 542 return global; | 546 return global; |
| 543 } | 547 } |
| 544 | 548 |
| 545 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) | 549 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) |
| 546 { | 550 { |
| 547 return toV8(window, creationContext, isolate); | 551 return toV8(window, creationContext, isolate); |
| 548 } | 552 } |
| 549 | 553 |
| 550 } // namespace WebCore | 554 } // namespace WebCore |
| OLD | NEW |