mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
Implement CefRequestCallback wrapper and expose for relevant CefRequestHandler interfaces
Resolves #982
This commit is contained in:
@@ -257,6 +257,7 @@
|
||||
<ClInclude Include="Internals\PluginVisitor.h" />
|
||||
<ClInclude Include="Internals\RenderClientAdapter.h" />
|
||||
<ClInclude Include="Internals\ReportUnhandledExceptions.h" />
|
||||
<ClInclude Include="Internals\RequestCallback.h" />
|
||||
<ClInclude Include="Internals\StringVisitor.h" />
|
||||
<ClInclude Include="Internals\TypeConversion.h" />
|
||||
<ClInclude Include="NativeMethodWrapper.h" />
|
||||
|
||||
@@ -151,6 +151,9 @@
|
||||
<ClInclude Include="Internals\CefFrameWrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Internals\RequestCallback.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "ClientAdapter.h"
|
||||
#include "DownloadAdapter.h"
|
||||
#include "StreamAdapter.h"
|
||||
#include "RequestCallback.h"
|
||||
#include "Internals/TypeConversion.h"
|
||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||
#include "include/internal/cef_types.h"
|
||||
@@ -247,30 +248,24 @@ namespace CefSharp
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handler->OnCertificateError(_browserControl, (CefErrorCode)cert_error, StringUtils::ToClr(request_url)))
|
||||
{
|
||||
callback->Continue(true);
|
||||
return true;
|
||||
}
|
||||
// If callback is empty the error cannot be recovered from and the request will be canceled automatically.
|
||||
// Still notify the user of the certificate error just don't provide a callback.
|
||||
auto requestCallback = callback == NULL ? nullptr : gcnew RequestCallback(callback);
|
||||
|
||||
return false;
|
||||
return handler->OnCertificateError(_browserControl, (CefErrorCode)cert_error, StringUtils::ToClr(request_url), requestCallback);
|
||||
}
|
||||
|
||||
bool ClientAdapter::OnQuotaRequest(CefRefPtr<CefBrowser> browser, const CefString& originUrl, int64 newSize, CefRefPtr<CefRequestCallback> callback)
|
||||
{
|
||||
IRequestHandler^ handler = _browserControl->RequestHandler;
|
||||
auto handler = _browserControl->RequestHandler;
|
||||
if (handler == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto requestCallback = gcnew RequestCallback(callback);
|
||||
|
||||
if (handler->OnQuotaRequest(_browserControl, StringUtils::ToClr(originUrl), newSize))
|
||||
{
|
||||
callback->Continue(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return handler->OnQuotaRequest(_browserControl, StringUtils::ToClr(originUrl), newSize, requestCallback);
|
||||
}
|
||||
|
||||
// CEF3 API: public virtual bool OnBeforePluginLoad( CefRefPtr< CefBrowser > browser, const CefString& url, const CefString& policy_url, CefRefPtr< CefWebPluginInfo > info );
|
||||
@@ -377,8 +372,9 @@ namespace CefSharp
|
||||
}
|
||||
|
||||
auto requestWrapper = gcnew CefRequestWrapper(request);
|
||||
auto requestCallback = gcnew RequestCallback(callback);
|
||||
|
||||
return (cef_return_value_t)handler->OnBeforeResourceLoad(_browserControl, requestWrapper, gcnew CefFrameWrapper(frame, _browserControl->BrowserAdapter));
|
||||
return (cef_return_value_t)handler->OnBeforeResourceLoad(_browserControl, requestWrapper, gcnew CefFrameWrapper(frame, _browserControl->BrowserAdapter), requestCallback);
|
||||
}
|
||||
|
||||
CefRefPtr<CefDownloadHandler> ClientAdapter::GetDownloadHandler()
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright © 2010-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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stdafx.h"
|
||||
#include "MCefRefPtr.h"
|
||||
|
||||
using namespace CefSharp;
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
namespace Internals
|
||||
{
|
||||
public ref class RequestCallback : public IRequestCallback
|
||||
{
|
||||
MCefRefPtr<CefRequestCallback> _callback;
|
||||
internal:
|
||||
RequestCallback(CefRefPtr<CefRequestCallback> callback) : _callback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
~RequestCallback()
|
||||
{
|
||||
_callback = NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void Continue(bool allow)
|
||||
{
|
||||
_callback->Continue(allow);
|
||||
}
|
||||
|
||||
virtual void Cancel()
|
||||
{
|
||||
_callback->Cancel();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,12 @@ namespace CefSharp.Example
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRequestHandler.OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl)
|
||||
bool IRequestHandler.OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl, IRequestCallback callback)
|
||||
{
|
||||
//To allow certificate
|
||||
//callback.Continue(true);
|
||||
//return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -22,7 +26,7 @@ namespace CefSharp.Example
|
||||
// TODO: Add your own code here for handling scenarios where a plugin crashed, for one reason or another.
|
||||
}
|
||||
|
||||
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IFrame frame)
|
||||
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IFrame frame, IRequestCallback callback)
|
||||
{
|
||||
//Note to Redirect simply set the request Url
|
||||
//if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -30,6 +34,10 @@ namespace CefSharp.Example
|
||||
// request.Url = "https://github.com/";
|
||||
//}
|
||||
|
||||
//Callback in async fashion
|
||||
//callback.Continue(true);
|
||||
//return CefReturnValue.ContinueAsync;
|
||||
|
||||
return CefReturnValue.Continue;
|
||||
}
|
||||
|
||||
@@ -53,8 +61,12 @@ namespace CefSharp.Example
|
||||
// TODO: Add your own code here for handling scenarios where the Render Process terminated for one reason or another.
|
||||
}
|
||||
|
||||
public bool OnQuotaRequest(IWebBrowser browser, string originUrl, long newSize)
|
||||
public bool OnQuotaRequest(IWebBrowser browser, string originUrl, long newSize, IRequestCallback callback)
|
||||
{
|
||||
//Accept Request to raise Quota
|
||||
//callback.Continue(true);
|
||||
//return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
<Compile Include="Internals\JavascriptCallbackEndpointBehavior.cs" />
|
||||
<Compile Include="Internals\JavascriptCallbackSurrogate.cs" />
|
||||
<Compile Include="Internals\ReflectionUtils.cs" />
|
||||
<Compile Include="IRequestCallback.cs" />
|
||||
<Compile Include="IResourceHandler.cs" />
|
||||
<Compile Include="IResourceHandlerFactory.cs" />
|
||||
<Compile Include="IResourceHandlerResponse.cs" />
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright © 2010-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.
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
public interface IRequestCallback
|
||||
{
|
||||
/// <summary>
|
||||
/// Continue the url request.
|
||||
/// </summary>
|
||||
/// <param name="allow">If is true the request will be continued, otherwise, the request will be canceled.</param>
|
||||
void Continue(bool allow);
|
||||
|
||||
/// <summary>
|
||||
/// Cancel the url request.
|
||||
/// </summary>
|
||||
void Cancel();
|
||||
}
|
||||
}
|
||||
+23
-12
@@ -22,13 +22,20 @@ namespace CefSharp
|
||||
bool OnBeforeBrowse(IWebBrowser browser, IRequest request, bool isRedirect, IFrame frame);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a certificate error is thrown.
|
||||
/// Called to handle requests for URLs with an invalid SSL certificate.
|
||||
/// Return true and call <see cref="IRequestCallback.Continue"/> either
|
||||
/// in this method or at a later time to continue or cancel the request.
|
||||
/// If <see cref="CefSettings.IgnoreCertificateErrors"/> is set all invalid certificates
|
||||
/// will be accepted without calling this method.
|
||||
/// </summary>
|
||||
/// <param name="browser">the browser object</param>
|
||||
/// <param name="errorCode">the error code for this invalid certificate</param>
|
||||
/// <param name="requestUrl">the url of the request for the invalid certificate</param>
|
||||
/// <returns>Return true to allow the invalid certificate and continue the request.</returns>
|
||||
bool OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl);
|
||||
/// <param name="callback">Callback interface used for asynchronous continuation of url requests.
|
||||
/// If empty the error cannot be recovered from and the request will be canceled automatically.</param>
|
||||
/// <returns>Return false to cancel the request immediately. Return true and use <see cref="IRequestCallback"/> to
|
||||
/// execute in an async fashion.</returns>
|
||||
bool OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl, IRequestCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a plugin has crashed
|
||||
@@ -38,18 +45,17 @@ namespace CefSharp
|
||||
void OnPluginCrashed(IWebBrowser browser, string pluginPath);
|
||||
|
||||
/// <summary>
|
||||
/// Called before a resource request is loaded.
|
||||
/// Called before a resource request is loaded. For async processing return <see cref="CefReturnValue.ContinueAsync"/>
|
||||
/// and execute <see cref="IRequestCallback.Continue"/> or <see cref="IRequestCallback.Cancel"/>
|
||||
/// </summary>
|
||||
/// <param name="browser">the browser object</param>
|
||||
/// <param name="request">the request object - can be modified in this callback.</param>
|
||||
/// <param name="frame">The frame object</param>
|
||||
/// <remarks>
|
||||
/// The async features of this method are not currently exposed
|
||||
/// as such returning <see cref="CefReturnValue.ContinueAsync"/> should be avoided.
|
||||
/// </remarks>
|
||||
/// <param name="callback">Callback interface used for asynchronous continuation of url requests.</param>
|
||||
/// <returns>To cancel loading of the resource return <see cref="CefReturnValue.Cancel"/>
|
||||
/// or <see cref="CefReturnValue.Continue"/> to allow the resource to load normally.</returns>
|
||||
CefReturnValue OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IFrame frame);
|
||||
/// or <see cref="CefReturnValue.Continue"/> to allow the resource to load normally. For async
|
||||
/// return <see cref="CefReturnValue.ContinueAsync"/></returns>
|
||||
CefReturnValue OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IFrame frame, IRequestCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the browser needs credentials from the user.
|
||||
@@ -85,12 +91,17 @@ namespace CefSharp
|
||||
|
||||
/// <summary>
|
||||
/// Called when JavaScript requests a specific storage quota size via the webkitStorageInfo.requestQuota function.
|
||||
/// For async processing return true and execute <see cref="IRequestCallback.Continue"/> at a later time to
|
||||
/// grant or deny the request or <see cref="IRequestCallback.Cancel"/> to cancel.
|
||||
/// </summary>
|
||||
/// <param name="browser">the browser object</param>
|
||||
/// <param name="originUrl">the origin of the page making the request</param>
|
||||
/// <param name="newSize">is the requested quota size in bytes</param>
|
||||
/// <returns>Return true grant the request. Return false to deny the request.</returns>
|
||||
bool OnQuotaRequest(IWebBrowser browser, string originUrl, Int64 newSize);
|
||||
/// <param name="callback">Callback interface used for asynchronous continuation of url requests.</param>
|
||||
/// <returns>Return false to cancel the request immediately. Return true to continue the request
|
||||
/// and call <see cref="IRequestCallback.Continue"/> either in this method or at a later time to
|
||||
/// grant or deny the request.</returns>
|
||||
bool OnQuotaRequest(IWebBrowser browser, string originUrl, Int64 newSize, IRequestCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Called on the IO thread when a resource load is redirected. The |old_url| parameter will contain . .
|
||||
|
||||
Reference in New Issue
Block a user