1/*
2 * Copyright (C) 2015 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library 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 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "WebKitConsoleMessage.h"
22
23#include "WebKitConsoleMessagePrivate.h"
24
25G_DEFINE_BOXED_TYPE(WebKitConsoleMessage, webkit_console_message, webkit_console_message_copy, webkit_console_message_free)
26
27/**
28 * webkit_console_message_copy:
29 * @console_message: a #WebKitConsoleMessage
30 *
31 * Make a copy of @console_message.
32 *
33 * Returns: (transfer full): A copy of passed in #WebKitConsoleMessage
34 *
35 * Since: 2.12
36 */
37WebKitConsoleMessage* webkit_console_message_copy(WebKitConsoleMessage* consoleMessage)
38{
39 g_return_val_if_fail(consoleMessage, nullptr);
40 WebKitConsoleMessage* copy = static_cast<WebKitConsoleMessage*>(fastZeroedMalloc(sizeof(WebKitConsoleMessage)));
41 new (copy) WebKitConsoleMessage(consoleMessage);
42 return copy;
43}
44
45/**
46 * webkit_console_message_free:
47 * @console_message: a #WebKitConsoleMessage
48 *
49 * Free the #WebKitConsoleMessage
50 *
51 * Since: 2.12
52 */
53void webkit_console_message_free(WebKitConsoleMessage* consoleMessage)
54{
55 g_return_if_fail(consoleMessage);
56 consoleMessage->~WebKitConsoleMessage();
57 fastFree(consoleMessage);
58}
59
60/**
61 * webkit_console_message_get_source:
62 * @console_message: a #WebKitConsoleMessage
63 *
64 * Gets the source of a #WebKitConsoleMessage
65 *
66 * Returns: a #WebKitConsoleMessageSource indicating the source of @console_message
67 *
68 * Since: 2.12
69 */
70WebKitConsoleMessageSource webkit_console_message_get_source(WebKitConsoleMessage* consoleMessage)
71{
72 g_return_val_if_fail(consoleMessage, WEBKIT_CONSOLE_MESSAGE_SOURCE_OTHER);
73 switch (consoleMessage->source) {
74 case JSC::MessageSource::JS:
75 return WEBKIT_CONSOLE_MESSAGE_SOURCE_JAVASCRIPT;
76 case JSC::MessageSource::Network:
77 return WEBKIT_CONSOLE_MESSAGE_SOURCE_NETWORK;
78 case JSC::MessageSource::ConsoleAPI:
79 return WEBKIT_CONSOLE_MESSAGE_SOURCE_CONSOLE_API;
80 case JSC::MessageSource::Security:
81 return WEBKIT_CONSOLE_MESSAGE_SOURCE_SECURITY;
82 case JSC::MessageSource::Other:
83 default:
84 break;
85 }
86
87 return WEBKIT_CONSOLE_MESSAGE_SOURCE_OTHER;
88}
89
90/**
91 * webkit_console_message_get_level:
92 * @console_message: a #WebKitConsoleMessage
93 *
94 * Gets the log level of a #WebKitConsoleMessage
95 *
96 * Returns: a #WebKitConsoleMessageLevel indicating the log level of @console_message
97 *
98 * Since: 2.12
99 */
100WebKitConsoleMessageLevel webkit_console_message_get_level(WebKitConsoleMessage* consoleMessage)
101{
102 g_return_val_if_fail(consoleMessage, WEBKIT_CONSOLE_MESSAGE_LEVEL_LOG);
103 switch (consoleMessage->level) {
104 case JSC::MessageLevel::Log:
105 return WEBKIT_CONSOLE_MESSAGE_LEVEL_LOG;
106 case JSC::MessageLevel::Warning:
107 return WEBKIT_CONSOLE_MESSAGE_LEVEL_WARNING;
108 case JSC::MessageLevel::Error:
109 return WEBKIT_CONSOLE_MESSAGE_LEVEL_ERROR;
110 case JSC::MessageLevel::Debug:
111 return WEBKIT_CONSOLE_MESSAGE_LEVEL_DEBUG;
112 case JSC::MessageLevel::Info:
113 return WEBKIT_CONSOLE_MESSAGE_LEVEL_INFO;
114 }
115
116 ASSERT_NOT_REACHED();
117 return WEBKIT_CONSOLE_MESSAGE_LEVEL_LOG;
118}
119
120/**
121 * webkit_console_message_get_text:
122 * @console_message: a #WebKitConsoleMessage
123 *
124 * Gets the text message of a #WebKitConsoleMessage
125 *
126 * Returns: the text message of @console_message
127 *
128 * Since: 2.12
129 */
130const gchar* webkit_console_message_get_text(WebKitConsoleMessage* consoleMessage)
131{
132 g_return_val_if_fail(consoleMessage, nullptr);
133 return consoleMessage->message.data();
134}
135
136/**
137 * webkit_console_message_get_line:
138 * @console_message: a #WebKitConsoleMessage
139 *
140 * Gets the line number of a #WebKitConsoleMessage
141 *
142 * Returns: the line number of @console_message
143 *
144 * Since: 2.12
145 */
146guint webkit_console_message_get_line(WebKitConsoleMessage* consoleMessage)
147{
148 g_return_val_if_fail(consoleMessage, 0);
149 return consoleMessage->lineNumber;
150}
151
152/**
153 * webkit_console_message_get_source_id:
154 * @console_message: a #WebKitConsoleMessage
155 *
156 * Gets the source identifier of a #WebKitConsoleMessage
157 *
158 * Returns: the source identifier of @console_message
159 *
160 * Since: 2.12
161 */
162const gchar* webkit_console_message_get_source_id(WebKitConsoleMessage* consoleMessage)
163{
164 g_return_val_if_fail(consoleMessage, nullptr);
165 return consoleMessage->sourceID.data();
166}
167