Exemple #1
0
static void gui_quit(void)
{
	nserror res;

	LOG("Quitting GUI");

	/* Ensure all scaffoldings are destroyed before we go into exit */
	nsgtk_download_destroy();
	urldb_save_cookies(nsoption_charp(cookie_jar));
	urldb_save(nsoption_charp(url_file));

	res = nsgtk_cookies_destroy();
	if (res != NSERROR_OK) {
		LOG("Error finalising cookie viewer: %s",
		    messages_get_errorcode(res));
	}

	res = nsgtk_global_history_destroy();
	if (res != NSERROR_OK) {
		LOG("Error finalising global history viewer: %s",
		    messages_get_errorcode(res));
	}

	res = nsgtk_hotlist_destroy();
	if (res != NSERROR_OK) {
		LOG("Error finalising hotlist viewer: %s",
		    messages_get_errorcode(res));
	}

	free(nsgtk_config_home);

	gtk_fetch_filetype_fin();
}
Exemple #2
0
/**
 * event handler for when a completion suggestion is selected.
 */
static gboolean
nsgtk_completion_match_select(GtkEntryCompletion *widget,
			      GtkTreeModel *model,
			      GtkTreeIter *iter,
			      gpointer user_data)
{
	GValue value = {0, };
	struct nsgtk_scaffolding *g = user_data;
	struct browser_window *bw = nsgtk_get_browser_window(nsgtk_scaffolding_top_level(g));
	nserror ret;
	nsurl *url;

	gtk_tree_model_get_value(model, iter, 0, &value);

	ret = search_web_omni(g_value_get_string(&value),
			      SEARCH_WEB_OMNI_NONE,
			      &url);

	g_value_unset(&value);

	if (ret == NSERROR_OK) {
		ret = browser_window_navigate(bw,
					      url, NULL, BW_NAVIGATE_HISTORY,
					      NULL, NULL, NULL);
		nsurl_unref(url);
	}
	if (ret != NSERROR_OK) {
		nsgtk_warning(messages_get_errorcode(ret), 0);
	}

	return TRUE;
}
Exemple #3
0
gboolean nsgtk_websearch_activate(GtkWidget *widget, gpointer data)
{
	struct nsgtk_scaffolding *g = data;
	nserror ret;
	nsurl *url;

	ret = search_web_omni(
		gtk_entry_get_text(GTK_ENTRY(nsgtk_scaffolding_websearch(g))),
		SEARCH_WEB_OMNI_SEARCHONLY,
		&url);
	if (ret == NSERROR_OK) {
		temp_open_background = 0;
		ret = browser_window_create(
			BW_CREATE_HISTORY | BW_CREATE_TAB,
			url,
			NULL,
			nsgtk_get_browser_window(nsgtk_scaffolding_top_level(g)),
			NULL);
		temp_open_background = -1;
		nsurl_unref(url);
	}
	if (ret != NSERROR_OK) {
		nsgtk_warning(messages_get_errorcode(ret), 0);
	}

	return TRUE;
}
Exemple #4
0
static void __CDECL menu_open_file(short item, short title, void *data)
{

	LOG(("%s", __FUNCTION__));

	const char * filename = file_select(messages_get("OpenFile"), "");
	if( filename != NULL ){
		char * urltxt = local_file_to_url( filename );
		if( urltxt ){
			nsurl *url;
			nserror error;

			error = nsurl_create(urltxt, &url);
			if (error == NSERROR_OK) {
				error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
							      BROWSER_WINDOW_HISTORY,
							      url,
							      NULL,
							      NULL,
							      NULL);
				nsurl_unref(url);
				
			}
			if (error != NSERROR_OK) {
				warn_user(messages_get_errorcode(error), 0);
			}
			free( urltxt );
		}
	}
}
Exemple #5
0
static void __CDECL menu_about(short item, short title, void *data)
{
	nsurl *url;
	nserror error;
	char buf[PATH_MAX];

	LOG(("%s", __FUNCTION__));
	strcpy((char*)&buf, "file://");
	strncat((char*)&buf, (char*)"./doc/README.TXT",
			PATH_MAX - (strlen("file://")+1) );

	error = nsurl_create(buf, &url);
	if (error == NSERROR_OK) {
		error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
					      BROWSER_WINDOW_HISTORY,
					      url,
					      NULL,
					      NULL,
					      NULL);
		nsurl_unref(url);
	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	} 
}
Exemple #6
0
static void __CDECL menu_new_win(short item, short title, void *data)
{
	nsurl *url;
	nserror error;
	const char *addr;

	LOG(("%s", __FUNCTION__));
		
	if (nsoption_charp(homepage_url) != NULL) {
		addr = nsoption_charp(homepage_url);
	} else {
		addr = NETSURF_HOMEPAGE;
	}

	/* create an initial browser window */
	error = nsurl_create(addr, &url);
	if (error == NSERROR_OK) {
		error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
					      BROWSER_WINDOW_HISTORY,
					      url,
					      NULL,
					      NULL,
					      NULL);
		nsurl_unref(url);

	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	}
}
Exemple #7
0
static bool save_complete_save_buffer(save_complete_ctx *ctx,
		const char *leafname, const char *data, size_t data_len,
		lwc_string *mime_type)
{
	nserror ret;
	FILE *fp;
	char *fname = NULL;

	ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, leafname);
	if (ret != NSERROR_OK) {
		guit->misc->warning(messages_get_errorcode(ret), 0);
		return false;
	}

	fp = fopen(fname, "wb");
	if (fp == NULL) {
		free(fname);
		LOG("fopen(): errno = %i", errno);
		guit->misc->warning("SaveError", strerror(errno));
		return false;
	}

	fwrite(data, sizeof(*data), data_len, fp);

	fclose(fp);

	if (ctx->set_type != NULL) {
		ctx->set_type(fname, mime_type);
	}
	free(fname);

	return true;
}
Exemple #8
0
static bool save_complete_save_html_document(save_complete_ctx *ctx,
		hlcache_handle *c, bool index)
{
	nserror ret;
	FILE *fp;
	char *fname = NULL;
	dom_document *doc;
	lwc_string *mime_type;
	char filename[32];

	if (index) {
		snprintf(filename, sizeof filename, "index");
	} else {
		snprintf(filename, sizeof filename, "%p", c);
	}

	ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, filename);
	if (ret != NSERROR_OK) {
		guit->misc->warning(messages_get_errorcode(ret), NULL);
		return false;
	}

	fp = fopen(fname, "wb");
	if (fp == NULL) {
		free(fname);
		LOG("fopen(): errno = %i", errno);
		guit->misc->warning("SaveError", strerror(errno));
		return false;
	}

	ctx->base = html_get_base_url(c);
	ctx->fp = fp;
	ctx->iter_state = STATE_NORMAL;

	doc = html_get_document(c);

	if (save_complete_libdom_treewalk((dom_node *) doc,
			save_complete_node_handler, ctx) == false) {
		free(fname);
		guit->misc->warning("NoMemory", 0);
		fclose(fp);
		return false;
	}

	fclose(fp);

	mime_type = content_get_mime_type(c);
	if (mime_type != NULL) {
		if (ctx->set_type != NULL)
			ctx->set_type(fname, mime_type);

		lwc_string_unref(mime_type);
	}
	free(fname);

	return true;
}
Exemple #9
0
bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
		wimp_selection *selection, menu_action action)
{
	nsurl *url;
	nserror error;

	if (w != wimp_ICON_BAR || i != wimp_ICON_WINDOW)
		return false;

	switch (action) {
	case HELP_OPEN_CONTENTS:
		error = nsurl_create("http://www.netsurf-browser.org/documentation/", &url);
		if (error == NSERROR_OK) {
			error = browser_window_create(BW_CREATE_HISTORY,
					url,
					NULL,
					NULL,
					NULL);
			nsurl_unref(url);
		}
		if (error != NSERROR_OK) {
			warn_user(messages_get_errorcode(error), 0);
		}
		return true;
	
	case BROWSER_NAVIGATE_URL:
		ro_gui_dialog_prepare_open_url();
		ro_gui_dialog_open_persistent(NULL, dialog_openurl, true);
		return true;
	case HOTLIST_SHOW:
		ro_gui_hotlist_open();
		return true;
	case HISTORY_SHOW_GLOBAL:
		ro_gui_global_history_open();
		return true;
	case COOKIES_SHOW:
		ro_gui_cookies_open();
		return true;
	case CHOICES_SHOW:
		ro_gui_configure_show();
		return true;
	case APPLICATION_QUIT:
		if (ro_gui_prequit()) {
			LOG(("QUIT in response to user request"));
			netsurf_quit = true;
		}
		return true;
	default:
		return false;
	}

	return false;
}
Exemple #10
0
void ro_uri_message_received(wimp_message *msg)
{
	uri_full_message_process *uri_message = (uri_full_message_process *)msg;
	uri_h uri_handle;
	char* uri_requested;
	int uri_length;
	nsurl *url;
	nserror error;

	uri_handle = uri_message->handle;

	if (nsurl_create(uri_message->uri, &url) != NSERROR_OK) {
		return;
	}

	if (!fetch_can_fetch(url)) {
		nsurl_unref(url);
		return;
	}

	nsurl_unref(url);

	uri_message->your_ref = uri_message->my_ref;
	uri_message->action = message_URI_PROCESS_ACK;

	xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)uri_message,
		uri_message->sender);

	xuri_request_uri(0, 0, 0, uri_handle, &uri_length);
	uri_requested = calloc((unsigned int)uri_length, sizeof(char));
	if (uri_requested == NULL)
		return;

	xuri_request_uri(0, uri_requested, uri_length, uri_handle, NULL);

	error = nsurl_create(uri_requested, &url);
	free(uri_requested);
	if (error == NSERROR_OK) {
		error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
					      BROWSER_WINDOW_HISTORY,
					      url,
					      NULL,
					      NULL,
					      NULL);
		nsurl_unref(url);
	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	}
}
Exemple #11
0
static int
fb_url_enter(void *pw, char *text)
{
	struct browser_window *bw = pw;
	nsurl *url;
	nserror error;

	error = nsurl_create(text, &url);
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	} else {
		browser_window_navigate(bw, url, NULL, BW_NAVIGATE_HISTORY,
				NULL, NULL, NULL);
		nsurl_unref(url);
	}

	return 0;
}
Exemple #12
0
static void ami_menu_item_project_newwin(struct Hook *hook, APTR window, struct IntuiMessage *msg)
{
	nsurl *url;
	nserror error;

	error = nsurl_create(nsoption_charp(homepage_url), &url);
	if (error == NSERROR_OK) {
		error = browser_window_create(BW_CREATE_HISTORY,
					      url,
					      NULL,
					      NULL,
					      NULL);
		nsurl_unref(url);
	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	}
}
Exemple #13
0
bool ro_gui_iconbar_click(wimp_pointer *pointer)
{
	int key_down = 0;
	nsurl *url;
	nserror error;

	switch (pointer->buttons) {
	case wimp_CLICK_SELECT:
		if (nsoption_charp(homepage_url) != NULL) {
			error = nsurl_create(nsoption_charp(homepage_url), &url);
		} else {
			error = nsurl_create(NETSURF_HOMEPAGE, &url);
		}

		/* create an initial browser window */
		if (error == NSERROR_OK) {
			error = browser_window_create(BW_CREATE_HISTORY,
					url,
					NULL,
					NULL,
					NULL);
			nsurl_unref(url);
		}
		if (error != NSERROR_OK) {
			warn_user(messages_get_errorcode(error), 0);
		}
		break;

	case wimp_CLICK_ADJUST:
		xosbyte1(osbyte_SCAN_KEYBOARD, 0 ^ 0x80, 0, &key_down);
		if (key_down == 0)
			ro_gui_hotlist_open();
		break;
	}

	return true;
}
Exemple #14
0
static void gui_init2(int argc, char** argv)
{
	const char *addr;
	nsurl *url;
	nserror error;

	if (argc > 1) {
		addr = argv[1];
	} else if (nsoption_charp(homepage_url) != NULL) {
		addr = nsoption_charp(homepage_url);
	} else {
		addr = NETSURF_HOMEPAGE;
	}

	/* create an initial browser window */
	error = nsurl_create(addr, &url);
	if (error == NSERROR_OK) {
		error = browser_window_create((browser_window_nav_flags)
			(BROWSER_WINDOW_VERIFIABLE | BROWSER_WINDOW_HISTORY),
			url,
			NULL,
			NULL,
			NULL);
		nsurl_unref(url);
	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	}

	if (gFirstRefsReceived) {
		// resend the refs we got before having a window to send them to
		be_app_messenger.SendMessage(gFirstRefsReceived);
		delete gFirstRefsReceived;
		gFirstRefsReceived = NULL;
	}
}
Exemple #15
0
/** Entry point from OS.
 *
 * /param argc The number of arguments in the string vector.
 * /param argv The argument string vector.
 * /return The return code to the OS
 */
int
main(int argc, char** argv)
{
	struct browser_window *bw;
	char *options;
	char *messages;
	nsurl *url;
	nserror ret;
	nsfb_t *nsfb;
	struct gui_table framebuffer_gui_table = {
		.browser = &framebuffer_browser_table,
		.window = &framebuffer_window_table,
		.clipboard = framebuffer_clipboard_table,
		.fetch = framebuffer_fetch_table,
		.utf8 = framebuffer_utf8_table,
	};

	respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH);

	/* initialise logging. Not fatal if it fails but not much we
	 * can do about it either.
	 */
	nslog_init(nslog_stream_configure, &argc, argv);

	/* user options setup */
	ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
	if (ret != NSERROR_OK) {
		die("Options failed to initialise");
	}
	options = filepath_find(respaths, "Choices");
	nsoption_read(options, nsoptions);
	free(options);
	nsoption_commandline(&argc, argv, nsoptions);

	/* common initialisation */
	messages = filepath_find(respaths, "Messages");
	ret = netsurf_init(messages, &framebuffer_gui_table);
	free(messages);
	if (ret != NSERROR_OK) {
		die("NetSurf failed to initialise");
	}

	/* Override, since we have no support for non-core SELECT menu */
	nsoption_set_bool(core_select_menu, true);

	if (process_cmdline(argc,argv) != true)
		die("unable to process command line.\n");

	nsfb = framebuffer_initialise(fename, fewidth, feheight, febpp);
	if (nsfb == NULL)
		die("Unable to initialise framebuffer");

	framebuffer_set_cursor(&pointer_image);

	if (fb_font_init() == false)
		die("Unable to initialise the font system");

	fbtk = fbtk_init(nsfb);

	fbtk_enable_oskb(fbtk);

	urldb_load_cookies(nsoption_charp(cookie_file));

	/* create an initial browser window */

	LOG(("calling browser_window_create"));

	ret = nsurl_create(feurl, &url);
	if (ret == NSERROR_OK) {
		ret = browser_window_create(BW_CREATE_HISTORY,
					      url,
					      NULL,
					      NULL,
					      &bw);
		nsurl_unref(url);
	}
	if (ret != NSERROR_OK) {
		warn_user(messages_get_errorcode(ret), 0);
	} else {
		netsurf_main_loop();

		browser_window_destroy(bw);
	}

	netsurf_exit();

	if (fb_font_finalise() == false)
		LOG(("Font finalisation failed."));

	/* finalise options */
	nsoption_finalise(nsoptions, nsoptions_default);

	return 0;
}
Exemple #16
0
static struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *gui)
{
	nsurl *url = download_context_get_url(ctx);
	const char *temp_name;
	char *filename = NULL;
	struct gui_download_window *dw;
	bool space_warning = false;
	os_error *error;
	char *local_path;
	nserror err;
	size_t i, last_dot;

	dw = malloc(sizeof *dw);
	if (!dw) {
		ro_warn_user("NoMemory", 0);
		return 0;
	}

	dw->ctx = ctx;
	dw->saved = false;
	dw->close_confirmed = false;
	dw->error = false;
	dw->query = QUERY_INVALID;
	dw->received = 0;
	dw->total_size = download_context_get_total_length(ctx);

	/** @todo change this to take a reference to the nsurl and use
	 * that value directly rather than using a fixed buffer.
	 */
	strncpy(dw->url, nsurl_access(url), sizeof dw->url);
	dw->url[sizeof dw->url - 1] = 0;

	dw->status[0] = 0;
	gettimeofday(&dw->start_time, 0);
	dw->last_time = dw->start_time;
	dw->last_received = 0;
	dw->file_type = 0;
	dw->average_rate = 0;
	dw->average_points = 0;

	/* get filetype */
	err = download_ro_filetype(ctx, &dw->file_type);
	if (err != NSERROR_OK) {
		ro_warn_user(messages_get_errorcode(err), 0);
		free(dw);
		return 0;
	}

	/* open temporary output file */
	temp_name = ro_gui_download_temp_name(dw);
	if (!ro_gui_download_check_space(dw, temp_name, NULL)) {
		/* issue a warning but continue with the download because the
		   user can save it to another medium whilst it's downloading */
		space_warning = true;
	}
	error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR,
			temp_name, 0, &dw->file);
	if (error) {
		LOG("xosfind_openoutw: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("SaveError", error->errmess);
		free(dw);
		return 0;
	}

	/* fill in download window icons */
	download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.text =
			dw->url;
	download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.size =
			sizeof dw->url;

	download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text.
			text = dw->status;
	download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text.
			size = sizeof dw->status;

	sprintf(dw->sprite_name, "file_%.3x", dw->file_type);
	if (!ro_gui_wimp_sprite_exists(dw->sprite_name))
		strcpy(dw->sprite_name, "file_xxx");
	download_template->icons[ICON_DOWNLOAD_ICON].data.indirected_sprite.id =
			(osspriteop_id) dw->sprite_name;

	/* Get a suitable path- and leafname for the download. */
	temp_name = download_context_get_filename(dw->ctx);

	if (temp_name == NULL)
		temp_name = messages_get("SaveObject");

	if (temp_name != NULL)
		filename = strdup(temp_name);

	if (filename == NULL) {
		LOG("Failed to establish download filename.");
		ro_warn_user("SaveError", error->errmess);
		free(dw);
		return 0;
	}

	for (i = 0, last_dot = (size_t) -1; filename[i] != '\0'; i++) {
		const char c = filename[i];

		if (c == '.') {
			last_dot = i;
			filename[i] = '/';
		} else if (c <= ' ' || strchr(":*#$&@^%\\", c) != NULL)
			filename[i] = '_';
	}

	if (nsoption_bool(strip_extensions) && last_dot != (size_t) -1)
		filename[last_dot] = '\0';

	if (download_dir != NULL && strlen(download_dir) > 0)
		snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s.%s",
				download_dir, filename);
	else
		snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s",
				filename);

	free(filename);

	err = utf8_to_local_encoding(dw->path, 0, &local_path);
	if (err != NSERROR_OK) {
		/* badenc should never happen */
		assert(err !=NSERROR_BAD_ENCODING);
		LOG("utf8_to_local_encoding failed");
		ro_warn_user("NoMemory", 0);
		free(dw);
		return 0;
	}
	else {
		strncpy(dw->path, local_path, sizeof dw->path);
		free(local_path);
	}

	download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.text =
			dw->path;
	download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.size =
			sizeof dw->path;

	download_template->icons[ICON_DOWNLOAD_DESTINATION].data.
			indirected_text.text = dw->path;
	download_template->icons[ICON_DOWNLOAD_DESTINATION].data.
			indirected_text.size = sizeof dw->path;

	download_template->icons[ICON_DOWNLOAD_DESTINATION].flags |=
			wimp_ICON_DELETED;

	/* create and open the download window */
	error = xwimp_create_window(download_template, &dw->window);
	if (error) {
		LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("WimpError", error->errmess);
		free(dw);
		return 0;
	}

	dw->prev = 0;
	dw->next = download_window_list;
	if (download_window_list)
		download_window_list->prev = dw;
	download_window_list = dw;

	ro_gui_download_update_status(dw);

	ro_gui_dialog_open(dw->window);

	ro_gui_wimp_event_set_user_data(dw->window, dw);
	ro_gui_wimp_event_register_mouse_click(dw->window, ro_gui_download_click);
	ro_gui_wimp_event_register_keypress(dw->window, ro_gui_download_keypress);
	ro_gui_wimp_event_register_close_window(dw->window, ro_gui_download_close);

	/* issue the warning now, so that it appears in front of the download
	 * window! */
	if (space_warning)
		ro_warn_user("DownloadWarn", messages_get("NoDiscSpace"));

	return dw;
}
Exemple #17
0
void ro_url_message_received(wimp_message *message)
{
	char *url;
	int i;
	inetsuite_message_open_url *url_message =
			(inetsuite_message_open_url*) &message->data;
	os_error *error;
	nsurl *nsurl;
	nserror errorns;

	/* If the url_message->indirect.tag is non-zero,
	 * then the message data is contained within the message block.
	 */
	if (url_message->indirect.tag != 0) {
		url = strndup(url_message->url, 236);
		if (!url) {
			warn_user("NoMemory", 0);
			return;
		}
		/* terminate at first control character */
		for (i = 0; !iscntrl(url[i]); i++)
			;
		url[i] = 0;

	} else {
		if (!url_message->indirect.url.offset) {
			LOG(("no URL in message"));
			return;
		}
		if (28 < message->size &&
				url_message->indirect.body_file.offset) {
			LOG(("POST for URL message not implemented"));
			return;
		}
		if (url_message->indirect.url.offset < 28 ||
				236 <= url_message->indirect.url.offset) {
			LOG(("external pointers in URL message unimplemented"));
			/* these messages have never been seen in the wild,
			 * and there is the problem of invalid addresses which
			 * would cause an abort */
			return;
		}

		url = strndup((char *) url_message +
				url_message->indirect.url.offset,
				236 - url_message->indirect.url.offset);
		if (!url) {
			warn_user("NoMemory", 0);
			return;
		}
		for (i = 0; !iscntrl(url[i]); i++)
			;
		url[i] = 0;
	}

	if (nsurl_create(url, &nsurl) != NSERROR_OK) {
		free(url);
		return;
	}

	if (!fetch_can_fetch(nsurl)) {
		nsurl_unref(nsurl);
		free(url);
		return;
	}

	free(url);

	/* send ack */
	message->your_ref = message->my_ref;
	error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, message,
			message->sender);
	if (error) {
		LOG(("xwimp_send_message: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
	}

	/* create new browser window */
	errorns = browser_window_create(BW_CREATE_HISTORY,
				      nsurl,
				      NULL,
				      NULL,
				      NULL);


	nsurl_unref(nsurl);
	if (errorns != NSERROR_OK) {
		warn_user(messages_get_errorcode(errorns), 0);
	}
}
Exemple #18
0
/**
 * Entry point from operating system
 **/
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
{
	char **argv = NULL;
	int argc = 0, argctemp = 0;
	size_t len;
	LPWSTR *argvw;
	char *messages;
	nserror ret;
	const char *addr;
	nsurl *url;
	nserror error;

	if (SLEN(lpcli) > 0) {
		argvw = CommandLineToArgvW(GetCommandLineW(), &argc);
	}

	setbuf(stderr, NULL);

	/* Construct a unix style argc/argv */
	argv = malloc(sizeof(char *) * argc);
	while (argctemp < argc) {
		len = wcstombs(NULL, argvw[argctemp], 0) + 1;
		if (len > 0) {
			argv[argctemp] = malloc(len);
		}

		if (argv[argctemp] != NULL) {
			wcstombs(argv[argctemp], argvw[argctemp], len);
			/* alter windows-style forward slash flags to
			 * hyphen flags.
			 */
			if (argv[argctemp][0] == '/')
				argv[argctemp][0] = '-';
		}
		argctemp++;
	}

	respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\NetSurf\\:"NETSURF_WINDOWS_RESPATH);

	messages = filepath_find(respaths, "messages");

	options_file_location = filepath_find(respaths, "preferences");

	/* initialise netsurf */
	netsurf_init(&argc, &argv, options_file_location, messages);

	free(messages);

	ret = nsws_create_main_class(hInstance);
	ret = nsws_create_drawable_class(hInstance);
	ret = nsws_create_localhistory_class(hInstance);

	nsoption_set_bool(target_blank, false);

	nsws_window_init_pointers(hInstance);

	/* If there is a url specified on the command line use it */
	if (argc > 1) {
		addr = argv[1];
	} else if (nsoption_charp(homepage_url) != NULL) {
		addr = nsoption_charp(homepage_url);
	} else {
		addr = NETSURF_HOMEPAGE;
	}

	LOG(("calling browser_window_create"));

	error = nsurl_create(addr, &url);
	if (error == NSERROR_OK) {
		error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
					      BROWSER_WINDOW_HISTORY,
					      url,
					      NULL,
					      NULL,
					      NULL);
		nsurl_unref(url);

	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	} else {
		netsurf_main_loop();
	}

	netsurf_exit();

	free(options_file_location);

	return 0;
}
Exemple #19
0
/**
 * Main entry point from OS.
 */
int main(int argc, char** argv)
{
	char *cache_home = NULL;
	nserror ret;
	struct netsurf_table nsgtk_table = {
		.misc = &nsgtk_misc_table,
		.window = nsgtk_window_table,
		.clipboard = nsgtk_clipboard_table,
		.download = nsgtk_download_table,
		.fetch = nsgtk_fetch_table,
		.llcache = filesystem_llcache_table,
		.search = nsgtk_search_table,
		.search_web = nsgtk_search_web_table,
		.bitmap = nsgtk_bitmap_table,
		.layout = nsgtk_layout_table,
	};

	ret = netsurf_register(&nsgtk_table);
	if (ret != NSERROR_OK) {
		die("NetSurf operation table failed registration\n");
	}

	/* Locate the correct user configuration directory path */
	ret = get_config_home(&nsgtk_config_home);
	if (ret == NSERROR_NOT_FOUND) {
		/* no config directory exists yet so try to create one */
		ret = create_config_home(&nsgtk_config_home);
	}
	if (ret != NSERROR_OK) {
		LOG("Unable to locate a configuration directory.");
		nsgtk_config_home = NULL;
	}

	/* Initialise gtk */
	gtk_init(&argc, &argv);

	/* initialise logging. Not fatal if it fails but not much we
	 * can do about it either.
	 */
	nslog_init(nslog_stream_configure, &argc, argv);

	/* build the common resource path list */
	respaths = nsgtk_init_resource_path(nsgtk_config_home);
	if (respaths == NULL) {
		fprintf(stderr, "Unable to locate resources\n");
		return 1;
	}

	/* initialise the gtk resource handling */
	ret = nsgtk_init_resources(respaths);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "GTK resources failed to initialise (%s)\n",
			messages_get_errorcode(ret));
		return 1;
	}

	/* Initialise user options */
	ret = nsgtk_option_init(&argc, argv);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "Options failed to initialise (%s)\n",
			messages_get_errorcode(ret));
		return 1;
	}

	/* Initialise translated messages */
	ret = nsgtk_messages_init(respaths);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "Unable to load translated messages (%s)\n",
			messages_get_errorcode(ret));
		LOG("Unable to load translated messages");
		/** \todo decide if message load faliure should be fatal */
	}

	/* Locate the correct user cache directory path */
	ret = get_cache_home(&cache_home);
	if (ret == NSERROR_NOT_FOUND) {
		/* no cache directory exists yet so try to create one */
		ret = create_cache_home(&cache_home);
	}
	if (ret != NSERROR_OK) {
		LOG("Unable to locate a cache directory.");
	}

	/* core initialisation */
	ret = netsurf_init(cache_home);
	free(cache_home);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "NetSurf core failed to initialise (%s)\n",
			messages_get_errorcode(ret));
		return 1;
	}

	/* run the browser */
	ret = nsgtk_init(argc, argv, respaths);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "NetSurf gtk initialise failed (%s)\n",
			messages_get_errorcode(ret));
	} else {
		nsgtk_main();
	}

	/* common finalisation */
	netsurf_exit();

	/* finalise options */
	nsoption_finalise(nsoptions, nsoptions_default);

	return 0;
}
Exemple #20
0
static void gui_init(int argc, char** argv)
{
	const char *addr;
	nsurl *url;
	nserror error;
	char buf[PATH_MAX];

	if (pipe(sEventPipe) < 0)
		return;
	if (!replicated) {
		sBAppThreadID = spawn_thread(bapp_thread, "BApplication(NetSurf)", B_NORMAL_PRIORITY, (void *)find_thread(NULL));
		if (sBAppThreadID < B_OK)
			return; /* #### handle errors */
		if (resume_thread(sBAppThreadID) < B_OK)
			return;
	}

	nsbeos_update_system_ui_colors();

	fetch_rsrc_register();

	check_homedir();

	// make sure the cache dir exists
	create_directory(TEMP_FILENAME_PREFIX, 0700);

	//nsbeos_completion_init();


	/* This is an ugly hack to just get the new-style throbber going.
	 * It, along with the PNG throbber loader, need making more generic.
	 */
	{
#define STROF(n) #n
#define FIND_THROB(n) filenames[(n)] = \
				"throbber/throbber" STROF(n) ".png";
		char *filenames[9];
		FIND_THROB(0);
		FIND_THROB(1);
		FIND_THROB(2);
		FIND_THROB(3);
		FIND_THROB(4);
		FIND_THROB(5);
		FIND_THROB(6);
		FIND_THROB(7);
		FIND_THROB(8);
		nsbeos_throbber_initialise_from_png(9,
			filenames[0], filenames[1], filenames[2], filenames[3],
			filenames[4], filenames[5], filenames[6], filenames[7], 
			filenames[8]);
#undef FIND_THROB
#undef STROF
	}

	if (nsbeos_throbber == NULL)
		die("Unable to load throbber image.\n");

	find_resource(buf, "Choices", "%/Choices");
	LOG(("Using '%s' as Preferences file", buf));
	options_file_location = strdup(buf);
	nsoption_read(buf, NULL);


	/* check what the font settings are, setting them to a default font
	 * if they're not set - stops Pango whinging
	 */
#define SETFONTDEFAULT(OPTION,y) if (nsoption_charp(OPTION) == NULL) nsoption_set_charp(OPTION, strdup((y)))

	//XXX: use be_plain_font & friends, when we can check if font is serif or not.
/*
	font_family family;
	font_style style;
	be_plain_font->GetFamilyAndStyle(&family, &style);
	SETFONTDEFAULT(font_sans, family);
	SETFONTDEFAULT(font_serif, family);
	SETFONTDEFAULT(font_mono, family);
	SETFONTDEFAULT(font_cursive, family);
	SETFONTDEFAULT(font_fantasy, family);
*/
#ifdef __HAIKU__
	SETFONTDEFAULT(font_sans, "DejaVu Sans");
	SETFONTDEFAULT(font_serif, "DejaVu Serif");
	SETFONTDEFAULT(font_mono, "DejaVu Mono");
	SETFONTDEFAULT(font_cursive, "DejaVu Sans");
	SETFONTDEFAULT(font_fantasy, "DejaVu Sans");
#else
	SETFONTDEFAULT(font_sans, "Bitstream Vera Sans");
	SETFONTDEFAULT(font_serif, "Bitstream Vera Serif");
	SETFONTDEFAULT(font_mono, "Bitstream Vera Sans Mono");
	SETFONTDEFAULT(font_cursive, "Bitstream Vera Serif");
	SETFONTDEFAULT(font_fantasy, "Bitstream Vera Serif");
#endif

	nsbeos_options_init();

	if (nsoption_charp(cookie_file) == NULL) {
		find_resource(buf, "Cookies", "%/Cookies");
		LOG(("Using '%s' as Cookies file", buf));
		nsoption_set_charp(cookie_file, strdup(buf));
	}
	if (nsoption_charp(cookie_jar) == NULL) {
		find_resource(buf, "Cookies", "%/Cookies");
		LOG(("Using '%s' as Cookie Jar file", buf));
		nsoption_set_charp(cookie_jar, strdup(buf));
	}
	if ((nsoption_charp(cookie_file) == NULL) || 
	    (nsoption_charp(cookie_jar) == NULL))
		die("Failed initialising cookie options");

	if (nsoption_charp(url_file) == NULL) {
		find_resource(buf, "URLs", "%/URLs");
		LOG(("Using '%s' as URL file", buf));
		nsoption_set_charp(url_file, strdup(buf));
	}

        if (nsoption_charp(ca_path) == NULL) {
                find_resource(buf, "certs", "/etc/ssl/certs");
                LOG(("Using '%s' as certificate path", buf));
                nsoption_set_charp(ca_path, strdup(buf));
        }

	//find_resource(buf, "mime.types", "/etc/mime.types");
	beos_fetch_filetype_init();

	urldb_load(nsoption_charp(url_file));
	urldb_load_cookies(nsoption_charp(cookie_file));

	//nsbeos_download_initialise();

	if (!replicated)
		be_app->Unlock();

	if (argc > 1) {
		addr = argv[1];
	} else if (nsoption_charp(homepage_url) != NULL) {
		addr = nsoption_charp(homepage_url);
	} else {
		addr = NETSURF_HOMEPAGE;
	}

	/* create an initial browser window */
	error = nsurl_create(addr, &url);
	if (error == NSERROR_OK) {
		error = browser_window_create(
			BW_CREATE_HISTORY,
			url,
			NULL,
			NULL,
			NULL);
		nsurl_unref(url);
	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	}

	if (gFirstRefsReceived) {
		// resend the refs we got before having a window to send them to
		be_app_messenger.SendMessage(gFirstRefsReceived);
		delete gFirstRefsReceived;
		gFirstRefsReceived = NULL;
	}

}
Exemple #21
0
/**
 * Entry point from OS.
 *
 * /param argc The number of arguments in the string vector.
 * /param argv The argument string vector.
 * /return The return code to the OS
 */
int main(int argc, char** argv)
{
    char messages[PATH_MAX];
    char store[PATH_MAX];
    const char *addr;
    char * file_url = NULL;
    struct stat stat_buf;
    nsurl *url;
    nserror ret;

    struct netsurf_table atari_table = {
	.misc = &atari_misc_table,
	.window = &atari_window_table,
	.clipboard = &atari_clipboard_table,
	.download = atari_download_table,
	.fetch = &atari_fetch_table,
	.file = atari_file_table,
	.utf8 = atari_utf8_table,
	.search = atari_search_table,
	.llcache = filesystem_llcache_table,
	.bitmap = atari_bitmap_table,
	.layout = atari_layout_table
    };

    ret = netsurf_register(&atari_table);
    if (ret != NSERROR_OK) {
	die("NetSurf operation table failed registration");
    }

    /** @todo logging file descriptor update belongs in a nslog_init callback */
    setbuf(stderr, NULL);
    setbuf(stdout, NULL);
#ifdef WITH_DBG_LOGFILE
    freopen("stdout.log", "a+", stdout);
    freopen("stderr.log", "a+", stderr);
#endif

    graf_mouse(BUSY_BEE, NULL);

    init_app(NULL);

    init_os_info();

    atari_find_resource((char*)&messages, "messages", "res/messages");
    atari_find_resource((char*)&options, "Choices", "Choices");
    atari_find_resource((char*)&store, "cache", "res/cache");

    /* initialise logging - not fatal if it fails but not much we can
     * do about it
     */
    nslog_init(NULL, &argc, argv);

    /* user options setup */
    ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
    if (ret != NSERROR_OK) {
	die("Options failed to initialise");
    }
    nsoption_read(options, NULL);
    nsoption_commandline(&argc, argv, NULL);

    ret = messages_add_from_file(messages);

    /* common initialisation */
    LOG("Initialising core...");
    ret = netsurf_init(store);
    if (ret != NSERROR_OK) {
	die("NetSurf failed to initialise");
    }

    LOG("Initializing GUI...");
    gui_init(argc, argv);

    graf_mouse( ARROW , NULL);

    LOG("Creating initial browser window...");
    addr = option_homepage_url;
    if (strncmp(addr, "file://", 7) && strncmp(addr, "http://", 7)) {
	if (stat(addr, &stat_buf) == 0) {
	    file_url = local_file_to_url(addr);
	    addr = file_url;
	}
    }

    /* create an initial browser window */
    ret = nsurl_create(addr, &url);
    if (ret == NSERROR_OK) {
	ret = browser_window_create(BW_CREATE_HISTORY,
				    url,
				    NULL,
				    NULL,
				    NULL);
	nsurl_unref(url);
    }
    if (ret != NSERROR_OK) {
	atari_warn_user(messages_get_errorcode(ret), 0);
    } else {
	LOG("Entering Atari event mainloop...");
	while (!atari_quit) {
	    atari_poll();
	}
    }

    netsurf_exit();

    free(file_url);

#ifdef WITH_DBG_LOGFILE
    fclose(stdout);
    fclose(stderr);
#endif
    LOG("exit_gem");
    exit_gem();

    return 0;
}
Exemple #22
0
static void ami_menu_item_project_about(struct Hook *hook, APTR window, struct IntuiMessage *msg)
{
	struct gui_window_2 *gwin;
	char *temp, *temp2;
	int sel;
	nsurl *url = NULL;
	nserror error;

	GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);

	ami_set_pointer(gwin, GUI_POINTER_WAIT, false);

	temp = ASPrintf("%s|%s|%s", messages_get("OK"),
								messages_get("HelpCredits"),
								messages_get("HelpLicence"));

	temp2 = ami_utf8_easy(temp);
	FreeVec(temp);

	sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO,
				TDR_TitleString, messages_get("NetSurf"),
				TDR_Window, gwin->win,
				TDR_GadgetString, temp2,
#ifndef NDEBUG
				TDR_FormatString,"NetSurf %s\n%s\nBuild date %s\n\nhttp://www.netsurf-browser.org",
#else
				TDR_FormatString,"NetSurf %s\n%s\n\nhttp://www.netsurf-browser.org",
#endif
				TDR_Arg1,netsurf_version,
#ifdef NS_AMIGA_CAIRO
				TDR_Arg2,"Cairo (OS4.1+) SObjs build",
#else
				TDR_Arg2,"graphics.library static build",
#endif
				TDR_Arg3,verdate,
				TAG_DONE);

	free(temp2);

	if(sel == 2) {
		error = nsurl_create("about:credits", &url);
	} else if(sel == 0) {
		error = nsurl_create("about:licence", &url);
	}

	if(url) {
		if (error == NSERROR_OK) {
			error = browser_window_create(BW_CREATE_HISTORY,
							  url,
							  NULL,
							  NULL,
							  NULL);
			nsurl_unref(url);
		}
		if (error != NSERROR_OK) {
			warn_user(messages_get_errorcode(error), 0);
		}
	}

	ami_reset_pointer(gwin);
}
Exemple #23
0
HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *)
{
	struct gui_window_2 *gwin;
	char *temp, *temp2;
	int sel;
	nsurl *url = NULL;
	nserror error = NSERROR_OK;

	GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);

	ami_set_pointer(gwin, GUI_POINTER_WAIT, false);

	temp = ASPrintf("%s|%s|%s", messages_get("OK"),
								messages_get("HelpCredits"),
								messages_get("HelpLicence"));

	temp2 = ami_utf8_easy(temp);
	FreeVec(temp);
#ifdef __amigaos4__
	sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO,
				TDR_TitleString, messages_get("NetSurf"),
				TDR_Window, gwin->win,
				TDR_GadgetString, temp2,
				TDR_FormatString,"NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org",
				TDR_Arg1,netsurf_version,
				TDR_Arg2,verdate,
				TAG_DONE);
#else
	struct EasyStruct about_req = {
		sizeof(struct EasyStruct),
		0,
		"NetSurf",
		"NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org",
		temp2,
	};

	sel = EasyRequest(gwin->win, &about_req, NULL, netsurf_version, verdate);
#endif
	free(temp2);

	if(sel == 2) {
		error = nsurl_create("about:credits", &url);
	} else if(sel == 0) {
		error = nsurl_create("about:licence", &url);
	}

	if(url) {
		if (error == NSERROR_OK) {
			error = browser_window_create(BW_CREATE_HISTORY,
							  url,
							  NULL,
							  NULL,
							  NULL);
			nsurl_unref(url);
		}
		if (error != NSERROR_OK) {
			amiga_warn_user(messages_get_errorcode(error), 0);
		}
	}

	ami_reset_pointer(gwin);
}