mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
Get plugins using a task wrapper around CefWebPluginInfoVisitor
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user