mbien commented on code in PR #6585:
URL: https://github.com/apache/netbeans/pull/6585#discussion_r1363953711
##########
ide/extbrowser/native/NbDDEBrowserImpl.cpp:
##########
@@ -23,6 +23,7 @@
// #include "stdafx.h"
#include <windows.h>
+#include <sysinfo.h>
Review Comment:
can be probably reverted, I think you switched to doing everything in java
at some point
##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -80,7 +85,7 @@ public class NbDdeBrowserImpl extends ExtBrowserImpl {
String sunDataModel =
System.getProperty("sun.arch.data.model"); //NOI18N
if (sunDataModel != null) {
if ("64".equals(sunDataModel)) { //NOI18N
- System.loadLibrary(EXTBROWSER_DLL_64BIT);
+ System.loadLibrary(EXTBROWSER_DLL_64BIT);
Review Comment:
revert whitespace change
##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -127,6 +132,169 @@ public NbDdeBrowserImpl (ExtWebBrowser extBrowserFactory)
{
*/
public static native String getDefaultOpenCommand() throws
NbBrowserException;
+ /**
+ * Get the default browser name using java
+ * part of the solution source
https://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java
+ * @return
+ */
+ private static String getDefaultWindowsBrowser()
+ {
+ try
+ {
+ Process process = Runtime.getRuntime().exec("reg query
HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\URLAssociations\\https\\UserChoice
/f ProgId /v");
+
+ InputStream is = process.getInputStream();
+ StringBuilder sw = new StringBuilder();
+
+ int c;
+ while ((c = is.read()) != -1)
+ {
+ sw.append((char)c);
+ }
+
+ String output = sw.toString();
+
+ // Output has the following format:
+ // \n<Version information>\n\n<key> <registry type>
<value>\r\n\r\n
+ int i = output.indexOf("REG_SZ");
+ if (i == -1)
+ {
+ return null;
+ }
+
+ sw = new StringBuilder();
+ i += 6; // skip REG_SZ
+
+ // skip spaces or tabs
+ for (;;)
+ {
+ if (i > output.length())
+ {
+ break;
+ }
+ char charExamine = output.charAt(i);
+ if (charExamine != ' ' && charExamine != '\t')
+ {
+ break;
+ }
+ ++i;
+ }
+
+ // take everything until end of line
+ for (;;)
+ {
+ if (i > output.length())
+ {
+ break;
+ }
+ char charExamine = output.charAt(i);
+ if (charExamine == '\r' || charExamine == '\n')
+ break;
+ sw.append(charExamine);
+ ++i;
+ }
+
+
+ if
(sw.toString().toLowerCase().contains(ExtWebBrowser.FIREFOX.toLowerCase()))
Review Comment:
```java
switch (sw.toString().toUpperCase(Locale.ROOT)) {
case ExtWebBrowser.FIREFOX: return ExtWebBrowser.FIREFOX;
....
}
```
##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -127,6 +132,169 @@ public NbDdeBrowserImpl (ExtWebBrowser extBrowserFactory)
{
*/
public static native String getDefaultOpenCommand() throws
NbBrowserException;
+ /**
+ * Get the default browser name using java
+ * part of the solution source
https://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java
+ * @return
+ */
+ private static String getDefaultWindowsBrowser()
+ {
+ try
+ {
Review Comment:
please put the opening braces on the same line as in the rest of the file:
```java
private static String getDefaultWindowsBrowser() {
try {
```
same applies for the rest of the new code
##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -127,6 +132,169 @@ public NbDdeBrowserImpl (ExtWebBrowser extBrowserFactory)
{
*/
public static native String getDefaultOpenCommand() throws
NbBrowserException;
+ /**
+ * Get the default browser name using java
+ * part of the solution source
https://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java
+ * @return
+ */
+ private static String getDefaultWindowsBrowser()
+ {
+ try
+ {
+ Process process = Runtime.getRuntime().exec("reg query
HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\URLAssociations\\https\\UserChoice
/f ProgId /v");
+
+ InputStream is = process.getInputStream();
+ StringBuilder sw = new StringBuilder();
+
+ int c;
+ while ((c = is.read()) != -1)
+ {
+ sw.append((char)c);
+ }
+
+ String output = sw.toString();
Review Comment:
i am wondering what charset this is. It might be worth to update the module
to JDK 11 and change this to:
```java
try (InputStream is = process.getInputStream()) {
output = new String(is.readAllBytes(), StandardCharsets.UTF_8); //
change to whatever charset reg uses
}
```
##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -212,7 +380,16 @@ private String realDDEServer () {
}
try {
- String cmd = getDefaultOpenCommand ();
+ String cmd = NbDdeBrowserImpl.getDefaultWindowsOpenCommand();
+
+ /** if not found with getDefaultWindowsOpenCommand function
+ * fallback to previous method
+ */
+ if (cmd.isEmpty())
+ {
+ cmd = getDefaultOpenCommand();
+ }
Review Comment:
assuming the java version works reliably, we should get rid the fallback and
the native function, since the C code did ask the registry too. We shouldn't
maintain two variants of the same thing.
https://github.com/apache/netbeans/blob/4086bd3bd687c616694d74f21aeab2ff6addc329/ide/extbrowser/native/NbDDEBrowserImpl.cpp#L439
##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -127,6 +132,169 @@ public NbDdeBrowserImpl (ExtWebBrowser extBrowserFactory)
{
*/
public static native String getDefaultOpenCommand() throws
NbBrowserException;
+ /**
+ * Get the default browser name using java
+ * part of the solution source
https://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java
+ * @return
+ */
+ private static String getDefaultWindowsBrowser()
+ {
+ try
+ {
+ Process process = Runtime.getRuntime().exec("reg query
HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\URLAssociations\\https\\UserChoice
/f ProgId /v");
Review Comment:
we might have to use `ProcessBuilder` and put this into a separate thread.
But lets leave it as is for now and see how well this approach works during
testing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists