Skip to content

Commit

Permalink
Add IRequestContext.ResolveHost
Browse files Browse the repository at this point in the history
Add IRequestContext.ResolveHostCached
Both methods are for DNS -> IPAddress resolution

https://bitbucket.org/chromiumembedded/cef/commits/ce1e9e65fd3f5a075cac924ed987165bb4641d9d?at=master
  • Loading branch information
amaitland committed Mar 19, 2016
1 parent 7b29d7a commit 174beb2
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions CefSharp.Core/CefSharp.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
<ClInclude Include="Internals\CefPdfPrintCallbackWrapper.h" />
<ClInclude Include="Internals\CefPostDataElementWrapper.h" />
<ClInclude Include="Internals\CefPostDataWrapper.h" />
<ClInclude Include="Internals\CefResolveCallbackAdapter.h" />
<ClInclude Include="Internals\CefResponseFilterAdapter.h" />
<ClInclude Include="Internals\CefResponseWrapper.h" />
<ClInclude Include="Internals\CefRunContextMenuCallbackWrapper.h" />
Expand Down
3 changes: 3 additions & 0 deletions CefSharp.Core/CefSharp.Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@
<ClInclude Include="PopupFeatures.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Internals\CefResolveCallbackAdapter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Internals\CefSharpBrowserWrapper.h">
Expand Down
35 changes: 35 additions & 0 deletions CefSharp.Core/Internals/CefResolveCallbackAdapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2010-2016 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.

#pragma once

#include "Stdafx.h"
#include "include/cef_request_context.h"

namespace CefSharp
{
private class CefResolveCallbackAdapter : public CefResolveCallback
{
private:
gcroot<IResolveCallback^> _handler;

public:
CefResolveCallbackAdapter(IResolveCallback^ handler)
{
_handler = handler;
}

~CefResolveCallbackAdapter()
{
_handler = nullptr;
}

void OnResolveCompleted(cef_errorcode_t result, const std::vector<CefString>& resolvedIps) OVERRIDE
{
_handler->OnResolveCompleted((CefErrorCode)result, StringUtils::ToClr(resolvedIps));
}

IMPLEMENT_REFCOUNTING(CefResolveCallbackAdapter);
};
}
40 changes: 40 additions & 0 deletions CefSharp.Core/RequestContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Internals\CefCompletionCallbackAdapter.h"
#include "Internals\CookieManager.h"
#include "Internals\CefWrapper.h"
#include "Internals\CefResolveCallbackAdapter.h"

using namespace System::Runtime::InteropServices;

Expand Down Expand Up @@ -280,6 +281,45 @@ namespace CefSharp
_requestContext->CloseAllConnections(wrapper);
}

///
// Attempts to resolve |origin| to a list of associated IP addresses.
// |callback| will be executed on the UI thread after completion.
///
/*--cef()--*/
virtual void ResolveHost(String^ origin, IResolveCallback^ callback)
{
ThrowIfDisposed();

if (callback == nullptr)
{
throw gcnew ArgumentNullException("callback");
}

CefRefPtr<CefResolveCallback> callbackWrapper = new CefResolveCallbackAdapter(callback);

_requestContext->ResolveHost(StringUtils::ToNative(origin), callbackWrapper);
}

///
// Attempts to resolve |origin| to a list of associated IP addresses using
// cached data. |resolved_ips| will be populated with the list of resolved IP
// addresses or empty if no cached data is available. Returns ERR_NONE on
// success. This method must be called on the browser process IO thread.
///
/*--cef(default_retval=ERR_FAILED)--*/
virtual CefErrorCode ResolveHostCached(String^ origin, [Out] IList<String^>^ %resolvedIpAddresses)
{
ThrowIfDisposed();

std::vector<CefString> addresses;

auto errorCode =_requestContext->ResolveHostCached(StringUtils::ToNative(origin), addresses);

resolvedIpAddresses = StringUtils::ToClr(addresses);

return (CefErrorCode)errorCode;
}

operator CefRefPtr<CefRequestContext>()
{
if(this == nullptr)
Expand Down
1 change: 1 addition & 0 deletions CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="IPopupFeatures.cs" />
<Compile Include="IRenderProcessMessageHandler.cs" />
<Compile Include="IRequestContext.cs" />
<Compile Include="IResolveCallback.cs" />
<Compile Include="IResponseFilter.cs" />
<Compile Include="IRunContextMenuCallback.cs" />
<Compile Include="MenuItemType.cs" />
Expand Down
17 changes: 17 additions & 0 deletions CefSharp/IRequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,22 @@ public interface IRequestContext : IDisposable
/// <param name="callback">If is non-NULL it will be executed on the CEF UI thread after
/// completion. This param is optional</param>
void CloseAllConnections(ICompletionCallback callback);

/// <summary>
/// Attempts to resolve origin to a list of associated IP addresses.
/// </summary>
/// <param name="origin">host name to resolve</param>
/// <param name="callback">callback will be executed on the CEF UI thread after completion.</param>
void ResolveHost(string origin, IResolveCallback callback);

/// <summary>
/// Attempts to resolve origin to a list of associated IP addresses using
/// cached data. This method must be called on the CEF IO thread.
/// </summary>
/// <param name="origin">host name to resolve</param>
/// <param name="resolvedIpAddresses">list of resolved IP
/// addresses or null if no cached data is available.</param>
/// <returns> Returns <see cref="CefErrorCode.None"/> on success</returns>
CefErrorCode ResolveHostCached(string origin, out IList<string> resolvedIpAddresses);
}
}
25 changes: 25 additions & 0 deletions CefSharp/IResolveCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright © 2010-2016 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.

using System;
using System.Collections.Generic;

namespace CefSharp
{
public interface IResolveCallback : IDisposable
{
/// <summary>
/// Called after the ResolveHost request has completed.
/// </summary>
/// <param name="result">The result code</param>
/// <param name="resolvedIpAddresses">will be the list of resolved IP addresses or
/// null if the resolution failed.</param>
void OnResolveCompleted(CefErrorCode result, IList<string> resolvedIpAddresses);

/// <summary>
/// Gets a value indicating whether the callback has been disposed of.
/// </summary>
bool IsDisposed { get; }
}
}

0 comments on commit 174beb2

Please sign in to comment.