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>
27 #include <webkit/webkit.h>
28 #include <wtf/gobject/GOwnPtr.h>
30 // Returns a newly allocated UTF-8 character buffer which must be freed with g_free()
31 gchar* JSStringCopyUTF8CString(JSStringRef jsString)
33 size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString);
34 gchar* utf8 = (gchar*)g_malloc(dataSize);
35 JSStringGetUTF8CString(jsString, utf8, dataSize);
40 bool LoadItem::invoke() const
42 gchar* targetString = JSStringCopyUTF8CString(m_target.get());
44 WebKitWebFrame* targetFrame;
45 if (!strlen(targetString))
46 targetFrame = mainFrame;
48 targetFrame = webkit_web_frame_find_frame(mainFrame, targetString);
51 gchar* urlString = JSStringCopyUTF8CString(m_url.get());
52 WebKitNetworkRequest* request = webkit_network_request_new(urlString);
54 webkit_web_frame_load_request(targetFrame, request);
55 g_object_unref(request);
60 bool LoadHTMLStringItem::invoke() const
62 GOwnPtr<gchar> content(JSStringCopyUTF8CString(m_content.get()));
63 GOwnPtr<gchar> baseURL(JSStringCopyUTF8CString(m_baseURL.get()));
65 if (m_unreachableURL) {
66 GOwnPtr<gchar> unreachableURL(JSStringCopyUTF8CString(m_unreachableURL.get()));
67 webkit_web_frame_load_alternate_string(mainFrame, content.get(), baseURL.get(), unreachableURL.get());
70 webkit_web_frame_load_string(mainFrame, content.get(), 0, 0, baseURL.get());
74 bool ReloadItem::invoke() const
76 webkit_web_frame_reload(mainFrame);
80 bool ScriptItem::invoke() const
82 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
83 gchar* scriptString = JSStringCopyUTF8CString(m_script.get());
84 webkit_web_view_execute_script(webView, scriptString);
89 bool BackForwardItem::invoke() const
91 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
93 webkit_web_view_go_forward(webView);
94 else if (m_howFar == -1)
95 webkit_web_view_go_back(webView);
97 WebKitWebBackForwardList* webBackForwardList = webkit_web_view_get_back_forward_list(webView);
98 WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_nth_item(webBackForwardList, m_howFar);
99 webkit_web_view_go_to_back_forward_item(webView, item);