2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2007-05-06 04:41:12 +04:00
|
|
|
* Copyright 2007 James Bursa <bursa@users.sourceforge.net>
|
2010-06-04 13:35:08 +04:00
|
|
|
* Copyright 2010 Michael Drake <tlsa@netsurf-browser.org>
|
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/>.
|
2004-02-20 03:43:17 +03:00
|
|
|
*/
|
|
|
|
|
2016-04-20 21:57:44 +03:00
|
|
|
/**
|
|
|
|
* \file
|
2018-05-10 13:34:26 +03:00
|
|
|
* Implementation of HTML content handling.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2005-08-21 16:04:18 +04:00
|
|
|
#include <stdint.h>
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <string.h>
|
2003-04-06 01:38:06 +04:00
|
|
|
#include <strings.h>
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <stdlib.h>
|
2016-04-20 21:18:15 +03:00
|
|
|
#include <nsutils/time.h>
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2017-01-20 00:15:08 +03:00
|
|
|
#include "utils/utils.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2014-02-02 02:17:36 +04:00
|
|
|
#include "utils/corestrings.h"
|
|
|
|
#include "utils/http.h"
|
|
|
|
#include "utils/libdom.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/talloc.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/nsoption.h"
|
2016-04-22 00:36:21 +03:00
|
|
|
#include "utils/string.h"
|
2016-09-13 00:50:46 +03:00
|
|
|
#include "utils/ascii.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
|
|
|
#include "netsurf/browser_window.h"
|
|
|
|
#include "netsurf/utf8.h"
|
2019-12-01 21:24:33 +03:00
|
|
|
#include "netsurf/keypress.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/layout.h"
|
|
|
|
#include "netsurf/misc.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/hlcache.h"
|
2011-07-01 15:16:43 +04:00
|
|
|
#include "desktop/selection.h"
|
2011-11-29 21:47:29 +04:00
|
|
|
#include "desktop/scrollbar.h"
|
2013-02-08 19:26:24 +04:00
|
|
|
#include "desktop/textarea.h"
|
2016-05-27 01:01:03 +03:00
|
|
|
#include "netsurf/bitmap.h"
|
2014-02-02 02:17:36 +04:00
|
|
|
#include "javascript/js.h"
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "desktop/gui_internal.h"
|
2014-02-02 02:17:36 +04:00
|
|
|
|
2018-05-11 15:15:17 +03:00
|
|
|
#include "html/html.h"
|
|
|
|
#include "html/html_save.h"
|
|
|
|
#include "html/html_internal.h"
|
2019-11-12 21:34:39 +03:00
|
|
|
#include "html/interaction.h"
|
2018-05-10 13:34:26 +03:00
|
|
|
#include "html/box.h"
|
2020-04-29 01:30:20 +03:00
|
|
|
#include "html/box_construct.h"
|
2020-04-29 22:37:42 +03:00
|
|
|
#include "html/box_inspect.h"
|
2018-05-10 13:34:26 +03:00
|
|
|
#include "html/form_internal.h"
|
|
|
|
#include "html/imagemap.h"
|
|
|
|
#include "html/layout.h"
|
|
|
|
#include "html/search.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
#define CHUNK 4096
|
|
|
|
|
2008-10-10 14:56:34 +04:00
|
|
|
/* Change these to 1 to cause a dump to stderr of the frameset or box
|
|
|
|
* when the trees have been built.
|
|
|
|
*/
|
|
|
|
#define ALWAYS_DUMP_FRAMESET 0
|
|
|
|
#define ALWAYS_DUMP_BOX 0
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
static const char *html_types[] = {
|
|
|
|
"application/xhtml+xml",
|
|
|
|
"text/html"
|
|
|
|
};
|
|
|
|
|
2019-12-01 13:11:38 +03:00
|
|
|
/**
|
|
|
|
* Fire an event at the DOM
|
|
|
|
*
|
|
|
|
* Helper that swallows DOM errors.
|
|
|
|
*
|
|
|
|
* \param[in] event the event to fire at the DOM
|
|
|
|
* \param[in] target the event target
|
|
|
|
* \return true on success
|
|
|
|
*/
|
|
|
|
static bool fire_dom_event(dom_event *event, dom_node *target)
|
|
|
|
{
|
|
|
|
dom_exception exc;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
exc = dom_event_target_dispatch_event(target, event, &result);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-31 20:01:17 +03:00
|
|
|
/* Exported interface, see html_internal.h */
|
2019-12-01 12:55:53 +03:00
|
|
|
bool fire_generic_dom_event(dom_string *type, dom_node *target,
|
|
|
|
bool bubbles, bool cancelable)
|
2015-10-31 20:01:17 +03:00
|
|
|
{
|
|
|
|
dom_exception exc;
|
|
|
|
dom_event *evt;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
exc = dom_event_create(&evt);
|
|
|
|
if (exc != DOM_NO_ERR) return false;
|
|
|
|
exc = dom_event_init(evt, type, bubbles, cancelable);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_event_unref(evt);
|
|
|
|
return false;
|
|
|
|
}
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
|
|
|
|
dom_string_length(type), dom_string_data(type), target);
|
2019-12-01 13:11:38 +03:00
|
|
|
result = fire_dom_event(evt, target);
|
2015-10-31 20:01:17 +03:00
|
|
|
dom_event_unref(evt);
|
|
|
|
return result;
|
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2019-12-01 21:24:33 +03:00
|
|
|
/* Exported interface, see html_internal.h */
|
|
|
|
bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
|
|
|
|
bool bubbles, bool cancelable, uint32_t key)
|
|
|
|
{
|
|
|
|
bool is_special = key <= 0x001F || (0x007F <= key && key <= 0x009F);
|
|
|
|
dom_string *dom_key = NULL;
|
|
|
|
dom_keyboard_event *evt;
|
|
|
|
dom_exception exc;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
if (is_special) {
|
|
|
|
switch (key) {
|
|
|
|
case NS_KEY_ESCAPE:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_Escape);
|
|
|
|
break;
|
|
|
|
case NS_KEY_LEFT:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_ArrowLeft);
|
|
|
|
break;
|
|
|
|
case NS_KEY_RIGHT:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_ArrowRight);
|
|
|
|
break;
|
|
|
|
case NS_KEY_UP:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_ArrowUp);
|
|
|
|
break;
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_ArrowDown);
|
|
|
|
break;
|
|
|
|
case NS_KEY_PAGE_UP:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_PageUp);
|
|
|
|
break;
|
|
|
|
case NS_KEY_PAGE_DOWN:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_PageDown);
|
|
|
|
break;
|
|
|
|
case NS_KEY_TEXT_START:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_Home);
|
|
|
|
break;
|
|
|
|
case NS_KEY_TEXT_END:
|
|
|
|
dom_key = dom_string_ref(corestring_dom_End);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dom_key = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char utf8[6];
|
|
|
|
size_t length = utf8_from_ucs4(key, utf8);
|
|
|
|
utf8[length] = '\0';
|
|
|
|
|
|
|
|
exc = dom_string_create((const uint8_t *)utf8, strlen(utf8),
|
|
|
|
&dom_key);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return exc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_keyboard_event_create(&evt);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(dom_key);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_keyboard_event_init(evt, type, bubbles, cancelable, NULL,
|
|
|
|
dom_key, NULL, DOM_KEY_LOCATION_STANDARD, false,
|
|
|
|
false, false, false, false, false);
|
|
|
|
dom_string_unref(dom_key);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_event_unref(evt);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
|
|
|
|
dom_string_length(type), dom_string_data(type), target);
|
|
|
|
|
|
|
|
result = fire_dom_event((dom_event *) evt, target);
|
|
|
|
dom_event_unref(evt);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
2012-07-06 23:00:32 +04:00
|
|
|
* Perform post-box-creation conversion of a document
|
|
|
|
*
|
|
|
|
* \param c HTML content to complete conversion of
|
|
|
|
* \param success Whether box tree construction was successful
|
2004-02-20 03:43:17 +03:00
|
|
|
*/
|
2012-07-06 23:00:32 +04:00
|
|
|
static void html_box_convert_done(html_content *c, bool success)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2012-11-26 21:23:03 +04:00
|
|
|
nserror err;
|
2012-07-06 23:00:32 +04:00
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
dom_node *html;
|
2009-04-15 15:28:07 +04:00
|
|
|
|
2020-04-29 01:30:20 +03:00
|
|
|
NSLOG(netsurf, INFO, "DOM to box conversion complete (content %p)", c);
|
2009-04-15 15:28:07 +04:00
|
|
|
|
2019-08-23 23:58:07 +03:00
|
|
|
c->box_conversion_context = NULL;
|
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
/* Clean up and report error if unsuccessful or aborted */
|
2012-10-18 00:52:43 +04:00
|
|
|
if ((success == false) || (c->aborted)) {
|
2013-02-25 22:24:04 +04:00
|
|
|
html_object_free_objects(c);
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2012-10-18 00:52:43 +04:00
|
|
|
if (success == false) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&c->base, NSERROR_BOX_CONVERT, NULL);
|
2012-10-18 00:52:43 +04:00
|
|
|
} else {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&c->base, NSERROR_STOPPED, NULL);
|
2012-10-18 00:52:43 +04:00
|
|
|
}
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
content_set_error(&c->base);
|
|
|
|
return;
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
}
|
2007-02-11 00:34:22 +03:00
|
|
|
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
#if ALWAYS_DUMP_BOX
|
2014-07-13 21:07:12 +04:00
|
|
|
box_dump(stderr, c->layout->children, 0, true);
|
2012-07-06 23:00:32 +04:00
|
|
|
#endif
|
|
|
|
#if ALWAYS_DUMP_FRAMESET
|
|
|
|
if (c->frameset)
|
|
|
|
html_dump_frameset(c->frameset, 0);
|
|
|
|
#endif
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
exc = dom_document_get_document_element(c->document, (void *) &html);
|
|
|
|
if ((exc != DOM_NO_ERR) || (html == NULL)) {
|
2013-02-25 22:24:04 +04:00
|
|
|
/** @todo should this call html_object_free_objects(c);
|
2018-05-10 13:34:26 +03:00
|
|
|
* like the other error paths
|
2012-10-18 00:52:43 +04:00
|
|
|
*/
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "error retrieving html element from dom");
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&c->base, NSERROR_DOM, NULL);
|
2012-07-06 23:00:32 +04:00
|
|
|
content_set_error(&c->base);
|
|
|
|
return;
|
|
|
|
}
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
|
2012-11-26 21:23:03 +04:00
|
|
|
/* extract image maps - can't do this sensibly in dom_to_box */
|
|
|
|
err = imagemap_extract(c);
|
|
|
|
if (err != NSERROR_OK) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "imagemap extraction failed");
|
2013-02-25 22:24:04 +04:00
|
|
|
html_object_free_objects(c);
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&c->base, err, NULL);
|
2012-07-06 23:00:32 +04:00
|
|
|
content_set_error(&c->base);
|
2012-07-21 23:10:44 +04:00
|
|
|
dom_node_unref(html);
|
2012-07-06 23:00:32 +04:00
|
|
|
return;
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
}
|
2012-07-06 23:00:32 +04:00
|
|
|
/*imagemap_dump(c);*/
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
/* Destroy the parser binding */
|
2012-07-14 03:33:15 +04:00
|
|
|
dom_hubbub_parser_destroy(c->parser);
|
|
|
|
c->parser = NULL;
|
2008-08-11 12:40:58 +04:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
content_set_ready(&c->base);
|
2009-01-07 01:06:14 +03:00
|
|
|
|
2020-02-21 13:46:21 +03:00
|
|
|
html_proceed_to_done(c);
|
2009-01-07 01:06:14 +03:00
|
|
|
|
2012-07-21 23:10:44 +04:00
|
|
|
dom_node_unref(html);
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2009-01-07 01:06:14 +03:00
|
|
|
|
2020-02-21 13:46:21 +03:00
|
|
|
/* Documented in html_internal.h */
|
|
|
|
nserror
|
|
|
|
html_proceed_to_done(html_content *html)
|
|
|
|
{
|
|
|
|
switch (content__get_status(&html->base)) {
|
|
|
|
case CONTENT_STATUS_READY:
|
|
|
|
if (html->base.active == 0) {
|
|
|
|
content_set_done(&html->base);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONTENT_STATUS_DONE:
|
2020-02-21 17:26:33 +03:00
|
|
|
/* fallthrough */
|
|
|
|
case CONTENT_STATUS_LOADING:
|
2020-02-21 13:46:21 +03:00
|
|
|
return NSERROR_OK;
|
|
|
|
default:
|
2020-02-21 17:26:33 +03:00
|
|
|
NSLOG(netsurf, ERROR, "Content status unexpectedly not LOADING/READY/DONE");
|
2020-02-21 13:46:21 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NSERROR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2013-05-23 16:29:40 +04:00
|
|
|
|
|
|
|
/** process link node */
|
|
|
|
static bool html_process_link(html_content *c, dom_node *node)
|
|
|
|
{
|
|
|
|
struct content_rfc5988_link link; /* the link added to the content */
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
dom_string *atr_string;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
memset(&link, 0, sizeof(struct content_rfc5988_link));
|
|
|
|
|
|
|
|
/* check that the relation exists - w3c spec says must be present */
|
|
|
|
exc = dom_element_get_attribute(node, corestring_dom_rel, &atr_string);
|
|
|
|
if ((exc != DOM_NO_ERR) || (atr_string == NULL)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* get a lwc string containing the link relation */
|
|
|
|
exc = dom_string_intern(atr_string, &link.rel);
|
|
|
|
dom_string_unref(atr_string);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that the href exists - w3c spec says must be present */
|
|
|
|
exc = dom_element_get_attribute(node, corestring_dom_href, &atr_string);
|
|
|
|
if ((exc != DOM_NO_ERR) || (atr_string == NULL)) {
|
|
|
|
lwc_string_unref(link.rel);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get nsurl */
|
|
|
|
error = nsurl_join(c->base_url, dom_string_data(atr_string),
|
|
|
|
&link.href);
|
|
|
|
dom_string_unref(atr_string);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
lwc_string_unref(link.rel);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for optional properties -- we don't care if internment fails */
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(node,
|
|
|
|
corestring_dom_hreflang, &atr_string);
|
|
|
|
if ((exc == DOM_NO_ERR) && (atr_string != NULL)) {
|
|
|
|
/* get a lwc string containing the href lang */
|
2020-02-23 12:36:07 +03:00
|
|
|
(void)dom_string_intern(atr_string, &link.hreflang);
|
2013-05-23 16:29:40 +04:00
|
|
|
dom_string_unref(atr_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(node,
|
|
|
|
corestring_dom_type, &atr_string);
|
|
|
|
if ((exc == DOM_NO_ERR) && (atr_string != NULL)) {
|
|
|
|
/* get a lwc string containing the type */
|
2020-02-23 12:36:07 +03:00
|
|
|
(void)dom_string_intern(atr_string, &link.type);
|
2013-05-23 16:29:40 +04:00
|
|
|
dom_string_unref(atr_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(node,
|
|
|
|
corestring_dom_media, &atr_string);
|
|
|
|
if ((exc == DOM_NO_ERR) && (atr_string != NULL)) {
|
|
|
|
/* get a lwc string containing the media */
|
2020-02-23 12:36:07 +03:00
|
|
|
(void)dom_string_intern(atr_string, &link.media);
|
2013-05-23 16:29:40 +04:00
|
|
|
dom_string_unref(atr_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(node,
|
|
|
|
corestring_dom_sizes, &atr_string);
|
|
|
|
if ((exc == DOM_NO_ERR) && (atr_string != NULL)) {
|
|
|
|
/* get a lwc string containing the sizes */
|
2020-02-23 12:36:07 +03:00
|
|
|
(void)dom_string_intern(atr_string, &link.sizes);
|
2013-05-23 16:29:40 +04:00
|
|
|
dom_string_unref(atr_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add to content */
|
|
|
|
content__add_rfc5988_link(&c->base, &link);
|
|
|
|
|
|
|
|
if (link.sizes != NULL)
|
|
|
|
lwc_string_unref(link.sizes);
|
|
|
|
if (link.media != NULL)
|
|
|
|
lwc_string_unref(link.media);
|
|
|
|
if (link.type != NULL)
|
|
|
|
lwc_string_unref(link.type);
|
|
|
|
if (link.hreflang != NULL)
|
|
|
|
lwc_string_unref(link.hreflang);
|
|
|
|
|
|
|
|
nsurl_unref(link.href);
|
|
|
|
lwc_string_unref(link.rel);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** process title node */
|
|
|
|
static bool html_process_title(html_content *c, dom_node *node)
|
|
|
|
{
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
dom_string *title;
|
|
|
|
char *title_str;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
exc = dom_node_get_text_content(node, &title);
|
|
|
|
if ((exc != DOM_NO_ERR) || (title == NULL)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
title_str = squash_whitespace(dom_string_data(title));
|
|
|
|
dom_string_unref(title);
|
|
|
|
|
|
|
|
if (title_str == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = content__set_title(&c->base, title_str);
|
|
|
|
|
|
|
|
free(title_str);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool html_process_base(html_content *c, dom_node *node)
|
|
|
|
{
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
dom_string *atr_string;
|
|
|
|
|
|
|
|
/* get href attribute if present */
|
|
|
|
exc = dom_element_get_attribute(node,
|
|
|
|
corestring_dom_href, &atr_string);
|
|
|
|
if ((exc == DOM_NO_ERR) && (atr_string != NULL)) {
|
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
/* get url from string */
|
|
|
|
error = nsurl_create(dom_string_data(atr_string), &url);
|
|
|
|
dom_string_unref(atr_string);
|
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
if (c->base_url != NULL)
|
|
|
|
nsurl_unref(c->base_url);
|
|
|
|
c->base_url = url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get target attribute if present and not already set */
|
|
|
|
if (c->base_target != NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(node,
|
|
|
|
corestring_dom_target, &atr_string);
|
|
|
|
if ((exc == DOM_NO_ERR) && (atr_string != NULL)) {
|
|
|
|
/* Validation rules from the HTML5 spec for the base element:
|
|
|
|
* The target must be one of _blank, _self, _parent, or
|
|
|
|
* _top or any identifier which does not begin with an
|
|
|
|
* underscore
|
|
|
|
*/
|
|
|
|
if (*dom_string_data(atr_string) != '_' ||
|
|
|
|
dom_string_caseless_lwc_isequal(atr_string,
|
|
|
|
corestring_lwc__blank) ||
|
|
|
|
dom_string_caseless_lwc_isequal(atr_string,
|
|
|
|
corestring_lwc__self) ||
|
|
|
|
dom_string_caseless_lwc_isequal(atr_string,
|
|
|
|
corestring_lwc__parent) ||
|
|
|
|
dom_string_caseless_lwc_isequal(atr_string,
|
|
|
|
corestring_lwc__top)) {
|
|
|
|
c->base_target = strdup(dom_string_data(atr_string));
|
|
|
|
}
|
|
|
|
dom_string_unref(atr_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-23 02:57:59 +04:00
|
|
|
static nserror html_meta_refresh_process_element(html_content *c, dom_node *n)
|
|
|
|
{
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
const char *url, *end, *refresh = NULL;
|
|
|
|
char *new_url;
|
|
|
|
char quote = '\0';
|
|
|
|
dom_string *equiv, *content;
|
|
|
|
dom_exception exc;
|
|
|
|
nsurl *nsurl;
|
|
|
|
nserror error = NSERROR_OK;
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(n, corestring_dom_http_equiv, &equiv);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return NSERROR_DOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (equiv == NULL) {
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dom_string_caseless_lwc_isequal(equiv, corestring_lwc_refresh)) {
|
|
|
|
dom_string_unref(equiv);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(equiv);
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(n, corestring_dom_content, &content);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return NSERROR_DOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content == NULL) {
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = dom_string_data(content) + dom_string_byte_length(content);
|
|
|
|
|
|
|
|
/* content := *LWS intpart fracpart? *LWS [';' *LWS *1url *LWS]
|
|
|
|
* intpart := 1*DIGIT
|
|
|
|
* fracpart := 1*('.' | DIGIT)
|
|
|
|
* url := "url" *LWS '=' *LWS (url-nq | url-sq | url-dq)
|
|
|
|
* url-nq := *urlchar
|
|
|
|
* url-sq := "'" *(urlchar | '"') "'"
|
|
|
|
* url-dq := '"' *(urlchar | "'") '"'
|
|
|
|
* urlchar := [#x9#x21#x23-#x26#x28-#x7E] | nonascii
|
|
|
|
* nonascii := [#x80-#xD7FF#xE000-#xFFFD#x10000-#x10FFFF]
|
|
|
|
*/
|
|
|
|
|
|
|
|
url = dom_string_data(content);
|
|
|
|
|
|
|
|
/* *LWS */
|
2016-09-13 00:50:46 +03:00
|
|
|
while (url < end && ascii_is_space(*url)) {
|
2013-05-23 02:57:59 +04:00
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* intpart */
|
|
|
|
if (url == end || (*url < '0' || '9' < *url)) {
|
|
|
|
/* Empty content, or invalid timeval */
|
|
|
|
dom_string_unref(content);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_data.delay = (int) strtol(url, &new_url, 10);
|
|
|
|
/* a very small delay and self-referencing URL can cause a loop
|
|
|
|
* that grinds machines to a halt. To prevent this we set a
|
|
|
|
* minimum refresh delay of 1s. */
|
|
|
|
if (msg_data.delay < 1) {
|
|
|
|
msg_data.delay = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = new_url;
|
|
|
|
|
|
|
|
/* fracpart? (ignored, as delay is integer only) */
|
|
|
|
while (url < end && (('0' <= *url && *url <= '9') ||
|
|
|
|
*url == '.')) {
|
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *LWS */
|
2016-09-13 00:50:46 +03:00
|
|
|
while (url < end && ascii_is_space(*url)) {
|
2013-05-23 02:57:59 +04:00
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ';' */
|
|
|
|
if (url < end && *url == ';')
|
|
|
|
url++;
|
|
|
|
|
|
|
|
/* *LWS */
|
2016-09-13 00:50:46 +03:00
|
|
|
while (url < end && ascii_is_space(*url)) {
|
2013-05-23 02:57:59 +04:00
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url == end) {
|
|
|
|
/* Just delay specified, so refresh current page */
|
|
|
|
dom_string_unref(content);
|
|
|
|
|
|
|
|
c->base.refresh = nsurl_ref(
|
|
|
|
content_get_url(&c->base));
|
|
|
|
|
2017-08-26 17:50:03 +03:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_REFRESH, &msg_data);
|
2013-05-23 02:57:59 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "url" */
|
|
|
|
if (url <= end - 3) {
|
|
|
|
if (strncasecmp(url, "url", 3) == 0) {
|
|
|
|
url += 3;
|
|
|
|
} else {
|
|
|
|
/* Unexpected input, ignore this header */
|
|
|
|
dom_string_unref(content);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Insufficient input, ignore this header */
|
|
|
|
dom_string_unref(content);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *LWS */
|
2016-09-13 00:50:46 +03:00
|
|
|
while (url < end && ascii_is_space(*url)) {
|
2013-05-23 02:57:59 +04:00
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '=' */
|
|
|
|
if (url < end) {
|
|
|
|
if (*url == '=') {
|
|
|
|
url++;
|
|
|
|
} else {
|
|
|
|
/* Unexpected input, ignore this header */
|
|
|
|
dom_string_unref(content);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Insufficient input, ignore this header */
|
|
|
|
dom_string_unref(content);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *LWS */
|
2016-09-13 00:50:46 +03:00
|
|
|
while (url < end && ascii_is_space(*url)) {
|
2013-05-23 02:57:59 +04:00
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '"' or "'" */
|
|
|
|
if (url < end && (*url == '"' || *url == '\'')) {
|
|
|
|
quote = *url;
|
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start of URL */
|
|
|
|
refresh = url;
|
|
|
|
|
|
|
|
if (quote != 0) {
|
|
|
|
/* url-sq | url-dq */
|
|
|
|
while (url < end && *url != quote)
|
|
|
|
url++;
|
|
|
|
} else {
|
|
|
|
/* url-nq */
|
2016-09-13 00:50:46 +03:00
|
|
|
while (url < end && !ascii_is_space(*url))
|
2013-05-23 02:57:59 +04:00
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '"' or "'" or *LWS (we don't care) */
|
|
|
|
if (url > refresh) {
|
|
|
|
/* There's a URL */
|
|
|
|
new_url = strndup(refresh, url - refresh);
|
|
|
|
if (new_url == NULL) {
|
|
|
|
dom_string_unref(content);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = nsurl_join(c->base_url, new_url, &nsurl);
|
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
/* broadcast valid refresh url */
|
|
|
|
|
|
|
|
c->base.refresh = nsurl;
|
|
|
|
|
2017-08-26 17:50:03 +03:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_REFRESH,
|
|
|
|
&msg_data);
|
2013-05-23 02:57:59 +04:00
|
|
|
c->refresh = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(new_url);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(content);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-01-05 18:34:04 +04:00
|
|
|
static bool html_process_img(html_content *c, dom_node *node)
|
|
|
|
{
|
|
|
|
dom_string *src;
|
|
|
|
nsurl *url;
|
|
|
|
nserror err;
|
|
|
|
dom_exception exc;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
/* Do nothing if foreground images are disabled */
|
|
|
|
if (nsoption_bool(foreground_images) == false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_element_get_attribute(node, corestring_dom_src, &src);
|
|
|
|
if (exc != DOM_NO_ERR || src == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = nsurl_join(c->base_url, dom_string_data(src), &url);
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
dom_string_unref(src);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dom_string_unref(src);
|
|
|
|
|
|
|
|
/* Speculatively fetch the image */
|
|
|
|
success = html_fetch_object(c, url, NULL, CONTENT_IMAGE, 0, 0, false);
|
|
|
|
nsurl_unref(url);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2019-05-06 17:37:44 +03:00
|
|
|
static void html_get_dimensions(html_content *htmlc)
|
|
|
|
{
|
|
|
|
unsigned w;
|
|
|
|
unsigned h;
|
|
|
|
union content_msg_data msg_data = {
|
|
|
|
.getdims = {
|
|
|
|
.viewport_width = &w,
|
|
|
|
.viewport_height = &h,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
content_broadcast(&htmlc->base, CONTENT_MSG_GETDIMS, &msg_data);
|
|
|
|
|
2019-05-07 16:01:51 +03:00
|
|
|
htmlc->media.width = nscss_pixels_physical_to_css(INTTOFIX(w));
|
|
|
|
htmlc->media.height = nscss_pixels_physical_to_css(INTTOFIX(h));
|
|
|
|
htmlc->media.client_font_size =
|
|
|
|
FDIV(INTTOFIX(nsoption_int(font_size)), F_10);
|
|
|
|
htmlc->media.client_line_height =
|
|
|
|
FMUL(nscss_len2px(NULL, htmlc->media.client_font_size,
|
|
|
|
CSS_UNIT_PT, NULL), FLTTOFIX(1.33));
|
2019-05-06 17:37:44 +03:00
|
|
|
}
|
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
/* exported function documented in html/html_internal.h */
|
2014-11-12 22:31:39 +03:00
|
|
|
void html_finish_conversion(html_content *htmlc)
|
2012-07-06 23:00:32 +04:00
|
|
|
{
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
dom_node *html;
|
2012-11-26 21:23:03 +04:00
|
|
|
nserror error;
|
2005-01-02 01:05:21 +03:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
/* Bail out if we've been aborted */
|
2014-11-12 22:31:39 +03:00
|
|
|
if (htmlc->aborted) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, NSERROR_STOPPED, NULL);
|
2014-11-12 22:31:39 +03:00
|
|
|
content_set_error(&htmlc->base);
|
2012-07-06 23:00:32 +04:00
|
|
|
return;
|
2005-01-02 01:05:21 +03:00
|
|
|
}
|
|
|
|
|
2018-08-27 22:47:37 +03:00
|
|
|
/* If we already have a selection context, then we have already
|
|
|
|
* "finished" conversion. We can get here twice if e.g. some JS
|
|
|
|
* adds a new stylesheet, and the stylesheet gets added after
|
|
|
|
* the HTML content is initially finished.
|
|
|
|
*
|
|
|
|
* If we didn't do this, the HTML content would try to rebuild the
|
|
|
|
* box tree for the html content when this new stylesheet is ready.
|
|
|
|
* NetSurf has no concept of dynamically changing documents, so this
|
|
|
|
* would break badly.
|
|
|
|
*/
|
|
|
|
if (htmlc->select_ctx != NULL) {
|
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"Ignoring style change: NS layout is static.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-24 17:15:05 +04:00
|
|
|
/* create new css selection context */
|
2014-11-12 22:31:39 +03:00
|
|
|
error = html_css_new_selection_context(htmlc, &htmlc->select_ctx);
|
2013-02-24 17:15:05 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, error, NULL);
|
2014-11-12 22:31:39 +03:00
|
|
|
content_set_error(&htmlc->base);
|
2012-07-06 23:00:32 +04:00
|
|
|
return;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2005-01-02 01:05:21 +03:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
|
2012-11-28 22:07:36 +04:00
|
|
|
/* fire a simple event named load at the Document's Window
|
|
|
|
* object, but with its target set to the Document object (and
|
|
|
|
* the currentTarget set to the Window object)
|
|
|
|
*/
|
2020-03-21 21:30:41 +03:00
|
|
|
if (htmlc->jsthread != NULL) {
|
|
|
|
js_fire_event(htmlc->jsthread, "load", htmlc->document, NULL);
|
2016-01-21 17:49:57 +03:00
|
|
|
}
|
2012-11-28 22:07:36 +04:00
|
|
|
|
2012-11-26 21:23:03 +04:00
|
|
|
/* convert dom tree to box tree */
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "DOM to box (%p)", htmlc);
|
2014-11-12 22:31:39 +03:00
|
|
|
content_set_status(&htmlc->base, messages_get("Processing"));
|
2012-08-15 22:00:50 +04:00
|
|
|
msg_data.explicit_status_text = NULL;
|
2017-08-26 17:50:03 +03:00
|
|
|
content_broadcast(&htmlc->base, CONTENT_MSG_STATUS, &msg_data);
|
2012-07-06 23:00:32 +04:00
|
|
|
|
2014-11-12 22:31:39 +03:00
|
|
|
exc = dom_document_get_document_element(htmlc->document, (void *) &html);
|
2012-07-06 23:00:32 +04:00
|
|
|
if ((exc != DOM_NO_ERR) || (html == NULL)) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "error retrieving html element from dom");
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, NSERROR_DOM, NULL);
|
2014-11-12 22:31:39 +03:00
|
|
|
content_set_error(&htmlc->base);
|
2012-07-06 23:00:32 +04:00
|
|
|
return;
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
2008-11-20 17:47:36 +03:00
|
|
|
|
2019-05-06 17:37:44 +03:00
|
|
|
html_get_dimensions(htmlc);
|
|
|
|
|
2019-08-23 23:58:07 +03:00
|
|
|
error = dom_to_box(html, htmlc, html_box_convert_done, &htmlc->box_conversion_context);
|
2012-11-26 21:23:03 +04:00
|
|
|
if (error != NSERROR_OK) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "box conversion failed");
|
2012-07-22 16:49:10 +04:00
|
|
|
dom_node_unref(html);
|
2014-11-12 22:31:39 +03:00
|
|
|
html_object_free_objects(htmlc);
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, error, NULL);
|
2014-11-12 22:31:39 +03:00
|
|
|
content_set_error(&htmlc->base);
|
2012-07-06 23:00:32 +04:00
|
|
|
return;
|
2008-09-23 06:19:50 +04:00
|
|
|
}
|
2012-07-22 16:49:10 +04:00
|
|
|
|
2012-07-21 23:10:44 +04:00
|
|
|
dom_node_unref(html);
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
|
2019-05-04 14:18:21 +03:00
|
|
|
/* handler for a SCRIPT which has been added to a tree */
|
|
|
|
static void
|
|
|
|
dom_SCRIPT_showed_up(html_content *htmlc, dom_html_script_element *script)
|
|
|
|
{
|
|
|
|
dom_exception exc;
|
|
|
|
dom_html_script_element_flags flags;
|
|
|
|
dom_hubbub_error res;
|
|
|
|
bool within;
|
|
|
|
|
|
|
|
if (!htmlc->enable_scripting) {
|
|
|
|
NSLOG(netsurf, INFO, "Encountered a script, but scripting is off, ignoring");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Encountered a script, node %p showed up", script);
|
|
|
|
|
|
|
|
exc = dom_html_script_element_get_flags(script, &flags);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to retrieve flags, giving up");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DOM_HTML_SCRIPT_ELEMENT_FLAG_PARSER_INSERTED) {
|
|
|
|
NSLOG(netsurf, DEBUG, "Script was parser inserted, skipping");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_node_contains(htmlc->document, script, &within);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEBUG, "Unable to determine if script was within document, ignoring");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!within) {
|
|
|
|
NSLOG(netsurf, DEBUG, "Script was not within the document, ignoring for now");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = html_process_script(htmlc, (dom_node *) script);
|
|
|
|
if (res == DOM_HUBBUB_OK) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Inserted script has finished running");
|
|
|
|
} else {
|
|
|
|
if (res == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED)) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Inserted script has launced asynchronously");
|
|
|
|
} else {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Failure starting script");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
/* callback for DOMNodeInserted end type */
|
|
|
|
static void
|
|
|
|
dom_default_action_DOMNodeInserted_cb(struct dom_event *evt, void *pw)
|
|
|
|
{
|
|
|
|
dom_event_target *node;
|
|
|
|
dom_node_type type;
|
|
|
|
dom_exception exc;
|
|
|
|
html_content *htmlc = pw;
|
|
|
|
|
|
|
|
exc = dom_event_get_target(evt, &node);
|
|
|
|
if ((exc == DOM_NO_ERR) && (node != NULL)) {
|
|
|
|
exc = dom_node_get_node_type(node, &type);
|
|
|
|
if ((exc == DOM_NO_ERR) && (type == DOM_ELEMENT_NODE)) {
|
|
|
|
/* an element node has been inserted */
|
2016-01-29 16:52:25 +03:00
|
|
|
dom_html_element_type tag_type;
|
|
|
|
|
|
|
|
exc = dom_html_element_get_tag_type(node, &tag_type);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
tag_type = DOM_HTML_ELEMENT_TYPE__UNKNOWN;
|
|
|
|
}
|
2013-02-23 01:28:07 +04:00
|
|
|
|
2016-01-29 16:52:25 +03:00
|
|
|
switch (tag_type) {
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_LINK:
|
|
|
|
/* Handle stylesheet loading */
|
|
|
|
html_css_process_link(htmlc, (dom_node *)node);
|
|
|
|
/* Generic link handling */
|
|
|
|
html_process_link(htmlc, (dom_node *)node);
|
|
|
|
break;
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_META:
|
|
|
|
if (htmlc->refresh)
|
|
|
|
break;
|
|
|
|
html_meta_refresh_process_element(htmlc,
|
|
|
|
(dom_node *)node);
|
|
|
|
break;
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_TITLE:
|
|
|
|
if (htmlc->title != NULL)
|
|
|
|
break;
|
|
|
|
htmlc->title = dom_node_ref(node);
|
|
|
|
break;
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_BASE:
|
|
|
|
html_process_base(htmlc, (dom_node *)node);
|
|
|
|
break;
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_IMG:
|
|
|
|
html_process_img(htmlc, (dom_node *) node);
|
|
|
|
break;
|
2016-09-24 14:44:28 +03:00
|
|
|
case DOM_HTML_ELEMENT_TYPE_STYLE:
|
|
|
|
html_css_process_style(htmlc, (dom_node *) node);
|
|
|
|
break;
|
2019-05-04 14:18:21 +03:00
|
|
|
case DOM_HTML_ELEMENT_TYPE_SCRIPT:
|
|
|
|
dom_SCRIPT_showed_up(htmlc, (dom_html_script_element *) node);
|
|
|
|
break;
|
2016-01-29 16:52:25 +03:00
|
|
|
default:
|
|
|
|
break;
|
2015-10-31 19:01:56 +03:00
|
|
|
}
|
2016-01-21 17:51:17 +03:00
|
|
|
if (htmlc->enable_scripting) {
|
|
|
|
/* ensure javascript context is available */
|
2020-03-21 21:30:41 +03:00
|
|
|
if (htmlc->jsthread == NULL) {
|
2016-01-21 17:51:17 +03:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
2020-03-21 21:30:41 +03:00
|
|
|
msg_data.jsthread = &htmlc->jsthread;
|
2016-01-21 17:51:17 +03:00
|
|
|
content_broadcast(&htmlc->base,
|
2020-03-21 21:30:41 +03:00
|
|
|
CONTENT_MSG_GETTHREAD,
|
2017-08-26 17:50:03 +03:00
|
|
|
&msg_data);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"javascript context: %p (htmlc: %p)",
|
2020-03-21 21:30:41 +03:00
|
|
|
htmlc->jsthread,
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
htmlc);
|
2016-01-21 17:51:17 +03:00
|
|
|
}
|
2020-03-21 21:30:41 +03:00
|
|
|
if (htmlc->jsthread != NULL) {
|
|
|
|
js_handle_new_element(htmlc->jsthread,
|
2016-01-21 17:51:17 +03:00
|
|
|
(dom_element *) node);
|
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2013-03-06 02:53:55 +04:00
|
|
|
dom_node_unref(node);
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2019-05-04 14:18:21 +03:00
|
|
|
/* callback for DOMNodeInsertedIntoDocument end type */
|
|
|
|
static void
|
|
|
|
dom_default_action_DOMNodeInsertedIntoDocument_cb(struct dom_event *evt, void *pw)
|
|
|
|
{
|
|
|
|
html_content *htmlc = pw;
|
|
|
|
dom_event_target *node;
|
|
|
|
dom_node_type type;
|
|
|
|
dom_exception exc;
|
|
|
|
|
|
|
|
exc = dom_event_get_target(evt, &node);
|
|
|
|
if ((exc == DOM_NO_ERR) && (node != NULL)) {
|
|
|
|
exc = dom_node_get_node_type(node, &type);
|
|
|
|
if ((exc == DOM_NO_ERR) && (type == DOM_ELEMENT_NODE)) {
|
|
|
|
/* an element node has been modified */
|
|
|
|
dom_html_element_type tag_type;
|
|
|
|
|
|
|
|
exc = dom_html_element_get_tag_type(node, &tag_type);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
tag_type = DOM_HTML_ELEMENT_TYPE__UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (tag_type) {
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_SCRIPT:
|
|
|
|
dom_SCRIPT_showed_up(htmlc, (dom_html_script_element *) node);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dom_node_unref(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 00:07:42 +03:00
|
|
|
/* Deal with input elements being modified by resyncing their gadget
|
|
|
|
* if they have one.
|
|
|
|
*/
|
|
|
|
static void html_texty_element_update(html_content *htmlc, dom_node *node)
|
|
|
|
{
|
|
|
|
struct box *box = box_for_node(node);
|
|
|
|
if (box == NULL) {
|
|
|
|
return; /* No Box (yet?) so no gadget to update */
|
|
|
|
}
|
|
|
|
if (box->gadget == NULL) {
|
|
|
|
return; /* No gadget yet (under construction perhaps?) */
|
|
|
|
}
|
|
|
|
form_gadget_sync_with_dom(box->gadget);
|
|
|
|
/* And schedule a redraw for the box */
|
|
|
|
html__redraw_a_box(htmlc, box);
|
|
|
|
}
|
|
|
|
|
2019-05-04 14:18:21 +03:00
|
|
|
/* callback for DOMSubtreeModified end type */
|
2013-02-20 21:13:23 +04:00
|
|
|
static void
|
|
|
|
dom_default_action_DOMSubtreeModified_cb(struct dom_event *evt, void *pw)
|
|
|
|
{
|
|
|
|
dom_event_target *node;
|
|
|
|
dom_node_type type;
|
|
|
|
dom_exception exc;
|
|
|
|
html_content *htmlc = pw;
|
|
|
|
|
|
|
|
exc = dom_event_get_target(evt, &node);
|
|
|
|
if ((exc == DOM_NO_ERR) && (node != NULL)) {
|
2013-05-23 18:02:15 +04:00
|
|
|
if (htmlc->title == (dom_node *)node) {
|
|
|
|
/* Node is our title node */
|
|
|
|
html_process_title(htmlc, (dom_node *)node);
|
|
|
|
dom_node_unref(node);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:13:23 +04:00
|
|
|
exc = dom_node_get_node_type(node, &type);
|
|
|
|
if ((exc == DOM_NO_ERR) && (type == DOM_ELEMENT_NODE)) {
|
2013-05-23 18:02:15 +04:00
|
|
|
/* an element node has been modified */
|
2017-06-10 19:35:11 +03:00
|
|
|
dom_html_element_type tag_type;
|
2013-05-23 18:02:15 +04:00
|
|
|
|
2017-06-10 19:35:11 +03:00
|
|
|
exc = dom_html_element_get_tag_type(node, &tag_type);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
tag_type = DOM_HTML_ELEMENT_TYPE__UNKNOWN;
|
|
|
|
}
|
2013-02-23 01:28:07 +04:00
|
|
|
|
2017-06-10 19:35:11 +03:00
|
|
|
switch (tag_type) {
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_STYLE:
|
|
|
|
html_css_update_style(htmlc, (dom_node *)node);
|
|
|
|
break;
|
2019-08-05 00:07:42 +03:00
|
|
|
case DOM_HTML_ELEMENT_TYPE_TEXTAREA:
|
|
|
|
case DOM_HTML_ELEMENT_TYPE_INPUT:
|
|
|
|
html_texty_element_update(htmlc, (dom_node *)node);
|
2017-06-10 19:35:11 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-02-20 21:13:23 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-06 02:53:55 +04:00
|
|
|
dom_node_unref(node);
|
2013-02-20 21:13:23 +04:00
|
|
|
}
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2015-10-31 16:52:37 +03:00
|
|
|
static void
|
|
|
|
dom_default_action_finished_cb(struct dom_event *evt, void *pw)
|
|
|
|
{
|
|
|
|
html_content *htmlc = pw;
|
|
|
|
|
2020-03-21 21:30:41 +03:00
|
|
|
if (htmlc->jsthread != NULL)
|
|
|
|
js_event_cleanup(htmlc->jsthread, evt);
|
2015-10-31 16:52:37 +03:00
|
|
|
}
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
/* callback function selector
|
2012-07-06 23:00:32 +04:00
|
|
|
*
|
2013-02-20 03:51:16 +04:00
|
|
|
* selects a callback function for libdom to call based on the type and phase.
|
|
|
|
* dom_default_action_phase from events/document_event.h
|
2012-07-06 23:00:32 +04:00
|
|
|
*
|
2013-02-25 19:00:50 +04:00
|
|
|
* The principle events are:
|
|
|
|
* DOMSubtreeModified
|
|
|
|
* DOMAttrModified
|
|
|
|
* DOMNodeInserted
|
|
|
|
* DOMNodeInsertedIntoDocument
|
|
|
|
*
|
2013-02-20 03:51:16 +04:00
|
|
|
* @return callback function pointer or NULL for none
|
2012-07-06 23:00:32 +04:00
|
|
|
*/
|
2013-02-20 03:51:16 +04:00
|
|
|
static dom_default_action_callback
|
|
|
|
dom_event_fetcher(dom_string *type,
|
|
|
|
dom_default_action_phase phase,
|
|
|
|
void **pw)
|
2012-07-06 23:00:32 +04:00
|
|
|
{
|
2019-05-04 14:18:21 +03:00
|
|
|
NSLOG(netsurf, DEEPDEBUG, "phase:%d type:%s", phase, dom_string_data(type));
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 21:13:23 +04:00
|
|
|
if (phase == DOM_DEFAULT_ACTION_END) {
|
|
|
|
if (dom_string_isequal(type, corestring_dom_DOMNodeInserted)) {
|
|
|
|
return dom_default_action_DOMNodeInserted_cb;
|
2019-05-04 14:18:21 +03:00
|
|
|
} else if (dom_string_isequal(type, corestring_dom_DOMNodeInsertedIntoDocument)) {
|
|
|
|
return dom_default_action_DOMNodeInsertedIntoDocument_cb;
|
2013-02-20 21:13:23 +04:00
|
|
|
} else if (dom_string_isequal(type, corestring_dom_DOMSubtreeModified)) {
|
|
|
|
return dom_default_action_DOMSubtreeModified_cb;
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
2015-10-31 16:52:37 +03:00
|
|
|
} else if (phase == DOM_DEFAULT_ACTION_FINISHED) {
|
|
|
|
return dom_default_action_finished_cb;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2013-02-20 03:51:16 +04:00
|
|
|
return NULL;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2015-08-09 14:00:25 +03:00
|
|
|
static void
|
|
|
|
html_document_user_data_handler(dom_node_operation operation,
|
|
|
|
dom_string *key, void *data,
|
|
|
|
struct dom_node *src,
|
|
|
|
struct dom_node *dst)
|
|
|
|
{
|
|
|
|
if (dom_string_isequal(corestring_dom___ns_key_html_content_data,
|
|
|
|
key) == false || data == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (operation) {
|
|
|
|
case DOM_NODE_CLONED:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Cloned");
|
2015-08-09 14:00:25 +03:00
|
|
|
break;
|
|
|
|
case DOM_NODE_RENAMED:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Renamed");
|
2015-08-09 14:00:25 +03:00
|
|
|
break;
|
|
|
|
case DOM_NODE_IMPORTED:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "imported");
|
2015-08-09 14:00:25 +03:00
|
|
|
break;
|
|
|
|
case DOM_NODE_ADOPTED:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Adopted");
|
2015-08-09 14:00:25 +03:00
|
|
|
break;
|
|
|
|
case DOM_NODE_DELETED:
|
|
|
|
/* This is the only path I expect */
|
|
|
|
break;
|
|
|
|
default:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "User data operation not handled.");
|
2015-08-09 14:00:25 +03:00
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
static nserror
|
|
|
|
html_create_html_data(html_content *c, const http_parameter *params)
|
2012-07-06 23:00:32 +04:00
|
|
|
{
|
2013-02-20 03:51:16 +04:00
|
|
|
lwc_string *charset;
|
|
|
|
nserror nerror;
|
|
|
|
dom_hubbub_parser_params parse_params;
|
|
|
|
dom_hubbub_error error;
|
2015-08-09 14:00:25 +03:00
|
|
|
dom_exception err;
|
|
|
|
void *old_node_data;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
c->parser = NULL;
|
2014-02-10 05:24:43 +04:00
|
|
|
c->parse_completed = false;
|
2019-05-04 14:18:21 +03:00
|
|
|
c->conversion_begun = false;
|
2013-02-20 03:51:16 +04:00
|
|
|
c->document = NULL;
|
|
|
|
c->quirks = DOM_DOCUMENT_QUIRKS_MODE_NONE;
|
|
|
|
c->encoding = NULL;
|
|
|
|
c->base_url = nsurl_ref(content_get_url(&c->base));
|
|
|
|
c->base_target = NULL;
|
|
|
|
c->aborted = false;
|
2013-05-23 02:57:59 +04:00
|
|
|
c->refresh = false;
|
2014-09-27 12:57:26 +04:00
|
|
|
c->reflowing = false;
|
2013-05-23 18:02:15 +04:00
|
|
|
c->title = NULL;
|
2013-02-20 03:51:16 +04:00
|
|
|
c->bctx = NULL;
|
|
|
|
c->layout = NULL;
|
|
|
|
c->background_colour = NS_TRANSPARENT;
|
|
|
|
c->stylesheet_count = 0;
|
|
|
|
c->stylesheets = NULL;
|
|
|
|
c->select_ctx = NULL;
|
2019-05-04 14:02:55 +03:00
|
|
|
c->media.type = CSS_MEDIA_SCREEN;
|
2013-02-20 03:51:16 +04:00
|
|
|
c->universal = NULL;
|
|
|
|
c->num_objects = 0;
|
|
|
|
c->object_list = NULL;
|
|
|
|
c->forms = NULL;
|
|
|
|
c->imagemaps = NULL;
|
|
|
|
c->bw = NULL;
|
|
|
|
c->frameset = NULL;
|
|
|
|
c->iframe = NULL;
|
|
|
|
c->page = NULL;
|
2016-04-24 01:32:21 +03:00
|
|
|
c->font_func = guit->layout;
|
2013-02-20 03:51:16 +04:00
|
|
|
c->drag_type = HTML_DRAG_NONE;
|
|
|
|
c->drag_owner.no_owner = true;
|
2013-02-22 17:24:36 +04:00
|
|
|
c->selection_type = HTML_SELECTION_NONE;
|
|
|
|
c->selection_owner.none = true;
|
|
|
|
c->focus_type = HTML_FOCUS_SELF;
|
|
|
|
c->focus_owner.self = true;
|
2013-05-07 17:41:40 +04:00
|
|
|
c->search = NULL;
|
|
|
|
c->search_string = NULL;
|
2013-02-20 03:51:16 +04:00
|
|
|
c->scripts_count = 0;
|
|
|
|
c->scripts = NULL;
|
2020-03-21 21:30:41 +03:00
|
|
|
c->jsthread = NULL;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2016-01-21 17:11:36 +03:00
|
|
|
c->enable_scripting = nsoption_bool(enable_javascript);
|
2013-02-20 03:51:16 +04:00
|
|
|
c->base.active = 1; /* The html content itself is active */
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
|
|
|
|
return NSERROR_NOMEM;
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
selection_prepare(&c->sel, (struct content *)c, true);
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-24 17:15:05 +04:00
|
|
|
nerror = http_parameter_list_find_item(params, corestring_lwc_charset, &charset);
|
2013-02-20 03:51:16 +04:00
|
|
|
if (nerror == NSERROR_OK) {
|
|
|
|
c->encoding = strdup(lwc_string_data(charset));
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
lwc_string_unref(charset);
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
if (c->encoding == NULL) {
|
|
|
|
lwc_string_unref(c->universal);
|
|
|
|
c->universal = NULL;
|
|
|
|
return NSERROR_NOMEM;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
}
|
|
|
|
c->encoding_source = DOM_HUBBUB_ENCODING_SOURCE_HEADER;
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
/* Create the parser binding */
|
|
|
|
parse_params.enc = c->encoding;
|
|
|
|
parse_params.fix_enc = true;
|
2016-01-21 17:11:36 +03:00
|
|
|
parse_params.enable_script = c->enable_scripting;
|
2013-02-20 03:51:16 +04:00
|
|
|
parse_params.msg = NULL;
|
|
|
|
parse_params.script = html_process_script;
|
|
|
|
parse_params.ctx = c;
|
|
|
|
parse_params.daf = dom_event_fetcher;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
error = dom_hubbub_parser_create(&parse_params,
|
|
|
|
&c->parser,
|
|
|
|
&c->document);
|
|
|
|
if ((error != DOM_HUBBUB_OK) && (c->encoding != NULL)) {
|
|
|
|
/* Ok, we don't support the declared encoding. Bailing out
|
|
|
|
* isn't exactly user-friendly, so fall back to autodetect */
|
|
|
|
free(c->encoding);
|
|
|
|
c->encoding = NULL;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
parse_params.enc = c->encoding;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
error = dom_hubbub_parser_create(&parse_params,
|
|
|
|
&c->parser,
|
|
|
|
&c->document);
|
2012-11-26 21:23:03 +04:00
|
|
|
}
|
2013-02-20 03:51:16 +04:00
|
|
|
if (error != DOM_HUBBUB_OK) {
|
|
|
|
nsurl_unref(c->base_url);
|
|
|
|
c->base_url = NULL;
|
2012-06-19 13:35:51 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
lwc_string_unref(c->universal);
|
|
|
|
c->universal = NULL;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
return libdom_hubbub_error_to_nserror(error);
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2015-08-09 14:00:25 +03:00
|
|
|
err = dom_node_set_user_data(c->document,
|
|
|
|
corestring_dom___ns_key_html_content_data,
|
|
|
|
c, html_document_user_data_handler,
|
|
|
|
(void *) &old_node_data);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_hubbub_parser_destroy(c->parser);
|
2019-05-04 14:18:21 +03:00
|
|
|
c->parser = NULL;
|
2015-08-09 14:00:25 +03:00
|
|
|
nsurl_unref(c->base_url);
|
|
|
|
c->base_url = NULL;
|
|
|
|
|
|
|
|
lwc_string_unref(c->universal);
|
|
|
|
c->universal = NULL;
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Unable to set user data.");
|
2015-08-12 12:00:22 +03:00
|
|
|
return NSERROR_DOM;
|
2015-08-09 14:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(old_node_data == NULL);
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
return NSERROR_OK;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
/**
|
|
|
|
* Create a CONTENT_HTML.
|
|
|
|
*
|
|
|
|
* The content_html_data structure is initialized and the HTML parser is
|
|
|
|
* created.
|
|
|
|
*/
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
static nserror
|
|
|
|
html_create(const content_handler *handler,
|
|
|
|
lwc_string *imime_type,
|
|
|
|
const http_parameter *params,
|
|
|
|
llcache_handle *llcache,
|
|
|
|
const char *fallback_charset,
|
|
|
|
bool quirks,
|
|
|
|
struct content **c)
|
|
|
|
{
|
|
|
|
html_content *html;
|
|
|
|
nserror error;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
html = calloc(1, sizeof(html_content));
|
|
|
|
if (html == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
error = content__init(&html->base, handler, imime_type, params,
|
|
|
|
llcache, fallback_charset, quirks);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
free(html);
|
|
|
|
return error;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
error = html_create_html_data(html, params);
|
|
|
|
if (error != NSERROR_OK) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&html->base, error, NULL);
|
2013-02-20 03:51:16 +04:00
|
|
|
free(html);
|
|
|
|
return error;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-24 17:15:05 +04:00
|
|
|
error = html_css_new_stylesheets(html);
|
|
|
|
if (error != NSERROR_OK) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&html->base, error, NULL);
|
2013-02-24 17:15:05 +04:00
|
|
|
free(html);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
*c = (struct content *) html;
|
2012-07-06 23:00:32 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static nserror
|
2018-05-10 13:34:26 +03:00
|
|
|
html_process_encoding_change(struct content *c,
|
|
|
|
const char *data,
|
2013-02-20 03:51:16 +04:00
|
|
|
unsigned int size)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
dom_hubbub_parser_params parse_params;
|
|
|
|
dom_hubbub_error error;
|
|
|
|
const char *encoding;
|
2019-05-06 00:46:40 +03:00
|
|
|
const uint8_t *source_data;
|
|
|
|
size_t source_size;
|
2013-02-20 03:51:16 +04:00
|
|
|
|
|
|
|
/* Retrieve new encoding */
|
2018-05-10 13:34:26 +03:00
|
|
|
encoding = dom_hubbub_parser_get_encoding(html->parser,
|
2013-02-20 03:51:16 +04:00
|
|
|
&html->encoding_source);
|
|
|
|
if (encoding == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
if (html->encoding != NULL) {
|
|
|
|
free(html->encoding);
|
2013-10-23 21:55:51 +04:00
|
|
|
html->encoding = NULL;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
html->encoding = strdup(encoding);
|
|
|
|
if (html->encoding == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
/* Destroy binding */
|
|
|
|
dom_hubbub_parser_destroy(html->parser);
|
|
|
|
html->parser = NULL;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
if (html->document != NULL) {
|
|
|
|
dom_node_unref(html->document);
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
parse_params.enc = html->encoding;
|
|
|
|
parse_params.fix_enc = true;
|
2016-01-21 17:11:36 +03:00
|
|
|
parse_params.enable_script = html->enable_scripting;
|
2013-02-20 03:51:16 +04:00
|
|
|
parse_params.msg = NULL;
|
|
|
|
parse_params.script = html_process_script;
|
|
|
|
parse_params.ctx = html;
|
|
|
|
parse_params.daf = dom_event_fetcher;
|
|
|
|
|
|
|
|
/* Create new binding, using the new encoding */
|
|
|
|
error = dom_hubbub_parser_create(&parse_params,
|
|
|
|
&html->parser,
|
|
|
|
&html->document);
|
|
|
|
if (error != DOM_HUBBUB_OK) {
|
|
|
|
/* Ok, we don't support the declared encoding. Bailing out
|
|
|
|
* isn't exactly user-friendly, so fall back to Windows-1252 */
|
|
|
|
free(html->encoding);
|
|
|
|
html->encoding = strdup("Windows-1252");
|
|
|
|
if (html->encoding == NULL) {
|
2012-11-26 21:23:03 +04:00
|
|
|
return NSERROR_NOMEM;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2013-02-20 03:51:16 +04:00
|
|
|
parse_params.enc = html->encoding;
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
error = dom_hubbub_parser_create(&parse_params,
|
|
|
|
&html->parser,
|
|
|
|
&html->document);
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
if (error != DOM_HUBBUB_OK) {
|
|
|
|
return libdom_hubbub_error_to_nserror(error);
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-07-06 23:00:32 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
source_data = content__get_source_data(c, &source_size);
|
2012-07-06 23:00:32 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
/* Reprocess all the data. This is safe because
|
|
|
|
* the encoding is now specified at parser start which means
|
2018-05-10 13:34:26 +03:00
|
|
|
* it cannot be changed again.
|
2013-02-20 03:51:16 +04:00
|
|
|
*/
|
2018-05-10 13:34:26 +03:00
|
|
|
error = dom_hubbub_parser_parse_chunk(html->parser,
|
2019-05-06 00:46:40 +03:00
|
|
|
source_data,
|
2013-02-20 03:51:16 +04:00
|
|
|
source_size);
|
|
|
|
|
|
|
|
return libdom_hubbub_error_to_nserror(error);
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-02-20 03:51:16 +04:00
|
|
|
* Process data for CONTENT_HTML.
|
2012-03-24 21:11:17 +04:00
|
|
|
*/
|
2012-07-06 23:00:32 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
static bool
|
|
|
|
html_process_data(struct content *c, const char *data, unsigned int size)
|
2012-03-24 21:11:17 +04:00
|
|
|
{
|
2013-02-20 03:51:16 +04:00
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
dom_hubbub_error dom_ret;
|
|
|
|
nserror err = NSERROR_OK; /* assume its all going to be ok */
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
dom_ret = dom_hubbub_parser_parse_chunk(html->parser,
|
|
|
|
(const uint8_t *) data,
|
2013-02-20 03:51:16 +04:00
|
|
|
size);
|
|
|
|
|
|
|
|
err = libdom_hubbub_error_to_nserror(dom_ret);
|
|
|
|
|
|
|
|
/* deal with encoding change */
|
|
|
|
if (err == NSERROR_ENCODING_CHANGE) {
|
|
|
|
err = html_process_encoding_change(c, data, size);
|
2012-11-27 00:33:27 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
/* broadcast the error if necessary */
|
|
|
|
if (err != NSERROR_OK) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(c, err, NULL);
|
2013-02-20 03:51:16 +04:00
|
|
|
return false;
|
2012-11-27 00:33:27 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
return true;
|
2013-02-20 03:51:16 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
2012-03-24 21:11:17 +04:00
|
|
|
* Convert a CONTENT_HTML for display.
|
|
|
|
*
|
|
|
|
* The following steps are carried out in order:
|
|
|
|
*
|
|
|
|
* - parsing to an XML tree is completed
|
|
|
|
* - stylesheets are fetched
|
|
|
|
* - the XML tree is converted to a box tree and object fetches are started
|
|
|
|
*
|
|
|
|
* On exit, the content status will be either CONTENT_STATUS_DONE if the
|
|
|
|
* document is completely loaded or CONTENT_STATUS_READY if objects are still
|
|
|
|
* being fetched.
|
2004-02-20 03:43:17 +03:00
|
|
|
*/
|
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
static bool html_convert(struct content *c)
|
2003-04-15 21:53:00 +04:00
|
|
|
{
|
2012-03-24 21:11:17 +04:00
|
|
|
html_content *htmlc = (html_content *) c;
|
2013-02-25 19:00:50 +04:00
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
|
|
|
|
/* The quirk check and associated stylesheet fetch is "safe"
|
|
|
|
* once the root node has been inserted into the document
|
|
|
|
* which must have happened by this point in the parse.
|
|
|
|
*
|
|
|
|
* faliure to retrive the quirk mode or to start the
|
|
|
|
* stylesheet fetch is non fatal as this "only" affects the
|
|
|
|
* render and it would annoy the user to fail the entire
|
|
|
|
* render for want of a quirks stylesheet.
|
|
|
|
*/
|
|
|
|
exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks);
|
|
|
|
if (exc == DOM_NO_ERR) {
|
|
|
|
html_css_quirks_stylesheets(htmlc);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "quirks set to %d", htmlc->quirks);
|
2013-02-25 19:00:50 +04:00
|
|
|
}
|
2012-07-30 21:18:11 +04:00
|
|
|
|
|
|
|
htmlc->base.active--; /* the html fetch is no longer active */
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active (%p)", htmlc->base.active, c);
|
2012-07-30 21:18:11 +04:00
|
|
|
|
2013-02-25 19:00:50 +04:00
|
|
|
/* The parse cannot be completed here because it may be paused
|
|
|
|
* untill all the resources being fetched have completed.
|
|
|
|
*/
|
|
|
|
|
2012-07-30 21:18:11 +04:00
|
|
|
/* if there are no active fetches in progress no scripts are
|
|
|
|
* being fetched or they completed already.
|
2013-03-18 18:48:00 +04:00
|
|
|
*/
|
|
|
|
if (html_can_begin_conversion(htmlc)) {
|
2012-07-30 21:18:11 +04:00
|
|
|
return html_begin_conversion(htmlc);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-18 18:48:00 +04:00
|
|
|
/* Exported interface documented in html_internal.h */
|
|
|
|
bool html_can_begin_conversion(html_content *htmlc)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2013-05-20 22:51:15 +04:00
|
|
|
|
2019-05-04 14:18:21 +03:00
|
|
|
/* Cannot begin conversion if we're still fetching stuff */
|
2013-05-20 22:51:15 +04:00
|
|
|
if (htmlc->base.active != 0)
|
|
|
|
return false;
|
2013-03-18 18:48:00 +04:00
|
|
|
|
|
|
|
for (i = 0; i != htmlc->stylesheet_count; i++) {
|
2019-05-04 14:18:21 +03:00
|
|
|
/* Cannot begin conversion if the stylesheets are modified */
|
2013-05-20 22:51:15 +04:00
|
|
|
if (htmlc->stylesheets[i].modified)
|
|
|
|
return false;
|
2013-03-18 18:48:00 +04:00
|
|
|
}
|
|
|
|
|
2019-05-04 14:18:21 +03:00
|
|
|
/* All is good, begin */
|
2013-03-18 18:48:00 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-30 21:18:11 +04:00
|
|
|
bool
|
|
|
|
html_begin_conversion(html_content *htmlc)
|
|
|
|
{
|
2013-05-23 18:02:15 +04:00
|
|
|
dom_node *html;
|
2012-11-26 21:23:03 +04:00
|
|
|
nserror ns_error;
|
2012-03-24 21:11:17 +04:00
|
|
|
struct form *f;
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
dom_string *node_name = NULL;
|
2012-07-30 21:18:11 +04:00
|
|
|
dom_hubbub_error error;
|
2004-01-24 20:08:16 +03:00
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
/* The act of completing the parse can result in additional data
|
|
|
|
* being flushed through the parser. This may result in new style or
|
|
|
|
* script nodes, upon which the conversion depends. Thus, once we
|
|
|
|
* have completed the parse, we must check again to see if we can
|
|
|
|
* begin the conversion. If we can't, we must stop and wait for the
|
2014-02-10 05:24:43 +04:00
|
|
|
* new styles/scripts to be processed. Once they have been processed,
|
2018-05-10 13:34:26 +03:00
|
|
|
* we will be called again to begin the conversion for real. Thus,
|
|
|
|
* we must also ensure that we don't attempt to complete the parse
|
2014-02-10 05:24:43 +04:00
|
|
|
* multiple times, so store a flag to indicate that parsing is
|
|
|
|
* complete to avoid repeating the completion pointlessly.
|
|
|
|
*/
|
|
|
|
if (htmlc->parse_completed == false) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Completing parse (%p)", htmlc);
|
2014-02-10 05:24:43 +04:00
|
|
|
/* complete parsing */
|
|
|
|
error = dom_hubbub_parser_completed(htmlc->parser);
|
2019-08-05 23:29:00 +03:00
|
|
|
if (error == DOM_HUBBUB_HUBBUB_ERR_PAUSED && htmlc->base.active > 0) {
|
|
|
|
/* The act of completing the parse failed because we've
|
|
|
|
* encountered a sync script which needs to run
|
|
|
|
*/
|
|
|
|
NSLOG(netsurf, INFO, "Completing parse brought synchronous JS to light, cannot complete yet");
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 05:24:43 +04:00
|
|
|
if (error != DOM_HUBBUB_OK) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Parsing failed");
|
2018-05-10 13:34:26 +03:00
|
|
|
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base,
|
|
|
|
libdom_hubbub_error_to_nserror(error),
|
|
|
|
NULL);
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2014-02-10 05:24:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
htmlc->parse_completed = true;
|
|
|
|
}
|
2011-04-27 17:50:49 +04:00
|
|
|
|
2014-02-10 05:24:43 +04:00
|
|
|
if (html_can_begin_conversion(htmlc) == false) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Can't begin conversion (%p)", htmlc);
|
2014-02-10 05:24:43 +04:00
|
|
|
/* We can't proceed (see commentary above) */
|
|
|
|
return true;
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
2011-04-27 17:50:49 +04:00
|
|
|
|
2012-11-26 21:23:03 +04:00
|
|
|
/* Give up processing if we've been aborted */
|
|
|
|
if (htmlc->aborted) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Conversion aborted (%p) (active: %u)",
|
|
|
|
htmlc, htmlc->base.active);
|
2017-03-23 17:25:46 +03:00
|
|
|
content_set_error(&htmlc->base);
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, NSERROR_STOPPED, NULL);
|
2012-11-26 21:23:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-04 14:18:21 +03:00
|
|
|
/* Conversion begins proper at this point */
|
|
|
|
htmlc->conversion_begun = true;
|
|
|
|
|
|
|
|
/* complete script execution, including deferred scripts */
|
|
|
|
html_script_exec(htmlc, true);
|
2012-08-01 01:33:08 +04:00
|
|
|
|
2012-11-26 21:23:03 +04:00
|
|
|
/* fire a simple event that bubbles named DOMContentLoaded at
|
|
|
|
* the Document.
|
|
|
|
*/
|
|
|
|
|
2012-08-05 13:53:03 +04:00
|
|
|
/* get encoding */
|
2012-03-24 21:11:17 +04:00
|
|
|
if (htmlc->encoding == NULL) {
|
2012-07-14 03:33:15 +04:00
|
|
|
const char *encoding;
|
2012-10-03 22:24:58 +04:00
|
|
|
|
2012-07-14 03:33:15 +04:00
|
|
|
encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
|
|
|
|
&htmlc->encoding_source);
|
2012-10-03 22:24:58 +04:00
|
|
|
if (encoding == NULL) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base,
|
|
|
|
NSERROR_NOMEM,
|
|
|
|
NULL);
|
2012-10-03 22:24:58 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-04-27 17:50:49 +04:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
htmlc->encoding = strdup(encoding);
|
2012-03-24 21:11:17 +04:00
|
|
|
if (htmlc->encoding == NULL) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base,
|
|
|
|
NSERROR_NOMEM,
|
|
|
|
NULL);
|
2012-03-24 21:11:17 +04:00
|
|
|
return false;
|
2011-04-27 17:50:49 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-06-18 02:12:29 +04:00
|
|
|
/* locate root element and ensure it is html */
|
2012-03-25 02:26:44 +04:00
|
|
|
exc = dom_document_get_document_element(htmlc->document, (void *) &html);
|
2012-07-06 23:00:32 +04:00
|
|
|
if ((exc != DOM_NO_ERR) || (html == NULL)) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "error retrieving html element from dom");
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, NSERROR_DOM, NULL);
|
2012-03-24 21:11:17 +04:00
|
|
|
return false;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
exc = dom_node_get_node_name(html, &node_name);
|
2012-07-06 23:00:32 +04:00
|
|
|
if ((exc != DOM_NO_ERR) ||
|
|
|
|
(node_name == NULL) ||
|
2012-07-23 02:28:45 +04:00
|
|
|
(!dom_string_caseless_lwc_isequal(node_name,
|
2018-05-10 13:34:26 +03:00
|
|
|
corestring_lwc_html))) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "root element not html");
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, NSERROR_DOM, NULL);
|
2012-07-21 23:10:44 +04:00
|
|
|
dom_node_unref(html);
|
2012-03-24 21:11:17 +04:00
|
|
|
return false;
|
2012-07-06 23:00:32 +04:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
dom_string_unref(node_name);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
/* Retrieve forms from parser */
|
2012-07-15 04:02:33 +04:00
|
|
|
htmlc->forms = html_forms_get_forms(htmlc->encoding,
|
|
|
|
(dom_html_document *) htmlc->document);
|
2012-03-24 21:11:17 +04:00
|
|
|
for (f = htmlc->forms; f != NULL; f = f->prev) {
|
2012-10-11 20:49:42 +04:00
|
|
|
nsurl *action;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
/* Make all actions absolute */
|
|
|
|
if (f->action == NULL || f->action[0] == '\0') {
|
2012-10-11 20:49:42 +04:00
|
|
|
/* HTML5 4.10.22.3 step 9 */
|
|
|
|
nsurl *doc_addr = content_get_url(&htmlc->base);
|
2012-11-26 21:23:03 +04:00
|
|
|
ns_error = nsurl_join(htmlc->base_url,
|
2018-05-10 13:34:26 +03:00
|
|
|
nsurl_access(doc_addr),
|
2012-11-26 21:23:03 +04:00
|
|
|
&action);
|
2012-03-24 21:11:17 +04:00
|
|
|
} else {
|
2018-05-10 13:34:26 +03:00
|
|
|
ns_error = nsurl_join(htmlc->base_url,
|
|
|
|
f->action,
|
2012-11-26 21:23:03 +04:00
|
|
|
&action);
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-11-26 21:23:03 +04:00
|
|
|
if (ns_error != NSERROR_OK) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base, ns_error, NULL);
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2012-07-21 23:10:44 +04:00
|
|
|
dom_node_unref(html);
|
2012-03-24 21:11:17 +04:00
|
|
|
return false;
|
2011-10-04 00:38:23 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
free(f->action);
|
2012-10-11 20:49:42 +04:00
|
|
|
f->action = strdup(nsurl_access(action));
|
|
|
|
nsurl_unref(action);
|
|
|
|
if (f->action == NULL) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base,
|
|
|
|
NSERROR_NOMEM,
|
|
|
|
NULL);
|
2012-11-26 21:23:03 +04:00
|
|
|
|
2012-10-11 20:49:42 +04:00
|
|
|
dom_node_unref(html);
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
|
|
|
|
/* Ensure each form has a document encoding */
|
|
|
|
if (f->document_charset == NULL) {
|
|
|
|
f->document_charset = strdup(htmlc->encoding);
|
|
|
|
if (f->document_charset == NULL) {
|
2019-08-05 17:25:15 +03:00
|
|
|
content_broadcast_error(&htmlc->base,
|
|
|
|
NSERROR_NOMEM,
|
|
|
|
NULL);
|
2012-07-21 23:10:44 +04:00
|
|
|
dom_node_unref(html);
|
2012-03-24 21:11:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-11 02:08:34 +03:00
|
|
|
}
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2013-02-20 03:51:16 +04:00
|
|
|
dom_node_unref(html);
|
2012-07-30 18:17:57 +04:00
|
|
|
|
2012-07-30 21:18:11 +04:00
|
|
|
if (htmlc->base.active == 0) {
|
|
|
|
html_finish_conversion(htmlc);
|
|
|
|
}
|
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-02 19:08:25 +04:00
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2004-06-21 03:09:52 +04:00
|
|
|
/**
|
2011-07-20 00:23:59 +04:00
|
|
|
* Stop loading a CONTENT_HTML.
|
2015-03-09 16:47:12 +03:00
|
|
|
*
|
|
|
|
* called when the content is aborted. This must clean up any state
|
|
|
|
* created during the fetch.
|
2004-06-21 03:09:52 +04:00
|
|
|
*/
|
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
static void html_stop(struct content *c)
|
2004-06-21 03:09:52 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *htmlc = (html_content *) c;
|
2004-06-21 03:09:52 +04:00
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
switch (c->status) {
|
|
|
|
case CONTENT_STATUS_LOADING:
|
|
|
|
/* Still loading; simply flag that we've been aborted
|
|
|
|
* html_convert/html_finish_conversion will do the rest */
|
|
|
|
htmlc->aborted = true;
|
2020-03-29 16:31:33 +03:00
|
|
|
if (htmlc->jsthread != NULL) {
|
|
|
|
/* Close the JS thread to cancel out any callbacks */
|
|
|
|
js_closethread(htmlc->jsthread);
|
|
|
|
}
|
2011-07-20 00:23:59 +04:00
|
|
|
break;
|
2012-06-19 13:35:51 +04:00
|
|
|
|
2013-02-25 22:24:04 +04:00
|
|
|
case CONTENT_STATUS_READY:
|
|
|
|
html_object_abort_objects(htmlc);
|
2011-07-20 03:08:55 +04:00
|
|
|
|
|
|
|
/* If there are no further active fetches and we're still
|
2018-05-10 13:34:26 +03:00
|
|
|
* in the READY state, transition to the DONE state. */
|
2011-07-20 03:08:55 +04:00
|
|
|
if (c->status == CONTENT_STATUS_READY && c->active == 0) {
|
|
|
|
content_set_done(c);
|
|
|
|
}
|
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
break;
|
2013-02-25 22:24:04 +04:00
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
case CONTENT_STATUS_DONE:
|
|
|
|
/* Nothing to do */
|
|
|
|
break;
|
2013-02-25 22:24:04 +04:00
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
default:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Unexpected status %d (%p)", c->status,
|
|
|
|
c);
|
2011-07-20 00:23:59 +04:00
|
|
|
assert(0);
|
2004-06-21 03:09:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Reformat a CONTENT_HTML to a new width.
|
|
|
|
*/
|
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
static void html_reformat(struct content *c, int width, int height)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *htmlc = (html_content *) c;
|
2006-09-17 01:33:55 +04:00
|
|
|
struct box *layout;
|
2016-04-20 21:57:44 +03:00
|
|
|
uint64_t ms_before;
|
|
|
|
uint64_t ms_after;
|
|
|
|
uint64_t ms_interval;
|
2010-03-30 02:33:21 +04:00
|
|
|
|
2016-04-20 21:18:15 +03:00
|
|
|
nsu_getmonotonic_ms(&ms_before);
|
2006-06-29 23:55:08 +04:00
|
|
|
|
2014-09-27 12:57:26 +04:00
|
|
|
htmlc->reflowing = true;
|
|
|
|
|
2019-06-29 23:59:15 +03:00
|
|
|
htmlc->len_ctx.vw = nscss_pixels_physical_to_css(INTTOFIX(width));
|
|
|
|
htmlc->len_ctx.vh = nscss_pixels_physical_to_css(INTTOFIX(height));
|
2018-01-04 02:58:18 +03:00
|
|
|
htmlc->len_ctx.root_style = htmlc->layout->style;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
layout_document(htmlc, width, height);
|
|
|
|
layout = htmlc->layout;
|
2006-09-17 01:33:55 +04:00
|
|
|
|
|
|
|
/* width and height are at least margin box of document */
|
|
|
|
c->width = layout->x + layout->padding[LEFT] + layout->width +
|
2016-04-20 21:57:44 +03:00
|
|
|
layout->padding[RIGHT] + layout->border[RIGHT].width +
|
|
|
|
layout->margin[RIGHT];
|
2006-09-17 01:33:55 +04:00
|
|
|
c->height = layout->y + layout->padding[TOP] + layout->height +
|
2016-04-20 21:57:44 +03:00
|
|
|
layout->padding[BOTTOM] + layout->border[BOTTOM].width +
|
|
|
|
layout->margin[BOTTOM];
|
2006-09-17 01:33:55 +04:00
|
|
|
|
|
|
|
/* if boxes overflow right or bottom edge, expand to contain it */
|
|
|
|
if (c->width < layout->x + layout->descendant_x1)
|
|
|
|
c->width = layout->x + layout->descendant_x1;
|
|
|
|
if (c->height < layout->y + layout->descendant_y1)
|
|
|
|
c->height = layout->y + layout->descendant_y1;
|
2010-03-30 02:33:21 +04:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
selection_reinit(&htmlc->sel, htmlc->layout);
|
|
|
|
|
2014-09-27 12:57:26 +04:00
|
|
|
htmlc->reflowing = false;
|
2019-08-06 11:41:22 +03:00
|
|
|
htmlc->had_initial_layout = true;
|
2014-09-27 12:57:26 +04:00
|
|
|
|
2016-04-20 21:57:44 +03:00
|
|
|
/* calculate next reflow time at three times what it took to reflow */
|
|
|
|
nsu_getmonotonic_ms(&ms_after);
|
2016-04-20 21:18:15 +03:00
|
|
|
|
2019-06-06 00:59:24 +03:00
|
|
|
ms_interval = (ms_after - ms_before) * 3;
|
2016-04-20 21:57:44 +03:00
|
|
|
if (ms_interval < (nsoption_uint(min_reflow_period) * 10)) {
|
|
|
|
ms_interval = nsoption_uint(min_reflow_period) * 10;
|
|
|
|
}
|
|
|
|
c->reformat_time = ms_after + ms_interval;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
/**
|
|
|
|
* Redraw a box.
|
|
|
|
*
|
2010-11-03 18:44:01 +03:00
|
|
|
* \param h content containing the box, of type CONTENT_HTML
|
2010-06-04 13:35:08 +04:00
|
|
|
* \param box box to redraw
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_redraw_a_box(hlcache_handle *h, struct box *box)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
box_coords(box, &x, &y);
|
|
|
|
|
|
|
|
content_request_redraw(h, x, y,
|
|
|
|
box->padding[LEFT] + box->width + box->padding[RIGHT],
|
|
|
|
box->padding[TOP] + box->height + box->padding[BOTTOM]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-07 21:50:04 +04:00
|
|
|
/**
|
|
|
|
* Redraw a box.
|
|
|
|
*
|
2014-11-12 19:21:23 +03:00
|
|
|
* \param html content containing the box, of type CONTENT_HTML
|
|
|
|
* \param box box to redraw.
|
2011-07-07 21:50:04 +04:00
|
|
|
*/
|
|
|
|
|
2012-08-16 16:22:35 +04:00
|
|
|
void html__redraw_a_box(struct html_content *html, struct box *box)
|
2011-07-07 21:50:04 +04:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
box_coords(box, &x, &y);
|
|
|
|
|
2012-08-16 16:22:35 +04:00
|
|
|
content__request_redraw((struct content *)html, x, y,
|
2011-07-07 21:50:04 +04:00
|
|
|
box->padding[LEFT] + box->width + box->padding[RIGHT],
|
|
|
|
box->padding[TOP] + box->height + box->padding[BOTTOM]);
|
|
|
|
}
|
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
static void html_destroy_frameset(struct content_html_frames *frameset)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (frameset->name) {
|
2012-10-03 23:48:53 +04:00
|
|
|
talloc_free(frameset->name);
|
2012-03-24 21:11:17 +04:00
|
|
|
frameset->name = NULL;
|
|
|
|
}
|
|
|
|
if (frameset->url) {
|
2012-10-03 23:48:53 +04:00
|
|
|
talloc_free(frameset->url);
|
2012-03-24 21:11:17 +04:00
|
|
|
frameset->url = NULL;
|
|
|
|
}
|
|
|
|
if (frameset->children) {
|
|
|
|
for (i = 0; i < (frameset->rows * frameset->cols); i++) {
|
|
|
|
if (frameset->children[i].name) {
|
2012-10-03 23:48:53 +04:00
|
|
|
talloc_free(frameset->children[i].name);
|
2012-03-24 21:11:17 +04:00
|
|
|
frameset->children[i].name = NULL;
|
|
|
|
}
|
|
|
|
if (frameset->children[i].url) {
|
|
|
|
nsurl_unref(frameset->children[i].url);
|
|
|
|
frameset->children[i].url = NULL;
|
|
|
|
}
|
2018-05-10 13:34:26 +03:00
|
|
|
if (frameset->children[i].children)
|
|
|
|
html_destroy_frameset(&frameset->children[i]);
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
2012-10-03 23:48:53 +04:00
|
|
|
talloc_free(frameset->children);
|
2012-03-24 21:11:17 +04:00
|
|
|
frameset->children = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void html_destroy_iframe(struct content_html_iframe *iframe)
|
|
|
|
{
|
|
|
|
struct content_html_iframe *next;
|
|
|
|
next = iframe;
|
|
|
|
while ((iframe = next) != NULL) {
|
|
|
|
next = iframe->next;
|
|
|
|
if (iframe->name)
|
2012-10-03 23:48:53 +04:00
|
|
|
talloc_free(iframe->name);
|
2012-03-24 21:11:17 +04:00
|
|
|
if (iframe->url) {
|
|
|
|
nsurl_unref(iframe->url);
|
|
|
|
iframe->url = NULL;
|
|
|
|
}
|
2012-10-03 23:48:53 +04:00
|
|
|
talloc_free(iframe);
|
2012-10-03 22:24:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void html_free_layout(html_content *htmlc)
|
|
|
|
{
|
|
|
|
if (htmlc->bctx != NULL) {
|
|
|
|
/* freeing talloc context should let the entire box
|
2018-05-10 13:34:26 +03:00
|
|
|
* set be destroyed
|
2012-10-03 22:24:58 +04:00
|
|
|
*/
|
|
|
|
talloc_free(htmlc->bctx);
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-07-07 21:50:04 +04:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_HTML and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
static void html_destroy(struct content *c)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *html = (html_content *) c;
|
2009-02-20 14:39:25 +03:00
|
|
|
struct form *f, *g;
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "content %p", c);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2019-08-23 23:58:07 +03:00
|
|
|
/* If we're still converting a layout, cancel it */
|
|
|
|
if (html->box_conversion_context != NULL) {
|
|
|
|
if (cancel_dom_to_box(html->box_conversion_context) != NSERROR_OK) {
|
|
|
|
NSLOG(netsurf, CRITICAL, "WARNING, Unable to cancel conversion context, browser may crash");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
/* Destroy forms */
|
2010-04-11 21:20:07 +04:00
|
|
|
for (f = html->forms; f != NULL; f = g) {
|
2009-02-20 14:39:25 +03:00
|
|
|
g = f->prev;
|
|
|
|
|
|
|
|
form_free(f);
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
imagemap_destroy(html);
|
2004-03-27 01:16:31 +03:00
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
if (c->refresh)
|
|
|
|
nsurl_unref(c->refresh);
|
|
|
|
|
|
|
|
if (html->base_url)
|
|
|
|
nsurl_unref(html->base_url);
|
|
|
|
|
2020-03-22 13:00:29 +03:00
|
|
|
/* At this point we can be moderately confident the JS is offline
|
|
|
|
* so we destroy the JS thread.
|
|
|
|
*/
|
|
|
|
if (html->jsthread != NULL) {
|
|
|
|
js_destroythread(html->jsthread);
|
|
|
|
html->jsthread = NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-14 03:33:15 +04:00
|
|
|
if (html->parser != NULL) {
|
|
|
|
dom_hubbub_parser_destroy(html->parser);
|
|
|
|
html->parser = NULL;
|
2012-07-07 03:28:45 +04:00
|
|
|
}
|
2004-02-20 03:43:17 +03:00
|
|
|
|
2012-07-14 03:33:15 +04:00
|
|
|
if (html->document != NULL) {
|
|
|
|
dom_node_unref(html->document);
|
2013-05-23 18:02:15 +04:00
|
|
|
html->document = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (html->title != NULL) {
|
|
|
|
dom_node_unref(html->title);
|
|
|
|
html->title = NULL;
|
2012-07-14 03:33:15 +04:00
|
|
|
}
|
2008-09-09 01:55:20 +04:00
|
|
|
|
2013-10-23 21:55:51 +04:00
|
|
|
/* Free encoding */
|
|
|
|
if (html->encoding != NULL) {
|
|
|
|
free(html->encoding);
|
|
|
|
html->encoding = NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* Free base target */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->base_target != NULL) {
|
2018-05-10 13:34:26 +03:00
|
|
|
free(html->base_target);
|
|
|
|
html->base_target = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free frameset */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->frameset != NULL) {
|
|
|
|
html_destroy_frameset(html->frameset);
|
2012-10-03 23:48:53 +04:00
|
|
|
talloc_free(html->frameset);
|
2010-04-11 21:20:07 +04:00
|
|
|
html->frameset = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free iframes */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->iframe != NULL) {
|
|
|
|
html_destroy_iframe(html->iframe);
|
|
|
|
html->iframe = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Destroy selection context */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->select_ctx != NULL) {
|
|
|
|
css_select_ctx_destroy(html->select_ctx);
|
|
|
|
html->select_ctx = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2011-10-08 04:21:59 +04:00
|
|
|
if (html->universal != NULL) {
|
|
|
|
lwc_string_unref(html->universal);
|
|
|
|
html->universal = NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/* Free stylesheets */
|
2013-02-24 17:15:05 +04:00
|
|
|
html_css_free_stylesheets(html);
|
2005-01-17 00:32:10 +03:00
|
|
|
|
2012-06-19 13:35:51 +04:00
|
|
|
/* Free scripts */
|
2015-03-09 16:47:12 +03:00
|
|
|
html_script_free(html);
|
2012-06-19 13:35:51 +04:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/* Free objects */
|
2013-02-25 22:24:04 +04:00
|
|
|
html_object_free_objects(html);
|
2012-10-03 22:24:58 +04:00
|
|
|
|
|
|
|
/* free layout */
|
|
|
|
html_free_layout(html);
|
2011-08-20 05:13:51 +04:00
|
|
|
}
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
static nserror html_clone(const struct content *old, struct content **newc)
|
2010-04-04 16:41:19 +04:00
|
|
|
{
|
|
|
|
/** \todo Clone HTML specifics */
|
2010-04-10 16:36:21 +04:00
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
/* In the meantime, we should never be called, as HTML contents
|
|
|
|
* cannot be shared and we're not intending to fix printing's
|
2010-04-10 16:36:21 +04:00
|
|
|
* cloning of documents. */
|
|
|
|
assert(0 && "html_clone should never be called");
|
|
|
|
|
2010-04-04 16:41:19 +04:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-12 02:08:26 +04:00
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
|
2004-08-12 02:08:26 +04:00
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_HTML being opened.
|
|
|
|
*/
|
|
|
|
|
2019-07-10 18:42:52 +03:00
|
|
|
static nserror
|
2012-07-06 23:00:32 +04:00
|
|
|
html_open(struct content *c,
|
2012-03-24 21:11:17 +04:00
|
|
|
struct browser_window *bw,
|
2012-07-06 23:00:32 +04:00
|
|
|
struct content *page,
|
2012-03-24 21:11:17 +04:00
|
|
|
struct object_params *params)
|
2004-08-12 02:08:26 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *html = (html_content *) c;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
html->bw = bw;
|
|
|
|
html->page = (html_content *) page;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
html->drag_type = HTML_DRAG_NONE;
|
|
|
|
html->drag_owner.no_owner = true;
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/* text selection */
|
2018-01-04 02:58:18 +03:00
|
|
|
selection_init(&html->sel, html->layout, &html->len_ctx);
|
2013-02-22 16:19:35 +04:00
|
|
|
html->selection_type = HTML_SELECTION_NONE;
|
|
|
|
html->selection_owner.none = true;
|
2011-07-01 15:16:43 +04:00
|
|
|
|
2013-02-25 22:24:04 +04:00
|
|
|
html_object_open_objects(html, bw);
|
2019-07-10 18:42:52 +03:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2004-08-12 02:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_HTML being closed.
|
|
|
|
*/
|
|
|
|
|
2019-07-10 18:42:52 +03:00
|
|
|
static nserror html_close(struct content *c)
|
2004-08-12 02:08:26 +04:00
|
|
|
{
|
2015-03-09 16:47:12 +03:00
|
|
|
html_content *htmlc = (html_content *) c;
|
2020-03-22 13:18:30 +03:00
|
|
|
nserror ret = NSERROR_OK;
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2015-03-09 16:47:12 +03:00
|
|
|
selection_clear(&htmlc->sel, false);
|
2013-02-22 16:19:35 +04:00
|
|
|
|
2015-03-09 16:47:12 +03:00
|
|
|
if (htmlc->search != NULL) {
|
|
|
|
search_destroy_context(htmlc->search);
|
|
|
|
}
|
2011-08-24 16:29:30 +04:00
|
|
|
|
2015-03-06 20:09:50 +03:00
|
|
|
/* clear the html content reference to the browser window */
|
2015-03-09 16:47:12 +03:00
|
|
|
htmlc->bw = NULL;
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2015-03-09 16:47:12 +03:00
|
|
|
/* remove all object references from the html content */
|
|
|
|
html_object_close_objects(htmlc);
|
2019-07-10 18:42:52 +03:00
|
|
|
|
2020-03-22 13:18:30 +03:00
|
|
|
if (htmlc->jsthread != NULL) {
|
|
|
|
/* Close, but do not destroy (yet) the JS thread */
|
|
|
|
ret = js_closethread(htmlc->jsthread);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2004-08-12 02:08:26 +04:00
|
|
|
}
|
2007-01-25 02:16:02 +03:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an HTML content's selection context
|
|
|
|
*/
|
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
static void html_clear_selection(struct content *c)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
switch (html->selection_type) {
|
|
|
|
case HTML_SELECTION_NONE:
|
|
|
|
/* Nothing to do */
|
|
|
|
assert(html->selection_owner.none == true);
|
|
|
|
break;
|
|
|
|
case HTML_SELECTION_TEXTAREA:
|
|
|
|
textarea_clear_selection(html->selection_owner.textarea->
|
|
|
|
gadget->data.text.ta);
|
|
|
|
break;
|
|
|
|
case HTML_SELECTION_SELF:
|
|
|
|
assert(html->selection_owner.none == false);
|
|
|
|
selection_clear(&html->sel, true);
|
|
|
|
break;
|
|
|
|
case HTML_SELECTION_CONTENT:
|
|
|
|
content_clear_selection(html->selection_owner.content->object);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There is no selection now. */
|
|
|
|
html->selection_type = HTML_SELECTION_NONE;
|
|
|
|
html->selection_owner.none = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an HTML content's selection context
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *html_get_selection(struct content *c)
|
2011-07-13 17:20:26 +04:00
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
switch (html->selection_type) {
|
|
|
|
case HTML_SELECTION_TEXTAREA:
|
|
|
|
return textarea_get_selection(html->selection_owner.textarea->
|
|
|
|
gadget->data.text.ta);
|
|
|
|
case HTML_SELECTION_SELF:
|
|
|
|
assert(html->selection_owner.none == false);
|
|
|
|
return selection_get_copy(&html->sel);
|
|
|
|
case HTML_SELECTION_CONTENT:
|
|
|
|
return content_get_selection(
|
|
|
|
html->selection_owner.content->object);
|
|
|
|
case HTML_SELECTION_NONE:
|
|
|
|
/* Nothing to do */
|
|
|
|
assert(html->selection_owner.none == true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2011-07-13 17:20:26 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 16:29:30 +04:00
|
|
|
|
2011-09-06 22:08:18 +04:00
|
|
|
/**
|
|
|
|
* Get access to any content, link URLs and objects (images) currently
|
|
|
|
* at the given (x, y) coordinates.
|
|
|
|
*
|
2014-11-02 18:46:42 +03:00
|
|
|
* \param[in] c html content to look inside
|
|
|
|
* \param[in] x x-coordinate of point of interest
|
|
|
|
* \param[in] y y-coordinate of point of interest
|
|
|
|
* \param[out] data Positional features struct to be updated with any
|
|
|
|
* relevent content, or set to NULL if none.
|
|
|
|
* \return NSERROR_OK on success else appropriate error code.
|
2011-09-06 22:08:18 +04:00
|
|
|
*/
|
2014-11-02 18:46:42 +03:00
|
|
|
static nserror
|
|
|
|
html_get_contextual_content(struct content *c, int x, int y,
|
|
|
|
struct browser_window_features *data)
|
2011-09-06 22:08:18 +04:00
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
struct box *box = html->layout;
|
|
|
|
struct box *next;
|
|
|
|
int box_x = 0, box_y = 0;
|
|
|
|
|
2018-01-04 02:58:18 +03:00
|
|
|
while ((next = box_at_point(&html->len_ctx, box, x, y,
|
|
|
|
&box_x, &box_y)) != NULL) {
|
2011-09-06 22:08:18 +04:00
|
|
|
box = next;
|
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
/* hidden boxes are ignored */
|
|
|
|
if ((box->style != NULL) &&
|
|
|
|
css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) {
|
2011-09-06 22:08:18 +04:00
|
|
|
continue;
|
2014-11-02 18:46:42 +03:00
|
|
|
}
|
2011-09-06 22:08:18 +04:00
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
if (box->iframe) {
|
2019-08-04 16:23:48 +03:00
|
|
|
float scale = browser_window_get_scale(box->iframe);
|
|
|
|
browser_window_get_features(box->iframe,
|
|
|
|
(x - box_x) * scale,
|
|
|
|
(y - box_y) * scale,
|
|
|
|
data);
|
2014-11-02 18:46:42 +03:00
|
|
|
}
|
2011-09-06 22:08:18 +04:00
|
|
|
|
2012-08-21 18:27:52 +04:00
|
|
|
if (box->object)
|
|
|
|
content_get_contextual_content(box->object,
|
|
|
|
x - box_x, y - box_y, data);
|
|
|
|
|
2011-09-06 22:08:18 +04:00
|
|
|
if (box->object)
|
|
|
|
data->object = box->object;
|
|
|
|
|
|
|
|
if (box->href)
|
2014-11-02 18:46:42 +03:00
|
|
|
data->link = box->href;
|
2011-09-06 22:08:18 +04:00
|
|
|
|
|
|
|
if (box->usemap) {
|
|
|
|
const char *target = NULL;
|
2012-11-22 21:40:20 +04:00
|
|
|
nsurl *url = imagemap_get(html, box->usemap, box_x,
|
|
|
|
box_y, x, y, &target);
|
|
|
|
/* Box might have imagemap, but no actual link area
|
|
|
|
* at point */
|
|
|
|
if (url != NULL)
|
2014-11-02 18:46:42 +03:00
|
|
|
data->link = url;
|
2011-09-06 22:08:18 +04:00
|
|
|
}
|
2012-08-21 01:02:37 +04:00
|
|
|
if (box->gadget) {
|
|
|
|
switch (box->gadget->type) {
|
|
|
|
case GADGET_TEXTBOX:
|
|
|
|
case GADGET_TEXTAREA:
|
|
|
|
case GADGET_PASSWORD:
|
|
|
|
data->form_features = CTX_FORM_TEXT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GADGET_FILE:
|
|
|
|
data->form_features = CTX_FORM_FILE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
data->form_features = CTX_FORM_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-09-06 22:08:18 +04:00
|
|
|
}
|
2014-11-02 18:46:42 +03:00
|
|
|
return NSERROR_OK;
|
2011-09-06 22:08:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-29 21:47:29 +04:00
|
|
|
/**
|
|
|
|
* Scroll deepest thing within the content which can be scrolled at given point
|
|
|
|
*
|
|
|
|
* \param c html content to look inside
|
|
|
|
* \param x x-coordinate of point of interest
|
|
|
|
* \param y y-coordinate of point of interest
|
2013-02-08 19:10:39 +04:00
|
|
|
* \param scrx number of px try to scroll something in x direction
|
|
|
|
* \param scry number of px try to scroll something in y direction
|
2011-11-29 21:47:29 +04:00
|
|
|
* \return true iff scroll was consumed by something in the content
|
|
|
|
*/
|
2012-07-06 23:00:32 +04:00
|
|
|
static bool
|
2012-03-24 21:11:17 +04:00
|
|
|
html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
|
2011-11-29 21:47:29 +04:00
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
struct box *box = html->layout;
|
|
|
|
struct box *next;
|
|
|
|
int box_x = 0, box_y = 0;
|
|
|
|
bool handled_scroll = false;
|
|
|
|
|
|
|
|
/* TODO: invert order; visit deepest box first */
|
|
|
|
|
2018-01-04 02:58:18 +03:00
|
|
|
while ((next = box_at_point(&html->len_ctx, box, x, y,
|
|
|
|
&box_x, &box_y)) != NULL) {
|
2011-11-29 21:47:29 +04:00
|
|
|
box = next;
|
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
if (box->style && css_computed_visibility(box->style) ==
|
2011-11-29 21:47:29 +04:00
|
|
|
CSS_VISIBILITY_HIDDEN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Pass into iframe */
|
2019-08-04 16:23:48 +03:00
|
|
|
if (box->iframe) {
|
|
|
|
float scale = browser_window_get_scale(box->iframe);
|
|
|
|
|
|
|
|
if (browser_window_scroll_at_point(box->iframe,
|
|
|
|
(x - box_x) * scale,
|
|
|
|
(y - box_y) * scale,
|
|
|
|
scrx, scry) == true)
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-08 19:26:24 +04:00
|
|
|
|
|
|
|
/* Pass into textarea widget */
|
|
|
|
if (box->gadget && (box->gadget->type == GADGET_TEXTAREA ||
|
|
|
|
box->gadget->type == GADGET_PASSWORD ||
|
|
|
|
box->gadget->type == GADGET_TEXTBOX) &&
|
|
|
|
textarea_scroll(box->gadget->data.text.ta,
|
|
|
|
scrx, scry) == true)
|
2011-11-29 21:47:29 +04:00
|
|
|
return true;
|
|
|
|
|
2012-08-21 18:27:52 +04:00
|
|
|
/* Pass into object */
|
|
|
|
if (box->object != NULL && content_scroll_at_point(
|
|
|
|
box->object, x - box_x, y - box_y,
|
|
|
|
scrx, scry) == true)
|
|
|
|
return true;
|
|
|
|
|
2011-11-29 21:47:29 +04:00
|
|
|
/* Handle box scrollbars */
|
|
|
|
if (box->scroll_y && scrollbar_scroll(box->scroll_y, scry))
|
|
|
|
handled_scroll = true;
|
|
|
|
|
|
|
|
if (box->scroll_x && scrollbar_scroll(box->scroll_x, scrx))
|
|
|
|
handled_scroll = true;
|
|
|
|
|
|
|
|
if (handled_scroll == true)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-04 20:30:52 +04:00
|
|
|
/** Helper for file gadgets to store their filename unencoded on the
|
|
|
|
* dom node associated with the gadget.
|
|
|
|
*
|
|
|
|
* \todo Get rid of this crap eventually
|
|
|
|
*/
|
|
|
|
static void html__dom_user_data_handler(dom_node_operation operation,
|
|
|
|
dom_string *key, void *_data, struct dom_node *src,
|
|
|
|
struct dom_node *dst)
|
|
|
|
{
|
|
|
|
char *oldfile;
|
|
|
|
char *data = (char *)_data;
|
|
|
|
|
2014-01-05 20:14:17 +04:00
|
|
|
if (!dom_string_isequal(corestring_dom___ns_key_file_name_node_data,
|
2014-01-04 20:30:52 +04:00
|
|
|
key) || data == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (operation) {
|
|
|
|
case DOM_NODE_CLONED:
|
|
|
|
if (dom_node_set_user_data(dst,
|
|
|
|
corestring_dom___ns_key_file_name_node_data,
|
|
|
|
strdup(data), html__dom_user_data_handler,
|
|
|
|
&oldfile) == DOM_NO_ERR) {
|
|
|
|
if (oldfile != NULL)
|
|
|
|
free(oldfile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_RENAMED:
|
|
|
|
case DOM_NODE_IMPORTED:
|
|
|
|
case DOM_NODE_ADOPTED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_DELETED:
|
|
|
|
free(data);
|
|
|
|
break;
|
|
|
|
default:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "User data operation not handled.");
|
2014-01-04 20:30:52 +04:00
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2011-11-29 21:47:29 +04:00
|
|
|
|
2014-01-05 20:04:35 +04:00
|
|
|
static void html__set_file_gadget_filename(struct content *c,
|
|
|
|
struct form_control *gadget, const char *fn)
|
|
|
|
{
|
2014-01-29 01:40:13 +04:00
|
|
|
nserror ret;
|
2014-01-05 20:04:35 +04:00
|
|
|
char *utf8_fn, *oldfile = NULL;
|
|
|
|
html_content *html = (html_content *)c;
|
|
|
|
struct box *file_box = gadget->box;
|
2014-03-11 02:19:23 +04:00
|
|
|
|
|
|
|
ret = guit->utf8->local_to_utf8(fn, 0, &utf8_fn);
|
2014-01-29 01:40:13 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
assert(ret != NSERROR_BAD_ENCODING);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"utf8 to local encoding conversion failed");
|
2014-01-05 20:04:35 +04:00
|
|
|
/* Load was for us - just no memory */
|
2018-05-10 13:34:26 +03:00
|
|
|
return;
|
2014-01-05 20:04:35 +04:00
|
|
|
}
|
2018-05-10 13:34:26 +03:00
|
|
|
|
2014-02-08 21:11:55 +04:00
|
|
|
form_gadget_update_value(gadget, utf8_fn);
|
2014-01-05 20:04:35 +04:00
|
|
|
|
|
|
|
/* corestring_dom___ns_key_file_name_node_data */
|
|
|
|
if (dom_node_set_user_data((dom_node *)file_box->gadget->node,
|
|
|
|
corestring_dom___ns_key_file_name_node_data,
|
|
|
|
strdup(fn), html__dom_user_data_handler,
|
|
|
|
&oldfile) == DOM_NO_ERR) {
|
|
|
|
if (oldfile != NULL)
|
|
|
|
free(oldfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw box. */
|
2018-05-10 13:34:26 +03:00
|
|
|
html__redraw_a_box(html, file_box);
|
2014-01-05 20:04:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void html_set_file_gadget_filename(struct hlcache_handle *hl,
|
|
|
|
struct form_control *gadget, const char *fn)
|
|
|
|
{
|
|
|
|
return html__set_file_gadget_filename(hlcache_handle_get_content(hl),
|
|
|
|
gadget, fn);
|
|
|
|
}
|
|
|
|
|
2011-12-02 01:49:57 +04:00
|
|
|
/**
|
2012-08-20 15:12:10 +04:00
|
|
|
* Drop a file onto a content at a particular point, or determine if a file
|
|
|
|
* may be dropped onto the content at given point.
|
2011-12-02 01:49:57 +04:00
|
|
|
*
|
|
|
|
* \param c html content to look inside
|
|
|
|
* \param x x-coordinate of point of interest
|
|
|
|
* \param y y-coordinate of point of interest
|
2012-08-20 15:12:10 +04:00
|
|
|
* \param file path to file to be dropped, or NULL to know if drop allowed
|
|
|
|
* \return true iff file drop has been handled, or if drop possible (NULL file)
|
2011-12-02 01:49:57 +04:00
|
|
|
*/
|
2012-03-24 21:11:17 +04:00
|
|
|
static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
|
2011-12-02 01:49:57 +04:00
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
struct box *box = html->layout;
|
|
|
|
struct box *next;
|
|
|
|
struct box *file_box = NULL;
|
|
|
|
struct box *text_box = NULL;
|
|
|
|
int box_x = 0, box_y = 0;
|
|
|
|
|
|
|
|
/* Scan box tree for boxes that can handle drop */
|
2018-01-04 02:58:18 +03:00
|
|
|
while ((next = box_at_point(&html->len_ctx, box, x, y,
|
|
|
|
&box_x, &box_y)) != NULL) {
|
2011-12-02 01:49:57 +04:00
|
|
|
box = next;
|
|
|
|
|
2019-08-04 16:23:48 +03:00
|
|
|
if (box->style &&
|
|
|
|
css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
|
2011-12-02 01:49:57 +04:00
|
|
|
continue;
|
|
|
|
|
2019-08-04 16:23:48 +03:00
|
|
|
if (box->iframe) {
|
|
|
|
float scale = browser_window_get_scale(box->iframe);
|
|
|
|
return browser_window_drop_file_at_point(
|
|
|
|
box->iframe,
|
|
|
|
(x - box_x) * scale,
|
|
|
|
(y - box_y) * scale,
|
|
|
|
file);
|
|
|
|
}
|
2011-12-02 03:52:45 +04:00
|
|
|
|
2019-08-04 16:23:48 +03:00
|
|
|
if (box->object &&
|
|
|
|
content_drop_file_at_point(box->object,
|
2012-08-21 18:27:52 +04:00
|
|
|
x - box_x, y - box_y, file) == true)
|
|
|
|
return true;
|
|
|
|
|
2011-12-02 01:49:57 +04:00
|
|
|
if (box->gadget) {
|
|
|
|
switch (box->gadget->type) {
|
|
|
|
case GADGET_FILE:
|
|
|
|
file_box = box;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GADGET_TEXTBOX:
|
|
|
|
case GADGET_TEXTAREA:
|
|
|
|
case GADGET_PASSWORD:
|
|
|
|
text_box = box;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* appease compiler */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file_box && !text_box)
|
|
|
|
/* No box capable of handling drop */
|
|
|
|
return false;
|
|
|
|
|
2012-08-20 15:12:10 +04:00
|
|
|
if (file == NULL)
|
|
|
|
/* There is a box capable of handling drop here */
|
|
|
|
return true;
|
|
|
|
|
2011-12-02 01:49:57 +04:00
|
|
|
/* Handle the drop */
|
|
|
|
if (file_box) {
|
|
|
|
/* File dropped on file input */
|
2014-03-11 02:25:36 +04:00
|
|
|
html__set_file_gadget_filename(c, file_box->gadget, file);
|
2011-12-02 01:49:57 +04:00
|
|
|
|
2013-02-08 20:05:44 +04:00
|
|
|
} else {
|
2011-12-02 01:49:57 +04:00
|
|
|
/* File dropped on text input */
|
|
|
|
|
|
|
|
size_t file_len;
|
|
|
|
FILE *fp = NULL;
|
|
|
|
char *buffer;
|
|
|
|
char *utf8_buff;
|
2014-01-29 01:40:13 +04:00
|
|
|
nserror ret;
|
2011-12-02 01:49:57 +04:00
|
|
|
unsigned int size;
|
2013-02-08 20:05:44 +04:00
|
|
|
int bx, by;
|
2011-12-02 01:49:57 +04:00
|
|
|
|
|
|
|
/* Open file */
|
|
|
|
fp = fopen(file, "rb");
|
|
|
|
if (fp == NULL) {
|
|
|
|
/* Couldn't open file, but drop was for us */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get filesize */
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
file_len = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
|
2015-04-26 02:32:42 +03:00
|
|
|
if ((long)file_len == -1) {
|
|
|
|
/* unable to get file length, but drop was for us */
|
|
|
|
fclose(fp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-02 01:49:57 +04:00
|
|
|
/* Allocate buffer for file data */
|
|
|
|
buffer = malloc(file_len + 1);
|
|
|
|
if (buffer == NULL) {
|
|
|
|
/* No memory, but drop was for us */
|
|
|
|
fclose(fp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stick file into buffer */
|
|
|
|
if (file_len != fread(buffer, 1, file_len, fp)) {
|
|
|
|
/* Failed, but drop was for us */
|
|
|
|
free(buffer);
|
|
|
|
fclose(fp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done with file */
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* Ensure buffer's string termination */
|
|
|
|
buffer[file_len] = '\0';
|
|
|
|
|
|
|
|
/* TODO: Sniff for text? */
|
|
|
|
|
|
|
|
/* Convert to UTF-8 */
|
2014-02-02 02:17:36 +04:00
|
|
|
ret = guit->utf8->local_to_utf8(buffer, file_len, &utf8_buff);
|
2014-01-29 01:40:13 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
2011-12-02 01:49:57 +04:00
|
|
|
/* bad encoding shouldn't happen */
|
2019-11-08 00:35:24 +03:00
|
|
|
NSLOG(netsurf, ERROR,
|
|
|
|
"local to utf8 encoding failed (%s)",
|
|
|
|
messages_get_errorcode(ret));
|
2014-01-29 01:40:13 +04:00
|
|
|
assert(ret != NSERROR_BAD_ENCODING);
|
2011-12-02 01:49:57 +04:00
|
|
|
free(buffer);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done with buffer */
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
/* Get new length */
|
|
|
|
size = strlen(utf8_buff);
|
|
|
|
|
|
|
|
/* Simulate a click over the input box, to place caret */
|
2013-02-08 20:05:44 +04:00
|
|
|
box_coords(text_box, &bx, &by);
|
|
|
|
textarea_mouse_action(text_box->gadget->data.text.ta,
|
|
|
|
BROWSER_MOUSE_PRESS_1, x - bx, y - by);
|
2011-12-02 03:52:45 +04:00
|
|
|
|
2011-12-02 01:49:57 +04:00
|
|
|
/* Paste the file as text */
|
2013-02-08 20:05:44 +04:00
|
|
|
textarea_drop_text(text_box->gadget->data.text.ta,
|
|
|
|
utf8_buff, size);
|
2011-12-02 01:49:57 +04:00
|
|
|
|
|
|
|
free(utf8_buff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-07 01:51:46 +03:00
|
|
|
/**
|
|
|
|
* set debug status.
|
|
|
|
*
|
|
|
|
* \param c The content to debug
|
|
|
|
* \param op The debug operation type
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
html_debug(struct content *c, enum content_debug op)
|
|
|
|
{
|
|
|
|
html_redraw_debug = !html_redraw_debug;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-20 19:04:44 +04:00
|
|
|
/**
|
|
|
|
* Dump debug info concerning the html_content
|
|
|
|
*
|
2014-11-07 01:51:46 +03:00
|
|
|
* \param c The content to debug
|
2014-08-04 03:36:14 +04:00
|
|
|
* \param f The file to dump to
|
2014-11-07 01:51:46 +03:00
|
|
|
* \param op The debug dump type
|
2012-08-20 19:04:44 +04:00
|
|
|
*/
|
2014-08-04 03:36:14 +04:00
|
|
|
static nserror
|
|
|
|
html_debug_dump(struct content *c, FILE *f, enum content_debug op)
|
2012-08-20 19:04:44 +04:00
|
|
|
{
|
2014-08-04 03:36:14 +04:00
|
|
|
html_content *htmlc = (html_content *)c;
|
|
|
|
dom_node *html;
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
nserror ret;
|
|
|
|
|
|
|
|
assert(htmlc != NULL);
|
2012-08-20 19:04:44 +04:00
|
|
|
|
2014-08-04 03:36:14 +04:00
|
|
|
if (op == CONTENT_DEBUG_RENDER) {
|
|
|
|
assert(htmlc->layout != NULL);
|
|
|
|
box_dump(f, htmlc->layout, 0, true);
|
|
|
|
ret = NSERROR_OK;
|
|
|
|
} else {
|
|
|
|
if (htmlc->document == NULL) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "No document to dump");
|
2014-08-04 03:36:14 +04:00
|
|
|
return NSERROR_DOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_document_get_document_element(htmlc->document, (void *) &html);
|
|
|
|
if ((exc != DOM_NO_ERR) || (html == NULL)) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Unable to obtain root node");
|
2014-08-04 03:36:14 +04:00
|
|
|
return NSERROR_DOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = libdom_dump_structure(html, f, 0);
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "DOM structure dump returning %d", ret);
|
2014-08-04 03:36:14 +04:00
|
|
|
|
|
|
|
dom_node_unref(html);
|
|
|
|
}
|
2012-08-20 19:04:44 +04:00
|
|
|
|
2014-08-04 03:36:14 +04:00
|
|
|
return ret;
|
2012-08-20 19:04:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 14:56:34 +04:00
|
|
|
#if ALWAYS_DUMP_FRAMESET
|
2007-01-25 02:16:02 +03:00
|
|
|
/**
|
|
|
|
* Print a frameset tree to stderr.
|
|
|
|
*/
|
|
|
|
|
2012-07-06 23:00:32 +04:00
|
|
|
static void
|
2012-03-24 21:11:17 +04:00
|
|
|
html_dump_frameset(struct content_html_frames *frame, unsigned int depth)
|
2007-01-25 02:16:02 +03:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int row, col, index;
|
|
|
|
const char *unit[] = {"px", "%", "*"};
|
|
|
|
const char *scrolling[] = {"auto", "yes", "no"};
|
|
|
|
|
|
|
|
assert(frame);
|
|
|
|
|
|
|
|
fprintf(stderr, "%p ", frame);
|
|
|
|
|
|
|
|
fprintf(stderr, "(%i %i) ", frame->rows, frame->cols);
|
|
|
|
|
|
|
|
fprintf(stderr, "w%g%s ", frame->width.value, unit[frame->width.unit]);
|
|
|
|
fprintf(stderr, "h%g%s ", frame->height.value,unit[frame->height.unit]);
|
|
|
|
fprintf(stderr, "(margin w%i h%i) ",
|
|
|
|
frame->margin_width, frame->margin_height);
|
|
|
|
|
|
|
|
if (frame->name)
|
|
|
|
fprintf(stderr, "'%s' ", frame->name);
|
|
|
|
if (frame->url)
|
|
|
|
fprintf(stderr, "<%s> ", frame->url);
|
|
|
|
|
|
|
|
if (frame->no_resize)
|
|
|
|
fprintf(stderr, "noresize ");
|
|
|
|
fprintf(stderr, "(scrolling %s) ", scrolling[frame->scrolling]);
|
|
|
|
if (frame->border)
|
|
|
|
fprintf(stderr, "border %x ",
|
|
|
|
(unsigned int) frame->border_colour);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
if (frame->children) {
|
|
|
|
for (row = 0; row != frame->rows; row++) {
|
|
|
|
for (col = 0; col != frame->cols; col++) {
|
|
|
|
for (i = 0; i != depth; i++)
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
fprintf(stderr, "(%i %i): ", row, col);
|
|
|
|
index = (row * frame->cols) + col;
|
|
|
|
html_dump_frameset(&frame->children[index],
|
|
|
|
depth + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-10 14:56:34 +04:00
|
|
|
|
|
|
|
#endif
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve HTML document tree
|
|
|
|
*
|
|
|
|
* \param h HTML content to retrieve document tree from
|
|
|
|
* \return Pointer to document tree
|
|
|
|
*/
|
2012-03-24 03:18:04 +04:00
|
|
|
dom_document *html_get_document(hlcache_handle *h)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->document;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve box tree
|
|
|
|
*
|
|
|
|
* \param h HTML content to retrieve tree from
|
|
|
|
* \return Pointer to box tree
|
|
|
|
*
|
2018-05-10 13:34:26 +03:00
|
|
|
* \todo This API must die, as must all use of the box tree outside of
|
|
|
|
* HTML content handler
|
2010-03-28 16:56:39 +04:00
|
|
|
*/
|
|
|
|
struct box *html_get_box_tree(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->layout;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the charset of an HTML document
|
|
|
|
*
|
2014-11-06 02:44:31 +03:00
|
|
|
* \param c Content to retrieve charset from
|
2014-11-12 19:21:23 +03:00
|
|
|
* \param op The content encoding operation to perform.
|
2010-03-28 16:56:39 +04:00
|
|
|
* \return Pointer to charset, or NULL
|
|
|
|
*/
|
2014-11-07 15:33:34 +03:00
|
|
|
static const char *html_encoding(const struct content *c, enum content_encoding_type op)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2014-11-06 02:44:31 +03:00
|
|
|
html_content *html = (html_content *) c;
|
2014-11-10 15:02:26 +03:00
|
|
|
static char enc_token[10] = "Encoding0";
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-11-06 02:44:31 +03:00
|
|
|
assert(html != NULL);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-11-07 15:33:34 +03:00
|
|
|
if (op == CONTENT_ENCODING_SOURCE) {
|
|
|
|
enc_token[8] = '0' + html->encoding_source;
|
|
|
|
return messages_get(enc_token);
|
|
|
|
}
|
|
|
|
|
2014-11-06 02:44:31 +03:00
|
|
|
return html->encoding;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2010-04-07 17:12:27 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
|
|
|
* Retrieve framesets used in an HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to inspect
|
|
|
|
* \return Pointer to framesets, or NULL if none
|
|
|
|
*/
|
|
|
|
struct content_html_frames *html_get_frameset(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->frameset;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve iframes used in an HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to inspect
|
|
|
|
* \return Pointer to iframes, or NULL if none
|
|
|
|
*/
|
|
|
|
struct content_html_iframe *html_get_iframe(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->iframe;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve an HTML content's base URL
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve base target from
|
|
|
|
* \return Pointer to URL
|
|
|
|
*/
|
2011-10-03 19:56:47 +04:00
|
|
|
nsurl *html_get_base_url(hlcache_handle *h)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->base_url;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve an HTML content's base target
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve base target from
|
|
|
|
* \return Pointer to target, or NULL if none
|
|
|
|
*/
|
|
|
|
const char *html_get_base_target(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->base_target;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
/**
|
|
|
|
* Retrieve layout coordinates of box with given id
|
|
|
|
*
|
|
|
|
* \param h HTML document to search
|
|
|
|
* \param frag_id String containing an element id
|
|
|
|
* \param x Updated to global x coord iff id found
|
|
|
|
* \param y Updated to global y coord iff id found
|
|
|
|
* \return true iff id found
|
|
|
|
*/
|
2011-10-29 15:37:05 +04:00
|
|
|
bool html_get_id_offset(hlcache_handle *h, lwc_string *frag_id, int *x, int *y)
|
2010-06-04 13:35:08 +04:00
|
|
|
{
|
|
|
|
struct box *pos;
|
2010-10-11 10:54:37 +04:00
|
|
|
struct box *layout;
|
2010-06-04 13:35:08 +04:00
|
|
|
|
|
|
|
if (content_get_type(h) != CONTENT_HTML)
|
|
|
|
return false;
|
|
|
|
|
2010-10-11 10:54:37 +04:00
|
|
|
layout = html_get_box_tree(h);
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
if ((pos = box_find_by_id(layout, frag_id)) != 0) {
|
|
|
|
box_coords(pos, x, y);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2020-04-18 00:43:44 +03:00
|
|
|
bool html_exec(struct content *c, const char *src, size_t srclen)
|
2019-05-05 17:38:20 +03:00
|
|
|
{
|
|
|
|
html_content *htmlc = (html_content *)c;
|
|
|
|
bool result = false;
|
|
|
|
dom_exception err;
|
|
|
|
dom_html_body_element *body_node;
|
|
|
|
dom_string *dom_src;
|
|
|
|
dom_text *text_node;
|
|
|
|
dom_node *spare_node;
|
|
|
|
dom_html_script_element *script_node;
|
2019-05-05 23:05:27 +03:00
|
|
|
|
2019-05-05 17:38:20 +03:00
|
|
|
if (htmlc->document == NULL) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to exec, no document");
|
|
|
|
goto out_no_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_string_create((const uint8_t *)src, srclen, &dom_src);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create string");
|
|
|
|
goto out_no_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_html_document_get_body(htmlc->document, &body_node);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to retrieve body element");
|
|
|
|
goto out_no_body;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_document_create_text_node(htmlc->document, dom_src, &text_node);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create text node");
|
|
|
|
goto out_no_text_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_document_create_element(htmlc->document, corestring_dom_SCRIPT, &script_node);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create script node");
|
|
|
|
goto out_no_script_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_node_append_child(script_node, text_node, &spare_node);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not insert code node into script node");
|
|
|
|
goto out_unparented;
|
|
|
|
}
|
|
|
|
dom_node_unref(spare_node); /* We do not need the spare ref at all */
|
|
|
|
|
|
|
|
err = dom_node_append_child(body_node, script_node, &spare_node);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not insert script node into document body");
|
|
|
|
goto out_unparented;
|
|
|
|
}
|
|
|
|
dom_node_unref(spare_node); /* Again no need for the spare ref */
|
|
|
|
|
|
|
|
/* We successfully inserted the node into the DOM */
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
/* Now we unwind, starting by removing the script from wherever it
|
|
|
|
* ended up parented
|
|
|
|
*/
|
|
|
|
|
|
|
|
err = dom_node_get_parent_node(script_node, &spare_node);
|
|
|
|
if (err == DOM_NO_ERR && spare_node != NULL) {
|
|
|
|
dom_node *second_spare;
|
|
|
|
err = dom_node_remove_child(spare_node, script_node, &second_spare);
|
|
|
|
if (err == DOM_NO_ERR) {
|
|
|
|
dom_node_unref(second_spare);
|
|
|
|
}
|
|
|
|
dom_node_unref(spare_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
out_unparented:
|
|
|
|
dom_node_unref(script_node);
|
|
|
|
out_no_script_node:
|
|
|
|
dom_node_unref(text_node);
|
|
|
|
out_no_text_node:
|
|
|
|
dom_node_unref(body_node);
|
|
|
|
out_no_body:
|
|
|
|
dom_string_unref(dom_src);
|
|
|
|
out_no_string:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-12-01 18:49:08 +03:00
|
|
|
/* See \ref content_saw_insecure_objects */
|
|
|
|
static bool
|
|
|
|
html_saw_insecure_objects(struct content *c)
|
|
|
|
{
|
|
|
|
html_content *htmlc = (html_content *)c;
|
|
|
|
struct content_html_object *obj = htmlc->object_list;
|
|
|
|
|
|
|
|
/* Check through the object list */
|
|
|
|
while (obj != NULL) {
|
|
|
|
if (obj->content != NULL) {
|
|
|
|
if (content_saw_insecure_objects(obj->content))
|
|
|
|
return true;
|
|
|
|
}
|
2019-12-01 20:04:39 +03:00
|
|
|
obj = obj->next;
|
2019-12-01 18:49:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now check the script list */
|
|
|
|
if (html_saw_insecure_scripts(htmlc)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now check stylesheets */
|
|
|
|
if (html_saw_insecure_stylesheets(htmlc)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
/**
|
|
|
|
* Compute the type of a content
|
|
|
|
*
|
|
|
|
* \return CONTENT_HTML
|
|
|
|
*/
|
2012-03-24 21:11:17 +04:00
|
|
|
static content_type html_content_type(void)
|
2011-05-07 00:40:09 +04:00
|
|
|
{
|
|
|
|
return CONTENT_HTML;
|
|
|
|
}
|
|
|
|
|
2012-03-24 21:11:17 +04:00
|
|
|
|
|
|
|
static void html_fini(void)
|
|
|
|
{
|
2013-02-24 17:15:05 +04:00
|
|
|
html_css_fini();
|
2012-03-24 21:11:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const content_handler html_content_handler = {
|
|
|
|
.fini = html_fini,
|
|
|
|
.create = html_create,
|
|
|
|
.process_data = html_process_data,
|
|
|
|
.data_complete = html_convert,
|
|
|
|
.reformat = html_reformat,
|
|
|
|
.destroy = html_destroy,
|
|
|
|
.stop = html_stop,
|
|
|
|
.mouse_track = html_mouse_track,
|
|
|
|
.mouse_action = html_mouse_action,
|
2013-02-22 16:19:35 +04:00
|
|
|
.keypress = html_keypress,
|
2012-03-24 21:11:17 +04:00
|
|
|
.redraw = html_redraw,
|
|
|
|
.open = html_open,
|
|
|
|
.close = html_close,
|
|
|
|
.get_selection = html_get_selection,
|
2013-02-22 16:19:35 +04:00
|
|
|
.clear_selection = html_clear_selection,
|
2012-03-24 21:11:17 +04:00
|
|
|
.get_contextual_content = html_get_contextual_content,
|
|
|
|
.scroll_at_point = html_scroll_at_point,
|
|
|
|
.drop_file_at_point = html_drop_file_at_point,
|
2013-05-07 17:41:40 +04:00
|
|
|
.search = html_search,
|
|
|
|
.search_clear = html_search_clear,
|
2012-08-20 19:04:44 +04:00
|
|
|
.debug_dump = html_debug_dump,
|
2014-11-07 01:51:46 +03:00
|
|
|
.debug = html_debug,
|
2012-03-24 21:11:17 +04:00
|
|
|
.clone = html_clone,
|
2014-11-06 02:44:31 +03:00
|
|
|
.get_encoding = html_encoding,
|
2012-03-24 21:11:17 +04:00
|
|
|
.type = html_content_type,
|
2019-05-05 17:38:20 +03:00
|
|
|
.exec = html_exec,
|
2019-12-01 18:49:08 +03:00
|
|
|
.saw_insecure_objects = html_saw_insecure_objects,
|
2012-03-24 21:11:17 +04:00
|
|
|
.no_share = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
nserror html_init(void)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
nserror error;
|
|
|
|
|
2013-02-24 17:15:05 +04:00
|
|
|
error = html_css_init();
|
2012-03-24 21:11:17 +04:00
|
|
|
if (error != NSERROR_OK)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < NOF_ELEMENTS(html_types); i++) {
|
|
|
|
error = content_factory_register_handler(html_types[i],
|
|
|
|
&html_content_handler);
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
|
|
|
|
error:
|
|
|
|
html_fini();
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
/**
|
|
|
|
* Get the browser window containing an HTML content
|
|
|
|
*
|
|
|
|
* \param c HTML content
|
|
|
|
* \return the browser window
|
|
|
|
*/
|
|
|
|
struct browser_window *html_get_browser_window(struct content *c)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
assert(c->handler == &html_content_handler);
|
|
|
|
|
|
|
|
return html->bw;
|
|
|
|
}
|