Skip to content

Commit

Permalink
Squashed commit of jsUgly2, misc2 and optim branches
Browse files Browse the repository at this point in the history
  • Loading branch information
hrj committed Feb 28, 2015
1 parent 1c22929 commit 677e04a
Show file tree
Hide file tree
Showing 55 changed files with 2,503 additions and 363 deletions.
6 changes: 5 additions & 1 deletion src/Common/org/lobobrowser/util/Urls.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ public static Long getExpiration(final URLConnection connection, final long base
}
}
}
return null;

// TODO: For issue #99
// When there is no cache setting; assume a 60 second cache expiry time for now.
// return null;
return baseTime + (60 * 1000);
}

public static List<NameValuePair> getHeaders(final URLConnection connection) {
Expand Down
6 changes: 6 additions & 0 deletions src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.awt.Component;
import java.net.URL;

import org.lobobrowser.ua.ParameterInfo;
import org.lobobrowser.ua.RequestType;
import org.lobobrowser.ua.TargetType;
import org.w3c.dom.Document;

/**
Expand Down Expand Up @@ -78,4 +81,7 @@ public interface BrowserFrame {
* See constants in {@link org.lobobrowser.html.style.RenderState}.
*/
public void setDefaultOverflowY(int overflowY);

// Trying out a way for a frame's target to be set to an iframe. for issue #96
public void navigate(URL url, String method, ParameterInfo pinfo, TargetType targetType, RequestType form);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import java.util.Map;

import org.lobobrowser.js.AbstractScriptableDelegate;
import org.lobobrowser.js.JavaScript;
import org.lobobrowser.util.Nodes;
import org.lobobrowser.util.Objects;
import org.w3c.dom.Node;
import org.w3c.dom.html.HTMLCollection;

Expand Down Expand Up @@ -116,6 +118,31 @@ public Node item(final int index) {
}
}

public Node item(final Object obj) {
// Assuming that non integer calls are supposed to be treated as zero, as per this test:
// https://github.com/w3c/web-platform-tests/blob/master/dom/nodes/Element-children.html#L10
// Reported bug https://github.com/w3c/web-platform-tests/issues/1264
if (obj instanceof Integer) {
final Integer index = (Integer) obj;
return item((int) index);
}
return item(0);
}

/* Quick hack to get w3c tests working. This function very likely needs to
* be included for every JS object. */
public boolean hasOwnProperty(final Object obj) {
System.out.println("Checking " + obj);
if (Objects.isAssignableOrBox(obj, Integer.TYPE)) {
// if (obj instanceof Integer) {
final Integer i = (Integer) JavaScript.getInstance().getJavaObject(obj, Integer.TYPE);
// final Integer i = (Integer) obj;
return i < getLength();
} else {
return false;
}
}

public Node namedItem(final String name) {
synchronized (this.treeLock) {
this.ensurePopulatedImpl();
Expand Down
18 changes: 10 additions & 8 deletions src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ public void setDir(final String dir) {

public final String getAttribute(final String name) {
final String normalName = normalizeAttributeName(name);
synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? null : attributes.get(normalName);
}
// synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? null : attributes.get(normalName);
// }
}

private Attr getAttr(final String normalName, final String value) {
Expand Down Expand Up @@ -171,6 +171,7 @@ protected static boolean isTagName(final Node node, final String name) {
return node.getNodeName().equalsIgnoreCase(name);
}

@Override
public NodeList getElementsByTagName(final String name) {
final boolean matchesAll = "*".equals(name);
final List<Node> descendents = new LinkedList<>();
Expand Down Expand Up @@ -213,10 +214,11 @@ public String getTagName() {

public boolean hasAttribute(final String name) {
final String normalName = normalizeAttributeName(name);
synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? false : attributes.containsKey(normalName);
}
// This was causing deadlocks, hence removed the sync
// synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? false : attributes.containsKey(normalName);
// }
}

public boolean hasAttributeNS(final String namespaceURI, final String localName) throws DOMException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.logging.Level;

import org.lobobrowser.html.js.Executor;
import org.lobobrowser.html.js.Window;
import org.lobobrowser.js.JavaScript;
import org.lobobrowser.ua.UserAgentContext;
import org.mozilla.javascript.Context;
Expand Down Expand Up @@ -170,12 +171,12 @@ protected Function getEventFunction(final Function varValue, final String attrib
if (doc == null) {
throw new IllegalStateException("Element does not belong to a document.");
}
final Context ctx = Executor.createContext(this.getDocumentURL(), uac);
final Window window = ((HTMLDocumentImpl) doc).getWindow();
final Context ctx = Executor.createContext(this.getDocumentURL(), uac, window.windowFactory);
try {
final Scriptable scope = (Scriptable) doc.getUserData(Executor.SCOPE_KEY);
final Scriptable scope = window.getWindowScope();
if (scope == null) {
throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using "
+ Executor.SCOPE_KEY);
throw new IllegalStateException("Scriptable (scope) instance was null");
}
final Scriptable thisScope = (Scriptable) JavaScript.getInstance().getJavascriptObject(this, scope);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import java.util.ArrayList;

import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.js.Executor;
import org.lobobrowser.html.js.Event;
import org.lobobrowser.html.js.NotGetterSetter;
import org.mozilla.javascript.Function;
import org.w3c.dom.Node;
import org.w3c.dom.html.HTMLFormElement;
Expand Down Expand Up @@ -381,11 +382,16 @@ private void dispatchEvent(final String expectedImgSrc, final ImageEvent event)
// Inform listener, holding no lock.
listenerArray[i].imageLoaded(event);
}

// TODO: With this change, setOnLoad method should add a listener with dispatch mechanism. Best implemented in a parent class.
dispatchEvent(new Event("load", this));

/*
final Function onload = this.getOnload();
if (onload != null) {
// TODO: onload event object?
Executor.executeFunction(HTMLBaseInputElement.this, onload, null);
}
}*/
}

private class LocalImageListener implements ImageListener {
Expand All @@ -398,6 +404,14 @@ public LocalImageListener(final String imgSrc) {
public void imageLoaded(final ImageEvent event) {
dispatchEvent(this.expectedImgSrc, event);
}

public void imageAborted() {
// Do nothing
}
}

@NotGetterSetter
public void setCustomValidity(final String message) {
System.out.println("HTMLBaseInputElement.setCustomValidity() " + message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ public class HTMLButtonElementImpl extends HTMLBaseInputElement {
public HTMLButtonElementImpl(final String name) {
super(name);
}

public void click() {
// TODO: see issue #95
System.out.println("Button clicked. TODO");
// inputContext.click();
}
}
Loading

0 comments on commit 677e04a

Please sign in to comment.