initial import
[vuplus_webkit] / Source / WebCore / bindings / js / ScheduledAction.h
1 /*
2  *  Copyright (C) 2000 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved.
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #ifndef ScheduledAction_h
21 #define ScheduledAction_h
22
23 #include "JSDOMBinding.h"
24 #include "PlatformString.h"
25 #include <heap/Strong.h>
26 #include <runtime/JSCell.h>
27 #include <wtf/PassOwnPtr.h>
28 #include <wtf/Vector.h>
29
30 namespace JSC {
31     class JSGlobalObject;
32 }
33
34 namespace WebCore {
35
36     class Document;
37     class ContentSecurityPolicy;
38     class ScriptExecutionContext;
39     class WorkerContext;
40
41    /* An action (either function or string) to be executed after a specified
42     * time interval, either once or repeatedly. Used for window.setTimeout()
43     * and window.setInterval()
44     */
45     class ScheduledAction {
46         WTF_MAKE_NONCOPYABLE(ScheduledAction); WTF_MAKE_FAST_ALLOCATED;
47     public:
48         static PassOwnPtr<ScheduledAction> create(JSC::ExecState*, DOMWrapperWorld* isolatedWorld, ContentSecurityPolicy*);
49
50         void execute(ScriptExecutionContext*);
51
52     private:
53         ScheduledAction(JSC::ExecState*, JSC::JSValue function, DOMWrapperWorld* isolatedWorld);
54         ScheduledAction(const String& code, DOMWrapperWorld* isolatedWorld)
55             : m_function(*isolatedWorld->globalData())
56             , m_code(code)
57             , m_isolatedWorld(isolatedWorld)
58         {
59         }
60
61         void executeFunctionInContext(JSC::JSGlobalObject*, JSC::JSValue thisValue, ScriptExecutionContext*);
62         void execute(Document*);
63 #if ENABLE(WORKERS)
64         void execute(WorkerContext*);
65 #endif
66
67         JSC::Strong<JSC::Unknown> m_function;
68         Vector<JSC::Strong<JSC::Unknown> > m_args;
69         String m_code;
70         RefPtr<DOMWrapperWorld> m_isolatedWorld;
71     };
72
73 } // namespace WebCore
74
75 #endif // ScheduledAction_h