WebKitTools/DumpRenderTree/WorkQueueItem.h
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     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 LoadHTMLStringItem : public WorkQueueItem {
       
    57 public:
       
    58     LoadHTMLStringItem(const JSStringRef content, const JSStringRef baseURL)
       
    59         : m_content(content)
       
    60         , m_baseURL(baseURL)
       
    61     {
       
    62     }
       
    63 
       
    64 private:
       
    65     virtual bool invoke() const;
       
    66 
       
    67     JSRetainPtr<JSStringRef> m_content;
       
    68     JSRetainPtr<JSStringRef> m_baseURL;
       
    69 };
       
    70 
       
    71 class ReloadItem : public WorkQueueItem {
       
    72 private:
       
    73     virtual bool invoke() const;
       
    74 };
       
    75 
       
    76 class ScriptItem : public WorkQueueItem {
       
    77 protected:
       
    78     ScriptItem(const JSStringRef script)
       
    79         : m_script(script)
       
    80     {
       
    81     }
       
    82 
       
    83 protected:
       
    84     virtual bool invoke() const;
       
    85 
       
    86 private:
       
    87     JSRetainPtr<JSStringRef> m_script;
       
    88 };
       
    89 
       
    90 class LoadingScriptItem : public ScriptItem {
       
    91 public:
       
    92     LoadingScriptItem(const JSStringRef script)
       
    93         : ScriptItem(script)
       
    94     {
       
    95     }
       
    96 
       
    97 private:
       
    98     virtual bool invoke() const { return ScriptItem::invoke(); }
       
    99 };
       
   100 
       
   101 class NonLoadingScriptItem : public ScriptItem {
       
   102 public:
       
   103     NonLoadingScriptItem(const JSStringRef script)
       
   104         : ScriptItem(script)
       
   105     {
       
   106     }
       
   107 
       
   108 private:
       
   109     virtual bool invoke() const { ScriptItem::invoke(); return false; }
       
   110 };
       
   111 
       
   112 class BackForwardItem : public WorkQueueItem {
       
   113 protected:
       
   114     BackForwardItem(int howFar)
       
   115         : m_howFar(howFar)
       
   116     {
       
   117     }
       
   118 
       
   119 private:
       
   120     virtual bool invoke() const;
       
   121 
       
   122     int m_howFar;
       
   123 };
       
   124 
       
   125 class BackItem : public BackForwardItem {
       
   126 public:
       
   127     BackItem(unsigned howFar)
       
   128         : BackForwardItem(-howFar)
       
   129     {
       
   130     }
       
   131 };
       
   132 
       
   133 class ForwardItem : public BackForwardItem {
       
   134 public:
       
   135     ForwardItem(unsigned howFar)
       
   136         : BackForwardItem(howFar)
       
   137     {
       
   138     }
       
   139 };
       
   140 
       
   141 #endif // !defined(WorkQueueItem_h)