WebKitTools/DumpRenderTree/gtk/WorkQueueItemGtk.cpp
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     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 bool LoadItem::invoke() const
       
    40 {
       
    41     gchar* targetString = JSStringCopyUTF8CString(m_target.get());
       
    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(m_url.get());
       
    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     return true;
       
    57 }
       
    58 
       
    59 bool LoadHTMLStringItem::invoke() const
       
    60 {
       
    61     return false;
       
    62 }
       
    63 
       
    64 bool ReloadItem::invoke() const
       
    65 {
       
    66     webkit_web_frame_reload(mainFrame);
       
    67     return true;
       
    68 }
       
    69 
       
    70 bool ScriptItem::invoke() const
       
    71 {
       
    72     WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
       
    73     gchar* scriptString = JSStringCopyUTF8CString(m_script.get());
       
    74     webkit_web_view_execute_script(webView, scriptString);
       
    75     g_free(scriptString);
       
    76     return true;
       
    77 }
       
    78 
       
    79 bool BackForwardItem::invoke() const
       
    80 {
       
    81     WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
       
    82     if (m_howFar == 1)
       
    83         webkit_web_view_go_forward(webView);
       
    84     else if (m_howFar == -1)
       
    85         webkit_web_view_go_back(webView);
       
    86     else {
       
    87         WebKitWebBackForwardList* webBackForwardList = webkit_web_view_get_back_forward_list(webView);
       
    88         WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_nth_item(webBackForwardList, m_howFar);
       
    89         webkit_web_view_go_to_back_forward_item(webView, item);
       
    90     }
       
    91     return true;
       
    92 }