summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2011-02-18 08:51:26 -0800
committerDan Nicholson <dbn.lists@gmail.com>2011-02-18 09:09:38 -0800
commit90d6e49e02c364b5a46d4336bea34c2e8dab8c07 (patch)
tree4c3a7b61e74048b0d0d890c7224a37e4b4c5b1e4
parent8e1ac838c4f72d48f6ab8181ee0391a2b094e28a (diff)
plugin: Only initialize backends once
Some of the plugin backends (I think evince in particular), don't react well when they're initialized repeatedly. Since we build the MIME string dynamically, we need to do initialization from both NP_Initialize and NP_GetMIMEDescription. Just move all the init and shutdown code to their own functions and make sure we only do it once.
-rw-r--r--plugin/evbp.c62
1 files changed, 46 insertions, 16 deletions
diff --git a/plugin/evbp.c b/plugin/evbp.c
index 24123b0..a26d39c 100644
--- a/plugin/evbp.c
+++ b/plugin/evbp.c
@@ -27,6 +27,49 @@
static char *evbp_mime_string = NULL;
static const NPNetscapeFuncs *npn_funcs = NULL;
+static gboolean evbp_is_initialized = FALSE;
+
+static gboolean
+evbp_initialize(void)
+{
+ /* Some backends don't handle repeated init */
+ if (evbp_is_initialized)
+ return TRUE;
+
+ /* Init glib threads asap */
+ if (!g_thread_supported())
+ g_thread_init(NULL);
+
+#ifdef ENABLE_NLS
+ /* Initialize the i18n stuff */
+ bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+ textdomain(GETTEXT_PACKAGE);
+#endif
+
+ /* Initialize gtk */
+ gtk_init(NULL, NULL);
+
+ /* Initialize evince */
+ if (!ev_init())
+ return FALSE;
+ ev_stock_icons_init();
+
+ evbp_is_initialized = TRUE;
+ return TRUE;
+}
+
+static void
+evbp_shutdown(void)
+{
+ if (!evbp_is_initialized)
+ return;
+
+ ev_shutdown();
+ ev_stock_icons_shutdown();
+
+ evbp_is_initialized = FALSE;
+}
static NPError
evbp_new(NPMIMEType pluginType, NPP instance, uint16_t mode,
@@ -196,20 +239,8 @@ NP_Initialize(NPNetscapeFuncs *nfuncs, NPPluginFuncs *pfuncs)
if (ret != NPERR_NO_ERROR)
return ret;
- /* Initialize gtk */
- gtk_init(NULL, NULL);
-
-#ifdef ENABLE_NLS
- /* Initialize the i18n stuff */
- bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
-#endif
-
- /* Initialize evince */
- if (!ev_init())
+ if (!evbp_initialize())
return NPERR_MODULE_LOAD_FAILED_ERROR;
- ev_stock_icons_init();
return NPERR_NO_ERROR;
}
@@ -225,7 +256,7 @@ NP_GetMIMEDescription(void)
{
GString *mimes;
- if (!ev_init())
+ if (!evbp_initialize())
return NULL;
mimes = evbp_get_mime_description();
@@ -245,8 +276,7 @@ NP_Shutdown(void)
}
npn_funcs = NULL;
- ev_shutdown();
- ev_stock_icons_shutdown();
+ evbp_shutdown();
return NPERR_NO_ERROR;
}