diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index 7cc136793..769d58675 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -252,6 +252,8 @@ + + @@ -310,7 +312,6 @@ - diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index 5fad10aba..836368641 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -142,9 +142,6 @@ Header Files - - Header Files - Header Files @@ -265,6 +262,12 @@ Header Files + + Header Files + + + Header Files + diff --git a/CefSharp.Core/CookieAsyncWrapper.h b/CefSharp.Core/CookieAsyncWrapper.h deleted file mode 100644 index eddc42900..000000000 --- a/CefSharp.Core/CookieAsyncWrapper.h +++ /dev/null @@ -1,81 +0,0 @@ -// 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. - -#pragma once - -#include "Stdafx.h" - -namespace CefSharp -{ - private ref class CookieAsyncWrapper - { - MCefRefPtr _cookieManager; - String^ _url; - String^ _name; - String^ _value; - String^ _domain; - String^ _path; - bool _secure; - bool _httponly; - bool _hasExpires; - DateTime _expires; - - public: - //Used for SetCookies - CookieAsyncWrapper(const CefRefPtr &cookieManager, String^ url, String^ name, String^ value, String^ domain, String^ path, bool secure, bool httponly, bool hasExpires, DateTime expires) : - _url(url), _name(name), _value(value), _domain(domain), _path(path), _secure(secure), _httponly(httponly), _hasExpires(hasExpires), _expires(expires), _cookieManager(cookieManager.get()) - { - } - - //Used for DeleteCookies - CookieAsyncWrapper(const CefRefPtr &cookieManager, String^ url, String^ name) : - _url(url), _name(name), _cookieManager(cookieManager.get()) - { - } - - bool SetCookie() - { - CefCookie cookie; - StringUtils::AssignNativeFromClr(cookie.name, _name); - StringUtils::AssignNativeFromClr(cookie.value, _value); - StringUtils::AssignNativeFromClr(cookie.domain, _domain); - StringUtils::AssignNativeFromClr(cookie.path, _path); - cookie.secure = _secure; - cookie.httponly = _httponly; - cookie.has_expires = _hasExpires; - cookie.expires.year = _expires.Year; - cookie.expires.month = _expires.Month; - cookie.expires.day_of_month = _expires.Day; - cookie.expires.hour = _expires.Hour; - cookie.expires.minute = _expires.Minute; - cookie.expires.second = _expires.Second; - cookie.expires.millisecond = _expires.Millisecond; - - auto result = _cookieManager->SetCookie(StringUtils::ToNative(_url), cookie, NULL); - - delete this; - - return result; - } - - bool DeleteCookies() - { - auto result = _cookieManager->DeleteCookies(StringUtils::ToNative(_url), StringUtils::ToNative(_name), NULL); - - delete this; - - return result; - } - - !CookieAsyncWrapper() - { - _cookieManager = nullptr; - } - - ~CookieAsyncWrapper() - { - this->!CookieAsyncWrapper(); - } - }; -} \ No newline at end of file diff --git a/CefSharp.Core/CookieManager.cpp b/CefSharp.Core/CookieManager.cpp index 82e19df5d..56dac01ff 100644 --- a/CefSharp.Core/CookieManager.cpp +++ b/CefSharp.Core/CookieManager.cpp @@ -5,9 +5,10 @@ #include "Stdafx.h" #include "CookieManager.h" -#include "CookieAsyncWrapper.h" #include "Internals\CookieVisitor.h" #include "Internals\CefCompletionCallbackAdapter.h" +#include "Internals\CefSetCookieCallbackAdapter.h" +#include "Internals\CefDeleteCookiesCallbackAdapter.h" #include "Cef.h" namespace CefSharp @@ -20,66 +21,66 @@ namespace CefSharp } } - Task^ CookieManager::DeleteCookiesAsync(String^ url, String^ name) + bool CookieManager::DeleteCookies(String^ url, String^ name, IDeleteCookiesCallback^ callback) { ThrowIfDisposed(); - auto cookieInvoker = gcnew CookieAsyncWrapper(_cookieManager.get(), url, name); + CefRefPtr wrapper = callback == nullptr ? NULL : new CefDeleteCookiesCallbackAdapter(callback); - if (CefCurrentlyOn(TID_IO)) + return _cookieManager->DeleteCookies(StringUtils::ToNative(url), StringUtils::ToNative(name), wrapper); + } + + bool CookieManager::SetCookie(String^ url, Cookie^ cookie, ISetCookieCallback^ callback) + { + ThrowIfDisposed(); + + CefRefPtr wrapper = callback == nullptr ? NULL : new CefSetCookieCallbackAdapter(callback); + + CefCookie c; + StringUtils::AssignNativeFromClr(c.name, cookie->Name); + StringUtils::AssignNativeFromClr(c.value, cookie->Value); + StringUtils::AssignNativeFromClr(c.domain, cookie->Domain); + StringUtils::AssignNativeFromClr(c.path, cookie->Path); + c.secure = cookie->Secure; + c.httponly = cookie->HttpOnly; + c.has_expires = cookie->Expires.HasValue; + if (cookie->Expires.HasValue) { - auto source = gcnew TaskCompletionSource(); - CefSharp::Internals::TaskExtensions::TrySetResultAsync(source, cookieInvoker->DeleteCookies()); - return source->Task; + auto expires = cookie->Expires.Value; + c.expires.year = expires.Year; + c.expires.month = expires.Month; + c.expires.day_of_month = expires.Day; + c.expires.hour = expires.Hour; + c.expires.minute = expires.Minute; + c.expires.second = expires.Second; + c.expires.millisecond = expires.Millisecond; } - return Cef::IOThreadTaskFactory->StartNew(gcnew Func(cookieInvoker, &CookieAsyncWrapper::DeleteCookies)); + auto timeSpan = cookie->Creation- DateTime(1970, 1, 1); + c.creation = CefTime(timeSpan.TotalSeconds); + + timeSpan = cookie->LastAccess - DateTime(1970, 1, 1); + c.last_access = CefTime(timeSpan.TotalSeconds); + + return _cookieManager->SetCookie(StringUtils::ToNative(url), c, wrapper); } - Task^ CookieManager::SetCookieAsync(String^ url, Cookie^ cookie) + bool CookieManager::SetStoragePath(String^ path, bool persistSessionCookies, ICompletionCallback^ callback) { ThrowIfDisposed(); - auto cookieInvoker = gcnew CookieAsyncWrapper(_cookieManager.get(), url, cookie->Name, cookie->Value, cookie->Domain, cookie->Path, cookie->Secure, cookie->HttpOnly, cookie->Expires.HasValue, cookie->Expires.HasValue ? cookie->Expires.Value : DateTime()); + CefRefPtr wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback); - if (CefCurrentlyOn(TID_IO)) - { - auto source = gcnew TaskCompletionSource(); - CefSharp::Internals::TaskExtensions::TrySetResultAsync(source, cookieInvoker->SetCookie()); - return source->Task; - } - - return Cef::IOThreadTaskFactory->StartNew(gcnew Func(cookieInvoker, &CookieAsyncWrapper::SetCookie)); + return _cookieManager->SetStoragePath(StringUtils::ToNative(path), persistSessionCookies, wrapper); } - bool CookieManager::SetStoragePath(String^ path, bool persistSessionCookies) + void CookieManager::SetSupportedSchemes(cli::array^ schemes, ICompletionCallback^ callback) { ThrowIfDisposed(); - return _cookieManager->SetStoragePath(StringUtils::ToNative(path), persistSessionCookies, NULL); - } + CefRefPtr wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback); - void CookieManager::SetSupportedSchemes(... cli::array^ schemes) - { - ThrowIfDisposed(); - - _cookieManager->SetSupportedSchemes(StringUtils::ToNative(schemes), NULL); - } - - Task^>^ CookieManager::VisitAllCookiesAsync() - { - ThrowIfDisposed(); - - auto cookieVisitor = gcnew TaskCookieVisitor(); - - auto result = VisitAllCookies(cookieVisitor); - - if (result == false) - { - delete cookieVisitor; - } - - return cookieVisitor->Task; + _cookieManager->SetSupportedSchemes(StringUtils::ToNative(schemes), wrapper); } bool CookieManager::VisitAllCookies(ICookieVisitor^ visitor) @@ -91,22 +92,6 @@ namespace CefSharp return _cookieManager->VisitAllCookies(cookieVisitor); } - Task^>^ CookieManager::VisitUrlCookiesAsync(String^ url, bool includeHttpOnly) - { - ThrowIfDisposed(); - - auto cookieVisitor = gcnew TaskCookieVisitor(); - - auto result = VisitUrlCookies(url, includeHttpOnly, cookieVisitor); - - if (result == false) - { - delete cookieVisitor; - } - - return cookieVisitor->Task; - } - bool CookieManager::VisitUrlCookies(String^ url, bool includeHttpOnly, ICookieVisitor^ visitor) { ThrowIfDisposed(); @@ -116,20 +101,12 @@ namespace CefSharp return _cookieManager->VisitUrlCookies(StringUtils::ToNative(url), includeHttpOnly, cookieVisitor); } - Task^ CookieManager::FlushStoreAsync() + bool CookieManager::FlushStore(ICompletionCallback^ callback) { ThrowIfDisposed(); - auto handler = gcnew TaskCompletionHandler(); + CefRefPtr wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback); - CefRefPtr wrapper = new CefCompletionCallbackAdapter(handler); - - if (_cookieManager->FlushStore(wrapper)) - { - return handler->Task; - } - - //returns false if cookies cannot be accessed. - return CefSharp::Internals::TaskExtensions::FromResult(false); + return _cookieManager->FlushStore(wrapper); } } \ No newline at end of file diff --git a/CefSharp.Core/CookieManager.h b/CefSharp.Core/CookieManager.h index e65d02b8e..fdce6817a 100644 --- a/CefSharp.Core/CookieManager.h +++ b/CefSharp.Core/CookieManager.h @@ -53,15 +53,21 @@ namespace CefSharp this->!CookieManager(); } - virtual Task^ DeleteCookiesAsync(String^ url, String^ name); - virtual Task^ SetCookieAsync(String^ url, Cookie^ cookie); - virtual bool SetStoragePath(String^ path, bool persistSessionSookies); - virtual void SetSupportedSchemes(... cli::array^ schemes); - virtual Task^>^ VisitAllCookiesAsync(); + virtual bool DeleteCookies(String^ url, String^ name, IDeleteCookiesCallback^ callback); + virtual bool SetCookie(String^ url, Cookie^ cookie, ISetCookieCallback^ callback); + virtual bool SetStoragePath(String^ path, bool persistSessionSookies, ICompletionCallback^ callback); + virtual void SetSupportedSchemes(cli::array^ schemes, ICompletionCallback^ callback); virtual bool VisitAllCookies(ICookieVisitor^ visitor); - virtual Task^>^ VisitUrlCookiesAsync(String^ url, bool includeHttpOnly); virtual bool VisitUrlCookies(String^ url, bool includeHttpOnly, ICookieVisitor^ visitor); - virtual Task^ FlushStoreAsync(); + virtual bool FlushStore(ICompletionCallback^ callback); + + virtual property bool IsDisposed + { + bool get() + { + return !_cookieManager.get(); + } + } operator CefRefPtr() { diff --git a/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h b/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h index cb01e0501..dc7d1400d 100644 --- a/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h +++ b/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h @@ -9,28 +9,31 @@ namespace CefSharp { - private class CefCompletionCallbackAdapter : public CefCompletionCallback - { - private: - gcroot _handler; + namespace Internals + { + private class CefCompletionCallbackAdapter : public CefCompletionCallback + { + private: + gcroot _handler; - public: - CefCompletionCallbackAdapter(ICompletionCallback^ handler) - { - _handler = handler; - } + public: + CefCompletionCallbackAdapter(ICompletionCallback^ handler) + { + _handler = handler; + } - ~CefCompletionCallbackAdapter() - { - delete _handler; - _handler = nullptr; - } + ~CefCompletionCallbackAdapter() + { + delete _handler; + _handler = nullptr; + } - void OnComplete() OVERRIDE - { - _handler->OnComplete(); - } + void OnComplete() OVERRIDE + { + _handler->OnComplete(); + } - IMPLEMENT_REFCOUNTING(CefCompletionCallbackAdapter); - }; + IMPLEMENT_REFCOUNTING(CefCompletionCallbackAdapter); + }; + } } \ No newline at end of file diff --git a/CefSharp.Core/Internals/CefDeleteCookiesCallbackAdapter.h b/CefSharp.Core/Internals/CefDeleteCookiesCallbackAdapter.h new file mode 100644 index 000000000..80c07ac13 --- /dev/null +++ b/CefSharp.Core/Internals/CefDeleteCookiesCallbackAdapter.h @@ -0,0 +1,40 @@ +// 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. + +#pragma once + +#include "Stdafx.h" +#include "include/cef_cookie.h" + +namespace CefSharp +{ + namespace Internals + { + private class CefDeleteCookiesCallbackAdapter : public CefDeleteCookiesCallback + { + private: + gcroot _handler; + + public: + CefDeleteCookiesCallbackAdapter(IDeleteCookiesCallback^ handler) + { + _handler = handler; + } + + ~CefDeleteCookiesCallbackAdapter() + { + delete _handler; + _handler = nullptr; + } + + void OnComplete(int numDeleted) OVERRIDE + { + _handler->OnComplete(numDeleted); + } + + IMPLEMENT_REFCOUNTING(CefDeleteCookiesCallbackAdapter); + }; + } +} + diff --git a/CefSharp.Core/Internals/CefSetCookieCallbackAdapter.h b/CefSharp.Core/Internals/CefSetCookieCallbackAdapter.h new file mode 100644 index 000000000..ec8b6020c --- /dev/null +++ b/CefSharp.Core/Internals/CefSetCookieCallbackAdapter.h @@ -0,0 +1,42 @@ +// 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. + +#pragma once + +#include "Stdafx.h" +#include "include/cef_cookie.h" + +namespace CefSharp +{ + namespace Internals + { + private class CefSetCookieCallbackAdapter : public CefSetCookieCallback + { + private: + gcroot _handler; + + public: + CefSetCookieCallbackAdapter(ISetCookieCallback^ handler) + { + _handler = handler; + } + + ~CefSetCookieCallbackAdapter() + { + delete _handler; + _handler = nullptr; + } + + void OnComplete(bool success) OVERRIDE + { + _handler->OnComplete(success); + } + + IMPLEMENT_REFCOUNTING(CefSetCookieCallbackAdapter); + }; + } +} + + + diff --git a/CefSharp/AsyncExtensions.cs b/CefSharp/AsyncExtensions.cs new file mode 100644 index 000000000..3247e88c3 --- /dev/null +++ b/CefSharp/AsyncExtensions.cs @@ -0,0 +1,115 @@ +// Copyright © 2010-2017 The CefSharp Project. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace CefSharp +{ + public static class AsyncExtensions + { + /// + /// Deletes all cookies that matches all the provided parameters asynchronously. If both and are empty, all cookies will be deleted. + /// + /// The cookie URL. If an empty string is provided, any URL will be matched. + /// The name of the cookie. If an empty string is provided, any URL will be matched. + /// A task that represents the delete operation. The value of the TResult parameter contains false if a non-empty invalid URL is specified, or if cookies cannot be accessed; otherwise, true. + //public static Task DeleteCookiesAsync(this ICookieManager cookieManager, string url = null, string name = null) + //{ + // if(cookieManager == null) + // { + // throw new NullReferenceException("cookieManager"); + // } + + // if(cookieManager.IsDisposed) + // { + // throw new ObjectDisposedException("cookieManager"); + // } + + // auto cookieInvoker = gcnew CookieAsyncWrapper(_cookieManager.get(), url, name); + + // if (CefCurrentlyOn(TID_IO)) + // { + // auto source = gcnew TaskCompletionSource(); + // CefSharp::Internals::TaskExtensions::TrySetResultAsync(source, cookieInvoker->DeleteCookies()); + // return source->Task; + // } + + // return Cef::IOThreadTaskFactory->StartNew(gcnew Func(cookieInvoker, &CookieAsyncWrapper::DeleteCookies)); + //} + + //public static Task SetCookieAsync(this ICookieManager cookieManager, string url, Cookie cookie) + //{ + // ThrowIfDisposed(); + + // auto cookieInvoker = gcnew CookieAsyncWrapper(_cookieManager.get(), url, cookie->Name, cookie->Value, cookie->Domain, cookie->Path, cookie->Secure, cookie->HttpOnly, cookie->Expires.HasValue, cookie->Expires.HasValue ? cookie->Expires.Value : DateTime()); + + // if (CefCurrentlyOn(TID_IO)) + // { + // auto source = gcnew TaskCompletionSource(); + // CefSharp::Internals::TaskExtensions::TrySetResultAsync(source, cookieInvoker->SetCookie()); + // return source->Task; + // } + + // return Cef::IOThreadTaskFactory->StartNew(gcnew Func(cookieInvoker, &CookieAsyncWrapper::SetCookie)); + //} + + + /// + /// Visits all cookies. The returned cookies are sorted by longest path, then by earliest creation date. + /// + /// A task that represents the VisitAllCookies operation. The value of the TResult parameter contains a List of cookies. + public static Task> VisitAllCookiesAsync(this ICookieManager cookieManager) + { + var cookieVisitor = new TaskCookieVisitor(); + + if(cookieManager.VisitAllCookies(cookieVisitor)) + { + return cookieVisitor.Task; + } + + return null; + } + + /// + /// Visits a subset of the cookies. The results are filtered by the given url scheme, host, domain and path. + /// If is true, HTTP-only cookies will also be included in the results. The returned cookies + /// are sorted by longest path, then by earliest creation date. + /// + /// The URL to use for filtering a subset of the cookies available. + /// A flag that determines whether HTTP-only cookies will be shown in results. + /// A task that represents the VisitUrlCookies operation. The value of the TResult parameter contains a List of cookies. + public static Task> VisitUrlCookiesAsync(this ICookieManager cookieManager, string url, bool includeHttpOnly) + { + var cookieVisitor = new TaskCookieVisitor(); + + if(cookieManager.VisitUrlCookies(url, includeHttpOnly, cookieVisitor)) + { + return cookieVisitor.Task; + } + + return null; + } + + /// + /// Flush the backing store (if any) to disk. + /// + /// cookieManager instance + /// A task that represents the FlushStore operation. Result indicates if the flush completed successfully. + /// Will return null if the cookikes cannot be accessed. + public static Task FlushStoreAsync(this ICookieManager cookieManager) + { + var handler = new TaskCompletionHandler(); + + if (cookieManager.FlushStore(handler)) + { + return handler.Task; + } + + //returns null if cookies cannot be accessed. + return null; + } + } +} diff --git a/CefSharp/Callback/IDeleteCookiesCallback.cs b/CefSharp/Callback/IDeleteCookiesCallback.cs new file mode 100644 index 000000000..216430345 --- /dev/null +++ b/CefSharp/Callback/IDeleteCookiesCallback.cs @@ -0,0 +1,27 @@ +// 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. + +using System; + +namespace CefSharp +{ + /// + /// Interface to implement to be notified of asynchronous completion via ICookieManager.DeleteCookies(). + /// It will be executed asnychronously on the CEF IO thread after the cookie has been deleted + /// + public interface IDeleteCookiesCallback : IDisposable + { + /// + /// Method that will be called upon completion. + /// + /// will be the number of cookies that were deleted or -1 if unknown. + void OnComplete(int numDeleted); + + /// + /// Gets a value indicating whether the callback has been disposed of. + /// + bool IsDisposed { get; } + } +} + diff --git a/CefSharp/Callback/ISetCookieCallback.cs b/CefSharp/Callback/ISetCookieCallback.cs new file mode 100644 index 000000000..426ae22cd --- /dev/null +++ b/CefSharp/Callback/ISetCookieCallback.cs @@ -0,0 +1,27 @@ +// 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. + +using System; + +namespace CefSharp +{ + /// + /// Interface to implement to be notified of asynchronous completion via ICookieManager.SetCookie(). + /// It will be executed asnychronously on the CEF IO thread after the cookie has been set + /// + public interface ISetCookieCallback : IDisposable + { + /// + /// Method that will be called upon completion. + /// + /// success will be true if the cookie was set successfully. + void OnComplete(bool success); + + /// + /// Gets a value indicating whether the callback has been disposed of. + /// + bool IsDisposed { get; } + } +} + diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index b4da25aee..15a79afd9 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -70,7 +70,10 @@ + + + diff --git a/CefSharp/ICookieManager.cs b/CefSharp/ICookieManager.cs index 288f09994..84cbe48b0 100644 --- a/CefSharp/ICookieManager.cs +++ b/CefSharp/ICookieManager.cs @@ -2,6 +2,7 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -10,15 +11,17 @@ namespace CefSharp /// /// Used for managing cookies. The methods may be called on any thread unless otherwise indicated. /// - public interface ICookieManager + public interface ICookieManager : IDisposable { /// - /// Deletes all cookies that matches all the provided parameters asynchronously. If both and are empty, all cookies will be deleted. + /// Deletes all cookies that matches all the provided parameters. If both and are empty, all cookies will be deleted. + /// Must be run on the CEF IO Thread /// /// The cookie URL. If an empty string is provided, any URL will be matched. /// The name of the cookie. If an empty string is provided, any URL will be matched. - /// A task that represents the delete operation. The value of the TResult parameter contains false if a non-empty invalid URL is specified, or if cookies cannot be accessed; otherwise, true. - Task DeleteCookiesAsync(string url, string name); + /// If non-NULL it will be executed asnychronously on the CEF IO thread after the cookies have been deleted. + /// Returns false if a non-empty invalid URL is specified, or if cookies cannot be accessed; otherwise, true. + bool DeleteCookies(string url, string name, IDeleteCookiesCallback callback = null); /// /// Sets a cookie given a valid URL and explicit user-provided cookie attributes. This function expects each attribute to be well-formed. It will check for disallowed @@ -27,8 +30,9 @@ namespace CefSharp /// /// The cookie URL /// The cookie - /// A task that represents the cookie set operation. The value of the TResult parameter contains false if the cookie cannot be set (e.g. if illegal charecters such as ';' are used); otherwise true. - Task SetCookieAsync(string url, Cookie cookie); + /// If non-NULL it will be executed asnychronously on the CEF IO thread after the cookie has been set. + /// returns false if the cookie cannot be set (e.g. if illegal charecters such as ';' are used); otherwise true. + bool SetCookie(string url, Cookie cookie, ISetCookieCallback callback = null); /// /// Sets the directory path that will be used for storing cookie data. If is empty data will be stored in @@ -38,20 +42,17 @@ namespace CefSharp /// /// The file path to write cookies to. /// A flag that determines whether session cookies will be persisted or not. - /// false if a non-empty invalid URL is specified; otherwise, true. - bool SetStoragePath(string path, bool persistSessionCookies); + /// If non-NULL it will be executed asnychronously on the CEF IO thread after the + /// manager's storage has been initialized + /// Returns false if cookies cannot be accessed + bool SetStoragePath(string path, bool persistSessionCookies, ICompletionCallback callback = null); /// /// Set the schemes supported by this manager. By default only "http" and "https" schemes are supported. Must be called before any cookies are accessed. /// /// The list of supported schemes. - void SetSupportedSchemes(params string[] schemes); - - /// - /// Visits all cookies. The returned cookies are sorted by longest path, then by earliest creation date. - /// - /// A task that represents the VisitAllCookies operation. The value of the TResult parameter contains a List of cookies. - Task> VisitAllCookiesAsync(); + /// If non-NULL it will be executed asnychronously on the CEF IO thread after the change has been applied. + void SetSupportedSchemes(string[] schemes, ICompletionCallback callback = null); /// /// Visits all cookies using the provided Cookie Visitor. The returned cookies are sorted by longest path, then by earliest creation date. @@ -60,16 +61,6 @@ namespace CefSharp /// Returns false if cookies cannot be accessed; otherwise, true. bool VisitAllCookies(ICookieVisitor visitor); - /// - /// Visits a subset of the cookies. The results are filtered by the given url scheme, host, domain and path. - /// If is true, HTTP-only cookies will also be included in the results. The returned cookies - /// are sorted by longest path, then by earliest creation date. - /// - /// The URL to use for filtering a subset of the cookies available. - /// A flag that determines whether HTTP-only cookies will be shown in results. - /// A task that represents the VisitUrlCookies operation. The value of the TResult parameter contains a List of cookies. - Task> VisitUrlCookiesAsync(string url, bool includeHttpOnly); - /// /// Visits a subset of the cookies. The results are filtered by the given url scheme, host, domain and path. /// If is true, HTTP-only cookies will also be included in the results. The returned cookies @@ -84,7 +75,13 @@ namespace CefSharp /// /// Flush the backing store (if any) to disk /// - /// A task that represents the Flush operation. The value of the TResult parameter contains false if cookies cannot be accessed; otherwise, true. - Task FlushStoreAsync(); + /// If non-NULL it willbe executed asnychronously on the CEF IO thread after the flush is complete. + /// Returns false if cookies cannot be accessed. + bool FlushStore(ICompletionCallback callback); + + /// + /// Returns true if disposed + /// + bool IsDisposed { get; } } } diff --git a/CefSharp/TaskCookieVisitor.cs b/CefSharp/TaskCookieVisitor.cs index 683f8a82c..3ae0bc708 100644 --- a/CefSharp/TaskCookieVisitor.cs +++ b/CefSharp/TaskCookieVisitor.cs @@ -15,7 +15,7 @@ namespace CefSharp /// public class TaskCookieVisitor : ICookieVisitor { - private TaskCompletionSource> taskCompletionSource; + private readonly TaskCompletionSource> taskCompletionSource; private List list; /// @@ -49,7 +49,6 @@ namespace CefSharp } list = null; - taskCompletionSource = null; } ///