CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

Swapable Plugins?

Open Beyondem opened this issue 12 years ago • 19 comments

I've been digging through this trying to see if this is possible,

What I am looking to do is have customizable plugins. So, in my Splash screen of my browser I'll have check boxes to enable / disable Java/Flash/Silverlight, etc. Also, drop down boxes to choose which version of Java I want. So, I can have a drop down of Java 7, 6.4, 6.3, 6.2, etc. Is something like that possible? Where I can specify multiple different versions of java and load a specific one when launched?

Can anybody point me in the right direction?

Thanks!

Beyondem avatar Oct 29 '14 21:10 Beyondem

This question might be better asked on the Cef forum, we currently only have fairly limited plugin support (and there's a couple of glitches with what we do have).

Another option would be to dig through the cefclient sample application source code and see if there's anything plugin specific in there that might give you some clues.

Contributions to expand our plugin support would be most welcome :+1:

amaitland avatar Oct 30 '14 01:10 amaitland

For reference API's located in cef_web_plugin.h maybe useful

https://bitbucket.org/chromiumembedded/branches-2062-cef3/src/a073e92426b3967f1fc2f1d3fd7711d809eeb03a/include/cef_web_plugin.h?at=master

amaitland avatar Jan 16 '15 13:01 amaitland

We plugin methods have been implement see https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Core/Cef.h#L455

amaitland avatar Mar 18 '15 11:03 amaitland

I have same issue with @Beyondem, How to use CefAddWebPluginPath () work for CefSharp.WinForm? My plan is to get it work for Cef then package and apply to CefSharp. but I can not make it success.

After automate build and create project for VS (whole thing with cef.sln) I tried in cefclient. after CefInitialize(main_args, settings, app.get()); CefRemoveWebPluginPath(CefString("C:\JRE\jre8u31x86\bin\plugin2\npjp2.dll")); CefAddWebPluginDirectory(CefString("C:\JRE\jre7u71x86\bin")); CefAddWebPluginPath(CefString("C:\JRE\jre7u71x86\bin\plugin2\npjp2.dll")); CefRefreshWebPlugins(); It does not have any effect - Browser still load the Java that set in regedit (C:\JRE\jre8u31x86\bin\plugin2\npjp2.dll).

Anyone can guide how use CefAddWebPluginPath again that would be great appreciated.

Thanks

shaunsphere avatar Mar 20 '15 16:03 shaunsphere

@amaitland : can you re open this issue?

CefRemoveWebPluginPath() --> seems NOT work / No effect

Using CefAddWebPluginPath( Path); --> Can add a specific plugin but when a new java added it might be conflict with the one (pre-set in Registry) --> Crash

Link: https://code.google.com/p/chromiumembedded/issues/detail?id=273 provides 2 patches to prevent loading Registry but I can not apply for CEF (any one know how?). I tried 2 patches with Chromium it worked.

Anyone can guide how use CefAddWebPluginPath again that would be great appreciated.

Thanks

shaunsphere avatar Mar 23 '15 16:03 shaunsphere

Have you seen CEF 645?

It suggests you call Cef.RefreshWebPlugins() after Cef.AddWebPluginPath.

Additionally, the way to prevent plugins from loading appears to be via OnBeforePluginLoad as listed in CEF 645.

CEF also apparently has these APIs that might assist if OnBeforePluginLoad combined with RefreshWebPlugins isn't enough:

  • UnregisterInternalWebPlugin
  • CefForceWebPluginShutdown

I would note that CefForceWebPluginShutdown isn't currently exposed from CefSharp atm.

Bill

rassilon avatar Mar 23 '15 20:03 rassilon

@Bill: Yes I did tried those unregister.....shutdown...refresh. It loads new plugin but still keep the preset plugin. Do i need to apply 2 patches (cef_web_plugin.h.diff , web_plugin_impl.cc.diff) in issue CEF 645?

 CefUnregisterInternalWebPlugin(CefString("C:\\JRE\\jre8u31x86\\bin\\plugin2\\npjp2.dll"));
  CefForceWebPluginShutdown(CefString("C:\\JRE\\jre8u31x86\\bin\\plugin2\\npjp2.dll"));
  CefRemoveWebPluginPath(CefString("C:\\JRE\\jre8u31x86\\bin\\plugin2\\npjp2.dll")); 

 CefAddWebPluginPath(CefString("C:\\JRE\\jre7u71x86\\bin\\plugin2\\npjp2.dll"));
  CefRefreshWebPlugins();

http://tests/plugin_info --> Show both Java version 7 and 8 loaded http://javatester.org/version.html --> Crash whatismybrowser.com --> Show Java Version 7 only.

Look like these fours: OnBeforePluginLoad / CefUnregisterInternalWebPlugin/ CefForceWebPluginShutdown / CefRemoveWebPluginPath not working or I don't know how to make them work?

I tried modified OnBeforePluginLoad in cef_request_handler.h and request_handler_cpptoc.cc to force it return true--> still no effect.

I am using automate CEF build for few recent brands, VS2013U4+ for cefclient.

shaunsphere avatar Mar 25 '15 20:03 shaunsphere

In the bit you pasted you do realize that you didn't escape your backslashes properly?

Additionally, I don't know what the plugin paths look like. I think CEF has a plugin visitor class in C++ that will ensure you know what path to supply for the Java plugin you desire to forcefully shutdown.

I don't think you need the patches from CEF 645.

Don't forget you need to call CefUnregisterInternalWebPlugin after calling CefRefreshWebPlugins since the refresh can refind the Java you're trying to ignore.

I would have imagined something like this MIGHT do the trick: (presuming the supplied path strings are good)

  • CefForceWebPluginShutdown()
  • CefAddWebPluginPath()
  • CefRefreshWebPlugins()
  • CefUnregisterInternalWebPlugin()

Usual disclaimer: The above comments are just a wild guess about what might work, Bill

rassilon avatar Mar 25 '15 20:03 rassilon

I added ForceWebPluginShutdown see https://github.com/cefsharp/CefSharp/commit/189c6c07fd6d4f2f53c6841971af9147a4694144

@shaunsphere I'd probably suggest posting on http://magpcss.org/ceforum/ for some clarification on how to use the API.

amaitland avatar Mar 25 '15 21:03 amaitland

Careful with that @bill @shaunsphere. You meant @rassilon. :wink:

Bill avatar Mar 26 '15 03:03 Bill

@Bill: I had double backslash, but one was removed when pasting here. A bug if I use:CefUnregisterInternalWebPlugin() --> Popup says: cefclient.exe has triggered a breakpoint. (Break / Conti..) Click Continue--> Run OK but still load Java 8, :-( . Thanks.

@amaitland: I found almost same post in magpcss and google cefsharp forums but still no specific solution, thanks. https://groups.google.com/forum/?nomobile=true#!searchin/cefsharp/java/cefsharp/Wkhyz-fKYP0/obQIIF4FJc4J

http://magpcss.org/ceforum/viewtopic.php?f=6&t=11150&p=18945&hilit=+patrick+jre#p18945

shaunsphere avatar Mar 26 '15 18:03 shaunsphere

@shaunsphere I think you need to read https://github.com/cefsharp/CefSharp/issues/538#issuecomment-86322751 closely.

I found almost same post in magpcss and google cefsharp forums but still no specific solution, thanks.

There isn't much more that we can do. You'll have to followup with CEF

amaitland avatar Mar 26 '15 22:03 amaitland

I made it work for cefclient, how to apply to CefSharp.Winform?

shaunsphere avatar Apr 02 '15 13:04 shaunsphere

What code changes did you make to cefclient?

amaitland avatar Apr 02 '15 21:04 amaitland

You need to call CefAddWebPluginDirectory and related methods after the context has been initialized. For example, from CefBrowserProcessHandler::OnContextInitialized(). Also, you may have better results specifying the full plugin path via CefAddWebPluginPath.

So that looks like the missing puzzle piece, with the follow up http://www.magpcss.org/ceforum/viewtopic.php?f=10&t=10736#p17080

CefSharp doesn't implement CefBrowserProcessHandler as yet.

http://magpcss.org/ceforum/apidocs3/projects/(default)/CefBrowserProcessHandler.html#OnContextInitialized()

Strictly speaking it might not be required to implement CefBrowserProcessHandler, just make sure the plugin calls happen after it's called.

amaitland avatar Apr 03 '15 02:04 amaitland

@amaitland: For Cefclient to swap Java versions I changed file \src\content\common\plugin_list_win.cc 2 Keys are changed to my setup for Registry:

const base::char16 kRegistryApps[] = L"Software\\\Microsoft\\\Windows\\\CurrentVersion\\NewPaths";
const base::char16 kRegistryJava[] = L"Software\\\JavaSoft\\\NewJRE";

and modify:

bool PluginList::ShouldLoadPluginUsingPluginList(
    const WebPluginInfo& info,
    std::vector<WebPluginInfo>* plugins) \{
 Code here is modified -> basically disable the loop to avoid update new version of Java
\}

And in file: \src\cef\tests\cefclient\cefclient_win.cc --> Only 3 lines added after CefInitialize(); No need to call remove/shutdown/unregister...

  CefAddWebPluginDirectory(CefString("C:\\JRE\\jre7u71x86\\bin")); \\ "C:\\JRE\\jre8\\bin" -->  load Java 8 as expected.
  CefAddWebPluginPath(CefString("C:\\JRE\\jre7u71x86\\bin\\plugin2\\npjp2.dll"));
  CefRefreshWebPlugins();

How to apply the above to CefSharp.Winform? Replace (copy) set of DLLs to Cefsharp (same version) --> crash. Does repackage work? How?

Thanks

shaunsphere avatar Apr 06 '15 13:04 shaunsphere

Please markup your code, very hard to read.

If you need to build a custom version of cef then your somewhat on your own there.

amaitland avatar Apr 06 '15 23:04 amaitland

Have implemented OnContextInitialized feel free to see if that makes any difference calling your plugin methods using the delegate. See code for example. PR #929

amaitland avatar Apr 07 '15 12:04 amaitland

Closing due to lack of feedback.

For reference you can disable plugin discovery entirely and load plugins manually. See example of command line arg. https://github.com/cefsharp/CefSharp/commit/59ded0957d7eb383ad8c4593c37a4604a2aaa609

Example of adding a plugin

Cef.OnContextInitialized = delegate
{
    Cef.AddWebPluginPath(@"C:\Program Files\Microsoft Silverlight\5.1.31211.0\npctrl.dll");
    Cef.RefreshWebPlugins();
};

Requires version 39.0.1 or greater

amaitland avatar May 12 '15 23:05 amaitland