NetSurf
content.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Vincent Sanders <vince@kyllikki.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * javascript content implementation
22 */
23
24#include <assert.h>
25#include <string.h>
26#include <stdbool.h>
27#include <stdlib.h>
28
29#include "utils/errors.h"
30#include "utils/config.h"
33#include "content/hlcache.h"
34#include "utils/log.h"
35#include "utils/messages.h"
36#include "utils/utils.h"
37#include "javascript/content.h"
38
39typedef struct javascript_content {
40 struct content base;
42
44 lwc_string *imime_type, const struct http_parameter *params,
46 bool quirks, struct content **c)
47{
48 javascript_content *script;
49 nserror error;
50
51 script = calloc(1, sizeof(javascript_content));
52 if (script == NULL)
53 return NSERROR_NOMEM;
54
55 error = content__init(&script->base, handler, imime_type, params,
57 if (error != NSERROR_OK) {
58 free(script);
59 return error;
60 }
61
62 *c = (struct content *) script;
63
64 return NSERROR_OK;
65}
66
67static bool javascript_convert(struct content *c)
68{
71
72 return true;
73}
74
75static nserror
76javascript_clone(const struct content *old, struct content **newc)
77{
78 javascript_content *script;
79 nserror error;
80
81 script = calloc(1, sizeof(javascript_content));
82 if (script == NULL)
83 return NSERROR_NOMEM;
84
85 error = content__clone(old, &script->base);
86 if (error != NSERROR_OK) {
87 content_destroy(&script->base);
88 return error;
89 }
90
91 *newc = (struct content *) script;
92
93 return NSERROR_OK;
94}
95
96static void javascript_destroy(struct content *c)
97{
98}
99
101{
102 return CONTENT_JS;
103}
104
105
108 .data_complete = javascript_convert,
109 .destroy = javascript_destroy,
110 .clone = javascript_clone,
112 .no_share = false,
113};
114
115static const char *javascript_types[] = {
116 "application/javascript", /* RFC 4329 */
117 "application/ecmascript", /* RFC 4329 */
118 "application/x-javascript", /* common usage */
119 "text/javascript", /* common usage */
120 "text/ecmascript", /* common usage */
121};
122
void content_destroy(struct content *c)
Destroy and free a content.
Definition: content.c:354
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
Definition: content.c:299
nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks)
Definition: content.c:190
nserror content__clone(const struct content *c, struct content *nc)
Clone a content's data members.
Definition: content.c:1382
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
Definition: content.c:285
Protected interface to Content handling.
content_type
The type of a content.
Definition: content_type.h:53
@ CONTENT_JS
Javascript.
Definition: content_type.h:76
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
struct javascript_content javascript_content
static bool javascript_convert(struct content *c)
Definition: content.c:67
static content_type javascript_content_type(void)
Definition: content.c:100
static const content_handler javascript_content_handler
Definition: content.c:106
static nserror javascript_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Definition: content.c:43
static nserror javascript_clone(const struct content *old, struct content **newc)
Definition: content.c:76
static void javascript_destroy(struct content *c)
Definition: content.c:96
static const char * javascript_types[]
Definition: content.c:115
CONTENT_FACTORY_REGISTER_TYPES(javascript, javascript_types, javascript_content_handler)
High-level resource cache interface.
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:267
Localised message support (interface).
Interface to utility string handling.
Content operation function table.
nserror(* create)(const struct content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, struct llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Content which corresponds to a single URL.
bool quirks
Content is in quirks mode.
char * fallback_charset
Fallback charset, or NULL.
const struct content_handler * handler
Handler for content.
Representation of an HTTP parameter.
Definition: parameter.c:31
struct content base
Definition: content.c:40
Handle to low-level cache object.
Definition: llcache.c:76
Interface to a number of general purpose functionality.