diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj
index dfb6b13c6..d5ad792da 100644
--- a/CefSharp.Core/CefSharp.Core.vcxproj
+++ b/CefSharp.Core/CefSharp.Core.vcxproj
@@ -257,6 +257,7 @@
+
diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters
index fbd4dbb56..6e9f63678 100644
--- a/CefSharp.Core/CefSharp.Core.vcxproj.filters
+++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters
@@ -151,6 +151,9 @@
Header Files
+
+ Header Files
+
diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp
index 67bbe6b2c..303f8874b 100644
--- a/CefSharp.Core/Internals/ClientAdapter.cpp
+++ b/CefSharp.Core/Internals/ClientAdapter.cpp
@@ -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 browser, const CefString& originUrl, int64 newSize, CefRefPtr 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 ClientAdapter::GetDownloadHandler()
diff --git a/CefSharp.Core/Internals/RequestCallback.h b/CefSharp.Core/Internals/RequestCallback.h
new file mode 100644
index 000000000..c30ff027a
--- /dev/null
+++ b/CefSharp.Core/Internals/RequestCallback.h
@@ -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 _callback;
+ internal:
+ RequestCallback(CefRefPtr callback) : _callback(callback)
+ {
+ }
+
+ ~RequestCallback()
+ {
+ _callback = NULL;
+ }
+
+ public:
+ virtual void Continue(bool allow)
+ {
+ _callback->Continue(allow);
+ }
+
+ virtual void Cancel()
+ {
+ _callback->Cancel();
+ }
+ };
+ }
+}
diff --git a/CefSharp.Example/RequestHandler.cs b/CefSharp.Example/RequestHandler.cs
index 9032ad9df..71ad7f5fd 100644
--- a/CefSharp.Example/RequestHandler.cs
+++ b/CefSharp.Example/RequestHandler.cs
@@ -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;
}
diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj
index 9e7c26c59..e6c86c5c8 100644
--- a/CefSharp/CefSharp.csproj
+++ b/CefSharp/CefSharp.csproj
@@ -105,6 +105,7 @@
+
diff --git a/CefSharp/IRequestCallback.cs b/CefSharp/IRequestCallback.cs
new file mode 100644
index 000000000..9a76cdb08
--- /dev/null
+++ b/CefSharp/IRequestCallback.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
+ {
+ ///
+ /// Continue the url request.
+ ///
+ /// If is true the request will be continued, otherwise, the request will be canceled.
+ void Continue(bool allow);
+
+ ///
+ /// Cancel the url request.
+ ///
+ void Cancel();
+ }
+}
diff --git a/CefSharp/IRequestHandler.cs b/CefSharp/IRequestHandler.cs
index 89dcc1d35..e076615e4 100644
--- a/CefSharp/IRequestHandler.cs
+++ b/CefSharp/IRequestHandler.cs
@@ -22,13 +22,20 @@ namespace CefSharp
bool OnBeforeBrowse(IWebBrowser browser, IRequest request, bool isRedirect, IFrame frame);
///
- /// Called when a certificate error is thrown.
+ /// Called to handle requests for URLs with an invalid SSL certificate.
+ /// Return true and call either
+ /// in this method or at a later time to continue or cancel the request.
+ /// If is set all invalid certificates
+ /// will be accepted without calling this method.
///
/// the browser object
/// the error code for this invalid certificate
/// the url of the request for the invalid certificate
- /// Return true to allow the invalid certificate and continue the request.
- bool OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl);
+ /// Callback interface used for asynchronous continuation of url requests.
+ /// If empty the error cannot be recovered from and the request will be canceled automatically.
+ /// Return false to cancel the request immediately. Return true and use to
+ /// execute in an async fashion.
+ bool OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl, IRequestCallback callback);
///
/// Called when a plugin has crashed
@@ -38,18 +45,17 @@ namespace CefSharp
void OnPluginCrashed(IWebBrowser browser, string pluginPath);
///
- /// Called before a resource request is loaded.
+ /// Called before a resource request is loaded. For async processing return
+ /// and execute or
///
/// the browser object
/// the request object - can be modified in this callback.
/// The frame object
- ///
- /// The async features of this method are not currently exposed
- /// as such returning should be avoided.
- ///
+ /// Callback interface used for asynchronous continuation of url requests.
/// To cancel loading of the resource return
- /// or to allow the resource to load normally.
- CefReturnValue OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IFrame frame);
+ /// or to allow the resource to load normally. For async
+ /// return
+ CefReturnValue OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IFrame frame, IRequestCallback callback);
///
/// Called when the browser needs credentials from the user.
@@ -85,12 +91,17 @@ namespace CefSharp
///
/// Called when JavaScript requests a specific storage quota size via the webkitStorageInfo.requestQuota function.
+ /// For async processing return true and execute at a later time to
+ /// grant or deny the request or to cancel.
///
/// the browser object
/// the origin of the page making the request
/// is the requested quota size in bytes
- /// Return true grant the request. Return false to deny the request.
- bool OnQuotaRequest(IWebBrowser browser, string originUrl, Int64 newSize);
+ /// Callback interface used for asynchronous continuation of url requests.
+ /// Return false to cancel the request immediately. Return true to continue the request
+ /// and call either in this method or at a later time to
+ /// grant or deny the request.
+ bool OnQuotaRequest(IWebBrowser browser, string originUrl, Int64 newSize, IRequestCallback callback);
///
/// Called on the IO thread when a resource load is redirected. The |old_url| parameter will contain . .