1/*
2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef WorkQueueItem_h
30#define WorkQueueItem_h
31
32#include <JavaScriptCore/JSRetainPtr.h>
33#include <JavaScriptCore/JSBase.h>
34
35class WorkQueueItem {
36public:
37    virtual ~WorkQueueItem() { }
38    virtual bool invoke() const = 0; // Returns true if this started a load.
39};
40
41class LoadItem : public WorkQueueItem {
42public:
43    LoadItem(const JSStringRef url, const JSStringRef target)
44        : m_url(url)
45        , m_target(target)
46    {
47    }
48
49private:
50    virtual bool invoke() const;
51
52    JSRetainPtr<JSStringRef> m_url;
53    JSRetainPtr<JSStringRef> m_target;
54};
55
56class LoadHTMLStringItem : public WorkQueueItem {
57public:
58    LoadHTMLStringItem(const JSStringRef content, const JSStringRef baseURL)
59        : m_content(content)
60        , m_baseURL(baseURL)
61    {
62    }
63
64    LoadHTMLStringItem(const JSStringRef content, const JSStringRef baseURL, const JSStringRef unreachableURL)
65        : m_content(content)
66        , m_baseURL(baseURL)
67        , m_unreachableURL(unreachableURL)
68    {
69    }
70
71private:
72    virtual bool invoke() const;
73
74    JSRetainPtr<JSStringRef> m_content;
75    JSRetainPtr<JSStringRef> m_baseURL;
76    JSRetainPtr<JSStringRef> m_unreachableURL;
77};
78
79class ReloadItem : public WorkQueueItem {
80private:
81    virtual bool invoke() const;
82};
83
84class ScriptItem : public WorkQueueItem {
85protected:
86    ScriptItem(const JSStringRef script)
87        : m_script(script)
88    {
89    }
90
91protected:
92    virtual bool invoke() const;
93
94private:
95    JSRetainPtr<JSStringRef> m_script;
96};
97
98class LoadingScriptItem : public ScriptItem {
99public:
100    LoadingScriptItem(const JSStringRef script)
101        : ScriptItem(script)
102    {
103    }
104
105private:
106    virtual bool invoke() const { return ScriptItem::invoke(); }
107};
108
109class NonLoadingScriptItem : public ScriptItem {
110public:
111    NonLoadingScriptItem(const JSStringRef script)
112        : ScriptItem(script)
113    {
114    }
115
116private:
117    virtual bool invoke() const { ScriptItem::invoke(); return false; }
118};
119
120class BackForwardItem : public WorkQueueItem {
121protected:
122    BackForwardItem(int howFar)
123        : m_howFar(howFar)
124    {
125    }
126
127private:
128    virtual bool invoke() const;
129
130    int m_howFar;
131};
132
133class BackItem : public BackForwardItem {
134public:
135    BackItem(unsigned howFar)
136        : BackForwardItem(-howFar)
137    {
138    }
139};
140
141class ForwardItem : public BackForwardItem {
142public:
143    ForwardItem(unsigned howFar)
144        : BackForwardItem(howFar)
145    {
146    }
147};
148
149#endif // !defined(WorkQueueItem_h)
150