Skip to content

Commit 8eac6fc

Browse files
committed
Applied misc and jsUgly patches
1 parent 5d186ec commit 8eac6fc

26 files changed

+252
-50
lines changed

src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.net.URL;
2828

2929
import org.eclipse.jdt.annotation.NonNull;
30+
import org.lobobrowser.ua.ParameterInfo;
31+
import org.lobobrowser.ua.RequestType;
32+
import org.lobobrowser.ua.TargetType;
3033
import org.w3c.dom.Document;
3134

3235
/**
@@ -84,4 +87,7 @@ public interface BrowserFrame {
8487
* See constants in {@link org.lobobrowser.html.style.RenderState}.
8588
*/
8689
public void setDefaultOverflowY(int overflowY);
90+
91+
// Trying out a way for a frame's target to be set to an iframe. for issue #96
92+
public void navigate(@NonNull URL url, String method, ParameterInfo pinfo, TargetType targetType, RequestType form);
8793
}

src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ public void setDir(final String dir) {
142142

143143
public final String getAttribute(final String name) {
144144
final String normalName = normalizeAttributeName(name);
145-
synchronized (this) {
146-
final Map<String, String> attributes = this.attributes;
147-
return attributes == null ? null : attributes.get(normalName);
148-
}
145+
// synchronized (this) {
146+
final Map<String, String> attributes = this.attributes;
147+
return attributes == null ? null : attributes.get(normalName);
148+
// }
149149
}
150150

151151
private Attr getAttr(final String normalName, final String value) {
@@ -174,6 +174,7 @@ protected static boolean isTagName(final Node node, final String name) {
174174
return node.getNodeName().equalsIgnoreCase(name);
175175
}
176176

177+
@Override
177178
public NodeList getElementsByTagName(final String name) {
178179
final boolean matchesAll = "*".equals(name);
179180
final List<Node> descendents = new LinkedList<>();
@@ -216,10 +217,11 @@ public String getTagName() {
216217

217218
public boolean hasAttribute(final String name) {
218219
final String normalName = normalizeAttributeName(name);
219-
synchronized (this) {
220-
final Map<String, String> attributes = this.attributes;
221-
return attributes == null ? false : attributes.containsKey(normalName);
222-
}
220+
// This was causing deadlocks, hence removed the sync
221+
// synchronized (this) {
222+
final Map<String, String> attributes = this.attributes;
223+
return attributes == null ? false : attributes.containsKey(normalName);
224+
// }
223225
}
224226

225227
public boolean hasAttributeNS(final String namespaceURI, final String localName) throws DOMException {

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLButtonElementImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public class HTMLButtonElementImpl extends HTMLBaseInputElement {
2424
public HTMLButtonElementImpl(final String name) {
2525
super(name);
2626
}
27+
28+
public void click() {
29+
// TODO: see issue #95
30+
System.out.println("Button clicked. TODO");
31+
// inputContext.click();
32+
}
2733
}

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLDocumentImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public HTMLDocumentImpl(final UserAgentContext ucontext, final HtmlRendererConte
158158
// with setCookie() method.
159159
final String protocol = docURL.getProtocol();
160160
if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) {
161-
sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect"));
161+
sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect"));
162162
}
163163
}
164164
this.documentURL = docURL;
@@ -279,6 +279,7 @@ public void setDefaultTarget(final String value) {
279279
this.defaultTarget = value;
280280
}
281281

282+
// TODO: Is this required? Check JS DOM specs.
282283
public AbstractView getDefaultView() {
283284
return this.window;
284285
}
@@ -414,16 +415,19 @@ public String getCookie() {
414415
}
415416

416417
public void setCookie(final String cookie) throws DOMException {
418+
// Update in gngr: Whoa! No, we won't allow the privilege escalation below until better justification is presented ;)
419+
// Chagned for Issue #78
420+
417421
// Justification: A caller (e.g. Google Analytics script)
418422
// might want to set cookies on the parent document.
419423
// If the caller has access to the document, it appears
420424
// they should be able to set cookies on that document.
421425
// Note that this Document instance cannot be created
422426
// with an arbitrary URL.
423-
SecurityUtil.doPrivileged(() -> {
424-
ucontext.setCookie(documentURL, cookie);
425-
return null;
426-
});
427+
// SecurityUtil.doPrivileged(() -> {
428+
ucontext.setCookie(documentURL, cookie);
429+
// return null;
430+
// });
427431
}
428432

429433
public void open() {
@@ -645,6 +649,7 @@ public EntityReference createEntityReference(final String name) throws DOMExcept
645649
* The element tag name or an asterisk character (*) to match all
646650
* elements.
647651
*/
652+
@Override
648653
public NodeList getElementsByTagName(final String tagname) {
649654
if ("*".equals(tagname)) {
650655
return this.getNodeList(new ElementFilter());

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLElementImpl.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
import org.w3c.dom.DOMException;
5353
import org.w3c.dom.Node;
5454
import org.w3c.dom.NodeList;
55+
import org.w3c.dom.events.Event;
56+
import org.w3c.dom.events.EventException;
57+
import org.w3c.dom.events.EventListener;
58+
import org.w3c.dom.events.EventTarget;
5559
import org.w3c.dom.html.HTMLElement;
5660
import org.w3c.dom.html.HTMLFormElement;
5761
import org.xml.sax.SAXException;
@@ -67,7 +71,7 @@
6771
import cz.vutbr.web.domassign.Analyzer.OrderedRule;
6872
import cz.vutbr.web.domassign.AnalyzerUtil;
6973

70-
public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext {
74+
public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext, EventTarget {
7175
private static final MatchConditionOnElements elementMatchCondition = new MatchConditionOnElements();
7276

7377
// TODO: noStyleSheet is not used. Consider removing.
@@ -310,6 +314,9 @@ protected void assignAttributeField(final String normalName, final String value)
310314
} else {
311315
if ("style".equals(normalName)) {
312316
this.forgetLocalStyle();
317+
// informDocumentInvalid();
318+
// informLayoutInvalid();
319+
// invalidateDescendentsForHover();
313320
}
314321
}
315322
super.assignAttributeField(normalName, value);
@@ -915,4 +922,22 @@ public boolean toggle(final String token, final boolean force) {
915922
/* TODO: stringifier; */
916923
}
917924

925+
@Override
926+
public void addEventListener(final String type, final EventListener listener, final boolean useCapture) {
927+
// TODO Auto-generated method stub
928+
throw new UnsupportedOperationException();
929+
}
930+
931+
@Override
932+
public void removeEventListener(final String type, final EventListener listener, final boolean useCapture) {
933+
// TODO Auto-generated method stub
934+
throw new UnsupportedOperationException();
935+
}
936+
937+
@Override
938+
public boolean dispatchEvent(final Event evt) throws EventException {
939+
// TODO Auto-generated method stub
940+
throw new UnsupportedOperationException();
941+
// return false;
942+
}
918943
}

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLIFrameElementImpl.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import org.lobobrowser.html.style.IFrameRenderState;
1212
import org.lobobrowser.html.style.RenderState;
1313
import org.lobobrowser.js.HideFromJS;
14+
import org.lobobrowser.ua.ParameterInfo;
15+
import org.lobobrowser.ua.RequestType;
16+
import org.lobobrowser.ua.TargetType;
1417
import org.lobobrowser.ua.UserAgentContext.Request;
1518
import org.lobobrowser.ua.UserAgentContext.RequestKind;
1619
import org.mozilla.javascript.Function;
@@ -270,4 +273,34 @@ public void run() {
270273
protected @NonNull RenderState createRenderState(final RenderState prevRenderState) {
271274
return new IFrameRenderState(prevRenderState, this);
272275
}
276+
277+
// Trying out a way for a frame's target to be set to an iframe. for issue #96
278+
279+
public void navigate(final @NonNull URL url, final String method, final ParameterInfo pinfo, final TargetType targetType, final RequestType form) {
280+
final Window window = ((HTMLDocumentImpl) document).getWindow();
281+
window.addJSTask(new JSRunnableTask(0, "Frame navigation to " + url, () -> {
282+
final BrowserFrame frame = this.browserFrame;
283+
if (frame != null) {
284+
if (getUserAgentContext().isRequestPermitted(new Request(url, RequestKind.Frame))) {
285+
frame.getHtmlRendererContext().setJobFinishedHandler(new Runnable() {
286+
public void run() {
287+
System.out.println("Iframes window's job over!");
288+
if (onload != null) {
289+
// TODO: onload event object?
290+
final Window window = ((HTMLDocumentImpl) document).getWindow();
291+
window.addJSTask(new JSRunnableTask(0, "IFrame onload handler", () -> {
292+
Executor.executeFunction(HTMLIFrameElementImpl.this, onload, null, window.getContextFactory());
293+
}));
294+
}
295+
// markJobDone();
296+
}
297+
});
298+
// frame.loadURL(fullURL);
299+
browserFrame.navigate(url, method, pinfo, targetType, form);
300+
}
301+
// browserFrame.navigate(url, method, pinfo, targetType, form);
302+
}
303+
}
304+
));
305+
}
273306
}

src/HTML_Renderer/org/lobobrowser/html/gui/HtmlBlockPanel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,10 @@ void disableRenderHints() {
654654
*
655655
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
656656
*/
657-
// protected void paintComponent(Graphics g) {
658657
@Override
659-
public void paint(final Graphics g) {
658+
protected void paintComponent(final Graphics g) {
659+
// public void paint(final Graphics g) {
660+
// Update to below: paintComponent seems to work fine too
660661
// We go against Sun's advice and override
661662
// paint() instead of paintComponent(). Scrollbars
662663
// do not repaint correctly if we use

src/HTML_Renderer/org/lobobrowser/html/js/Window.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,24 @@ public void run() {
14961496
jobsOver.set(true);
14971497
}
14981498

1499+
/*
14991500
@PropertyName("Element")
15001501
public Class<Element> getElement() {
15011502
return Element.class;
1503+
}*/
1504+
1505+
/* changed from above For prototype.js */
1506+
private Object element = Element.class;
1507+
1508+
@PropertyName("Element")
1509+
public Object getElement() {
1510+
return element;
1511+
}
1512+
1513+
@PropertyName("Element")
1514+
public void setElement(final Object o) {
1515+
System.out.println("Setting element to: " + o);
1516+
element = o;
15021517
}
15031518

15041519
@PropertyName("Node")

src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextAreaControl.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import java.awt.Font;
2727
import java.awt.FontMetrics;
2828
import java.awt.Insets;
29+
import java.awt.event.KeyEvent;
30+
import java.awt.event.KeyListener;
31+
import java.security.AccessController;
32+
import java.security.PrivilegedAction;
2933

3034
import javax.swing.JScrollPane;
3135
import javax.swing.JTextArea;
@@ -42,6 +46,23 @@ public InputTextAreaControl(final HTMLBaseInputElement modelNode) {
4246
super(modelNode);
4347
this.setLayout(WrapperLayout.getInstance());
4448
final JTextComponent widget = this.createTextField();
49+
widget.addKeyListener(new KeyListener() {
50+
51+
@Override
52+
public void keyTyped(final KeyEvent e) {
53+
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyTyped()" + e);
54+
}
55+
56+
@Override
57+
public void keyReleased(final KeyEvent e) {
58+
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyReleased()" + e);
59+
}
60+
61+
@Override
62+
public void keyPressed(final KeyEvent e) {
63+
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyPressed(): " + e);
64+
}
65+
});
4566
this.widget = widget;
4667
this.add(new JScrollPane(widget));
4768

@@ -78,7 +99,16 @@ public void reset(final int availWidth, final int availHeight) {
7899
}
79100

80101
protected JTextComponent createTextField() {
81-
return new JTextArea();
102+
// Creating with privileges; otherwise the AWT events generated for this component
103+
// capture the current stack of priviliges. If the component is created from javascript
104+
// it fails for AccessController.checkPermission('accessClipboard')
105+
return AccessController.doPrivileged(new PrivilegedAction<JTextComponent>() {
106+
107+
@Override
108+
public JTextComponent run() {
109+
return new JTextArea();
110+
}
111+
});
82112
}
83113

84114
/*

src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextControl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import java.awt.event.ActionEvent;
2727
import java.awt.event.ActionListener;
28+
import java.awt.event.KeyEvent;
29+
import java.awt.event.KeyListener;
2830

2931
import javax.swing.JTextField;
3032
import javax.swing.text.JTextComponent;
@@ -35,6 +37,22 @@ class InputTextControl extends BaseInputTextControl {
3537
public InputTextControl(final HTMLBaseInputElement modelNode) {
3638
super(modelNode);
3739
final JTextField w = (JTextField) this.widget;
40+
w.addKeyListener(new KeyListener() {
41+
@Override
42+
public void keyTyped(final KeyEvent e) {
43+
// System.out.println("typed: " + e);
44+
}
45+
46+
@Override
47+
public void keyReleased(final KeyEvent e) {
48+
HtmlController.getInstance().onKeyUp(modelNode, e);
49+
}
50+
51+
@Override
52+
public void keyPressed(final KeyEvent e) {
53+
// System.out.println("pressed: " + e);
54+
}
55+
});
3856
w.addActionListener(new ActionListener() {
3957
public void actionPerformed(final ActionEvent event) {
4058
HtmlController.getInstance().onEnterPressed(modelNode, null);

0 commit comments

Comments
 (0)