edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [Edbrowse-dev] [PATCH] bundle of changes that makes diedrescher link work
@ 2016-06-30  4:35 Kevin Carhart
  0 siblings, 0 replies; only message in thread
From: Kevin Carhart @ 2016-06-30  4:35 UTC (permalink / raw)
  To: Edbrowse-dev

[-- Attachment #1: Type: text/plain, Size: 21258 bytes --]

>From 3881be938b602018cf426006d9a29e32b49d1041 Mon Sep 17 00:00:00 2001
From: Kevin Carhart <kevin@carhart.net>
Date: Wed, 29 Jun 2016 20:10:30 -0700
Subject: [PATCH] Changes that get you successfully from a click on a
 diedrescher.com link, to javascript, to xhr, to content coming back over xhr
 and into a div on the edbrowse side, thus illustrating the complete circuit
 for other pages as well. Please see edbrowse-dev post for more detail of what
 was done and why.

---
 src/decorate.c     |  25 ++++++++-
 src/jseng-moz.cpp  |  16 +++---
 src/startwindow.js | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 177 insertions(+), 14 deletions(-)

diff --git a/src/decorate.c b/src/decorate.c
index 3773e26..4092ac5 100644
--- a/src/decorate.c
+++ b/src/decorate.c
@@ -820,6 +820,7 @@ call out to process those and add them to the object */
 /* Other attributes that are expected by pages, even if they
  * aren't populated at domLink-time */
 set_property_string(io, "className", "");
+set_property_string(io, "class", "");
 set_property_string(io, "nodeValue","");
 instantiate_array(io, "attributes");
 set_property_object(io, "ownerDocument", cw->docobj);
@@ -894,6 +895,7 @@ set_property_object(io, "ownerDocument", cw->docobj);
 
 	if (htmlclass) {
 		set_property_string(io, "className", htmlclass);
+		set_property_string(io, "class", htmlclass);
 	}
 
 	t->jv = io;
@@ -1025,6 +1027,7 @@ static void jsNode(struct htmlTag *t, bool opentag)
 				w = emptyString;
 			set_property_string(t->jv, "data", w);
 			set_property_string(t->jv, "nodeName", "text");
+			set_property_number(t->jv, "nodeType", 3);
 		}
 		break;
 
@@ -1050,52 +1053,62 @@ static void jsNode(struct htmlTag *t, bool opentag)
                 }else {
                         set_property_string(t->jv, "data", "");
                 }
+		set_property_number(t->jv, "nodeType", 1);
 		break;
 	case TAGACT_FORM:
 		domLink(t, "Form", "action", "forms", cw->docobj, 0);
 		set_onhandlers(t);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_INPUT:
 		formControlJS(t);
 		if (t->itype == INP_TA)
 			establish_inner(t->jv, t->value, 0, true);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_OPTION:
 		optionJS(t);
 // The parent child relationship has already been established,
 // don't break, just return;
+                set_property_number(t->jv, "nodeType", 1);
 		return;
 
 	case TAGACT_A:
 		domLink(t, "Anchor", "href", "anchors", cw->docobj, 0);
 		set_onhandlers(t);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_HEAD:
 		domLink(t, "Head", 0, "heads", cw->docobj, 0);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_BODY:
 		domLink(t, "Body", 0, "bodies", cw->docobj, 0);
 		set_onhandlers(t);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_OL:
 	case TAGACT_UL:
 	case TAGACT_DL:
 		domLink(t, "Lister", 0, 0, cw->docobj, 0);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_LI:
 		domLink(t, "Listitem", 0, 0, cw->docobj, 0);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_TABLE:
 		domLink(t, "Table", 0, "tables", cw->docobj, 0);
 /* create the array of rows under the table */
 		instantiate_array(t->jv, "rows");
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_TR:
@@ -1103,6 +1116,7 @@ static void jsNode(struct htmlTag *t, bool opentag)
 			domLink(t, "Trow", 0, "rows", above->jv, 0);
 			instantiate_array(t->jv, "cells");
 		}
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_TD:
@@ -1110,16 +1124,19 @@ static void jsNode(struct htmlTag *t, bool opentag)
 			domLink(t, "Cell", 0, "cells", above->jv, 0);
 			establish_inner(t->jv, t->innerHTML, 0, false);
 		}
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_DIV:
 		domLink(t, "Div", 0, "divs", cw->docobj, 0);
 		establish_inner(t->jv, t->innerHTML, 0, false);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_OBJECT:
 		domLink(t, "HtmlObj", 0, "htmlobjs", cw->docobj, 0);
 		establish_inner(t->jv, t->innerHTML, 0, false);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_SPAN:
@@ -1128,28 +1145,34 @@ static void jsNode(struct htmlTag *t, bool opentag)
 	case TAGACT_OVB:
 		domLink(t, "Span", 0, "spans", cw->docobj, 0);
 		establish_inner(t->jv, t->innerHTML, 0, false);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_AREA:
 		domLink(t, "Area", "href", "areas", cw->docobj, 0);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_FRAME:
 		domLink(t, "Frame", "src", "frames", cw->winobj, 0);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_IMAGE:
 		domLink(t, "Image", "src", "images", cw->docobj, 0);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_P:
 		domLink(t, "P", 0, "paragraphs", cw->docobj, 0);
 		establish_inner(t->jv, t->innerHTML, 0, false);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	case TAGACT_TITLE:
 		if (cw->ft)
 			set_property_string(cw->docobj, "title", cw->ft);
+                set_property_number(t->jv, "nodeType", 1);
 		break;
 
 	}			/* switch */
@@ -1251,7 +1274,7 @@ const struct tagInfo availableTags[] = {
 	{"form", "a form", TAGACT_FORM, 10, 1},
 	{"button", "a button", TAGACT_INPUT, 0, 4},
 	{"frame", "a frame", TAGACT_FRAME, 2, 4},
-	{"iframe", "a frame", TAGACT_FRAME, 2, 4},
+//	{"iframe", "a frame", TAGACT_FRAME, 2, 4},
 	{"map", "an image map", TAGACT_MAP, 2, 4},
 	{"area", "an image map area", TAGACT_AREA, 0, 4},
 	{"table", "a table", TAGACT_TABLE, 10, 1},
diff --git a/src/jseng-moz.cpp b/src/jseng-moz.cpp
index 429353e..9a0adca 100644
--- a/src/jseng-moz.cpp
+++ b/src/jseng-moz.cpp
@@ -1888,12 +1888,17 @@ static JSObject *setTimeout(unsigned int argc, jsval * argv, bool isInterval)
 	const char *allocatedName = NULL;
 	const char *s = NULL;
 
-	if (argc != 2 || !JSVAL_IS_INT(argv[1]))
-		goto badarg;
 
 	v0 = argv[0];
-	v1 = argv[1];
-	n = JSVAL_TO_INT(v1);
+	if (argc != 2 || !JSVAL_IS_INT(argv[1]))
+	{
+		// if only one parameter was supplied, hardcode
+		// a number of milliseconds.  1?  100?  1000?
+		n = 100;
+	} else {
+        	v1 = argv[1];
+        	n = JSVAL_TO_INT(v1);
+	}
 	if (JSVAL_IS_STRING(v0) ||
 	    v0.isObject() &&
 	    JS_ValueToObject(jcx, v0, fo.address()) &&
@@ -1980,9 +1985,6 @@ abort:
 		return to;
 	}
 
-badarg:
-	JS_ReportError(jcx, "invalid arguments to %s()", methname);
-	return NULL;
 }				/* setTimeout */
 
 /* set timer and set interval */
diff --git a/src/startwindow.js b/src/startwindow.js
index b9b8451..77053c5 100644
--- a/src/startwindow.js
+++ b/src/startwindow.js
@@ -16,7 +16,8 @@ The classes are created first, so that you can write meaningful prototypes here.
  * Better to have something than nothing at all. */
 height = 768;
 width = 1024;
-status = 0;
+// document.status is removed because it creates a conflict with
+// the status property of the XMLHttpRequest implementation
 defaultStatus = 0;
 returnValue = true;
 menubar = true;
@@ -30,6 +31,8 @@ document.bgcolor = "white";
 document.readyState = "loading";
 document.nodeType = 9;
 document.implementation = {};
+// pages seem to want document.style to exist
+document.style = {"bgcolor":"white"};
 
 screen = new Object;
 screen.height = 768;
@@ -64,7 +67,7 @@ return document.gebtn$(this, s);
 }
 document.gebtn$ = function(top, s) { 
 var a = new Array;
-if(s === '*' || (top.nodeName && top.nodeName === s))
+if(s === '*' || (top.nodeName && top.nodeName.toLowerCase() === s))
 a.push(top);
 if(top.childNodes) {
 for(var i=0; i<top.childNodes.length; ++i) {
@@ -81,7 +84,7 @@ return document.gebn$(this, s);
 }
 document.gebn$ = function(top, s) { 
 var a = new Array;
-if(s === '*' || (top.name && top.name === s))
+if(s === '*' || (top.name && top.name.toLowerCase() === s))
 a.push(top);
 if(top.childNodes) {
 for(var i=0; i<top.childNodes.length; ++i) {
@@ -98,7 +101,7 @@ return document.gebcn$(this, s);
 }
 document.gebcn$ = function(top, s) { 
 var a = new Array;
-if(s === '*' || (top.className && top.className === s))
+if(s === '*' || (top.className && top.className.toLowerCase() === s))
 a.push(top);
 if(top.childNodes) {
 for(var i=0; i<top.childNodes.length; ++i) {
@@ -231,9 +234,12 @@ c.attributes = new Object;
 c.nodeName = t;
 c.nodeType = 1;
 c.nodeValue = undefined;
+c.class = new String;
 c.className = new String;
 c.ownerDocument = document;
 c.tagName = t;
+
+
 return c;
 } 
 
@@ -470,6 +476,10 @@ return this.toString().lastIndexOf(s);
 URL.prototype.substring = function(from, to) { 
 return this.toString().substring(from, to);
 }
+// pages expect both substring and substr 
+URL.prototype.substr = function(from, to) {
+return this.toString().substring(from, to);
+}
 URL.prototype.toLowerCase = function() { 
 return this.toString().toLowerCase();
 }
@@ -482,6 +492,9 @@ return this.toString().match(s);
 URL.prototype.replace = function(s, t) { 
 return this.toString().replace(s, t);
 }
+URL.prototype.split = function(s) {
+return this.toString().split(s);
+}
 
 /*********************************************************************
 This is our addEventListener function.
@@ -497,6 +510,7 @@ Third arg is not used cause I don't understand it.
 
 function addEventListener(ev, handler, notused)
 {
+ev_before_changes = ev;
 ev = "on" + ev;
 var evarray = ev + "$$array"; // array of handlers
 var evorig = ev + "$$orig"; // original handler from html
@@ -510,7 +524,7 @@ this[ev] = undefined;
 }
 this[evarray] = a;
 eval(
-'this.' + ev + ' = function(){ var a = this.' + evarray + '; if(this.' + evorig + ') this.' + evorig + '(); for(var i = 0; i<a.length; ++i) a[i](); };');
+'this.' + ev + ' = function(){ var a = this.' + evarray + '; if(this.' + evorig + ') this.' + evorig + '(); for(var i = 0; i<a.length; ++i) {var tempEvent = new Event;tempEvent.type = "' + ev_before_changes + '";a[i](tempEvent);} };');
 }
 this[evarray].push(handler);
 }
@@ -616,6 +630,23 @@ document.setAttribute = function(name, v) {
 this.attributes[name.toLowerCase()] = v;
 this[name.toLowerCase()] = v; 
 }
+// hasAttribute works in a comparable way to get and set, returning true/false
+document.hasAttribute = function(name) {
+if (this[name.toLowerCase()])
+        {
+                return true;
+        }
+        else
+        {
+                for (var i=0; i < this.attributes.length; ++i)
+                {
+                        if (this.attributes[i] == name.toLowerCase()) {
+                                return true;
+                        }
+                }
+        }
+return false;
+}
 
 /*********************************************************************
 Notes on cloneNode:
@@ -738,6 +769,7 @@ Array.prototype.hasChildNodes = document.hasChildNodes;
 Array.prototype.replaceChild = document.replaceChild;
 Array.prototype.getAttribute = document.getAttribute;
 Array.prototype.setAttribute = document.setAttribute;
+Array.prototype.hasAttribute = document.setAttribute;
 
 Head.prototype.appendChild = document.appendChild;
 Head.prototype.apch$ = document.apch$;
@@ -754,6 +786,7 @@ Head.prototype.replaceChild = document.replaceChild;
 Head.prototype.getAttribute = document.getAttribute;
 Head.prototype.setAttribute = document.setAttribute;
 Head.prototype.cloneNode = document.cloneNode;
+Head.prototype.hasAttribute = document.setAttribute;
 
 Body.prototype.appendChild = document.appendChild;
 Body.prototype.apch$ = document.apch$;
@@ -770,7 +803,7 @@ Body.prototype.replaceChild = document.replaceChild;
 Body.prototype.getAttribute = document.getAttribute;
 Body.prototype.setAttribute = document.setAttribute;
 Body.prototype.cloneNode = document.cloneNode;
-
+Body.prototype.hasAttribute = document.setAttribute;
 
 /*********************************************************************
 Special functions for form and input.
@@ -829,6 +862,7 @@ Form.prototype.replaceChild = document.replaceChild;
 Form.prototype.getAttribute = document.getAttribute;
 Form.prototype.setAttribute = document.setAttribute;
 Form.prototype.cloneNode = document.cloneNode;
+Form.prototype.hasAttribute = document.setAttribute;
 
 Element.prototype.appendChild = document.appendChild;
 Element.prototype.apch$ = document.apch$;
@@ -847,6 +881,7 @@ Element.prototype.setAttribute = document.setAttribute;
 Element.prototype.focus = document.focus;
 Element.prototype.blur = document.blur;
 Element.prototype.cloneNode = document.cloneNode;
+Element.prototype.hasAttribute = document.setAttribute;
 
 Anchor.prototype.appendChild = document.appendChild;
 Anchor.prototype.apch$ = document.apch$;
@@ -855,6 +890,7 @@ Anchor.prototype.blur = document.blur;
 Anchor.prototype.getAttribute = document.getAttribute;
 Anchor.prototype.setAttribute = document.setAttribute;
 Anchor.prototype.cloneNode = document.cloneNode;
+Anchor.prototype.hasAttribute = document.setAttribute;
 
 Div.prototype.appendChild = document.appendChild;
 Div.prototype.apch$ = document.apch$;
@@ -871,6 +907,7 @@ Div.prototype.replaceChild = document.replaceChild;
 Div.prototype.getAttribute = document.getAttribute;
 Div.prototype.setAttribute = document.setAttribute;
 Div.prototype.cloneNode = document.cloneNode;
+Div.prototype.hasAttribute = document.setAttribute;
 
 HtmlObj.prototype.appendChild = document.appendChild;
 HtmlObj.prototype.apch$ = document.apch$;
@@ -887,10 +924,12 @@ HtmlObj.prototype.replaceChild = document.replaceChild;
 HtmlObj.prototype.getAttribute = document.getAttribute;
 HtmlObj.prototype.setAttribute = document.setAttribute;
 HtmlObj.prototype.cloneNode = document.cloneNode;
+HtmlObj.prototype.hasAttribute = document.setAttribute;
 
 Script.prototype.getAttribute = document.getAttribute;
 Script.prototype.setAttribute = document.setAttribute;
 Script.prototype.cloneNode = document.cloneNode;
+Script.prototype.hasAttribute = document.setAttribute;
 
 P.prototype.appendChild = document.appendChild;
 P.prototype.apch$ = document.apch$;
@@ -907,6 +946,7 @@ P.prototype.hasChildNodes = document.hasChildNodes;
 P.prototype.removeChild = document.removeChild;
 P.prototype.replaceChild = document.replaceChild;
 P.prototype.cloneNode = document.cloneNode;
+P.prototype.setAttribute = document.setAttribute;
 
 Lister.prototype.appendChild = document.appendChild;
 Lister.prototype.apch$ = document.apch$;
@@ -923,6 +963,7 @@ Lister.prototype.hasChildNodes = document.hasChildNodes;
 Lister.prototype.removeChild = document.removeChild;
 Lister.prototype.replaceChild = document.replaceChild;
 Lister.prototype.cloneNode = document.cloneNode;
+Lister.prototype.hasAttribute = document.setAttribute;
 
 Listitem.prototype.appendChild = document.appendChild;
 Listitem.prototype.apch$ = document.apch$;
@@ -939,6 +980,7 @@ Listitem.prototype.hasChildNodes = document.hasChildNodes;
 Listitem.prototype.removeChild = document.removeChild;
 Listitem.prototype.replaceChild = document.replaceChild;
 Listitem.prototype.cloneNode = document.cloneNode;
+Listitem.prototype.hasAttribute = document.setAttribute;
 
 Table.prototype.appendChild = document.appendChild;
 Table.prototype.apch$ = document.apch$;
@@ -955,6 +997,7 @@ Table.prototype.hasChildNodes = document.hasChildNodes;
 Table.prototype.removeChild = document.removeChild;
 Table.prototype.replaceChild = document.replaceChild;
 Table.prototype.cloneNode = document.cloneNode;
+Table.prototype.hasAttribute = document.setAttribute;
 
 Tbody.prototype.appendChild = document.appendChild;
 Tbody.prototype.apch$ = document.apch$;
@@ -971,6 +1014,7 @@ Tbody.prototype.hasChildNodes = document.hasChildNodes;
 Tbody.prototype.removeChild = document.removeChild;
 Tbody.prototype.replaceChild = document.replaceChild;
 Tbody.prototype.cloneNode = document.cloneNode;
+Tbody.prototype.hasAttribute = document.setAttribute;
 
 Trow.prototype.appendChild = document.appendChild;
 Trow.prototype.apch$ = document.apch$;
@@ -987,6 +1031,7 @@ Trow.prototype.hasChildNodes = document.hasChildNodes;
 Trow.prototype.removeChild = document.removeChild;
 Trow.prototype.replaceChild = document.replaceChild;
 Trow.prototype.cloneNode = document.cloneNode;
+Trow.prototype.hasAttribute = document.setAttribute;
 
 Cell.prototype.appendChild = document.appendChild;
 Cell.prototype.apch$ = document.apch$;
@@ -1003,6 +1048,7 @@ Cell.prototype.hasChildNodes = document.hasChildNodes;
 Cell.prototype.removeChild = document.removeChild;
 Cell.prototype.replaceChild = document.replaceChild;
 Cell.prototype.cloneNode = document.cloneNode;
+Cell.prototype.hasAttribute = document.setAttribute;
 
 Span.prototype.appendChild = document.appendChild;
 Span.prototype.apch$ = document.apch$;
@@ -1019,6 +1065,42 @@ Span.prototype.hasChildNodes = document.hasChildNodes;
 Span.prototype.removeChild = document.removeChild;
 Span.prototype.replaceChild = document.replaceChild;
 Span.prototype.cloneNode = document.cloneNode;
+Span.prototype.hasAttribute = document.setAttribute;
+
+Image.prototype.appendChild = document.appendChild;
+Image.prototype.apch$ = document.apch$;
+Image.prototype.getAttribute = document.getAttribute;
+Image.prototype.setAttribute = document.setAttribute;
+Image.prototype.insertBefore = document.insertBefore;
+Object.defineProperty(Image.prototype, "firstChild", {
+get: function() { return this.childNodes[0]; }
+});
+Object.defineProperty(Image.prototype, "lastChild", {
+get: function() { return this.childNodes[this.childNodes.length-1]; }
+});
+Image.prototype.hasChildNodes = document.hasChildNodes;
+Image.prototype.removeChild = document.removeChild;
+Image.prototype.replaceChild = document.replaceChild;
+Image.prototype.cloneNode = document.cloneNode;
+Image.prototype.hasAttribute = document.hasAttribute;
+
+Frame.prototype.appendChild = document.appendChild;
+Frame.prototype.apch$ = document.apch$;
+Frame.prototype.getAttribute = document.getAttribute;
+Frame.prototype.setAttribute = document.setAttribute;
+Frame.prototype.insertBefore = document.insertBefore;
+Object.defineProperty(Frame.prototype, "firstChild", {
+get: function() { return this.childNodes[0]; }
+});
+Object.defineProperty(Frame.prototype, "lastChild", {
+get: function() { return this.childNodes[this.childNodes.length-1]; }
+});
+Frame.prototype.hasChildNodes = document.hasChildNodes;
+Frame.prototype.removeChild = document.removeChild;
+Frame.prototype.replaceChild = document.replaceChild;
+Frame.prototype.cloneNode = document.cloneNode;
+Frame.prototype.hasAttribute = document.hasAttribute;
+
 
 
 /* navigator; some parameters are filled in by the buildstartwindow script. */
@@ -1121,6 +1203,8 @@ this.async = false;
 
 this.method = method || "GET";
 this.url = convert_url(url);
+this.status = 0;
+this.statusText = "";
 this.onreadystatechange();
 },
 setRequestHeader: function(header, value){
@@ -1165,6 +1249,8 @@ this.readyState = 4;
 
 if ((!this.aborted) && this.responseText.length > 0){
 this.readyState = 4;
+this.status = 200;
+this.statusText = "OK";
 this.onreadystatechange();
 }
 
@@ -1247,3 +1333,55 @@ new_url = sideprotocol + '//' + sidehost + path;
 return new_url;
 }
 
+document.defaultView = function()
+{
+return this.style;
+}
+
+document.defaultView.getComputedStyle = function()
+{
+        obj = new CSSStyleDeclaration;
+        obj.element = document;
+        obj.style = document.style;
+        return obj;
+}
+
+getComputedStyle = function(n)
+{
+        obj = new CSSStyleDeclaration;
+        obj.element = this;
+        obj.style = new Array;
+        obj.style.push({n:obj.style[n]});
+        return obj;
+}
+
+CSSStyleDeclaration = function(){
+        this.element = null;
+        this.style = null;
+};
+
+CSSStyleDeclaration.prototype = {
+getPropertyValue: function (n)
+        {
+                if (this.style[n] == undefined)
+                {
+                        this.style[n] = 0;
+                        return 0;
+                } else {
+                        return this.style[n];
+                }
+        }
+}
+
+Event = function(options){
+    this._bubbles = true;
+    this._cancelable = true;
+    this._cancelled = false;
+    this._currentTarget = null;
+    this._target = null;
+    this._eventPhase = Event.AT_TARGET;
+    this._timeStamp = new Date().getTime();
+    this._preventDefault = false;
+    this._stopPropagation = false;
+};
+
-- 
1.8.3.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-06-30  4:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-30  4:35 [Edbrowse-dev] [PATCH] bundle of changes that makes diedrescher link work Kevin Carhart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).