From 11cd6888477e206f66b8dbf38b1db3d632ba5dfd Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 8 Apr 2015 17:21:44 +1000 Subject: [PATCH] Get plugins using a task wrapper around CefWebPluginInfoVisitor --- CefSharp.Core/Cef.h | 12 +++++ CefSharp.Core/CefSharp.Core.vcxproj | 1 + CefSharp.Core/CefSharp.Core.vcxproj.filters | 3 ++ CefSharp.Core/Internals/PluginVisitor.h | 58 +++++++++++++++++++++ CefSharp/CefSharp.csproj | 1 + CefSharp/Plugin.cs | 14 +++++ 6 files changed, 89 insertions(+) create mode 100644 CefSharp.Core/Internals/PluginVisitor.h create mode 100644 CefSharp/Plugin.cs diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index 12d3b68de..7485ca25f 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -14,6 +14,7 @@ #include "Internals/CookieVisitor.h" #include "Internals/CompletionHandler.h" #include "Internals/StringUtils.h" +#include "Internals/PluginVisitor.h" #include "ManagedCefBrowserAdapter.h" #include "CefSettings.h" #include "SchemeHandlerWrapper.h" @@ -454,6 +455,17 @@ namespace CefSharp return CefClearSchemeHandlerFactories(); } + /// Visits all plugins using the provided Plugin Visitor. + /// A user-provided Plugin Visitor implementation. + static Task^>^ GetPlugins() + { + CefRefPtr visitor = new PluginVisitor(); + + CefVisitWebPluginInfo(visitor); + + return visitor->GetTask(); + } + /// /// Add a plugin path (directory + file). This change may not take affect until after RefreshWebPlugins() is called. /// diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index d0c9ab88e..b055d4f37 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -250,6 +250,7 @@ + diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index a172e2c67..8bba5ac71 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -136,6 +136,9 @@ Header Files + + Header Files + diff --git a/CefSharp.Core/Internals/PluginVisitor.h b/CefSharp.Core/Internals/PluginVisitor.h new file mode 100644 index 000000000..a63263c60 --- /dev/null +++ b/CefSharp.Core/Internals/PluginVisitor.h @@ -0,0 +1,58 @@ +// Copyright © 2010-2014 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 + +using namespace System::Threading::Tasks; +using namespace CefSharp; + +#include "Stdafx.h" +#include "include/cef_web_plugin.h" + +namespace CefSharp +{ + private class PluginVisitor : public CefWebPluginInfoVisitor + { + private: + gcroot^>^> _taskCompletionSource; + gcroot^> _list; + + public: + PluginVisitor() + { + _list = gcnew List(); + _taskCompletionSource = gcnew TaskCompletionSource^>(); + } + + ~PluginVisitor() + { + _taskCompletionSource = nullptr; + } + + Task^>^ GetTask() + { + return _taskCompletionSource->Task; + } + + virtual bool Visit(CefRefPtr info, int count, int total) OVERRIDE + { + Plugin plugin; + plugin.Name = StringUtils::ToClr(info->GetName()); + plugin.Description = StringUtils::ToClr(info->GetDescription()); + plugin.Path = StringUtils::ToClr(info->GetPath()); + plugin.Version = StringUtils::ToClr(info->GetVersion()); + + _list->Add(plugin); + + if(count == (total - 1)) + { + _taskCompletionSource->SetResult(_list); + } + + return true; + } + + IMPLEMENT_REFCOUNTING(PluginVisitor); + }; +} \ No newline at end of file diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 24eb87832..87c061e96 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -127,6 +127,7 @@ + diff --git a/CefSharp/Plugin.cs b/CefSharp/Plugin.cs new file mode 100644 index 000000000..f7426ae2f --- /dev/null +++ b/CefSharp/Plugin.cs @@ -0,0 +1,14 @@ +// Copyright © 2010-2014 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 struct Plugin + { + public string Name { get; set; } + public string Description { get; set; } + public string Path { get; set; } + public string Version { get; set; } + } +}