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); } }
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); } }
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 ); } } }
static void __CDECL menu_open_url(short item, short title, void *data) { struct gui_window * gw; struct browser_window * bw ; LOG(("%s", __FUNCTION__)); gw = input_window; if( gw == NULL ) { browser_window_create(BROWSER_WINDOW_VERIFIABLE | BROWSER_WINDOW_HISTORY, NULL, NULL, NULL, &bw); gw = bw->window; } /* Loose focus: */ window_set_focus(gw->root, WIDGET_NONE, NULL ); /* trigger on-focus event (select all text): */ window_set_focus(gw->root, URL_WIDGET, NULL); /* delete selection: */ toolbar_key_input(gw->root->toolbar, NK_DEL); }
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; }
/** 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; setbuf(stderr, NULL); respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); options = filepath_find(respaths, "Choices"); messages = filepath_find(respaths, "messages"); netsurf_init(&argc, &argv, options, messages); free(messages); free(options); gui_init(argc, argv); LOG(("calling browser_window_create")); bw = browser_window_create(feurl, 0, 0, true, false); netsurf_main_loop(); browser_window_destroy(bw); netsurf_exit(); return 0; }
/* Menu event handlers: */ static void __CDECL menu_about(WINDOW *win, int item, int title, void *data) { LOG(("%s", __FUNCTION__)); char buf[PATH_MAX]; strcpy((char*)&buf, "file://"); strncat((char*)&buf, (char*)"./doc/README.TXT", PATH_MAX - (strlen("file://")+1) ); browser_window_create((char*)&buf, 0, 0, true, false); }
static void __CDECL menu_ghistory(WINDOW *win, int item, int title, void *data) { LOG(("%s", __FUNCTION__)); char buf[PATH_MAX]; strcpy((char*)&buf, "file://"); strncat((char*)&buf, nsoption_charp(url_file), PATH_MAX - (strlen("file://")+1) ); browser_window_create((char*)&buf, 0, 0, true, false); }
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; }
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); } }
void nsgtk_history_row_activated(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *column) { GtkTreeModel *model; GtkTreeIter iter; model = gtk_tree_view_get_model(tv); if (gtk_tree_model_get_iter(model, &iter, path)) { gchar *address; gtk_tree_model_get(model, &iter, SITE_ADDRESS, &address, -1); browser_window_create(address, NULL, NULL, true, false); } }
static void __CDECL menu_open_file(WINDOW *win, int item, int title, void *data) { struct gui_window * gw; struct browser_window * bw ; LOG(("%s", __FUNCTION__)); const char * filename = file_select( messages_get("OpenFile"), "" ); if( filename != NULL ){ char * url = local_file_to_url( filename ); if( url ){ bw = browser_window_create(url, NULL, NULL, true, false); free( url ); } } }
/** 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]; 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"); LOG(("Initialising core...")); netsurf_init(&argc, &argv, options, messages); LOG(("Initializing GUI...")); gui_init(argc, argv); LOG(("Initializing GUI2")); gui_init2(argc, argv); graf_mouse( ARROW , NULL); LOG(("Creating initial browser window...")); browser_window_create(option_homepage_url, 0, 0, true, false); LOG(("Entering NetSurf mainloop...")); netsurf_main_loop(); netsurf_exit(); LOG(("ApplExit")); #ifdef WITH_DBG_LOGFILE fclose(stdout); fclose(stderr); #endif exit_gem(); return 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); } }
/* Documented in local_history.h */ void browser_window_history_go(struct browser_window *bw, struct history_entry *entry, bool new_window) { struct history *history; nsurl *url; struct history_entry *current; nserror error; assert(bw != NULL); history = bw->history; if (entry->page.frag_id) { error = nsurl_refragment(entry->page.url, entry->page.frag_id, &url); if (error != NSERROR_OK) { warn_user("NoMemory", 0); return; } } else { url = nsurl_ref(entry->page.url); } if (new_window) { current = history->current; history->current = entry; error = browser_window_create(BW_CREATE_CLONE, url, NULL, bw, NULL); history->current = current; if (error != NSERROR_OK) { nsurl_unref(url); return; } } else { history->current = entry; browser_window_navigate(bw, url, NULL, BW_NAVIGATE_NONE, NULL, NULL, NULL); } nsurl_unref(url); }
static void __CDECL menu_open_url(WINDOW *win, int item, int title, void *data) { struct gui_window * gw; struct browser_window * bw ; LOG(("%s", __FUNCTION__)); gw = input_window; if( gw == NULL ) { bw = browser_window_create("", 0, 0, true, false); gw = bw->window; } /* Loose focus: */ window_set_focus( gw, WIDGET_NONE, NULL ); /* trigger on-focus event (select all text): */ window_set_focus( gw, URL_WIDGET, &gw->root->toolbar->url ); /* delete selection: */ tb_url_input( gw, NK_DEL ); }
/** * Launches a node using all known methods. * * \param node the node to launch * \return whether the node could be launched */ bool ami_tree_launch_node(struct tree *tree, struct node *node) { struct node_element *element; assert(node); element = tree_find_element(node, TREE_ELEMENT_URL); if (element) { browser_window_create(element->text, NULL, 0, true, false); return true; } /* not implemented yet element = tree_find_element(node, TREE_ELEMENT_SSL); if (element) { ro_gui_cert_open(tree, node); return true; } */ return false; }
static nserror global_history_tree_node_entry_cb(struct treeview_node_msg msg, void *data) { struct global_history_entry *e = data; nserror ret = NSERROR_OK; switch (msg.msg) { case TREE_MSG_NODE_DELETE: e->entry = NULL; e->user_delete = msg.data.delete.user; global_history_delete_entry_internal(e); break; case TREE_MSG_NODE_EDIT: break; case TREE_MSG_NODE_LAUNCH: { struct browser_window *existing = NULL; enum browser_window_create_flags flags = BW_CREATE_HISTORY; /* TODO: Set existing to window that new tab appears in */ if (msg.data.node_launch.mouse & (BROWSER_MOUSE_MOD_1 | BROWSER_MOUSE_MOD_2) || existing == NULL) { /* Shift or Ctrl launch, open in new window rather * than tab. */ /* TODO: flags ^= BW_CREATE_TAB; */ } ret = browser_window_create(flags, e->url, NULL, existing, NULL); } break; } return ret; }
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; }
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; } }
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); }
/** * 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; }
/** * 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; }
node_callback_resp tree_url_node_callback(void *user_data, struct node_msg_data *msg_data) { struct tree *tree; struct node_element *element; nsurl *nsurl; nserror error; const char *text; char *norm_text; const struct url_data *data; /** @todo memory leaks on non-shared folder deletion. */ switch (msg_data->msg) { case NODE_DELETE_ELEMENT_TXT: switch (msg_data->flag) { /* only history is using non-editable url * elements so only history deletion will run * this code */ case TREE_ELEMENT_URL: /* reset URL characteristics */ urldb_reset_url_visit_data( msg_data->data.text); return NODE_CALLBACK_HANDLED; case TREE_ELEMENT_TITLE: return NODE_CALLBACK_HANDLED; } break; case NODE_DELETE_ELEMENT_IMG: if (msg_data->flag == TREE_ELEMENT_THUMBNAIL || msg_data->flag == TREE_ELEMENT_TITLE) return NODE_CALLBACK_HANDLED; break; case NODE_LAUNCH: element = tree_node_find_element(msg_data->node, TREE_ELEMENT_URL, NULL); if (element != NULL) { text = tree_node_element_get_text(element); if (msg_data->flag == TREE_ELEMENT_LAUNCH_IN_TABS) { msg_data->data.bw = browser_window_create(text, msg_data->data.bw, 0, true, true); } else { browser_window_create(text, NULL, 0, true, false); } return NODE_CALLBACK_HANDLED; } break; case NODE_ELEMENT_EDIT_FINISHING: text = msg_data->data.text; if (msg_data->flag == TREE_ELEMENT_URL) { size_t len; error = nsurl_create(text, &nsurl); if (error != NSERROR_OK) { warn_user("NoMemory", 0); return NODE_CALLBACK_REJECT; } error = nsurl_get(nsurl, NSURL_WITH_FRAGMENT, &norm_text, &len); nsurl_unref(nsurl); if (error != NSERROR_OK) { warn_user("NoMemory", 0); return NODE_CALLBACK_REJECT; } msg_data->data.text = norm_text; data = urldb_get_url_data(norm_text); if (data == NULL) { urldb_add_url(norm_text); urldb_set_url_persistence(norm_text, true); data = urldb_get_url_data(norm_text); if (data == NULL) return NODE_CALLBACK_REJECT; } tree = user_data; tree_update_URL_node(tree, msg_data->node, norm_text, NULL); } else if (msg_data->flag == TREE_ELEMENT_TITLE) { while (isspace(*text)) text++; norm_text = strdup(text); if (norm_text == NULL) { LOG(("malloc failed")); warn_user("NoMemory", 0); return NODE_CALLBACK_REJECT; } /* don't allow zero length entry text, return false */ if (norm_text[0] == '\0') { warn_user("NoNameError", 0); msg_data->data.text = NULL; return NODE_CALLBACK_CONTINUE; } msg_data->data.text = norm_text; } return NODE_CALLBACK_HANDLED; default: break; } return NODE_CALLBACK_NOT_HANDLED; }
/** * Initialize GTK interface. */ static void gui_init(int argc, char** argv, char **respath) { char buf[PATH_MAX]; const char *addr = NETSURF_HOMEPAGE; char *resource_filename; /* check user options */ check_options(respath); /* find the languages file */ languages_file_location = filepath_find(respath, "languages"); if ((languages_file_location == NULL) || (strlen(languages_file_location) < 10)) { die("Unable to find resources.\n"); } /* Obtain resources path location. * * Uses the directory the languages file was found in, * @todo find and slaughter all references to this! */ res_dir_location = calloc(1, strlen(languages_file_location) - 8); memcpy(res_dir_location, languages_file_location, strlen(languages_file_location) - 9); LOG(("Using '%s' for resource path", res_dir_location)); /* initialise the glade templates */ nsgtk_init_glade(respath); /* set default icon if its available */ resource_filename = filepath_find(respath, "netsurf.xpm"); if (resource_filename != NULL) { gtk_window_set_default_icon_from_file(resource_filename, NULL); free(resource_filename); } /* Search engine sources */ search_engines_file_location = filepath_find(respath, "SearchEngines"); LOG(("Using '%s' as Search Engines file", search_engines_file_location)); /* Default Icon */ search_default_ico_location = filepath_find(respath, "default.ico"); LOG(("Using '%s' as default search ico", search_default_ico_location)); /* Default favicon */ resource_filename = filepath_find(respath, "favicon.png"); if (resource_filename != NULL) { favicon_pixbuf = gdk_pixbuf_new_from_file(resource_filename, NULL); free(resource_filename); if (favicon_pixbuf == NULL) { favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16,16); } } /* Toolbar inicies file */ toolbar_indices_file_location = filepath_find(respath, "toolbarIndices"); LOG(("Using '%s' as custom toolbar settings file", toolbar_indices_file_location)); /* load throbber images */ if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false) die("Unable to load throbber image.\n"); /* Initialise completions - cannot fail */ nsgtk_completion_init(); filepath_sfinddef(respath, buf, "mime.types", "/etc/"); gtk_fetch_filetype_init(buf); urldb_load(nsoption_charp(url_file)); urldb_load_cookies(nsoption_charp(cookie_file)); /* The tree view system needs to know the screen's DPI, so we * find that out here, rather than when we create a first browser * window. */ nscss_screen_dpi = FLTTOFIX(gdk_screen_get_resolution( gdk_screen_get_default())); LOG(("Set CSS DPI to %f", FIXTOFLT(nscss_screen_dpi))); if (nsgtk_history_init(glade_file_location->history) == false) die("Unable to initialise history window.\n"); if (nsgtk_download_init(glade_file_location->downloads) == false) die("Unable to initialise download window.\n"); if (nsgtk_cookies_init(glade_file_location->cookies) == false) die("Unable to initialise cookies window.\n"); if (nsgtk_hotlist_init(glade_file_location->hotlist) == false) die("Unable to initialise hotlist window.\n"); sslcert_init(tree_content_icon_name); if (nsoption_charp(homepage_url) != NULL) { addr = nsoption_charp(homepage_url); } if (2 <= argc) addr = argv[1]; /* Last step of initialization. Opens the main browser window. */ browser_window_create(addr, 0, 0, true, false); }
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); } }
/** 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; }
/** * Initialize GTK interface. */ static nserror nsgtk_init(int argc, char** argv, char **respath) { char buf[PATH_MAX]; char *resource_filename; char *addr = NULL; nsurl *url; nserror error; error = nsgtk_builder_new_from_resname("warning", &warning_builder); if (error != NSERROR_OK) { LOG("Unable to initialise warning dialog"); return error; } gtk_builder_connect_signals(warning_builder, NULL); /* set default icon if its available */ error = nsgdk_pixbuf_new_from_resname("netsurf.xpm", &win_default_icon_pixbuf); if (error == NSERROR_OK) { LOG("Seting default window icon"); gtk_window_set_default_icon(win_default_icon_pixbuf); } /* Search engine sources */ resource_filename = filepath_find(respath, "SearchEngines"); search_web_init(resource_filename); if (resource_filename != NULL) { LOG("Using '%s' as Search Engines file", resource_filename); free(resource_filename); } /* Default favicon */ error = nsgdk_pixbuf_new_from_resname("favicon.png", &favicon_pixbuf); if (error != NSERROR_OK) { favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16, 16); } /* arrow down icon */ error = nsgdk_pixbuf_new_from_resname("arrow_down_8x32.png", &arrow_down_pixbuf); if (error != NSERROR_OK) { arrow_down_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 8, 32); } /* initialise throbber */ error = nsgtk_throbber_init(); if (error != NSERROR_OK) { LOG("Unable to initialise throbber."); return error; } /* Initialise completions - cannot fail */ nsgtk_completion_init(); filepath_sfinddef(respath, buf, "mime.types", "/etc/"); gtk_fetch_filetype_init(buf); save_complete_init(); urldb_load(nsoption_charp(url_file)); urldb_load_cookies(nsoption_charp(cookie_file)); /* The tree view system needs to know the screen's DPI, so we * find that out here, rather than when we create a first browser * window. */ browser_set_dpi(gdk_screen_get_resolution(gdk_screen_get_default())); LOG("Set CSS DPI to %d", browser_get_dpi()); /* Initialise top level UI elements */ error = nsgtk_download_init(); if (error != NSERROR_OK) { LOG("Unable to initialise download window."); return error; } /* If there is a url specified on the command line use it */ if (argc > 1) { struct stat fs; if (stat(argv[1], &fs) == 0) { size_t addrlen; char *rp = realpath(argv[1], NULL); assert(rp != NULL); /* calculate file url length including terminator */ addrlen = SLEN("file://") + strlen(rp) + 1; addr = malloc(addrlen); assert(addr != NULL); snprintf(addr, addrlen, "file://%s", rp); free(rp); } else { addr = strdup(argv[1]); } } if (addr != NULL) { /* managed to set up based on local launch */ } else if (nsoption_charp(homepage_url) != NULL) { addr = strdup(nsoption_charp(homepage_url)); } else { addr = strdup(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); } free(addr); return error; }
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); }
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; } }