Get plugins using a task wrapper around CefWebPluginInfoVisitor

This commit is contained in:
amaitland
2015-04-08 17:21:44 +10:00
parent 0f522a6f01
commit 11cd688847
6 changed files with 89 additions and 0 deletions
+12
View File
@@ -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();
}
/// <summary>Visits all plugins using the provided Plugin Visitor.</summary>
/// <param name="visitor">A user-provided Plugin Visitor implementation.</param>
static Task<List<Plugin>^>^ GetPlugins()
{
CefRefPtr<PluginVisitor> visitor = new PluginVisitor();
CefVisitWebPluginInfo(visitor);
return visitor->GetTask();
}
/// <summary>
/// Add a plugin path (directory + file). This change may not take affect until after RefreshWebPlugins() is called.
/// </summary>
+1
View File
@@ -250,6 +250,7 @@
<ClInclude Include="Internals\CefSharpApp.h" />
<ClInclude Include="Internals\CefRequestWrapper.h" />
<ClInclude Include="Internals\MCefRefPtr.h" />
<ClInclude Include="Internals\PluginVisitor.h" />
<ClInclude Include="Internals\RenderClientAdapter.h" />
<ClInclude Include="Internals\StringVisitor.h" />
<ClInclude Include="Internals\TypeConversion.h" />
@@ -136,6 +136,9 @@
<ClInclude Include="SchemeHandlerFactoryWrapper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Internals\PluginVisitor.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
+58
View File
@@ -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<List<Plugin>^>^> _taskCompletionSource;
gcroot<List<Plugin>^> _list;
public:
PluginVisitor()
{
_list = gcnew List<Plugin>();
_taskCompletionSource = gcnew TaskCompletionSource<List<Plugin>^>();
}
~PluginVisitor()
{
_taskCompletionSource = nullptr;
}
Task<List<Plugin>^>^ GetTask()
{
return _taskCompletionSource->Task;
}
virtual bool Visit(CefRefPtr<CefWebPluginInfo> 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);
};
}
+1
View File
@@ -127,6 +127,7 @@
<Compile Include="Internals\BrowserProcessServiceHost.cs" />
<Compile Include="Internals\WCFExtensions.cs" />
<Compile Include="KeyType.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="ResourceHandler.cs" />
<Compile Include="ResponseAction.cs" />
<Compile Include="ScreenInfo.cs" />
+14
View File
@@ -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; }
}
}