summaryrefslogtreecommitdiff
path: root/extensions/source/nsplugin
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/source/nsplugin')
-rw-r--r--extensions/source/nsplugin/source/exports.dxp16
-rw-r--r--extensions/source/nsplugin/source/exports_wnt.dxp18
-rw-r--r--extensions/source/nsplugin/source/makefile.mk162
-rw-r--r--extensions/source/nsplugin/source/npshell.cxx930
-rw-r--r--extensions/source/nsplugin/source/npshell.hxx91
-rw-r--r--extensions/source/nsplugin/source/ns_debug.hxx40
-rw-r--r--extensions/source/nsplugin/source/nsp_func.hxx103
-rw-r--r--extensions/source/nsplugin/source/nsp_windows.cxx63
-rw-r--r--extensions/source/nsplugin/source/nsp_windows.hxx36
-rw-r--r--extensions/source/nsplugin/source/nsplugin.rc30
-rw-r--r--extensions/source/nsplugin/source/nsplugin_oo.rc30
-rw-r--r--extensions/source/nsplugin/source/so_closelistener.cxx48
-rw-r--r--extensions/source/nsplugin/source/so_closelistener.hxx54
-rw-r--r--extensions/source/nsplugin/source/so_env.cxx507
-rw-r--r--extensions/source/nsplugin/source/so_env.hxx94
-rw-r--r--extensions/source/nsplugin/source/so_instance.cxx495
-rw-r--r--extensions/source/nsplugin/source/so_instance.hxx110
-rw-r--r--extensions/source/nsplugin/source/so_main.cxx497
-rw-r--r--extensions/source/nsplugin/source/so_msg.hxx54
19 files changed, 3378 insertions, 0 deletions
diff --git a/extensions/source/nsplugin/source/exports.dxp b/extensions/source/nsplugin/source/exports.dxp
new file mode 100644
index 000000000000..e8b697289c20
--- /dev/null
+++ b/extensions/source/nsplugin/source/exports.dxp
@@ -0,0 +1,16 @@
+NPP_GetMIMEDescription
+NPP_GetValue
+NPP_Initialize
+NPP_GetJavaClass
+NPP_Shutdown
+NPP_New
+NPP_Destroy
+NPP_SetWindow
+NPP_NewStream
+NPP_WriteReady
+NPP_Write
+NPP_DestroyStream
+NPP_StreamAsFile
+NPP_URLNotify
+NPP_Print
+NPP_Shutdown
diff --git a/extensions/source/nsplugin/source/exports_wnt.dxp b/extensions/source/nsplugin/source/exports_wnt.dxp
new file mode 100644
index 000000000000..a27be8c38300
--- /dev/null
+++ b/extensions/source/nsplugin/source/exports_wnt.dxp
@@ -0,0 +1,18 @@
+NPP_GetMIMEDescription
+NPP_Initialize
+NPP_Shutdown
+NPP_New
+NPP_Destroy
+NPP_SetWindow
+NPP_NewStream
+NPP_WriteReady
+NPP_Write
+NPP_DestroyStream
+NPP_StreamAsFile
+NPP_URLNotify
+NPP_Print
+NPP_Shutdown
+NP_GetEntryPoints
+NP_Initialize
+NP_Shutdown
+NP_GetMIMEDescription
diff --git a/extensions/source/nsplugin/source/makefile.mk b/extensions/source/nsplugin/source/makefile.mk
new file mode 100644
index 000000000000..5a0870b47194
--- /dev/null
+++ b/extensions/source/nsplugin/source/makefile.mk
@@ -0,0 +1,162 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+PRJNAME=extensions
+TARGET=npsoplugin
+
+ENABLE_EXCEPTIONS=TRUE
+USE_DEFFILE=TRUE
+
+# --- Settings ----------------------------------
+
+.INCLUDE : settings.mk
+
+INCPRE=$(SOLARINCDIR)$/npsdk
+
+.IF "$(GUI)"=="UNX"
+
+# not sure about -DMOZ_X11 but otheriwse some struct member don't exist...
+CFLAGS+=-DMOZ_X11
+
+.IF "$(ENABLE_GTK)"==""
+
+dummy:
+ @echo GTK disabled - nothing to build
+
+.ELSE # "$(ENABLE_GTK)"==""
+.IF "$(OS)"=="LINUX" || "$(OS)"=="FREEBSD"
+INC+= -DNP_LINUX
+.ENDIF
+PKGCONFIG_MODULES=gtk+-2.0
+.INCLUDE: pkg_config.mk
+.ENDIF # "$(ENABLE_GTK)"==""
+.ENDIF # "$(GUI)"=="UNX"
+.IF "$(GUI)"=="WNT"
+INC+= -DENGLISH
+.ENDIF
+
+
+# --- Files -------------------------------------
+
+SLOFILES= $(SLO)$/npshell.obj \
+ $(SLO)$/so_env.obj
+
+SHL1OBJS= $(SLO)$/npshell.obj \
+ $(SLO)$/so_env.obj
+
+.IF "$(GUI)"=="UNX"
+STDLIBS+=$(SOLARLIBDIR)$/npunix.o
+SHL1STDLIBS+=$(SOLARLIBDIR)$/npunix.o
+#.IF "$(OS)"!="FREEBSD"
+#SHL1STDLIBS+= -ldl -lnsl
+#.ENDIF #FREEBSD
+.ENDIF #UNX
+.IF "$(GUI)"=="WNT"
+SHL1OBJS+=$(SOLARLIBDIR)$/pathutils-obj.obj
+STDLIBS+=$(SOLARLIBDIR)$/npwin.obj
+SHL1STDLIBS+= $(SHELL32LIB) $(SOLARLIBDIR)$/npwin.obj
+
+.ENDIF
+
+OBJFILES=\
+ $(OBJ)$/so_closelistener.obj\
+ $(OBJ)$/so_instance.obj\
+ $(OBJ)$/so_env.obj\
+ $(OBJ)$/so_main.obj
+
+# --- Plugin executable -------------------------
+APP1TARGET=nsplugin$(EXEPOSTFIX)
+APP1OBJS=$(OBJFILES)
+
+APP1STDLIBS=\
+ $(CPPULIB) \
+ $(CPPUHELPERLIB) \
+ $(SALLIB)
+
+.IF "$(OS)"=="SOLARIS"
+APP1STDLIBS+= -lsocket -lnsl
+.ENDIF
+
+.IF "$(GUI)"=="WNT"
+DEPOBJFILES=$(OBJ)$/nsp_windows.obj
+APP1OBJS+=$(OBJ)$/nsp_windows.obj $(SOLARLIBDIR)$/pathutils-obj.obj
+APP1STDLIBS+= $(WS2_32LIB) $(SHELL32LIB) $(OLE32LIB) $(KERNEL32LIB) $(USER32LIB) $(GDI32LIB) $(WINSPOOLLIB) $(COMDLG32LIB) $(ADVAPI32LIB) $(OLEAAUT32LIB) $(UUIDLIB)
+.ENDIF
+
+# --- Library -----------------------------------
+
+SHL1TARGET=$(TARGET)_so
+.IF "$(GUI)"=="WNT"
+SHL1STDLIBS+= $(WS2_32LIB) $(SHELL32LIB) $(OLE32LIB) $(KERNEL32LIB) $(USER32LIB) $(GDI32LIB) $(WINSPOOLLIB) $(COMDLG32LIB) $(ADVAPI32LIB) $(OLE32LIB) $(OLEAAUT32LIB) $(UUIDLIB) $(KERNEL32LIB) $(USER32LIB) $(GDI32LIB) $(WINSPOOLLIB) $(COMDLG32LIB) $(ADVAPI32LIB)
+.ENDIF
+
+SHL1DEPN=
+SHL1IMPLIB= i$(SHL1TARGET)
+SHL1DEF= $(MISC)$/$(SHL1TARGET).def
+SHL1RPATH=BRAND
+
+# ----- get some additional keys in versioninfo ------------
+SHL1ADD_VERINFO=nsplugin.rc
+SHL1DEPN+=$(SHL1ADD_VERINFO)
+
+DEF1NAME=$(SHL1TARGET)
+.IF "$(GUI)"=="UNX"
+DEF1EXPORTFILE=exports.dxp
+.ENDIF
+.IF "$(GUI)"=="WNT"
+DEF1EXPORTFILE=exports_wnt.dxp
+.ENDIF
+
+SHL2OBJS=$(SHL1OBJS)
+SHL2STDLIBS=$(SHL1STDLIBS)
+SHL2TARGET=$(TARGET)
+.IF "$(GUI)"=="WNT"
+SHL2STDLIBS+= $(WS2_32LIB) $(SHELL32LIB) $(OLE32LIB) $(KERNEL32LIB) $(USER32LIB) $(GDI32LIB) $(WINSPOOLLIB) $(COMDLG32LIB) $(ADVAPI32LIB) $(OLE32LIB) $(OLEAAUT32LIB) $(UUIDLIB) $(KERNEL32LIB) $(USER32LIB) $(GDI32LIB) $(WINSPOOLLIB) $(COMDLG32LIB) $(ADVAPI32LIB)
+.ENDIF
+
+SHL2DEPN=
+SHL2IMPLIB= i$(SHL2TARGET)
+SHL2DEF= $(MISC)$/$(SHL2TARGET).def
+SHL2RPATH=BRAND
+
+# ----- get some additional keys in versioninfo ------------
+SHL2ADD_VERINFO=nsplugin_oo.rc
+SHL2DEPN+=$(SHL2ADD_VERINFO)
+
+DEF2NAME=$(SHL2TARGET)
+.IF "$(GUI)"=="UNX"
+DEF2EXPORTFILE=exports.dxp
+.ENDIF
+.IF "$(GUI)"=="WNT"
+DEF2EXPORTFILE=exports_wnt.dxp
+.ENDIF
+
+# --- Targets ----------------------------------
+
+.INCLUDE : target.mk
+
diff --git a/extensions/source/nsplugin/source/npshell.cxx b/extensions/source/nsplugin/source/npshell.cxx
new file mode 100644
index 000000000000..94edb1b0e48c
--- /dev/null
+++ b/extensions/source/nsplugin/source/npshell.cxx
@@ -0,0 +1,930 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_extensions.hxx"
+
+#ifdef OS2
+#define UNIX
+#endif
+
+#ifdef UNIX
+
+#define XP_UNIX 1
+
+#include <strings.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#endif //end of UNIX
+
+#ifdef WNT
+
+#define _WINDOWS
+
+#pragma warning (push,1)
+#pragma warning (disable:4668)
+
+#include <windows.h>
+#include <direct.h>
+#include <stdlib.h>
+#include <io.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#pragma warning (pop)
+
+#endif //end of WNT
+
+
+#include <stdio.h>
+
+#include <string.h>
+#include <errno.h>
+#include "boost/scoped_array.hpp"
+#include "tools/pathutils.hxx"
+
+//http://qa.openoffice.org/issues/show_bug.cgi?id=82545
+//https://bugzilla.mozilla.org/show_bug.cgi?id=241262
+#ifdef UNIX
+# ifndef _UINT32
+# if defined(__alpha) || defined(__LP64__)
+ typedef unsigned int uint32;
+# else /* __alpha */
+ typedef unsigned long uint32;
+# endif
+# define _UINT32
+# endif
+# ifndef _INT32
+# if defined(__alpha) || defined(__LP64__)
+ typedef int int32;
+# else /* __alpha */
+ typedef long int32;
+# endif
+# define _INT32
+# endif
+#endif
+
+#include "npapi.h"
+#include "npshell.hxx"
+#include "so_env.hxx"
+#include "so_msg.hxx"
+#include "ns_debug.hxx"
+
+
+#include "nsp_func.hxx"
+
+#include <comphelper/documentconstants.hxx>
+
+/***********************************************************************
+ *
+ * Implementations of plugin API functions
+ *
+ ***********************************************************************/
+
+static NSP_Mute_Obj send_lock = NSP_New_Mute_Obj();
+static NSP_PIPE_FD write_fd = 0;
+
+
+long int NSP_WriteToPipe(NSP_PIPE_FD fp, void* buf, unsigned long int len)
+{
+ unsigned long int len_unix = 0, len_wnt = 0;
+
+ len_unix = NSP_Write_Pipe(fp, buf, len, &len_wnt);
+#ifdef UNIX
+ (void)len_wnt;
+ return len_unix;
+#endif //end of UNIX
+#ifdef WNT
+ return len_wnt;
+#endif //end of WNT
+
+}
+
+#ifdef UNIX
+static pid_t nChildPID = 0;
+#endif
+
+#define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
+#define MY_STRING(s) (s), MY_LENGTH(s)
+
+#if defined WNT
+namespace {
+
+bool extendEnvironment(
+ boost::scoped_array< WCHAR > * environment, WCHAR const * pathBegin,
+ WCHAR const * pathEnd)
+{
+ WCHAR ure[MAX_PATH];
+ if (tools::buildPath(ure, pathBegin, pathEnd, MY_STRING(L"\\ure-link")) ==
+ NULL)
+ {
+ return false;
+ }
+ WCHAR * ureEnd = tools::resolveLink(ure);
+ if (ureEnd == NULL) {
+ return false;
+ }
+ ureEnd = tools::buildPath(ure, ure, ureEnd, MY_STRING(L"\\bin"));
+ if (ureEnd == NULL) {
+ return false;
+ }
+ WCHAR const * env = GetEnvironmentStringsW();
+ if (env == NULL) {
+ return false;
+ }
+ WCHAR const * p = env;
+ WCHAR const * p1 = NULL;
+ while (*p != L'\0') {
+ size_t n = wcslen(p);
+ if (p1 == NULL && n >= MY_LENGTH(L"PATH=") &&
+ (p[0] == L'P' || p[0] == L'p') &&
+ (p[1] == L'A' || p[1] == L'a') &&
+ (p[2] == L'T' || p[2] == L't') &&
+ (p[3] == L'H' || p[3] == L'h') && p[4] == L'=')
+ {
+ p1 = p + MY_LENGTH(L"PATH=");
+ //TODO: check whether the ure path is already present in PATH (at
+ // the beginning of PATH?)
+ }
+ p += n + 1;
+ }
+ ++p;
+ if (p1 == NULL) {
+ environment->reset(
+ new WCHAR[MY_LENGTH(L"PATH=") + (ureEnd - ure) + 1 + (p - env)]);
+ //TODO: overflow
+ memcpy(environment->get(), MY_STRING(L"PATH=") * sizeof (WCHAR));
+ memcpy(
+ environment->get() + MY_LENGTH(L"PATH="), ure,
+ ((ureEnd - ure) + 1) * sizeof (WCHAR));
+ memcpy(
+ environment->get() + MY_LENGTH(L"PATH=") + (ureEnd - ure) + 1, env,
+ (p - env) * sizeof (WCHAR));
+ } else {
+ environment->reset(
+ new WCHAR[(p - env) + (ureEnd - ure) + MY_LENGTH(L";")]);
+ //TODO: overflow
+ memcpy(environment->get(), env, (p1 - env) * sizeof (WCHAR));
+ memcpy(
+ environment->get() + (p1 - env), ure,
+ (ureEnd - ure) * sizeof (WCHAR));
+ environment->get()[(p1 - env) + (ureEnd - ure)] = L';';
+ memcpy(
+ environment->get() + (p1 - env) + (ureEnd - ure) + 1, p1,
+ (p - p1) * sizeof (WCHAR));
+ }
+ return true;
+}
+
+}
+#endif
+
+// start nspluin executable in child process, and use pipe to talk with it
+int do_init_pipe()
+{
+ debug_fprintf(NSP_LOG_APPEND, "enter do_init_pipe 1\n");
+ NSP_PIPE_FD fd[2];
+
+ if( 0 != NSP_Inherited_Pipe(fd) )
+ return NPERR_GENERIC_ERROR;
+
+ write_fd = fd[1]; // write fd
+#ifdef UNIX
+ // the parent process will wait for the child process in NPP_Shutdown code
+ nChildPID = fork();
+
+ if( ! nChildPID ) // child process
+#endif //end of UNIX
+ {
+#ifdef UNIX
+ char s_read_fd[16] = {0};
+ char s_write_fd[16] = {0};
+ sprintf(s_read_fd, "%d", fd[0]);
+ sprintf(s_write_fd, "%d", fd[1]);
+ char const * instdir = findInstallDir();
+ boost::scoped_array< char > exepath(
+ new char[strlen(instdir) +
+ RTL_CONSTASCII_LENGTH("/basis-link/program/nsplugin") +
+ 1]);
+ sprintf(exepath.get(), "%s/basis-link/program/nsplugin", instdir);
+ char const * progdir = findProgramDir();
+ boost::scoped_array< char > inifilepath(
+ new char[
+ RTL_CONSTASCII_LENGTH(
+ "-env:INIFILENAME=vnd.sun.star.pathname:") +
+ strlen(progdir) + RTL_CONSTASCII_LENGTH("/redirectrc") + 1]);
+ //TODO: overflow
+ sprintf(
+ inifilepath.get(),
+ "-env:INIFILENAME=vnd.sun.star.pathname:%s/redirectrc", progdir);
+ execl(
+ exepath.get(), exepath.get(), s_read_fd, s_write_fd,
+ inifilepath.get(), progdir, NULL);
+ _exit(255);
+#endif //end of UNIX
+#ifdef WNT
+ WCHAR s_read_fd[16] = {0};
+ WCHAR s_write_fd[16] = {0};
+ wsprintfW(s_read_fd, L"%d", fd[0]);
+ wsprintfW(s_write_fd, L"%d", fd[1]);
+ WCHAR brand[MAX_PATH];
+ int brandLen = MultiByteToWideChar(
+ CP_ACP, MB_PRECOMPOSED, findInstallDir(), -1, brand, MAX_PATH);
+ //TODO: conversion errors
+ if (brandLen == 0) {
+ return NPERR_GENERIC_ERROR;
+ }
+ WCHAR path[MAX_PATH];
+ if (tools::buildPath(
+ path, brand, brand + brandLen - 1, MY_STRING(L"\\basis-link"))
+ == NULL)
+ {
+ return NPERR_GENERIC_ERROR;
+ }
+ WCHAR * pathEnd = tools::resolveLink(path);
+ if (pathEnd == NULL) {
+ return NPERR_GENERIC_ERROR;
+ }
+ boost::scoped_array< WCHAR > env;
+ if (!extendEnvironment(&env, path, pathEnd)) {
+ return NPERR_GENERIC_ERROR;
+ }
+ pathEnd = tools::buildPath(
+ path, path, pathEnd, MY_STRING(L"\\program"));
+ if (pathEnd == NULL) {
+ return NPERR_GENERIC_ERROR;
+ }
+ WCHAR exe[MAX_PATH];
+ WCHAR * exeEnd = tools::buildPath(
+ exe, path, pathEnd, MY_STRING(L"\\nsplugin.exe"));
+ if (exeEnd == NULL) {
+ return NPERR_GENERIC_ERROR;
+ }
+ WCHAR * brandEnd = tools::buildPath(
+ brand, brand, brand + brandLen - 1,
+ MY_STRING(L"\\program\\redirect.ini"));
+ if (brandEnd == NULL) {
+ return NPERR_GENERIC_ERROR;
+ }
+ boost::scoped_array< WCHAR > args(
+ new WCHAR[
+ MY_LENGTH(L"\"") + (exeEnd - exe) + MY_LENGTH(L"\" ") +
+ wcslen(s_read_fd) + MY_LENGTH(L" ") + wcslen(s_write_fd) +
+ MY_LENGTH(L" \"-env:INIFILENAME=vnd.sun.star.pathname:") +
+ (brandEnd - brand) + MY_LENGTH(L"\"") + 1]); //TODO: overflow
+ wsprintfW(
+ args.get(),
+ L"\"%s\" %s %s \"-env:INIFILENAME=vnd.sun.star.pathname:%s\"", exe,
+ s_read_fd, s_write_fd, brand);
+ STARTUPINFOW NSP_StarInfo;
+ memset((void*) &NSP_StarInfo, 0, sizeof(STARTUPINFOW));
+ NSP_StarInfo.cb = sizeof(STARTUPINFOW);
+ PROCESS_INFORMATION NSP_ProcessInfo;
+ memset((void*)&NSP_ProcessInfo, 0, sizeof(PROCESS_INFORMATION));
+ if(!CreateProcessW(
+ exe, args.get(), NULL, NULL, TRUE,
+ CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT, env.get(), path,
+ &NSP_StarInfo, &NSP_ProcessInfo))
+ {
+ DWORD Err = GetLastError();
+ (void)Err;
+ }
+#endif //end of WNT
+ }
+ NSP_Close_Pipe(fd[0]);
+ return NPERR_NO_ERROR;
+}
+
+bool sendMsg( PLUGIN_MSG* pMsg, size_t len, int iEnsure)
+{
+ NSP_Lock_Mute_Obj(send_lock);
+ size_t len_w = 0;
+
+ debug_fprintf(NSP_LOG_APPEND, "try to send message type:%d; len: %d\n", pMsg->msg_id, len);
+ /*
+ debug_fprintf(NSP_LOG_APPEND, "NSPlugin Message: msg_id:%d; instance_id:%d;
+ wnd_id:%d;wnd_x:%d;wnd_y:%d;wnd_w:%d;wnd_h:%d; url:%s\n",
+ pMsg->msg_id, pMsg->instance_id, pMsg->wnd_id,
+ pMsg->wnd_x, pMsg->wnd_y, pMsg->wnd_w, pMsg->wnd_h, pMsg->url);*/
+ len_w = NSP_WriteToPipe(write_fd, (void*) pMsg, len);
+ if (len_w != len){
+ if(errno == EPIPE) // If pipe breaks, then init pipe again and resend the msg
+ {
+ if(iEnsure){
+ debug_fprintf(NSP_LOG_APPEND, "send message error, plugin exec need to be restart\n");
+ NSP_Close_Pipe(write_fd);
+ do_init_pipe();
+ len_w = NSP_WriteToPipe(write_fd, (void*) pMsg, len);
+ }
+ }
+ else if(errno == EINTR) // If interrupted by signal, then continue to send
+ {
+ long new_len;
+ debug_fprintf(NSP_LOG_APPEND, "send message error, send intrrupted by singal, resend again\n");
+ new_len = NSP_WriteToPipe(write_fd, (char*)pMsg+len_w, len-len_w);
+ len_w = len_w + new_len;
+ }
+ else // else return error
+ {
+ debug_fprintf(NSP_LOG_APPEND, "send message error :%s.\n", strerror(errno));
+ len_w = 0;
+ }
+ }
+ NSP_Unlock_Mute_Obj(send_lock);
+ debug_fprintf(NSP_LOG_APPEND, "send message success!\n");
+ return len_w == len;
+}
+
+extern "C"
+{
+char* pMimeTypes = const_cast< char* >( "application/vnd.stardivision.calc:sdc:StarCalc 3.0 - 5.0;"
+"application/vnd.stardivision.chart:sds:StarChart 3.0 - 5.0;"
+"application/vnd.stardivision.draw:sda:StarDraw 3.0 - 5.0;"
+"application/vnd.stardivision.impress:sdd:StarImpress 3.0 - 5.0;"
+"application/vnd.stardivision.impress-packed:sdp:StarImpress-packed 3.0 - 5.0;"
+"application/vnd.stardivision.math:smf:StarMath 3.0 - 5.0;"
+"application/vnd.stardivision.writer:vor:StarWriter Template 3.0 - 5.0;"
+"application/vnd.stardivision.writer-global:sgl:StarWriter Global 3.0 - 5.0;"
+"application/vnd.staroffice.writer:sdw:StarWriter 3.0 - 5.0;"
+MIMETYPE_VND_SUN_XML_CALC_ASCII ":sxc:StarOffice 6.0/7 Spreadsheet;"
+MIMETYPE_VND_SUN_XML_CALC_TEMPLATE_ASCII":stc:StarOffice 6.0/7 Spreadsheet Template;"
+MIMETYPE_VND_SUN_XML_DRAW_ASCII ":sxd:StarOffice 6.0/7 Drawing;"
+MIMETYPE_VND_SUN_XML_DRAW_TEMPLATE_ASCII ":std:StarOffice 6.0/7 Drawing Template;"
+MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ":sxi:StarOffice 6.0/7 Presentation;"
+MIMETYPE_VND_SUN_XML_IMPRESS_TEMPLATE_ASCII ":sti:StarOffice 6.0/7 Presentation Template;"
+MIMETYPE_VND_SUN_XML_MATH_ASCII ":sxm:StarOffice 6.0/7 Formula;"
+MIMETYPE_VND_SUN_XML_WRITER_ASCII ":sxw:StarOffice 6.0/7 Text Document;"
+MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII ":sxg:StarOffice 6.0/7 Master Document;"
+MIMETYPE_VND_SUN_XML_WRITER_TEMPLATE_ASCII ":stw:StarOffice 6.0/7 Text Document Template;"
+MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ":odt:OpenDocument Text;"
+MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ":ott:OpenDocument Text Template;"
+MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ":odm:OpenDocument Master Document;"
+MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ":oth:HTML Document Template;"
+MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ":ods:OpenDocument Spreadsheet;"
+MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ":ots:OpenDocument Spreadsheet Template;"
+MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ":odg:OpenDocument Drawing;"
+MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ":otg:OpenDocument Drawing Template;"
+MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ":odp:OpenDocument Presentation;"
+MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ":otp:OpenDocument Presentation Template;"
+MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ":odf:OpenDocument Formula;" );
+
+char*
+NPP_GetMIMEDescription(void)
+{
+ debug_fprintf(NSP_LOG_APPEND, "print by Netscape Plugin, NPP_GetMIMEDescription:%s.\n", pMimeTypes);
+ return(pMimeTypes);
+}
+
+#ifdef UNIX
+NPError
+// I am not actually sure wrt this, it ast least compiles with external
+// npapi.h now...
+NPP_GetValue(NPP /*instance*/, NPPVariable variable, void *value)
+{
+ NPError err = NPERR_NO_ERROR;
+
+ switch (variable) {
+ case NPPVpluginNameString:
+ // add here, for dynamic productname
+ *((char **)value) = NSP_getPluginName();
+ break;
+ case NPPVpluginDescriptionString:
+ // add here, for dynamic product description
+ *((char **)value) = NSP_getPluginDesc();
+ break;
+ default:
+ err = NPERR_GENERIC_ERROR;
+ }
+ debug_fprintf(NSP_LOG_APPEND, "print by Netscape Plugin, NPP_GetValue return %d.\n", err);
+ return err;
+}
+
+
+NPMIMEType
+dupMimeType(NPMIMEType type)
+{
+ NPMIMEType mimetype = (NPMIMEType) NPN_MemAlloc(strlen(type)+1);
+ mimetype[strlen(type)] = 0;
+ if (mimetype)
+ strcpy(mimetype, type);
+ return(mimetype);
+}
+#endif // end of UNIX
+
+NPError
+NPP_Initialize(void)
+{
+ debug_fprintf(NSP_LOG_NEW, "NS Plugin begin initialize.\n");
+ return (NPError)do_init_pipe();
+}
+
+#ifdef OJI
+jref
+NPP_GetJavaClass()
+{
+ return NULL;
+}
+#endif
+
+void
+NPP_Shutdown(void)
+{
+ PLUGIN_MSG msg;
+ memset((char*)&msg, 0, sizeof(PLUGIN_MSG));
+ msg.msg_id = SO_SHUTDOWN;
+ sendMsg(&msg, sizeof(PLUGIN_MSG), 0);
+ NSP_Close_Pipe(write_fd);
+
+#ifdef UNIX
+ // on Unix we should wait till the child process is dead
+ int nStatus;
+ waitpid( nChildPID, &nStatus, 0 );
+#endif
+}
+
+NPError
+NPP_New(NPMIMEType pluginType,
+ NPP instance,
+ uint16 mode,
+ int16 /*argc*/,
+ char* /*argn*/[],
+ char* /*argv*/[],
+ NPSavedData* /*saved*/)
+{
+ PluginInstance* This;
+
+ debug_fprintf(NSP_LOG_APPEND, "print by Netscape Plugin, enter NPP_New.\n");
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ instance->pdata = (PluginInstance*)NPN_MemAlloc(sizeof(PluginInstance));
+
+ memset(instance->pdata, 0 , sizeof(PluginInstance));
+ This = (PluginInstance*) instance->pdata;
+
+ if (This == NULL)
+ {
+ return NPERR_OUT_OF_MEMORY_ERROR;
+ }
+
+ memset(This, 0, sizeof(PluginInstance));
+
+ /* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
+#ifdef UNIX
+ This->mode = mode;
+ This->type = dupMimeType(pluginType);
+ This->instance = instance;
+ This->pluginsPageUrl = NULL;
+ This->exists = FALSE;
+#endif //end of UNIX
+#ifdef WNT
+ (void)pluginType;
+ This->fWindow = (NPWindow*)NPN_MemAlloc(sizeof(NPWindow));
+ memset(This->fWindow, 0, sizeof (NPWindow));
+ This->fMode = mode;
+ #endif //end of WNT
+ PLUGIN_MSG msg;
+ memset((char*)&msg, 0, sizeof(PLUGIN_MSG));
+ msg.msg_id = SO_NEW_INSTANCE;
+ msg.instance_id = (plugin_Int32)instance;
+ if (!sendMsg(&msg, sizeof(PLUGIN_MSG), 1))
+ return NPERR_GENERIC_ERROR;
+
+ NPN_Status(instance, "......");
+ return NPERR_NO_ERROR;
+}
+
+NPError
+NPP_Destroy(NPP instance, NPSavedData** /*save*/)
+{
+ debug_fprintf(NSP_LOG_APPEND, "print by Nsplugin, enter NPP_Destroy.\n");
+ PluginInstance* This;
+
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ // Send destroy message
+ PLUGIN_MSG msg;
+ memset((char*)&msg, 0, sizeof(PLUGIN_MSG));
+ msg.msg_id = SO_DESTROY;
+ msg.instance_id = (plugin_Int32)instance;
+#ifdef UNIX
+ msg.wnd_id =(plugin_Int32)((PluginInstance*) instance->pdata)->window;
+#endif //end of UNIX
+#ifdef WNT
+ msg.wnd_id =(plugin_Int32)((PluginInstance*) instance->pdata)->fhWnd;
+#endif //end of WNT
+ sendMsg(&msg, sizeof(PLUGIN_MSG), 0);
+
+ // Free the instance space
+ This = (PluginInstance*) instance->pdata;
+ if (This != NULL) {
+#ifdef UNIX
+ if (This->type)
+ NPN_MemFree(This->type);
+ if (This->pluginsPageUrl)
+ NPN_MemFree(This->pluginsPageUrl);
+ if (This->pluginsFileUrl)
+ NPN_MemFree(This->pluginsFileUrl);
+#endif //end of UNIX
+#ifdef WNT
+ if(This->fWindow)
+ NPN_MemFree(This->fWindow);
+#endif //end of WNT
+ NPN_MemFree(instance->pdata);
+ instance->pdata = NULL;
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+
+NPError
+NPP_SetWindow(NPP instance, NPWindow* window)
+{
+ PluginInstance* This;
+#ifdef UNIX
+ NPSetWindowCallbackStruct *ws_info;
+#endif //end of UNIX
+
+ debug_fprintf(NSP_LOG_APPEND, "print by Netscape Plugin, received window resize.\n");
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ This = (PluginInstance*) instance->pdata;
+ if (This == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ // Prepare the general part of the SET_WINDOW message
+ PLUGIN_MSG msg;
+ memset((char*)&msg, 0, sizeof(msg));
+ msg.msg_id = SO_SET_WINDOW;
+ msg.instance_id = (plugin_Int32)instance;
+
+ if ( window )
+ {
+ // Set window info for instance
+#ifdef UNIX
+ ws_info = (NPSetWindowCallbackStruct *)window->ws_info;
+ This->window = (Window) window->window;
+ This->x = window->x;
+ This->y = window->y;
+ This->width = window->width;
+ This->height = window->height;
+ This->display = ws_info->display;
+ This->visual = ws_info->visual;
+ This->depth = ws_info->depth;
+ This->colormap = ws_info->colormap;
+#endif //end of UNIX
+#ifdef WNT
+ This->fhWnd = (HWND) window->window;
+ This->fWindow->x = window->x;
+ This->fWindow->y = window->y;
+ This->fWindow->width = window->width;
+ This->fWindow->height = window->height;
+#endif //end of WNT
+ debug_fprintf(NSP_LOG_APPEND, "begin Set window of Office\n");
+ debug_fprintf(NSP_LOG_APPEND, "W=(%d) H=(%d)\n", window->width, window->height);
+
+ // fill the window dependent part of the message
+ msg.wnd_id = (plugin_Int32) window->window;
+ msg.wnd_x = window->x;
+ msg.wnd_y = window->y;
+ msg.wnd_w = window->width;
+ msg.wnd_h = window->height;
+ }
+ else
+ {
+ // empty window pointer usually means closing of the parent window
+#ifdef UNIX
+ ws_info = NULL;
+ This->window = (Window) NULL;
+ This->x = 0;
+ This->y = 0;
+ This->width = 0;
+ This->height = 0;
+ This->display = NULL;
+ This->visual = NULL;
+#endif //end of UNIX
+#ifdef WNT
+ This->fhWnd = (HWND) NULL;
+ This->fWindow->x = 0;
+ This->fWindow->y = 0;
+ This->fWindow->width = 0;
+ This->fWindow->height = 0;
+#endif //end of WNT
+ debug_fprintf(NSP_LOG_APPEND, "Empty window pointer is provided\n");
+
+ // fill the window dependent part of the message
+ msg.wnd_id = (plugin_Int32) NULL;
+ msg.wnd_x = 0;
+ msg.wnd_y = 0;
+ msg.wnd_w = 0;
+ msg.wnd_h = 0;
+ }
+
+ if(!sendMsg(&msg, sizeof(PLUGIN_MSG), 1))
+ {
+ debug_fprintf(NSP_LOG_APPEND, "NPP_SetWindow return failure \n");
+ return NPERR_GENERIC_ERROR;
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+
+NPError
+NPP_NewStream(NPP instance,
+ NPMIMEType /*type*/,
+ NPStream* /*stream*/,
+ NPBool /*seekable*/,
+ uint16 *stype)
+{
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ // Notify Mozilla to fetch the remote file into local cache directory
+ *stype=NP_ASFILEONLY;
+
+ return NPERR_NO_ERROR;
+}
+
+
+int32 STREAMBUFSIZE = 0X0FFFFFFF;
+/* If we are reading from a file in NPAsFile
+ * mode so we can take any size stream in our
+ * write call (since we ignore it) */
+
+int32
+NPP_WriteReady(NPP /*instance*/, NPStream* /*stream*/)
+{
+ return STREAMBUFSIZE;
+}
+
+
+int32
+NPP_Write(NPP /*instance*/, NPStream* /*stream*/, int32 /*offset*/, int32 len, void* /*buffer*/)
+{
+ return len; /* The number of bytes accepted */
+}
+
+
+NPError
+NPP_DestroyStream(NPP instance, NPStream* /*stream*/, NPError /*reason*/)
+{
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+ return NPERR_NO_ERROR;
+}
+
+// save fname to another file with the original file name
+void
+NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
+{
+ debug_fprintf(NSP_LOG_APPEND, "Into Stream\n");
+ char* url = (char*)stream->url;
+ char filename[1024] = {0};
+ char* pfilename = NULL;
+ if (NULL != (pfilename = strrchr(url, '/')))
+ {
+ strcpy(filename, pfilename+1);
+ } else {
+ return;
+ }
+
+ int length = strlen(url);
+ debug_fprintf(NSP_LOG_APPEND, "url: %s; length: %d\n", url, length);
+ PluginInstance* This;
+ This = (PluginInstance*) instance->pdata;
+
+ debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile\n");
+
+ // copy cached file to another file with original name
+ char localPathNew[NPP_PATH_MAX] = {0};
+ char localFileNew[NPP_PATH_MAX] = {0};
+ // if the file is from local
+ if (0 == STRNICMP(url, "file:///", strlen("file:///")))
+ {
+ sprintf(localPathNew, "%s", fname);
+ char* pAskSymbol = NULL;
+ if(NULL != (pAskSymbol = strrchr(localPathNew, '?')))
+ *pAskSymbol = 0;
+ }
+ else // from network, on windows, fname is c:\abc123
+ {
+ strncpy(localPathNew, fname, sizeof(localPathNew));
+ char* pRandomFilename = NULL;
+
+#ifdef UNIX
+ if(NULL != (pRandomFilename = strrchr(localPathNew, '/')))
+#endif //end of UNIX
+#ifdef WNT
+ if(NULL != (pRandomFilename = strrchr(localPathNew, '\\')))
+#endif //end of WNT
+ {
+ pRandomFilename[1] = 0;
+ } else {
+ return;
+ }
+ strcat(localPathNew, filename);
+ char* pAskSymbol = NULL;
+ if(NULL != (pAskSymbol = strrchr(localPathNew, '?')))
+ *pAskSymbol = 0;
+
+ sprintf(localFileNew, "file://%s", localPathNew);
+ UnixToDosPath(localFileNew);
+ debug_fprintf(NSP_LOG_APPEND, "fname: %s\n localPathNew: %s\nlocalFileNew: %s\n",
+ fname, localPathNew, localFileNew);
+
+ restoreUTF8(localPathNew);
+ restoreUTF8(localFileNew);
+ if(0 != strcmp(fname, localPathNew)) {
+
+#ifdef WNT
+ if(NULL == CopyFile(fname, localPathNew, FALSE))
+ return;
+#endif //end of WNT
+
+#ifdef UNIX
+ int fdSrc, fdDst;
+ if((0 > (fdSrc = open(fname, O_RDONLY)))){
+ return;
+ }
+ remove(localPathNew);
+ umask(0);
+ if (0 > (fdDst = open(localPathNew, O_WRONLY|O_CREAT,
+ S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))){
+ close( fdSrc);
+ debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile:can not create cache file %s. error: %s \n",
+ localPathNew, strerror(errno));
+ return;
+ }
+ char buffer[NPP_BUFFER_SIZE] = {0};
+ int ret;
+ while(0 <= (ret = read(fdSrc, buffer, NPP_BUFFER_SIZE)))
+ {
+ if (0 == ret)
+ {
+ if(EINTR == errno)
+ continue;
+ else
+
+ break;
+ }
+ write(fdDst, buffer, ret);
+ }
+ close(fdSrc);
+ close(fdDst);
+#endif //end of UNIX
+
+ debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile:before SetURL\n");
+ }
+ }
+
+ // send SO_SET_URl message to inform the new URL
+ PLUGIN_MSG msg;
+ memset((char*)&msg, 0, sizeof(PLUGIN_MSG));
+ msg.msg_id = SO_SET_URL;
+ msg.instance_id = (plugin_Int32)instance;
+#ifdef UNIX
+ msg.wnd_id =(plugin_Int32)(This->window);
+ sprintf(msg.url, "file://%s", localPathNew);
+#endif //end of UNIX
+#ifdef WNT
+ msg.wnd_id =(int)(This->fhWnd);
+ sprintf(msg.url, "file:///%s", localPathNew);
+ DosToUnixPath(msg.url);
+#endif //endof WNT
+ if(!sendMsg(&msg, sizeof(PLUGIN_MSG), 1))
+ debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile send SO_SET_URL return failure \n");
+
+ // send SO_SET_WINDOW message
+// memset((char*)&msg, 0, sizeof(PLUGIN_MSG));
+ msg.msg_id = SO_SET_WINDOW;
+ msg.instance_id = (plugin_Int32)instance;
+// msg.wnd_id =(plugin_Int32)((PluginInstance*) instance->pdata)->window;
+#ifdef UNIX
+ msg.wnd_x = This->x;
+ msg.wnd_y = This->y;
+ msg.wnd_w = This->width;
+ msg.wnd_h = This->height;
+#endif //end of UNIX
+#ifdef WNT
+ msg.wnd_x = This->fWindow->x;
+ msg.wnd_y = This->fWindow->y;
+ msg.wnd_w = This->fWindow->width;
+ msg.wnd_h = This->fWindow->height;
+#endif //endof WNT
+ if(!sendMsg(&msg, sizeof(PLUGIN_MSG), 1))
+ debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile send SO_SET_WINDOW return failure \n");
+}
+
+void
+NPP_URLNotify(NPP /*instance*/, const char* /*url*/,
+ NPReason /*reason*/, void* /*notifyData*/)
+{
+}
+
+
+void
+NPP_Print(NPP instance, NPPrint* printInfo)
+{
+ if(printInfo == NULL)
+ return;
+
+ if (instance != NULL) {
+ /***** Insert NPP_Print code here *****/
+ PluginInstance* This = (PluginInstance*) instance->pdata;
+ (void)This;
+ PLUGIN_MSG msg;
+ memset((char*)&msg, 0, sizeof(PLUGIN_MSG));
+ msg.msg_id = SO_PRINT;
+ msg.instance_id = (plugin_Int32)instance;
+ if(!sendMsg(&msg, sizeof(PLUGIN_MSG), 1))
+ debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile send SO_SET_WINDOW return failure \n");
+ printInfo->mode = TRUE;
+ /**************************************/
+
+ if (printInfo->mode == NP_FULL) {
+ /*
+ * PLUGIN DEVELOPERS:
+ * If your plugin would like to take over
+ * printing completely when it is in full-screen mode,
+ * set printInfo->pluginPrinted to TRUE and print your
+ * plugin as you see fit. If your plugin wants Netscape
+ * to handle printing in this case, set
+ * printInfo->pluginPrinted to FALSE (the default) and
+ * do nothing. If you do want to handle printing
+ * yourself, printOne is true if the print button
+ * (as opposed to the print menu) was clicked.
+ * On the Macintosh, platformPrint is a THPrint; on
+ * Windows, platformPrint is a structure
+ * (defined in npapi.h) containing the printer name, port,
+ * etc.
+ */
+
+ /***** Insert NPP_Print code here *****\
+ void* platformPrint =
+ printInfo->print.fullPrint.platformPrint;
+ NPBool printOne =
+ printInfo->print.fullPrint.printOne;
+ \**************************************/
+
+ /* Do the default*/
+ printInfo->print.fullPrint.pluginPrinted = FALSE;
+ }
+ else { /* If not fullscreen, we must be embedded */
+ /*
+ * PLUGIN DEVELOPERS:
+ * If your plugin is embedded, or is full-screen
+ * but you returned false in pluginPrinted above, NPP_Print
+ * will be called with mode == NP_EMBED. The NPWindow
+ * in the printInfo gives the location and dimensions of
+ * the embedded plugin on the printed page. On the
+ * Macintosh, platformPrint is the printer port; on
+ * Windows, platformPrint is the handle to the printing
+ * device context.
+ */
+
+ /***** Insert NPP_Print code here *****\
+ NPWindow* printWindow =
+ &(printInfo->print.embedPrint.window);
+ void* platformPrint =
+ printInfo->print.embedPrint.platformPrint;
+ \**************************************/
+ }
+ }
+}
+
+}// end of extern "C"
diff --git a/extensions/source/nsplugin/source/npshell.hxx b/extensions/source/nsplugin/source/npshell.hxx
new file mode 100644
index 000000000000..2f9cfb5bf4d1
--- /dev/null
+++ b/extensions/source/nsplugin/source/npshell.hxx
@@ -0,0 +1,91 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifdef UNIX
+
+#ifndef MOZ_X11
+# define MOZ_X11
+#endif
+
+#include <gtk/gtk.h>
+#include <X11/Xlib.h>
+
+typedef struct _PluginInstance
+{
+ uint16 mode;
+#ifdef MOZ_X11
+ Window window;
+ Display *display;
+#endif
+ uint32 x, y;
+ uint32 width, height;
+ NPMIMEType type;
+ char *message;
+
+ NPP instance;
+ char *pluginsPageUrl;
+ char *pluginsFileUrl;
+ NPBool pluginsHidden;
+#ifdef MOZ_X11
+ Visual* visual;
+ Colormap colormap;
+#endif
+ unsigned int depth;
+ GtkWidget* dialogBox;
+
+ NPBool exists; /* Does the widget already exist? */
+ int action; /* What action should we take? (GET or REFRESH) */
+
+} PluginInstance;
+
+typedef struct _MimeTypeElement
+{
+ PluginInstance *pinst;
+ struct _MimeTypeElement *next;
+} MimeTypeElement;
+
+#endif //end of UNIX
+
+
+#ifdef WNT
+
+#include <windows.h>
+
+typedef struct _PluginInstance
+{
+ NPWindow* fWindow;
+ uint16 fMode;
+
+ HWND fhWnd;
+ WNDPROC fDefaultWindowProc;
+} PluginInstance;
+
+#endif //end of WNT
+
+
+/* Extern functions */
+extern "C" NPMIMEType dupMimeType(NPMIMEType type);
diff --git a/extensions/source/nsplugin/source/ns_debug.hxx b/extensions/source/nsplugin/source/ns_debug.hxx
new file mode 100644
index 000000000000..e1782c5da5e7
--- /dev/null
+++ b/extensions/source/nsplugin/source/ns_debug.hxx
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __NSDEBUG_HXX_
+#define __NSDEBUG_HXX_
+
+#define NPP_PATH_MAX 1024
+#define NPP_BUFFER_SIZE 1024
+
+#define NSP_LOG_APPEND 2
+#define NSP_LOG_NEW 0
+
+#define debug_fprintf NSP_WriteLog
+
+#endif
+
diff --git a/extensions/source/nsplugin/source/nsp_func.hxx b/extensions/source/nsplugin/source/nsp_func.hxx
new file mode 100644
index 000000000000..e132235ec4b6
--- /dev/null
+++ b/extensions/source/nsplugin/source/nsp_func.hxx
@@ -0,0 +1,103 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef __NSP_FUNC_HXX
+#define __NSP_FUNC_HXX
+
+
+// Some function diffrent from UNIX and Window.
+
+/************************ In UNIX ************************/
+
+
+#ifdef UNIX
+// for chdir()
+#define NSP_CHDIR chdir
+//for vsnprintf()
+#define NSP_vsnprintf vsnprintf
+
+
+//for pipe()
+typedef int NSP_PIPE_FD;
+#define NSP_Inherited_Pipe(fp) pipe(fd)
+#define NSP_Close_Pipe(fp) close(fp)
+//for write(), read()
+#define NSP_Write_Pipe(a, b, c, d) write(a, b, c)
+#define NSP_Read_Pipe(a, b, c, d) read(a, b, c)
+
+//for socket
+#define NSP_CloseSocket close
+
+//for sleep
+#define NSP_Sleep(a) sleep(a)
+
+//for mutex
+#define NSP_Mute_Obj pthread_mutex_t
+#define NSP_New_Mute_Obj() PTHREAD_MUTEX_INITIALIZER
+#define NSP_Lock_Mute_Obj(a) pthread_mutex_lock(&a)
+#define NSP_Unlock_Mute_Obj(a) pthread_mutex_unlock(&a)
+
+#define STRNICMP(a, b ,c) strncasecmp(a, b ,c)
+#endif //end of UNIX
+
+/************************ In WINWS ************************/
+
+#ifdef WNT
+
+#include <windows.h>
+//for chdir()
+#define NSP_CHDIR(a) _chdir(a)
+//for vsnprintf()
+#define NSP_vsnprintf _vsnprintf
+
+//for pipe()
+typedef HANDLE NSP_PIPE_FD;
+SECURITY_ATTRIBUTES NSP_pipe_access = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
+#define NSP_Inherited_Pipe(fd) (!CreatePipe(&fd[0], &fd[1], &NSP_pipe_access, 1024*10))
+#define NSP_Close_Pipe(fp) CloseHandle(fp)
+//for write(), read()
+#define NSP_Write_Pipe(a, b, c, d) WriteFile(a, b, c, d, NULL)
+#define NSP_Read_Pipe(a, b, c, d) ReadFile(a, b, c, d, NULL)
+
+//for execl()
+#define NSP_CreateProcess(a, b ) CreateProcess(a, b, NULL, NULL, TRUE, 0, NULL, NULL, NULL, NULL)
+
+//for socket
+#define NSP_CloseSocket closesocket
+//for sleep
+#define NSP_Sleep(a) Sleep(a*1000)
+
+//for mutex
+#define NSP_Mute_Obj HANDLE
+#define NSP_New_Mute_Obj() CreateMutex (NULL, FALSE, NULL)
+#define NSP_Lock_Mute_Obj(a) WaitForSingleObject(a, INFINITE)
+#define NSP_Unlock_Mute_Obj(a) ReleaseMutex(a)
+#define STRNICMP(a, b ,c) strnicmp(a, b ,c)
+
+#endif //end of WNT
+
+
+#endif //end of __NSP_FUNC_HXX
diff --git a/extensions/source/nsplugin/source/nsp_windows.cxx b/extensions/source/nsplugin/source/nsp_windows.cxx
new file mode 100644
index 000000000000..58a56b7c82e5
--- /dev/null
+++ b/extensions/source/nsplugin/source/nsp_windows.cxx
@@ -0,0 +1,63 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_extensions.hxx"
+
+#ifdef WNT
+ #pragma warning (push,1)
+ #pragma warning (disable:4668)
+ #include <windows.h>
+ #pragma warning (pop)
+#endif
+
+int NSP_ResetWinStyl(long hParent)
+{
+ int ret = 0;
+#ifdef WNT
+ LONG dOldStyl = GetWindowLong( (HWND)hParent, GWL_STYLE);
+ ret = dOldStyl;
+
+ if(ret != 0)
+ {
+ LONG dNewStyl = dOldStyl|WS_CLIPCHILDREN;
+ if(0 == SetWindowLong((HWND)hParent, GWL_STYLE, dNewStyl))
+ ret = 0;
+ }
+#endif
+ return ret;
+
+}
+
+int NSP_RestoreWinStyl(long hParent, long dOldStyle)
+{
+ int ret = 0;
+#ifdef WNT
+ ret = SetWindowLong((HWND)hParent, GWL_STYLE, dOldStyle);
+#endif
+ return ret;
+}
diff --git a/extensions/source/nsplugin/source/nsp_windows.hxx b/extensions/source/nsplugin/source/nsp_windows.hxx
new file mode 100644
index 000000000000..707bb8bf515d
--- /dev/null
+++ b/extensions/source/nsplugin/source/nsp_windows.hxx
@@ -0,0 +1,36 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __NSP_WINDOWS_HXX__
+#define __NSP_WINDOWS_HXX__
+
+
+int NSP_ResetWinStyl(long hParent);
+int NSP_RestoreWinStyl(long hParent, long dOldStyle);
+
+#endif
+
diff --git a/extensions/source/nsplugin/source/nsplugin.rc b/extensions/source/nsplugin/source/nsplugin.rc
new file mode 100644
index 000000000000..7d4b60b5bdad
--- /dev/null
+++ b/extensions/source/nsplugin/source/nsplugin.rc
@@ -0,0 +1,30 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#define ADDITIONAL_VERINFO1 value "FileExtents", "sdc|sds|sda|sdd|sdp|smf|vor|sgl|sdw|sxc|stc|sxd|std|sxi|sti|sxm|sxw|sxg|stw|odt|ott|odm|oth|ods|ots|odg|otg|odp|otp|odf\0"\
+ value "FileOpenName", "StarCalc 3.0 - 5.0|StarChart 3.0 - 5.0|StarDraw 3.0 - 5.0|StarImpress 3.0 - 5.0|StarImpress-packed 3.0 - 5.0|StarMath 3.0 - 5.0|StarWriter Template 3.0 - 5.0|StarWriter Global 3.0 - 5.0|StarWriter 3.0 - 5.0|StarOffice 6.0/7 Spreadsheet|StarOffice 6.0/7 Spreadsheet Template|StarOffice 6.0/7 Drawing|StarOffice 6.0/7 Drawing Template|StarOffice 6.0/7 Presentation|StarOffice 6.0/7 Presentation Template|StarOffice 6.0/7 Formula|StarOffice 6.0/7 Text Document|StarOffice 6.0/7 Master Document|StarOffice 6.0/7 Text Document Template|OpenDocument Text|OpenDocument Text Template|OpenDocument Master Document|HTML Document Template|OpenDocument Spreadsheet|OpenDocument Spreadsheet Template|OpenDocument Drawing|OpenDocument Drawing Template|OpenDocument Presentation|OpenDocument Presentation Template|OpenDocument Formula\0"
+#define ADDITIONAL_VERINFO2 value "FileDescription", "Oracle Open Office Plug-in handles all its documents" value "ProductName", "Oracle Open Office Plug-in" value "MIMEType", "application/vnd.stardivision.calc|application/vnd.stardivision.chart|application/vnd.stardivision.draw|application/vnd.stardivision.impress|application/vnd.stardivision.impress-packed|application/vnd.stardivision.math|application/vnd.stardivision.writer|application/vnd.stardivision.writer-global|application/vnd.staroffice.writer|application/vnd.sun.xml.calc|application/vnd.sun.xml.calc.template|application/vnd.sun.xml.draw|application/vnd.sun.xml.draw.template|"
+#define ADDITIONAL_VERINFO3 "application/vnd.sun.xml.impress|application/vnd.sun.xml.impress.template|application/vnd.sun.xml.math|application/vnd.sun.xml.writer|application/vnd.sun.xml.writer.global|application/vnd.sun.xml.writer.template|application/vnd.oasis.opendocument.text|application/vnd.oasis.opendocument.text-template|application/vnd.oasis.opendocument.text-master|application/vnd.oasis.opendocument.text-web|application/vnd.oasis.opendocument.spreadsheet|application/vnd.oasis.opendocument.spreadsheet-template|application/vnd.oasis.opendocument.graphics|application/vnd.oasis.opendocument.graphics-template|application/vnd.oasis.opendocument.presentation|application/vnd.oasis.opendocument.presentation-template|application/vnd.oasis.opendocument.formula\0"
diff --git a/extensions/source/nsplugin/source/nsplugin_oo.rc b/extensions/source/nsplugin/source/nsplugin_oo.rc
new file mode 100644
index 000000000000..42a2a642e023
--- /dev/null
+++ b/extensions/source/nsplugin/source/nsplugin_oo.rc
@@ -0,0 +1,30 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#define ADDITIONAL_VERINFO1 value "FileExtents", "sdc|sds|sda|sdd|sdp|smf|vor|sgl|sdw|sxc|stc|sxd|std|sxi|sti|sxm|sxw|sxg|stw|odt|ott|odm|oth|ods|ots|odg|otg|odp|otp|odf\0"\
+ value "FileOpenName", "StarCalc 3.0 - 5.0|StarChart 3.0 - 5.0|StarDraw 3.0 - 5.0|StarImpress 3.0 - 5.0|StarImpress-packed 3.0 - 5.0|StarMath 3.0 - 5.0|StarWriter Template 3.0 - 5.0|StarWriter Global 3.0 - 5.0|StarWriter 3.0 - 5.0|StarOffice 6.0/7 Spreadsheet|StarOffice 6.0/7 Spreadsheet Template|StarOffice 6.0/7 Drawing|StarOffice 6.0/7 Drawing Template|StarOffice 6.0/7 Presentation|StarOffice 6.0/7 Presentation Template|StarOffice 6.0/7 Formula|StarOffice 6.0/7 Text Document|StarOffice 6.0/7 Master Document|StarOffice 6.0/7 Text Document Template|OpenDocument Text|OpenDocument Text Template|OpenDocument Master Document|HTML Document Template|OpenDocument Spreadsheet|OpenDocument Spreadsheet Template|OpenDocument Drawing|OpenDocument Drawing Template|OpenDocument Presentation|OpenDocument Presentation Template|OpenDocument Formula\0"
+#define ADDITIONAL_VERINFO2 value "FileDescription", "OpenOffice.org Plug-in handles all its documents" value "ProductName", "OpenOffice.org Plug-in" value "MIMEType", "application/vnd.stardivision.calc|application/vnd.stardivision.chart|application/vnd.stardivision.draw|application/vnd.stardivision.impress|application/vnd.stardivision.impress-packed|application/vnd.stardivision.math|application/vnd.stardivision.writer|application/vnd.stardivision.writer-global|application/vnd.staroffice.writer|application/vnd.sun.xml.calc|application/vnd.sun.xml.calc.template|application/vnd.sun.xml.draw|application/vnd.sun.xml.draw.template|"
+#define ADDITIONAL_VERINFO3 "application/vnd.sun.xml.impress|application/vnd.sun.xml.impress.template|application/vnd.sun.xml.math|application/vnd.sun.xml.writer|application/vnd.sun.xml.writer.global|application/vnd.sun.xml.writer.template|application/vnd.oasis.opendocument.text|application/vnd.oasis.opendocument.text-template|application/vnd.oasis.opendocument.text-master|application/vnd.oasis.opendocument.text-web|application/vnd.oasis.opendocument.spreadsheet|application/vnd.oasis.opendocument.spreadsheet-template|application/vnd.oasis.opendocument.graphics|application/vnd.oasis.opendocument.graphics-template|application/vnd.oasis.opendocument.presentation|application/vnd.oasis.opendocument.presentation-template|application/vnd.oasis.opendocument.formula\0"
diff --git a/extensions/source/nsplugin/source/so_closelistener.cxx b/extensions/source/nsplugin/source/so_closelistener.cxx
new file mode 100644
index 000000000000..8836b9f3dc17
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_closelistener.cxx
@@ -0,0 +1,48 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_extensions.hxx"
+
+#include "so_closelistener.hxx"
+
+using namespace ::com::sun::star;
+
+void SAL_CALL PluginDocumentClosePreventer::queryClosing( const lang::EventObject& /*aEvent*/, sal_Bool /*bDeliverOwnership*/ )
+ throw ( uno::RuntimeException, util::CloseVetoException )
+{
+ if ( m_bPreventClose )
+ throw util::CloseVetoException();
+}
+
+void SAL_CALL PluginDocumentClosePreventer::notifyClosing( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
+{}
+
+void SAL_CALL PluginDocumentClosePreventer::disposing( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
+{}
+
+
diff --git a/extensions/source/nsplugin/source/so_closelistener.hxx b/extensions/source/nsplugin/source/so_closelistener.hxx
new file mode 100644
index 000000000000..7ce20c9eaaf6
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_closelistener.hxx
@@ -0,0 +1,54 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __SO_CLOSELISTENER_HXX_
+#define __SO_CLOSELISTENER_HXX_
+
+#include <com/sun/star/util/XCloseListener.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+class PluginDocumentClosePreventer : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
+{
+ sal_Bool m_bPreventClose;
+
+public:
+ PluginDocumentClosePreventer()
+ : m_bPreventClose( sal_True )
+ {}
+
+ void StopPreventClose() { m_bPreventClose = sal_False; }
+
+ virtual void SAL_CALL queryClosing( const ::com::sun::star::lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
+ throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::util::CloseVetoException );
+
+ virtual void SAL_CALL notifyClosing( const ::com::sun::star::lang::EventObject& aEvent ) throw ( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw ( ::com::sun::star::uno::RuntimeException ) ;
+};
+
+#endif
+
diff --git a/extensions/source/nsplugin/source/so_env.cxx b/extensions/source/nsplugin/source/so_env.cxx
new file mode 100644
index 000000000000..f4eb2ef42169
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_env.cxx
@@ -0,0 +1,507 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_extensions.hxx"
+
+#ifdef UNIX
+#include <sys/types.h>
+#include <strings.h>
+#ifdef LINUX
+#include <dlfcn.h>
+#endif
+#include <stdarg.h>
+// For vsnprintf()
+#define NSP_vsnprintf vsnprintf
+#include "nsp_func.hxx"
+#endif // End UNIX
+
+#ifdef WNT
+#define _WINDOWS
+
+#pragma warning (push,1)
+#pragma warning (disable:4668)
+#pragma warning (disable:4917)
+
+#include <windows.h>
+#include <direct.h>
+#include <stdlib.h>
+#include <shlobj.h>
+#include <objidl.h>
+// For vsnprintf()
+#define NSP_vsnprintf _vsnprintf
+
+#pragma warning (pop)
+#endif // End WNT
+
+#include <sys/stat.h>
+#include <errno.h>
+#include "so_env.hxx"
+#include "ns_debug.hxx"
+#include <sal/config.h>
+
+#define PLUGIN_NAME "OpenOffice.org"
+
+// Tranform all strings like %20 in pPath to one char like space
+/*int retoreUTF8(char* pPath)
+{
+ // Prepare buf
+ int len = strlen(pPath) + 1;
+ char* pBuf = (char*)malloc(len);
+ memset(pBuf, 0, len);
+
+ // Store the original pBuf and pPath
+ char* pBufCur = pBuf;
+ char* pPathCur = pPath;
+ // ie, for %20, UTF8Numbers[0][0] = 2, UTF8Numbers[1][0] = 0
+ char UTF8Numbers[2][2] = {{0, 0}, {0,0}};
+ int temp;
+
+ while (*pPathCur) {
+ if (('%' == *pPathCur) && (0 != *(pPathCur + 1))
+ && (0 != *(pPathCur + 2)))
+ {
+ UTF8Numbers[0][0] = *(pPathCur + 1);
+ UTF8Numbers[1][0] = *(pPathCur + 2);
+ temp = 0;
+ temp = atoi(UTF8Numbers[0])*16 + atoi(UTF8Numbers[1]);
+ *pBufCur = (char)temp;
+ pBufCur++;
+ pPathCur += 3;
+ } else {
+ *pBufCur++ = *pPathCur++;
+ }
+ }
+
+ *pBufCur = 0;
+ strcpy(pPath, pBuf);
+ free(pBuf);
+ return 0;
+}*/
+
+int
+restoreUTF8(char *pPath)
+{
+ unsigned char *s, *d;
+
+#define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
+
+ s = d = (unsigned char *)pPath;
+ do {
+ if (*s == '%' && s[1] && s[2]) {
+ *d++ = (XDIGIT (s[1]) << 4) + XDIGIT (s[2]);
+ s += 2;
+ } else
+ *d++ = *s;
+ } while (*s++);
+ debug_fprintf(NSP_LOG_APPEND, "after restoreUTF8, pPath is %s\n", pPath);
+ return 0;
+}
+
+#ifdef LINUX
+extern int nspluginOOoModuleHook (void** aResult);
+int nspluginOOoModuleHook (void** aResult)
+{
+ void *dl_handle;
+
+ dl_handle = dlopen(NULL, RTLD_NOW);
+ if (!dl_handle)
+ {
+ fprintf (stderr, "Can't open myself '%s'\n", dlerror());
+ return 1;
+ }
+
+ Dl_info dl_info = { 0,0,0,0 };
+ if(!dladdr((void *)nspluginOOoModuleHook, &dl_info))
+ {
+ fprintf (stderr, "Can't find my own address '%s'\n", dlerror());
+ return 1;
+ }
+
+ if (!dl_info.dli_fname)
+ {
+ fprintf (stderr, "Can't find my own file name\n");
+ return 1;
+ }
+
+ char cwdstr[NPP_PATH_MAX];
+ if (!getcwd (cwdstr, sizeof(cwdstr)))
+ {
+ fprintf (stderr, "Can't get cwd\n");
+ return 1;
+ }
+
+ char libFileName[NPP_PATH_MAX];
+
+ if (dl_info.dli_fname[0] != '/')
+ {
+ if ((strlen(cwdstr) + 1 + strlen(dl_info.dli_fname)) >= NPP_PATH_MAX)
+ {
+ fprintf (stderr, "Plugin path too long\n");
+ return 1;
+ }
+ strcpy (libFileName, cwdstr);
+ strcat (libFileName, "/");
+ strcat (libFileName, dl_info.dli_fname);
+ }
+ else
+ {
+ if (strlen(dl_info.dli_fname) >= NPP_PATH_MAX)
+ {
+ fprintf (stderr, "Plugin path too long\n");
+ return 1;
+ }
+ strcpy (libFileName, dl_info.dli_fname);
+ }
+
+ char *clobber;
+ static char realFileName[NPP_PATH_MAX] = {0};
+# define SEARCH_SUFFIX "/program/libnpsoplug"
+
+ if (!(clobber = strstr (libFileName, SEARCH_SUFFIX)))
+ {
+ ssize_t len = readlink(libFileName, realFileName, NPP_PATH_MAX-1);
+ if (len == -1)
+ {
+ fprintf (stderr, "Couldn't read link '%s'\n", libFileName);
+ return 1;
+ }
+ realFileName[len] = '\0';
+ if (!(clobber = strstr (realFileName, SEARCH_SUFFIX)))
+ {
+ fprintf (stderr, "Couldn't find suffix in '%s'\n", realFileName);
+ return 1;
+ }
+ *clobber = '\0';
+ }
+ else
+ {
+ *clobber = '\0';
+ strcpy (realFileName, libFileName);
+ }
+
+ #if OSL_DEBUG_LEVEL > 1
+ fprintf (stderr, "OpenOffice path before fixup is '%s'\n", realFileName);
+ #endif
+
+ if (realFileName[0] != '/') {
+ /* a relative sym-link and we need to get an absolute path */
+ char scratch[NPP_PATH_MAX] = {0};
+ if (strlen (realFileName) + strlen (libFileName) + 2 >= NPP_PATH_MAX - 1)
+ {
+ fprintf (stderr, "Paths too long to fix up.\n");
+ return 1;
+ }
+ strcpy (scratch, libFileName);
+ if (strrchr (scratch, '/')) /* remove the last element */
+ *(strrchr (scratch, '/') + 1) = '\0';
+ strcat (scratch, realFileName);
+ strcpy (realFileName, scratch);
+ }
+
+ *aResult = realFileName;
+
+ #if OSL_DEBUG_LEVEL > 1
+ fprintf (stderr, "OpenOffice path is '%s'\n", realFileName);
+ #endif
+
+ return 0;
+}
+#endif
+
+// *aResult points the static string holding "/opt/staroffice8"
+int findReadSversion(void** aResult, int /*bWnt*/, const char* /*tag*/, const char* /*entry*/)
+{
+#ifdef UNIX
+ // The real space to hold "/opt/staroffice8"
+ static char realFileName[NPP_PATH_MAX] = {0};
+ memset(realFileName, 0, NPP_PATH_MAX);
+ *aResult = realFileName;
+
+ // Filename of lnk file, eg. "soffice"
+ char lnkFileName[NPP_PATH_MAX] = {0};
+ char* pTempZero = NULL;
+
+#ifdef LINUX
+ /* try to fetch a 'self' pointer */
+ if (!nspluginOOoModuleHook (aResult))
+ return 0;
+
+ /* .. now in $HOME */
+#endif
+ sprintf(lnkFileName, "%s/.mozilla/plugins/libnpsoplugin%s", getenv("HOME"), SAL_DLLEXTENSION);
+#ifdef LINUX
+ ssize_t len = readlink(lnkFileName, realFileName, NPP_PATH_MAX-1);
+ if (-1 == len)
+ {
+ *realFileName = 0;
+ return -1;
+ }
+ realFileName[len] = '\0';
+
+ if (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION)))
+#else
+ if ((0 > readlink(lnkFileName, realFileName, NPP_PATH_MAX)) ||
+ (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION))))
+#endif
+ {
+ *realFileName = 0;
+ return -1;
+ }
+ *pTempZero = 0;
+ return 0;
+#endif
+#ifdef WNT
+ static char realFileName[NPP_PATH_MAX] = {0};
+ *aResult = realFileName;
+ HKEY hKey;
+ DWORD dwBufLen = NPP_PATH_MAX;
+ LONG lRet;
+
+ debug_fprintf(NSP_LOG_APPEND, "1 before before strstr realFileName is %s\n", realFileName);
+ lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\MozillaPlugins\\@sun.com/npsopluginmi;version=1.0",
+ 0, KEY_QUERY_VALUE, &hKey );
+ if (lRet == ERROR_FILE_NOT_FOUND) {
+ lRet = RegOpenKeyEx(
+ HKEY_CURRENT_USER,
+ "SOFTWARE\\MozillaPlugins\\@sun.com/npsopluginmi;version=1.0", 0,
+ KEY_QUERY_VALUE, &hKey);
+ }
+ debug_fprintf(NSP_LOG_APPEND, "2 before before strstr realFileName is %s\n", realFileName);
+ if( lRet != ERROR_SUCCESS )
+ return FALSE;
+
+ lRet = RegQueryValueEx( hKey, "Path", NULL, NULL,
+ (LPBYTE) realFileName, &dwBufLen);
+ debug_fprintf(NSP_LOG_APPEND, "3 before before strstr realFileName is %s\n", realFileName);
+ if( (lRet != ERROR_SUCCESS) || (dwBufLen > NPP_PATH_MAX) )
+ return FALSE;
+
+ RegCloseKey( hKey );
+ char* pTempZero = NULL;
+ debug_fprintf(NSP_LOG_APPEND, "before strstr realFileName is %s\n", realFileName);
+ if (NULL == (pTempZero = strstr(realFileName, "\\program")))
+ {
+ *realFileName = 0;
+ return -1;
+ }
+ *pTempZero = 0;
+ debug_fprintf(NSP_LOG_APPEND, "realFileName is %s\n", realFileName);
+ return 0;
+#endif
+}
+
+// Return the install dir path of staroffice, return value like "/home/build/staroffice"
+const char* findInstallDir()
+{
+ static char* pInstall = NULL;
+ debug_fprintf(NSP_LOG_APPEND, "start of findInstallDir()\n");
+ if (!pInstall)
+ {
+ findReadSversion((void**)&pInstall, 0, "["SECTION_NAME"]", SOFFICE_VERSION"=");
+ if (!pInstall)
+ pInstall = const_cast< char* >( "" );
+ }
+ return pInstall;
+}
+
+// Return the program dir path of staroffice, return value like "/home/build/staroffice/program"
+const char* findProgramDir()
+{
+ static char sProgram[NPP_BUFFER_SIZE] = {0};
+ if (!sProgram[0])
+ {
+ sprintf(sProgram, "%s/program", findInstallDir());
+#ifdef WNT
+ UnixToDosPath(sProgram);
+#endif
+ }
+ return sProgram;
+}
+
+#ifdef WNT
+// Return SO executable absolute path, like "/home/build/staroffice/program/soffice"
+const char* findSofficeExecutable()
+{
+ static char pSofficeExeccutable[NPP_PATH_MAX] = {0};
+ if (!pSofficeExeccutable[0])
+ {
+ sprintf(pSofficeExeccutable, "%s/%s", findProgramDir(), STAROFFICE_EXE_FILE_NAME);
+#ifdef WNT
+ UnixToDosPath(pSofficeExeccutable);
+#endif
+ }
+
+ return pSofficeExeccutable;
+}
+
+// Change Dos path such as c:\program\soffice to c:/program/soffice
+int DosToUnixPath(char* sPath)
+{
+ if (!sPath)
+ return -1;
+ char* p = sPath;
+ while (*p)
+ {
+ if(*p == '\\')
+ *p = '/';
+ p++;
+ }
+ return 0;
+
+}
+#endif
+// Change Unix path such as program/soffice to program\soffice
+int UnixToDosPath(char* sPath)
+{
+ if (!sPath)
+ return -1;
+ char* p = sPath;
+ while (*p)
+ {
+ if(*p == '/')
+ *p = '\\';
+ p++;
+ }
+ return 0;
+
+}
+
+#ifdef UNIX
+char productName[128] = {0};
+char* NSP_getProductName()
+{
+ if(productName[0])
+ return productName;
+ char fullBootstrapIniPath[1024] = {0};
+ const char* pFullFilePath = findProgramDir();
+ if(0 == *pFullFilePath)
+ {
+ strcpy(productName, PLUGIN_NAME);
+ return productName;
+ }
+ sprintf(fullBootstrapIniPath, "%s/%s", pFullFilePath,
+ "bootstraprc");
+
+ FILE* fp = fopen(fullBootstrapIniPath, "r");
+
+ if (NULL == fp)
+ {
+ strcpy(productName, PLUGIN_NAME);
+ return productName;
+ }
+ char line[4096] = {0};
+ char *pStart = 0;
+ char *pEnd = 0;
+ while(!feof(fp))
+ {
+ if (fgets( line, sizeof(line), fp ) == NULL)
+ continue;
+ if (NULL == (pStart = strstr( line, "ProductKey=" )))
+ continue;
+ pStart += strlen("ProductKey=");
+ if (NULL == (pEnd = strchr( pStart, ' ' )) &&
+ (NULL == (pEnd = strchr( pStart, '\r' ))))
+ continue;
+ *pEnd = 0;
+ strcpy(productName, pStart);
+ }
+ fclose(fp);
+ if ((*productName == 0) ||
+ (0 != STRNICMP(productName, "StarOffice", sizeof("StarOffice"))))
+ {
+ strcpy(productName, PLUGIN_NAME);
+ return productName;
+ }
+ memset(productName, 0, sizeof(productName));
+ strcat(productName, "StarOffice/StarSuite");
+ return productName;
+}
+
+char PluginName[1024] = {0};
+char* NSP_getPluginName()
+{
+ if(*PluginName)
+ return PluginName;
+ sprintf(PluginName, "%s Plug-in", NSP_getProductName());
+ return PluginName;
+}
+
+char PluginDesc[1024] = {0};
+char* NSP_getPluginDesc()
+{
+ if(*PluginDesc)
+ return PluginDesc;
+
+ sprintf(PluginDesc, "%s Plug-in handles all its documents",
+ productName);
+ return PluginDesc;
+}
+#endif //end of UNIX
+
+void NSP_WriteLog(int level, const char* pFormat, ...)
+{
+ (void)level;
+#ifndef DEBUG
+ (void)pFormat;
+#else
+ va_list ap;
+ char msgBuf[NPP_BUFFER_SIZE];
+ static char logName[NPP_PATH_MAX] = {0};
+ FILE * fp = NULL;
+
+ va_start(ap,pFormat);
+ NSP_vsnprintf(msgBuf, NPP_BUFFER_SIZE, pFormat, ap);
+ va_end(ap);
+
+ if (!logName[0])
+ {
+#ifdef UNIX
+ const char* homeDir = getenv("HOME");
+ sprintf(logName,"%s/%s",homeDir,"nsplugin.log");
+#endif // End UNIX
+#ifdef WNT
+ char szPath[MAX_PATH];
+ if (!SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, 0))
+ {
+ return;
+ }
+ char* homeDir = szPath;
+ sprintf(logName,"%s\\%s", szPath, "nsplugin.log");
+#endif // End WNT
+ }
+ else
+ fp = fopen(logName, "a+");
+
+ if (!fp)
+ return;
+ fputs(msgBuf, fp);
+ fclose(fp);
+#endif
+}
+
diff --git a/extensions/source/nsplugin/source/so_env.hxx b/extensions/source/nsplugin/source/so_env.hxx
new file mode 100644
index 000000000000..0cf1194c2dc2
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_env.hxx
@@ -0,0 +1,94 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __SO_ENVIRON_HXX__
+#define __SO_ENVIRON_HXX__
+
+
+
+#ifdef UNIX
+
+
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#endif //end of UNIX
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <string.h>
+
+#define SO_SERVER_PORT 8100
+
+
+#ifdef UNIX
+#define STAROFFICE_VERSION_FILE "/.sversionrc"
+#define STAROFFICE_EXE_FILE_NAME "soffice"
+#endif
+#ifdef WNT
+#define STAROFFICE_VERSION_FILE "\\sversion.ini"
+#define STAROFFICE_EXE_FILE_NAME "soffice.exe"
+#endif
+
+#define SECTION_NAME "Versions"
+#define SOFFICE_VERSION "StarOffice 8"
+//#define SOFFICE_VERSION "SunShine Office 1.0"
+
+#define APP_ERROR 1
+#define APP_CHAR 2
+#define APP_WCHAR 3
+
+// return the install path of staroffice, return value like "/home/build/staroffice"
+const char* findInstallDir();
+
+// return SO program dir absolute path, like "/home/build/staroffice/program"
+const char* findProgramDir();
+
+#ifdef WNT
+// return SO executable absolute path, like "/home/build/staroffice/program/soffice"
+const char* findSofficeExecutable();
+
+// change Dos path such as c:\program\soffice to c:/program/soffice
+int DosToUnixPath(char*);
+#endif
+
+//change Unix path such as program\soffice to program/soffice
+int UnixToDosPath(char*);
+
+void NSP_WriteLog(int level, const char* pFormat, ...);
+
+int restoreUTF8(char* pPath);
+
+char* NSP_getPluginName();
+
+char* NSP_getPluginDesc();
+
+#endif
diff --git a/extensions/source/nsplugin/source/so_instance.cxx b/extensions/source/nsplugin/source/so_instance.cxx
new file mode 100644
index 000000000000..4b1e41f724bd
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_instance.cxx
@@ -0,0 +1,495 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_extensions.hxx"
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/lang/SystemDependent.hpp>
+#include <com/sun/star/awt/XSystemChildFactory.hpp>
+#include <com/sun/star/awt/XVclWindowPeer.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+#include <com/sun/star/presentation/XPresentation.hpp>
+#include <com/sun/star/presentation/XPresentationSupplier.hpp>
+#include <tools/debug.hxx>
+#include <tools/color.hxx>
+#include <vcl/window.hxx>
+#include <rtl/textenc.h>
+#include <rtl/locale.h>
+#include <osl/nlsupport.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "so_instance.hxx"
+#include "ns_debug.hxx"
+#include "so_env.hxx"
+#include "nsp_windows.hxx"
+#include "so_closelistener.hxx"
+#include <osl/process.h>
+
+namespace css=com::sun::star;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::connection;
+using namespace cppu;
+using namespace rtl;
+using namespace com::sun::star;
+
+char SoPluginInstance::sSO_Dir[] = {0};
+Reference< XMultiServiceFactory > SoPluginInstance::mxRemoteMSF = Reference< XMultiServiceFactory >(NULL);
+
+
+SoPluginInstance::SoPluginInstance(long pParent, Reference< XMultiServiceFactory > xMSF):
+ m_xUnoWin(NULL),
+ m_xComponent(NULL),
+ m_xFrame(NULL),
+ m_xFrames(NULL),
+ m_xDispatcher(NULL),
+ m_xDispatchProvider(NULL),
+ m_pCloseListener(NULL)
+{
+ m_nWidth = 0;
+ m_nHeight = 0;
+ m_nX = 0;
+ m_nY = 0;
+ m_nFlag = 15;
+ m_bInit = sal_False;
+ m_sURL = rtl::OUString::createFromAscii("");
+ m_hParent = 0;
+ m_pParent = pParent;
+ m_dParentStyl = 0;
+ mxRemoteMSF = xMSF;
+}
+
+SoPluginInstance::~SoPluginInstance()
+{
+}
+
+sal_Bool SoPluginInstance::SetURL(char* aURL)
+{
+ debug_fprintf(NSP_LOG_APPEND, "SoPluginInstance::SetURL %s\n", aURL);
+ sal_uInt16 encoding = 11;
+
+ rtl_Locale* pLocale = NULL;
+ osl_getProcessLocale(&pLocale);
+ encoding = osl_getTextEncodingFromLocale(pLocale);
+
+ m_sURL = ::rtl::OUString(aURL, strlen(aURL), encoding);
+ debug_fprintf(NSP_LOG_APPEND, "SetURL %s\nencoding is: %d\n", ::rtl::OUStringToOString(m_sURL,
+ RTL_TEXTENCODING_GB_18030).getStr(), m_sURL.getLength(), encoding);
+ return sal_True;
+}
+
+// plugin window UI part: create window, load document
+sal_Bool SoPluginInstance::LoadDocument(NSP_HWND hParent)
+{
+ // If doc has been loaded, we just resize the window and return
+ if(m_bInit)
+ {
+ debug_fprintf(NSP_LOG_APPEND, "only reset windows size\n");
+ m_xUnoWin->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, m_nFlag );
+ debug_fprintf(NSP_LOG_APPEND, "set windows to x:%d y:%d w:%d h%d falg:%d\n",
+ m_nX, m_nY, m_nWidth, m_nHeight, m_nFlag);
+ return sal_True;
+ }
+
+ // If mxRemoteMSF is not initialized, we assert and return sal_False
+ if(!mxRemoteMSF.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "Remote StarOfiice ServiceManager is not initilzed correctly!\n");
+ return sal_False;
+ }
+
+ try
+ {
+ // try to create netscape plugin window
+ Reference< awt::XToolkit > xToolkit(
+ mxRemoteMSF->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.awt.Toolkit") ),
+ uno::UNO_QUERY );
+ if( !xToolkit.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "Can not create Toolkit!\n");
+ return sal_False;
+ }
+
+ // prepare parameters for plugin window
+ css::uno::Any hwndParent = css::uno::makeAny((sal_Int32)hParent);
+#ifdef UNIX
+ sal_Int16 nWindowType = css::lang::SystemDependent::SYSTEM_XWINDOW;
+#endif //end of UNIX
+#ifdef WNT
+ sal_Int16 nWindowType = css::lang::SystemDependent::SYSTEM_WIN32;
+#endif //end of WNT
+
+ Reference< awt::XSystemChildFactory > xToolkitSystemChildFactory(xToolkit, uno::UNO_QUERY);
+ if (!xToolkitSystemChildFactory.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "print by Nsplugin, get xToolkitSystemChildFactory failure.\n");
+ return sal_False;
+ }
+
+ debug_fprintf(NSP_LOG_APPEND, "print by Nsplugin, try to create plugin container window HWIN:%ld.\n", hParent);
+
+ // create the plugin window
+ Reference< awt::XWindowPeer > xNewWinPeer =
+ xToolkitSystemChildFactory->createSystemChild( hwndParent,
+ css::uno::Sequence<sal_Int8>(), nWindowType );
+ if ( !xNewWinPeer.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not create first window\n", hParent);
+ return sal_False;
+ }
+
+ // get interface of first window
+ m_xUnoWin = Reference< awt::XWindow >( xNewWinPeer, uno::UNO_QUERY );
+ if( !m_xUnoWin.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not get interface of first window\n", hParent);
+ return sal_False;
+ }
+
+ // initialize window
+ xNewWinPeer->setBackground( COL_GRAY );
+ m_xUnoWin->setVisible( sal_True );
+ m_xUnoWin->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, m_nFlag );
+ debug_fprintf(NSP_LOG_APPEND, "set windows to x:%d y:%d w:%d h%d falg:%d\n",
+ m_nX, m_nY, m_nWidth, m_nHeight, m_nFlag);
+
+ // create frame
+ m_xFrame = Reference< frame::XFrame >(
+ mxRemoteMSF->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.Frame") ),
+ uno::UNO_QUERY );
+ if (!m_xFrame.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not create frame\n");
+ return sal_False;
+ }
+
+ // initialize frame
+ m_xFrame->initialize( m_xUnoWin );
+
+ try
+ {
+ // currently ignore errors in this code
+ uno::Reference< beans::XPropertySet > xFrameProps( m_xFrame, uno::UNO_QUERY_THROW );
+ uno::Reference< beans::XPropertySet > xLMProps;
+ xFrameProps->getPropertyValue( ::rtl::OUString::createFromAscii("LayoutManager") ) >>= xLMProps;
+ if ( xLMProps.is() )
+ xLMProps->setPropertyValue( ::rtl::OUString::createFromAscii("AutomaticToolbars"), uno::makeAny( (sal_Bool)sal_False ) );
+ }
+ catch( uno::Exception& )
+ {}
+
+ // get frames supplier
+ Reference< frame::XFramesSupplier > m_xFramesSupplier(
+ mxRemoteMSF->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop") ),
+ uno::UNO_QUERY );
+ if ( !m_xFramesSupplier.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not get desktop\n");
+ return sal_False;
+ }
+
+ // get frames
+ m_xFrames = m_xFramesSupplier->getFrames();
+ if ( !m_xFrames.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not get frames from FramesSupplier\n");
+ return sal_False;
+ }
+
+ // append m_xFrame to m_xFrames
+ m_xFrames->append( m_xFrame );
+
+ // create XComponentLoader
+ Reference< frame::XComponentLoader > xLoader( m_xFrame, uno::UNO_QUERY );
+ if ( !xLoader.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not get ComponentLoader to load URL\n");
+ return sal_False;
+ }
+
+ //create stream for the document
+ Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleFileAccess(
+ mxRemoteMSF->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess") ),
+ uno::UNO_QUERY );
+ if(!xSimpleFileAccess.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not create SimpleFileAccess to load URL\n");
+ return sal_False;
+ }
+ Reference<io::XInputStream> xInputStream = xSimpleFileAccess->openFileRead( m_sURL );
+
+ if(!xInputStream.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "can not create XInputStream for URL\n");
+ return sal_False;
+ }
+
+ // prepare to load document
+ debug_fprintf(NSP_LOG_APPEND, "try to load document\n");
+ Sequence< ::com::sun::star::beans::PropertyValue > setPropValues(3);
+ setPropValues[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ViewOnly") );
+ setPropValues[0].Value <<= sal_True;
+ setPropValues[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ReadOnly") );
+ setPropValues[1].Value <<= sal_True;
+ setPropValues[2].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream"));
+ setPropValues[2].Value <<= xInputStream;
+ /*
+ setPropValues[ 3 ].Name = "FilterName";
+ setPropValues[ 3 ].Value = "Flat XML File";*/
+
+ debug_fprintf(NSP_LOG_APPEND, "try to load copy of URL from local file %s:%d\n",
+ ::rtl::OUStringToOString( m_sURL, RTL_TEXTENCODING_ASCII_US ).getStr( ),
+ m_sURL.getLength() );
+
+
+ // load document
+/*
+ m_xComponent = xLoader->loadComponentFromURL(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("private:stream")), //m_sURL,
+ m_xFrame->getName(), 0, setPropValues );
+ */
+
+ Sequence< ::com::sun::star::beans::PropertyValue > setPropValues2(3);
+ setPropValues2[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ViewOnly") );
+ setPropValues2[0].Value <<= sal_True;
+ setPropValues2[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ReadOnly") );
+ setPropValues2[1].Value <<= sal_True;
+ setPropValues2[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("AsTemplate") );
+ setPropValues2[2].Value <<= sal_False;
+ m_xComponent = xLoader->loadComponentFromURL(
+ m_sURL,
+ m_xFrame->getName(), 0, setPropValues2 );
+
+ if ( !m_xComponent.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "print by Nsplugin, Load Componment error\n");
+ return sal_False;
+ }
+
+ // register the closelistener that will prevent closing of the component
+ Reference< util::XCloseable > xCloseable( m_xFrame, uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ {
+ m_pCloseListener = new PluginDocumentClosePreventer();
+ m_xCloseListener = Reference< util::XCloseListener >( m_pCloseListener );
+ xCloseable->addCloseListener( m_xCloseListener );
+ }
+
+ //free the input stream, it is hold by the m_xComponent
+ xInputStream = Reference<io::XInputStream>();
+
+ debug_fprintf(NSP_LOG_APPEND, "load document success\n");
+
+ // create frame::XDispatchHelper and frame::XDispatchProvider
+ m_xDispatcher = Reference< frame::XDispatchHelper > (
+ mxRemoteMSF->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")),
+ uno::UNO_QUERY );
+ if(!m_xDispatcher.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "m_xDispatcher can not be getten\n");
+ return sal_False;
+ }
+ m_xDispatchProvider = Reference< frame::XDispatchProvider >(m_xFrame, uno::UNO_QUERY);
+ if(!m_xDispatchProvider.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "m_xDispatchProvider can not be getten\n");
+ return sal_False;
+ }
+
+ //try to enable toolbar and tool windows
+ Sequence< ::com::sun::star::beans::PropertyValue > propertyValue(1);
+ propertyValue[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("FunctionBarVisible") );
+ propertyValue[0].Value <<= sal_True;
+ m_xDispatcher->executeDispatch(m_xDispatchProvider,
+ ::rtl::OUString::createFromAscii(".uno:FunctionBarVisible"),
+ m_xFrame->getName(), 0,
+ propertyValue );
+
+ // reset window style of parent window
+#ifdef WNT
+ m_dParentStyl = ::NSP_ResetWinStyl (m_hParent);
+#endif
+ m_bInit = sal_True;
+
+ try
+ {
+ // in case of presentation try to set the mode of slide-show, and start it
+ uno::Reference< presentation::XPresentationSupplier > xPresSuppl( m_xComponent, uno::UNO_QUERY_THROW );
+ uno::Reference< presentation::XPresentation > xPres( xPresSuppl->getPresentation(), uno::UNO_SET_THROW );
+ uno::Reference< beans::XPropertySet > xProps( xPresSuppl->getPresentation(), uno::UNO_QUERY_THROW );
+ xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFullScreen" ) ), uno::makeAny( sal_False ) );
+ xPres->start();
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ catch( uno::Exception& e )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "Unknown exception while loading document in netscape plugin windows\n");
+ OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
+ debug_fprintf(NSP_LOG_APPEND, "error: %s \n", o.pData->buffer );
+ return sal_False;
+ }
+ return sal_True;
+}
+
+sal_Bool SoPluginInstance::SetWindow(NSP_HWND hParent, int x, int y, int w, int h)
+{
+ sal_Bool bRetval(sal_True);
+
+ if ( m_hParent && !hParent )
+ {
+ // the plugin instance has the parent window set already and now it becomes NULL as parent window
+ // that means that the instance should be closed
+ Destroy();
+ m_hParent = hParent;
+ }
+ else
+ {
+ m_hParent = hParent;
+
+ debug_fprintf(NSP_LOG_APPEND, "SoPluginInstance::SetWindow %s : %d\n",
+ ::rtl::OUStringToOString(m_sURL, RTL_TEXTENCODING_ASCII_US).getStr(),
+ m_sURL.getLength() );
+ m_nWidth = w;
+ m_nHeight =h;
+ m_nX = x;
+ m_nY = y;
+
+ if (0 == m_sURL.getLength())
+ return sal_True;
+
+ if(!mxRemoteMSF.is())
+ {
+ debug_fprintf(NSP_LOG_APPEND, "Remote StarOfiice ServiceManager is not initilzed correctly!\n");
+ return sal_False;
+ }
+ debug_fprintf(NSP_LOG_APPEND, "in SoPluginInstance::SetWindow, begin LoadDocument(hParent)\n");
+ bRetval = LoadDocument(hParent); // Load document into current window
+ if(!bRetval){
+ // try to reload document again
+ debug_fprintf(NSP_LOG_APPEND, "load document error, try to reload it once again\n");
+ mxRemoteMSF = Reference< XMultiServiceFactory >();
+ m_bInit = sal_False;
+ bRetval = LoadDocument(hParent);
+ debug_fprintf(NSP_LOG_APPEND, "load document again, return %d\n", bRetval);
+ }
+ }
+
+ return bRetval;
+}
+
+sal_Bool SoPluginInstance::Destroy(void)
+{
+#ifdef WNT
+ if(m_dParentStyl != 0)
+ NSP_RestoreWinStyl(m_hParent, m_dParentStyl);
+#endif
+// if(m_xDispatcher.is()){
+// m_xDispatcher->executeDispatch(m_xDispatchProvider,
+// ::rtl::OUString::createFromAscii(".uno:CloseFrame"),
+// ::rtl::OUString::createFromAscii("_top"), 0,
+// Sequence< ::com::sun::star::beans::PropertyValue >() );
+// }
+
+ uno::Reference< util::XCloseable > xCloseable( m_xFrame, uno::UNO_QUERY );
+
+ try
+ {
+ if ( m_xCloseListener.is() )
+ {
+ if ( m_pCloseListener )
+ m_pCloseListener->StopPreventClose();
+
+ if ( xCloseable.is() )
+ xCloseable->removeCloseListener( m_xCloseListener );
+ }
+ }
+ catch( uno::Exception& )
+ {}
+
+ try
+ {
+ uno::Sequence< uno::Any > aArgs( 1 );
+ aArgs[0] <<= m_xFrame;
+ uno::Reference< lang::XComponent > xDocumentCloser(
+ mxRemoteMSF->createInstanceWithArguments(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.DocumentCloser" ) ),
+ aArgs ),
+ uno::UNO_QUERY_THROW );
+
+ xDocumentCloser->dispose(); // this call should close the document
+ }
+ catch( uno::Exception& )
+ {
+ debug_fprintf(NSP_LOG_APPEND, "print by Nsplugin.exe, could not close the document correctly!\n");
+ try
+ {
+ if ( xCloseable.is() )
+ xCloseable->close( sal_True );
+ else
+ {
+ uno::Reference< lang::XComponent > xDisposable( m_xFrame, uno::UNO_QUERY );
+ if ( xDisposable.is() )
+ xDisposable->dispose();
+ }
+ }
+ catch (const uno::Exception&)
+ {
+ }
+ }
+
+ m_xUnoWin = Reference< awt::XWindow >();
+ m_xComponent = Reference< XComponent >();
+ m_xFrame = Reference< frame::XFrame >();
+ m_xFrames = Reference< frame::XFrames >();
+ m_xDispatcher = Reference< frame::XDispatchHelper >();
+ m_xDispatchProvider = Reference< frame::XDispatchProvider >();
+ return sal_True;
+}
+
+sal_Bool SoPluginInstance::Print(void)
+{
+ if(!m_xDispatcher.is())
+ return sal_False;
+
+ Sequence< ::com::sun::star::beans::PropertyValue > propertyValue(1);
+ m_xDispatcher->executeDispatch(m_xDispatchProvider,
+ ::rtl::OUString::createFromAscii(".uno:PrintDefault"),
+ m_xFrame->getName(), 0,
+ propertyValue );
+ return sal_True;
+}
diff --git a/extensions/source/nsplugin/source/so_instance.hxx b/extensions/source/nsplugin/source/so_instance.hxx
new file mode 100644
index 000000000000..e95bb7c024ec
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_instance.hxx
@@ -0,0 +1,110 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __SO_INSTANCE_HXX__
+#define __SO_INSTANCE_HXX__
+
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <osl/diagnose.h>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
+#include <com/sun/star/uno/XNamingService.hpp>
+#include <com/sun/star/connection/ConnectionSetupException.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/util/XCloseListener.hpp>
+#include <cppuhelper/bootstrap.hxx>
+#include <com/sun/star/awt/WindowDescriptor.hpp>
+#include <rtl/ustring.hxx>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XDispatchHelper.hpp>
+
+#include "ns_debug.hxx"
+
+typedef sal_Int32 NSP_HWND;
+
+class PluginDocumentClosePreventer;
+class SoPluginInstance
+{
+
+private:
+ // Service manager of remote Soffice
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxRemoteMSF;
+ // Dir where Soffice is in, ie. /Soffice7/program
+ static char sSO_Dir[NPP_PATH_MAX];
+ int m_nWidth;
+ int m_nHeight;
+ int m_nX;
+ int m_nY;
+ sal_Int16 m_nFlag; // Set to 12 during initialization
+ ::rtl::OUString m_sURL; // URL of the document to be loaded
+ sal_Bool m_bInit; // If the Plugin instance is initilaized.
+ NSP_HWND m_hParent; // Windows handle of parent window
+ long m_pParent; // ID of this instance - get from NPP
+ // StarOffice window
+ ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xUnoWin;
+ // StarOffice component window
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xComponent;
+ // StarOffice frame for this Plugin
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
+ // Frames of StarOffice
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrames > m_xFrames;
+ // Dispatcher of frame
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchHelper > m_xDispatcher;
+ // DispatchProvider of frame
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > m_xDispatchProvider;
+
+ // the closelistener that will prevent document closing
+ PluginDocumentClosePreventer* m_pCloseListener;
+ ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener > m_xCloseListener;
+
+ sal_Bool LoadDocument(NSP_HWND hParent);
+
+ long m_dParentStyl; // Old Windows style of parent window
+
+
+public:
+ SoPluginInstance(long iInstance, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF);
+ virtual ~SoPluginInstance(void);
+ virtual sal_Bool SetURL(char* aURL);
+ virtual sal_Bool IsInit(void){return m_bInit;};
+ virtual sal_Bool SetWindow(NSP_HWND hParent, int x, int y, int w, int h) ;
+ virtual sal_Bool Destroy(void) ;
+ virtual sal_Bool Print(void) ;
+
+ static sal_Bool ShutDown(void);
+ static char* GetSODir(void) {return sSO_Dir;};
+ long GetParent(void) {return m_pParent;};
+};
+
+#endif
diff --git a/extensions/source/nsplugin/source/so_main.cxx b/extensions/source/nsplugin/source/so_main.cxx
new file mode 100644
index 000000000000..49c899994424
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_main.cxx
@@ -0,0 +1,497 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_extensions.hxx"
+#ifdef UNIX
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#endif //end of UNIX
+
+#ifdef WNT
+#ifdef _MSC_VER
+#pragma once
+#endif
+#pragma warning (push,1)
+#pragma warning (disable:4668)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <winsock2.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <memory.h>
+#include <tchar.h>
+#pragma warning (pop)
+#endif //end of WNT
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "boost/scoped_array.hpp"
+
+#include "ns_debug.hxx"
+#include "so_msg.hxx"
+#include "so_instance.hxx"
+#include "so_env.hxx"
+
+#include "nsp_func.hxx"
+
+#include "sal/main.h"
+
+#include "rtl/process.h"
+#include "rtl/bootstrap.hxx"
+#include "rtl/string.hxx"
+#include "rtl/ustrbuf.hxx"
+
+#include "osl/security.hxx"
+#include "osl/thread.hxx"
+
+#include "cppuhelper/bootstrap.hxx"
+
+
+
+#include "com/sun/star/uno/XComponentContext.hpp"
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "com/sun/star/bridge/UnoUrlResolver.hpp"
+#include "com/sun/star/bridge/XUnoUrlResolver.hpp"
+
+#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
+#define ARLEN(x) sizeof (x) / sizeof *(x)
+
+using namespace ::rtl;
+using namespace ::osl;
+using namespace ::cppu;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+
+#define MAX_NODE_NUM 1024
+
+SoPluginInstance* lpInstance[MAX_NODE_NUM];
+
+static NSP_PIPE_FD la_read_fd = 0;
+static char const * progdir = NULL;
+
+
+long int NSP_ReadFromPipe(NSP_PIPE_FD fp, void* buf, unsigned long int len)
+{
+ unsigned long int len_unix = 0, len_wnt = 0;
+
+ len_unix = NSP_Read_Pipe(fp, buf, len, &len_wnt);
+#ifdef UNIX
+ (void)len_wnt;
+ return len_unix;
+#endif //end of UNIX
+#ifdef WNT
+ return len_wnt;
+#endif //end of WNT
+
+}
+
+int find_free_node()
+{
+ for(int i=0; i<MAX_NODE_NUM; i++)
+ {
+ if(NULL == lpInstance[i])
+ return i;
+ }
+ return -1;
+}
+
+int find_cur_node(long cur_id)
+{
+ for(int i=0; i<MAX_NODE_NUM; i++)
+ {
+ if(lpInstance[i] == NULL)
+ continue;
+ if(cur_id == lpInstance[i]->GetParent())
+ return i;
+ }
+ return -1;
+}
+
+sal_Bool dump_plugin_message(PLUGIN_MSG* pMsg)
+{
+ if (!pMsg)
+ return sal_False;
+ debug_fprintf(NSP_LOG_APPEND, "NSPlugin Message: msg_id:%d; instance_id:%d;wnd_id:%d;wnd_x:%d;wnd_y:%d;wnd_w:%d;wnd_h:%d; url:%s\n",
+ pMsg->msg_id, pMsg->instance_id, pMsg->wnd_id,
+ pMsg->wnd_x, pMsg->wnd_y, pMsg->wnd_w, pMsg->wnd_h, pMsg->url);
+ return sal_True;
+}
+
+int Set_Window(PLUGIN_MSG* pMsg)
+{
+ dump_plugin_message(pMsg);
+ int cur_no;
+ if( -1 == (cur_no = find_cur_node(pMsg->instance_id)))
+ return -1;
+ if(lpInstance[cur_no]->SetWindow(pMsg->wnd_id,
+ pMsg->wnd_x, pMsg->wnd_y, pMsg->wnd_w, pMsg->wnd_h))
+ return 0;
+ else
+ return -1;
+}
+
+int Set_URL(PLUGIN_MSG* pMsg)
+{
+ dump_plugin_message(pMsg);
+ int cur_no;
+ if( -1 == (cur_no = find_cur_node(pMsg->instance_id)))
+ return -1;
+ if(lpInstance[cur_no]->SetURL(pMsg->url))
+ return 0;
+ else
+ return -1;
+}
+
+int New_Instance(PLUGIN_MSG* pMsg, Reference< lang::XMultiServiceFactory > xMSF)
+{
+ dump_plugin_message(pMsg);
+ int free_no;
+ if( -1 == (free_no = find_free_node()))
+ return -1;
+ lpInstance[free_no] = new SoPluginInstance(pMsg->instance_id, xMSF);
+ return 0;
+}
+
+int Destroy(PLUGIN_MSG* pMsg)
+{
+ dump_plugin_message(pMsg);
+ int cur_no;
+ if( -1 == (cur_no = find_cur_node(pMsg->instance_id)))
+ return -1;
+ if(lpInstance[cur_no] != NULL)
+ {
+ lpInstance[cur_no]->Destroy();
+ debug_fprintf(NSP_LOG_APPEND, "print by Nsplugin, begin delete.\n");
+ delete(lpInstance[cur_no]);
+ lpInstance[cur_no] = NULL;
+ }
+ return 0;
+}
+
+int Print(PLUGIN_MSG* pMsg)
+{
+ dump_plugin_message(pMsg);
+ int cur_no;
+ if( -1 == (cur_no = find_cur_node(pMsg->instance_id)))
+ return -1;
+ if(lpInstance[cur_no] != NULL)
+ {
+ lpInstance[cur_no]->Print();
+ }
+ return 0;
+}
+
+int Shutdown()
+{
+ for(int cur_no=0; cur_no<MAX_NODE_NUM; cur_no++)
+ {
+ if(lpInstance[cur_no] == NULL)
+ continue;
+ lpInstance[cur_no]->Destroy();
+ debug_fprintf(NSP_LOG_APPEND, "print by Nsplugin, begin delete.\n");
+ delete(lpInstance[cur_no]);
+ lpInstance[cur_no] = NULL;
+ }
+ return -1;
+}
+
+int dispatchMsg(PLUGIN_MSG* pMsg, Reference< lang::XMultiServiceFactory > xMSF)
+{
+ switch(pMsg->msg_id)
+ {
+ case SO_SET_WINDOW:
+ return Set_Window(pMsg);
+ case SO_NEW_INSTANCE:
+ if(xMSF.is())
+ return New_Instance(pMsg, xMSF);
+ case SO_SET_URL:
+ return Set_URL(pMsg);
+ case SO_DESTROY:
+ return Destroy(pMsg);
+ case SO_SHUTDOWN:
+ Shutdown();
+ return -1;
+ case SO_PRINT:
+ Print(pMsg);
+ return 0;
+ default:
+ return -1;
+ }
+}
+
+Reference< lang::XMultiServiceFactory > SAL_CALL start_office(NSP_PIPE_FD read_fd)
+{
+ Reference< XComponentContext > xRemoteContext;
+
+ try
+ {
+ OUString aOfficePath;
+
+#ifdef UNIX
+ boost::scoped_array< char > exepath(
+ new char[( progdir ? strlen( progdir ) : 0 ) + RTL_CONSTASCII_LENGTH( "/soffice" ) + 1] );
+ if ( progdir )
+ sprintf( exepath.get(), "%s/soffice", progdir );
+ else
+ sprintf( exepath.get(), "soffice" );
+ if (!rtl_convertStringToUString(
+ &aOfficePath.pData, exepath.get(), strlen(exepath.get()), osl_getThreadTextEncoding(),
+ (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
+ RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
+ RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
+ {
+ debug_fprintf(NSP_LOG_APPEND,"bad characters in soffice installation path!\n");
+ return Reference< lang::XMultiServiceFactory >(NULL);
+ }
+#endif //end of UNIX
+#ifdef WNT
+ char sPath[NPP_PATH_MAX];
+ sPath[0] = 0;
+
+ // The quotes will be added in osl_executeProcess
+ sprintf(sPath, "%s", findSofficeExecutable() );
+ if (!rtl_convertStringToUString(
+ &aOfficePath.pData, sPath, strlen(sPath), osl_getThreadTextEncoding(),
+ (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
+ RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
+ RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
+ {
+ debug_fprintf(NSP_LOG_APPEND,"bad characters in soffice installation path!\n");
+ return Reference< lang::XMultiServiceFactory >(NULL);
+ }
+#endif //end of WNT
+
+ // create default local component context
+ Reference< XComponentContext > xLocalContext(
+ defaultBootstrap_InitialComponentContext() );
+ if ( !xLocalContext.is() )
+ {
+ debug_fprintf(NSP_LOG_APPEND,"no local component context!\n");
+ return Reference< lang::XMultiServiceFactory >(NULL);
+ }
+
+ // env string
+ ::rtl::OUStringBuffer buf;
+ OUString aIniPath, aPluginPipeName;
+
+ if(!Bootstrap::get(OUSTR("BRAND_BASE_DIR"), aIniPath))
+ {
+ debug_fprintf(NSP_LOG_APPEND,"failed to get BRAND_BASE_DIR!\n");
+ return Reference< lang::XMultiServiceFactory >(NULL);
+ }
+ aIniPath += OUSTR("/program/");
+ aIniPath += OUSTR(SAL_CONFIGFILE("bootstrap"));
+ Bootstrap aVersionFile(aIniPath);
+ aVersionFile.getFrom(OUSTR("BaseInstallation"), aPluginPipeName, OUString());
+
+ aPluginPipeName = ::rtl::OUString::valueOf( aPluginPipeName.hashCode() );
+
+ // accept string
+ OSL_ASSERT( buf.getLength() == 0 );
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "-accept=pipe,name=" ) );
+ buf.append( aPluginPipeName ); //user installation path as pipe name
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ";urp;" ) );
+ OUString sConnectStartString( buf.makeStringAndClear() );
+
+ // arguments
+ OUString args [] = {
+ OUSTR( "-nologo" ),
+ OUSTR( "-nodefault" ),
+ OUSTR( "-nolockcheck" ),
+ sConnectStartString,
+ };
+
+ // create a URL resolver
+ Reference< bridge::XUnoUrlResolver > xUrlResolver(
+ bridge::UnoUrlResolver::create( xLocalContext ) );
+
+ // connection string
+ OSL_ASSERT( buf.getLength() == 0 );
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "uno:pipe,name=" ) );
+ buf.append( aPluginPipeName );
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
+ ";urp;StarOffice.ComponentContext" ) );
+ OUString sConnectString( buf.makeStringAndClear() );
+
+ try
+ {
+ // try to connect to office, no need to start instance again if office already started
+ xRemoteContext.set(
+ xUrlResolver->resolve( sConnectString ), UNO_QUERY_THROW );
+ debug_fprintf(NSP_LOG_APPEND, "Staroffice already start\n");
+ return Reference< lang::XMultiServiceFactory >(xRemoteContext->getServiceManager(), UNO_QUERY);
+ }
+ catch ( connection::NoConnectException & )
+ {
+ }
+
+ // start office process
+#ifdef UNIX
+ // a temporary solution
+ // in future the process should be started using the osl_executeProcess call
+ int nChildPID = fork();
+ if( ! nChildPID ) // child process
+ {
+ NSP_Close_Pipe(read_fd);
+ execl( "/bin/sh",
+ "/bin/sh",
+ ::rtl::OUStringToOString( aOfficePath, osl_getThreadTextEncoding() ).getStr(),
+ ::rtl::OUStringToOString( args[0], osl_getThreadTextEncoding() ).getStr(),
+ ::rtl::OUStringToOString( args[1], osl_getThreadTextEncoding() ).getStr(),
+ ::rtl::OUStringToOString( args[2], osl_getThreadTextEncoding() ).getStr(),
+ ::rtl::OUStringToOString( args[3], osl_getThreadTextEncoding() ).getStr(),
+ NULL);
+ _exit(255);
+ }
+#else
+ (void) read_fd; /* avoid warning about unused parameter */
+ Security sec;
+ oslProcess hProcess = 0;
+ rtl_uString * ar_args [] = {
+ args[ 0 ].pData,
+ args[ 1 ].pData,
+ args[ 2 ].pData,
+ args[ 3 ].pData,
+ };
+
+ oslProcessError rc = osl_executeProcess(
+ aOfficePath.pData,
+ ar_args,
+ ARLEN( ar_args ),
+ osl_Process_DETACHED,
+ sec.getHandle(),
+ 0, // => current working dir
+ 0,
+ 0, // => no env vars
+ &hProcess );
+ switch ( rc )
+ {
+ case osl_Process_E_None:
+ osl_freeProcessHandle( hProcess );
+ break;
+ default:
+ debug_fprintf(NSP_LOG_APPEND, "unmapped error!\n");
+ return Reference< lang::XMultiServiceFactory >(NULL);
+ }
+#endif
+
+ // wait until office is started
+ for ( int i = 0; i < 240 /* stop the connection after 240 * 500ms */; ++i )
+ {
+ try
+ {
+ // try to connect to office
+ xRemoteContext.set(
+ xUrlResolver->resolve( sConnectString ), UNO_QUERY_THROW );
+ return Reference< lang::XMultiServiceFactory >(xRemoteContext->getServiceManager(), UNO_QUERY);
+ }
+ catch ( connection::NoConnectException & )
+ {
+ // wait 500 ms, then try to connect again
+ TimeValue tv = { 0 /* secs */, 500000000 /* nanosecs */ };
+ ::osl::Thread::wait( tv );
+ }
+ }
+ debug_fprintf(NSP_LOG_APPEND, "Failed to connect to Staroffice in 2 minutes\n");
+ return Reference< lang::XMultiServiceFactory >(NULL);
+ }
+ catch ( Exception & e)
+ {
+ debug_fprintf(NSP_LOG_APPEND, "unexpected UNO exception caught: ");
+ debug_fprintf(NSP_LOG_APPEND, (sal_Char *)e.Message.getStr());
+ return Reference< lang::XMultiServiceFactory >(NULL);
+ }
+
+}
+
+
+SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
+{
+ // Sleep(20*1000);
+ debug_fprintf(NSP_LOG_APPEND, "start of main\n");
+ memset(lpInstance, 0, sizeof(lpInstance));
+
+ // MessageBox( NULL, "nsplugin has been started", "Info", MB_OK );
+
+ NSP_PIPE_FD fd_pipe[2];
+ int iPipe[2];
+ if(argc < 3)
+ {
+ debug_fprintf(NSP_LOG_APPEND, "print by nsplugin, command error; too little argument to start plugin exec\n");
+ return EXIT_FAILURE;
+ }
+ iPipe[0] = atoi(argv[1]);
+ iPipe[1] = atoi(argv[2]);
+
+ // fd_pipe[0]: read, fd_pipe[0]: write
+ fd_pipe[0] = (NSP_PIPE_FD) iPipe[0] ;
+ fd_pipe[1] = (NSP_PIPE_FD) iPipe[1] ;
+ NSP_Close_Pipe(fd_pipe[1]);
+
+ la_read_fd = fd_pipe[0];
+ if(la_read_fd < 0)
+ {
+ debug_fprintf(NSP_LOG_APPEND, "print by nsplugin, command error: bad read file id:%s \n", la_read_fd);
+ return 0;
+ }
+
+ // the program path is provided only on unix, on windows the registry entry is used
+ if ( argc > 4 )
+ progdir = argv[4];
+
+ Reference< lang::XMultiServiceFactory > xFactory = start_office(la_read_fd);
+ if(!xFactory.is())
+ {
+ NSP_Close_Pipe(la_read_fd);
+ return -1;
+ }
+ PLUGIN_MSG nMsg;
+ int len;
+ while(1)
+ {
+ memset(&nMsg, 0, sizeof(PLUGIN_MSG));
+ len = NSP_ReadFromPipe(la_read_fd, (char*)&nMsg, sizeof(PLUGIN_MSG));
+ if(len != sizeof(PLUGIN_MSG))
+ break;
+ debug_fprintf(NSP_LOG_APPEND, "Read message from pipe type %d \n", nMsg.msg_id);
+ if(-1 == dispatchMsg(&nMsg, xFactory))
+ {
+ debug_fprintf(NSP_LOG_APPEND, "plugin will shutdown\n");
+ break;
+ }
+ }
+ NSP_Close_Pipe(la_read_fd);
+ _exit(0);
+ return EXIT_SUCCESS; // avoid warnings
+}
diff --git a/extensions/source/nsplugin/source/so_msg.hxx b/extensions/source/nsplugin/source/so_msg.hxx
new file mode 100644
index 000000000000..ee3d5fff75f8
--- /dev/null
+++ b/extensions/source/nsplugin/source/so_msg.hxx
@@ -0,0 +1,54 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __PLUGIN_MSG_HXX
+#define __PLUGIN_MSG_HXX
+enum msg_type
+{
+ SO_EMPTY, // 0
+ SO_SET_WINDOW, // 1
+ SO_SET_URL, // 2
+ SO_NEW_INSTANCE, // 3
+ SO_DESTROY, // 4
+ SO_SHUTDOWN, // 5
+ SO_PRINT // 6
+};
+
+#define plugin_Int32 unsigned long int
+
+typedef struct _PLUGIN_MSG {
+ plugin_Int32 msg_id;
+ plugin_Int32 instance_id;
+ plugin_Int32 wnd_id;
+ plugin_Int32 wnd_x;
+ plugin_Int32 wnd_y;
+ plugin_Int32 wnd_w;
+ plugin_Int32 wnd_h;
+ char url[484];
+} PLUGIN_MSG;
+
+#endif