summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2009-10-03 21:47:59 +0200
committerSamuel Lidén Borell <samuel@slbdata.se>2010-01-02 22:30:12 +0100
commit205717fab38b52f72f16c7c73ec959e7cd900d62 (patch)
treec752e406ade789a2db22b47f8beaa351f0701a76 /plugin
parent9d77e5b29487cf27eb9f6571e62f0be34ffa0649 (diff)
downloadfribid-205717fab38b52f72f16c7c73ec959e7cd900d62.tar.gz
fribid-205717fab38b52f72f16c7c73ec959e7cd900d62.tar.bz2
fribid-205717fab38b52f72f16c7c73ec959e7cd900d62.zip
Made the window modal instead of "stay on top"
Diffstat (limited to 'plugin')
-rw-r--r--plugin/ipc.c28
-rw-r--r--plugin/npobject.c15
-rw-r--r--plugin/plugin.c4
-rw-r--r--plugin/plugin.h4
4 files changed, 43 insertions, 8 deletions
diff --git a/plugin/ipc.c b/plugin/ipc.c
index 3629e86..3b15616 100644
--- a/plugin/ipc.c
+++ b/plugin/ipc.c
@@ -39,6 +39,7 @@
static const char *mainBinary = SIGNING_EXECUTABLE;
static const char *versionOption = "--internal--bankid-version-string";
static const char *ipcOption = "--internal--ipc";
+static const char *windowIdOption = "--internal--window-id";
static int savedOut;
static int savedIn;
@@ -56,7 +57,7 @@ static FILE *pipeout;
static pid_t child;
-static void openPipes(const char *option) {
+static void openPipes(const char *argv[]) {
savedOut = dup(STDOUT_FILENO);
savedIn = dup(STDIN_FILENO);
close(STDOUT_FILENO);
@@ -77,7 +78,7 @@ static void openPipes(const char *option) {
//close(pipeIn[PIPE_WRITE_END]);
//close(pipeOut[PIPE_READ_END]);
- execlp(mainBinary, mainBinary, option, (char *)NULL);
+ execvp(mainBinary, (char *const *)argv);
perror(BINNAME ": Failed to execute main binary");
exit(1);
} else {
@@ -90,6 +91,23 @@ static void openPipes(const char *option) {
}
}
+static void openVersionPipes() {
+ const char *argv[] = {
+ mainBinary, versionOption, (char *)NULL,
+ };
+ openPipes(argv);
+}
+
+static void openInteractivePipes(Plugin *plugin) {
+ char windowId[11]; // This holds a native window id (such as an XID)
+ const char *argv[] = {
+ mainBinary, ipcOption, windowIdOption, windowId, (char *)NULL,
+ };
+
+ snprintf(windowId, 11, "%d", plugin->windowId);
+ openPipes(argv);
+}
+
static void closePipes() {
close(PIPEOUT);
close(PIPEIN);
@@ -100,7 +118,7 @@ static void closePipes() {
char *version_getVersion(Plugin *plugin) {
char buff[1000];
- openPipes(versionOption);
+ openVersionPipes();
if (fgets(buff, sizeof(buff), pipein) != NULL) {
buff[strlen(buff)-1] = '\0';
} else {
@@ -122,7 +140,7 @@ static void sendSignCommon(const Plugin *plugin) {
}
int sign_performAction_Authenticate(Plugin *plugin) {
- openPipes(ipcOption);
+ openInteractivePipes(plugin);
pipe_sendCommand(pipeout, PMC_Authenticate);
sendSignCommon(plugin);
@@ -136,7 +154,7 @@ int sign_performAction_Authenticate(Plugin *plugin) {
}
int sign_performAction_Sign(Plugin *plugin) {
- openPipes(ipcOption);
+ openInteractivePipes(plugin);
pipe_sendCommand(pipeout, PMC_Sign);
sendSignCommon(plugin);
diff --git a/plugin/npobject.c b/plugin/npobject.c
index 10dbfa3..5e41783 100644
--- a/plugin/npobject.c
+++ b/plugin/npobject.c
@@ -144,6 +144,17 @@ static char *getDocumentIP(NPP instance) {
return strdup(ip);
}
+/**
+ * Returns the native ID of the browser window, or -1 on error.
+ */
+int getWindowId(NPP instance) {
+ int id;
+ if (NPN_GetValue(instance, NPNVnetscapeWindow, &id) == NPERR_NO_ERROR) {
+ return id;
+ } else {
+ return -1;
+ }
+}
/* Object methods */
static NPObject *objAllocate(NPP npp, NPClass *aClass) {
@@ -310,10 +321,12 @@ static NPObject *npobject_new(NPP instance, PluginType pluginType) {
char *url = getDocumentURL(instance);
char *hostname = getDocumentHostname(instance);
char *ip = getDocumentIP(instance);
+ int windowId = getWindowId(instance);
obj->plugin = plugin_new(pluginType,
(url != NULL ? url : ""),
(hostname != NULL ? hostname : ""),
- (ip != NULL ? ip : ""));
+ (ip != NULL ? ip : ""),
+ windowId);
free(ip);
free(hostname);
free(url);
diff --git a/plugin/plugin.c b/plugin/plugin.c
index 11b5b42..3b69d9f 100644
--- a/plugin/plugin.c
+++ b/plugin/plugin.c
@@ -30,12 +30,14 @@
#include "plugin.h"
Plugin *plugin_new(PluginType pluginType, const char *url,
- const char *hostname, const char *ip) {
+ const char *hostname, const char *ip,
+ int windowId) {
Plugin *plugin = calloc(1, sizeof(Plugin));
plugin->type = pluginType;
plugin->url = strdup(url);
plugin->hostname = strdup(hostname);
plugin->ip = strdup(ip);
+ plugin->windowId = windowId;
return plugin;
}
diff --git a/plugin/plugin.h b/plugin/plugin.h
index 0fb9f28..3fbfe51 100644
--- a/plugin/plugin.h
+++ b/plugin/plugin.h
@@ -42,6 +42,7 @@ typedef struct {
char *url;
char *hostname;
char *ip;
+ int windowId;
PluginError lastError;
union {
@@ -68,7 +69,8 @@ typedef struct {
/* Plugin creation */
Plugin *plugin_new(PluginType pluginType, const char *url,
- const char *hostname, const char *ip);
+ const char *hostname, const char *ip,
+ int windowId);
void plugin_free(Plugin *plugin);
/* Javascript API */