WorkQueueItemGtk.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "config.h"
  20. #include "WorkQueueItem.h"
  21. #include "DumpRenderTree.h"
  22. #include <JavaScriptCore/JSStringRef.h>
  23. #include <string.h>
  24. #include <webkit/webkit.h>
  25. #include <wtf/gobject/GOwnPtr.h>
  26. // Returns a newly allocated UTF-8 character buffer which must be freed with g_free()
  27. gchar* JSStringCopyUTF8CString(JSStringRef jsString)
  28. {
  29. size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString);
  30. gchar* utf8 = (gchar*)g_malloc(dataSize);
  31. JSStringGetUTF8CString(jsString, utf8, dataSize);
  32. return utf8;
  33. }
  34. bool LoadItem::invoke() const
  35. {
  36. gchar* targetString = JSStringCopyUTF8CString(m_target.get());
  37. WebKitWebFrame* targetFrame;
  38. if (!strlen(targetString))
  39. targetFrame = mainFrame;
  40. else
  41. targetFrame = webkit_web_frame_find_frame(mainFrame, targetString);
  42. g_free(targetString);
  43. gchar* urlString = JSStringCopyUTF8CString(m_url.get());
  44. WebKitNetworkRequest* request = webkit_network_request_new(urlString);
  45. g_free(urlString);
  46. webkit_web_frame_load_request(targetFrame, request);
  47. g_object_unref(request);
  48. return true;
  49. }
  50. bool LoadHTMLStringItem::invoke() const
  51. {
  52. GOwnPtr<gchar> content(JSStringCopyUTF8CString(m_content.get()));
  53. GOwnPtr<gchar> baseURL(JSStringCopyUTF8CString(m_baseURL.get()));
  54. if (m_unreachableURL) {
  55. GOwnPtr<gchar> unreachableURL(JSStringCopyUTF8CString(m_unreachableURL.get()));
  56. webkit_web_frame_load_alternate_string(mainFrame, content.get(), baseURL.get(), unreachableURL.get());
  57. return true;
  58. }
  59. webkit_web_frame_load_string(mainFrame, content.get(), 0, 0, baseURL.get());
  60. return true;
  61. }
  62. bool ReloadItem::invoke() const
  63. {
  64. webkit_web_frame_reload(mainFrame);
  65. return true;
  66. }
  67. bool ScriptItem::invoke() const
  68. {
  69. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  70. gchar* scriptString = JSStringCopyUTF8CString(m_script.get());
  71. webkit_web_view_execute_script(webView, scriptString);
  72. g_free(scriptString);
  73. return true;
  74. }
  75. bool BackForwardItem::invoke() const
  76. {
  77. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  78. if (m_howFar == 1)
  79. webkit_web_view_go_forward(webView);
  80. else if (m_howFar == -1)
  81. webkit_web_view_go_back(webView);
  82. else {
  83. WebKitWebBackForwardList* webBackForwardList = webkit_web_view_get_back_forward_list(webView);
  84. WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_nth_item(webBackForwardList, m_howFar);
  85. webkit_web_view_go_to_back_forward_item(webView, item);
  86. }
  87. return true;
  88. }