| Differences between
and this patch
- a/Source/WebKit2/ChangeLog +57 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2015-07-22  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
2
3
        [EFL] Support indexeddb for WK2
4
        https://bugs.webkit.org/show_bug.cgi?id=145867
5
6
        Reviewed by Csaba Osztrogonác.
7
8
        Add stub implementation for indexeddb. Move KeyedDecoder and KeyedEncoder from gtk to glib
9
        in order to share it between GTK and EFL ports.
10
11
        * DatabaseProcess/EntryPoint/unix/DatabaseProcessMain.cpp:
12
        * DatabaseProcess/efl/DatabaseProcessMainEfl.cpp: Copied from Source/WebKit2/DatabaseProcess/EntryPoint/unix/DatabaseProcessMain.cpp.
13
        (WebKit::DatabaseProcessMainUnix):
14
        * PlatformEfl.cmake:
15
        * PlatformGTK.cmake:
16
        * Shared/glib/KeyedDecoder.cpp: Renamed from Source/WebKit2/Shared/gtk/KeyedDecoder.cpp.
17
        (WebKit::KeyedDecoder::KeyedDecoder):
18
        (WebKit::KeyedDecoder::~KeyedDecoder):
19
        (WebKit::KeyedDecoder::dictionaryFromGVariant):
20
        (WebKit::KeyedDecoder::decodeBytes):
21
        (WebKit::KeyedDecoder::decodeSimpleValue):
22
        (WebKit::KeyedDecoder::decodeBool):
23
        (WebKit::KeyedDecoder::decodeUInt32):
24
        (WebKit::KeyedDecoder::decodeInt32):
25
        (WebKit::KeyedDecoder::decodeInt64):
26
        (WebKit::KeyedDecoder::decodeFloat):
27
        (WebKit::KeyedDecoder::decodeDouble):
28
        (WebKit::KeyedDecoder::decodeString):
29
        (WebKit::KeyedDecoder::beginObject):
30
        (WebKit::KeyedDecoder::endObject):
31
        (WebKit::KeyedDecoder::beginArray):
32
        (WebKit::KeyedDecoder::beginArrayElement):
33
        (WebKit::KeyedDecoder::endArrayElement):
34
        (WebKit::KeyedDecoder::endArray):
35
        * Shared/glib/KeyedDecoder.h: Renamed from Source/WebKit2/Shared/gtk/KeyedDecoder.h.
36
        * Shared/glib/KeyedEncoder.cpp: Renamed from Source/WebKit2/Shared/gtk/KeyedEncoder.cpp.
37
        (WebKit::KeyedEncoder::KeyedEncoder):
38
        (WebKit::KeyedEncoder::~KeyedEncoder):
39
        (WebKit::KeyedEncoder::encodeBytes):
40
        (WebKit::KeyedEncoder::encodeBool):
41
        (WebKit::KeyedEncoder::encodeUInt32):
42
        (WebKit::KeyedEncoder::encodeInt32):
43
        (WebKit::KeyedEncoder::encodeInt64):
44
        (WebKit::KeyedEncoder::encodeFloat):
45
        (WebKit::KeyedEncoder::encodeDouble):
46
        (WebKit::KeyedEncoder::encodeString):
47
        (WebKit::KeyedEncoder::beginObject):
48
        (WebKit::KeyedEncoder::endObject):
49
        (WebKit::KeyedEncoder::beginArray):
50
        (WebKit::KeyedEncoder::beginArrayElement):
51
        (WebKit::KeyedEncoder::endArrayElement):
52
        (WebKit::KeyedEncoder::endArray):
53
        (WebKit::KeyedEncoder::finishEncoding):
54
        * Shared/glib/KeyedEncoder.h: Renamed from Source/WebKit2/Shared/gtk/KeyedEncoder.h.
55
        * UIProcess/Databases/efl/DatabaseProcessProxyEfl.cpp: Copied from Source/WebKit2/DatabaseProcess/EntryPoint/unix/DatabaseProcessMain.cpp.
56
        (WebKit::DatabaseProcessProxy::platformGetLaunchOptions):
57
1
2015-07-22  Carlos Garcia Campos  <cgarcia@igalia.com>
58
2015-07-22  Carlos Garcia Campos  <cgarcia@igalia.com>
2
59
3
        Unreviewed. Fix some warnings when generating GTK+ HTML API docs.
60
        Unreviewed. Fix some warnings when generating GTK+ HTML API docs.
- a/Source/WebKit2/DatabaseProcess/EntryPoint/unix/DatabaseProcessMain.cpp +1 lines
Lines 23-28 a/Source/WebKit2/DatabaseProcess/EntryPoint/unix/DatabaseProcessMain.cpp_sec1
23
 * THE POSSIBILITY OF SUCH DAMAGE.
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
24
 */
25
25
26
#include "config.h"
26
#include "DatabaseProcessMainUnix.h"
27
#include "DatabaseProcessMainUnix.h"
27
28
28
using namespace WebKit;
29
using namespace WebKit;
- a/Source/WebKit2/DatabaseProcess/efl/DatabaseProcessMainEfl.cpp +53 lines
Line 0 a/Source/WebKit2/DatabaseProcess/efl/DatabaseProcessMainEfl.cpp_sec1
1
/*
2
 * Copyright (C) 2015 Naver Corp. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "DatabaseProcess.h"
28
29
#if ENABLE(DATABASE_PROCESS)
30
31
#include "ChildProcessMain.h"
32
#include "DatabaseProcessMainUnix.h"
33
34
using namespace WebCore;
35
36
namespace WebKit {
37
38
class DatabaseProcessMain final: public ChildProcessMainBase {
39
public:
40
    bool platformInitialize() override
41
    {
42
        return true;
43
    }
44
};
45
46
int DatabaseProcessMainUnix(int argc, char** argv)
47
{
48
    return ChildProcessMain<DatabaseProcess, DatabaseProcessMain>(argc, argv);
49
}
50
51
} // namespace WebKit
52
53
#endif // ENABLE(DATABASE_PROCESS)
- a/Source/WebKit2/PlatformEfl.cmake +14 lines
Lines 1-4 a/Source/WebKit2/PlatformEfl.cmake_sec1
1
list(APPEND WebKit2_SOURCES
1
list(APPEND WebKit2_SOURCES
2
    DatabaseProcess/efl/DatabaseProcessMainEfl.cpp
3
2
    NetworkProcess/efl/NetworkProcessMainEfl.cpp
4
    NetworkProcess/efl/NetworkProcessMainEfl.cpp
3
5
4
    NetworkProcess/soup/NetworkProcessSoup.cpp
6
    NetworkProcess/soup/NetworkProcessSoup.cpp
Lines 45-50 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformEfl.cmake_sec2
45
    Shared/efl/ProcessExecutablePathEfl.cpp
47
    Shared/efl/ProcessExecutablePathEfl.cpp
46
    Shared/efl/WebEventFactory.cpp
48
    Shared/efl/WebEventFactory.cpp
47
49
50
    Shared/glib/KeyedDecoder.cpp
51
    Shared/glib/KeyedEncoder.cpp
52
48
    Shared/linux/WebMemorySamplerLinux.cpp
53
    Shared/linux/WebMemorySamplerLinux.cpp
49
54
50
    Shared/linux/SeccompFilters/OpenSyscall.cpp
55
    Shared/linux/SeccompFilters/OpenSyscall.cpp
Lines 123-128 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformEfl.cmake_sec3
123
    UIProcess/CoordinatedGraphics/WebView.cpp
128
    UIProcess/CoordinatedGraphics/WebView.cpp
124
    UIProcess/CoordinatedGraphics/WebViewClient.cpp
129
    UIProcess/CoordinatedGraphics/WebViewClient.cpp
125
130
131
    UIProcess/Databases/efl/DatabaseProcessProxyEfl.cpp
132
126
    UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp
133
    UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp
127
134
128
    UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp
135
    UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp
Lines 230-235 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformEfl.cmake_sec4
230
    "${WEBCORE_DIR}/platform/graphics/x11"
237
    "${WEBCORE_DIR}/platform/graphics/x11"
231
    "${WEBCORE_DIR}/platform/network/soup"
238
    "${WEBCORE_DIR}/platform/network/soup"
232
    "${WEBCORE_DIR}/platform/text/enchant"
239
    "${WEBCORE_DIR}/platform/text/enchant"
240
    "${WEBKIT2_DIR}/DatabaseProcess/unix"
233
    "${WEBKIT2_DIR}/NetworkProcess/efl"
241
    "${WEBKIT2_DIR}/NetworkProcess/efl"
234
    "${WEBKIT2_DIR}/NetworkProcess/unix"
242
    "${WEBKIT2_DIR}/NetworkProcess/unix"
235
    "${WEBKIT2_DIR}/Platform/efl"
243
    "${WEBKIT2_DIR}/Platform/efl"
Lines 260-265 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformEfl.cmake_sec5
260
    "${WEBKIT2_DIR}/WebProcess/WebPage/CoordinatedGraphics"
268
    "${WEBKIT2_DIR}/WebProcess/WebPage/CoordinatedGraphics"
261
    "${WTF_DIR}/wtf/efl"
269
    "${WTF_DIR}/wtf/efl"
262
    "${WTF_DIR}/wtf/glib"
270
    "${WTF_DIR}/wtf/glib"
271
    "${WTF_DIR}"
272
    "${WEBKIT2_DIR}"
263
)
273
)
264
274
265
list(APPEND WebKit2_SYSTEM_INCLUDE_DIRECTORIES
275
list(APPEND WebKit2_SYSTEM_INCLUDE_DIRECTORIES
Lines 316-321 list(APPEND NetworkProcess_SOURCES a/Source/WebKit2/PlatformEfl.cmake_sec6
316
    NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
326
    NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
317
)
327
)
318
328
329
list(APPEND DatabaseProcess_SOURCES
330
    DatabaseProcess/EntryPoint/unix/DatabaseProcessMain.cpp
331
)
332
319
list(APPEND WebProcess_LIBRARIES
333
list(APPEND WebProcess_LIBRARIES
320
    ${CAIRO_LIBRARIES}
334
    ${CAIRO_LIBRARIES}
321
    ${ECORE_IMF_EVAS_LIBRARIES}
335
    ${ECORE_IMF_EVAS_LIBRARIES}
- a/Source/WebKit2/PlatformGTK.cmake -2 / +3 lines
Lines 62-70 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformGTK.cmake_sec1
62
62
63
    Shared/cairo/ShareableBitmapCairo.cpp
63
    Shared/cairo/ShareableBitmapCairo.cpp
64
64
65
    Shared/glib/KeyedDecoder.cpp
66
    Shared/glib/KeyedEncoder.cpp
65
    Shared/gtk/ArgumentCodersGtk.cpp
67
    Shared/gtk/ArgumentCodersGtk.cpp
66
    Shared/gtk/KeyedDecoder.cpp
67
    Shared/gtk/KeyedEncoder.cpp
68
    Shared/gtk/NativeContextMenuItemGtk.cpp
68
    Shared/gtk/NativeContextMenuItemGtk.cpp
69
    Shared/gtk/NativeWebKeyboardEventGtk.cpp
69
    Shared/gtk/NativeWebKeyboardEventGtk.cpp
70
    Shared/gtk/NativeWebMouseEventGtk.cpp
70
    Shared/gtk/NativeWebMouseEventGtk.cpp
Lines 482-487 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformGTK.cmake_sec2
482
    "${WEBKIT2_DIR}/Shared/Network/CustomProtocols/soup"
482
    "${WEBKIT2_DIR}/Shared/Network/CustomProtocols/soup"
483
    "${WEBKIT2_DIR}/Shared/Downloads/soup"
483
    "${WEBKIT2_DIR}/Shared/Downloads/soup"
484
    "${WEBKIT2_DIR}/Shared/Plugins/unix"
484
    "${WEBKIT2_DIR}/Shared/Plugins/unix"
485
    "${WEBKIT2_DIR}/Shared/glib"
485
    "${WEBKIT2_DIR}/Shared/gtk"
486
    "${WEBKIT2_DIR}/Shared/gtk"
486
    "${WEBKIT2_DIR}/Shared/linux"
487
    "${WEBKIT2_DIR}/Shared/linux"
487
    "${WEBKIT2_DIR}/Shared/linux/SeccompFilters"
488
    "${WEBKIT2_DIR}/Shared/linux/SeccompFilters"
- a/Source/WebKit2/Shared/glib/KeyedDecoder.cpp +168 lines
Line 0 a/Source/WebKit2/Shared/glib/KeyedDecoder.cpp_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "KeyedDecoder.h"
28
29
#include <wtf/text/CString.h>
30
31
namespace WebKit {
32
33
KeyedDecoder::KeyedDecoder(const uint8_t* data, size_t size)
34
{
35
    GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new(data, size));
36
    GRefPtr<GVariant> variant = g_variant_new_from_bytes(G_VARIANT_TYPE("a{sv}"), bytes.get(), TRUE);
37
    m_dictionaryStack.append(dictionaryFromGVariant(variant.get()));
38
}
39
40
KeyedDecoder::~KeyedDecoder()
41
{
42
    ASSERT(m_dictionaryStack.size() == 1);
43
    ASSERT(m_arrayStack.isEmpty());
44
    ASSERT(m_arrayIndexStack.isEmpty());
45
}
46
47
HashMap<String, GRefPtr<GVariant>> KeyedDecoder::dictionaryFromGVariant(GVariant* variant)
48
{
49
    HashMap<String, GRefPtr<GVariant>> dictionary;
50
    GVariantIter iter;
51
    g_variant_iter_init(&iter, variant);
52
    const char* key;
53
    GVariant* value;
54
    while (g_variant_iter_loop(&iter, "{&sv}", &key, &value))
55
        dictionary.set(String::fromUTF8(key), value);
56
    return WTF::move(dictionary);
57
}
58
59
bool KeyedDecoder::decodeBytes(const String& key, const uint8_t*& bytes, size_t& size)
60
{
61
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
62
    if (!value)
63
        return false;
64
65
    size = g_variant_get_size(value.get());
66
    bytes = static_cast<const uint8_t*>(g_variant_get_data(value.get()));
67
    return true;
68
}
69
70
template<typename T, typename F>
71
bool KeyedDecoder::decodeSimpleValue(const String& key, T& result, F getFunction)
72
{
73
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
74
    if (!value)
75
        return false;
76
77
    result = getFunction(value.get());
78
    return true;
79
}
80
81
bool KeyedDecoder::decodeBool(const String& key, bool& result)
82
{
83
    return decodeSimpleValue(key, result, g_variant_get_boolean);
84
}
85
86
bool KeyedDecoder::decodeUInt32(const String& key, uint32_t& result)
87
{
88
    return decodeSimpleValue(key, result, g_variant_get_uint32);
89
}
90
91
bool KeyedDecoder::decodeInt32(const String& key, int32_t& result)
92
{
93
    return decodeSimpleValue(key, result, g_variant_get_int32);
94
}
95
96
bool KeyedDecoder::decodeInt64(const String& key, int64_t& result)
97
{
98
    return decodeSimpleValue(key, result, g_variant_get_int64);
99
}
100
101
bool KeyedDecoder::decodeFloat(const String& key, float& result)
102
{
103
    return decodeSimpleValue(key, result, g_variant_get_double);
104
}
105
106
bool KeyedDecoder::decodeDouble(const String& key, double& result)
107
{
108
    return decodeSimpleValue(key, result, g_variant_get_double);
109
}
110
111
bool KeyedDecoder::decodeString(const String& key, String& result)
112
{
113
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
114
    if (!value)
115
        return false;
116
117
    result = String::fromUTF8(g_variant_get_string(value.get(), nullptr));
118
    return true;
119
}
120
121
bool KeyedDecoder::beginObject(const String& key)
122
{
123
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
124
    if (!value)
125
        return false;
126
127
    m_dictionaryStack.append(dictionaryFromGVariant(value.get()));
128
    return true;
129
}
130
131
void KeyedDecoder::endObject()
132
{
133
    m_dictionaryStack.removeLast();
134
}
135
136
bool KeyedDecoder::beginArray(const String& key)
137
{
138
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
139
    if (!value)
140
        return false;
141
142
    m_arrayStack.append(value.get());
143
    m_arrayIndexStack.append(0);
144
    return true;
145
}
146
147
bool KeyedDecoder::beginArrayElement()
148
{
149
    if (m_arrayIndexStack.last() >= g_variant_n_children(m_arrayStack.last()))
150
        return false;
151
152
    GRefPtr<GVariant> variant = adoptGRef(g_variant_get_child_value(m_arrayStack.last(), m_arrayIndexStack.last()++));
153
    m_dictionaryStack.append(dictionaryFromGVariant(variant.get()));
154
    return true;
155
}
156
157
void KeyedDecoder::endArrayElement()
158
{
159
    m_dictionaryStack.removeLast();
160
}
161
162
void KeyedDecoder::endArray()
163
{
164
    m_arrayStack.removeLast();
165
    m_arrayIndexStack.removeLast();
166
}
167
168
} // namespace WebKit
- a/Source/WebKit2/Shared/glib/KeyedDecoder.h +71 lines
Line 0 a/Source/WebKit2/Shared/glib/KeyedDecoder.h_sec1
1
/*
2
 * Copyright (C) 2015 Igaia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef KeyedDecoder_h
27
#define KeyedDecoder_h
28
29
#include <WebCore/KeyedCoding.h>
30
#include <glib.h>
31
#include <wtf/HashMap.h>
32
#include <wtf/glib/GRefPtr.h>
33
#include <wtf/text/StringHash.h>
34
#include <wtf/text/WTFString.h>
35
36
namespace WebKit {
37
38
class KeyedDecoder final : public WebCore::KeyedDecoder {
39
public:
40
    KeyedDecoder(const uint8_t* data, size_t);
41
    virtual ~KeyedDecoder() override;
42
43
private:
44
    virtual bool decodeBytes(const String& key, const uint8_t*&, size_t&) override;
45
    virtual bool decodeBool(const String& key, bool&) override;
46
    virtual bool decodeUInt32(const String& key, uint32_t&) override;
47
    virtual bool decodeInt32(const String& key, int32_t&) override;
48
    virtual bool decodeInt64(const String& key, int64_t&) override;
49
    virtual bool decodeFloat(const String& key, float&) override;
50
    virtual bool decodeDouble(const String& key, double&) override;
51
    virtual bool decodeString(const String& key, String&) override;
52
53
    virtual bool beginObject(const String& key) override;
54
    virtual void endObject() override;
55
56
    virtual bool beginArray(const String& key) override;
57
    virtual bool beginArrayElement() override;
58
    virtual void endArrayElement() override;
59
    virtual void endArray() override;
60
61
    template<typename T, typename F> bool decodeSimpleValue(const String& key, T& result, F getFunction);
62
    HashMap<String, GRefPtr<GVariant>> dictionaryFromGVariant(GVariant*);
63
64
    Vector<HashMap<String, GRefPtr<GVariant>>> m_dictionaryStack;
65
    Vector<GVariant*, 16> m_arrayStack;
66
    Vector<unsigned> m_arrayIndexStack;
67
};
68
69
} // namespace WebKit
70
71
#endif // KeyedDecoder_h
- a/Source/WebKit2/Shared/glib/KeyedEncoder.cpp +135 lines
Line 0 a/Source/WebKit2/Shared/glib/KeyedEncoder.cpp_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "KeyedEncoder.h"
28
29
#include <WebCore/SharedBuffer.h>
30
#include <wtf/text/CString.h>
31
32
using namespace WebCore;
33
34
namespace WebKit {
35
36
KeyedEncoder::KeyedEncoder()
37
{
38
    g_variant_builder_init(&m_variantBuilder, G_VARIANT_TYPE("a{sv}"));
39
    m_variantBuilderStack.append(&m_variantBuilder);
40
}
41
42
KeyedEncoder::~KeyedEncoder()
43
{
44
    ASSERT(m_variantBuilderStack.size() == 1);
45
    ASSERT(m_variantBuilderStack.last() == &m_variantBuilder);
46
    ASSERT(m_arrayStack.isEmpty());
47
    ASSERT(m_objectStack.isEmpty());
48
}
49
50
void KeyedEncoder::encodeBytes(const String& key, const uint8_t* bytes, size_t size)
51
{
52
    GRefPtr<GBytes> gBytes = adoptGRef(g_bytes_new_static(bytes, size));
53
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_from_bytes(G_VARIANT_TYPE("ay"), gBytes.get(), TRUE));
54
}
55
56
void KeyedEncoder::encodeBool(const String& key, bool value)
57
{
58
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_boolean(value));
59
}
60
61
void KeyedEncoder::encodeUInt32(const String& key, uint32_t value)
62
{
63
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_uint32(value));
64
}
65
66
void KeyedEncoder::encodeInt32(const String& key, int32_t value)
67
{
68
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_int32(value));
69
}
70
71
void KeyedEncoder::encodeInt64(const String& key, int64_t value)
72
{
73
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_int64(value));
74
}
75
76
void KeyedEncoder::encodeFloat(const String& key, float value)
77
{
78
    encodeDouble(key, value);
79
}
80
81
void KeyedEncoder::encodeDouble(const String& key, double value)
82
{
83
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_double(value));
84
}
85
86
void KeyedEncoder::encodeString(const String& key, const String& value)
87
{
88
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_string(value.utf8().data()));
89
}
90
91
void KeyedEncoder::beginObject(const String& key)
92
{
93
    GRefPtr<GVariantBuilder> builder = adoptGRef(g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")));
94
    m_objectStack.append(std::make_pair(key, builder));
95
    m_variantBuilderStack.append(builder.get());
96
}
97
98
void KeyedEncoder::endObject()
99
{
100
    GVariantBuilder* builder = m_variantBuilderStack.takeLast();
101
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", m_objectStack.last().first.utf8().data(), g_variant_builder_end(builder));
102
    m_objectStack.removeLast();
103
}
104
105
void KeyedEncoder::beginArray(const String& key)
106
{
107
    m_arrayStack.append(std::make_pair(key, adoptGRef(g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")))));
108
}
109
110
void KeyedEncoder::beginArrayElement()
111
{
112
    m_variantBuilderStack.append(g_variant_builder_new(G_VARIANT_TYPE("a{sv}")));
113
}
114
115
void KeyedEncoder::endArrayElement()
116
{
117
    GRefPtr<GVariantBuilder> variantBuilder = adoptGRef(m_variantBuilderStack.takeLast());
118
    g_variant_builder_add_value(m_arrayStack.last().second.get(), g_variant_builder_end(variantBuilder.get()));
119
}
120
121
void KeyedEncoder::endArray()
122
{
123
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", m_arrayStack.last().first.utf8().data(), g_variant_builder_end(m_arrayStack.last().second.get()));
124
    m_arrayStack.removeLast();
125
}
126
127
PassRefPtr<SharedBuffer> KeyedEncoder::finishEncoding()
128
{
129
    g_assert(m_variantBuilderStack.last() == &m_variantBuilder);
130
    GRefPtr<GVariant> variant = g_variant_builder_end(&m_variantBuilder);
131
    GRefPtr<GBytes> data = g_variant_get_data_as_bytes(variant.get());
132
    return SharedBuffer::create(static_cast<const unsigned char*>(g_bytes_get_data(data.get(), nullptr)), static_cast<unsigned>(g_bytes_get_size(data.get())));
133
}
134
135
} // namespace WebKit
- a/Source/WebKit2/Shared/glib/KeyedEncoder.h +70 lines
Line 0 a/Source/WebKit2/Shared/glib/KeyedEncoder.h_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef KeyedEncoder_h
27
#define KeyedEncoder_h
28
29
#include <WebCore/KeyedCoding.h>
30
#include <glib.h>
31
#include <wtf/Vector.h>
32
#include <wtf/glib/GRefPtr.h>
33
#include <wtf/text/WTFString.h>
34
35
namespace WebKit {
36
37
class KeyedEncoder final : public WebCore::KeyedEncoder {
38
public:
39
    KeyedEncoder();
40
    ~KeyedEncoder();
41
42
    virtual PassRefPtr<WebCore::SharedBuffer> finishEncoding() override;
43
44
private:
45
    virtual void encodeBytes(const String& key, const uint8_t*, size_t) override;
46
    virtual void encodeBool(const String& key, bool) override;
47
    virtual void encodeUInt32(const String& key, uint32_t) override;
48
    virtual void encodeInt32(const String& key, int32_t) override;
49
    virtual void encodeInt64(const String& key, int64_t) override;
50
    virtual void encodeFloat(const String& key, float) override;
51
    virtual void encodeDouble(const String& key, double) override;
52
    virtual void encodeString(const String& key, const String&) override;
53
54
    virtual void beginObject(const String& key) override;
55
    virtual void endObject() override;
56
57
    virtual void beginArray(const String& key) override;
58
    virtual void beginArrayElement() override;
59
    virtual void endArrayElement() override;
60
    virtual void endArray() override;
61
62
    GVariantBuilder m_variantBuilder;
63
    Vector<GVariantBuilder*, 16> m_variantBuilderStack;
64
    Vector<std::pair<String, GRefPtr<GVariantBuilder>>, 16> m_arrayStack;
65
    Vector<std::pair<String, GRefPtr<GVariantBuilder>>, 16> m_objectStack;
66
};
67
68
} // namespace WebKit
69
70
#endif // KeyedEncoder_h
- a/Source/WebKit2/Shared/gtk/KeyedDecoder.cpp -168 lines
Lines 1-168 a/Source/WebKit2/Shared/gtk/KeyedDecoder.cpp_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "KeyedDecoder.h"
28
29
#include <wtf/text/CString.h>
30
31
namespace WebKit {
32
33
KeyedDecoder::KeyedDecoder(const uint8_t* data, size_t size)
34
{
35
    GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new(data, size));
36
    GRefPtr<GVariant> variant = g_variant_new_from_bytes(G_VARIANT_TYPE("a{sv}"), bytes.get(), TRUE);
37
    m_dictionaryStack.append(dictionaryFromGVariant(variant.get()));
38
}
39
40
KeyedDecoder::~KeyedDecoder()
41
{
42
    ASSERT(m_dictionaryStack.size() == 1);
43
    ASSERT(m_arrayStack.isEmpty());
44
    ASSERT(m_arrayIndexStack.isEmpty());
45
}
46
47
HashMap<String, GRefPtr<GVariant>> KeyedDecoder::dictionaryFromGVariant(GVariant* variant)
48
{
49
    HashMap<String, GRefPtr<GVariant>> dictionary;
50
    GVariantIter iter;
51
    g_variant_iter_init(&iter, variant);
52
    const char* key;
53
    GVariant* value;
54
    while (g_variant_iter_loop(&iter, "{&sv}", &key, &value))
55
        dictionary.set(String::fromUTF8(key), value);
56
    return WTF::move(dictionary);
57
}
58
59
bool KeyedDecoder::decodeBytes(const String& key, const uint8_t*& bytes, size_t& size)
60
{
61
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
62
    if (!value)
63
        return false;
64
65
    size = g_variant_get_size(value.get());
66
    bytes = static_cast<const uint8_t*>(g_variant_get_data(value.get()));
67
    return true;
68
}
69
70
template<typename T, typename F>
71
bool KeyedDecoder::decodeSimpleValue(const String& key, T& result, F getFunction)
72
{
73
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
74
    if (!value)
75
        return false;
76
77
    result = getFunction(value.get());
78
    return true;
79
}
80
81
bool KeyedDecoder::decodeBool(const String& key, bool& result)
82
{
83
    return decodeSimpleValue(key, result, g_variant_get_boolean);
84
}
85
86
bool KeyedDecoder::decodeUInt32(const String& key, uint32_t& result)
87
{
88
    return decodeSimpleValue(key, result, g_variant_get_uint32);
89
}
90
91
bool KeyedDecoder::decodeInt32(const String& key, int32_t& result)
92
{
93
    return decodeSimpleValue(key, result, g_variant_get_int32);
94
}
95
96
bool KeyedDecoder::decodeInt64(const String& key, int64_t& result)
97
{
98
    return decodeSimpleValue(key, result, g_variant_get_int64);
99
}
100
101
bool KeyedDecoder::decodeFloat(const String& key, float& result)
102
{
103
    return decodeSimpleValue(key, result, g_variant_get_double);
104
}
105
106
bool KeyedDecoder::decodeDouble(const String& key, double& result)
107
{
108
    return decodeSimpleValue(key, result, g_variant_get_double);
109
}
110
111
bool KeyedDecoder::decodeString(const String& key, String& result)
112
{
113
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
114
    if (!value)
115
        return false;
116
117
    result = String::fromUTF8(g_variant_get_string(value.get(), nullptr));
118
    return true;
119
}
120
121
bool KeyedDecoder::beginObject(const String& key)
122
{
123
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
124
    if (!value)
125
        return false;
126
127
    m_dictionaryStack.append(dictionaryFromGVariant(value.get()));
128
    return true;
129
}
130
131
void KeyedDecoder::endObject()
132
{
133
    m_dictionaryStack.removeLast();
134
}
135
136
bool KeyedDecoder::beginArray(const String& key)
137
{
138
    GRefPtr<GVariant> value = m_dictionaryStack.last().get(key);
139
    if (!value)
140
        return false;
141
142
    m_arrayStack.append(value.get());
143
    m_arrayIndexStack.append(0);
144
    return true;
145
}
146
147
bool KeyedDecoder::beginArrayElement()
148
{
149
    if (m_arrayIndexStack.last() >= g_variant_n_children(m_arrayStack.last()))
150
        return false;
151
152
    GRefPtr<GVariant> variant = adoptGRef(g_variant_get_child_value(m_arrayStack.last(), m_arrayIndexStack.last()++));
153
    m_dictionaryStack.append(dictionaryFromGVariant(variant.get()));
154
    return true;
155
}
156
157
void KeyedDecoder::endArrayElement()
158
{
159
    m_dictionaryStack.removeLast();
160
}
161
162
void KeyedDecoder::endArray()
163
{
164
    m_arrayStack.removeLast();
165
    m_arrayIndexStack.removeLast();
166
}
167
168
} // namespace WebKit
- a/Source/WebKit2/Shared/gtk/KeyedDecoder.h -71 lines
Lines 1-71 a/Source/WebKit2/Shared/gtk/KeyedDecoder.h_sec1
1
/*
2
 * Copyright (C) 2015 Igaia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef KeyedDecoder_h
27
#define KeyedDecoder_h
28
29
#include <WebCore/KeyedCoding.h>
30
#include <glib.h>
31
#include <wtf/HashMap.h>
32
#include <wtf/glib/GRefPtr.h>
33
#include <wtf/text/StringHash.h>
34
#include <wtf/text/WTFString.h>
35
36
namespace WebKit {
37
38
class KeyedDecoder final : public WebCore::KeyedDecoder {
39
public:
40
    KeyedDecoder(const uint8_t* data, size_t);
41
    virtual ~KeyedDecoder() override;
42
43
private:
44
    virtual bool decodeBytes(const String& key, const uint8_t*&, size_t&) override;
45
    virtual bool decodeBool(const String& key, bool&) override;
46
    virtual bool decodeUInt32(const String& key, uint32_t&) override;
47
    virtual bool decodeInt32(const String& key, int32_t&) override;
48
    virtual bool decodeInt64(const String& key, int64_t&) override;
49
    virtual bool decodeFloat(const String& key, float&) override;
50
    virtual bool decodeDouble(const String& key, double&) override;
51
    virtual bool decodeString(const String& key, String&) override;
52
53
    virtual bool beginObject(const String& key) override;
54
    virtual void endObject() override;
55
56
    virtual bool beginArray(const String& key) override;
57
    virtual bool beginArrayElement() override;
58
    virtual void endArrayElement() override;
59
    virtual void endArray() override;
60
61
    template<typename T, typename F> bool decodeSimpleValue(const String& key, T& result, F getFunction);
62
    HashMap<String, GRefPtr<GVariant>> dictionaryFromGVariant(GVariant*);
63
64
    Vector<HashMap<String, GRefPtr<GVariant>>> m_dictionaryStack;
65
    Vector<GVariant*, 16> m_arrayStack;
66
    Vector<unsigned> m_arrayIndexStack;
67
};
68
69
} // namespace WebKit
70
71
#endif // KeyedDecoder_h
- a/Source/WebKit2/Shared/gtk/KeyedEncoder.cpp -135 lines
Lines 1-135 a/Source/WebKit2/Shared/gtk/KeyedEncoder.cpp_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "KeyedEncoder.h"
28
29
#include <WebCore/SharedBuffer.h>
30
#include <wtf/text/CString.h>
31
32
using namespace WebCore;
33
34
namespace WebKit {
35
36
KeyedEncoder::KeyedEncoder()
37
{
38
    g_variant_builder_init(&m_variantBuilder, G_VARIANT_TYPE("a{sv}"));
39
    m_variantBuilderStack.append(&m_variantBuilder);
40
}
41
42
KeyedEncoder::~KeyedEncoder()
43
{
44
    ASSERT(m_variantBuilderStack.size() == 1);
45
    ASSERT(m_variantBuilderStack.last() == &m_variantBuilder);
46
    ASSERT(m_arrayStack.isEmpty());
47
    ASSERT(m_objectStack.isEmpty());
48
}
49
50
void KeyedEncoder::encodeBytes(const String& key, const uint8_t* bytes, size_t size)
51
{
52
    GRefPtr<GBytes> gBytes = adoptGRef(g_bytes_new_static(bytes, size));
53
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_from_bytes(G_VARIANT_TYPE("ay"), gBytes.get(), TRUE));
54
}
55
56
void KeyedEncoder::encodeBool(const String& key, bool value)
57
{
58
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_boolean(value));
59
}
60
61
void KeyedEncoder::encodeUInt32(const String& key, uint32_t value)
62
{
63
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_uint32(value));
64
}
65
66
void KeyedEncoder::encodeInt32(const String& key, int32_t value)
67
{
68
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_int32(value));
69
}
70
71
void KeyedEncoder::encodeInt64(const String& key, int64_t value)
72
{
73
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_int64(value));
74
}
75
76
void KeyedEncoder::encodeFloat(const String& key, float value)
77
{
78
    encodeDouble(key, value);
79
}
80
81
void KeyedEncoder::encodeDouble(const String& key, double value)
82
{
83
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_double(value));
84
}
85
86
void KeyedEncoder::encodeString(const String& key, const String& value)
87
{
88
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", key.utf8().data(), g_variant_new_string(value.utf8().data()));
89
}
90
91
void KeyedEncoder::beginObject(const String& key)
92
{
93
    GRefPtr<GVariantBuilder> builder = adoptGRef(g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")));
94
    m_objectStack.append(std::make_pair(key, builder));
95
    m_variantBuilderStack.append(builder.get());
96
}
97
98
void KeyedEncoder::endObject()
99
{
100
    GVariantBuilder* builder = m_variantBuilderStack.takeLast();
101
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", m_objectStack.last().first.utf8().data(), g_variant_builder_end(builder));
102
    m_objectStack.removeLast();
103
}
104
105
void KeyedEncoder::beginArray(const String& key)
106
{
107
    m_arrayStack.append(std::make_pair(key, adoptGRef(g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")))));
108
}
109
110
void KeyedEncoder::beginArrayElement()
111
{
112
    m_variantBuilderStack.append(g_variant_builder_new(G_VARIANT_TYPE("a{sv}")));
113
}
114
115
void KeyedEncoder::endArrayElement()
116
{
117
    GRefPtr<GVariantBuilder> variantBuilder = adoptGRef(m_variantBuilderStack.takeLast());
118
    g_variant_builder_add_value(m_arrayStack.last().second.get(), g_variant_builder_end(variantBuilder.get()));
119
}
120
121
void KeyedEncoder::endArray()
122
{
123
    g_variant_builder_add(m_variantBuilderStack.last(), "{sv}", m_arrayStack.last().first.utf8().data(), g_variant_builder_end(m_arrayStack.last().second.get()));
124
    m_arrayStack.removeLast();
125
}
126
127
PassRefPtr<SharedBuffer> KeyedEncoder::finishEncoding()
128
{
129
    g_assert(m_variantBuilderStack.last() == &m_variantBuilder);
130
    GRefPtr<GVariant> variant = g_variant_builder_end(&m_variantBuilder);
131
    GRefPtr<GBytes> data = g_variant_get_data_as_bytes(variant.get());
132
    return SharedBuffer::create(static_cast<const unsigned char*>(g_bytes_get_data(data.get(), nullptr)), static_cast<unsigned>(g_bytes_get_size(data.get())));
133
}
134
135
} // namespace WebKit
- a/Source/WebKit2/Shared/gtk/KeyedEncoder.h -70 lines
Lines 1-70 a/Source/WebKit2/Shared/gtk/KeyedEncoder.h_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef KeyedEncoder_h
27
#define KeyedEncoder_h
28
29
#include <WebCore/KeyedCoding.h>
30
#include <glib.h>
31
#include <wtf/Vector.h>
32
#include <wtf/glib/GRefPtr.h>
33
#include <wtf/text/WTFString.h>
34
35
namespace WebKit {
36
37
class KeyedEncoder final : public WebCore::KeyedEncoder {
38
public:
39
    KeyedEncoder();
40
    ~KeyedEncoder();
41
42
    virtual PassRefPtr<WebCore::SharedBuffer> finishEncoding() override;
43
44
private:
45
    virtual void encodeBytes(const String& key, const uint8_t*, size_t) override;
46
    virtual void encodeBool(const String& key, bool) override;
47
    virtual void encodeUInt32(const String& key, uint32_t) override;
48
    virtual void encodeInt32(const String& key, int32_t) override;
49
    virtual void encodeInt64(const String& key, int64_t) override;
50
    virtual void encodeFloat(const String& key, float) override;
51
    virtual void encodeDouble(const String& key, double) override;
52
    virtual void encodeString(const String& key, const String&) override;
53
54
    virtual void beginObject(const String& key) override;
55
    virtual void endObject() override;
56
57
    virtual void beginArray(const String& key) override;
58
    virtual void beginArrayElement() override;
59
    virtual void endArrayElement() override;
60
    virtual void endArray() override;
61
62
    GVariantBuilder m_variantBuilder;
63
    Vector<GVariantBuilder*, 16> m_variantBuilderStack;
64
    Vector<std::pair<String, GRefPtr<GVariantBuilder>>, 16> m_arrayStack;
65
    Vector<std::pair<String, GRefPtr<GVariantBuilder>>, 16> m_objectStack;
66
};
67
68
} // namespace WebKit
69
70
#endif // KeyedEncoder_h
- a/Source/WebKit2/UIProcess/Databases/efl/DatabaseProcessProxyEfl.cpp +39 lines
Line 0 a/Source/WebKit2/UIProcess/Databases/efl/DatabaseProcessProxyEfl.cpp_sec1
1
/*
2
 * Copyright (C) 2015 Naver Corp. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "DatabaseProcessProxy.h"
28
29
#if ENABLE(DATABASE_PROCESS)
30
31
namespace WebKit {
32
33
void DatabaseProcessProxy::platformGetLaunchOptions(ProcessLauncher::LaunchOptions&)
34
{
35
}
36
37
} // namespace WebKit
38
39
#endif // ENABLE(DATABASE_PROCESS)

Return to Bug 145867