Beispiel #1
0
NPError
NP_Initialize (NPNetscapeFuncs *mozilla_funcs, NPPluginFuncs *plugin_funcs)
{
	MoonlightPlugin *moon_host = MMP_HANDLE ();
	gsize mozilla_funcs_size;

	MOON_CHECK_LOAD_PLUGIN ();

	mp_debug ("NP_Initialize (%p, %p)", mozilla_funcs, plugin_funcs);

	// Copy the Mozilla function table
	mozilla_funcs_size = sizeof (NPNetscapeFuncs);
	memset (&moon_host->mozilla_funcs, 0, mozilla_funcs_size);
	mozilla_funcs_size = mozilla_funcs->size < mozilla_funcs_size
		? mozilla_funcs->size
		: mozilla_funcs_size;
	memcpy (&moon_host->mozilla_funcs, mozilla_funcs, mozilla_funcs_size);
	moon_host->mozilla_funcs.size = sizeof (moon_host->mozilla_funcs);

	// Proxy NP_Initialize to Moonlight
	if (MMP_HANDLE ()->np_initialize != NULL) {
		NPError result = MMP_HANDLE ()->np_initialize (&moon_host->mozilla_funcs, plugin_funcs);
		if (result == NPERR_NO_ERROR) {
			// Override some Moonlight NPP functions
			moon_host->moon_npp_new = plugin_funcs->newp;
			plugin_funcs->newp = mmp_binder_npp_new;

			moon_host->moon_npp_destroy = plugin_funcs->destroy;
			plugin_funcs->destroy = mmp_binder_npp_destroy;

			moon_host->moon_npp_stream_as_file = plugin_funcs->asfile;
			plugin_funcs->asfile = mmp_binder_npp_stream_as_file;
		} else {
			mp_error ("Unknown error in libmoonloader's NP_Initialize: %d", result);
		}

		return result;
	}

	mp_error ("Could not call NP_Initialize from libmoonloader (NULL)");

	return NPERR_GENERIC_ERROR;
}
Beispiel #2
0
bool
mp_app_grab_mm_keys(struct appdata *ad)
{
	utilx_grab_key(ecore_x_display_get(), ad->xwin, KEY_MEDIA, OR_EXCLUSIVE_GRAB);
	int err = media_key_reserve(_mp_app_media_key_event_cb, ad);
	if (err != MEDIA_KEY_ERROR_NONE) {
		mp_error("media_key_reserve().. [0x%x]", err);
		return false;
	}

	return true;
}
Beispiel #3
0
static gboolean
mmp_plugin_proxy_load_module (gchar *prefix)
{
	MoonlightPlugin *plugin_host = MMP_HANDLE ();

	// Moonlight's loader is named libmoonloader if it is installed as a
	// package, and libmoonloaderxpi if it is installed as an XPI
	gchar *path = g_module_build_path (prefix, "moonloader");
	if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
		g_free (path);
		path = g_module_build_path (prefix, "moonloaderxpi");
		if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
			g_free (path);
			return FALSE;
		}
	}

	plugin_host->module = g_module_open (path, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
	
	if (plugin_host->module != NULL
		&& mmp_plugin_proxy_load_symbol ("NP_Initialize", (gpointer *)&plugin_host->np_initialize)
		&& mmp_plugin_proxy_load_symbol ("NP_Shutdown", (gpointer *)&plugin_host->np_shutdown)
		&& mmp_plugin_proxy_load_symbol ("NP_GetValue", (gpointer *)&plugin_host->np_getvalue)) {
		mp_debug ("Loaded Moonlight plugin: %s", path);
		g_free (path);
		return TRUE;
	} else if (plugin_host->module != NULL) {
		if (!g_module_close (plugin_host->module)) {
			mp_error ("Could not unload library that was loaded but had invalid symbols: %s (%s)",
				path, g_module_error ());
		}
		plugin_host->module = NULL;
	}
	
	mp_error ("Could not load Moonlight plugin: %s (%s)", path, g_module_error ());

	g_free (path);
	return FALSE;
}
Beispiel #4
0
static gboolean
mmp_plugin_proxy_load_symbol (const gchar *symbol_name, gpointer *symbol)
{
	MoonlightPlugin *plugin_host = MMP_HANDLE ();

	if (!g_module_symbol (plugin_host->module, symbol_name, symbol)) {
		mp_error ("Could not locate '%s' symbol in Moonlight plugin (%s)",
			symbol_name, g_module_error ());

		g_module_close (plugin_host->module);
		plugin_host->module = NULL;

		return FALSE;
	}

	return TRUE;
}
Beispiel #5
0
static NPError
mmp_plugin_proxy_load_moonlight ()
{
	static gchar *search_prefixes [] = {
		NULL,
		NULL,
		NULL,
		(gchar *)"/usr/lib/moon/plugin",
		(gchar *)"/usr/lib64/moon/plugin",
		(gchar *)"/usr/local/lib/moon/plugin",
		(gchar *)"/usr/local/lib64/moon/plugin",
		(gchar *)INSTALL_PREFIX "/lib/moon/plugin",
		(gchar *)INSTALL_PREFIX "/lib64/moon/plugin"
	};

	MoonlightPlugin *plugin_host = MMP_HANDLE ();
	guint i;

	if (plugin_host->module != NULL) {
		return NPERR_NO_ERROR;
	} else if (moon_module_load_attempted) {
		return NPERR_GENERIC_ERROR;
	}

	search_prefixes[0] = (gchar *)g_getenv ("MOON_LOADER_PATH");
	search_prefixes[1] = mmp_plugin_proxy_get_xpi_moonlight_path ();
	search_prefixes[2] = g_build_filename (g_get_home_dir (), ".mozilla", "plugins", NULL);
	
	for (i = 0; i < G_N_ELEMENTS (search_prefixes) 
		&& !mmp_plugin_proxy_load_module (search_prefixes[i]); i++);

	if (search_prefixes[1] != NULL) {
		g_free (search_prefixes[1]);
	}

	g_free (search_prefixes[2]);

	moon_module_load_attempted = TRUE;
	
	if (plugin_host->module == NULL) {
		mp_error ("Could not find Moonlight's libmoonloader plugin");
		return NPERR_GENERIC_ERROR;
	}

	return NPERR_NO_ERROR;
}