Npapi Plugin not detected in demobrowser of QtWebkit - plugins

I am a newbie to StackOverflow and QtWebkit as well.
I have written a very basic Npapi plugin which has functions like NP_GetMimeTypeDescription and Np_Initialise etc for Mimetype application/basic-plugin and Mimetype description application/basic-plugin:bsc:Plug-ins SDK sample.
But I am facing a problem while loading it on the demobrowser of QtWebKit and also on Mozilla Firefox. I have placed the generated .so file in the paths where ever browser finds plugins like /usr/lib/mozilla/plugins/ and Qt Lib path.
I have a test.html file which contains the Mimetype application/basic-plugin. I am trying to launch this plugin in both the Mozilla browser and QtWebKit Demo Browser But in both the cases its not launching the plugin.
I am not able to find out why.
Any suggestions are Welcome...

Thanks for help and suggestions.
I was able to find out the problem why my plugin was not getting invoked,
even if I placed the .so file in the correct folders
/usr/lib/mozilla/plugins/ and Qt Lib path.
There were 2 reasons...
Had to enable the Define XP_UNIX (-DXP_UNIX) during compilation as a compiler directive.
This will consider different prototypes of the functions and also implementation
extern "C"
NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs
#ifdef XP_UNIX
, NPPluginFuncs *pluginFuncs
#endif
)
{
// keep a pointer to the browser functions
g_browser = browserFuncs;
// any memory that is to be shared by all instances of
the browser plugin should be initialized here.
;
#ifdef XP_UNIX
// under Linux, as the browser won't call NP_GetEntryPoints()
explicitly, do it now to fill in <pluginFuncs>
return NP_GetEntryPoints(pluginFuncs);
#else
return NPERR_NO_ERROR;
#endif
}
and
extern "C"
#ifdef XP_UNIX
NPError NP_GetValue(void* instance, NPPVariable variable, void *value)
#else
NPError NP_GetValue(NPP instance, NPPVariable variable, void *value)
#endif
2.. There were 2 functions NP_GetValue and NPP_GetValue.
extern "C"
NPError NP_GetValue(void* instance, NPPVariable variable, void *value);
and
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value);
NPP_GetValue is a plugin function whose registration should be made in
NP_GetEntryPoints
extern "C"
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* NPPluginFuncsptr)
{
......
NPPluginFuncsptr->newp = NPP_New;
NPPluginFuncsptr->getvalue = NPP_GetValue;
NPPluginFuncsptr->setvalue = NPP_SetValue;
return NPERR_NO_ERROR;
}
In my code only NP_GetValue was implemented and NPP_GetValue was not implemented.
So NPP_GetValue was undefined in .so and due to it the .so was not loading.
On implementing the function NPP_GetValue this function was defined and exported in the .so file and was able to load it successfully.
The sequence of calling of the functions from the browser to plugin is as follows...
NP_Initialize - > Browser calls the initialization function first.
(In case of Linux the set of plugin function should be exported by calling
NP_GetEntryPoints explicity As browser will not call GetEntryPoints)
NP_GetEntryPoints -> Called explicitly from NP_Initialize for Linux to
expose/export plugin functions.
NP_GetValue variable : 1 -> Called from Browser to get the Plugin Name
(NPPVpluginNameString)
NP_GetValue variable : 2 -> Called from Browser to get the
Plugin Description (NPPVpluginDescriptionString)
NP_GetMimeDescription -> Called from browser to get MimeType Description
(This function should return Mime Type description
e.g. :
return("application/basic-plugin:bsc:Plug-ins SDK sample");)
NPP_New -> Called from browser to create plugin instance.
NPP_GetValue PLUGIN:main.cpp,NPP_GetValue,446ENTRY - > Called from browser to get plugin specific data...
......
Please note that the next function in the above sequence will be called
IF and ONLY IF the previous function call returns a success.:-)

Related

The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' FIX

Can someone please help me with this, am trying to use OpenFileDialog class from System.Windows.Forms to open a file dialog and read the selected file. Then, this error showed up. I've referenced it but still the same, below is the code.
`using UnityEngine
using UnityEngine.UI
using System.Windows.Forms;
public class OpenFileButtonScript : MonoBehaviour
{
public TextFieldScript textFieldScript;
public void OpenFile()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
openFileDialog.FilterIndex = 1;
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = openFileDialog.FileName;
string text = System.IO.File.ReadAllText(filePath);
textFieldScript.inputField.text = text;
}
}
}`
It may look like you have access to all of the native Window system libraries, but it just looks like it. In actuality, a lot of the time you're simply given stubs, or shims, that look like the full Window libraries, because there's a certain element that Unity wants to use from those namespaces. If you think about it, the code you present above, what do you think it should do on Android or Nintendo devices? The simple answer is, it simply won't work.
Generally in cases like this, you have to gain access to the native operating system, and perform those calls directly. For example, there is a file browser asset on the Asset Store, that does this for you. It's not free, because the process isn't trivial.
Depending on how much effort you want to put in, you CAN read files from the local file stores (to varying degrees based on platform). It's possible to read the list of files in a location, and use either uGUI or UIToolkit to create your own File Open Dialogue box. Again, this isn't a trivial task either. So you have to be sure that you'd want to go down that path.

Visual Studio Extension: Project context is applied to every opened file except the first one

I have a Visual Studio extension package where I am applying C++ syntax settings to custom file extensions. This is done in the Visual Studio's Text Editor options. Those files are plain text and I mean to have them behave as code files in the IDE (IntelliSense, find matching braces, etc...)
It's mostly working fine, but there is one problem. The C++ syntax context is not applied to whichever is the first file I open in a given Visual Studio session. I will launch Visual Studio, open one of our custom projects, and open one file. The IDE opens a document window and the file is opened, can be edited and saved, no problem in appearance. But the file behaves as a plain text and not a C++ source. Now, whenever I open a second file in the IDE, or any further file, the C++ settings do get applied successfully. I can close all document tabs, and open new ones, and all those tabs are fine. Even re-opening the first file in a new tab, or after re-loading the project or the solution, is fine. Only the first document opened in a Visual Studio session has the issue.
For the following segment, I will refer to the Microsoft documentation on using their standard editor: https ://msdn.microsoft.com/en-us/library/bb166504.aspx
To implement the OpenItem method with a standard editor
1.Call IVsRunningDocumentTable (RDT_EditLock) to determine whether the document data object file is already open.
2.If the file is already open, resurface the file by calling the IsDocumentOpen method, specifying a value of IDO_ActivateIfOpen for the grfIDO parameter.
If the file is open and the document is owned by a different project than the calling project, your project receives a warning that the editor being opened is from another project. The file window is then surfaced.
3.If the document is not open or not in the running document table, call the OpenStandardEditor method (OSE_ChooseBestStdEditor) to open a standard editor for the file.
When you call the method, the IDE performs the following tasks:
a.The IDE scans the Editors/{guidEditorType}/Extensions subkey in the registry to determine which editor can open the file and has the highest priority for doing this.
b.After the IDE has determined which editor can open the file, the IDE calls CreateEditorInstance. The editor's implementation of this method returns information that is required for the IDE to call CreateDocumentWindow and site the newly opened document.
c.Finally, the IDE loads the document by using the usual persistence interface, such as IVsPersistDocData2.
d.If the IDE has previously determined that the hierarchy or hierarchy item is available, the IDE calls GetItemContext method on the project to get a project-level context IServiceProvider pointer to pass back in with the CreateDocumentWindow method call.
4.Return an IServiceProvider pointer to the IDE when the IDE calls GetItemContext on your project if you want to let the editor get context from your project.
Performing this step lets the project offer additional services to the editor.
If the document view or document view object was successfully sited in a window frame, the object is initialized with its data by calling LoadDocData.
It definitely seems to me that I need to hit element (D) from the above instructions. I have debuged through my extension code, and I do see where my implementation of GetItemContext() comes into play. When I open most files, the code path does effectively go through this method, however it does not when I open the first file of a Visual Studio session.
Call stack from OpenStandardEditor
GetItemContext is invoked by the Microsoft assemblies and I do not know what is the condition that triggers whether it is called or not. I can only trace up to my call to the method OpenStandardEditor(), in FileDocumentManager.cs, then I don't know what happens beyond that. The above screenshot is the call stack when GetItemContext is successfully invoked, but when I'm opening the first file I'm totally in the dark as to what OpenStandardEditor is doing. I do know that in both cases, when the context is loaded and when it is not, the exact same parameter values are passed to OpenStandardEditor. So here's my code where this method is invoked, if that can be of some help:
My override of class DocumentManager:
private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
{
windowFrame = null;
if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
{
return VSConstants.E_FAIL;
}
int returnValue = VSConstants.S_OK;
string caption = this.GetOwnerCaption();
string fullPath = this.GetFullPathForDocument();
// Make sure that the file is on disk before we open the editor and display message if not found
if (!((FileNode)this.Node).IsFileOnDisk(true))
{
// Inform clients that we have an invalid item (wrong icon)
this.Node.OnInvalidateItems(this.Node.Parent);
// Bail since we are not able to open the item
return VSConstants.E_FAIL;
}
IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;
try
{
int result = VSConstants.E_FAIL;
if (openWith)
{
result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
}
else
{
__VSOSEFLAGS openFlags = 0;
if (newFile)
{
openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile;
}
//NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid
// of the node being opened, otherwise the debugger doesn't work.
if (editorType != Guid.Empty)
{
result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
}
else
{
openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor;
// THIS IS THE CALL THAT I'M ALWAYS INVOKING. PARAMS ARE ALWAYS THE SAME, BUT ITEM CONTEXT IS NOT ACTIVATED FOR FIRST FILE OF A SESSION.
result = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
}
}
if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED)
{
ErrorHandler.ThrowOnFailure(result);
}
if (windowFrame != null)
{
object var;
if (newFile)
{
ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var));
IVsPersistDocData persistDocData = (IVsPersistDocData)var;
ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath));
}
var = null;
ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var));
this.Node.DocCookie = (uint)(int)var;
if (windowFrameAction == WindowFrameShowAction.Show)
{
ErrorHandler.ThrowOnFailure(windowFrame.Show());
}
else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate)
{
ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate());
}
else if (windowFrameAction == WindowFrameShowAction.Hide)
{
ErrorHandler.ThrowOnFailure(windowFrame.Hide());
}
}
}
catch (COMException e)
{
Trace.WriteLine("Exception e:" + e.Message);
returnValue = e.ErrorCode;
this.CloseWindowFrame(ref windowFrame);
}
return returnValue;
}
I have also tried an alternative. In the call stack where I perform DoDefaultAction on my FileNode (extends HierarchyNode), I normally call an instance of my DocumentManager.Open() directly. I have changed that to try OpenDocumentViaProject() instead. Now, the MSENV assembly turns out to call my GetItemContext, then goes out to my implementation of DocumentManager.Open I quoted above.
Call stack from OpenDocumentViaProject
Sounds promising... but no. Beyond the screenshot above, once I call OpenStandardEditor the exact same behavior happens. No project context is applied to the first document opened in a session, and the context is applied to every further file. The call to GetItemContext() that is done by OpenDocumentViaProject() does not seem to matter in the slightest. Only when OpenStandardEditor() also ends up calling GetItemContext() somewhere downstream does the project settings I want get applied.
I don't see where I would be doing something fundamentally wrong. It seems to me that I am following the Mimcrosoft instructions on opening standard editors. Would you have a clue as to how my GetItemContext implementation is not invoked when I'm opening the first file of a VS session? Thanks

Changing working directory in Scala [duplicate]

How can I change the current working directory from within a Java program? Everything I've been able to find about the issue claims that you simply can't do it, but I can't believe that that's really the case.
I have a piece of code that opens a file using a hard-coded relative file path from the directory it's normally started in, and I just want to be able to use that code from within a different Java program without having to start it from within a particular directory. It seems like you should just be able to call System.setProperty( "user.dir", "/path/to/dir" ), but as far as I can figure out, calling that line just silently fails and does nothing.
I would understand if Java didn't allow you to do this, if it weren't for the fact that it allows you to get the current working directory, and even allows you to open files using relative file paths....
There is no reliable way to do this in pure Java. Setting the user.dir property via System.setProperty() or java -Duser.dir=... does seem to affect subsequent creations of Files, but not e.g. FileOutputStreams.
The File(String parent, String child) constructor can help if you build up your directory path separately from your file path, allowing easier swapping.
An alternative is to set up a script to run Java from a different directory, or use JNI native code as suggested below.
The relevant OpenJDK bug was closed in 2008 as "will not fix".
If you run your legacy program with ProcessBuilder, you will be able to specify its working directory.
There is a way to do this using the system property "user.dir". The key part to understand is that getAbsoluteFile() must be called (as shown below) or else relative paths will be resolved against the default "user.dir" value.
import java.io.*;
public class FileUtils
{
public static boolean setCurrentDirectory(String directory_name)
{
boolean result = false; // Boolean indicating whether directory was set
File directory; // Desired current working directory
directory = new File(directory_name).getAbsoluteFile();
if (directory.exists() || directory.mkdirs())
{
result = (System.setProperty("user.dir", directory.getAbsolutePath()) != null);
}
return result;
}
public static PrintWriter openOutputFile(String file_name)
{
PrintWriter output = null; // File to open for writing
try
{
output = new PrintWriter(new File(file_name).getAbsoluteFile());
}
catch (Exception exception) {}
return output;
}
public static void main(String[] args) throws Exception
{
FileUtils.openOutputFile("DefaultDirectoryFile.txt");
FileUtils.setCurrentDirectory("NewCurrentDirectory");
FileUtils.openOutputFile("CurrentDirectoryFile.txt");
}
}
It is possible to change the PWD, using JNA/JNI to make calls to libc. The JRuby guys have a handy java library for making POSIX calls called jnr-posix. Here's the maven info
As mentioned you can't change the CWD of the JVM but if you were to launch another process using Runtime.exec() you can use the overloaded method that lets you specify the working directory. This is not really for running your Java program in another directory but for many cases when one needs to launch another program like a Perl script for example, you can specify the working directory of that script while leaving the working dir of the JVM unchanged.
See Runtime.exec javadocs
Specifically,
public Process exec(String[] cmdarray,String[] envp, File dir) throws IOException
where dir is the working directory to run the subprocess in
If I understand correctly, a Java program starts with a copy of the current environment variables. Any changes via System.setProperty(String, String) are modifying the copy, not the original environment variables. Not that this provides a thorough reason as to why Sun chose this behavior, but perhaps it sheds a little light...
The working directory is a operating system feature (set when the process starts).
Why don't you just pass your own System property (-Dsomeprop=/my/path) and use that in your code as the parent of your File:
File f = new File ( System.getProperty("someprop"), myFilename)
The smarter/easier thing to do here is to just change your code so that instead of opening the file assuming that it exists in the current working directory (I assume you are doing something like new File("blah.txt"), just build the path to the file yourself.
Let the user pass in the base directory, read it from a config file, fall back to user.dir if the other properties can't be found, etc. But it's a whole lot easier to improve the logic in your program than it is to change how environment variables work.
I have tried to invoke
String oldDir = System.setProperty("user.dir", currdir.getAbsolutePath());
It seems to work. But
File myFile = new File("localpath.ext");
InputStream openit = new FileInputStream(myFile);
throws a FileNotFoundException though
myFile.getAbsolutePath()
shows the correct path.
I have read this. I think the problem is:
Java knows the current directory with the new setting.
But the file handling is done by the operation system. It does not know the new set current directory, unfortunately.
The solution may be:
File myFile = new File(System.getPropety("user.dir"), "localpath.ext");
It creates a file Object as absolute one with the current directory which is known by the JVM. But that code should be existing in a used class, it needs changing of reused codes.
~~~~JcHartmut
You can use
new File("relative/path").getAbsoluteFile()
after
System.setProperty("user.dir", "/some/directory")
System.setProperty("user.dir", "C:/OtherProject");
File file = new File("data/data.csv").getAbsoluteFile();
System.out.println(file.getPath());
Will print
C:\OtherProject\data\data.csv
You can change the process's actual working directory using JNI or JNA.
With JNI, you can use native functions to set the directory. The POSIX method is chdir(). On Windows, you can use SetCurrentDirectory().
With JNA, you can wrap the native functions in Java binders.
For Windows:
private static interface MyKernel32 extends Library {
public MyKernel32 INSTANCE = (MyKernel32) Native.loadLibrary("Kernel32", MyKernel32.class);
/** BOOL SetCurrentDirectory( LPCTSTR lpPathName ); */
int SetCurrentDirectoryW(char[] pathName);
}
For POSIX systems:
private interface MyCLibrary extends Library {
MyCLibrary INSTANCE = (MyCLibrary) Native.loadLibrary("c", MyCLibrary.class);
/** int chdir(const char *path); */
int chdir( String path );
}
The other possible answer to this question may depend on the reason you are opening the file. Is this a property file or a file that has some configuration related to your application?
If this is the case you may consider trying to load the file through the classpath loader, this way you can load any file Java has access to.
If you run your commands in a shell you can write something like "java -cp" and add any directories you want separated by ":" if java doesnt find something in one directory it will go try and find them in the other directories, that is what I do.
Use FileSystemView
private FileSystemView fileSystemView;
fileSystemView = FileSystemView.getFileSystemView();
currentDirectory = new File(".");
//listing currentDirectory
File[] filesAndDirs = fileSystemView.getFiles(currentDirectory, false);
fileList = new ArrayList<File>();
dirList = new ArrayList<File>();
for (File file : filesAndDirs) {
if (file.isDirectory())
dirList.add(file);
else
fileList.add(file);
}
Collections.sort(dirList);
if (!fileSystemView.isFileSystemRoot(currentDirectory))
dirList.add(0, new File(".."));
Collections.sort(fileList);
//change
currentDirectory = fileSystemView.getParentDirectory(currentDirectory);

Debugging Groovy scripts running in a ScriptEngine from Eclipse

I have a Groovy script which is run like this:
File scriptFile = ...;
ScriptEngine engine = ...;
String script = FileUtils.readFileToString(scriptFile);
Object evalResult = engine.eval(script, bindings);
Unsurprisingly, breakpoint set in the script file doesn't trigger. What can I change to make it work? The script needs to be run in the context of the larger program (no separate launch configuration), and through a ScriptEngine, and the file is only known at runtime.
I'm using this hack: I've defined a Java class Debugger which looks like this:
public class Debugger {
private static final Logger log = LoggerFactory.getLogger( Debugger.class );
/**
* Invoke this method anywhere to end up in the Java debugger.
*
* <p>Sometimes, you have code that might eventually be executed or you have a place
* where you want to stop but no code line.
*
* <p>In these case, use this method.
*
* <p>Don't forget to set a breakpoint, first :-)
* */
public static void stopInDebugger() {
log.error( "Please set a breakpoint in Debugger.stopInDebugger() and try again whatever you just did!" );
}
}
I have a breakpoint in the log.error line in Ecipse.
Now, I can put this line into the script where I want a breakpoint:
Debugger.stopInDebugger();
Granted, it doesn't allow me to easily step through the script but it's better than nothing.
Is your script file in a source folder on the classpath (sounds like it's not)? If not, make it so. You can also change your preferences to ensure that the script file is never compiled by the compiler (and optionally not even copied to the output folder). Go to Preferences -> Groovy -> Compiler and look at script folders to make this happen.

RCP - Proper register Listener not from view

I try to register my class as PostSelectionListener from separate plugin (this class is not a view, only simple class), I use this:
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService().
addPostSelectionListener(VIEWS_VISUALIZATION_TYP_ID, this);
It works fine, but I have a warning:
- Discouraged access: The method getActiveWorkbenchWindow()
from the type Workbench is not accessible due to restriction on required library F:
\elipseSource\plugins\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
- Discouraged access: The method getInstance()
from the type Workbench is not accessible due to restriction on required library F:\elipseSource\plugins
\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
- Discouraged access: The type Workbench is not accessible
due to restriction on required library F:\elipseSource\plugins
\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
How can I register listener in proper way ?
I have found a solution, instead of
Workbench.getInstance()
I should use:
PlatformUI.getWorkbench()
I am RCP beginner so it was not obvious for me
Check if this is a MANFEST.MF generation issue (see this thread)
Open the MANIFEST.MF of the base project and look at the Runtime tab.
The packages that are to be accessed in other plugins should be listed as Exported Packages.
Try to re-compute the right list of exported packages.
If this is not working, as described in this thread, you still have the option to de-activate the warning:
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
(or: Project) Properties -> Java Compiler -> Errors/Warnings
"Warning" or "Ignore" options will only hide the potential issue in the project, by allowing the project to use any classes ignoring predefined access rules.
To completely resolve this issue, analyze the project and located the use of restricted classes and take necessary actions (either remove those references or access rules).
For external jar (not your case), Potential workaround:
If I add the Jar file as an external jar and move it up before the JRE system Library (in order of export), I don't get this error.
Actually the OP slowik managed to avoid the dependency by accessing the Workbench services through the PlatformUI
PlatformUI.getWorkbench()
instead of Workbench.getInstance()
You can see this approach used in the rcp.util.RCPUtil class:
/**
* Returns wether the ViewPart with the given id is currently visble in
* one of the pages of the active Workbench window. Will also return
* true when the page-book containing this view is minimized.
*
* #param viewID The id of the view to be queried
* #return Wether the view is visible
*/
public static boolean isViewVisible(String JavaDoc viewID) {
// IWorkbenchPage[] pages = Workbench.getInstance().getActiveWorkbenchWindow().getPages();
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
for (int i = 0; i < pages.length; i++) {
IWorkbenchPart part = pages[i].findView(viewID);
if (part != null) {
return isPartVisible(part);
}
}
return false;
}