Working with Plugins in DotNetBrowser 1.x

Опубликовано: 14 Декабрь 2017
на канале: Embedded Browsers
991
9

Today we are talking about working with plugins in DotNetBrowser.
Get a free 30-days DotNetBrowser trial licence: https://www.teamdev.com/dotnetbrowser...

Download DotNetBrowser form the Visual Studio Gallery: https://goo.gl/tn9kBX

About DotNetBrowser:

DotNetBrowser allows embedding a Chromium-based browser to your .NET app to display and process HTML5, CSS3, JavaScript, Flash etc.

For more ideas on using an advanced browser-component in your .NET application, please see examples on DotNetBrowser support site: https://goo.gl/hxrJhs

Previous tutorials:

   • How to get DotNetBrowser Evaluation L...  

Transcript:

00:08 We need to create a WPF solution, reference the DotNetBrowser library using NuGet and add the license file. You can find detailed instructions in the previous tutorials.

00:17 MainWindow markup.

00:21 Add the ‘DotNetBrowser.WPF’ XML-namespace.

00:23 Create two column definitions in the root grid.

00:41 Add a stack panel with vertical orientation to the root grid and place it into the left column.

00:53 Add a stack panel with horizontal orientation to the outer stack panel.

01:00 Add a checkbox named ‘ViewPDF’ to the inner stack panel. This check box will be used for changing the state of the PDF Viewer plugin.

01:19 Add a button named ‘Refresh’ to the inner stack panel and create a ‘Click’ event handler.

01:39 Add a list box named ‘PluginsListBox’ to the outer stack panel. This list box will be used for displaying the list of the available plugins.

01:57 Finally add WPFBrowserView, set its name and place it into the right column.

02:15 Also, add a ‘FinishLoadingFrameEvent’ handler.

02:29 Implementing the behavior.

02:34 Create the ‘CustomPluginFilter’ class, inherited from the ‘PluginFilter’ interface and generate the method stubs.

02:52 Add the bool field named ‘allowPdf’ and fill it from the constructor.

03:00 Go to the ‘IsPluginAllowed’ method. In this method we need to enable or disable the plugins related to the PDF.

03:10 Check if the ‘pluginInfo.Name’ property contains the ‘pdf’ string. If yes, return the value of the ‘allowPdf’ property.
Otherwise, allow the plugin to launch by returning the ‘true’ value.

03:25 Inside of the ‘MainWindow’ constructor after the InitializeComponent method call, set the Browser.PluginManager.PluginFilter property value to the new instance of the CustomPluginFilter class. Set the ‘allowPdf’ argument to ‘true’ by default.

03:44 Now let’s load a sample PDF file from the solution. This file should be copied into the output directory.

03:50 The path to the PDF file is the combination of the AppDomains base directory and the name of the file.

04:15 Call the BrowserView.Browser.LoadURL method and pass the generated path as its argument.

04:29 Go to the Refresh button click handler.
Here we need to update the plugin filter based on the checkbox state.

04:56 Then call the ‘BrowserView.Browser.Reload’ method.

05:00 The last step is obtaining the list of plugins and displaying it in the ListBox.

05:07 Go to the ‘FinishLoadingFrameEvent’ handler. Check if the loaded frame is the main frame. Then open the Dispatcher.BeginInvoke instruction.

05:23 Set the content of the PluginsListPox to the plugin list.

05:30 We can get the list of the plugins using the selection from the ‘Browser.PluginManager.GetPluginsInfo’ method which returns the list of the ‘PluginInfo’ class instances.

05:58 Build and launch.

06:00 You can see that by default the PDF file is displayed. Also, the list of the available plugins is in the left side of the window.
If we uncheck the checkbox, DotNetBrowser does not display the PDF file. Instead of this, DotNetBrowser suggests downloading it.

#WorkingWithPlugins
#DotNetBrowser
#EmbeddedBrowsers