WorkQueueItemBlackBerry.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2009, 2010, 2012 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser 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. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "WorkQueueItem.h"
  20. #include "DumpRenderTreeBlackBerry.h"
  21. #include "Frame.h"
  22. #include "FrameLoadRequest.h"
  23. #include "KURL.h"
  24. #include "WebPage.h"
  25. #include <wtf/OwnArrayPtr.h>
  26. using namespace WebCore;
  27. bool LoadItem::invoke() const
  28. {
  29. size_t targetArrSize = JSStringGetMaximumUTF8CStringSize(m_target.get());
  30. size_t urlArrSize = JSStringGetMaximumUTF8CStringSize(m_url.get());
  31. OwnArrayPtr<char> target = adoptArrayPtr(new char[targetArrSize]);
  32. OwnArrayPtr<char> url = adoptArrayPtr(new char[urlArrSize]);
  33. size_t targetLen = JSStringGetUTF8CString(m_target.get(), target.get(), targetArrSize) - 1;
  34. JSStringGetUTF8CString(m_url.get(), url.get(), urlArrSize);
  35. Frame* frame;
  36. if (target && targetLen)
  37. frame = mainFrame->tree()->find(target.get());
  38. else
  39. frame = mainFrame;
  40. if (!frame)
  41. return false;
  42. KURL kurl = KURL(KURL(), url.get());
  43. frame->loader()->load(FrameLoadRequest(frame, ResourceRequest(kurl)));
  44. return true;
  45. }
  46. bool LoadHTMLStringItem::invoke() const
  47. {
  48. size_t contentSize = JSStringGetMaximumUTF8CStringSize(m_content.get());
  49. size_t baseURLSize = JSStringGetMaximumUTF8CStringSize(m_baseURL.get());
  50. size_t unreachableURLSize = JSStringGetMaximumUTF8CStringSize(m_unreachableURL.get());
  51. OwnArrayPtr<char> content = adoptArrayPtr(new char[contentSize]);
  52. OwnArrayPtr<char> baseURL = adoptArrayPtr(new char[baseURLSize]);
  53. OwnArrayPtr<char> unreachableURL = adoptArrayPtr(new char[unreachableURLSize]);
  54. JSStringGetUTF8CString(m_content.get(), content.get(), contentSize);
  55. JSStringGetUTF8CString(m_baseURL.get(), baseURL.get(), baseURLSize);
  56. JSStringGetUTF8CString(m_unreachableURL.get(), unreachableURL.get(), unreachableURLSize);
  57. STATIC_LOCAL_STRING(s_textHtml, "text/html");
  58. BlackBerry::WebKit::DumpRenderTree::currentInstance()->page()->loadString(BlackBerry::Platform::String::fromUtf8(content.get()), BlackBerry::Platform::String::fromUtf8(baseURL.get()), s_textHtml, unreachableURLSize ? BlackBerry::Platform::String::fromUtf8(unreachableURL.get()) : BlackBerry::Platform::String::emptyString());
  59. return true;
  60. }
  61. bool ReloadItem::invoke() const
  62. {
  63. mainFrame->loader()->reload(true);
  64. return true;
  65. }
  66. bool ScriptItem::invoke() const
  67. {
  68. BlackBerry::WebKit::JavaScriptDataType type;
  69. BlackBerry::Platform::String result;
  70. size_t scriptArrSize = JSStringGetMaximumUTF8CStringSize(m_script.get());
  71. OwnArrayPtr<char> script = adoptArrayPtr(new char[scriptArrSize]);
  72. JSStringGetUTF8CString(m_script.get(), script.get(), scriptArrSize);
  73. BlackBerry::WebKit::DumpRenderTree::currentInstance()->page()->executeJavaScript(BlackBerry::Platform::String::fromRawData(script.get(), scriptArrSize), type, result);
  74. return true;
  75. }
  76. bool BackForwardItem::invoke() const
  77. {
  78. return BlackBerry::WebKit::DumpRenderTree::currentInstance()->page()->goBackOrForward(m_howFar);
  79. }