WorkQueueItem.h 4.1 KB

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