| /* |
| * This file is part of the WebKit open source project. |
| * This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| * |
| * 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 "WebKitDOMUserMessageHandler.h" |
| |
| #include <WebCore/CSSImportRule.h> |
| #include "DOMObjectCache.h" |
| #include <WebCore/Document.h> |
| #include <WebCore/ExceptionCode.h> |
| #include <WebCore/ExceptionCodeDescription.h> |
| #include <WebCore/JSMainThreadExecState.h> |
| #include <WebCore/SerializedScriptValue.h> |
| #include "WebKitDOMPrivate.h" |
| #include "WebKitDOMUserMessageHandlerPrivate.h" |
| #include "ConvertToUTF8String.h" |
| #include <wtf/GetPtr.h> |
| #include <wtf/RefPtr.h> |
| |
| #define WEBKIT_DOM_USER_MESSAGE_HANDLER_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_USER_MESSAGE_HANDLER, WebKitDOMUserMessageHandlerPrivate) |
| |
| typedef struct _WebKitDOMUserMessageHandlerPrivate { |
| #if ENABLE(USER_MESSAGE_HANDLERS) |
| RefPtr<WebCore::UserMessageHandler> coreObject; |
| #endif // ENABLE(USER_MESSAGE_HANDLERS) |
| } WebKitDOMUserMessageHandlerPrivate; |
| |
| #if ENABLE(USER_MESSAGE_HANDLERS) |
| |
| namespace WebKit { |
| |
| WebKitDOMUserMessageHandler* kit(WebCore::UserMessageHandler* obj) |
| { |
| if (!obj) |
| return 0; |
| |
| if (gpointer ret = DOMObjectCache::get(obj)) |
| return WEBKIT_DOM_USER_MESSAGE_HANDLER(ret); |
| |
| return wrapUserMessageHandler(obj); |
| } |
| |
| WebCore::UserMessageHandler* core(WebKitDOMUserMessageHandler* request) |
| { |
| return request ? static_cast<WebCore::UserMessageHandler*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
| } |
| |
| WebKitDOMUserMessageHandler* wrapUserMessageHandler(WebCore::UserMessageHandler* coreObject) |
| { |
| ASSERT(coreObject); |
| return WEBKIT_DOM_USER_MESSAGE_HANDLER(g_object_new(WEBKIT_DOM_TYPE_USER_MESSAGE_HANDLER, "core-object", coreObject, nullptr)); |
| } |
| |
| } // namespace WebKit |
| |
| #endif // ENABLE(USER_MESSAGE_HANDLERS) |
| |
| G_DEFINE_TYPE(WebKitDOMUserMessageHandler, webkit_dom_user_message_handler, WEBKIT_DOM_TYPE_OBJECT) |
| |
| static void webkit_dom_user_message_handler_finalize(GObject* object) |
| { |
| WebKitDOMUserMessageHandlerPrivate* priv = WEBKIT_DOM_USER_MESSAGE_HANDLER_GET_PRIVATE(object); |
| #if ENABLE(USER_MESSAGE_HANDLERS) |
| WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
| #endif // ENABLE(USER_MESSAGE_HANDLERS) |
| priv->~WebKitDOMUserMessageHandlerPrivate(); |
| G_OBJECT_CLASS(webkit_dom_user_message_handler_parent_class)->finalize(object); |
| } |
| |
| static GObject* webkit_dom_user_message_handler_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties) |
| { |
| GObject* object = G_OBJECT_CLASS(webkit_dom_user_message_handler_parent_class)->constructor(type, constructPropertiesCount, constructProperties); |
| #if ENABLE(USER_MESSAGE_HANDLERS) |
| WebKitDOMUserMessageHandlerPrivate* priv = WEBKIT_DOM_USER_MESSAGE_HANDLER_GET_PRIVATE(object); |
| priv->coreObject = static_cast<WebCore::UserMessageHandler*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
| WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
| #endif // ENABLE(USER_MESSAGE_HANDLERS) |
| return object; |
| } |
| |
| static void webkit_dom_user_message_handler_class_init(WebKitDOMUserMessageHandlerClass* requestClass) |
| { |
| GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
| g_type_class_add_private(gobjectClass, sizeof(WebKitDOMUserMessageHandlerPrivate)); |
| gobjectClass->constructor = webkit_dom_user_message_handler_constructor; |
| gobjectClass->finalize = webkit_dom_user_message_handler_finalize; |
| } |
| |
| static void webkit_dom_user_message_handler_init(WebKitDOMUserMessageHandler* request) |
| { |
| WebKitDOMUserMessageHandlerPrivate* priv = WEBKIT_DOM_USER_MESSAGE_HANDLER_GET_PRIVATE(request); |
| new (priv) WebKitDOMUserMessageHandlerPrivate(); |
| } |
| |
| void webkit_dom_user_message_handler_post_message(WebKitDOMUserMessageHandler* self, const gchar* message, GError** error) |
| { |
| #if ENABLE(USER_MESSAGE_HANDLERS) |
| WebCore::JSMainThreadNullState state; |
| g_return_if_fail(WEBKIT_DOM_IS_USER_MESSAGE_HANDLER(self)); |
| g_return_if_fail(message); |
| g_return_if_fail(!error || !*error); |
| WebCore::UserMessageHandler* item = WebKit::core(self); |
| WebCore::ExceptionCode ec = 0; |
| item->postMessage(WebCore::SerializedScriptValue::create(WTF::String::fromUTF8(message)), ec); |
| if (ec) { |
| WebCore::ExceptionCodeDescription ecdesc(ec); |
| g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name); |
| } |
| #else |
| UNUSED_PARAM(self); |
| UNUSED_PARAM(message); |
| UNUSED_PARAM(error); |
| WEBKIT_WARN_FEATURE_NOT_PRESENT("User Message Handlers") |
| #endif /* ENABLE(USER_MESSAGE_HANDLERS) */ |
| } |
| |