Subversion Repositories Kolibri OS

Rev

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

  1. /* Binding to generate Location 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. webidlfile "html.idl";
  12.  
  13. hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
  14. hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
  15. hdrcomment "Released under the terms of the MIT License,";
  16. hdrcomment "        http://www.opensource.org/licenses/mit-license";
  17.  
  18. preamble %{
  19.  
  20. #include "desktop/browser.h"
  21.        
  22. #include "utils/config.h"
  23. #include "utils/log.h"
  24. #include "javascript/jsapi.h"
  25. #include "render/html_internal.h"
  26.  
  27. #include "location.h"
  28.  
  29. %}
  30.  
  31. binding location {
  32.         type js_libdom; /* the binding type */
  33.  
  34.         interface Location; /* Web IDL interface to generate */
  35.  
  36.         private "nsurl *" url;
  37.         private "struct html_content *" htmlc;
  38.  
  39.         property unshared href;
  40.  
  41. }
  42.  
  43. operation reload %{
  44.         browser_window_reload(private->htmlc->bw, false);
  45. %}
  46.  
  47.  
  48. getter href %{
  49.         char *url_s = NULL;
  50.         size_t url_l;
  51.  
  52.         if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
  53.                 /* already created - return it */
  54.                 return JS_TRUE;
  55.         }
  56.  
  57.         nsurl_get(private->url, NSURL_COMPLETE, &url_s, &url_l);
  58.         if (url_s != NULL) {
  59.                 jsret = JS_NewStringCopyN(cx, url_s, url_l);
  60.                 free(url_s);           
  61.         }
  62. %}
  63.  
  64. setter href %{
  65.         JSString *url_jsstr = NULL;
  66.         int url_len = 0;
  67.         char *url = NULL;
  68.  
  69.         url_jsstr = JS_ValueToString(cx, *vp);
  70.         if (url_jsstr != NULL) {
  71.                 JSString_to_char(url_jsstr, url, url_len);
  72.                 browser_window_go(private->htmlc->bw, url, NULL, false);
  73.         } else {
  74.                 JSLOG("failed to convert string value");
  75.         }
  76. %}
  77.  
  78. getter protocol %{
  79.         lwc_string *component;
  80.         component = nsurl_get_component(private->url, NSURL_SCHEME);
  81.         if (component != NULL) {
  82.                 jsret = JS_NewStringCopyN(cx,
  83.                                           lwc_string_data(component),
  84.                                           lwc_string_length(component));
  85.                 lwc_string_unref(component);
  86.         }
  87. %}
  88.  
  89. getter host %{
  90.         lwc_string *component;
  91.         component = nsurl_get_component(private->url, NSURL_HOST);
  92.         if (component != NULL) {
  93.                 jsret = JS_NewStringCopyN(cx,
  94.                                           lwc_string_data(component),
  95.                                           lwc_string_length(component));
  96.                 lwc_string_unref(component);
  97.         }
  98. %}
  99.  
  100. getter hostname %{
  101.         lwc_string *component;
  102.         component = nsurl_get_component(private->url, NSURL_HOST);
  103.         if (component != NULL) {
  104.                 jsret = JS_NewStringCopyN(cx,
  105.                                           lwc_string_data(component),
  106.                                           lwc_string_length(component));
  107.                 lwc_string_unref(component);
  108.         }
  109.  
  110. %}
  111.  
  112. getter port %{
  113.         lwc_string *component;
  114.         component = nsurl_get_component(private->url, NSURL_PORT);
  115.         if (component != NULL) {
  116.                 jsret = JS_NewStringCopyN(cx,
  117.                                           lwc_string_data(component),
  118.                                           lwc_string_length(component));
  119.                 lwc_string_unref(component);
  120.         }
  121.  
  122. %}
  123.  
  124. getter pathname %{
  125.         lwc_string *component;
  126.         component = nsurl_get_component(private->url, NSURL_PATH);
  127.         if (component != NULL) {
  128.                 jsret = JS_NewStringCopyN(cx,
  129.                                           lwc_string_data(component),
  130.                                           lwc_string_length(component));
  131.                 lwc_string_unref(component);
  132.         }
  133.  
  134. %}
  135.  
  136. getter search %{
  137.         lwc_string *component;
  138.         component = nsurl_get_component(private->url, NSURL_QUERY);
  139.         if (component != NULL) {
  140.                 jsret = JS_NewStringCopyN(cx,
  141.                                           lwc_string_data(component),
  142.                                           lwc_string_length(component));
  143.                 lwc_string_unref(component);
  144.         }
  145.  
  146. %}
  147.  
  148. getter hash %{
  149.         lwc_string *component;
  150.         component = nsurl_get_component(private->url, NSURL_FRAGMENT);
  151.         if (component != NULL) {
  152.                 jsret = JS_NewStringCopyN(cx,
  153.                                           lwc_string_data(component),
  154.                                           lwc_string_length(component));
  155.                 lwc_string_unref(component);
  156.         }
  157. %}
  158.