Skip to content

Commit 416ed30

Browse files
committed
Core - Migrate from CefTime to CefBaseTime (Execution/Binding)
- Convert more of the methods used by JavaScript binding/execution - Fix naming of FromDateTimeToBaseTime Issue #4234
1 parent 1a8c7cf commit 416ed30

11 files changed

Lines changed: 218 additions & 130 deletions

File tree

CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ namespace CefSharp
6969
}
7070
else if (obj->IsDate())
7171
{
72-
//TODO: Issue #4234
73-
auto baseTime = obj->GetDateValue();
74-
CefTime time;
75-
cef_time_from_basetime(baseTime, &time);
76-
SetCefTime(list, index, time);
72+
SetCefTime(list, index, obj->GetDateValue().val);
7773
}
7874
else if (obj->IsArray())
7975
{
@@ -160,11 +156,8 @@ namespace CefSharp
160156

161157
if (IsCefTime(list, index))
162158
{
163-
//TODO: Issue #4234
164159
auto time = GetCefTime(list, index);
165-
CefBaseTime baseTime;
166-
cef_time_to_basetime(&time, &baseTime);
167-
return CefV8Value::CreateDate(baseTime);
160+
return CefV8Value::CreateDate(time);
168161
}
169162

170163
if (type == VTYPE_LIST)

CefSharp.BrowserSubprocess.Core/TypeUtils.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ namespace CefSharp
9292
}
9393
if (type == DateTime::typeid)
9494
{
95-
return CefV8Value::CreateDate(TypeUtils::ConvertDateTimeToCefTime(safe_cast<DateTime>(obj)));
95+
CefBaseTime baseTime;
96+
baseTime.val = CefTimeUtils::FromDateTimeToBaseTime(safe_cast<DateTime>(obj));
97+
return CefV8Value::CreateDate(baseTime);
9698
}
9799
if (type->IsArray)
98100
{
@@ -175,7 +177,7 @@ namespace CefSharp
175177
}
176178
if (obj->IsDate())
177179
{
178-
return TypeUtils::ConvertCefTimeToDateTime(obj->GetDateValue());
180+
return CefTimeUtils::FromBaseTimeToDateTime(obj->GetDateValue().val);
179181
}
180182

181183
if (obj->IsArray())
@@ -254,30 +256,5 @@ namespace CefSharp
254256
//TODO: What exception type?
255257
throw gcnew Exception("Cannot convert object from Cef to CLR.");
256258
}
257-
258-
DateTime TypeUtils::ConvertCefTimeToDateTime(CefBaseTime baseTime)
259-
{
260-
//TODO: Issue #4234
261-
CefTime time;
262-
cef_time_from_basetime(baseTime, &time);
263-
264-
return CefTimeUtils::FromCefTime(time.year,
265-
time.month,
266-
time.day_of_month,
267-
time.hour,
268-
time.minute,
269-
time.second,
270-
time.millisecond);
271-
}
272-
273-
CefBaseTime TypeUtils::ConvertDateTimeToCefTime(DateTime dateTime)
274-
{
275-
//TODO: Issue #4234
276-
auto time = CefTime(CefTimeUtils::ToCefTime(dateTime));
277-
CefBaseTime baseTime;
278-
cef_time_to_basetime(&time, &baseTime);
279-
280-
return baseTime;
281-
}
282259
}
283260
}

CefSharp.Core.Runtime/CookieManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ namespace CefSharp
4848

4949
if (cookie->Expires.HasValue)
5050
{
51-
c.expires.val = CefTimeUtils::FromDateTimeBaseTime(cookie->Expires.Value);
51+
c.expires.val = CefTimeUtils::FromDateTimeToBaseTime(cookie->Expires.Value);
5252
}
5353

54-
c.creation.val = CefTimeUtils::FromDateTimeBaseTime(cookie->Creation);
55-
c.last_access.val = CefTimeUtils::FromDateTimeBaseTime(cookie->LastAccess);
54+
c.creation.val = CefTimeUtils::FromDateTimeToBaseTime(cookie->Creation);
55+
c.last_access.val = CefTimeUtils::FromDateTimeToBaseTime(cookie->LastAccess);
5656
c.same_site = (cef_cookie_same_site_t)cookie->SameSite;
5757
c.priority = (cef_cookie_priority_t)cookie->Priority;
5858

CefSharp.Core.Runtime/Internals/Serialization/ObjectsSerialization.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace CefSharp
3636
else if (IsCefTime(list, index))
3737
{
3838
auto cefTime = GetCefTime(list, index);
39-
result = ConvertCefTimeToDateTime(cefTime);
39+
result = CefTimeUtils::FromBaseTimeToDateTime(cefTime.val);
4040
}
4141
else if (IsJsCallback(list, index) && javascriptCallbackFactory != nullptr)
4242
{
@@ -81,16 +81,6 @@ namespace CefSharp
8181

8282
return result;
8383
}
84-
85-
DateTime ConvertCefTimeToDateTime(CefTime time)
86-
{
87-
auto epoch = time.GetDoubleT();
88-
if (epoch == 0)
89-
{
90-
return DateTime::MinValue;
91-
}
92-
return DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(epoch).ToLocalTime();
93-
}
9484
}
9585
}
9686
}

CefSharp.Core.Runtime/Internals/Serialization/Primitives.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,25 @@ namespace CefSharp
6565
}
6666

6767
template<typename TList, typename TIndex>
68-
void SetCefTime(const CefRefPtr<TList>& list, TIndex index, const CefTime &value)
68+
void SetCefTime(const CefRefPtr<TList>& list, TIndex index, const int64 &value)
6969
{
70-
auto doubleT = value.GetDoubleT();
71-
unsigned char mem[1 + sizeof(double)];
70+
unsigned char mem[1 + sizeof(int64)];
7271
mem[0] = static_cast<unsigned char>(PrimitiveType::CEFTIME);
73-
memcpy(reinterpret_cast<void*>(mem + 1), &doubleT, sizeof(double));
72+
memcpy(reinterpret_cast<void*>(mem + 1), &value, sizeof(int64));
7473

7574
auto binaryValue = CefBinaryValue::Create(mem, sizeof(mem));
7675
list->SetBinary(index, binaryValue);
7776
}
7877

7978
template<typename TList, typename TIndex>
80-
CefTime GetCefTime(const CefRefPtr<TList>& list, TIndex index)
79+
CefBaseTime GetCefTime(const CefRefPtr<TList>& list, TIndex index)
8180
{
82-
double doubleT;
81+
CefBaseTime baseTime;
8382

8483
auto binaryValue = list->GetBinary(index);
85-
binaryValue->GetData(&doubleT, sizeof(double), 1);
84+
binaryValue->GetData(&baseTime.val, sizeof(int64), 1);
8685

87-
return CefTime(doubleT);
86+
return baseTime;
8887
}
8988

9089
template<typename TList, typename TIndex>
@@ -136,4 +135,4 @@ namespace CefSharp
136135
}
137136
}
138137
}
139-
}
138+
}

CefSharp.Core.Runtime/Internals/Serialization/Primitives.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ namespace CefSharp
2020
bool IsInt64(const CefRefPtr<TList>& list, TIndex index);
2121

2222
template<typename TList, typename TIndex>
23-
void SetCefTime(const CefRefPtr<TList>& list, TIndex index, const CefTime &value);
23+
void SetCefTime(const CefRefPtr<TList>& list, TIndex index, const int64 &value);
2424
template<typename TList, typename TIndex>
25-
CefTime GetCefTime(const CefRefPtr<TList>& list, TIndex index);
25+
CefBaseTime GetCefTime(const CefRefPtr<TList>& list, TIndex index);
2626
template<typename TList, typename TIndex>
2727
bool IsCefTime(const CefRefPtr<TList>& list, TIndex index);
2828

@@ -43,12 +43,12 @@ namespace CefSharp
4343
template bool IsInt64(const CefRefPtr<CefListValue>& list, size_t index);
4444
template bool IsInt64(const CefRefPtr<CefDictionaryValue>& list, CefString index);
4545

46-
template void SetCefTime(const CefRefPtr<CefListValue>& list, int index, const CefTime &value);
47-
template void SetCefTime(const CefRefPtr<CefListValue>& list, size_t index, const CefTime &value);
48-
template void SetCefTime(const CefRefPtr<CefDictionaryValue>& list, CefString index, const CefTime &value);
49-
template CefTime GetCefTime(const CefRefPtr<CefListValue>& list, int index);
50-
template CefTime GetCefTime(const CefRefPtr<CefListValue>& list, size_t index);
51-
template CefTime GetCefTime(const CefRefPtr<CefDictionaryValue>& list, CefString index);
46+
template void SetCefTime(const CefRefPtr<CefListValue>& list, int index, const int64 &value);
47+
template void SetCefTime(const CefRefPtr<CefListValue>& list, size_t index, const int64 &value);
48+
template void SetCefTime(const CefRefPtr<CefDictionaryValue>& list, CefString index, const int64 &value);
49+
template CefBaseTime GetCefTime(const CefRefPtr<CefListValue>& list, int index);
50+
template CefBaseTime GetCefTime(const CefRefPtr<CefListValue>& list, size_t index);
51+
template CefBaseTime GetCefTime(const CefRefPtr<CefDictionaryValue>& list, CefString index);
5252
template bool IsCefTime(const CefRefPtr<CefListValue>& list, size_t index);
5353
template bool IsCefTime(const CefRefPtr<CefListValue>& list, int index);
5454
template bool IsCefTime(const CefRefPtr<CefDictionaryValue>& list, CefString index);
@@ -64,4 +64,4 @@ namespace CefSharp
6464
template bool IsJsCallback(const CefRefPtr<CefDictionaryValue>& list, CefString index);
6565
}
6666
}
67-
}
67+
}

CefSharp.Core.Runtime/Internals/Serialization/V8Serialization.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace CefSharp
114114
}
115115
else if (type == DateTime::typeid)
116116
{
117-
SetCefTime(list, index, ConvertDateTimeToCefTime(safe_cast<DateTime>(obj)));
117+
SetCefTime(list, index, CefTimeUtils::FromDateTimeToBaseTime(safe_cast<DateTime>(obj)));
118118
}
119119
// Serialize enum to sbyte, short, int, long, byte, ushort, uint, ulong (check type of enum)
120120
else if (type->IsEnum)
@@ -214,13 +214,6 @@ namespace CefSharp
214214

215215
ancestors->Remove(obj);
216216
}
217-
218-
CefTime ConvertDateTimeToCefTime(DateTime dateTime)
219-
{
220-
auto timeSpan = dateTime.ToUniversalTime() - DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind::Utc);
221-
222-
return CefTime(timeSpan.TotalSeconds);
223-
}
224217
}
225218
}
226219
}

CefSharp.Test/Javascript/EvaluateScriptAsyncFacts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public async Task CanEvaluateIntValues(object num)
102102
}
103103

104104
[Theory]
105+
[InlineData("1970-01-01", "1970-01-01")]
105106
[InlineData("1980-01-01", "1980-01-01")]
106107
//https://github.com/cefsharp/CefSharp/issues/4234
107108
public async Task CanEvaluateDateValues(DateTime expected, string actual)

0 commit comments

Comments
 (0)