WebDriverConnection.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #include "WebDriverConnection.h"
  9. #include "BrowserWindow.h"
  10. #include <AK/Vector.h>
  11. #include <LibWeb/Cookie/Cookie.h>
  12. namespace Browser {
  13. WebDriverConnection::WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window)
  14. : IPC::ConnectionToServer<WebDriverSessionClientEndpoint, WebDriverSessionServerEndpoint>(*this, move(socket))
  15. , m_browser_window(move(browser_window))
  16. {
  17. }
  18. void WebDriverConnection::quit()
  19. {
  20. dbgln("WebDriverConnection: quit");
  21. if (auto browser_window = m_browser_window.strong_ref())
  22. browser_window->close();
  23. }
  24. Messages::WebDriverSessionClient::GetUrlResponse WebDriverConnection::get_url()
  25. {
  26. dbgln("WebDriverConnection: get_url");
  27. if (auto browser_window = m_browser_window.strong_ref())
  28. return { browser_window->active_tab().url() };
  29. return { URL("") };
  30. }
  31. void WebDriverConnection::set_url(AK::URL const& url)
  32. {
  33. dbgln("WebDriverConnection: set_url {}", url);
  34. if (auto browser_window = m_browser_window.strong_ref())
  35. browser_window->active_tab().load(url);
  36. }
  37. Messages::WebDriverSessionClient::GetTitleResponse WebDriverConnection::get_title()
  38. {
  39. dbgln("WebDriverConnection: get_title");
  40. if (auto browser_window = m_browser_window.strong_ref())
  41. return { browser_window->active_tab().title() };
  42. return { "" };
  43. }
  44. void WebDriverConnection::refresh()
  45. {
  46. dbgln("WebDriverConnection: refresh");
  47. if (auto browser_window = m_browser_window.strong_ref())
  48. browser_window->active_tab().reload();
  49. }
  50. void WebDriverConnection::back()
  51. {
  52. dbgln("WebDriverConnection: back");
  53. if (auto browser_window = m_browser_window.strong_ref())
  54. browser_window->active_tab().go_back();
  55. }
  56. void WebDriverConnection::forward()
  57. {
  58. dbgln("WebDriverConnection: forward");
  59. if (auto browser_window = m_browser_window.strong_ref())
  60. browser_window->active_tab().go_forward();
  61. }
  62. Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
  63. {
  64. dbgln("WebDriverConnection: get_cookies");
  65. if (auto browser_window = m_browser_window.strong_ref()) {
  66. if (browser_window->active_tab().on_get_cookies_entries) {
  67. return { browser_window->active_tab().on_get_cookies_entries() };
  68. }
  69. }
  70. return { {} };
  71. }
  72. }