OSDN Git Service

auto import from //depot/cupcake/@135843
[android-x86/external-webkit.git] / WebKitTools / DumpRenderTree / gtk / WorkQueueItemGtk.cpp
1 /*
2  * Copyright (C) 2007 Alp Toker <alp@atoker.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21 #include "WorkQueueItem.h"
22
23 #include "DumpRenderTree.h"
24
25 #include <JavaScriptCore/JSStringRef.h>
26 #include <webkit/webkit.h>
27 #include <string.h>
28
29 // Returns a newly allocated UTF-8 character buffer which must be freed with g_free()
30 gchar* JSStringCopyUTF8CString(JSStringRef jsString)
31 {
32     size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString);
33     gchar* utf8 = (gchar*)g_malloc(dataSize);
34     JSStringGetUTF8CString(jsString, utf8, dataSize);
35
36     return utf8;
37 }
38
39 void LoadItem::invoke() const
40 {
41     gchar* targetString = JSStringCopyUTF8CString(target());
42
43     WebKitWebFrame* targetFrame;
44     if (!strlen(targetString))
45         targetFrame = mainFrame;
46     else
47         targetFrame = webkit_web_frame_find_frame(mainFrame, targetString);
48     g_free(targetString);
49
50     gchar* urlString = JSStringCopyUTF8CString(url());
51     WebKitNetworkRequest* request = webkit_network_request_new(urlString);
52     g_free(urlString);
53     webkit_web_frame_load_request(targetFrame, request);
54     g_object_unref(request);
55 }
56
57 void ReloadItem::invoke() const
58 {
59     webkit_web_frame_reload(mainFrame);
60 }
61
62 void ScriptItem::invoke() const
63 {
64     WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
65     gchar* scriptString = JSStringCopyUTF8CString(script());
66     webkit_web_view_execute_script(webView, scriptString);
67     g_free(scriptString);
68 }
69
70 void BackForwardItem::invoke() const
71 {
72     WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
73     webkit_web_view_go_back_or_forward(webView, m_howFar);
74 }