[WTF] Add environment variable helpers
[WebKit-https.git] / Source / WebKit / UIProcess / API / wpe / WPEView.cpp
index 5565645..d39eb77 100644 (file)
@@ -35,8 +35,8 @@
 #include "NativeWebWheelEvent.h"
 #include "WebPageGroup.h"
 #include "WebProcessPool.h"
-#include <JavaScriptCore/JSBase.h>
-#include <wpe/view-backend.h>
+#include <wpe/wpe.h>
+#include <wtf/Environment.h>
 
 using namespace WebKit;
 
@@ -46,9 +46,13 @@ View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseC
     : m_client(std::make_unique<API::ViewClient>())
     , m_pageClient(std::make_unique<PageClientImpl>(*this))
     , m_size { 800, 600 }
-    , m_viewStateFlags(WebCore::ActivityState::WindowIsActive | WebCore::ActivityState::IsFocused | WebCore::ActivityState::IsVisible | WebCore::ActivityState::IsInWindow)
-    , m_compositingManagerProxy(*this)
+#if !defined(WPE_BACKEND_CHECK_VERSION) || !WPE_BACKEND_CHECK_VERSION(1, 1, 0)
+    , m_viewStateFlags { WebCore::ActivityState::WindowIsActive, WebCore::ActivityState::IsFocused, WebCore::ActivityState::IsVisible, WebCore::ActivityState::IsInWindow }
+#endif
+    , m_backend(backend)
 {
+    ASSERT(m_backend);
+
     auto configuration = baseConfiguration.copy();
     auto* preferences = configuration->preferences();
     if (!preferences && configuration->pageGroup()) {
@@ -66,10 +70,10 @@ View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseC
     auto* pool = configuration->processPool();
     m_pageProxy = pool->createWebPage(*m_pageClient, WTFMove(configuration));
 
-    m_backend = backend;
-    if (!m_backend)
-        m_backend = wpe_view_backend_create();
-    m_compositingManagerProxy.initialize();
+#if ENABLE(MEMORY_SAMPLER)
+    if (Environment::get("WEBKIT_SAMPLE_MEMORY"))
+        pool->startMemorySampler(0);
+#endif
 
     static struct wpe_view_backend_client s_backendClient = {
         // set_size
@@ -83,7 +87,30 @@ View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseC
         {
             auto& view = *reinterpret_cast<View*>(data);
             view.frameDisplayed();
-        }
+        },
+#if defined(WPE_BACKEND_CHECK_VERSION) && WPE_BACKEND_CHECK_VERSION(1, 1, 0)
+        // activity_state_changed
+        [](void* data, uint32_t state)
+        {
+            auto& view = *reinterpret_cast<View*>(data);
+            OptionSet<WebCore::ActivityState::Flag> flags;
+            if (state & wpe_view_activity_state_visible)
+                flags.add(WebCore::ActivityState::IsVisible);
+            if (state & wpe_view_activity_state_focused) {
+                flags.add(WebCore::ActivityState::IsFocused);
+                flags.add(WebCore::ActivityState::WindowIsActive);
+            }
+            if (state & wpe_view_activity_state_in_window)
+                flags.add(WebCore::ActivityState::IsInWindow);
+            view.setViewState(flags);
+        },
+#else
+        nullptr,
+#endif
+        // padding
+        nullptr,
+        nullptr,
+        nullptr
     };
     wpe_view_backend_set_backend_client(m_backend, &s_backendClient, this);
 
@@ -95,7 +122,7 @@ View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseC
             if (event->pressed
                 && event->modifiers & wpe_input_keyboard_modifier_control
                 && event->modifiers & wpe_input_keyboard_modifier_shift
-                && event->keyCode == 'G') {
+                && event->key_code == WPE_KEY_G) {
                 auto& preferences = view.page().preferences();
                 preferences.setResourceUsageOverlayVisible(!preferences.resourceUsageOverlayVisible());
                 return;
@@ -120,6 +147,11 @@ View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseC
             auto& page = reinterpret_cast<View*>(data)->page();
             page.handleTouchEvent(WebKit::NativeWebTouchEvent(event, page.deviceScaleFactor()));
         },
+        // padding
+        nullptr,
+        nullptr,
+        nullptr,
+        nullptr
     };
     wpe_view_backend_set_input_client(m_backend, &s_inputClient, this);
 
@@ -128,12 +160,6 @@ View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseC
     m_pageProxy->initializeWebPage();
 }
 
-View::~View()
-{
-    m_compositingManagerProxy.finalize();
-    wpe_view_backend_destroy(m_backend);
-}
-
 void View::setClient(std::unique_ptr<API::ViewClient>&& client)
 {
     if (!client)
@@ -152,24 +178,17 @@ void View::handleDownloadRequest(DownloadProxy& download)
     m_client->handleDownloadRequest(*this, download);
 }
 
-JSGlobalContextRef View::javascriptGlobalContext()
-{
-    return m_client->javascriptGlobalContext();
-}
-
 void View::setSize(const WebCore::IntSize& size)
 {
     m_size = size;
     if (m_pageProxy->drawingArea())
-        m_pageProxy->drawingArea()->setSize(size, WebCore::IntSize(), WebCore::IntSize());
+        m_pageProxy->drawingArea()->setSize(size);
 }
 
-void View::setViewState(WebCore::ActivityState::Flags flags)
+void View::setViewState(OptionSet<WebCore::ActivityState::Flag> flags)
 {
-    static const WebCore::ActivityState::Flags defaultFlags = WebCore::ActivityState::WindowIsActive | WebCore::ActivityState::IsFocused;
-
-    WebCore::ActivityState::Flags changedFlags = m_viewStateFlags ^ (defaultFlags | flags);
-    m_viewStateFlags = defaultFlags | flags;
+    auto changedFlags = m_viewStateFlags ^ flags;
+    m_viewStateFlags = flags;
 
     if (changedFlags)
         m_pageProxy->activityStateDidChange(changedFlags);