Skip to content

Commit

Permalink
Core - PublicApi remove references to CefSharp.Core.Runtime
Browse files Browse the repository at this point in the history
- Add an UnWrap method to the interfaces (should be hidden from IntelliSense)
- For .Net 4.5.2 projects they're  not a decorator class which an inner instance of the CefSharp.Core.Runtime Type
- For Net Core we have a ref assembly which allows us to reference the CefSharp.Core.Runtime without issues
  We can potentially remove the ref assembly now and forgo any direct reference.
  • Loading branch information
amaitland committed Jan 13, 2021
1 parent 980b6b0 commit 2b4a8cb
Show file tree
Hide file tree
Showing 42 changed files with 1,358 additions and 48 deletions.
7 changes: 6 additions & 1 deletion CefSharp.Core.Runtime.RefAssembly/CefSharp.Core.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void Dispose() { }
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute]
protected virtual void Dispose(bool A_0) { }
~BrowserSettings() { }
public virtual CefSharp.IBrowserSettings UnWrap() { throw null; }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public sealed partial class Cef
Expand Down Expand Up @@ -224,6 +225,7 @@ protected virtual void Dispose(bool A_0) { }
~PostData() { }
public virtual bool RemoveElement(CefSharp.IPostDataElement element) { throw null; }
public virtual void RemoveElements() { }
public virtual CefSharp.IPostData UnWrap() { throw null; }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public partial class PostDataElement : CefSharp.Internals.CefWrapper, CefSharp.IPostDataElement
Expand All @@ -238,6 +240,7 @@ public void Dispose() { }
protected virtual void Dispose(bool A_0) { }
~PostDataElement() { }
public virtual void SetToEmpty() { }
public virtual CefSharp.IPostDataElement UnWrap() { throw null; }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public partial class Request : CefSharp.Internals.CefWrapper, CefSharp.IRequest
Expand All @@ -262,6 +265,7 @@ protected virtual void Dispose(bool A_0) { }
public virtual void InitializePostData() { }
public virtual void SetHeaderByName(string name, string value, bool overwrite) { }
public virtual void SetReferrer(string referrerUrl, CefSharp.ReferrerPolicy policy) { }
public virtual CefSharp.IRequest UnWrap() { throw null; }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public partial class RequestContext : CefSharp.Internals.CefWrapper, CefSharp.IRequestContext
Expand Down Expand Up @@ -299,6 +303,7 @@ public virtual void PurgePluginListCache(bool reloadPages) { }
public virtual bool RegisterSchemeHandlerFactory(string schemeName, string domainName, CefSharp.ISchemeHandlerFactory factory) { throw null; }
public virtual System.Threading.Tasks.Task<CefSharp.ResolveCallbackResult> ResolveHostAsync(System.Uri origin) { throw null; }
public virtual bool SetPreference(string name, object value, out string error) { throw null; }
public virtual CefSharp.IRequestContext UnWrap() { throw null; }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public partial class RequestContextSettings : System.IDisposable
Expand Down Expand Up @@ -350,6 +355,7 @@ public virtual void SetAsChild(System.IntPtr parentHandle) { }
public virtual void SetAsChild(System.IntPtr parentHandle, int left, int top, int right, int bottom) { }
public virtual void SetAsPopup(System.IntPtr parentHandle, string windowName) { }
public virtual void SetAsWindowless(System.IntPtr parentHandle) { }
public virtual CefSharp.IWindowInfo UnWrap() { throw null; }
}
}
namespace CefSharp.Internals
Expand All @@ -364,4 +370,3 @@ protected void ThrowIfExecutedOnNonCefUiThread() { }
}
}


5 changes: 5 additions & 0 deletions CefSharp.Core.Runtime/BrowserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ namespace CefSharp
{
bool get() { return _autoDispose; }
}

virtual IBrowserSettings^ UnWrap()
{
return this;
}
};
}
}
3 changes: 2 additions & 1 deletion CefSharp.Core.Runtime/Internals/CefBrowserHostWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ void CefBrowserHostWrapper::ShowDevTools(IWindowInfo^ windowInfo, int inspectEle
}
else
{
auto cefWindowInfoWrapper = static_cast<WindowInfo^>(windowInfo);
//Get the inner instance then case that
auto cefWindowInfoWrapper = static_cast<WindowInfo^>(windowInfo->UnWrap());

nativeWindowInfo = *cefWindowInfoWrapper->GetWindowInfo();
}
Expand Down
4 changes: 2 additions & 2 deletions CefSharp.Core.Runtime/Internals/CefFrameWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void CefFrameWrapper::LoadRequest(IRequest^ request)
ThrowIfDisposed();
ThrowIfFrameInvalid();

auto requestWrapper = (Request^)request;
auto requestWrapper = (Request^)request->UnWrap();
_frame->LoadRequest(requestWrapper);
}

Expand Down Expand Up @@ -416,7 +416,7 @@ IUrlRequest^ CefFrameWrapper::CreateUrlRequest(IRequest^ request, IUrlRequestCli
}

auto urlRequest = _frame->CreateURLRequest(
(Request^)request,
(Request^)request->UnWrap(),
new CefUrlRequestClientAdapter(client));

return gcnew UrlRequest(urlRequest);
Expand Down
13 changes: 10 additions & 3 deletions CefSharp.Core.Runtime/ManagedCefBrowserAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@ namespace CefSharp
}
}

auto requestCtx = (RequestContext^)requestContext;
auto bSettings =(BrowserSettings^)browserSettings;
CefRefPtr<CefRequestContext> requestCtx;

if (requestContext != nullptr)
{
auto managedRequestCtx = (RequestContext^)requestContext->UnWrap();
requestCtx = static_cast<CefRefPtr<CefRequestContext>>(managedRequestCtx);
}

auto bSettings = (BrowserSettings^)browserSettings->UnWrap();

if (!CefBrowserHost::CreateBrowser(*cefWindowInfoWrapper->GetWindowInfo(), _clientAdapter.get(), addressNative,
*bSettings->_browserSettings, extraInfo, static_cast<CefRefPtr<CefRequestContext>>(requestCtx)))
*bSettings->_browserSettings, extraInfo, requestCtx))
{
throw gcnew InvalidOperationException("CefBrowserHost::CreateBrowser call failed, review the CEF log file for more details.");
}
Expand Down
9 changes: 7 additions & 2 deletions CefSharp.Core.Runtime/PostData.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace CefSharp

_postDataElements->Add(element);

auto elementWrapper = (PostDataElement^)element;
auto elementWrapper = (PostDataElement^)element->UnWrap();

return _postData->AddElement(elementWrapper);
}
Expand All @@ -190,7 +190,7 @@ namespace CefSharp

_postDataElements->Remove(element);

auto elementWrapper = (PostDataElement^)element;
auto elementWrapper = (PostDataElement^)element->UnWrap();

return _postData->RemoveElement(elementWrapper);
}
Expand Down Expand Up @@ -233,6 +233,11 @@ namespace CefSharp
return _postData->HasExcludedElements();
}
}

virtual IPostData^ UnWrap()
{
return this;
}
};
}
}
5 changes: 5 additions & 0 deletions CefSharp.Core.Runtime/PostDataElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ namespace CefSharp
_postDataElement->SetToBytes(val->Length, static_cast<void*>(src));
}
}

virtual IPostDataElement^ UnWrap()
{
return this;
}
};
}
}
2 changes: 1 addition & 1 deletion CefSharp.Core.Runtime/Request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace CefSharp

ThrowIfReadOnly();

_request->SetPostData((CefSharp::Core::PostData^)postData);
_request->SetPostData((CefSharp::Core::PostData^)postData->UnWrap());
}

bool Request::IsReadOnly::get()
Expand Down
5 changes: 5 additions & 0 deletions CefSharp.Core.Runtime/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ namespace CefSharp

virtual String^ GetHeaderByName(String^ name);
virtual void SetHeaderByName(String^ name, String^ value, bool overwrite);

virtual IRequest^ UnWrap()
{
return this;
}
};
}
}
9 changes: 7 additions & 2 deletions CefSharp.Core.Runtime/RequestContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace CefSharp
{
ThrowIfDisposed();

auto requestContext = (RequestContext^)context;
auto requestContext = (RequestContext^)context->UnWrap();

return _requestContext->IsSame(requestContext);
}
Expand All @@ -46,7 +46,7 @@ namespace CefSharp
{
ThrowIfDisposed();

auto requestContext = (RequestContext^)context;
auto requestContext = (RequestContext^)context->UnWrap();

return _requestContext->IsSharingWith(requestContext);
}
Expand Down Expand Up @@ -268,5 +268,10 @@ namespace CefSharp
CefPostTask(TID_UI, base::Bind(&CefRequestContext::LoadExtension, _requestContext.get(), StringUtils::ToNative(rootDirectory), manifest, extensionHandler));
}
}

IRequestContext^ RequestContext::UnWrap()
{
return this;
}
}
}
10 changes: 8 additions & 2 deletions CefSharp.Core.Runtime/RequestContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ namespace CefSharp
///Creates a new context object that shares storage with | other | and uses an optional | handler | .
RequestContext(IRequestContext^ otherRequestContext)
{
_requestContext = CefRequestContext::CreateContext((RequestContext^)otherRequestContext, NULL);
_requestContext = CefRequestContext::CreateContext((RequestContext^)otherRequestContext->UnWrap(), NULL);
}

RequestContext(IRequestContext^ otherRequestContext, IRequestContextHandler^ requestContextHandler)
{
_requestContext = CefRequestContext::CreateContext((RequestContext^)otherRequestContext, new CefRequestContextHandlerAdapter(requestContextHandler));
_requestContext = CefRequestContext::CreateContext((RequestContext^)otherRequestContext->UnWrap(), new CefRequestContextHandlerAdapter(requestContextHandler));
}

!RequestContext()
Expand Down Expand Up @@ -396,6 +396,12 @@ namespace CefSharp
/// and manifestJson should contain the contents that would otherwise be read from the manifest.json file on disk</param>
/// <param name="handler">handle events related to browser extensions</param>
virtual void LoadExtension(String^ rootDirectory, String^ manifestJson, IExtensionHandler^ handler);

/// <summary>
/// Gets the inner most instance
/// </summary>
/// <returns>current instance</returns>
virtual IRequestContext^ UnWrap();
};
}
}
Expand Down
5 changes: 5 additions & 0 deletions CefSharp.Core.Runtime/WindowInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ namespace CefSharp
{
_windowInfo->SetAsWindowless((HWND)parentHandle.ToPointer());
}

virtual IWindowInfo^ UnWrap()
{
return this;
}
};
}
}
Loading

0 comments on commit 2b4a8cb

Please sign in to comment.