How to enable/allow java to run in a CefSharp application - c#

We are making a web browser to experiment with Oracle's ADT/Forms technology. All it needs to do is go to the web address and run the Java applet.
I'm using (trying to, at least) CefSharp3 (fresh clone from https://github.com/cefsharp/CefSharp).
I created a WPF project for this, got it working (I can navigate to Google, here, Oracle, etc) however, when I navigate to our Java applet I seem to get nothing but a blank screen.
I have set browser-attributes
"JavaDisabled"
"PluginsDisabled"
"WebSecurityDisabled"
(grasping at straws there!) appropriately and still I only see a blank screen.
I'm wondering if maybe the app does not have permissions to the JRE? Maybe the JRE needs to be included in the project?
This is the result of the Debug file (after a fresh run that ONLY goes to the Java applet)
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:ERROR:renderer_main.cc(226)] Running without renderer sandbox
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
The Java applet works no problem in Firefox, Chrome, IE, and Chromium (with WinForms). It could just be that WPF and Java don't jive.
Here's some code! -- it's not much, but it doesn't take much to use this framework -- I AM quite impressed.
public partial class MainWindow : Window
{
public MainWindow() {
InitializeCef();
InitializeComponent();
SetBrowserSettings();
((IWebBrowser)webBrowser).Load("URL_To_Java_Applet");
}
private void InitializeCef() {
var settings = new CefSharp.CefSettings()
{
PackLoadingDisabled = true
};
settings.IgnoreCertificateErrors = true; // could be preventing the JRE?
Cef.Initialize(settings);
}
private void SetBrowserSettings() {
BrowserSettings settings = new BrowserSettings();
settings.JavaDisabled = false;
settings.PluginsDisabled = false;
settings.WebSecurityDisabled = true; // desperate attempt to allow JRE to run!
webBrowser.BrowserSettings = settings;
}
}

Looks like you're right...
It could just be that WPF and Java don't jive.
Try with WinForms, not WPF where prospects doesn't look good (note WPF run in OSR mode)
See this CEF forum thread
update: I tried with http://java.com/en/download/installed8.jsp and Win32 builds of CefSharp.Winforms|Wpf.Example - they both work as expected with JRE 7.67 x86. Of course the x64 Examples didn't work as I don't have a x64 JRE on my PC.

Related

UIAutomation throws AccessViolationException on Windows 11

The issue:
We have an application written in C# that uses UIAutomation to get the current text (either selected or the word behind the carret) in other applications (Word, OpenOffice, Notepad, etc.).
All is working great on Windows 10, even up to 21H2, last update check done today.
But we had several clients informing us that the application is closing abruptly on Windows 11.
After some debugging I've seen some System.AccessViolationException thrown when trying to use the TextPatternRange.GetText() method:
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
What we've tried so far:
Setting uiaccess=true in manifest and signing the app : as mentionned here https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/350ceab8-436b-4ef1-8512-3fee4b470c0a/problem-with-manifest-and-uiaccess-set-to-true?forum=windowsgeneraldevelopmentissues => no changes (app is in C:\Program Files\
In addition to the above, I did try to set the level to "requireAdministrator" in the manifest, no changes either
As I've seen that it may come from a bug in Windows 11 (https://forum.emclient.com/t/emclient-9-0-1317-0-up-to-9-0-1361-0-password-correction-crashes-the-app/79904), I tried to install the 22H2 Preview release, still no changes.
Reproductible example
In order to be able to isolate the issue (and check it was not something else in our app that was causing the exception) I quickly made the following test (based on : How to get selected text of currently focused window? validated answer)
private void btnRefresh_Click(object sender, RoutedEventArgs e)
{
var p = Process.GetProcessesByName("notepad").FirstOrDefault();
var root = AutomationElement.FromHandle(p.MainWindowHandle);
var documentControl = new
PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Document);
var textPatternAvailable = new PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, true);
var findControl = new AndCondition(documentControl, textPatternAvailable);
var targetDocument = root.FindFirst(TreeScope.Descendants, findControl);
var textPattern = targetDocument.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
string text = "";
foreach (var selection in textPattern.GetSelection())
{
text += selection.GetText(255);
Console.WriteLine($"Selection: \"{selection.GetText(255)}\"");
}
lblFocusedProcess.Content = p.ProcessName;
lblSelectedText.Content = text;
}
When pressing a button, this method is called and the results displayed in labels.
The method uses UIAutomation to get the notepad process and extract the selected text.
This works well in Windows 10 with latest update, crashes immediately on Windows 11 with the AccessViolationException.
On Windows 10 it works even without the uiaccess=true setting in the manifest.
Questions/Next steps
Do anyone know/has a clue about what can cause this?
Is Windows 11 way more regarding towards UIAutomation?
On my side I'll probably open an issue by Microsoft.
And one track we might follow is getting an EV and sign the app itself and the installer as it'll also enhance the installation process, removing the big red warnings. But as this is an app distributed for free we had not done it as it was working without it.
I'll also continue testing with the reproductible code and update this question should anything new appear.
I posted the same question on MSDN forums and got this answer:
https://learn.microsoft.com/en-us/answers/questions/915789/uiautomation-throws-accessviolationexception-on-wi.html
Using IUIautomation instead of System.Windows.Automation works on Windows 11.
So I'm marking this as solved but if anyone has another idea or knows what happens you're welcome to comment!

How to enable LightningProviders for GPIO?

I am trying to access the GPIO on my custom SBC using Windows 10 IoT Core. I have discovered that I must use LightningProviders to accomplish this . So I tried to follow this guide to use lightning providers properly.
I used very simple code:
if (LightningProvider.IsLightningEnabled)
{
LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
}
GpioStatus = "Initializing...";
var gpio = GpioController.GetDefault();
if (gpio == null)
{
GpioStatus = "There is no GPIO controller on this device.";
}
else
{
gpio.OpenPin(1).Write(GpioPinValue.High);
GpioStatus = gpio.OpenPin(1).Read().ToString();
}
Where GpioStatus is output text on a UI.
I discovered that if I run the LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); line outside of the enabled check, it picks up the GPIO controller and lets me detect how many pins I have and read them (All low). However I can't change the DriveMode or write to the pins without error. The error I get just says to Make sure the LightningProviders are enabled.
This brings me back to the guide I linked at the start. It suggests to enable DMAP drivers using the Device Portal for W10IoT or DMAPUtil.exe. I have tried both. In the Device Portal the area where it should be is just blank. And in the command line trying to use the DMAPUtil.exe only returns that dmaputil.exe is not available on this system.
Therefore I am asking if there is any other way to enable the LightningProviders or if there a way to know if they are incompatible with my board?
Thanks!
UPDATE
Also tried using the devcon.exe commands in the W10IoT Command line.
I am able to locate the Direct memory access controller but when i do devcon.exe enable *PNP0200 it says it is enabled but remains disabled when checked with devcon.exe status *PNP0200
Please confirm if you have added the IOT_DMAP_DRIVER feature in your OEMInput.xml, this feature will add the DMAP driver in the image. If IOT_DMAP_DRIVER is removed from the OEMInput.xml, the Default Driver Controller will be blank in device protal, and dmaputil will be not available on Windows IoT Core. Please see the IoT Core feature list.
Update:
You can download the source of Lighting Provider, and then deploy and debug in your custom image.

Unable to handle authentication pop up

I am using C# , Selenium , AutoIt and Google Chrome.
I can launch the browser, and can see the authentication pop up.
Pop up window disappears when below code is executed and after that the browser stays there forever.
autoItX3 autoIt = new AutoItX3();
Driver.Instance.Manage().Window.Maximize();
Driver.Instance.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(2);
try
{
Driver.Instance.Navigate().GoToUrl(Driver.BaseAddress);
}
catch
{
return;
}
autoIt.WinWait("Authentication Required");
autoIt.WinActivate("Authentication Required");
autoIt.Send("admin");
autoIt.Send("{TAB}");
autoIt.Send("pass");
autoIt.Send("{ENTER}");
Driver.Instance.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(-1);
You are trying to automate a child window.
Autoit doesn't see child windows untill told to.
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
Allows the window search routines to search child windows as well as
top-level windows. 0 = (default) Only search top-level windows 1 =
Search top-level and child windows
hard to make comment without knowing the internals of the authentication implementation on the server. One thing is sure - it is a bad idea from security view because parameters appended to the URL are not secure.
like : http://myURL.com/index.jsp/j_security_check?j_username=username&j_password=password
or
"http://username:password#www.example.com/")
this is what worked for me according to our internal authentication :
https://myURL.com/login/Login.aspx?usestandardlogin=1
so its => "http:YouURL.com" + "?" + "usestandardlogin=1"
now I am not seeing any pop up , it just re-direct me on login.

WPF Printing (XpsDocumentWriter) working in debug but not in deployment

Hopefully some of the experienced WPF developers have come across this issue before.
BACKGROUND: This information is probably not necessary to helping fixing the problem, but in case it is relevant.
My solution consists of three projects. A front-end GUI, a business logic service, and a printer service. The three projects have IPC via named pipes. The business logic hands the printing logic a label type and a pallet id.
The Problem: The printing logic then creates the label and prints it (by adding it to the print queue of a printer) As the title suggests this all works fine when I am debugging in visual studio. However when I deploy / install the services on my developer pc it is not working.
Update: It is not throwing an exception but I am only logging "About to send doc to printer" and not the line "Sent doc to printer" So it is hanging on the dw1.Write(fixedDoc); line
More Information: I am using .Net 4.0 in the printing project / visual studio 2013
public void printLabel(string labelType, string _palletID = null)
{
try
{
ILabelTemplate Label = createLabel(labelType, _palletID);
PrintDialog pd = new PrintDialog();
FixedDocument fixedDoc = new FixedDocument();
PageContent pageContent = new PageContent();
FixedPage fixedPage = getFixedPage();
fixedDoc.DocumentPaginator.PageSize = new System.Windows.Size(fixedPage.Width, fixedPage.Height);
IXamlTemplate vm = CreateViewModel(Label);
ILabelPrintDocument template = CreateTemplate(Label);
template.dockPanel.DataContext = vm;
template.dockPanel.Height = fixedPage.Height;
template.dockPanel.Width = fixedPage.Width;
template.dockPanel.UpdateLayout();
fixedPage.Children.Add(template.dockPanel);
((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
XpsDocumentWriter dw1 = PrintQueue.CreateXpsDocumentWriter(new System.Printing.PrintQueue(new System.Printing.PrintServer(), Label.PrinterName));
Library.WriteErrorLog("About to send doc to printer");
dw1.Write(fixedDoc);
Library.WriteErrorLog("Sent doc to printer");
}
catch (Exception ex)
{
Library.WriteErrorLog(ex);
}
SOLVED ... kind of
After several hours of trying different things and reading about this, I found that it was due to my application running as me when I'm debugging but as a LOCAL SYSTEM when I have it deployed. And a local system service does not have access to network resources such as printers. Despite learning this, I then started down the path of how to make a C# service print. Well after seeing many posts (too late in the game to be very helpful)
Like this and also this one I have learned that I was going down the wrong path.
The moral of the story is, if you're reading this post you're probably not at the level of "writing your own printing DLL using the Win32 API (in C/C++ for instance), then use it from your service with P/Invoke"
The solution that did work for me was instead of running this project as a service which was started via my GUI. I have instead turned it into a process which is still started and stopped via my GUI.
The code in question is
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\yourAppNameGoesHere.exe"))
{
Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\yourAppNameGoesHere.exe");
}
then when the GUI is closed I run the code
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\yourAppNameGoesHere.exe"))
{
Process[] myapps = Process.GetProcesses("yourAppNameGoesHere.exe");
foreach (Process _p in myapps)
{
_p.Kill();
}
}

Calling C# BHO methods from Javascript In Internet Explorer 10 (Release preview)

I'm trying to develop a BHO for the release preview of IE 10. The BHO needs to be able to allow javascript to call a C# function.
I've followed the instructions available here:
Calling C# BHO methods from Javascript
These instructions work great in IE 9.
Unfortunately, I've found that they only work for the first tab created in IE 10. The second and subsequent tabs do not expose the BHO interface to Javascript. On occasion, new tabs work, but most of the time they do not. Moreover, it fails silently. I'm guessing this has something to do with the process model -- but again, it works fine in IE 9 (which has the same process model).
Here is the specific snippet of code that I'm using:
private void InstallJSObject(IHTMLWindow2 window)
{
// Install our javascript object
IExpando windowEx = (IExpando)window;
PropertyInfo property = windowEx.GetProperty("myBHO", System.Reflection.BindingFlags.IgnoreCase);
if (property == null)
{
property = windowEx.AddProperty("myBHO");
}
property.SetValue(windowEx, this, null);
}
Before posting, I researched the following: http://bit.ly/R9qldf
var myATL = new ActiveXObject("MySampleATL.MyClass");
if (myATL.IsBHOInstalled)
alert (myATL. SayHelloFromBHO());
else
alert ("BHO isn't installed now !");
window.external.AddFavorite(<url>, "text");
Extracted from here.
The the blog is dated back to April'07, still, may be this is what you were looking for..

Categories