2 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "WorkQueueItem.h"
23 #include "DumpRenderTree.h"
25 #include <JavaScriptCore/JSStringRef.h>
26 #include <webkit/webkit.h>
29 // Returns a newly allocated UTF-8 character buffer which must be freed with g_free()
30 gchar* JSStringCopyUTF8CString(JSStringRef jsString)
32 size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString);
33 gchar* utf8 = (gchar*)g_malloc(dataSize);
34 JSStringGetUTF8CString(jsString, utf8, dataSize);
39 void LoadItem::invoke() const
41 gchar* targetString = JSStringCopyUTF8CString(target());
43 WebKitWebFrame* targetFrame;
44 if (!strlen(targetString))
45 targetFrame = mainFrame;
47 targetFrame = webkit_web_frame_find_frame(mainFrame, targetString);
50 gchar* urlString = JSStringCopyUTF8CString(url());
51 WebKitNetworkRequest* request = webkit_network_request_new(urlString);
53 webkit_web_frame_load_request(targetFrame, request);
54 g_object_unref(request);
57 void ReloadItem::invoke() const
59 webkit_web_frame_reload(mainFrame);
62 void ScriptItem::invoke() const
64 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
65 gchar* scriptString = JSStringCopyUTF8CString(script());
66 webkit_web_view_execute_script(webView, scriptString);
70 void BackForwardItem::invoke() const
72 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
73 webkit_web_view_go_back_or_forward(webView, m_howFar);