NetSurf
content.h
Go to the documentation of this file.
1/*
2 * Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
3 * Copyright 2003 Philip Pemberton <philpem@users.sourceforge.net>
4 *
5 * This file is part of NetSurf, http://www.netsurf-browser.org/
6 *
7 * NetSurf is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * NetSurf is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/**
21 * \file
22 * Content handling interface.
23 *
24 * The content functions manipulate struct contents, which correspond to URLs.
25 */
26
27#ifndef NETSURF_CONTENT_CONTENT_H_
28#define NETSURF_CONTENT_CONTENT_H_
29
30#include <libwapcaplet/libwapcaplet.h>
31
33#include "netsurf/mouse.h" /* mouse state enums */
34#include "netsurf/console.h" /* console state and flags enums */
35
36struct browser_window;
38struct content;
39struct llcache_handle;
40struct hlcache_handle;
41struct object_params;
42struct rect;
43struct redraw_context;
44struct cert_chain;
45
46
47/** RFC5988 metadata link */
49 struct content_rfc5988_link *next; /**< next rfc5988_link in list */
50
51 lwc_string *rel; /**< the link relationship - must be present */
52 struct nsurl *href; /**< the link href - must be present */
53 lwc_string *hreflang;
54 lwc_string *type;
55 lwc_string *media;
56 lwc_string *sizes;
57};
58
59/** Extra data for some content_msg messages. */
61 /**
62 * CONTENT_MSG_LOG - Information for logging
63 */
64 struct {
65 /** The source of the logging */
67 /** The message to log */
68 const char *msg;
69 /** The length of that message */
70 size_t msglen;
71 /** The flags of the logging */
73 } log;
74
75 /**
76 * CONTENT_MSG_SSL_CERTS - The certificate chain from the
77 * underlying fetch
78 */
79 const struct cert_chain *chain;
80
81 /**
82 * CONTENT_MSG_ERROR - Error from content or underlying fetch
83 */
84 struct {
85 /**
86 * The error code to convey meaning
87 */
89 /**
90 * The message. if NSERROR_UNKNOWN then this is the direct
91 * message, otherwise is some kind of metadata (e.g. a
92 * message name or somesuch) but always a null terminated
93 * string.
94 */
95 const char *errormsg;
97
98 /**
99 * CONTENT_MSG_REDIRECT - Redirect info
100 */
101 struct {
102 struct nsurl *from; /**< Redirect origin */
103 struct nsurl *to; /**< Redirect target */
104 } redirect; /**< Fetch URL redirect occured */
105
106 /**
107 * CONTENT_MSG_REDRAW - Area of content which needs redrawing
108 */
109 struct {
110 int x, y, width, height;
112
113 /**
114 * CONTENT_MSG_REFRESH - Minimum delay
115 */
116 int delay;
117
118 /**
119 * CONTENT_MSG_REFORMAT - Reformat should not cause a redraw
120 */
122
123 /**
124 * CONTENT_MSG_STATUS - Status message update. If NULL, the
125 * content's internal status text has been updated, and
126 * listener should use content_get_status_message()
127 */
129
130 /**
131 * CONTENT_MSG_DOWNLOAD - Low-level cache handle
132 */
134
135 /**
136 * CONTENT_MSG_RFC5988_LINK - rfc5988 link data
137 */
139
140 /**
141 * CONTENT_MSG_GETTHREAD - Javascript context (thread)
142 */
144
145 /**
146 * CONTENT_MSG_GETDIMS - Get the viewport dimensions
147 */
148 struct {
149 /** \todo Consider getting screen_width, screen_height too. */
150 unsigned *viewport_width;
153
154 /**
155 * CONTENT_MSG_SCROLL - Part of content to scroll to show
156 */
157 struct {
158 /*
159 * if true, scroll to show area given by (x0, y0) and (x1,y1).
160 * if false, scroll point (x0, y0) to top left of viewport
161 */
162 bool area;
163 int x0, y0;
164 int x1, y1;
166
167 /**
168 * CONTENT_MSG_DRAGSAVE - Drag save a content
169 */
170 struct {
171 enum {
177 /** if NULL, save the content generating the message */
180
181 /**
182 * CONTENT_MSG_SAVELINK - Save a URL
183 */
184 struct {
185 struct nsurl *url;
186 const char *title;
188
189 /**
190 * CONTENT_MSG_POINTER - Mouse pointer to set
191 */
193
194 /**
195 * CONTENT_MSG_SELECTION - Selection made or cleared
196 */
197 struct {
198 bool selection; /**< false for selection cleared */
201
202 /**
203 * CONTENT_MSG_CARET - set caret position or, hide caret
204 */
205 struct {
206 enum {
211 struct {
212 int x; /**< Carret x-coord */
213 int y; /**< Carret y-coord */
214 int height; /**< Carret height */
215 const struct rect *clip; /**< Carret clip rect */
216 } pos; /**< With CONTENT_CARET_SET_POS */
218
219 /**
220 * CONTENT_MSG_DRAG - Drag start or end
221 */
222 struct {
223 enum {
228 const struct rect *rect;
230
231 /**
232 * CONTENT_MSG_SELECTMENU - Create select menu at pointer
233 */
234 struct {
237
238 /**
239 * CONTENT_MSG_GADGETCLICK - User clicked on a form gadget
240 */
241 struct {
242 struct form_control *gadget;
244
245 /**
246 * CONTENT_MSG_TEXTSEARCH - Free text search action
247 */
248 struct {
249 /**
250 * The type of text search operation
251 */
252 enum {
253 /**
254 * Free text search find operation has started or finished
255 */
257 /**
258 * Free text search match state has changed
259 */
261 /**
262 * Free text search back available state changed
263 */
265 /**
266 * Free text search forward available state changed
267 */
269 /**
270 * add a search query string to the recent searches
271 */
274 /**
275 * context passed to browser_window_search()
276 */
277 void *ctx;
278 /**
279 * state for operation
280 */
281 bool state;
282 /**
283 * search string
284 */
285 const char *string;
287
288};
289
290
291/**
292 * Get whether a content can reformat
293 *
294 * \param h content to check
295 * \return whether the content can reformat
296 */
298
299/**
300 * Reformat to new size.
301 *
302 * Calls the reformat function for the content.
303 */
304void content_reformat(struct hlcache_handle *h, bool background,
305 int width, int height);
306
307/**
308 * Request a redraw of an area of a content
309 *
310 * \param h high-level cache handle
311 * \param x x co-ord of left edge
312 * \param y y co-ord of top edge
313 * \param width Width of rectangle
314 * \param height Height of rectangle
315 */
317 int x, int y, int width, int height);
318
319/**
320 * Handle mouse movements in a content window.
321 *
322 * \param h Content handle
323 * \param bw browser window
324 * \param mouse state of mouse buttons and modifier keys
325 * \param x coordinate of mouse
326 * \param y coordinate of mouse
327 */
328void content_mouse_track(struct hlcache_handle *h, struct browser_window *bw,
329 browser_mouse_state mouse, int x, int y);
330
331/**
332 * Handle mouse clicks and movements in a content window.
333 *
334 * \param h Content handle
335 * \param bw browser window
336 * \param mouse state of mouse buttons and modifier keys
337 * \param x coordinate of mouse
338 * \param y coordinate of mouse
339 *
340 * This function handles both hovering and clicking. It is important that the
341 * code path is identical (except that hovering doesn't carry out the action),
342 * so that the status bar reflects exactly what will happen. Having separate
343 * code paths opens the possibility that an attacker will make the status bar
344 * show some harmless action where clicking will be harmful.
345 */
346void content_mouse_action(struct hlcache_handle *h, struct browser_window *bw,
347 browser_mouse_state mouse, int x, int y);
348
349/**
350 * Handle keypresses.
351 *
352 * \param h Content handle
353 * \param key The UCS4 character codepoint
354 * \return true if key handled, false otherwise
355 */
356bool content_keypress(struct hlcache_handle *h, uint32_t key);
357
358
359/**
360 * A window containing the content has been opened.
361 *
362 * \param h handle to content that has been opened
363 * \param bw browser window containing the content
364 * \param page content of type CONTENT_HTML containing h, or NULL if not an
365 * object within a page
366 * \param params object parameters, or NULL if not an object
367 *
368 * Calls the open function for the content.
369 */
371 struct content *page, struct object_params *params);
372
373/**
374 * The window containing the content has been closed.
375 *
376 * Calls the close function for the content.
377 */
379
380/**
381 * Tell a content that any selection it has, or one of its objects
382 * has, must be cleared.
383 */
385
386/**
387 * Get a text selection from a content. Ownership is passed to the caller,
388 * who must free() it.
389 */
390char * content_get_selection(struct hlcache_handle *h);
391
392/**
393 * Get positional contextural information for a content.
394 *
395 * \param[in] h Handle to content to examine.
396 * \param[in] x The x coordinate to examine.
397 * \param[in] y The y coordinate to examine.
398 * \param[out] data The context structure to fill in.
399 */
401 int x, int y, struct browser_window_features *data);
402
403/**
404 * scroll content at coordnate
405 *
406 * \param[in] h Handle to content to examine.
407 * \param[in] x The x coordinate to examine.
408 * \param[in] y The y coordinate to examine.
409 */
411 int x, int y, int scrx, int scry);
412
413/**
414 * Drag and drop a file at coordinate
415 *
416 * \param[in] h Handle to content to examine.
417 * \param[in] x The x coordinate to examine.
418 * \param[in] y The y coordinate to examine.
419 */
421 int x, int y, char *file);
422
423
424/**
425 * Control debug con a content.
426 *
427 * \param h content handle to debug.
428 * \param op Debug operation type.
429 */
431
432
433/**
434 * find link in content that matches the rel string.
435 *
436 * \param h handle to the content to retrieve tyoe of.
437 * \param rel The string to match.
438 * \return A matching rfc5988 link or NULL if none is found.
439 *
440 */
442
443
444/**
445 * Retrieve status of content
446 *
447 * \param h handle to the content to retrieve status from
448 * \return Content status
449 */
451
452
453/**
454 * Retrieve status of content
455 *
456 * \param c Content to retrieve status from.
457 * \return Content status
458 */
460
461
462/**
463 * Retrieve status message associated with content
464 *
465 * \param h handle to the content to retrieve status message from
466 * \return Pointer to status message, or NULL if not found.
467 */
468const char *content_get_status_message(struct hlcache_handle *h);
469
470
471/**
472 * Retrieve available width of content
473 *
474 * \param h handle to the content to get available width of.
475 * \return Available width of content.
476 */
478
479
480/**
481 * Retrieve the refresh URL for a content
482 *
483 * \param h Content to retrieve refresh URL from
484 * \return Pointer to URL, or NULL if none
485 */
487
488
489/**
490 * Determine if a content is opaque from handle
491 *
492 * \param h high level cache handle to retrieve opacity from.
493 * \return false if the content is not opaque or information is not
494 * known else true.
495 */
496bool content_get_opaque(struct hlcache_handle *h);
497
498
499/**
500 * Retrieve quirkiness of a content
501 *
502 * \param h Content to examine
503 * \return True if content is quirky, false otherwise
504 */
505bool content_get_quirks(struct hlcache_handle *h);
506
507
508/**
509 * Return whether a content is currently locked
510 *
511 * \param h handle to the content.
512 * \return true iff locked, else false
513 */
514bool content_is_locked(struct hlcache_handle *h);
515
516
517/**
518 * Execute some JavaScript code inside a content object.
519 *
520 * Runs the passed in JavaScript code in the content object's context.
521 *
522 * \param h The handle to the content
523 * \param src The JavaScript source code
524 * \param srclen The length of the source code
525 * \return Whether the JS function was successfully injected into the content
526 */
527bool content_exec(struct hlcache_handle *h, const char *src, size_t srclen);
528
529/**
530 * Determine if the content referred to any insecure objects.
531 *
532 * Query the content to determine if any of its referred objects were loaded
533 * in a manner not considered secure. For a content to be recursively
534 * secure it must only load over https and must not have certificate overrides
535 * in place.
536 *
537 * \param h The handle to the content
538 * \return Whether the content referred to any insecure objects
539 */
541
542#endif
Browser window console stuff.
browser_window_console_source
Sources of messages which end up in the browser window console.
Definition: console.h:30
browser_window_console_flags
Flags for browser window console logging.
Definition: console.h:41
struct content_rfc5988_link * content_find_rfc5988_link(struct hlcache_handle *h, lwc_string *rel)
find link in content that matches the rel string.
Definition: content.c:954
nserror content_close(struct hlcache_handle *h)
The window containing the content has been closed.
Definition: content.c:813
bool content_get_quirks(struct hlcache_handle *h)
Retrieve quirkiness of a content.
Definition: content.c:1308
bool content_exec(struct hlcache_handle *h, const char *src, size_t srclen)
Execute some JavaScript code inside a content object.
Definition: content.c:477
void content_mouse_track(struct hlcache_handle *h, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle mouse movements in a content window.
Definition: content.c:398
void content_request_redraw(struct hlcache_handle *h, int x, int y, int width, int height)
Request a redraw of an area of a content.
Definition: content.c:450
void content_reformat(struct hlcache_handle *h, bool background, int width, int height)
Reformat to new size.
Definition: content.c:321
bool content_saw_insecure_objects(struct hlcache_handle *h)
Determine if the content referred to any insecure objects.
Definition: content.c:500
bool content_scroll_at_point(struct hlcache_handle *h, int x, int y, int scrx, int scry)
scroll content at coordnate
Definition: content.c:890
bool content_is_locked(struct hlcache_handle *h)
Return whether a content is currently locked.
Definition: content.c:1344
nserror content_get_contextual_content(struct hlcache_handle *h, int x, int y, struct browser_window_features *data)
Get positional contextural information for a content.
Definition: content.c:872
bool content_keypress(struct hlcache_handle *h, uint32_t key)
Handle keypresses.
Definition: content.c:437
int content_get_available_width(struct hlcache_handle *h)
Retrieve available width of content.
Definition: content.c:1192
content_status content__get_status(struct content *c)
Retrieve status of content.
Definition: content.c:1131
void content_clear_selection(struct hlcache_handle *h)
Tell a content that any selection it has, or one of its objects has, must be cleared.
Definition: content.c:847
bool content_get_opaque(struct hlcache_handle *h)
Determine if a content is opaque from handle.
Definition: content.c:1288
struct nsurl * content_get_refresh_url(struct hlcache_handle *h)
Retrieve the refresh URL for a content.
Definition: content.c:1247
const char * content_get_status_message(struct hlcache_handle *h)
Retrieve status message associated with content.
Definition: content.c:1141
void content_mouse_action(struct hlcache_handle *h, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle mouse clicks and movements in a content window.
Definition: content.c:421
bool content_drop_file_at_point(struct hlcache_handle *h, int x, int y, char *file)
Drag and drop a file at coordinate.
Definition: content.c:906
content_status content_get_status(struct hlcache_handle *h)
Retrieve status of content.
Definition: content.c:1124
nserror content_open(struct hlcache_handle *h, struct browser_window *bw, struct content *page, struct object_params *params)
A window containing the content has been opened.
Definition: content.c:791
char * content_get_selection(struct hlcache_handle *h)
Get a text selection from a content.
Definition: content.c:858
nserror content_debug(struct hlcache_handle *h, enum content_debug op)
Control debug con a content.
Definition: content.c:936
bool content_can_reformat(struct hlcache_handle *h)
Get whether a content can reformat.
Definition: content.c:258
Declaration of content enumerations.
content_status
Status of a content.
Definition: content_type.h:87
content_debug
Debugging dump operations.
Definition: content_type.h:30
nserror
Enumeration of error codes.
Definition: errors.h:29
Core mouse and pointer states.
browser_pointer_shape
Mouse pointer type.
Definition: mouse.h:112
browser_mouse_state
Mouse state.
Definition: mouse.h:43
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
int width
Definition: gui.c:159
int height
Definition: gui.c:160
Page features at a specific spatial location.
Browser window data.
X509 certificate chain.
Definition: ssl_certs.h:59
Content which corresponds to a single URL.
Form control.
Definition: form_internal.h:73
High-level cache handle.
Definition: hlcache.c:66
dukky javascript thread
Definition: dukky.c:70
Handle to low-level cache object.
Definition: llcache.c:76
Parameters for object element and similar elements.
Definition: box.h:164
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
Extra data for some content_msg messages.
Definition: content.h:60
struct content_msg_data::@99 errordata
CONTENT_MSG_ERROR - Error from content or underlying fetch.
nserror errorcode
The error code to convey meaning.
Definition: content.h:88
struct content_msg_data::@103 scroll
CONTENT_MSG_SCROLL - Part of content to scroll to show.
int x
Carret x-coord.
Definition: content.h:110
browser_window_console_flags flags
The flags of the logging.
Definition: content.h:72
@ CONTENT_TEXTSEARCH_FIND
Free text search find operation has started or finished.
Definition: content.h:256
const char * msg
The message to log.
Definition: content.h:68
const struct rect * clip
Carret clip rect.
Definition: content.h:215
struct content_msg_data::@111 textsearch
CONTENT_MSG_TEXTSEARCH - Free text search action.
int delay
CONTENT_MSG_REFRESH - Minimum delay.
Definition: content.h:116
struct content_msg_data::@110 gadget_click
CONTENT_MSG_GADGETCLICK - User clicked on a form gadget.
int height
Carret height.
Definition: content.h:110
size_t msglen
The length of that message.
Definition: content.h:70
browser_pointer_shape pointer
CONTENT_MSG_POINTER - Mouse pointer to set.
Definition: content.h:192
struct content_msg_data::@107 caret
CONTENT_MSG_CARET - set caret position or, hide caret.
const char * title
Definition: content.h:186
struct content_msg_data::@105 savelink
CONTENT_MSG_SAVELINK - Save a URL.
const char * errormsg
The message.
Definition: content.h:95
@ CONTENT_SAVE_COMPLETE
Definition: content.h:174
bool selection
false for selection cleared
Definition: content.h:198
const struct cert_chain * chain
CONTENT_MSG_SSL_CERTS - The certificate chain from the underlying fetch.
Definition: content.h:79
struct jsthread ** jsthread
CONTENT_MSG_GETTHREAD - Javascript context (thread)
Definition: content.h:143
struct hlcache_handle * content
if NULL, save the content generating the message
Definition: content.h:178
struct content_rfc5988_link * rfc5988_link
CONTENT_MSG_RFC5988_LINK - rfc5988 link data.
Definition: content.h:138
struct nsurl * to
Redirect target.
Definition: content.h:103
struct content_msg_data::@104 dragsave
CONTENT_MSG_DRAGSAVE - Drag save a content.
@ CONTENT_TEXTSEARCH_MATCH
Free text search match state has changed.
Definition: content.h:260
@ CONTENT_TEXTSEARCH_BACK
Free text search back available state changed.
Definition: content.h:264
@ CONTENT_CARET_REMOVE
Definition: content.h:209
unsigned * viewport_height
Definition: content.h:151
struct content_msg_data::@108 drag
CONTENT_MSG_DRAG - Drag start or end.
struct content_msg_data::@109 select_menu
CONTENT_MSG_SELECTMENU - Create select menu at pointer.
struct nsurl * from
Redirect origin.
Definition: content.h:102
unsigned * viewport_width
Definition: content.h:150
@ CONTENT_TEXTSEARCH_FORWARD
Free text search forward available state changed.
Definition: content.h:268
struct content_msg_data::@98 log
CONTENT_MSG_LOG - Information for logging.
struct llcache_handle * download
CONTENT_MSG_DOWNLOAD - Low-level cache handle.
Definition: content.h:133
struct form_control * gadget
Definition: content.h:235
browser_window_console_source src
The source of the logging.
Definition: content.h:66
struct content_msg_data::@102 getdims
CONTENT_MSG_GETDIMS - Get the viewport dimensions.
bool state
state for operation
Definition: content.h:281
const char * string
search string
Definition: content.h:285
enum content_msg_data::@104::@112 type
int y
Carret y-coord.
Definition: content.h:110
struct content_msg_data::@100 redirect
CONTENT_MSG_REDIRECT - Redirect info.
struct nsurl * url
Definition: content.h:185
@ CONTENT_DRAG_SELECTION
Definition: content.h:226
const struct rect * rect
Definition: content.h:228
void * ctx
context passed to browser_window_search()
Definition: content.h:277
struct content_msg_data::@101 redraw
CONTENT_MSG_REDRAW - Area of content which needs redrawing.
const char * explicit_status_text
CONTENT_MSG_STATUS - Status message update.
Definition: content.h:128
struct content_msg_data::@107::@114 pos
With CONTENT_CARET_SET_POS.
@ CONTENT_TEXTSEARCH_RECENT
add a search query string to the recent searches
Definition: content.h:272
bool background
CONTENT_MSG_REFORMAT - Reformat should not cause a redraw.
Definition: content.h:121
@ CONTENT_CARET_SET_POS
Definition: content.h:207