Skip to content

Commit 33515af

Browse files
authored
Merge dda5607 into e893b04
2 parents e893b04 + dda5607 commit 33515af

File tree

3 files changed

+43
-81
lines changed

3 files changed

+43
-81
lines changed

CefSharp.Core/Internals/CefBrowserHostWrapper.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -458,48 +458,7 @@ NavigationEntry^ CefBrowserHostWrapper::GetVisibleNavigationEntry()
458458

459459
auto entry = _browserHost->GetVisibleNavigationEntry();
460460

461-
NavigationEntry^ navEntry;
462-
SslStatus^ sslStatus;
463-
464-
//TODO: This code is duplicated in CefNavigationEntryVisitor
465-
//TODO: NavigationEntry is a struct and so is SslStatus, this should
466-
// be reviewed as it's likely not ideal.
467-
if (entry->IsValid())
468-
{
469-
auto time = entry->GetCompletionTime();
470-
DateTime completionTime = CefTimeUtils::ConvertCefTimeToDateTime(time.GetDoubleT());
471-
auto ssl = entry->GetSSLStatus();
472-
X509Certificate2^ sslCertificate;
473-
474-
if (ssl.get())
475-
{
476-
auto certificate = ssl->GetX509Certificate();
477-
if (certificate.get())
478-
{
479-
auto derEncodedCertificate = certificate->GetDEREncoded();
480-
auto byteCount = derEncodedCertificate->GetSize();
481-
if (byteCount > 0)
482-
{
483-
auto bytes = gcnew cli::array<Byte>(byteCount);
484-
pin_ptr<Byte> src = &bytes[0]; // pin pointer to first element in arr
485-
486-
derEncodedCertificate->GetData(static_cast<void*>(src), byteCount, 0);
487-
488-
sslCertificate = gcnew X509Certificate2(bytes);
489-
}
490-
}
491-
sslStatus = gcnew SslStatus(ssl->IsSecureConnection(), (CertStatus)ssl->GetCertStatus(), (SslVersion)ssl->GetSSLVersion(), (SslContentStatus)ssl->GetContentStatus(), sslCertificate);
492-
}
493-
494-
navEntry = gcnew NavigationEntry(true, completionTime, StringUtils::ToClr(entry->GetDisplayURL()), entry->GetHttpStatusCode(), StringUtils::ToClr(entry->GetOriginalURL()), StringUtils::ToClr(entry->GetTitle()), (TransitionType)entry->GetTransitionType(), StringUtils::ToClr(entry->GetURL()), entry->HasPostData(), true, sslStatus);
495-
}
496-
else
497-
{
498-
//Invalid nav entry
499-
navEntry = gcnew NavigationEntry(true, DateTime::MinValue, nullptr, -1, nullptr, nullptr, (TransitionType)-1, nullptr, false, false, sslStatus);
500-
}
501-
502-
return navEntry;
461+
return TypeConversion::FromNative(entry, true);
503462
}
504463

505464
void CefBrowserHostWrapper::NotifyMoveOrResizeStarted()

CefSharp.Core/Internals/CefNavigationEntryVisitorAdapter.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "Stdafx.h"
88
#include "include\cef_browser.h"
99

10-
using namespace System::Security::Cryptography::X509Certificates;
11-
1210
namespace CefSharp
1311
{
1412
namespace Internals
@@ -35,43 +33,7 @@ namespace CefSharp
3533
int index,
3634
int total) OVERRIDE
3735
{
38-
NavigationEntry^ navEntry;
39-
SslStatus^ sslStatus;
40-
41-
if (entry->IsValid())
42-
{
43-
auto time = entry->GetCompletionTime();
44-
DateTime completionTime = CefSharp::Internals::CefTimeUtils::ConvertCefTimeToDateTime(time.GetDoubleT());
45-
auto ssl = entry->GetSSLStatus();
46-
X509Certificate2^ sslCertificate;
47-
48-
if (ssl.get())
49-
{
50-
auto certificate = ssl->GetX509Certificate();
51-
if (certificate.get())
52-
{
53-
auto derEncodedCertificate = certificate->GetDEREncoded();
54-
auto byteCount = derEncodedCertificate->GetSize();
55-
if (byteCount > 0)
56-
{
57-
auto bytes = gcnew cli::array<Byte>(byteCount);
58-
pin_ptr<Byte> src = &bytes[0]; // pin pointer to first element in arr
59-
60-
derEncodedCertificate->GetData(static_cast<void*>(src), byteCount, 0);
61-
62-
sslCertificate = gcnew X509Certificate2(bytes);
63-
}
64-
}
65-
sslStatus = gcnew SslStatus(ssl->IsSecureConnection(), (CertStatus)ssl->GetCertStatus(), (SslVersion)ssl->GetSSLVersion(), (SslContentStatus)ssl->GetContentStatus(), sslCertificate);
66-
}
67-
68-
navEntry = gcnew NavigationEntry(current, completionTime, StringUtils::ToClr(entry->GetDisplayURL()), entry->GetHttpStatusCode(), StringUtils::ToClr(entry->GetOriginalURL()), StringUtils::ToClr(entry->GetTitle()), (TransitionType)entry->GetTransitionType(), StringUtils::ToClr(entry->GetURL()), entry->HasPostData(), true, sslStatus);
69-
}
70-
else
71-
{
72-
//Invalid nav entry
73-
navEntry = gcnew NavigationEntry(current, DateTime::MinValue, nullptr, -1, nullptr, nullptr, (TransitionType)-1, nullptr, false, false, sslStatus);
74-
}
36+
auto navEntry = TypeConversion::FromNative(entry, current);
7537

7638
return _handler->Visit(navEntry, current, index, total);
7739
}

CefSharp.Core/Internals/TypeConversion.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using namespace System::Collections::Generic;
1818
using namespace System::Collections::Specialized;
19+
using namespace System::Security::Cryptography::X509Certificates;
1920
using namespace CefSharp::Internals::Serialization;
2021

2122
namespace CefSharp
@@ -294,6 +295,46 @@ namespace CefSharp
294295

295296
return cookie;
296297
}
298+
299+
static NavigationEntry^ FromNative(const CefRefPtr<CefNavigationEntry> entry, bool current)
300+
{
301+
SslStatus^ sslStatus;
302+
303+
if (!entry->IsValid())
304+
{
305+
return gcnew NavigationEntry(current, DateTime::MinValue, nullptr, -1, nullptr, nullptr, (TransitionType)-1, nullptr, false, false, sslStatus);
306+
}
307+
308+
auto time = entry->GetCompletionTime();
309+
DateTime completionTime = CefTimeUtils::ConvertCefTimeToDateTime(time.GetDoubleT());
310+
auto ssl = entry->GetSSLStatus();
311+
X509Certificate2^ sslCertificate;
312+
313+
if (ssl.get())
314+
{
315+
auto certificate = ssl->GetX509Certificate();
316+
if (certificate.get())
317+
{
318+
auto derEncodedCertificate = certificate->GetDEREncoded();
319+
auto byteCount = derEncodedCertificate->GetSize();
320+
if (byteCount > 0)
321+
{
322+
auto bytes = gcnew cli::array<Byte>(byteCount);
323+
pin_ptr<Byte> src = &bytes[0]; // pin pointer to first element in arr
324+
325+
derEncodedCertificate->GetData(static_cast<void*>(src), byteCount, 0);
326+
327+
sslCertificate = gcnew X509Certificate2(bytes);
328+
}
329+
}
330+
331+
sslStatus = gcnew SslStatus(ssl->IsSecureConnection(), (CertStatus)ssl->GetCertStatus(), (SslVersion)ssl->GetSSLVersion(), (SslContentStatus)ssl->GetContentStatus(), sslCertificate);
332+
}
333+
334+
return gcnew NavigationEntry(current, completionTime, StringUtils::ToClr(entry->GetDisplayURL()), entry->GetHttpStatusCode(),
335+
StringUtils::ToClr(entry->GetOriginalURL()), StringUtils::ToClr(entry->GetTitle()), (TransitionType)entry->GetTransitionType(),
336+
StringUtils::ToClr(entry->GetURL()), entry->HasPostData(), true, sslStatus);
337+
}
297338
};
298339
}
299340
}

0 commit comments

Comments
 (0)