1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/*
* Copyright (C) 2017 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "WebKitWebViewBackend.h"
#include "WebKitWebViewBackendPrivate.h"
/**
* WebKitWebViewBackend:
* @See_also: #WebKitWebView.
*
* A web view backend.
*
* A WebKitWebViewBackend is a boxed type wrapping a WPE backend used to create a
* #WebKitWebView. A WebKitWebViewBackend is created with webkit_web_view_backend_new()
* and it should be passed to a WebKitWebView constructor that will take the ownership.
*
* Since: 2.20
*/
struct _WebKitWebViewBackend {
_WebKitWebViewBackend(struct wpe_view_backend* backend, GDestroyNotify notifyCallback, gpointer notifyCallbackData)
: backend(backend)
, notifyCallback(notifyCallback)
, notifyCallbackData(notifyCallbackData)
{
ASSERT(backend);
ASSERT(notifyCallback);
ASSERT(notifyCallbackData);
}
~_WebKitWebViewBackend()
{
notifyCallback(notifyCallbackData);
}
struct wpe_view_backend* backend;
GDestroyNotify notifyCallback;
gpointer notifyCallbackData;
int referenceCount { 1 };
};
static WebKitWebViewBackend* webkitWebViewBackendRef(WebKitWebViewBackend* viewBackend)
{
ASSERT(viewBackend);
g_atomic_int_inc(&viewBackend->referenceCount);
return viewBackend;
}
G_DEFINE_BOXED_TYPE(WebKitWebViewBackend, webkit_web_view_backend, webkitWebViewBackendRef, webkitWebViewBackendUnref)
void webkitWebViewBackendUnref(WebKitWebViewBackend* viewBackend)
{
ASSERT(viewBackend);
if (g_atomic_int_dec_and_test(&viewBackend->referenceCount)) {
viewBackend->~WebKitWebViewBackend();
fastFree(viewBackend);
}
}
/**
* webkit_web_view_backend_new:
* @backend: (transfer full): a #wpe_view_backend
* @notify: (nullable): a #GDestroyNotify, or %NULL
* @user_data: user data to pass to @notify
*
* Create a new #WebKitWebViewBackend for the given WPE @backend. You can pass a #GDestroyNotify
* that will be called when the object is destroyed passing @user_data as the argument. If @notify
* is %NULL, wpe_view_backend_destroy() will be used with @backend as argument.
* The returned #WebKitWebViewBackend should never be freed by the user; it must be passed to a
* #WebKitWebView constructor that will take the ownership.
*
* Returns: a newly created #WebKitWebViewBackend
*
* Since: 2.20
*/
WebKitWebViewBackend* webkit_web_view_backend_new(struct wpe_view_backend* backend, GDestroyNotify notify, gpointer userData)
{
g_return_val_if_fail(backend, nullptr);
auto* viewBackend = static_cast<WebKitWebViewBackend*>(fastMalloc(sizeof(WebKitWebViewBackend)));
new (viewBackend) WebKitWebViewBackend(backend, notify ? notify : reinterpret_cast<GDestroyNotify>(wpe_view_backend_destroy), notify ? userData : backend);
return viewBackend;
}
/**
* webkit_web_view_backend_get_wpe_backend:
* @view_backend: a #WebKitWebViewBackend
*
* Get the WPE backend of @view_backend
*
* Returns: (transfer none): the #wpe_view_backend
*
* Since: 2.20
*/
struct wpe_view_backend* webkit_web_view_backend_get_wpe_backend(WebKitWebViewBackend* viewBackend)
{
g_return_val_if_fail(viewBackend, nullptr);
return viewBackend->backend;
}
namespace WTF {
template <> WebKitWebViewBackend* refGPtr(WebKitWebViewBackend* ptr)
{
if (ptr)
webkitWebViewBackendRef(ptr);
return ptr;
}
template <> void derefGPtr(WebKitWebViewBackend* ptr)
{
if (ptr)
webkitWebViewBackendUnref(ptr);
}
}
|