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 35 class WorkQueueItem { 36 public: 37 virtual ~WorkQueueItem() { } 38 virtual bool invoke() const = 0; // Returns true if this started a load. 39 }; 40 41 class LoadItem : public WorkQueueItem { 42 public: 43 LoadItem(const JSStringRef url, const JSStringRef target) 44 : m_url(url) 45 , m_target(target) 46 { 47 } 48 49 private: 50 virtual bool invoke() const; 51 52 JSRetainPtr<JSStringRef> m_url; 53 JSRetainPtr<JSStringRef> m_target; 54 }; 55 56 class ReloadItem : public WorkQueueItem { 57 private: 58 virtual bool invoke() const; 59 }; 60 61 class ScriptItem : public WorkQueueItem { 62 protected: 63 ScriptItem(const JSStringRef script) 64 : m_script(script) 65 { 66 } 67 68 protected: 69 virtual bool invoke() const; 70 71 private: 72 JSRetainPtr<JSStringRef> m_script; 73 }; 74 75 class LoadingScriptItem : public ScriptItem { 76 public: 77 LoadingScriptItem(const JSStringRef script) 78 : ScriptItem(script) 79 { 80 } 81 82 private: 83 virtual bool invoke() const { return ScriptItem::invoke(); } 84 }; 85 86 class NonLoadingScriptItem : public ScriptItem { 87 public: 88 NonLoadingScriptItem(const JSStringRef script) 89 : ScriptItem(script) 90 { 91 } 92 93 private: 94 virtual bool invoke() const { ScriptItem::invoke(); return false; } 95 }; 96 97 class BackForwardItem : public WorkQueueItem { 98 protected: 99 BackForwardItem(int howFar) 100 : m_howFar(howFar) 101 { 102 } 103 104 private: 105 virtual bool invoke() const; 106 107 int m_howFar; 108 }; 109 110 class BackItem : public BackForwardItem { 111 public: 112 BackItem(unsigned howFar) 113 : BackForwardItem(-howFar) 114 { 115 } 116 }; 117 118 class ForwardItem : public BackForwardItem { 119 public: 120 ForwardItem(unsigned howFar) 121 : BackForwardItem(howFar) 122 { 123 } 124 }; 125 126 #endif // !defined(WorkQueueItem_h) 127