21#define __STDBOOL_H__ 1
30#include <sys/select.h>
35#include <Application.h>
37#include <FindDirectory.h>
40#include <PathFinder.h>
46#include <LocaleRoster.h>
88#define USE_RESOURCES 1
118 NSLOG(netsurf, INFO,
"warn_user: %s (%s)", warning, detail);
120 BString
text(warning);
122 text <<
":\n" << detail;
124 alert =
new BAlert(
"NetSurf Warning",
text.String(),
"Debug",
"Ok",
125 NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
126 if (alert->Go() < 1) {
127 debugger(
"warn_user");
134 : BApplication(
"application/x-vnd.NetSurf")
147 switch (message->what) {
148 case B_REFS_RECEIVED:
162 case B_NETPOSITIVE_OPEN_URL:
163 case B_NETPOSITIVE_BACK:
164 case B_NETPOSITIVE_FORWARD:
165 case B_NETPOSITIVE_HOME:
166 case B_NETPOSITIVE_RELOAD:
167 case B_NETPOSITIVE_STOP:
168 case B_NETPOSITIVE_DOWN:
169 case B_NETPOSITIVE_UP:
174 BApplication::MessageReceived(message);
187 BMessage *message = DetachCurrentMessage();
195 DetachCurrentMessage();
228#if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO)
229extern "C" char *
realpath(
const char *f,
char *buf);
232 BPath
path(f, NULL,
true);
233 if (
path.InitCheck() < 0) {
234 strncpy(buf, f, MAXPATHLEN);
238 strncpy(buf,
path.Path(), MAXPATHLEN);
250 while (get_next_image_info(0, &cookie, &info) == B_OK) {
256 memset(
path, 0, B_PATH_NAME_LENGTH);
257 strncpy(
path, info.name, B_PATH_NAME_LENGTH-1);
279 const char *cdir = NULL;
284 err = find_directory(B_USER_SETTINGS_DIRECTORY, &
path);
285 path.Append(
"NetSurf");
293 if (access(buf, R_OK) == 0)
297 cdir = getenv(
"HOME");
300 strcat(t,
"/.netsurf/");
303 if (access(buf, R_OK) == 0)
307 cdir = getenv(
"NETSURFRES");
312 strcat(buf, filename);
313 if (access(buf, R_OK) == 0)
321 if (f.FindPath(B_FIND_PATH_APPS_DIRECTORY,
"netsurf/res", p) == B_OK) {
325 if (access(buf, R_OK) == 0)
334 }
else if (def[0] ==
'~') {
335 snprintf(t,
PATH_MAX,
"%s%s", getenv(
"HOME"), def + 1);
356 err = find_directory(B_USER_SETTINGS_DIRECTORY, &
path,
true);
361 "Can't find user settings directory - nowhere to store state!");
362 die(
"NetSurf needs to find the user settings directory in order to run.\n");
365 path.Append(
"NetSurf");
366 err = create_directory(
path.Path(), 0644);
368 NSLOG(netsurf, INFO,
"Unable to create %s",
path.Path());
369 die(
"NetSurf could not create its settings directory.\n");
383 BString u(
"rsrc:///");
386 if (strcmp(
path,
"default.css") == 0)
387 path =
"beosdefault.css";
390 if (strcmp(
path,
"favicon.ico") == 0)
391 path =
"favicon.png";
394 NSLOG(netsurf, INFO,
"(%s) -> '%s'\n",
path, u.String());
401#if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO)
403#define B_PANEL_TEXT_COLOR ((color_which)10)
404#define B_DOCUMENT_BACKGROUND_COLOR ((color_which)11)
405#define B_DOCUMENT_TEXT_COLOR ((color_which)12)
406#define B_CONTROL_BACKGROUND_COLOR ((color_which)13)
407#define B_CONTROL_TEXT_COLOR ((color_which)14)
408#define B_CONTROL_BORDER_COLOR ((color_which)15)
409#define B_CONTROL_HIGHLIGHT_COLOR ((color_which)16)
410#define B_NAVIGATION_BASE_COLOR ((color_which)4)
411#define B_NAVIGATION_PULSE_COLOR ((color_which)17)
412#define B_SHINE_COLOR ((color_which)18)
413#define B_SHADOW_COLOR ((color_which)19)
414#define B_MENU_SELECTED_BORDER_COLOR ((color_which)9)
415#define B_TOOL_TIP_BACKGROUND_COLOR ((color_which)20)
416#define B_TOOL_TIP_TEXT_COLOR ((color_which)21)
417#define B_SUCCESS_COLOR ((color_which)100)
418#define B_FAILURE_COLOR ((color_which)101)
419#define B_MENU_SELECTED_BACKGROUND_COLOR B_MENU_SELECTION_BACKGROUND_COLOR
420#define B_RANDOM_COLOR ((color_which)0x80000000)
421#define B_MICHELANGELO_FAVORITE_COLOR ((color_which)0x80000001)
422#define B_DSANDLER_FAVORITE_SKY_COLOR ((color_which)0x80000002)
423#define B_DSANDLER_FAVORITE_INK_COLOR ((color_which)0x80000003)
424#define B_DSANDLER_FAVORITE_SHOES_COLOR ((color_which)0x80000004)
425#define B_DAVE_BROWN_FAVORITE_COLOR ((color_which)0x80000005)
427#if defined(B_BEOS_VERSION_DANO)
428#define B_TOOL_TIP_BACKGROUND_COLOR B_TOOLTIP_BACKGROUND_COLOR
429#define B_TOOL_TIP_TEXT_COLOR B_TOOLTIP_TEXT_COLOR
432#define NOCOL ((color_which)0)
445 if (ui == B_DESKTOP_COLOR) {
447 c = s.DesktopColor();
452 def_colour = ((((uint32_t)c.blue << 16) & 0xff0000) |
453 ((c.green << 8) & 0x00ff00) |
454 ((c.red) & 0x0000ff));
524 f.FindPath(B_FIND_PATH_APPS_DIRECTORY,
"netsurf/res", p);
527 BMessage preferredLangs;
528 if (BLocaleRoster::Default()->GetPreferredLanguages(&preferredLangs) == B_OK) {
529 preferredLangs.FindString(
"language", 0, &lang);
533 if (lang.Length() < 1) {
534 lang.SetTo(getenv(
"LC_MESSAGES"));
537 BDirectory d(p.Path());
538 if (!d.Contains(lang.String(), B_DIRECTORY_NODE))
540 p.Append(lang.String());
541 p.Append(
"Messages");
580#define FIND_THROB(n) filenames[(n)] = \
581 "throbber/throbber" STROF(n) ".png";
582 const char *filenames[9];
593 filenames[0], filenames[1], filenames[2], filenames[3],
594 filenames[4], filenames[5], filenames[6], filenames[7],
601 die(
"Unable to load throbber image.\n");
604 NSLOG(netsurf, INFO,
"Using '%s' as Preferences file", buf);
612#define SETFONTDEFAULT(OPTION,y) if (nsoption_charp(OPTION) == NULL) nsoption_set_charp(OPTION, strdup((y)))
647 NSLOG(netsurf, INFO,
"Using '%s' as Cookies file", buf);
652 NSLOG(netsurf, INFO,
"Using '%s' as Cookie Jar file", buf);
657 die(
"Failed initialising cookie options");
661 NSLOG(netsurf, INFO,
"Using '%s' as URL file", buf);
667 NSLOG(netsurf, INFO,
"Using '%s' as certificate path", buf);
687 addr = NETSURF_HOMEPAGE;
719 if (message == NULL) {
720 fprintf(stderr,
"%s(NULL)!\n", __FUNCTION__);
724 message->AddPointer(
"View", _this);
726 message->AddPointer(
"gui_window",
gui);
727 write(
sEventPipe[1], &message,
sizeof(
void *));
733 if (message == NULL) {
734 fprintf(stderr,
"%s(NULL)!\n", __FUNCTION__);
738 message->AddPointer(
"Window", _this);
740 message->AddPointer(
"scaffolding",
scaffold);
741 write(
sEventPipe[1], &message,
sizeof(
void *));
747 fd_set read_fd_set, write_fd_set, exc_fd_set;
749 struct timeval timeout;
750 unsigned int fd_count = 0;
751 bigtime_t next_schedule = 0;
757 fetch_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
773 if (next_schedule < 0)
776 timeout.tv_sec = (long)(next_schedule / 1000000LL);
777 timeout.tv_usec = (long)(next_schedule % 1000000LL);
779 NSLOG(netsurf, DEEPDEBUG,
780 "gui_poll: select(%d, ..., %Ldus",
781 max_fd, next_schedule);
782 fd_count = select(max_fd, &read_fd_set, &write_fd_set, &exc_fd_set,
784 NSLOG(netsurf, DEEPDEBUG,
"select: %d\n", fd_count);
786 if (fd_count > 0 && FD_ISSET(
sEventPipe[0], &read_fd_set)) {
788 int len = read(
sEventPipe[0], &message,
sizeof(
void *));
789 NSLOG(netsurf, DEEPDEBUG,
"gui_poll: BMessage ? %d read", len);
790 if (len ==
sizeof(
void *)) {
791 NSLOG(netsurf, DEEPDEBUG,
792 "gui_poll: BMessage.what %-4.4s\n",
793 (
char *)&(message->what));
837 const uint8_t *source;
849 path.SetTo(temp_name);
851 if (entry.SetTo(
path.Path()) >= B_OK
852 && entry.Exists() && entry.IsFile())
863 if (filename.IsEmpty()) {
872 BMimeType
type(lwc_string_data(mime));
874 if (
type.GetFileExtensions(&extensions) == B_OK) {
876 if (extensions.FindString(
"extensions", &ext) == B_OK)
877 filename <<
"." << ext;
883 path.Append(filename.String());
884 BFile file(
path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
885 err = file.InitCheck();
890 err = file.Write(source, size);
897 file.WriteAttr(
"BEOS:TYPE", B_MIME_STRING_TYPE, 0LL,
898 lwc_string_data(mime), lwc_string_length(mime) + 1);
899 lwc_string_unref(mime);
905 if (get_ref_for_path(
path.Path(), &ref) < B_OK)
908 BMessage m(B_REFS_RECEIVED);
909 m.AddRef(
"refs", &ref);
913 const char *editorSigs[] = {
914 "text/x-source-code",
915 "application/x-vnd.beunited.pe",
916 "application/x-vnd.XEmacs",
917 "application/x-vnd.Haiku-StyledEdit",
918 "application/x-vnd.Be-STEE",
919 "application/x-vnd.yT-STEE",
923 for (i = 0; editorSigs[i]; i++) {
926 BMessenger msgr(editorSigs[i], team);
927 if (msgr.SendMessage(&m) >= B_OK)
932 err = be_roster->Launch(editorSigs[i], (BMessage *)&m, &team);
933 if (err >= B_OK || err == B_ALREADY_RUNNING)
946 BString mimeType =
"application/x-vnd.Be.URL.";
949 mimeType.Append(arg, arg.FindFirst(
":"));
953 if (arg.IFindFirst(
"mailto:") == 0)
954 mimeType =
"text/x-email";
959 if (!BMimeType::IsValid(mimeType.String()))
962 status = be_roster->Launch(mimeType.String(), 1, args);
970void die(
const char *
const error)
972 fprintf(stderr,
"%s", error);
974 BString
text(
"Cannot continue:\n");
977 alert =
new BAlert(
"NetSurf Error",
text.String(),
"Debug",
"Ok", NULL,
978 B_WIDTH_AS_USUAL, B_STOP_ALERT);
1026 die(
"NetSurf operation table failed registration");
1029 if (find_directory(B_USER_SETTINGS_DIRECTORY, &
options,
true) == B_OK) {
1030 options.Append(
"x-vnd.NetSurf");
1047 die(
"Options failed to initialise");
1053 BResources resources;
1054 resources.SetToImage((
const void*)
main);
1059 BMessage preferredLangs;
1060 if (BLocaleRoster::Default()->GetPreferredLanguages(&preferredLangs) == B_OK) {
1061 preferredLangs.FindString(
"language", 0, &lang);
1064 if (lang.Length() < 1)
1065 lang.SetTo(getenv(
"LC_MESSAGES"));
1068 sprintf(
path,
"%.2s/Messages", lang.String());
1069 NSLOG(netsurf, INFO,
"Loading messages from resource %s\n",
path);
1071 const uint8_t* res = (
const uint8_t*)resources.LoadResource(
'data',
path, &size);
1072 if (size > 0 && res != NULL) {
1081 die(
"NetSurf failed to initialise");
1123 die(
"NetSurf operation table failed registration");
1126 if (find_directory(B_USER_SETTINGS_DIRECTORY, &
options,
true) == B_OK) {
1127 options.Append(
"x-vnd.NetSurf");
1140 die(
"Options failed to initialise");
1152 die(
"NetSurf failed to initialise");
const char * fetch_filetype(const char *unix_path)
Determine the MIME type of a local file.
int schedule_run(void)
Process events up to current time.
#define B_UI_SETTINGS_CHANGED
struct gui_bitmap_table * beos_bitmap_table
Browser window creation and manipulation interface.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
virtual void AboutRequested()
virtual void MessageReceived(BMessage *message)
virtual void ArgvReceived(int32 argc, char **argv)
virtual ~NSBrowserApplication()
virtual bool QuitRequested()
virtual void RefsReceived(BMessage *message)
struct beos_scaffolding * Scaffolding() const
nserror fetch_fdset(fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, int *maxfd_out)
Get the set of file descriptors the fetchers are currently using.
Fetching of data from a URL (interface).
Unified cookie database public interface.
void urldb_save_cookies(const char *filename)
Save persistent cookies to file.
void urldb_load_cookies(const char *filename)
Load a cookie file into the database.
Useful interned string pointers (interface).
#define FILE_SCHEME_PREFIX_LEN
File url prefix length.
struct gui_download_table * beos_download_table
nserror
Enumeration of error codes.
@ NSERROR_NO_FETCH_HANDLER
No fetch handler for URL scheme.
void fetch_rsrc_unregister(void)
void fetch_rsrc_register(void)
const char * filename_request(void)
Request a new, unique, filename.
#define TEMP_FILENAME_PREFIX
void beos_fetch_filetype_fin(void)
void beos_fetch_filetype_init(void)
struct gui_layout_table * beos_layout_table
Beos font layout handling interface.
struct gui_window * search_current_window
char * realpath(const char *f, char *buf)
void nsbeos_gui_view_source(struct hlcache_handle *content)
Send the source of a content to a text editor.
image_id nsbeos_find_app_path(char *path)
static nsurl * gui_get_resource_url(const char *path)
static void gui_init(int argc, char **argv)
#define SETFONTDEFAULT(OPTION, y)
#define B_TOOL_TIP_BACKGROUND_COLOR
static nserror gui_launch_url(struct nsurl *url)
Broadcast an URL that we can't handle.
int main(int argc, char **argv)
Normal entry point from OS.
void nsbeos_gui_poll(void)
static struct gui_fetch_table beos_fetch_table
static char * url_to_path(const char *url)
#define B_DOCUMENT_TEXT_COLOR
int gui_init_replicant(int argc, char **argv)
called when replicated from NSBaseView::Instantiate()
void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold)
static nserror set_defaults(struct nsoption_s *defaults)
Set option defaults for framebuffer frontend.
static bool nslog_stream_configure(FILE *fptr)
Ensures output logging stream is correctly configured.
static nserror set_colour_from_ui(struct nsoption_s *opts, color_which ui, enum nsoption_e option, colour def_colour)
set option from pen
static void check_homedir(void)
Check that ~/.netsurf/ exists, and if it doesn't, create it.
static void gui_quit(void)
void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui)
char * find_resource(char *buf, const char *filename, const char *def)
Locate a shared resource file by searching known places in order.
#define B_TOOL_TIP_TEXT_COLOR
#define B_CONTROL_BACKGROUND_COLOR
bool replicated
if we are running as a replicant
static struct gui_misc_table beos_misc_table
static int32 bapp_thread(void *arg)
void die(const char *const error)
Cause an abnormal program termination.
nserror beos_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
char * glade_file_location
#define B_CONTROL_TEXT_COLOR
void nsbeos_update_system_ui_colors(void)
static thread_id sBAppThreadID
static BMessage * gFirstRefsReceived
#define B_DOCUMENT_BACKGROUND_COLOR
char * options_file_location
#define B_CONTROL_HIGHLIGHT_COLOR
static BPath get_messages_path()
void nsbeos_options_init(void)
Interface to platform-specific clipboard operations.
Public content interface.
struct nsurl * hlcache_handle_get_url(const struct hlcache_handle *handle)
Retrieve the URL associated with a high level cache handle.
const uint8_t * content_get_source_data(struct hlcache_handle *h, size_t *size)
Retrieve source of content.
lwc_string * content_get_mime_type(struct hlcache_handle *h)
Retrieve mime-type of content.
Interface to platform-specific fetcher operations.
Interface to platform-specific miscellaneous browser operation table.
Interface to platform-specific search operations.
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
Initialise the logging system.
void nslog_finalise(void)
Shut down the logging system.
#define NSLOG(catname, level, logmsg, args...)
nserror messages_add_from_inline(const uint8_t *data, size_t size)
Read keys and values from inline message data into the standard Messages hash.
nserror messages_add_from_file(const char *path)
Read keys and values from messages file into the standard Messages hash.
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Localised message support (interface).
NetSurf core interface registration, construction and destruction.
void netsurf_exit(void)
Finalise NetSurf core.
nserror netsurf_init(const char *store_path)
Initialise netsurf core.
nserror netsurf_register(struct netsurf_table *table)
Register operation table.
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
NSBrowserWindow * nsbeos_find_last_window(void)
nserror beos_schedule(int t, void(*callback)(void *p), void *p)
bigtime_t earliest_callback_timeout
earliest deadline.
Interface to utility string handling.
Content which corresponds to a single URL.
function table for fetcher operations.
Graphical user interface browser misc function table.
first entry in window list
nsbeos_scaffolding * scaffold
struct gui_window::@47 option
Options.
NetSurf operation function table.
union nsoption_s::@149 value
bool nsbeos_throbber_initialise_from_png(const int frames,...)
Creates the throbber using a PNG for each frame.
uint32_t colour
Colour type: XBGR.
nserror url_unescape(const char *str, size_t length, size_t *length_out, char **result_out)
Convert an escaped string to plain.
Interface to URL parsing and joining operations.
Unified URL information database public interface.
nserror urldb_save(const char *filename)
Export the current database to file.
nserror urldb_load(const char *filename)
Import an URL database from file, replacing any existing database.
struct nsoption_s * nsoptions_default
global default option table.
static struct nsoption_s defaults[]
The table of compiled in default options.
nserror nsoption_read(const char *path, struct nsoption_s *opts)
Read choices file and set them in the passed table.
struct nsoption_s * nsoptions
global active option table.
nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts)
Process commandline and set options approriately.
nserror nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **popts, struct nsoption_s **pdefs)
Initialise option system.
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
Finalise option system.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
UTF-8 manipulation functions (interface).
Interface to a number of general purpose functionality.
void nsbeos_dispatch_event(BMessage *message)
Process beos messages into browser operations.
struct gui_clipboard_table * beos_clipboard_table
struct gui_window_table * beos_window_table
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.