Dillo v3.1.1-111-gd4f56d0d
Loading...
Searching...
No Matches
web.cc
Go to the documentation of this file.
1/*
2 * File: web.cc
3 *
4 * Copyright 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
5 * Copyright 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program 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; either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13#include "msg.h"
14#include "nav.h"
15
16#include "uicmd.hh"
17
18#include "IO/IO.h"
19#include "IO/mime.h"
20
21#include "dw/core.hh"
22#include "styleengine.hh"
23#include "web.hh"
24
25// Platform independent part
26using namespace dw::core;
27
28
29/*
30 * Local data
31 */
32static Dlist *ValidWebs; /* Active web structures list; it holds
33 * pointers to DilloWeb structures. */
34
35/*
36 * Initialize local data
37 */
38void a_Web_init(void)
39{
40 ValidWebs = dList_new(32);
41}
42
50int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web,
51 CA_Callback_t *Call, void **Data)
52{
53 Widget *dw = NULL;
54
55 _MSG("a_Web_dispatch_by_type\n");
56
57 BrowserWindow *bw = Web->bw;
58 dReturn_val_if_fail(bw != NULL, -1);
59
61
62 Viewer_t viewer = a_Mime_get_viewer(Type);
63 if (viewer == NULL)
64 return -1;
65
66 if (Web->flags & WEB_RootUrl) {
67 /* We have RootUrl! */
68
70 Web->bgColor = bgColor->getColor ();
71 layout->setBgColor (bgColor);
76
77 /* Set a style for the widget */
78 StyleEngine styleEngine (layout, Web->url, Web->url, bw->zoom);
79 styleEngine.startElement ("body", Web->bw);
80
81 dw = (Widget*) viewer(Type, Web, Call, Data);
82 if (dw == NULL)
83 return -1;
84
85 dw->setStyle (styleEngine.style (Web->bw));
86
87 /* This method frees the old dw if any */
89
90 /* Set the page title with the bare filename (e.g. for images),
91 * HTML pages with a <TITLE> tag will overwrite it later */
92 const char *p = strrchr(URL_STR(Web->url), '/');
93 a_UIcmd_set_page_title(Web->bw, p ? p+1 : "");
94
96 /* Reset both progress bars */
97 a_UIcmd_set_page_prog(Web->bw, 0, 2);
98 a_UIcmd_set_img_prog(Web->bw, 0, 0, 2);
99 /* Reset the bug meter */
100 a_UIcmd_set_bug_prog(Web->bw, 0);
101
102 /* Let the Nav module know... */
103 a_Nav_expect_done(Web->bw);
104
105 } else {
106 /* A non-RootUrl. At this moment we only handle image-children */
107 if (!dStrnAsciiCasecmp(Type, "image/", 6)) {
108 dw = (Widget*) viewer(Type, Web, Call, Data);
109 } else {
110 MSG_HTTP("'%s' cannot be displayed as image; has media type '%s'\n",
111 URL_STR(Web->url), Type);
112 }
113 }
114 return (dw ? 1 : -1);
115}
116
117
122 const DilloUrl *requester)
123{
124 DilloWeb *web= dNew(DilloWeb, 1);
125
126 _MSG(" a_Web_new: ValidWebs ==> %d\n", dList_length(ValidWebs));
127 web->url = a_Url_dup(url);
128 web->requester = a_Url_dup(requester);
129 web->bw = bw;
130 web->flags = 0;
131 web->Image = NULL;
132 web->filename = NULL;
133 web->stream = NULL;
134 web->SavedBytes = 0;
135 web->bgColor = 0x000000; /* Dummy value will be overwritten
136 * in a_Web_dispatch_by_type. */
137 dList_append(ValidWebs, (void *)web);
138 return web;
139}
140
145{
146 return (dList_find(ValidWebs, web) != NULL);
147}
148
153{
154 if (!web) return;
155 a_Url_free(web->url);
156 a_Url_free(web->requester);
157 a_Image_unref(web->Image);
158 dFree(web->filename);
159 dList_remove(ValidWebs, (void *)web);
160 _MSG("a_Web_free: ValidWebs=%d\n", dList_length(ValidWebs));
161 dFree(web);
162}
163
#define _MSG(...)
Definition bookmarks.c:45
void(* CA_Callback_t)(int Op, CacheClient_t *Client)
Callback type for cache clients.
Definition cache.h:43
This class provides the glue between HTML parser and CSS subsystem.
void startElement(int tag, BrowserWindow *bw)
tell the styleEngine that a new html element has started.
dw::core::style::Style * style(BrowserWindow *bw)
The central class for managing and drawing a widget tree.
Definition layout.hh:17
void setWidget(Widget *widget)
Definition layout.cc:433
void setBgColor(style::Color *color)
Definition layout.cc:826
void setBgImage(style::StyleImage *bgImage, style::BackgroundRepeat bgRepeat, style::BackgroundAttachment bgAttachment, style::Length bgPositionX, style::Length bgPositionY)
Definition layout.cc:839
The base class of all dillo widgets.
Definition widget.hh:44
static Color * create(Layout *layout, int color)
Definition style.cc:529
void dFree(void *mem)
Definition dlib.c:68
Dlist * dList_new(int size)
Create a new empty list.
Definition dlib.c:548
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)
Definition dlib.c:215
int dList_length(Dlist *lp)
For completing the ADT.
Definition dlib.c:613
void dList_append(Dlist *lp, void *data)
Append a data item to the list.
Definition dlib.c:597
void dList_remove(Dlist *lp, const void *data)
Definition dlib.c:641
void * dList_find(Dlist *lp, const void *data)
Return the found data item, or NULL if not present.
Definition dlib.c:672
#define dReturn_val_if_fail(expr, val)
Definition dlib.h:76
#define dNew(type, count)
Definition dlib.h:49
static Layout * layout
Viewer_t a_Mime_get_viewer(const char *content_type)
Get the handler for the MIME type.
Definition mime.c:133
void *(* Viewer_t)(const char *, void *, CA_Callback_t *, void **)
Definition mime.h:24
@ BACKGROUND_ATTACHMENT_SCROLL
Definition style.hh:245
Length createPerLength(double v)
Returns a percentage, v is relative to 1, not to 100.
Definition style.hh:435
The core of Dw is defined in this namespace.
Definition core.hh:23
Dw is in this namespace, or sub namespaces of this one.
void a_Nav_expect_done(BrowserWindow *bw)
Definition nav.c:272
DilloPrefs prefs
Global Data.
Definition prefs.c:33
void a_Image_unref(DilloImage *Image)
Unref and free if necessary Do nothing if the argument is NULL.
Definition image.cc:89
#define MSG_HTTP(...)
Definition msg.h:25
Contains the specific data for a single window.
Definition bw.h:27
void * render_layout
All the rendering is done by this.
Definition bw.h:34
float zoom
Definition bw.h:74
int32_t bg_color
Definition prefs.h:54
Definition url.h:88
Definition dlib.h:131
char * filename
Variables for Local saving.
Definition web.hh:34
int flags
Additional info.
Definition web.hh:29
DilloUrl * url
Requested URL.
Definition web.hh:25
FILE * stream
Definition web.hh:35
DilloUrl * requester
URL that caused this request, or < NULL if user-initiated.
Definition web.hh:26
BrowserWindow * bw
The requesting browser window [reference].
Definition web.hh:28
DilloImage * Image
For image urls [reference].
Definition web.hh:31
int32_t bgColor
for image backgrounds
Definition web.hh:33
int SavedBytes
Definition web.hh:36
void a_UIcmd_set_bug_prog(BrowserWindow *bw, int n_bug)
Definition uicmd.cc:1531
void a_UIcmd_set_page_title(BrowserWindow *bw, const char *label)
Definition uicmd.cc:1540
void a_UIcmd_set_page_prog(BrowserWindow *bw, size_t nbytes, int cmd)
Definition uicmd.cc:1510
void a_UIcmd_set_img_prog(BrowserWindow *bw, int n_img, int t_img, int cmd)
Definition uicmd.cc:1519
void a_UIcmd_set_location_text(void *vbw, const char *text)
Definition uicmd.cc:1500
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
Definition url.c:208
DilloUrl * a_Url_dup(const DilloUrl *ori)
Duplicate a Url structure.
Definition url.c:477
#define URL_STR(u)
Definition url.h:76
static Dlist * ValidWebs
Definition web.cc:32
int a_Web_dispatch_by_type(const char *Type, DilloWeb *Web, CA_Callback_t *Call, void **Data)
Given the MIME content type, and a fd to read it from, this function connects the proper MIME viewer ...
Definition web.cc:50
void a_Web_init(void)
Definition web.cc:38
DilloWeb * a_Web_new(BrowserWindow *bw, const DilloUrl *url, const DilloUrl *requester)
Allocate and set safe values for a DilloWeb structure.
Definition web.cc:121
void a_Web_free(DilloWeb *web)
Deallocate a DilloWeb structure.
Definition web.cc:152
int a_Web_valid(DilloWeb *web)
Validate a DilloWeb pointer.
Definition web.cc:144
#define WEB_RootUrl
Definition web.hh:16