Skip to content

Commit

Permalink
Rename IPluginHandler to IRequestContextHandler
Browse files Browse the repository at this point in the history
Add IRequestContextHandler.GetCookieManager() - Can now have unique CookieManager for each RequestContext
**Breaking Change**
CookieManager should be moved from the CefSharp.Internals namespace - will do that at some point later hopefully
  • Loading branch information
amaitland committed Sep 25, 2016
1 parent 895932d commit fb1c70a
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 31 deletions.
27 changes: 27 additions & 0 deletions CefSharp.Core/Internals/CookieManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Stdafx.h"

#include "include/cef_cookie.h"
#include "CefCompletionCallbackAdapter.h"

using namespace System::Threading::Tasks;

Expand All @@ -21,6 +22,23 @@ namespace CefSharp

void ThrowIfDisposed();
public:
///
// Creates a new cookie manager. If |path| is empty data will be stored in
// memory only. Otherwise, data will be stored at the specified |path|. To
// persist session cookies (cookies without an expiry date or validity
// interval) set |persist_session_cookies| to true. Session cookies are
// generally intended to be transient and most Web browsers do not persist
// them. If |callback| is non-NULL it will be executed asnychronously on the
// IO thread after the manager's storage has been initialized.
///
/*--cef(optional_param=path,optional_param=callback)--*/
CookieManager(String^ path, bool persistSessionCookies, ICompletionCallback^ callback)
{
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback);

_cookieManager = CefCookieManager::CreateManager(StringUtils::ToNative(path), persistSessionCookies, wrapper);
}

CookieManager(const CefRefPtr<CefCookieManager> &cookieManager)
:_cookieManager(cookieManager.get())
{
Expand All @@ -46,6 +64,15 @@ namespace CefSharp
virtual Task<List<Cookie^>^>^ VisitUrlCookiesAsync(String^ url, bool includeHttpOnly);
virtual bool VisitUrlCookies(String^ url, bool includeHttpOnly, ICookieVisitor^ visitor);
virtual Task<bool>^ FlushStoreAsync();

operator CefRefPtr<CefCookieManager>()
{
if (this == nullptr)
{
return NULL;
}
return _cookieManager.get();
}
};
}
}
8 changes: 4 additions & 4 deletions CefSharp.Core/RequestContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ namespace CefSharp
_requestContext = CefRequestContext::CreateContext(settings, NULL);
}

RequestContext(IPluginHandler^ pluginHandler)
RequestContext(IRequestContextHandler^ requestContextHandler)
{
CefRequestContextSettings settings;
_requestContext = CefRequestContext::CreateContext(settings, new RequestContextHandler(pluginHandler));
_requestContext = CefRequestContext::CreateContext(settings, new RequestContextHandler(requestContextHandler));
}

RequestContext(RequestContextSettings^ settings, IPluginHandler^ pluginHandler) : _settings(settings)
RequestContext(RequestContextSettings^ settings, IRequestContextHandler^ requestContextHandler) : _settings(settings)
{
_requestContext = CefRequestContext::CreateContext(settings, new RequestContextHandler(pluginHandler));
_requestContext = CefRequestContext::CreateContext(settings, new RequestContextHandler(requestContextHandler));
}

!RequestContext()
Expand Down
30 changes: 24 additions & 6 deletions CefSharp.Core/RequestContextHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,40 @@
#include "Stdafx.h"

#include "Internals\TypeConversion.h"
#include "Internals\CookieManager.h"

namespace CefSharp
{
private class RequestContextHandler : public CefRequestContextHandler
{
gcroot<IPluginHandler^> _pluginHandler;
gcroot<IRequestContextHandler^> _requestContextHandler;

public:
RequestContextHandler(IPluginHandler^ pluginHandler)
: _pluginHandler(pluginHandler)
RequestContextHandler(IRequestContextHandler^ requestContextHandler)
: _requestContextHandler(requestContextHandler)
{
}

~RequestContextHandler()
{
_pluginHandler = nullptr;
_requestContextHandler = nullptr;
}

virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE
{
if (Object::ReferenceEquals(_requestContextHandler, nullptr))
{
return NULL;
}

auto cookieManager = _requestContextHandler->GetCookieManager();

if (cookieManager == nullptr)
{
return NULL;
}

return (CookieManager^)cookieManager;
}

virtual bool OnBeforePluginLoad(const CefString& mime_type,
Expand All @@ -31,12 +49,12 @@ namespace CefSharp
CefRefPtr<CefWebPluginInfo> plugin_info,
CefRequestContextHandler::PluginPolicy* plugin_policy) OVERRIDE
{
if (!Object::ReferenceEquals(_pluginHandler, nullptr))
if (!Object::ReferenceEquals(_requestContextHandler, nullptr))
{
auto pluginInfo = TypeConversion::FromNative(plugin_info);
auto pluginPolicy = (CefSharp::PluginPolicy)*plugin_policy;

auto result = _pluginHandler->OnBeforePluginLoad(StringUtils::ToClr(mime_type),
auto result = _requestContextHandler->OnBeforePluginLoad(StringUtils::ToClr(mime_type),
StringUtils::ToClr(plugin_url),
StringUtils::ToClr(top_origin_url),
pluginInfo,
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<Compile Include="Handlers\GeolocationHandler.cs" />
<Compile Include="Handlers\MenuHandler.cs" />
<Compile Include="Handlers\LifespanHandler.cs" />
<Compile Include="Handlers\PluginHandler.cs" />
<Compile Include="Handlers\RequestContextHandler.cs" />
<Compile Include="Handlers\WpfBrowserProcessHandler.cs" />
<Compile Include="SimpleMainWindow.xaml.cs">
<DependentUpon>SimpleMainWindow.xaml</DependentUpon>
Expand Down
17 changes: 0 additions & 17 deletions CefSharp.Wpf.Example/Handlers/PluginHandler.cs

This file was deleted.

23 changes: 23 additions & 0 deletions CefSharp.Wpf.Example/Handlers/RequestContextHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

namespace CefSharp.Wpf.Example.Handlers
{
public class RequestContextHandler : IRequestContextHandler
{
bool IRequestContextHandler.OnBeforePluginLoad(string mimeType, string url, string topOriginUrl, WebPluginInfo pluginInfo, ref PluginPolicy pluginPolicy)
{
//pluginPolicy = PluginPolicy.Disable;
//return true;

return false;
}

ICookieManager IRequestContextHandler.GetCookieManager()
{
//Provide your own cookie manager
return null;
}
}
}
2 changes: 1 addition & 1 deletion CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<Compile Include="Internals\CefTimeUtils.cs" />
<Compile Include="Internals\CommandLineArgsParser.cs" />
<Compile Include="Internals\MethodParameter.cs" />
<Compile Include="IPluginHandler.cs" />
<Compile Include="IRequestContextHandler.cs" />
<Compile Include="IPopupFeatures.cs" />
<Compile Include="IRenderProcessMessageHandler.cs" />
<Compile Include="IRequestContext.cs" />
Expand Down
16 changes: 14 additions & 2 deletions CefSharp/IPluginHandler.cs → CefSharp/IRequestContextHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
namespace CefSharp
{
/// <summary>
/// Implement this interface to cancel loading of specific plugins
/// Implement this interface to provide handler implementations. The handler
/// instance will not be released until all objects related to the context have
/// been destroyed. Implement this interface to cancel loading of specific plugins
/// </summary>
public interface IPluginHandler
public interface IRequestContextHandler
{
/// <summary>
/// Called on the browser process IO thread to retrieve the cookie manager. If
/// this method returns NULL the default cookie manager retrievable via
/// IRequestContext.GetDefaultCookieManager() will be used.
/// </summary>
/// <returns>If
/// this method returns null the default cookie manager retrievable via
/// IRequestContext.GetDefaultCookieManager() will be used..</returns>
ICookieManager GetCookieManager();

/// <summary>
/// Called on the CEF IO thread before a plugin instance is loaded.
/// The default plugin policy can be set at runtime using the `--plugin-policy=[allow|detect|block]` command-line flag.
Expand Down

0 comments on commit fb1c70a

Please sign in to comment.