2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2007-05-06 10:11:00 +04:00
|
|
|
* Copyright 2007 James Bursa <bursa@users.sourceforge.net>
|
2004-07-27 00:13:45 +04:00
|
|
|
* Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2002-09-11 18:24:02 +04:00
|
|
|
*/
|
|
|
|
|
2008-10-14 03:32:21 +04:00
|
|
|
#include <locale.h>
|
2007-10-31 18:39:55 +03:00
|
|
|
#include <signal.h>
|
2003-11-06 22:41:41 +03:00
|
|
|
#include <stdbool.h>
|
2004-09-27 09:21:00 +04:00
|
|
|
#include <stdio.h>
|
2003-11-06 22:41:41 +03:00
|
|
|
#include <stdlib.h>
|
2010-03-28 16:56:39 +04:00
|
|
|
#include <libwapcaplet/libwapcaplet.h>
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2014-10-13 18:08:16 +04:00
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/corestrings.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/messages.h"
|
2011-05-17 01:16:44 +04:00
|
|
|
#include "content/content_factory.h"
|
2014-06-19 21:27:24 +04:00
|
|
|
#include "content/fetchers.h"
|
2010-04-12 00:21:13 +04:00
|
|
|
#include "content/hlcache.h"
|
2011-09-04 10:28:09 +04:00
|
|
|
#include "content/mimesniff.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
2011-02-26 04:19:11 +03:00
|
|
|
#include "css/css.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "image/image.h"
|
2011-09-07 13:15:33 +04:00
|
|
|
#include "image/image_cache.h"
|
2014-10-13 18:08:16 +04:00
|
|
|
#include "javascript/js.h"
|
|
|
|
#include "render/html.h"
|
|
|
|
#include "render/textplain.h"
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/browser.h"
|
2014-01-10 18:32:29 +04:00
|
|
|
#include "desktop/system_colour.h"
|
2011-01-20 16:51:41 +03:00
|
|
|
#include "desktop/searchweb.h"
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "desktop/gui_misc.h"
|
|
|
|
#include "desktop/gui_internal.h"
|
|
|
|
#include "desktop/netsurf.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
/** speculative pre-conversion small image size
|
|
|
|
*
|
|
|
|
* Experimenting by visiting every page from default page in order and
|
|
|
|
* then netsurf homepage
|
|
|
|
*
|
|
|
|
* 0 : Cache hit/miss/speculative miss/fail 604/147/ 0/0 (80%/19%/ 0%/ 0%)
|
|
|
|
* 2048 : Cache hit/miss/speculative miss/fail 622/119/ 17/0 (82%/15%/ 2%/ 0%)
|
|
|
|
* 4096 : Cache hit/miss/speculative miss/fail 656/109/ 25/0 (83%/13%/ 3%/ 0%)
|
|
|
|
* 8192 : Cache hit/miss/speculative miss/fail 648/104/ 40/0 (81%/13%/ 5%/ 0%)
|
|
|
|
* ALL : Cache hit/miss/speculative miss/fail 775/ 0/161/0 (82%/ 0%/17%/ 0%)
|
|
|
|
*/
|
|
|
|
#define SPECULATE_SMALL 4096
|
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
/** the time between image cache clean runs in ms. */
|
2011-09-07 13:15:33 +04:00
|
|
|
#define IMAGE_CACHE_CLEAN_TIME (10 * 1000)
|
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
/** default time between content cache cleans. */
|
2011-09-10 04:55:39 +04:00
|
|
|
#define HL_CACHE_CLEAN_TIME (2 * IMAGE_CACHE_CLEAN_TIME)
|
2011-09-08 16:04:57 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
/** ensure there is a minimal amount of memory for source objetcs and
|
|
|
|
* decoded bitmaps.
|
|
|
|
*/
|
|
|
|
#define MINIMUM_MEMORY_CACHE_SIZE (2 * 1024 * 1024)
|
|
|
|
|
2014-11-28 22:17:42 +03:00
|
|
|
/** default minimum object time before object is pushed to backing store. (s) */
|
|
|
|
#define LLCACHE_STORE_MIN_LIFETIME (60 * 30)
|
|
|
|
|
|
|
|
/** default minimum bandwidth for backing store writeout. (byte/s) */
|
|
|
|
#define LLCACHE_STORE_MIN_BANDWIDTH (128 * 1024)
|
|
|
|
|
|
|
|
/** default maximum bandwidth for backing store writeout. (byte/s) */
|
|
|
|
#define LLCACHE_STORE_MAX_BANDWIDTH (1024 * 1024)
|
|
|
|
|
|
|
|
/** default time quantum with which to calculate bandwidth (ms) */
|
|
|
|
#define LLCACHE_STORE_TIME_QUANTUM (100)
|
|
|
|
|
2010-04-28 02:14:52 +04:00
|
|
|
static void netsurf_lwc_iterator(lwc_string *str, void *pw)
|
|
|
|
{
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("[%3u] %.*s", str->refcnt, (int)lwc_string_length(str), lwc_string_data(str));
|
2010-04-28 02:14:52 +04:00
|
|
|
}
|
|
|
|
|
2010-04-15 03:03:49 +04:00
|
|
|
/**
|
|
|
|
* Dispatch a low-level cache query to the frontend
|
|
|
|
*
|
|
|
|
* \param query Query descriptor
|
|
|
|
* \param pw Private data
|
|
|
|
* \param cb Continuation callback
|
|
|
|
* \param cbpw Private data for continuation
|
|
|
|
* \return NSERROR_OK
|
|
|
|
*/
|
|
|
|
static nserror netsurf_llcache_query_handler(const llcache_query *query,
|
|
|
|
void *pw, llcache_query_response cb, void *cbpw)
|
|
|
|
{
|
|
|
|
switch (query->type) {
|
|
|
|
case LLCACHE_QUERY_AUTH:
|
2014-01-16 04:52:17 +04:00
|
|
|
guit->browser->login(query->url, query->data.auth.realm, cb, cbpw);
|
2010-04-15 03:03:49 +04:00
|
|
|
break;
|
|
|
|
case LLCACHE_QUERY_REDIRECT:
|
|
|
|
/** \todo Need redirect query dialog */
|
|
|
|
/* For now, do nothing, as this query type isn't emitted yet */
|
|
|
|
break;
|
|
|
|
case LLCACHE_QUERY_SSL:
|
2014-01-15 23:37:05 +04:00
|
|
|
guit->browser->cert_verify(query->url, query->data.ssl.certs,
|
2010-04-15 03:03:49 +04:00
|
|
|
query->data.ssl.num, cb, cbpw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-10 13:22:10 +04:00
|
|
|
/* exported interface documented in desktop/netsurf.h */
|
2015-06-19 18:29:42 +03:00
|
|
|
nserror netsurf_init(const char *store_path)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2014-03-22 18:54:51 +04:00
|
|
|
nserror ret;
|
2011-09-08 16:04:57 +04:00
|
|
|
struct hlcache_parameters hlcache_parameters = {
|
|
|
|
.bg_clean_time = HL_CACHE_CLEAN_TIME,
|
2014-03-22 18:54:51 +04:00
|
|
|
.llcache = {
|
|
|
|
.cb = netsurf_llcache_query_handler,
|
2014-11-28 22:17:42 +03:00
|
|
|
.minimum_lifetime = LLCACHE_STORE_MIN_LIFETIME,
|
|
|
|
.minimum_bandwidth = LLCACHE_STORE_MIN_BANDWIDTH,
|
|
|
|
.maximum_bandwidth = LLCACHE_STORE_MAX_BANDWIDTH,
|
|
|
|
.time_quantum = LLCACHE_STORE_TIME_QUANTUM,
|
2014-03-22 18:54:51 +04:00
|
|
|
}
|
2011-09-08 16:04:57 +04:00
|
|
|
};
|
2011-09-07 13:15:33 +04:00
|
|
|
struct image_cache_parameters image_cache_parameters = {
|
|
|
|
.bg_clean_time = IMAGE_CACHE_CLEAN_TIME,
|
|
|
|
.speculative_small = SPECULATE_SMALL
|
|
|
|
};
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2010-01-31 03:36:02 +03:00
|
|
|
#ifdef HAVE_SIGPIPE
|
2007-10-31 18:39:55 +03:00
|
|
|
/* Ignore SIGPIPE - this is necessary as OpenSSL can generate these
|
|
|
|
* and the default action is to terminate the app. There's no easy
|
|
|
|
* way of determining the cause of the SIGPIPE (other than using
|
|
|
|
* sigaction() and some mechanism for getting the file descriptor
|
|
|
|
* out of libcurl). However, we expect nothing else to generate a
|
2013-05-23 12:29:00 +04:00
|
|
|
* SIGPIPE, anyway, so may as well just ignore them all.
|
|
|
|
*/
|
2007-10-31 18:39:55 +03:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2010-01-31 03:36:02 +03:00
|
|
|
#endif
|
2007-10-31 18:39:55 +03:00
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
/* corestrings init */
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = corestrings_init();
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2012-07-22 18:48:55 +04:00
|
|
|
|
2011-09-10 04:55:39 +04:00
|
|
|
/* set up cache limits based on the memory cache size option */
|
2014-03-22 18:54:51 +04:00
|
|
|
hlcache_parameters.llcache.limit = nsoption_int(memory_cache_size);
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
if (hlcache_parameters.llcache.limit < MINIMUM_MEMORY_CACHE_SIZE) {
|
|
|
|
hlcache_parameters.llcache.limit = MINIMUM_MEMORY_CACHE_SIZE;
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Setting minimum memory cache size %zd", hlcache_parameters.llcache.limit);
|
2011-09-10 04:55:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* image cache is 25% of total memory cache size */
|
2014-03-22 18:54:51 +04:00
|
|
|
image_cache_parameters.limit = (hlcache_parameters.llcache.limit * 25) / 100;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2013-05-27 03:32:08 +04:00
|
|
|
/* image cache hysteresis is 20% of the image cache size */
|
2011-09-10 04:55:39 +04:00
|
|
|
image_cache_parameters.hysteresis = (image_cache_parameters.limit * 20) / 100;
|
|
|
|
|
|
|
|
/* account for image cache use from total */
|
2014-03-22 18:54:51 +04:00
|
|
|
hlcache_parameters.llcache.limit -= image_cache_parameters.limit;
|
|
|
|
|
|
|
|
/* set backing store target limit */
|
2014-06-09 16:10:56 +04:00
|
|
|
hlcache_parameters.llcache.store.limit = nsoption_uint(disc_cache_size);
|
2014-03-22 18:54:51 +04:00
|
|
|
|
|
|
|
/* set backing store hysterissi to 20% */
|
|
|
|
hlcache_parameters.llcache.store.hysteresis = (hlcache_parameters.llcache.store.limit * 20) / 100;;
|
|
|
|
|
|
|
|
/* set the path to the backing store */
|
2014-03-23 15:33:32 +04:00
|
|
|
hlcache_parameters.llcache.store.path = store_path;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
/* image handler bitmap cache */
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = image_cache_init(&image_cache_parameters);
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-09-07 13:15:33 +04:00
|
|
|
|
|
|
|
/* content handler initialisation */
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = nscss_init();
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = html_init();
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = image_init();
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = textplain_init();
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = mimesniff_init();
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2008-10-14 03:32:21 +04:00
|
|
|
setlocale(LC_ALL, "C");
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2014-01-19 22:17:32 +04:00
|
|
|
/* initialise the fetchers */
|
2014-06-19 21:27:24 +04:00
|
|
|
ret = fetcher_init();
|
2014-03-22 18:54:51 +04:00
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-03-13 21:26:46 +03:00
|
|
|
|
|
|
|
/* Initialise the hlcache and allow it to init the llcache for us */
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = hlcache_initialise(&hlcache_parameters);
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2011-01-30 16:40:47 +03:00
|
|
|
/* Initialize system colours */
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = ns_system_colour_init();
|
|
|
|
if (ret != NSERROR_OK)
|
|
|
|
return ret;
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2012-01-02 01:42:38 +04:00
|
|
|
js_initialise();
|
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
return NSERROR_OK;
|
2002-11-03 12:39:53 +03:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
/**
|
|
|
|
* Clean up components used by gui NetSurf.
|
|
|
|
*/
|
2002-10-15 14:41:12 +04:00
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
void netsurf_exit(void)
|
|
|
|
{
|
2011-03-13 23:20:31 +03:00
|
|
|
hlcache_stop();
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Closing GUI");
|
2014-01-15 23:37:05 +04:00
|
|
|
guit->browser->quit();
|
2012-06-30 00:37:32 +04:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Finalising JavaScript");
|
2012-06-30 00:37:32 +04:00
|
|
|
js_finalise();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Finalising Web Search");
|
2014-05-25 03:57:48 +04:00
|
|
|
search_web_finalise();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Finalising high-level cache");
|
2010-12-16 03:03:57 +03:00
|
|
|
hlcache_finalise();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Closing fetches");
|
2014-06-19 21:27:24 +04:00
|
|
|
fetcher_quit();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
mimesniff_fini();
|
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
/* dump any remaining cache entries */
|
|
|
|
image_cache_fini();
|
|
|
|
|
2011-09-16 02:47:50 +04:00
|
|
|
/* Clean up after content handlers */
|
2011-05-17 01:16:44 +04:00
|
|
|
content_factory_fini();
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Closing utf8");
|
2005-07-11 22:10:10 +04:00
|
|
|
utf8_finalise();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Destroying URLdb");
|
2006-12-09 01:38:46 +03:00
|
|
|
urldb_destroy();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Destroying System colours");
|
2014-01-10 18:32:29 +04:00
|
|
|
ns_system_colour_finalize();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
corestrings_fini();
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Remaining lwc strings:");
|
2010-04-28 02:14:52 +04:00
|
|
|
lwc_iterate_strings(netsurf_lwc_iterator, NULL);
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Exited successfully");
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|