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 <heap/Strong.h>
25#include <heap/StrongInlines.h>
26#include <memory>
27#include <runtime/JSCell.h>
28#include <wtf/Vector.h>
29#include <wtf/text/WTFString.h>
30
31namespace JSC {
32    class JSGlobalObject;
33}
34
35namespace WebCore {
36
37    class Document;
38    class ContentSecurityPolicy;
39    class ScriptExecutionContext;
40    class WorkerGlobalScope;
41
42   /* An action (either function or string) to be executed after a specified
43    * time interval, either once or repeatedly. Used for window.setTimeout()
44    * and window.setInterval()
45    */
46    class ScheduledAction {
47        WTF_MAKE_NONCOPYABLE(ScheduledAction); WTF_MAKE_FAST_ALLOCATED;
48    public:
49        static std::unique_ptr<ScheduledAction> create(JSC::ExecState*, DOMWrapperWorld& isolatedWorld, ContentSecurityPolicy*);
50
51        void execute(ScriptExecutionContext*);
52
53    private:
54        ScheduledAction(JSC::ExecState*, JSC::JSValue function, DOMWrapperWorld& isolatedWorld);
55        ScheduledAction(const String& code, DOMWrapperWorld& isolatedWorld)
56            : m_function(isolatedWorld.vm())
57            , m_code(code)
58            , m_isolatedWorld(&isolatedWorld)
59        {
60        }
61
62        void executeFunctionInContext(JSC::JSGlobalObject*, JSC::JSValue thisValue, ScriptExecutionContext*);
63        void execute(Document*);
64        void execute(WorkerGlobalScope*);
65
66        JSC::Strong<JSC::Unknown> m_function;
67        Vector<JSC::Strong<JSC::Unknown>> m_args;
68        String m_code;
69        RefPtr<DOMWrapperWorld> m_isolatedWorld;
70    };
71
72} // namespace WebCore
73
74#endif // ScheduledAction_h
75