admin
2020-06-10 a610f2ab6e543d2cb78c1ef212ac6a74ddc067d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright © 2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
 
#include "stdafx.h"
#include "JsObjectsSerialization.h"
#include "../CefSharp.Core/Internals/Serialization/Primitives.h"
#include "../CefSharp.Core/Internals/Serialization/ObjectsSerialization.h"
 
namespace CefSharp
{
    namespace Internals
    {
        namespace Serialization
        {
            JavascriptObject^ DeserializeJsObject(const CefRefPtr<CefListValue>& rootList, int index)
            {
                if (rootList->GetType(index) == VTYPE_INVALID ||
                    rootList->GetType(index) == VTYPE_NULL)
                {
                    return nullptr;
                }
 
                auto list = rootList->GetList(index);
                auto jsObject = gcnew JavascriptObject();
                jsObject->Id = GetInt64(list, 0);
                jsObject->Name = StringUtils::ToClr(list->GetString(1));
                jsObject->JavascriptName = StringUtils::ToClr(list->GetString(2));
                jsObject->IsAsync = list->GetBool(3);
 
                auto methodList = list->GetList(4);
                auto methodCount = methodList->GetInt(0);
                auto k = 1;
                for (auto j = 0; j < methodCount; j++)
                {
                    auto jsMethod = gcnew JavascriptMethod();
 
                    jsMethod->Id = GetInt64(methodList, k++);
                    jsMethod->ManagedName = StringUtils::ToClr(methodList->GetString(k++));
                    jsMethod->JavascriptName = StringUtils::ToClr(methodList->GetString(k++));
                    jsMethod->ParameterCount = methodList->GetInt(k++);
 
                    jsObject->Methods->Add(jsMethod);
                }
 
                auto propertyList = list->GetList(5);
                auto propertyCount = propertyList->GetInt(0);
                k = 1;
                for (auto j = 0; j < propertyCount; j++)
                {
                    auto jsProperty = gcnew JavascriptProperty();
 
                    jsProperty->Id = GetInt64(propertyList, k++);
                    jsProperty->ManagedName = StringUtils::ToClr(propertyList->GetString(k++));
                    jsProperty->JavascriptName = StringUtils::ToClr(propertyList->GetString(k++));
                    jsProperty->IsComplexType = propertyList->GetBool(k++);
                    jsProperty->IsReadOnly = propertyList->GetBool(k++);
 
                    jsProperty->JsObject = DeserializeJsObject(propertyList, k++);
                    jsProperty->PropertyValue = DeserializeObject(propertyList, k++, nullptr);
 
                    jsObject->Properties->Add(jsProperty);
                }
                return jsObject;
            }
 
            List<JavascriptObject^>^ DeserializeJsObjects(const CefRefPtr<CefListValue>& list, int index)
            {
                auto result = gcnew List<JavascriptObject^>();
                auto subList = list->GetList(index);
                for (auto i = 0; i < subList->GetSize(); i++)
                {
                    result->Add(DeserializeJsObject(subList, i));
                }
 
                return result;
            }
        }
    }
}