2008-06-03 23:07:09 +04:00
|
|
|
/*
|
2008-06-07 05:13:07 +04:00
|
|
|
* Copyright 2008 François Revol <mmu_man@users.sourceforge.net>
|
2008-06-03 23:07:09 +04:00
|
|
|
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-08-13 23:35:41 +04:00
|
|
|
#define __STDBOOL_H__ 1
|
2008-06-03 23:07:09 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
#include <Alert.h>
|
|
|
|
#include <Application.h>
|
2008-08-13 23:35:41 +04:00
|
|
|
#include <BeBuild.h>
|
2008-10-02 22:10:22 +04:00
|
|
|
#include <FindDirectory.h>
|
2008-06-03 23:07:09 +04:00
|
|
|
#include <Mime.h>
|
2008-08-13 23:35:41 +04:00
|
|
|
#include <Path.h>
|
2014-06-20 15:23:22 +04:00
|
|
|
#include <PathFinder.h>
|
2008-06-03 23:07:09 +04:00
|
|
|
#include <Roster.h>
|
2013-12-07 04:26:39 +04:00
|
|
|
#include <Screen.h>
|
2008-06-03 23:07:09 +04:00
|
|
|
#include <String.h>
|
|
|
|
|
|
|
|
extern "C" {
|
2008-10-06 00:35:28 +04:00
|
|
|
|
2014-10-17 01:22:51 +04:00
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/filename.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/url.h"
|
2015-02-26 18:58:40 +03:00
|
|
|
#include "utils/corestrings.h"
|
2014-10-17 01:22:51 +04:00
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
#include "content/content.h"
|
2010-08-03 03:35:35 +04:00
|
|
|
#include "content/content_protected.h"
|
2008-06-03 23:07:09 +04:00
|
|
|
#include "content/fetch.h"
|
2014-06-26 21:56:42 +04:00
|
|
|
#include "content/fetchers.h"
|
2011-02-24 01:27:55 +03:00
|
|
|
#include "content/fetchers/resource.h"
|
2014-02-05 02:34:41 +04:00
|
|
|
#include "content/hlcache.h"
|
2008-06-03 23:07:09 +04:00
|
|
|
#include "content/urldb.h"
|
2014-10-25 16:11:10 +04:00
|
|
|
#include "desktop/browser.h"
|
2014-10-17 01:22:51 +04:00
|
|
|
#include "desktop/gui_misc.h"
|
|
|
|
#include "desktop/gui_clipboard.h"
|
|
|
|
#include "desktop/gui_search.h"
|
|
|
|
#include "desktop/gui_fetch.h"
|
2008-06-03 23:07:09 +04:00
|
|
|
#include "desktop/netsurf.h"
|
2014-10-17 01:22:51 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
2012-03-23 01:48:24 +04:00
|
|
|
#include "beos/gui.h"
|
|
|
|
#include "beos/gui_options.h"
|
|
|
|
//#include "beos/completion.h"
|
|
|
|
#include "beos/window.h"
|
|
|
|
#include "beos/throbber.h"
|
|
|
|
#include "beos/filetype.h"
|
2014-01-16 20:27:31 +04:00
|
|
|
#include "beos/download.h"
|
2012-03-23 01:48:24 +04:00
|
|
|
#include "beos/schedule.h"
|
|
|
|
#include "beos/fetch_rsrc.h"
|
|
|
|
#include "beos/scaffolding.h"
|
2015-04-17 01:47:10 +03:00
|
|
|
#include "beos/bitmap.h"
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-06 00:35:28 +04:00
|
|
|
static void *myrealloc(void *ptr, size_t len, void *pw);
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
//TODO: use resources
|
2008-10-02 17:34:20 +04:00
|
|
|
// enable using resources instead of files
|
|
|
|
#define USE_RESOURCES 1
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2014-10-13 03:15:44 +04:00
|
|
|
bool nsbeos_done = false;
|
|
|
|
|
2008-10-16 18:24:09 +04:00
|
|
|
bool replicated = false; /**< if we are running as a replicant */
|
2008-06-03 23:07:09 +04:00
|
|
|
|
|
|
|
char *options_file_location;
|
|
|
|
char *glade_file_location;
|
|
|
|
|
|
|
|
struct gui_window *search_current_window = 0;
|
|
|
|
|
|
|
|
BWindow *wndAbout;
|
|
|
|
BWindow *wndWarning;
|
|
|
|
//GladeXML *gladeWindows;
|
|
|
|
BWindow *wndTooltip;
|
|
|
|
//beosLabel *labelTooltip;
|
|
|
|
BFilePanel *wndOpenFile;
|
|
|
|
|
|
|
|
static thread_id sBAppThreadID;
|
|
|
|
|
2008-10-02 23:57:19 +04:00
|
|
|
static BMessage *gFirstRefsReceived = NULL;
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
static int sEventPipe[2];
|
|
|
|
|
|
|
|
// #pragma mark - class NSBrowserFrameView
|
|
|
|
|
|
|
|
|
|
|
|
NSBrowserApplication::NSBrowserApplication()
|
|
|
|
: BApplication("application/x-vnd.NetSurf")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSBrowserApplication::~NSBrowserApplication()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
NSBrowserApplication::MessageReceived(BMessage *message)
|
|
|
|
{
|
|
|
|
switch (message->what) {
|
|
|
|
case B_REFS_RECEIVED:
|
2014-01-16 21:12:41 +04:00
|
|
|
case B_UI_SETTINGS_CHANGED:
|
2008-06-03 23:07:09 +04:00
|
|
|
// messages for top-level
|
|
|
|
// we'll just send them to the first window
|
|
|
|
case 'back':
|
|
|
|
case 'forw':
|
|
|
|
case 'stop':
|
|
|
|
case 'relo':
|
|
|
|
case 'home':
|
|
|
|
case 'urlc':
|
|
|
|
case 'urle':
|
|
|
|
case 'menu':
|
2008-10-16 20:01:44 +04:00
|
|
|
// NetPositive messages
|
|
|
|
case B_NETPOSITIVE_OPEN_URL:
|
|
|
|
case B_NETPOSITIVE_BACK:
|
|
|
|
case B_NETPOSITIVE_FORWARD:
|
|
|
|
case B_NETPOSITIVE_HOME:
|
|
|
|
case B_NETPOSITIVE_RELOAD:
|
|
|
|
case B_NETPOSITIVE_STOP:
|
|
|
|
case B_NETPOSITIVE_DOWN:
|
|
|
|
case B_NETPOSITIVE_UP:
|
2008-06-03 23:07:09 +04:00
|
|
|
//DetachCurrentMessage();
|
|
|
|
//nsbeos_pipe_message(message, this, fGuiWindow);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BApplication::MessageReceived(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-02 23:57:19 +04:00
|
|
|
void
|
|
|
|
NSBrowserApplication::ArgvReceived(int32 argc, char **argv)
|
|
|
|
{
|
2008-10-09 05:22:14 +04:00
|
|
|
NSBrowserWindow *win = nsbeos_find_last_window();
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
win->Unlock();
|
|
|
|
BMessage *message = DetachCurrentMessage();
|
|
|
|
nsbeos_pipe_message_top(message, win, win->Scaffolding());
|
2008-10-02 23:57:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
void
|
|
|
|
NSBrowserApplication::RefsReceived(BMessage *message)
|
|
|
|
{
|
|
|
|
DetachCurrentMessage();
|
|
|
|
NSBrowserWindow *win = nsbeos_find_last_window();
|
2008-10-02 23:57:19 +04:00
|
|
|
if (!win) {
|
|
|
|
gFirstRefsReceived = message;
|
2008-06-03 23:07:09 +04:00
|
|
|
return;
|
2008-10-02 23:57:19 +04:00
|
|
|
}
|
2008-06-03 23:07:09 +04:00
|
|
|
win->Unlock();
|
|
|
|
nsbeos_pipe_message_top(message, win, win->Scaffolding());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-09 05:22:14 +04:00
|
|
|
void
|
|
|
|
NSBrowserApplication::AboutRequested()
|
|
|
|
{
|
|
|
|
nsbeos_pipe_message(new BMessage(B_ABOUT_REQUESTED), NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
bool
|
|
|
|
NSBrowserApplication::QuitRequested()
|
|
|
|
{
|
|
|
|
// let it notice it
|
|
|
|
nsbeos_pipe_message(new BMessage(B_QUIT_REQUESTED), NULL, NULL);
|
|
|
|
// we'll let the main thread Quit() ourselves when it's done.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark - implementation
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-13 23:35:41 +04:00
|
|
|
/* realpath fallback on R5 */
|
|
|
|
#if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO)
|
2010-08-03 03:35:35 +04:00
|
|
|
extern "C" char *realpath(const char *f, char *buf);
|
2008-08-13 23:35:41 +04:00
|
|
|
char *realpath(const char *f, char *buf)
|
|
|
|
{
|
|
|
|
BPath path(f, NULL, true);
|
|
|
|
if (path.InitCheck() < 0) {
|
|
|
|
strncpy(buf, f, MAXPATHLEN);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-04-22 21:59:00 +04:00
|
|
|
//printf("RP: '%s'\n", path.Path());
|
2008-08-13 23:35:41 +04:00
|
|
|
strncpy(buf, path.Path(), MAXPATHLEN);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 18:24:09 +04:00
|
|
|
/* finds the NetSurf binary image ID and path
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
image_id nsbeos_find_app_path(char *path)
|
|
|
|
{
|
|
|
|
image_info info;
|
|
|
|
int32 cookie = 0;
|
|
|
|
while (get_next_image_info(0, &cookie, &info) == B_OK) {
|
|
|
|
//fprintf(stderr, "%p <> %p, %p\n", (char *)&find_app_resources, (char *)info.text, (char *)info.text + info.text_size);
|
|
|
|
if (((char *)&nsbeos_find_app_path >= (char *)info.text)
|
|
|
|
&& ((char *)&nsbeos_find_app_path < (char *)info.text + info.text_size)) {
|
|
|
|
//fprintf(stderr, "match\n");
|
2008-10-17 00:52:00 +04:00
|
|
|
if (path) {
|
|
|
|
memset(path, 0, B_PATH_NAME_LENGTH);
|
|
|
|
strncpy(path, info.name, B_PATH_NAME_LENGTH-1);
|
|
|
|
}
|
2008-10-16 18:24:09 +04:00
|
|
|
return info.id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
/**
|
|
|
|
* Locate a shared resource file by searching known places in order.
|
|
|
|
*
|
2014-11-09 01:08:29 +03:00
|
|
|
* Search order is: ~/config/settings/NetSurf/, ~/.netsurf/, $NETSURFRES/
|
|
|
|
* (where NETSURFRES is an environment variable), and finally the path
|
|
|
|
* specified by the macro at the top of this file.
|
|
|
|
*
|
2008-06-03 23:07:09 +04:00
|
|
|
* \param buf buffer to write to. must be at least PATH_MAX chars
|
|
|
|
* \param filename file to look for
|
|
|
|
* \param def default to return if file not found
|
2014-11-09 01:08:29 +03:00
|
|
|
* \return path to resource.
|
2008-06-03 23:07:09 +04:00
|
|
|
*/
|
|
|
|
static char *find_resource(char *buf, const char *filename, const char *def)
|
|
|
|
{
|
2008-10-02 22:10:22 +04:00
|
|
|
const char *cdir = NULL;
|
|
|
|
status_t err;
|
|
|
|
BPath path;
|
2008-06-03 23:07:09 +04:00
|
|
|
char t[PATH_MAX];
|
|
|
|
|
2008-10-02 22:10:22 +04:00
|
|
|
err = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
|
|
|
path.Append("NetSurf");
|
|
|
|
if (err >= B_OK)
|
|
|
|
cdir = path.Path();
|
|
|
|
if (cdir != NULL) {
|
|
|
|
strcpy(t, cdir);
|
|
|
|
strcat(t, "/");
|
|
|
|
strcat(t, filename);
|
|
|
|
realpath(t, buf);
|
|
|
|
if (access(buf, R_OK) == 0)
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
cdir = getenv("HOME");
|
2008-06-03 23:07:09 +04:00
|
|
|
if (cdir != NULL) {
|
|
|
|
strcpy(t, cdir);
|
|
|
|
strcat(t, "/.netsurf/");
|
|
|
|
strcat(t, filename);
|
|
|
|
realpath(t, buf);
|
|
|
|
if (access(buf, R_OK) == 0)
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
cdir = getenv("NETSURFRES");
|
|
|
|
|
|
|
|
if (cdir != NULL) {
|
|
|
|
realpath(cdir, buf);
|
|
|
|
strcat(buf, "/");
|
|
|
|
strcat(buf, filename);
|
|
|
|
if (access(buf, R_OK) == 0)
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-06-20 15:23:22 +04:00
|
|
|
|
|
|
|
BPathFinder f((void*)find_resource);
|
|
|
|
|
|
|
|
BPath p;
|
2014-07-02 05:11:25 +04:00
|
|
|
if (f.FindPath(B_FIND_PATH_APPS_DIRECTORY, "netsurf/res", p) == B_OK) {
|
|
|
|
strcpy(t, p.Path());
|
|
|
|
strcat(t, filename);
|
|
|
|
realpath(t, buf);
|
|
|
|
if (access(buf, R_OK) == 0)
|
|
|
|
return buf;
|
|
|
|
}
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 22:10:22 +04:00
|
|
|
if (def[0] == '%') {
|
|
|
|
snprintf(t, PATH_MAX, "%s%s", path.Path(), def + 1);
|
2014-07-02 05:40:32 +04:00
|
|
|
if (realpath(t, buf) == NULL) {
|
|
|
|
strcpy(buf, t);
|
|
|
|
}
|
2008-10-02 22:10:22 +04:00
|
|
|
} else if (def[0] == '~') {
|
2008-06-03 23:07:09 +04:00
|
|
|
snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1);
|
2014-07-02 05:40:32 +04:00
|
|
|
if (realpath(t, buf) == NULL) {
|
|
|
|
strcpy(buf, t);
|
|
|
|
}
|
2008-06-03 23:07:09 +04:00
|
|
|
} else {
|
2014-07-02 05:40:32 +04:00
|
|
|
if (realpath(def, buf) == NULL) {
|
|
|
|
strcpy(buf, def);
|
|
|
|
}
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that ~/.netsurf/ exists, and if it doesn't, create it.
|
|
|
|
*/
|
|
|
|
static void check_homedir(void)
|
|
|
|
{
|
2008-10-02 22:10:22 +04:00
|
|
|
status_t err;
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 22:10:22 +04:00
|
|
|
BPath path;
|
|
|
|
err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-02 22:10:22 +04:00
|
|
|
if (err < B_OK) {
|
|
|
|
/* we really can't continue without a home directory. */
|
|
|
|
LOG(("Can't find user settings directory - nowhere to store state!"));
|
|
|
|
die("NetSurf needs to find the user settings directory in order to run.\n");
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
2008-10-02 22:10:22 +04:00
|
|
|
path.Append("NetSurf");
|
|
|
|
err = create_directory(path.Path(), 0644);
|
|
|
|
if (err < B_OK) {
|
|
|
|
LOG(("Unable to create %s", path.Path()));
|
|
|
|
die("NetSurf could not create its settings directory.\n");
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32 bapp_thread(void *arg)
|
|
|
|
{
|
|
|
|
be_app->Lock();
|
|
|
|
be_app->Run();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-15 16:28:55 +04:00
|
|
|
static nsurl *gui_get_resource_url(const char *path)
|
2011-02-24 01:27:55 +03:00
|
|
|
{
|
2011-10-05 12:32:52 +04:00
|
|
|
nsurl *url = NULL;
|
2012-03-19 07:19:03 +04:00
|
|
|
BString u("rsrc:///");
|
2013-12-31 19:05:15 +04:00
|
|
|
|
|
|
|
/* default.css -> beosdefault.css */
|
2011-10-05 12:32:52 +04:00
|
|
|
if (strcmp(path, "default.css") == 0)
|
2013-12-31 19:05:15 +04:00
|
|
|
path = "beosdefault.css";
|
|
|
|
|
|
|
|
/* favicon.ico -> favicon.png */
|
|
|
|
if (strcmp(path, "favicon.ico") == 0)
|
|
|
|
path = "favicon.png";
|
|
|
|
|
|
|
|
u << path;
|
2012-11-25 23:00:27 +04:00
|
|
|
LOG(("(%s) -> '%s'\n", path, u.String()));
|
2011-10-05 12:32:52 +04:00
|
|
|
nsurl_create(u.String(), &url);
|
|
|
|
return url;
|
2011-02-24 01:27:55 +03:00
|
|
|
}
|
|
|
|
|
2010-03-29 20:59:30 +04:00
|
|
|
|
2013-05-28 15:55:34 +04:00
|
|
|
|
|
|
|
#if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO)
|
|
|
|
/* more ui_colors, R5 only had a few defined... */
|
|
|
|
#define B_PANEL_TEXT_COLOR ((color_which)10)
|
|
|
|
#define B_DOCUMENT_BACKGROUND_COLOR ((color_which)11)
|
|
|
|
#define B_DOCUMENT_TEXT_COLOR ((color_which)12)
|
|
|
|
#define B_CONTROL_BACKGROUND_COLOR ((color_which)13)
|
|
|
|
#define B_CONTROL_TEXT_COLOR ((color_which)14)
|
|
|
|
#define B_CONTROL_BORDER_COLOR ((color_which)15)
|
|
|
|
#define B_CONTROL_HIGHLIGHT_COLOR ((color_which)16)
|
|
|
|
#define B_NAVIGATION_BASE_COLOR ((color_which)4)
|
|
|
|
#define B_NAVIGATION_PULSE_COLOR ((color_which)17)
|
|
|
|
#define B_SHINE_COLOR ((color_which)18)
|
|
|
|
#define B_SHADOW_COLOR ((color_which)19)
|
|
|
|
#define B_MENU_SELECTED_BORDER_COLOR ((color_which)9)
|
|
|
|
#define B_TOOL_TIP_BACKGROUND_COLOR ((color_which)20)
|
|
|
|
#define B_TOOL_TIP_TEXT_COLOR ((color_which)21)
|
|
|
|
#define B_SUCCESS_COLOR ((color_which)100)
|
|
|
|
#define B_FAILURE_COLOR ((color_which)101)
|
|
|
|
#define B_MENU_SELECTED_BACKGROUND_COLOR B_MENU_SELECTION_BACKGROUND_COLOR
|
|
|
|
#define B_RANDOM_COLOR ((color_which)0x80000000)
|
|
|
|
#define B_MICHELANGELO_FAVORITE_COLOR ((color_which)0x80000001)
|
|
|
|
#define B_DSANDLER_FAVORITE_SKY_COLOR ((color_which)0x80000002)
|
|
|
|
#define B_DSANDLER_FAVORITE_INK_COLOR ((color_which)0x80000003)
|
|
|
|
#define B_DSANDLER_FAVORITE_SHOES_COLOR ((color_which)0x80000004)
|
|
|
|
#define B_DAVE_BROWN_FAVORITE_COLOR ((color_which)0x80000005)
|
|
|
|
#endif
|
|
|
|
#if defined(B_BEOS_VERSION_DANO)
|
|
|
|
#define B_TOOL_TIP_BACKGROUND_COLOR B_TOOLTIP_BACKGROUND_COLOR
|
|
|
|
#define B_TOOL_TIP_TEXT_COLOR B_TOOLTIP_TEXT_COLOR
|
|
|
|
#define
|
|
|
|
#endif
|
|
|
|
#define NOCOL ((color_which)0)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set option from pen
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
set_colour_from_ui(struct nsoption_s *opts,
|
|
|
|
color_which ui,
|
|
|
|
enum nsoption_e option,
|
|
|
|
colour def_colour)
|
|
|
|
{
|
2013-12-07 04:28:55 +04:00
|
|
|
if (ui != NOCOL) {
|
|
|
|
rgb_color c;
|
|
|
|
if (ui == B_DESKTOP_COLOR) {
|
2013-05-28 15:55:34 +04:00
|
|
|
BScreen s;
|
|
|
|
c = s.DesktopColor();
|
2013-12-07 04:28:55 +04:00
|
|
|
} else {
|
|
|
|
c = ui_color(ui);
|
|
|
|
}
|
|
|
|
|
|
|
|
def_colour = ((((uint32_t)c.blue << 16) & 0xff0000) |
|
|
|
|
((c.green << 8) & 0x00ff00) |
|
|
|
|
((c.red) & 0x0000ff));
|
|
|
|
}
|
2013-12-07 04:26:39 +04:00
|
|
|
|
|
|
|
opts[option].value.c = def_colour;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2013-05-28 15:55:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set option defaults for framebuffer frontend
|
|
|
|
*
|
|
|
|
* @param defaults The option table to update.
|
|
|
|
* @return error status.
|
|
|
|
*/
|
|
|
|
static nserror set_defaults(struct nsoption_s *defaults)
|
|
|
|
{
|
|
|
|
/* set system colours for beos ui */
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_ActiveBorder, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, B_WINDOW_TAB_COLOR, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd);
|
|
|
|
set_colour_from_ui(defaults, B_PANEL_BACKGROUND_COLOR, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee);
|
|
|
|
set_colour_from_ui(defaults, B_DESKTOP_COLOR, NSOPTION_sys_colour_Background, 0x00aa0000);
|
|
|
|
set_colour_from_ui(defaults, B_CONTROL_BACKGROUND_COLOR, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa);
|
|
|
|
set_colour_from_ui(defaults, B_CONTROL_HIGHLIGHT_COLOR, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb);
|
|
|
|
set_colour_from_ui(defaults, B_CONTROL_TEXT_COLOR, NSOPTION_sys_colour_ButtonText, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_CaptionText, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_GrayText, 0x00777777);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_Highlight, 0x00ee0000);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_HighlightText, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_InactiveBorder, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc);
|
|
|
|
set_colour_from_ui(defaults, B_TOOL_TIP_BACKGROUND_COLOR, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa);
|
|
|
|
set_colour_from_ui(defaults, B_TOOL_TIP_TEXT_COLOR, NSOPTION_sys_colour_InfoText, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, B_MENU_BACKGROUND_COLOR, NSOPTION_sys_colour_Menu, 0x00aaaaaa);
|
|
|
|
set_colour_from_ui(defaults, B_MENU_ITEM_TEXT_COLOR, NSOPTION_sys_colour_MenuText, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_ThreeDShadow, 0x00777777);
|
|
|
|
set_colour_from_ui(defaults, B_DOCUMENT_BACKGROUND_COLOR, NSOPTION_sys_colour_Window, 0x00aaaaaa);
|
|
|
|
set_colour_from_ui(defaults, NOCOL, NSOPTION_sys_colour_WindowFrame, 0x00000000);
|
|
|
|
set_colour_from_ui(defaults, B_DOCUMENT_TEXT_COLOR, NSOPTION_sys_colour_WindowText, 0x00000000);
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-16 21:12:41 +04:00
|
|
|
void nsbeos_update_system_ui_colors(void)
|
|
|
|
{
|
|
|
|
set_defaults(nsoptions);
|
|
|
|
}
|
|
|
|
|
2013-05-23 14:50:57 +04:00
|
|
|
/**
|
|
|
|
* Ensures output logging stream is correctly configured
|
|
|
|
*/
|
|
|
|
static bool nslog_stream_configure(FILE *fptr)
|
|
|
|
{
|
|
|
|
/* set log stream to be non-buffering */
|
|
|
|
setbuf(fptr, NULL);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-30 19:18:53 +04:00
|
|
|
static BPath get_messages_path()
|
|
|
|
{
|
2014-06-20 15:23:22 +04:00
|
|
|
BPathFinder f((void*)get_messages_path);
|
|
|
|
|
|
|
|
BPath p;
|
|
|
|
f.FindPath(B_FIND_PATH_APPS_DIRECTORY, "netsurf/res", p);
|
2013-12-30 19:18:53 +04:00
|
|
|
// TODO: use Haiku's BLocale stuff
|
|
|
|
BString lang(getenv("LC_MESSAGES"));
|
|
|
|
lang.Truncate(2);
|
|
|
|
BDirectory d(p.Path());
|
|
|
|
if (!d.Contains(lang.String(), B_DIRECTORY_NODE))
|
|
|
|
lang = "en";
|
|
|
|
p.Append(lang.String());
|
|
|
|
p.Append("Messages");
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-11-25 22:47:48 +04:00
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
static void gui_init(int argc, char** argv)
|
2008-06-03 23:07:09 +04:00
|
|
|
{
|
2014-01-11 18:20:30 +04:00
|
|
|
const char *addr;
|
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
2008-06-03 23:07:09 +04:00
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
|
|
|
if (pipe(sEventPipe) < 0)
|
|
|
|
return;
|
2008-10-16 18:24:09 +04:00
|
|
|
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;
|
|
|
|
}
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2014-01-16 21:12:41 +04:00
|
|
|
nsbeos_update_system_ui_colors();
|
2011-01-30 22:23:42 +03:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
fetch_rsrc_register();
|
|
|
|
|
|
|
|
check_homedir();
|
|
|
|
|
2008-10-03 07:42:10 +04:00
|
|
|
// make sure the cache dir exists
|
2013-12-30 18:32:50 +04:00
|
|
|
create_directory(TEMP_FILENAME_PREFIX, 0700);
|
2008-10-03 07:42:10 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
//nsbeos_completion_init();
|
|
|
|
|
2008-06-04 05:53:20 +04:00
|
|
|
|
|
|
|
/* 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
|
2008-06-07 06:48:31 +04:00
|
|
|
#define FIND_THROB(n) filenames[(n)] = \
|
2013-12-31 17:28:09 +04:00
|
|
|
"throbber/throbber" STROF(n) ".png";
|
2008-06-07 06:48:31 +04:00
|
|
|
char *filenames[9];
|
2008-06-04 05:53:20 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
if (nsbeos_throbber == NULL)
|
|
|
|
die("Unable to load throbber image.\n");
|
|
|
|
|
2008-10-02 22:10:22 +04:00
|
|
|
find_resource(buf, "Choices", "%/Choices");
|
2008-06-03 23:07:09 +04:00
|
|
|
LOG(("Using '%s' as Preferences file", buf));
|
|
|
|
options_file_location = strdup(buf);
|
2013-05-28 19:44:46 +04:00
|
|
|
nsoption_read(buf, NULL);
|
2008-06-03 23:07:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* check what the font settings are, setting them to a default font
|
|
|
|
* if they're not set - stops Pango whinging
|
|
|
|
*/
|
2012-11-16 01:34:42 +04:00
|
|
|
#define SETFONTDEFAULT(OPTION,y) if (nsoption_charp(OPTION) == NULL) nsoption_set_charp(OPTION, strdup((y)))
|
2012-03-22 13:34:34 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
//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);
|
2012-11-16 01:34:42 +04:00
|
|
|
SETFONTDEFAULT(font_sans, family);
|
|
|
|
SETFONTDEFAULT(font_serif, family);
|
|
|
|
SETFONTDEFAULT(font_mono, family);
|
|
|
|
SETFONTDEFAULT(font_cursive, family);
|
|
|
|
SETFONTDEFAULT(font_fantasy, family);
|
2008-06-03 23:07:09 +04:00
|
|
|
*/
|
|
|
|
#ifdef __HAIKU__
|
2012-11-16 01:34:42 +04:00
|
|
|
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");
|
2008-06-03 23:07:09 +04:00
|
|
|
#else
|
2012-11-16 01:34:42 +04:00
|
|
|
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");
|
2008-06-03 23:07:09 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsbeos_options_init();
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if (nsoption_charp(cookie_file) == NULL) {
|
2008-10-02 22:10:22 +04:00
|
|
|
find_resource(buf, "Cookies", "%/Cookies");
|
2008-06-03 23:07:09 +04:00
|
|
|
LOG(("Using '%s' as Cookies file", buf));
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_set_charp(cookie_file, strdup(buf));
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
2012-03-22 13:34:34 +04:00
|
|
|
if (nsoption_charp(cookie_jar) == NULL) {
|
2008-10-02 22:10:22 +04:00
|
|
|
find_resource(buf, "Cookies", "%/Cookies");
|
2008-06-03 23:07:09 +04:00
|
|
|
LOG(("Using '%s' as Cookie Jar file", buf));
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_set_charp(cookie_jar, strdup(buf));
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
2012-03-22 13:34:34 +04:00
|
|
|
if ((nsoption_charp(cookie_file) == NULL) ||
|
|
|
|
(nsoption_charp(cookie_jar) == NULL))
|
2008-06-03 23:07:09 +04:00
|
|
|
die("Failed initialising cookie options");
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if (nsoption_charp(url_file) == NULL) {
|
2008-10-02 22:10:22 +04:00
|
|
|
find_resource(buf, "URLs", "%/URLs");
|
2008-06-03 23:07:09 +04:00
|
|
|
LOG(("Using '%s' as URL file", buf));
|
2012-03-23 01:11:35 +04:00
|
|
|
nsoption_set_charp(url_file, strdup(buf));
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if (nsoption_charp(ca_path) == NULL) {
|
2008-06-03 23:07:09 +04:00
|
|
|
find_resource(buf, "certs", "/etc/ssl/certs");
|
|
|
|
LOG(("Using '%s' as certificate path", buf));
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_set_charp(ca_path, strdup(buf));
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
2008-10-02 18:10:52 +04:00
|
|
|
//find_resource(buf, "mime.types", "/etc/mime.types");
|
|
|
|
beos_fetch_filetype_init();
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
urldb_load(nsoption_charp(url_file));
|
|
|
|
urldb_load_cookies(nsoption_charp(cookie_file));
|
2008-06-03 23:07:09 +04:00
|
|
|
|
|
|
|
//nsbeos_download_initialise();
|
|
|
|
|
2008-10-16 18:24:09 +04:00
|
|
|
if (!replicated)
|
|
|
|
be_app->Unlock();
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
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) {
|
2014-02-13 20:18:17 +04:00
|
|
|
error = browser_window_create(
|
2014-02-10 18:08:45 +04:00
|
|
|
BW_CREATE_HISTORY,
|
2014-01-11 18:20:30 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui)
|
|
|
|
{
|
|
|
|
if (message == NULL) {
|
|
|
|
fprintf(stderr, "%s(NULL)!\n", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this)
|
|
|
|
message->AddPointer("View", _this);
|
|
|
|
if (gui)
|
|
|
|
message->AddPointer("gui_window", gui);
|
|
|
|
int len = write(sEventPipe[1], &message, sizeof(void *));
|
|
|
|
//LOG(("nsbeos_pipe_message: %d written", len));
|
2008-10-06 08:11:28 +04:00
|
|
|
//printf("nsbeos_pipe_message: %d written\n", len);
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold)
|
|
|
|
{
|
|
|
|
if (message == NULL) {
|
|
|
|
fprintf(stderr, "%s(NULL)!\n", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this)
|
|
|
|
message->AddPointer("Window", _this);
|
|
|
|
if (scaffold)
|
|
|
|
message->AddPointer("scaffolding", scaffold);
|
|
|
|
int len = write(sEventPipe[1], &message, sizeof(void *));
|
|
|
|
//LOG(("nsbeos_pipe_message: %d written", len));
|
2008-10-06 08:11:28 +04:00
|
|
|
//printf("nsbeos_pipe_message: %d written\n", len);
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-13 03:15:44 +04:00
|
|
|
void nsbeos_gui_poll(void)
|
2008-06-03 23:07:09 +04:00
|
|
|
{
|
|
|
|
fd_set read_fd_set, write_fd_set, exc_fd_set;
|
2014-06-26 21:56:42 +04:00
|
|
|
int max_fd;
|
2008-06-03 23:07:09 +04:00
|
|
|
struct timeval timeout;
|
|
|
|
unsigned int fd_count = 0;
|
2012-11-16 01:34:42 +04:00
|
|
|
bigtime_t next_schedule = 0;
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2014-06-26 21:56:42 +04:00
|
|
|
/* get any active fetcher fd */
|
|
|
|
fetcher_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2014-06-26 21:56:42 +04:00
|
|
|
/* run the scheduler */
|
|
|
|
schedule_run();
|
2012-11-25 21:17:55 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
// our own event pipe
|
|
|
|
FD_SET(sEventPipe[0], &read_fd_set);
|
2014-06-26 21:56:42 +04:00
|
|
|
|
2014-07-02 19:54:57 +04:00
|
|
|
// max of all the fds in the set, plus one for select()
|
|
|
|
max_fd = MAX(max_fd, sEventPipe[0]) + 1;
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2014-06-30 19:40:56 +04:00
|
|
|
// compute schedule timeout
|
|
|
|
if (earliest_callback_timeout != B_INFINITE_TIMEOUT) {
|
|
|
|
next_schedule = earliest_callback_timeout - system_time();
|
|
|
|
} else {
|
|
|
|
next_schedule = earliest_callback_timeout;
|
2014-06-26 21:56:42 +04:00
|
|
|
}
|
2012-11-25 21:17:55 +04:00
|
|
|
|
2014-06-30 19:40:56 +04:00
|
|
|
// we're quite late already...
|
|
|
|
if (next_schedule < 0)
|
|
|
|
next_schedule = 0;
|
2012-11-16 01:34:42 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
timeout.tv_sec = (long)(next_schedule / 1000000LL);
|
|
|
|
timeout.tv_usec = (long)(next_schedule % 1000000LL);
|
|
|
|
|
2012-11-25 21:17:55 +04:00
|
|
|
//LOG(("gui_poll: select(%d, ..., %Ldus", max_fd, next_schedule));
|
|
|
|
fd_count = select(max_fd, &read_fd_set, &write_fd_set, &exc_fd_set,
|
2014-06-30 19:40:56 +04:00
|
|
|
&timeout);
|
2012-11-25 21:17:55 +04:00
|
|
|
//LOG(("select: %d\n", fd_count));
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-06 04:29:02 +04:00
|
|
|
if (fd_count > 0 && FD_ISSET(sEventPipe[0], &read_fd_set)) {
|
2008-06-03 23:07:09 +04:00
|
|
|
BMessage *message;
|
|
|
|
int len = read(sEventPipe[0], &message, sizeof(void *));
|
2012-11-25 21:17:55 +04:00
|
|
|
//LOG(("gui_poll: BMessage ? %d read", len));
|
|
|
|
if (len == sizeof(void *)) {
|
|
|
|
//LOG(("gui_poll: BMessage.what %-4.4s\n", &(message->what)));
|
2008-06-03 23:07:09 +04:00
|
|
|
nsbeos_dispatch_event(message);
|
2012-11-25 21:17:55 +04:00
|
|
|
}
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
static void gui_quit(void)
|
2008-06-03 23:07:09 +04:00
|
|
|
{
|
2012-03-22 13:34:34 +04:00
|
|
|
urldb_save_cookies(nsoption_charp(cookie_jar));
|
|
|
|
urldb_save(nsoption_charp(url_file));
|
|
|
|
//options_save_tree(hotlist,nsoption_charp(hotlist_file),messages_get("TreeHotlist"));
|
2008-10-06 00:35:28 +04:00
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
free(nsoption_charp(cookie_file));
|
|
|
|
free(nsoption_charp(cookie_jar));
|
2008-06-03 23:07:09 +04:00
|
|
|
beos_fetch_filetype_fin();
|
|
|
|
fetch_rsrc_unregister();
|
|
|
|
}
|
|
|
|
|
2014-01-26 03:00:22 +04:00
|
|
|
static char *url_to_path(const char *url)
|
|
|
|
{
|
|
|
|
char *url_path = curl_unescape(url, 0);
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
/* return the absolute path including leading / */
|
|
|
|
path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
|
|
|
|
curl_free(url_path);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2008-06-03 23:07:09 +04:00
|
|
|
|
2008-10-03 07:42:10 +04:00
|
|
|
/**
|
|
|
|
* Send the source of a content to a text editor.
|
|
|
|
*/
|
|
|
|
|
2013-02-22 19:12:10 +04:00
|
|
|
void nsbeos_gui_view_source(struct hlcache_handle *content)
|
2008-10-03 07:42:10 +04:00
|
|
|
{
|
|
|
|
char *temp_name;
|
|
|
|
bool done = false;
|
|
|
|
BPath path;
|
|
|
|
status_t err;
|
2010-08-03 03:35:35 +04:00
|
|
|
size_t size;
|
|
|
|
const char *source = content_get_source_data(content, &size);
|
2008-10-03 07:42:10 +04:00
|
|
|
|
2010-08-03 03:35:35 +04:00
|
|
|
if (!content || !source) {
|
2008-10-03 07:42:10 +04:00
|
|
|
warn_user("MiscError", "No document source");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to load local files directly. */
|
2011-12-04 18:55:23 +04:00
|
|
|
temp_name = url_to_path(nsurl_access(hlcache_handle_get_url(content)));
|
2008-10-03 07:42:10 +04:00
|
|
|
if (temp_name) {
|
|
|
|
path.SetTo(temp_name);
|
|
|
|
BEntry entry;
|
|
|
|
if (entry.SetTo(path.Path()) >= B_OK
|
|
|
|
&& entry.Exists() && entry.IsFile())
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
if (!done) {
|
|
|
|
/* We cannot release the requested filename until after it
|
|
|
|
* has finished being used. As we can't easily find out when
|
|
|
|
* this is, we simply don't bother releasing it and simply
|
|
|
|
* allow it to be re-used next time NetSurf is started. The
|
|
|
|
* memory overhead from doing this is under 1 byte per
|
|
|
|
* filename. */
|
|
|
|
const char *filename = filename_request();
|
|
|
|
if (!filename) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
path.SetTo(TEMP_FILENAME_PREFIX);
|
|
|
|
path.Append(filename);
|
|
|
|
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
|
|
|
|
err = file.InitCheck();
|
|
|
|
if (err < B_OK) {
|
|
|
|
warn_user("IOError", strerror(err));
|
|
|
|
return;
|
|
|
|
}
|
2010-08-03 03:35:35 +04:00
|
|
|
err = file.Write(source, size);
|
2008-10-03 07:42:10 +04:00
|
|
|
if (err < B_OK) {
|
|
|
|
warn_user("IOError", strerror(err));
|
|
|
|
return;
|
|
|
|
}
|
2011-05-07 21:17:54 +04:00
|
|
|
lwc_string *mime = content_get_mime_type(content);
|
2013-12-30 18:40:12 +04:00
|
|
|
if (mime) {
|
2008-10-05 19:10:22 +04:00
|
|
|
file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL,
|
2013-12-30 18:40:12 +04:00
|
|
|
lwc_string_data(mime), lwc_string_length(mime) + 1);
|
|
|
|
lwc_string_unref(mime);
|
|
|
|
}
|
2008-10-03 07:42:10 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
entry_ref ref;
|
|
|
|
if (get_ref_for_path(path.Path(), &ref) < B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
BMessage m(B_REFS_RECEIVED);
|
|
|
|
m.AddRef("refs", &ref);
|
|
|
|
|
2008-10-11 01:43:25 +04:00
|
|
|
|
2008-10-03 07:42:10 +04:00
|
|
|
// apps to try
|
|
|
|
const char *editorSigs[] = {
|
|
|
|
"application/x-vnd.beunited.pe",
|
|
|
|
"application/x-vnd.XEmacs",
|
2008-10-07 05:36:11 +04:00
|
|
|
"application/x-vnd.Haiku-StyledEdit",
|
2008-10-03 07:42:10 +04:00
|
|
|
"application/x-vnd.Be-STEE",
|
|
|
|
"application/x-vnd.yT-STEE",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
for (i = 0; editorSigs[i]; i++) {
|
|
|
|
team_id team = -1;
|
2008-10-05 19:10:22 +04:00
|
|
|
{
|
|
|
|
BMessenger msgr(editorSigs[i], team);
|
2008-10-03 07:42:10 +04:00
|
|
|
if (msgr.SendMessage(&m) >= B_OK)
|
|
|
|
break;
|
|
|
|
}
|
2008-10-05 19:10:22 +04:00
|
|
|
|
|
|
|
err = be_roster->Launch(editorSigs[i], (BMessage *)&m, &team);
|
|
|
|
if (err >= B_OK)
|
|
|
|
break;
|
2008-10-03 07:42:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
/**
|
|
|
|
* Broadcast an URL that we can't handle.
|
|
|
|
*/
|
|
|
|
|
2014-05-28 02:52:35 +04:00
|
|
|
static nserror gui_launch_url(struct nsurl *url)
|
2008-06-03 23:07:09 +04:00
|
|
|
{
|
|
|
|
status_t status;
|
|
|
|
// try to open it as an URI
|
|
|
|
BString mimeType = "application/x-vnd.Be.URL.";
|
2014-05-28 02:52:35 +04:00
|
|
|
BString arg(nsurl_access(url));
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
mimeType.Append(arg, arg.FindFirst(":"));
|
|
|
|
|
2008-10-16 20:01:44 +04:00
|
|
|
// special case, text/x-email is used traditionally
|
|
|
|
// use it instead
|
|
|
|
if (arg.IFindFirst("mailto:") == 0)
|
|
|
|
mimeType = "text/x-email";
|
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
// the protocol should be alphanum
|
|
|
|
// we just check if it's registered
|
|
|
|
// if not there is likely no supporting app anyway
|
|
|
|
if (!BMimeType::IsValid(mimeType.String()))
|
2014-05-28 02:52:35 +04:00
|
|
|
return NSERROR_NO_FETCH_HANDLER;
|
|
|
|
char *args[2] = { (char *)nsurl_access(url), NULL };
|
2008-06-03 23:07:09 +04:00
|
|
|
status = be_roster->Launch(mimeType.String(), 1, args);
|
|
|
|
if (status < B_OK)
|
|
|
|
warn_user("Cannot launch url", strerror(status));
|
2014-05-28 02:52:35 +04:00
|
|
|
return NSERROR_OK;
|
2008-06-03 23:07:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a warning for a serious problem (eg memory exhaustion).
|
|
|
|
*
|
|
|
|
* \param warning message key for warning message
|
|
|
|
* \param detail additional message, or 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
void warn_user(const char *warning, const char *detail)
|
|
|
|
{
|
|
|
|
LOG(("warn_user: %s (%s)", warning, detail));
|
|
|
|
BAlert *alert;
|
|
|
|
BString text(warning);
|
|
|
|
if (detail)
|
|
|
|
text << ":\n" << detail;
|
2013-02-18 18:47:21 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
alert = new BAlert("NetSurf Warning", text.String(), "Debug", "Ok", NULL,
|
|
|
|
B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
|
|
|
if (alert->Go() < 1)
|
|
|
|
debugger("warn_user");
|
|
|
|
}
|
|
|
|
|
|
|
|
void die(const char * const error)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", error);
|
|
|
|
BAlert *alert;
|
|
|
|
BString text("Cannot continue:\n");
|
|
|
|
text << error;
|
2013-02-18 18:47:21 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
alert = new BAlert("NetSurf Error", text.String(), "Debug", "Ok", NULL,
|
|
|
|
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
|
|
if (alert->Go() < 1)
|
|
|
|
debugger("die");
|
2013-02-18 18:47:21 +04:00
|
|
|
|
2008-06-03 23:07:09 +04:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nsbeos_create_ssl_verify_window(struct browser_window *bw,
|
2010-08-03 03:35:35 +04:00
|
|
|
hlcache_handle *c, const struct ssl_cert_info *certs,
|
2008-06-03 23:07:09 +04:00
|
|
|
unsigned long num)
|
|
|
|
{
|
|
|
|
CALLED();
|
|
|
|
}
|
|
|
|
|
2008-10-06 00:35:28 +04:00
|
|
|
static void *myrealloc(void *ptr, size_t len, void *pw)
|
|
|
|
{
|
2010-04-30 11:00:58 +04:00
|
|
|
if (len == 0) {
|
|
|
|
free(ptr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-10-06 00:35:28 +04:00
|
|
|
return realloc(ptr, len);
|
|
|
|
}
|
2010-03-21 16:32:59 +03:00
|
|
|
|
2014-01-05 20:01:03 +04:00
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
static struct gui_clipboard_table beos_clipboard_table = {
|
2014-01-16 20:27:31 +04:00
|
|
|
gui_get_clipboard,
|
|
|
|
gui_set_clipboard,
|
2014-01-15 23:37:05 +04:00
|
|
|
};
|
|
|
|
|
2014-01-23 03:19:57 +04:00
|
|
|
static struct gui_fetch_table beos_fetch_table = {
|
|
|
|
fetch_filetype,
|
|
|
|
gui_get_resource_url,
|
|
|
|
NULL //fetch_mimetype
|
|
|
|
};
|
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
static struct gui_browser_table beos_browser_table = {
|
2014-06-20 17:06:16 +04:00
|
|
|
beos_schedule,
|
2014-01-16 20:27:31 +04:00
|
|
|
gui_quit,
|
|
|
|
gui_launch_url,
|
|
|
|
NULL, //cert_verify
|
|
|
|
gui_401login_open
|
2014-01-11 18:20:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Normal entry point from OS */
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
nserror ret;
|
|
|
|
BPath options;
|
2014-05-10 13:22:10 +04:00
|
|
|
struct netsurf_table beos_table = {
|
2014-01-16 20:27:31 +04:00
|
|
|
&beos_browser_table,
|
|
|
|
beos_window_table,
|
|
|
|
beos_download_table,
|
2014-01-23 03:19:57 +04:00
|
|
|
&beos_clipboard_table,
|
2015-04-17 01:47:10 +03:00
|
|
|
&beos_fetch_table,
|
|
|
|
NULL, /* use POSIX file */
|
|
|
|
NULL, /* default utf8 */
|
|
|
|
NULL, /* default search */
|
|
|
|
NULL, /* default web search */
|
|
|
|
NULL, /* default low level cache persistant storage */
|
|
|
|
beos_bitmap_table
|
2014-01-15 23:37:05 +04:00
|
|
|
};
|
|
|
|
|
2014-05-10 13:22:10 +04:00
|
|
|
ret = netsurf_register(&beos_table);
|
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
die("NetSurf operation table failed registration");
|
|
|
|
}
|
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) {
|
|
|
|
options.Append("x-vnd.NetSurf");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!replicated) {
|
|
|
|
// create the Application object before trying to use messages
|
|
|
|
// so we can open an alert in case of error.
|
|
|
|
new NSBrowserApplication;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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");
|
|
|
|
}
|
|
|
|
nsoption_read(options.Path(), NULL);
|
|
|
|
nsoption_commandline(&argc, argv, NULL);
|
|
|
|
|
|
|
|
/* common initialisation */
|
|
|
|
BPath messages = get_messages_path();
|
2014-03-23 15:33:32 +04:00
|
|
|
ret = netsurf_init(messages.Path(), NULL);
|
2014-01-11 18:20:30 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
die("NetSurf failed to initialise");
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_init(argc, argv);
|
|
|
|
|
2014-10-13 03:15:44 +04:00
|
|
|
while (!nsbeos_done) {
|
|
|
|
nsbeos_gui_poll();
|
|
|
|
}
|
2014-01-11 18:20:30 +04:00
|
|
|
|
|
|
|
netsurf_exit();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** called when replicated from NSBaseView::Instantiate() */
|
|
|
|
int gui_init_replicant(int argc, char** argv)
|
|
|
|
{
|
|
|
|
nserror ret;
|
|
|
|
BPath options;
|
2014-05-10 13:22:10 +04:00
|
|
|
struct netsurf_table beos_table = {
|
2014-01-16 20:27:31 +04:00
|
|
|
&beos_browser_table,
|
|
|
|
beos_window_table,
|
|
|
|
beos_download_table,
|
2014-01-23 03:19:57 +04:00
|
|
|
&beos_clipboard_table,
|
2015-04-17 02:29:58 +03:00
|
|
|
&beos_fetch_table,
|
2015-04-17 01:47:10 +03:00
|
|
|
NULL, /* use POSIX file */
|
|
|
|
NULL, /* default utf8 */
|
|
|
|
NULL, /* default search */
|
|
|
|
NULL, /* default web search */
|
|
|
|
NULL, /* default low level cache persistant storage */
|
|
|
|
beos_bitmap_table
|
2014-01-15 23:37:05 +04:00
|
|
|
};
|
|
|
|
|
2014-05-10 13:22:10 +04:00
|
|
|
ret = netsurf_register(&beos_table);
|
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
die("NetSurf operation table failed registration");
|
|
|
|
}
|
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) {
|
|
|
|
options.Append("x-vnd.NetSurf");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialise logging. Not fatal if it fails but not much we
|
|
|
|
* can do about it either.
|
|
|
|
*/
|
|
|
|
nslog_init(nslog_stream_configure, &argc, argv);
|
|
|
|
|
|
|
|
// FIXME: use options as readonly for replicants
|
|
|
|
/* user options setup */
|
|
|
|
ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
|
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
// FIXME: must not die when in replicant!
|
|
|
|
die("Options failed to initialise");
|
|
|
|
}
|
|
|
|
nsoption_read(options.Path(), NULL);
|
|
|
|
nsoption_commandline(&argc, argv, NULL);
|
|
|
|
|
|
|
|
/* common initialisation */
|
|
|
|
BPath messages = get_messages_path();
|
2014-03-23 15:33:32 +04:00
|
|
|
ret = netsurf_init(messages.Path(), NULL);
|
2014-01-11 18:20:30 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
// FIXME: must not die when in replicant!
|
|
|
|
die("NetSurf failed to initialise");
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_init(argc, argv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|