Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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. /** \file
  20.  * Content for javascript (implementation)
  21.  */
  22.  
  23. #include <assert.h>
  24. #include <string.h>
  25. #include <stdbool.h>
  26. #include <stdlib.h>
  27.  
  28. #include "utils/config.h"
  29. #include "content/content_protected.h"
  30. #include "content/hlcache.h"
  31. #include "utils/log.h"
  32. #include "utils/messages.h"
  33. #include "utils/utils.h"
  34. #include "javascript/content.h"
  35.  
  36. typedef struct javascript_content {
  37.         struct content base;
  38. } javascript_content;
  39.  
  40. static nserror javascript_create(const content_handler *handler,
  41.                 lwc_string *imime_type, const http_parameter *params,
  42.                 llcache_handle *llcache, const char *fallback_charset,
  43.                 bool quirks, struct content **c)
  44. {
  45.         javascript_content *script;
  46.         nserror error;
  47.  
  48.         script = calloc(1, sizeof(javascript_content));
  49.         if (script == NULL)
  50.                 return NSERROR_NOMEM;
  51.  
  52.         error = content__init(&script->base, handler, imime_type, params,
  53.                         llcache, fallback_charset, quirks);
  54.         if (error != NSERROR_OK) {
  55.                 free(script);
  56.                 return error;
  57.         }
  58.  
  59.         *c = (struct content *) script;
  60.  
  61.         return NSERROR_OK;
  62. }
  63.  
  64. static bool javascript_convert(struct content *c)
  65. {
  66.         content_set_ready(c);
  67.         content_set_done(c);
  68.  
  69.         return true;
  70. }
  71.  
  72. static nserror
  73. javascript_clone(const struct content *old, struct content **newc)
  74. {
  75.         javascript_content *script;
  76.         nserror error;
  77.  
  78.         script = calloc(1, sizeof(javascript_content));
  79.         if (script == NULL)
  80.                 return NSERROR_NOMEM;
  81.  
  82.         error = content__clone(old, &script->base);
  83.         if (error != NSERROR_OK) {
  84.                 content_destroy(&script->base);
  85.                 return error;
  86.         }
  87.  
  88.         *newc = (struct content *) script;
  89.  
  90.         return NSERROR_OK;
  91. }
  92.  
  93. static void javascript_destroy(struct content *c)
  94. {
  95. }
  96.  
  97. static content_type javascript_content_type(void)
  98. {
  99.         return CONTENT_JS;
  100. }
  101.  
  102.  
  103. static const content_handler javascript_content_handler = {
  104.         .create = javascript_create,
  105.         .data_complete = javascript_convert,
  106.         .destroy = javascript_destroy,
  107.         .clone = javascript_clone,
  108.         .type = javascript_content_type,
  109.         .no_share = false,
  110. };
  111.  
  112. static const char *javascript_types[] = {
  113.         "application/javascript", /* RFC 4329 */
  114.         "application/ecmascript", /* RFC 4329 */
  115.         "application/x-javascript", /* common usage */
  116.         "text/javascript", /* common usage */
  117.         "text/ecmascript", /* common usage */
  118. };
  119.  
  120. CONTENT_FACTORY_REGISTER_TYPES(javascript, javascript_types, javascript_content_handler);
  121.