| Differences between
and this patch
- a/Source/WebKit2/ChangeLog +57 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2015-07-10  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 NOBODY (OOPS!).
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-09  Dan Bernstein  <mitz@apple.com>
58
2015-07-09  Dan Bernstein  <mitz@apple.com>
2
59
3
        WebKit2 part of Track and expose policies for external URL schemes and App Links separately
60
        WebKit2 part of Track and expose policies for external URL schemes and App Links separately
- 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 43-48 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformEfl.cmake_sec2
43
    Shared/efl/ProcessExecutablePathEfl.cpp
45
    Shared/efl/ProcessExecutablePathEfl.cpp
44
    Shared/efl/WebEventFactory.cpp
46
    Shared/efl/WebEventFactory.cpp
45
47
48
    Shared/glib/KeyedDecoder.cpp
49
    Shared/glib/KeyedEncoder.cpp
50
46
    Shared/linux/WebMemorySamplerLinux.cpp
51
    Shared/linux/WebMemorySamplerLinux.cpp
47
52
48
    Shared/linux/SeccompFilters/OpenSyscall.cpp
53
    Shared/linux/SeccompFilters/OpenSyscall.cpp
Lines 121-126 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformEfl.cmake_sec3
121
    UIProcess/CoordinatedGraphics/WebView.cpp
126
    UIProcess/CoordinatedGraphics/WebView.cpp
122
    UIProcess/CoordinatedGraphics/WebViewClient.cpp
127
    UIProcess/CoordinatedGraphics/WebViewClient.cpp
123
128
129
    UIProcess/Databases/efl/DatabaseProcessProxyEfl.cpp
130
124
    UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp
131
    UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp
125
132
126
    UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp
133
    UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp
Lines 228-233 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformEfl.cmake_sec4
228
    "${WEBCORE_DIR}/platform/graphics/x11"
235
    "${WEBCORE_DIR}/platform/graphics/x11"
229
    "${WEBCORE_DIR}/platform/network/soup"
236
    "${WEBCORE_DIR}/platform/network/soup"
230
    "${WEBCORE_DIR}/platform/text/enchant"
237
    "${WEBCORE_DIR}/platform/text/enchant"
238
    "${WEBKIT2_DIR}/DatabaseProcess/unix"
231
    "${WEBKIT2_DIR}/NetworkProcess/efl"
239
    "${WEBKIT2_DIR}/NetworkProcess/efl"
232
    "${WEBKIT2_DIR}/NetworkProcess/unix"
240
    "${WEBKIT2_DIR}/NetworkProcess/unix"
233
    "${WEBKIT2_DIR}/Platform/efl"
241
    "${WEBKIT2_DIR}/Platform/efl"
Lines 257-262 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformEfl.cmake_sec5
257
    "${WEBKIT2_DIR}/WebProcess/WebPage/CoordinatedGraphics"
265
    "${WEBKIT2_DIR}/WebProcess/WebPage/CoordinatedGraphics"
258
    "${WTF_DIR}/wtf/efl"
266
    "${WTF_DIR}/wtf/efl"
259
    "${WTF_DIR}/wtf/glib"
267
    "${WTF_DIR}/wtf/glib"
268
    "${WTF_DIR}"
269
    "${WEBKIT2_DIR}"
260
)
270
)
261
271
262
list(APPEND WebKit2_SYSTEM_INCLUDE_DIRECTORIES
272
list(APPEND WebKit2_SYSTEM_INCLUDE_DIRECTORIES
Lines 313-318 list(APPEND NetworkProcess_SOURCES a/Source/WebKit2/PlatformEfl.cmake_sec6
313
    NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
323
    NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
314
)
324
)
315
325
326
list(APPEND DatabaseProcess_SOURCES
327
    DatabaseProcess/EntryPoint/unix/DatabaseProcessMain.cpp
328
)
329
316
list(APPEND WebProcess_LIBRARIES
330
list(APPEND WebProcess_LIBRARIES
317
    ${CAIRO_LIBRARIES}
331
    ${CAIRO_LIBRARIES}
318
    ${ECORE_IMF_EVAS_LIBRARIES}
332
    ${ECORE_IMF_EVAS_LIBRARIES}
- a/Source/WebKit2/PlatformGTK.cmake -2 / +3 lines
Lines 57-65 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformGTK.cmake_sec1
57
57
58
    Shared/cairo/ShareableBitmapCairo.cpp
58
    Shared/cairo/ShareableBitmapCairo.cpp
59
59
60
    Shared/glib/KeyedDecoder.cpp
61
    Shared/glib/KeyedEncoder.cpp
60
    Shared/gtk/ArgumentCodersGtk.cpp
62
    Shared/gtk/ArgumentCodersGtk.cpp
61
    Shared/gtk/KeyedDecoder.cpp
62
    Shared/gtk/KeyedEncoder.cpp
63
    Shared/gtk/NativeContextMenuItemGtk.cpp
63
    Shared/gtk/NativeContextMenuItemGtk.cpp
64
    Shared/gtk/NativeWebKeyboardEventGtk.cpp
64
    Shared/gtk/NativeWebKeyboardEventGtk.cpp
65
    Shared/gtk/NativeWebMouseEventGtk.cpp
65
    Shared/gtk/NativeWebMouseEventGtk.cpp
Lines 470-475 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformGTK.cmake_sec2
470
    "${WEBKIT2_DIR}/Shared/API/c/gtk"
470
    "${WEBKIT2_DIR}/Shared/API/c/gtk"
471
    "${WEBKIT2_DIR}/Shared/Network/CustomProtocols/soup"
471
    "${WEBKIT2_DIR}/Shared/Network/CustomProtocols/soup"
472
    "${WEBKIT2_DIR}/Shared/Downloads/soup"
472
    "${WEBKIT2_DIR}/Shared/Downloads/soup"
473
    "${WEBKIT2_DIR}/Shared/glib"
473
    "${WEBKIT2_DIR}/Shared/gtk"
474
    "${WEBKIT2_DIR}/Shared/gtk"
474
    "${WEBKIT2_DIR}/Shared/soup"
475
    "${WEBKIT2_DIR}/Shared/soup"
475
    "${WEBKIT2_DIR}/Shared/unix"
476
    "${WEBKIT2_DIR}/Shared/unix"
- 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