Пример #1
0
nserror html_css_init(void)
{
	nserror error;

	error = html_css_fetcher_register();
	if (error != NSERROR_OK)
		return error;

	error = nsurl_create("resource:default.css",
			&html_default_stylesheet_url);
	if (error != NSERROR_OK)
		return error;

	error = nsurl_create("resource:adblock.css",
			&html_adblock_stylesheet_url);
	if (error != NSERROR_OK)
		return error;

	error = nsurl_create("resource:quirks.css",
			&html_quirks_stylesheet_url);
	if (error != NSERROR_OK)
		return error;

	error = nsurl_create("resource:user.css",
			&html_user_stylesheet_url);

	return error;
}
Пример #2
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);
	}
}
Пример #3
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);
	} 
}
Пример #4
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);
	}
}
Пример #5
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 );
		}
	}
}
Пример #6
0
END_TEST


/**
 * url reference (copy) and unreference(free)
 */
START_TEST(nsurl_ref_test)
{
	nserror err;
	nsurl *res1;
	nsurl *res2;

	err = nsurl_create(base_str, &res1);

	/* result must be valid */
	ck_assert(err == NSERROR_OK);

	res2 = nsurl_ref(res1);

	ck_assert_str_eq(nsurl_access(res1), nsurl_access(res2));

	nsurl_unref(res2);

	nsurl_unref(res1);
}
Пример #7
0
/**
 * Create a nsurl from a path using amiga file handling.
 *
 * Perform the necessary operations on a path to generate a nsurl.
 *
 * @param[in] path The path to convert.
 * @param[out] url_out pointer to recive the nsurl, The returned url
 *                     must be unreferenced by the caller.
 * @return NSERROR_OK and the url is placed in \a url or error code on
 *         faliure.
 */
static nserror amiga_path_to_nsurl(const char *path, struct nsurl **url_out)
{
	char *colon = NULL;
	char *r = NULL;
	char newpath[1024 + strlen(path)];
	BPTR lock = 0;
	nserror ret;

	if((lock = Lock(path, SHARED_LOCK))) {
		DevNameFromLock(lock, newpath, sizeof newpath, DN_FULLPATH);
		UnLock(lock);
	}
	else strlcpy(newpath, path, sizeof newpath);

	r = malloc(strlen(newpath) + SLEN("file:///") + 1);
	if (r == NULL) {
		return NSERROR_NOMEM;
	}

	if((colon = strchr(newpath, ':'))) *colon = '/';

	strcpy(r, "file:///");
	strcat(r, newpath);

	ret = nsurl_create(r, url_out);
	free(r);

	return ret;
}
Пример #8
0
END_TEST

/**
 * refragment url
 */
START_TEST(nsurl_refragment_test)
{
	nserror err;
	nsurl *url;
	nsurl *res_url;
	const struct test_pairs *tst = &fragment_tests[_i];
	lwc_string *frag;

	/* not testing create, this should always succeed */
	err = nsurl_create(tst->test, &url);
	ck_assert(err == NSERROR_OK);

	/* grab the fragment - not testing should succeed */
	frag = nsurl_get_component(url, NSURL_FRAGMENT);
	ck_assert(frag != NULL);
	nsurl_unref(url);

	/* not testing create, this should always succeed */
	err = nsurl_create(tst->res, &url);
	ck_assert(err == NSERROR_OK);

	err = nsurl_refragment(url, frag, &res_url);
	if (tst->res == NULL) {
		/* result must be invalid (bad input) */
		ck_assert(err != NSERROR_OK);
	} else {
		/* result must be valid */
		ck_assert(err == NSERROR_OK);

		ck_assert_str_eq(nsurl_access(res_url), tst->test);

		nsurl_unref(res_url);
	}

	lwc_string_unref(frag);

	nsurl_unref(url);
}
Пример #9
0
static void gui_download_window_done(struct gui_download_window *dw)
{
	struct dlnode *dln,*dln2 = NULL;
	struct browser_window *bw;
	bool queuedl = false;

	if(!dw) return;
	bw = dw->bw;

	if((nsoption_bool(download_notify)) && (dw->result == AMINS_DLOAD_OK))
	{
		Notify(ami_gui_get_app_id(), APPNOTIFY_Title, messages_get("amiDownloadComplete"),
				APPNOTIFY_PubScreenName, "FRONT",
				APPNOTIFY_BackMsg, dw->fname,
				APPNOTIFY_CloseOnDC, TRUE,
				APPNOTIFY_Text, dw->fname,
				TAG_DONE);
	}

	download_context_destroy(dw->ctx);

	if((dln = dw->dln))
	{
		dln2 = (struct dlnode *)GetSucc((struct Node *)dln);
		if((dln!=dln2) && (dln2)) queuedl = true;

		free(dln->filename);
		Remove((struct Node *)dln);
		FreeVec(dln);
	}

	FClose(dw->fh);
	SetComment(dw->fname, dw->url);

	downloads_in_progress--;

	DisposeObject(dw->objects[OID_MAIN]);
	DelObject(dw->node);
	if(queuedl) {
		nsurl *url;
		if (nsurl_create(dln2->node.ln_Name, &url) != NSERROR_OK) {
			amiga_warn_user("NoMemory", 0);
		} else {
			browser_window_navigate(bw,
				url,
				NULL,
				BW_NAVIGATE_DOWNLOAD,
				NULL,
				NULL,
				NULL);
			nsurl_unref(url);
		}
	}
	ami_try_quit(); /* In case the only window open was this download */
}
Пример #10
0
static nserror
html_stylesheet_from_domnode(html_content *c,
			     dom_node *node,
			     hlcache_handle **sheet)
{
	hlcache_child_context child;
	dom_string *style;
	nsurl *url;
	dom_exception exc;
	nserror error;
	uint32_t key;
	char urlbuf[64];

	child.charset = c->encoding;
	child.quirks = c->base.quirks;

	exc = dom_node_get_text_content(node, &style);
	if ((exc != DOM_NO_ERR) || (style == NULL)) {
		LOG("No text content");
		return NSERROR_OK;
	}

	error = html_css_fetcher_add_item(style, c->base_url, &key);
	if (error != NSERROR_OK) {
		dom_string_unref(style);
		return error;
	}

	dom_string_unref(style);

	snprintf(urlbuf, sizeof(urlbuf), "x-ns-css:%u", key);

	error = nsurl_create(urlbuf, &url);
	if (error != NSERROR_OK) {
		return error;
	}

	error = hlcache_handle_retrieve(url, 0,
			content_get_url(&c->base), NULL,
			html_convert_css_callback, c, &child, CONTENT_CSS,
			sheet);
	if (error != NSERROR_OK) {
		nsurl_unref(url);
		return error;
	}

	nsurl_unref(url);

	c->base.active++;
	LOG("%d fetches active", c->base.active);

	return NSERROR_OK;
}
Пример #11
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;
}
Пример #12
0
nsurl *gui_get_resource_url(const char *path)
{
	nsurl *url = NULL;
	BString u("rsrc:///");
	if (strcmp(path, "default.css") == 0)
		u << "beosdefault.css";
	else
		u << path;
	LOG(("(%s) -> '%s'\n", path, u.String()));
	nsurl_create(u.String(), &url);
	return url;
}
Пример #13
0
END_TEST


/**
 * check creation asserts on NULL parameter
 */
START_TEST(nsurl_api_assert_create_test)
{
	nserror err;
	nsurl *res1;
	err = nsurl_create(NULL, &res1);

	ck_assert(err != NSERROR_OK);
}
Пример #14
0
nsurl *gui_get_resource_url(const char *path)
{
	char buf[PATH_MAX];
	char *raw;
	nsurl *url = NULL;

	raw = path_to_url(filepath_sfind(respaths, buf, path));
	if (raw != NULL) {
		nsurl_create(raw, &url);
		free(raw);
	}

	return url;
}
Пример #15
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;
}
Пример #16
0
nsurl *gui_get_resource_url(const char *path)
{
    char buf[PATH_MAX];
    char *raw;
    nsurl *url = NULL;

    atari_find_resource((char*)&buf, path, path);
    raw = path_to_url((char*)&buf);
    if (raw != NULL) {
        nsurl_create(raw, &url);
        free(raw);
    }

    return url;
}
Пример #17
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);
	}
}
Пример #18
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;
}
Пример #19
0
END_TEST

/**
 * check compare asserts on NULL parameter
 */
START_TEST(nsurl_api_assert_compare2_test)
{
	nserror err;
	nsurl *res;
	bool same;

	err = nsurl_create(base_str, &res);
	ck_assert(err == NSERROR_OK);

	same = nsurl_compare(res, NULL, NSURL_PATH);

	ck_assert(same == false);
}
Пример #20
0
static nsurl *gui_get_resource_url(const char *path)
{
	nsurl *url = NULL;
	BString u("rsrc:///");

	/* default.css -> beosdefault.css */
	if (strcmp(path, "default.css") == 0)
		path = "beosdefault.css";

	/* favicon.ico -> favicon.png */
	if (strcmp(path, "favicon.ico") == 0)
		path = "favicon.png";

	u << path;
	LOG(("(%s) -> '%s'\n", path, u.String()));
	nsurl_create(u.String(), &url);
	return url;
}
Пример #21
0
END_TEST

/**
 * check join asserts on NULL parameter
 */
START_TEST(nsurl_api_assert_join2_test)
{
	nsurl *url;
	nsurl *res;
	nserror err;

	err = nsurl_create(base_str, &url);
	ck_assert(err == NSERROR_OK);

	err = nsurl_join(url, NULL, &res);
	ck_assert(err != NSERROR_OK);

	nsurl_unref(url);
}
Пример #22
0
END_TEST

/**
 * check query replacement asserts on NULL parameter
 */
START_TEST(nsurl_api_assert_replace_query2_test)
{
	nsurl *url;
	nsurl *res;
	nserror err;

	err = nsurl_create(base_str, &url);
	ck_assert(err == NSERROR_OK);

	err = nsurl_replace_query(url, NULL, &res);
	ck_assert(err != NSERROR_OK);

	nsurl_unref(url);
}
Пример #23
0
END_TEST

/**
 * check get component asserts on bad component parameter
 */
START_TEST(nsurl_api_assert_get_component2_test)
{
	nserror err;
	nsurl *res;
	lwc_string *lwcs;

	err = nsurl_create(base_str, &res);
	ck_assert(err == NSERROR_OK);

	lwcs = nsurl_get_component(res, -1);
	ck_assert(lwcs == NULL);

	nsurl_unref(res);
}
Пример #24
0
END_TEST

/**
 * check has component asserts on bad component parameter
 */
START_TEST(nsurl_api_assert_has_component2_test)
{
	nserror err;
	nsurl *res;
	bool has;

	err = nsurl_create(base_str, &res);
	ck_assert(err == NSERROR_OK);

	has = nsurl_has_component(res, -1);
	ck_assert(has == false);

	nsurl_unref(res);
}
Пример #25
0
nsurl *gui_get_resource_url(const char *path)
{
	char buf[PATH_MAX];
	char *raw;
	nsurl *url = NULL;

	if (strcmp(path, "favicon.ico") == 0)
		path = "favicon.png";

	raw = path_to_url(filepath_sfind(respaths, buf, path));
	
	LOG(("Findfile gui: %s", raw));
	if (raw != NULL) {
		nsurl_create(raw, &url);
		free(raw);
	}

	return url;
}
Пример #26
0
END_TEST

/**
 * check query replacement asserts on bad parameter
 */
START_TEST(nsurl_api_assert_replace_query3_test)
{
	nsurl *url;
	nsurl *res;
	nserror err;
	const char *rel = "moo";

	err = nsurl_create(base_str, &url);
	ck_assert(err == NSERROR_OK);

	err = nsurl_replace_query(url, rel, &res);
	ck_assert(err != NSERROR_OK);

	nsurl_unref(url);
}
Пример #27
0
END_TEST

/**
 * url access leaf test
 */
START_TEST(nsurl_access_leaf_test)
{
	nserror err;
	nsurl *res_url;
	const struct test_triplets *tst = &access_tests[_i];

	/* not testing create, this should always succeed */
	err = nsurl_create(tst->test1, &res_url);
	ck_assert(err == NSERROR_OK);

	ck_assert_str_eq(nsurl_access_leaf(res_url), tst->res);

	nsurl_unref(res_url);

}
Пример #28
0
END_TEST

/**
 * has component
 */
START_TEST(nsurl_has_component_test)
{
	nserror err;
	nsurl *url1;
	const struct test_compare *tst = &component_tests[_i];
	bool status;

	/* not testing create, this should always succeed */
	err = nsurl_create(tst->test1, &url1);
	ck_assert(err == NSERROR_OK);

	status = nsurl_has_component(url1, tst->parts);
	ck_assert(status == tst->res);

	nsurl_unref(url1);
}
Пример #29
0
nsurl *gui_get_resource_url(const char *path)
{
	char buf[PATH_MAX];
	char *raw;
	nsurl *url = NULL;

	/* default.css -> gtkdefault.css */
	if (strcmp(path, "default.css") == 0)
		path = "gtkdefault.css";

	/* favicon.ico -> favicon.png */
	if (strcmp(path, "favicon.ico") == 0)
		path = "favicon.png";	

	raw = path_to_url(filepath_sfind(respaths, buf, path));
	if (raw != NULL) {
		nsurl_create(raw, &url);
		free(raw);
	}

	return url;
}
Пример #30
0
void ami_file_open(struct gui_window_2 *gwin)
{
	char *temp, *temp2;
	nsurl *url;

	if(AslRequestTags(filereq,
			ASLFR_TitleText, messages_get("NetSurf"),
			ASLFR_Window, gwin->win,
			ASLFR_SleepWindow, TRUE,
			ASLFR_Screen, scrn,
			ASLFR_DoSaveMode, FALSE,
			ASLFR_RejectIcons, TRUE,
			ASLFR_FilterFunc, &aslhookfunc,
			TAG_DONE))
	{
		if(temp = AllocVecTagList(1024, NULL))
		{
			strlcpy(temp, filereq->fr_Drawer, 1024);
			AddPart(temp, filereq->fr_File, 1024);
			temp2 = path_to_url(temp);

			if (nsurl_create(temp2, &url) != NSERROR_OK) {
				warn_user("NoMemory", 0);
			} else {
				browser_window_navigate(gwin->bw,
					url,
					NULL,
					BW_NAVIGATE_HISTORY,
					NULL,
					NULL,
					NULL);
				nsurl_unref(url);
			}

			free(temp2);
			FreeVec(temp);
		}
	}
}