Skip to content

Commit

Permalink
API changed for OnBeforeResourceLoad, OnCertificateError, OnQuotaRequ…
Browse files Browse the repository at this point in the history
…est.

For OnCertificateError, OnQuotaRequest the callback was changed to be a generic one, so no outward facing API change.
With OnBeforeResourceLoad there is now a async callback which isn't used, the only two options that will work are Cancel or Continue
  • Loading branch information
amaitland committed Apr 28, 2015
1 parent 83f3a69 commit 6abfb8c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
11 changes: 6 additions & 5 deletions CefSharp.Core/Internals/ClientAdapter.cpp
Expand Up @@ -12,6 +12,7 @@
#include "StreamAdapter.h"
#include "Internals/TypeConversion.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "include/internal/cef_types.h"

namespace CefSharp
{
Expand Down Expand Up @@ -236,7 +237,7 @@ namespace CefSharp
return handler->OnBeforeBrowse(_browserControl, wrapper, isRedirect, frame->IsMain());
}

bool ClientAdapter::OnCertificateError(CefRefPtr<CefBrowser> browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr<CefSSLInfo> ssl_info, CefRefPtr<CefAllowCertificateErrorCallback> callback)
bool ClientAdapter::OnCertificateError(CefRefPtr<CefBrowser> browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr<CefSSLInfo> ssl_info, CefRefPtr<CefRequestCallback> callback)
{
IRequestHandler^ handler = _browserControl->RequestHandler;
if (handler == nullptr)
Expand All @@ -253,7 +254,7 @@ namespace CefSharp
return false;
}

bool ClientAdapter::OnQuotaRequest(CefRefPtr<CefBrowser> browser, const CefString& originUrl, int64 newSize, CefRefPtr<CefQuotaCallback> callback)
bool ClientAdapter::OnQuotaRequest(CefRefPtr<CefBrowser> browser, const CefString& originUrl, int64 newSize, CefRefPtr<CefRequestCallback> callback)
{
IRequestHandler^ handler = _browserControl->RequestHandler;
if (handler == nullptr)
Expand Down Expand Up @@ -365,18 +366,18 @@ namespace CefSharp
return NULL;
}

bool ClientAdapter::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request)
cef_return_value_t ClientAdapter::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRefPtr<CefRequestCallback> callback)
{
IRequestHandler^ handler = _browserControl->RequestHandler;

if (handler == nullptr)
{
return false;
return cef_return_value_t::RV_CONTINUE;
}

auto requestWrapper = gcnew CefRequestWrapper(request);

return handler->OnBeforeResourceLoad(_browserControl, requestWrapper, frame->IsMain());
return (cef_return_value_t)handler->OnBeforeResourceLoad(_browserControl, requestWrapper, frame->IsMain());
}

CefRefPtr<CefDownloadHandler> ClientAdapter::GetDownloadHandler()
Expand Down
7 changes: 4 additions & 3 deletions CefSharp.Core/Internals/ClientAdapter.h
Expand Up @@ -9,6 +9,7 @@
#include "include/cef_app.h"
#include "include/cef_client.h"
#include "include/cef_render_process_handler.h"
#include "include/internal/cef_types.h"

using namespace System;

Expand Down Expand Up @@ -88,12 +89,12 @@ namespace CefSharp

// CefRequestHandler
virtual DECL CefRefPtr<CefResourceHandler> GetResourceHandler(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) OVERRIDE;
virtual DECL bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) OVERRIDE;
virtual DECL cef_return_value_t OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRefPtr<CefRequestCallback> callback) OVERRIDE;
virtual DECL bool GetAuthCredentials(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isProxy,
const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr<CefAuthCallback> callback) OVERRIDE;
virtual DECL bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool isRedirect) OVERRIDE;
virtual DECL bool OnCertificateError(CefRefPtr<CefBrowser> browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr<CefSSLInfo> ssl_info, CefRefPtr<CefAllowCertificateErrorCallback> callback) OVERRIDE;
virtual DECL bool OnQuotaRequest(CefRefPtr<CefBrowser> browser, const CefString& originUrl, int64 newSize, CefRefPtr<CefQuotaCallback> callback) OVERRIDE;
virtual DECL bool OnCertificateError(CefRefPtr<CefBrowser> browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr<CefSSLInfo> ssl_info, CefRefPtr<CefRequestCallback> callback) OVERRIDE;
virtual DECL bool OnQuotaRequest(CefRefPtr<CefBrowser> browser, const CefString& originUrl, int64 newSize, CefRefPtr<CefRequestCallback> callback) OVERRIDE;
virtual DECL void OnResourceRedirect(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& oldUrl, CefString& newUrl) OVERRIDE;
virtual DECL void OnProtocolExecution(CefRefPtr<CefBrowser> browser, const CefString& url, bool& allowOSExecution) OVERRIDE;

Expand Down
4 changes: 2 additions & 2 deletions CefSharp.Example/RequestHandler.cs
Expand Up @@ -22,15 +22,15 @@ void IRequestHandler.OnPluginCrashed(IWebBrowser browser, string pluginPath)
// TODO: Add your own code here for handling scenarios where a plugin crashed, for one reason or another.
}

bool IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequest request, bool isMainFrame)
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequest request, bool isMainFrame)
{
//Note to Redirect simply set the request Url
//if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
//{
// request.Url = "https://github.com/";
//}

return false;
return CefReturnValue.Continue;
}

bool IRequestHandler.GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme, ref string username, ref string password)
Expand Down
24 changes: 24 additions & 0 deletions CefSharp/CefReturnValue.cs
@@ -0,0 +1,24 @@
// 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 enum CefReturnValue
{
/// <summary>
/// Cancel immediately.
/// </summary>
Cancel = 0,

/// <summary>
/// Continue immediately.
/// </summary>
Continue,

/// <summary>
/// Continue asynchronously (usually via a callback).
/// </summary>
ContinueAsync
}
}
1 change: 1 addition & 0 deletions CefSharp/CefSharp.csproj
Expand Up @@ -90,6 +90,7 @@
<ItemGroup>
<Compile Include="CefDirtyRect.cs" />
<Compile Include="CefFileDialogMode.cs" />
<Compile Include="CefReturnValue.cs" />
<Compile Include="CefThreadIds.cs" />
<Compile Include="DefaultResourceHandlerFactory.cs" />
<Compile Include="DependencyChecker.cs" />
Expand Down
11 changes: 8 additions & 3 deletions CefSharp/IRequestHandler.cs
Expand Up @@ -42,9 +42,14 @@ public interface IRequestHandler
/// </summary>
/// <param name="browser">the browser object</param>
/// <param name="request">the request object - can be modified in this callback.</param>
/// /// <param name="isMainFrame">whether the request comes from main frame or not</param>
/// <returns>To cancel loading of the resource return true or false to allow the resource to load normally.</returns>
bool OnBeforeResourceLoad(IWebBrowser browser, IRequest request, bool isMainFrame);
/// <param name="isMainFrame">whether the request comes from main frame or not</param>
/// <remarks>
/// The async features of this method are not currently exposed
/// as such returning <see cref="CefReturnValue.ContinueAsync"/> should be avoided.
/// </remarks>
/// <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, bool isMainFrame);

/// <summary>
/// Called when the browser needs credentials from the user.
Expand Down

0 comments on commit 6abfb8c

Please sign in to comment.