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.
20 #include "WorkQueueItem.h"
21 #include "DumpRenderTree.h"
23 #include <JavaScriptCore/JSStringRef.h>
24 #include <webkit/webkit.h>
26 // Returns a newly allocated UTF-8 character buffer which must be freed with g_free()
27 static gchar* JSStringCopyUTF8CString(JSStringRef jsString)
29 size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString);
30 gchar* utf8 = (gchar*)g_malloc(dataSize);
31 JSStringGetUTF8CString(jsString, utf8, dataSize);
36 void LoadItem::invoke() const
38 gchar* targetString = JSStringCopyUTF8CString(target());
40 WebKitWebFrame* targetFrame;
41 if (!strlen(targetString))
42 targetFrame = mainFrame;
44 targetFrame = webkit_web_frame_find_frame(mainFrame, targetString);
47 gchar* urlString = JSStringCopyUTF8CString(url());
48 WebKitNetworkRequest* request = webkit_network_request_new(urlString);
50 webkit_web_frame_load_request(targetFrame, request);
51 g_object_unref(request);
54 void ReloadItem::invoke() const
56 webkit_web_frame_reload(mainFrame);
59 void ScriptItem::invoke() const
61 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
62 gchar* scriptString = JSStringCopyUTF8CString(script());
63 // TODO: does this return something we need to free? If not, why not?
64 webkit_web_view_execute_script(webView, scriptString);
68 void BackForwardItem::invoke() const
70 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
71 webkit_web_view_go_back_or_forward(webView, m_howFar);