Subversion Repositories Kolibri OS

Rev

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

  1. /* Binding to generate Navigator interface
  2.  *
  3.  * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
  4.  *
  5.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  6.  *
  7.  * Released under the terms of the MIT License,
  8.  *         http://www.opensource.org/licenses/mit-license
  9.  */
  10.  
  11.  
  12. webidlfile "html.idl";
  13.  
  14. hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
  15. hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
  16. hdrcomment "Released under the terms of the MIT License,";
  17. hdrcomment "        http://www.opensource.org/licenses/mit-license";
  18.  
  19. preamble %{
  20.  
  21. #include <assert.h>
  22. #include <stdlib.h>
  23.  
  24. #include "desktop/netsurf.h"
  25. #include "desktop/options.h"
  26. #include "utils/config.h"
  27. #include "utils/useragent.h"
  28. #include "utils/log.h"
  29. #include "utils/utsname.h"
  30. #include "javascript/jsapi.h"
  31.  
  32. #include "navigator.h"
  33.  
  34. /*
  35.  * navigator properties for netsurf
  36.  *
  37.  * Property    | Everyone else   | NetSurf      | Notes
  38.  * ------------+-----------------+--------------+------------------------------
  39.  * appCodeName | "Mozilla"       | "NetSurf"    | This is kinda a pointless
  40.  *             |                 |              |  constant as everyone returns
  41.  *             |                 |              |  "Mozilla" which is dumb
  42.  * ------------+-----------------+--------------+------------------------------
  43.  * appName     | "<Browsername>" | "NetSurf"    | Browsers named other than
  44.  *             |                 |              | "Netscape", "Mozilla",
  45.  *             |                 |              | "Netscape Navigator",
  46.  *             |                 |              | "Microsoft Internet Explorer"
  47.  *             |                 |              |  often other browser have
  48.  *             |                 |              | "(compatible with Netscape)"
  49.  *             |                 |              |  append.
  50.  * ------------+-----------------+--------------+------------------------------
  51.  * appVersion  | "<ver> (<type>)"| "<ver>"      | Actually just the version
  52.  *             |                 |              |  number e.g "3.0".
  53.  * ------------+-----------------+--------------+------------------------------
  54.  * language    | "<lang>"        | "<lang>"     | The language the frontend is
  55.  *             |                 |              |  configured for
  56.  * ------------+-----------------+--------------+------------------------------
  57.  * platform    | "<krn> <hw>"    | "<krn> <hw>" | Efectively uname -s -i,
  58.  *             |                 |              |   eg "Linux x86_64"
  59.  * ------------+-----------------+--------------+------------------------------
  60.  * userAgent   | "Mozilla/5.0 (" | "NetSurf"    | The usual useragent string  
  61.  *             |                 |              |  with excessive lies
  62.  * ------------+-----------------+--------------+------------------------------
  63.  */
  64.  
  65. #define NAVIGATOR_APPNAME "NetSurf"
  66. #define NAVIGATOR_APPCODENAME "NetSurf"
  67. %}
  68.  
  69. binding navigator {
  70.     type js_libdom; /* the binding type */
  71.  
  72.     interface Navigator; /* Web IDL interface to generate */
  73.  
  74. }
  75.  
  76. getter appName %{
  77.   jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME);
  78. %}
  79.  
  80. getter appCodeName %{
  81.   jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME);
  82. %}
  83.  
  84. getter appVersion %{
  85.    jsret = JS_NewStringCopyZ(cx, netsurf_version);
  86. %}
  87.  
  88. getter language %{
  89.   const char *alang = nsoption_charp(accept_language);
  90.  
  91.   if (alang != NULL) {
  92.     jsret = JS_NewStringCopyZ(cx, alang);
  93.   }
  94.  
  95. %}
  96.  
  97. getter platform %{
  98.   struct utsname *cutsname;
  99.  
  100.   cutsname = malloc(sizeof(struct utsname));
  101.  
  102.   if ((cutsname != NULL) && (uname(cutsname) >= 0)) {
  103.     char *platstr;
  104.     int platstrlen;
  105.  
  106.     platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2;
  107.     platstr = malloc(platstrlen);
  108.     if (platstr != NULL) {
  109.       snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
  110.       jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1);
  111.       free(platstr);
  112.     }
  113.   }
  114. %}
  115.  
  116. getter userAgent %{
  117.   jsret = JS_NewStringCopyZ(cx, user_agent_string());
  118. %}
  119.