2929#include " PlatformWebView.h"
3030#include " TestController.h"
3131#include < WebKit2/WKPage.h>
32+ #include < WebKit2/WKRetainPtr.h>
3233#include < wtf/PassOwnPtr.h>
3334#include < wtf/text/CString.h>
3435
@@ -53,11 +54,48 @@ static inline bool goToItemAtIndex(int index)
5354 return true ;
5455}
5556
57+ class WorkQueueItem {
58+ public:
59+ enum Type {
60+ Loading,
61+ NonLoading
62+ };
63+
64+ virtual ~WorkQueueItem () { }
65+ virtual Type invoke () const = 0;
66+ };
67+
68+ // Required by WKPageRunJavaScriptInMainFrame().
69+ static void runJavaScriptFunction (WKSerializedScriptValueRef, WKErrorRef, void *)
70+ {
71+ }
72+
73+ template <WorkQueueItem::Type type>
74+ class ScriptItem : public WorkQueueItem {
75+ public:
76+ explicit ScriptItem (const String& script)
77+ : m_script(AdoptWK, WKStringCreateWithUTF8CString(script.utf8().data()))
78+ {
79+ }
80+
81+ WorkQueueItem::Type invoke () const
82+ {
83+ WKPageRunJavaScriptInMainFrame (mainPage (), m_script.get (), 0 , runJavaScriptFunction);
84+ return type;
85+ }
86+
87+ WKRetainPtr<WKStringRef> m_script;
88+ };
89+
5690WorkQueueManager::WorkQueueManager ()
5791 : m_processing(false )
5892{
5993}
6094
95+ WorkQueueManager::~WorkQueueManager ()
96+ {
97+ }
98+
6199void WorkQueueManager::clearWorkQueue ()
62100{
63101 m_processing = false ;
@@ -69,7 +107,7 @@ bool WorkQueueManager::processWorkQueue()
69107 m_processing = false ;
70108 while (!m_processing && !m_workQueue.isEmpty ()) {
71109 OwnPtr<WorkQueueItem> item (m_workQueue.takeFirst ());
72- m_processing = item->invoke ();
110+ m_processing = ( item->invoke () == WorkQueueItem::Loading );
73111 }
74112
75113 return !m_processing;
@@ -85,15 +123,15 @@ void WorkQueueManager::queueLoad(const String& url, const String& target)
85123 {
86124 }
87125
88- bool invoke () const
126+ WorkQueueItem::Type invoke () const
89127 {
90128 if (!m_target.isEmpty ()) {
91129 // FIXME: Use target. Some layout tests cannot pass as they rely on this functionality.
92130 fprintf (stderr, " queueLoad for a specific target is not implemented.\n " );
93- return false ;
131+ return WorkQueueItem::NonLoading ;
94132 }
95133 WKPageLoadURL (mainPage (), m_url.get ());
96- return true ;
134+ return WorkQueueItem::Loading ;
97135 }
98136
99137 WKRetainPtr<WKURLRef> m_url;
@@ -107,9 +145,9 @@ void WorkQueueManager::queueBackNavigation(unsigned howFarBackward)
107145{
108146 class BackNavigationItem : public WorkQueueItem {
109147 public:
110- BackNavigationItem (unsigned howFarBackward) : m_howFarBackward(howFarBackward) { }
148+ explicit BackNavigationItem (unsigned howFarBackward) : m_howFarBackward(howFarBackward) { }
111149
112- bool invoke () const { return goToItemAtIndex (-m_howFarBackward); }
150+ WorkQueueItem::Type invoke () const { return goToItemAtIndex (-m_howFarBackward) ? WorkQueueItem::Loading : WorkQueueItem::NonLoading ; }
113151
114152 unsigned m_howFarBackward;
115153 };
@@ -121,16 +159,26 @@ void WorkQueueManager::queueReload()
121159{
122160 class ReloadItem : public WorkQueueItem {
123161 public:
124- bool invoke () const
162+ WorkQueueItem::Type invoke () const
125163 {
126164 WKPageReload (mainPage ());
127- return true ;
165+ return WorkQueueItem::Loading ;
128166 }
129167 };
130168
131169 enqueue (new ReloadItem ());
132170}
133171
172+ void WorkQueueManager::queueLoadingScript (const String& script)
173+ {
174+ enqueue (new ScriptItem<WorkQueueItem::Loading>(script));
175+ }
176+
177+ void WorkQueueManager::queueNonLoadingScript (const String& script)
178+ {
179+ enqueue (new ScriptItem<WorkQueueItem::NonLoading>(script));
180+ }
181+
134182void WorkQueueManager::enqueue (WorkQueueItem* item)
135183{
136184 ASSERT (item);
0 commit comments