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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #include "core/page/Settings.h" | 62 #include "core/page/Settings.h" |
63 #include "core/page/WindowFeatures.h" | 63 #include "core/page/WindowFeatures.h" |
64 #include "core/platform/PlatformScreen.h" | 64 #include "core/platform/PlatformScreen.h" |
65 #include "core/platform/graphics/MediaPlayer.h" | 65 #include "core/platform/graphics/MediaPlayer.h" |
66 #include "core/storage/Storage.h" | 66 #include "core/storage/Storage.h" |
67 #include "core/workers/SharedWorkerRepository.h" | 67 #include "core/workers/SharedWorkerRepository.h" |
68 #include "wtf/ArrayBuffer.h" | 68 #include "wtf/ArrayBuffer.h" |
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, DOMTi
mer::TimerType timerType) |
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 = V8Window::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) { |
(...skipping 22 matching lines...) Expand all Loading... |
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 ASSERT(imp->frame()); |
| 116 |
115 int id; | 117 int id; |
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 v8::Local<v8::Value>* params = 0; | 120 v8::Local<v8::Value>* params = 0; |
119 if (paramCount > 0) { | 121 if (paramCount > 0) { |
120 params = new v8::Local<v8::Value>[paramCount]; | 122 params = 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 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(imp->frame
()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), p
aramCount, params, args.GetIsolate())); | 130 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(imp->frame
()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), p
aramCount, params, args.GetIsolate())); |
130 | 131 |
131 // FIXME: We should use OwnArrayPtr for params. | 132 // FIXME: We should use OwnArrayPtr for params. |
132 delete[] params; | 133 delete[] params; |
133 | 134 |
134 id = DOMTimer::install(scriptContext, action.release(), timeout, singleS
hot); | 135 id = DOMTimer::install(scriptContext, timerType, action.release(), timeo
ut); |
135 } else { | 136 } else { |
136 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE
val()) { | 137 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE
val()) { |
137 v8SetReturnValue(args, 0); | 138 v8SetReturnValue(args, 0); |
138 return; | 139 return; |
139 } | 140 } |
140 ASSERT(imp->frame()); | 141 id = DOMTimer::install(scriptContext, timerType, adoptPtr(new ScheduledA
ction(imp->frame()->script()->currentWorldContext(), functionString, KURL(), arg
s.GetIsolate())), timeout); |
141 id = DOMTimer::install(scriptContext, adoptPtr(new ScheduledAction(imp->
frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolat
e())), timeout, singleShot); | |
142 } | 142 } |
143 | 143 |
144 // 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 |
145 // 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. |
146 if (timeout >= 0) { | 146 if (timeout >= 0) { |
147 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; | 147 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; |
148 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); | 148 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); |
149 } | 149 } |
150 | 150 |
151 v8SetReturnValue(args, id); | 151 v8SetReturnValue(args, id); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 v8SetReturnValue(info, toV8Fast(items.release(), info, window)); | 412 v8SetReturnValue(info, toV8Fast(items.release(), info, window)); |
413 return; | 413 return; |
414 } | 414 } |
415 } | 415 } |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 | 419 |
420 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
args) | 420 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
args) |
421 { | 421 { |
422 WindowSetTimeoutImpl(args, true); | 422 WindowSetTimeoutImpl(args, DOMTimer::TimerTypeTimeout); |
423 } | 423 } |
424 | 424 |
425 | 425 |
426 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& args) | 426 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& args) |
427 { | 427 { |
428 WindowSetTimeoutImpl(args, false); | 428 WindowSetTimeoutImpl(args, DOMTimer::TimerTypeInterval); |
429 } | 429 } |
430 | 430 |
431 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) | 431 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) |
432 { | 432 { |
433 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 433 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
434 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window:
:GetTemplate(isolate, worldTypeInMainThread(isolate))); | 434 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window:
:GetTemplate(isolate, worldTypeInMainThread(isolate))); |
435 if (window.IsEmpty()) | 435 if (window.IsEmpty()) |
436 return false; // the frame is gone. | 436 return false; // the frame is gone. |
437 | 437 |
438 DOMWindow* targetWindow = V8Window::toNative(window); | 438 DOMWindow* targetWindow = V8Window::toNative(window); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 ASSERT(!global.IsEmpty()); | 539 ASSERT(!global.IsEmpty()); |
540 return global; | 540 return global; |
541 } | 541 } |
542 | 542 |
543 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) | 543 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) |
544 { | 544 { |
545 return toV8(window, creationContext, isolate); | 545 return toV8(window, creationContext, isolate); |
546 } | 546 } |
547 | 547 |
548 } // namespace WebCore | 548 } // namespace WebCore |
OLD | NEW |