From c2061510c11b5155ec4d9492951e232a5311bd0a Mon Sep 17 00:00:00 2001 From: hrj Date: Sun, 13 Sep 2015 11:07:19 +0530 Subject: [PATCH] squashed commit of curr/jsUgly2 and curr/misc3 branches --- .../org/lobobrowser/html/BrowserFrame.java | 6 ++++ .../lobobrowser/html/domimpl/ElementImpl.java | 18 +++++----- .../html/domimpl/HTMLButtonElementImpl.java | 6 ++++ .../html/domimpl/HTMLDocumentImpl.java | 15 ++++++--- .../html/domimpl/HTMLElementImpl.java | 27 ++++++++++++++- .../html/domimpl/HTMLIFrameElementImpl.java | 33 +++++++++++++++++++ .../lobobrowser/html/gui/HtmlBlockPanel.java | 5 +-- .../org/lobobrowser/html/js/Window.java | 15 +++++++++ .../html/renderer/InputTextAreaControl.java | 32 +++++++++++++++++- .../html/renderer/InputTextControl.java | 18 ++++++++++ .../org/lobobrowser/html/renderer/RBlock.java | 6 ++-- .../html/renderer/RBlockViewport.java | 16 ++++++--- .../html/style/ComputedJStyleProperties.java | 3 +- .../html/style/JStyleProperties.java | 3 +- .../html/style/LocalJStyleProperties.java | 3 +- .../gui/AbstractBrowserWindow.java | 5 --- .../org/lobobrowser/gui/FramePanel.java | 11 +++++-- .../lobobrowser/gui/NavigatorWindowImpl.java | 3 +- .../org/lobobrowser/main/Extension.java | 4 +-- .../lobobrowser/request/RequestEngine.java | 18 ++++++---- .../request/SilentUserAgentContextImpl.java | 3 +- .../request/UserAgentContextImpl.java | 3 +- .../org/lobobrowser/ua/TargetType.java | 4 ++- .../clientlets/html/BrowserFrameImpl.java | 6 ++++ .../html/HtmlRendererContextImpl.java | 31 +++++++++++++++-- .../primary/ext/ComponentSource.java | 10 ++++-- 26 files changed, 253 insertions(+), 51 deletions(-) diff --git a/src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java b/src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java index 2256cb79..ba4ff5fd 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java +++ b/src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java @@ -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; /** @@ -83,4 +86,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); } diff --git a/src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java b/src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java index 3e5bc863..07fa1d04 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java +++ b/src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java @@ -143,10 +143,10 @@ public void setDir(final String dir) { public final String getAttribute(final String name) { final String normalName = normalizeAttributeName(name); - synchronized (this) { - final Map attributes = this.attributes; - return attributes == null ? null : attributes.get(normalName); - } + // synchronized (this) { + final Map attributes = this.attributes; + return attributes == null ? null : attributes.get(normalName); + // } } private Attr getAttr(final String normalName, final String value) { @@ -175,6 +175,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 descendents = new LinkedList<>(); @@ -217,10 +218,11 @@ public String getTagName() { public boolean hasAttribute(final String name) { final String normalName = normalizeAttributeName(name); - synchronized (this) { - final Map attributes = this.attributes; - return attributes == null ? false : attributes.containsKey(normalName); - } + // This was causing deadlocks, hence removed the sync + // synchronized (this) { + final Map attributes = this.attributes; + return attributes == null ? false : attributes.containsKey(normalName); + // } } public boolean hasAttributeNS(final String namespaceURI, final String localName) throws DOMException { diff --git a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLButtonElementImpl.java b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLButtonElementImpl.java index 7711934a..fa4797e8 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLButtonElementImpl.java +++ b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLButtonElementImpl.java @@ -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(); + } } diff --git a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLDocumentImpl.java b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLDocumentImpl.java index c9251577..58d69a39 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLDocumentImpl.java +++ b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLDocumentImpl.java @@ -159,7 +159,7 @@ public HTMLDocumentImpl(final UserAgentContext ucontext, final HtmlRendererConte // with setCookie() method. final String protocol = docURL.getProtocol(); if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) { - sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect")); + sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect")); } } this.documentURL = docURL; @@ -264,6 +264,7 @@ public void setDefaultTarget(final String value) { this.defaultTarget = value; } + // TODO: Is this required? Check JS DOM specs. public AbstractView getDefaultView() { return this.window; } @@ -399,16 +400,19 @@ public String getCookie() { } public void setCookie(final String cookie) throws DOMException { + // Update in gngr: Whoa! No, we won't allow the privilege escalation below until better justification is presented ;) + // Chagned for Issue #78 + // Justification: A caller (e.g. Google Analytics script) // might want to set cookies on the parent document. // If the caller has access to the document, it appears // they should be able to set cookies on that document. // Note that this Document instance cannot be created // with an arbitrary URL. - SecurityUtil.doPrivileged(() -> { - ucontext.setCookie(documentURL, cookie); - return null; - }); + // SecurityUtil.doPrivileged(() -> { + ucontext.setCookie(documentURL, cookie); + // return null; + // }); } public void open() { @@ -630,6 +634,7 @@ public EntityReference createEntityReference(final String name) throws DOMExcept * The element tag name or an asterisk character (*) to match all * elements. */ + @Override public NodeList getElementsByTagName(final String tagname) { if ("*".equals(tagname)) { return this.getNodeList(new ElementFilter()); diff --git a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLElementImpl.java b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLElementImpl.java index 4eee56c1..7f399eb7 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLElementImpl.java +++ b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLElementImpl.java @@ -53,6 +53,10 @@ import org.w3c.dom.DOMException; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.w3c.dom.events.Event; +import org.w3c.dom.events.EventException; +import org.w3c.dom.events.EventListener; +import org.w3c.dom.events.EventTarget; import org.w3c.dom.html.HTMLElement; import org.w3c.dom.html.HTMLFormElement; @@ -73,7 +77,7 @@ import cz.vutbr.web.domassign.Analyzer.OrderedRule; import cz.vutbr.web.domassign.AnalyzerUtil; -public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext { +public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext, EventTarget { private final boolean noStyleSheet; private static final MatchConditionOnElements elementMatchCondition = new MatchConditionOnElements(); @@ -315,6 +319,9 @@ protected void assignAttributeField(final String normalName, final String value) } else { if ("style".equals(normalName)) { this.forgetLocalStyle(); + // informDocumentInvalid(); + // informLayoutInvalid(); + // invalidateDescendentsForHover(); } } super.assignAttributeField(normalName, value); @@ -923,4 +930,22 @@ public boolean toggle(final String token, final boolean force) { /* TODO: stringifier; */ } + @Override + public void addEventListener(final String type, final EventListener listener, final boolean useCapture) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException(); + } + + @Override + public void removeEventListener(final String type, final EventListener listener, final boolean useCapture) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException(); + } + + @Override + public boolean dispatchEvent(final Event evt) throws EventException { + // TODO Auto-generated method stub + throw new UnsupportedOperationException(); + // return false; + } } diff --git a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLIFrameElementImpl.java b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLIFrameElementImpl.java index 44dcff7c..ddf07f5c 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLIFrameElementImpl.java +++ b/src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLIFrameElementImpl.java @@ -10,6 +10,9 @@ import org.lobobrowser.html.style.IFrameRenderState; import org.lobobrowser.html.style.RenderState; import org.lobobrowser.js.HideFromJS; +import org.lobobrowser.ua.ParameterInfo; +import org.lobobrowser.ua.RequestType; +import org.lobobrowser.ua.TargetType; import org.lobobrowser.ua.UserAgentContext.Request; import org.lobobrowser.ua.UserAgentContext.RequestKind; import org.mozilla.javascript.Function; @@ -269,4 +272,34 @@ public void run() { protected RenderState createRenderState(final RenderState prevRenderState) { return new IFrameRenderState(prevRenderState, this); } + + // Trying out a way for a frame's target to be set to an iframe. for issue #96 + + public void navigate(final URL url, final String method, final ParameterInfo pinfo, final TargetType targetType, final RequestType form) { + final Window window = ((HTMLDocumentImpl) document).getWindow(); + window.addJSTask(new JSRunnableTask(0, "Frame navigation to " + url, () -> { + final BrowserFrame frame = this.browserFrame; + if (frame != null) { + if (getUserAgentContext().isRequestPermitted(new Request(url, RequestKind.Frame))) { + frame.getHtmlRendererContext().setJobFinishedHandler(new Runnable() { + public void run() { + System.out.println("Iframes window's job over!"); + if (onload != null) { + // TODO: onload event object? + final Window window = ((HTMLDocumentImpl) document).getWindow(); + window.addJSTask(new JSRunnableTask(0, "IFrame onload handler", () -> { + Executor.executeFunction(HTMLIFrameElementImpl.this, onload, null, window.getContextFactory()); + })); + } + // markJobDone(); + } + }); + // frame.loadURL(fullURL); + browserFrame.navigate(url, method, pinfo, targetType, form); + } + // browserFrame.navigate(url, method, pinfo, targetType, form); + } + } + )); + } } diff --git a/src/HTML_Renderer/org/lobobrowser/html/gui/HtmlBlockPanel.java b/src/HTML_Renderer/org/lobobrowser/html/gui/HtmlBlockPanel.java index 6227bd58..081b5091 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/gui/HtmlBlockPanel.java +++ b/src/HTML_Renderer/org/lobobrowser/html/gui/HtmlBlockPanel.java @@ -646,9 +646,10 @@ private void onMouseMoved(final MouseEvent event) { * * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) */ - // protected void paintComponent(Graphics g) { @Override - public void paint(final Graphics g) { + protected void paintComponent(final Graphics g) { + // public void paint(final Graphics g) { + // Update to below: paintComponent seems to work fine too // We go against Sun's advice and override // paint() instead of paintComponent(). Scrollbars // do not repaint correctly if we use diff --git a/src/HTML_Renderer/org/lobobrowser/html/js/Window.java b/src/HTML_Renderer/org/lobobrowser/html/js/Window.java index 9778776b..80d3c5dd 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/js/Window.java +++ b/src/HTML_Renderer/org/lobobrowser/html/js/Window.java @@ -1452,9 +1452,24 @@ public void run() { // jobsOver.set(true); } + /* @PropertyName("Element") public Class getElement() { return Element.class; + }*/ + + /* changed from above For prototype.js */ + private Object element = Element.class; + + @PropertyName("Element") + public Object getElement() { + return element; + } + + @PropertyName("Element") + public void setElement(final Object o) { + System.out.println("Setting element to: " + o); + element = o; } @PropertyName("Node") diff --git a/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextAreaControl.java b/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextAreaControl.java index 40596773..47288059 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextAreaControl.java +++ b/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextAreaControl.java @@ -26,6 +26,10 @@ import java.awt.Font; import java.awt.FontMetrics; import java.awt.Insets; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.security.AccessController; +import java.security.PrivilegedAction; import javax.swing.JScrollPane; import javax.swing.JTextArea; @@ -42,6 +46,23 @@ public InputTextAreaControl(final HTMLBaseInputElement modelNode) { super(modelNode); this.setLayout(WrapperLayout.getInstance()); final JTextComponent widget = this.createTextField(); + widget.addKeyListener(new KeyListener() { + + @Override + public void keyTyped(final KeyEvent e) { + System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyTyped()" + e); + } + + @Override + public void keyReleased(final KeyEvent e) { + System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyReleased()" + e); + } + + @Override + public void keyPressed(final KeyEvent e) { + System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyPressed(): " + e); + } + }); this.widget = widget; this.add(new JScrollPane(widget)); @@ -78,7 +99,16 @@ public void reset(final int availWidth, final int availHeight) { } protected JTextComponent createTextField() { - return new JTextArea(); + // Creating with privileges; otherwise the AWT events generated for this component + // capture the current stack of priviliges. If the component is created from javascript + // it fails for AccessController.checkPermission('accessClipboard') + return AccessController.doPrivileged(new PrivilegedAction() { + + @Override + public JTextComponent run() { + return new JTextArea(); + } + }); } /* diff --git a/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextControl.java b/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextControl.java index 478d0007..4497e27b 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextControl.java +++ b/src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextControl.java @@ -25,6 +25,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import javax.swing.JTextField; import javax.swing.text.JTextComponent; @@ -35,6 +37,22 @@ class InputTextControl extends BaseInputTextControl { public InputTextControl(final HTMLBaseInputElement modelNode) { super(modelNode); final JTextField w = (JTextField) this.widget; + w.addKeyListener(new KeyListener() { + @Override + public void keyTyped(final KeyEvent e) { + // System.out.println("typed: " + e); + } + + @Override + public void keyReleased(final KeyEvent e) { + HtmlController.getInstance().onKeyUp(modelNode, e); + } + + @Override + public void keyPressed(final KeyEvent e) { + // System.out.println("pressed: " + e); + } + }); w.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { HtmlController.getInstance().onEnterPressed(modelNode, null); diff --git a/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlock.java b/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlock.java index 519639f2..41cf4853 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlock.java +++ b/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlock.java @@ -490,9 +490,11 @@ private final LayoutValue forceLayout(final RenderState renderState, final int a // Expected to be invoked in the GUI thread. // TODO: Not necessary to do full layout if only expandWidth or // expandHeight change (specifically in tables). - RenderState rs = renderState; + final RenderState rs = renderState; if (rs == null) { - rs = new BlockRenderState(null); + // Doesn't seem to be null ever + throw new IllegalStateException("rs was null"); + // rs = new BlockRenderState(null); } // // Clear adjust() cache. diff --git a/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlockViewport.java b/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlockViewport.java index ee4c3450..6dcdab0d 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlockViewport.java +++ b/src/HTML_Renderer/org/lobobrowser/html/renderer/RBlockViewport.java @@ -2362,10 +2362,10 @@ public void layoutMarkup(final RBlockViewport bodyLayout, final HTMLElementImpl } } } + final UINode node = markupElement.getUINode(); switch (display) { case DISPLAY_NONE: // skip it completely. - final UINode node = markupElement.getUINode(); if (node instanceof BaseBoundableRenderable) { // This is necessary so that if the element is made // visible again, it can be invalidated. @@ -2374,16 +2374,24 @@ public void layoutMarkup(final RBlockViewport bodyLayout, final HTMLElementImpl break; case DISPLAY_BLOCK: //TODO refer issue #87 + if (node instanceof RTable) { + bodyLayout.layoutRTable(markupElement); + } else { + bodyLayout.layoutRBlock(markupElement); + } + break; + case DISPLAY_LIST_ITEM: final String tagName = markupElement.getTagName(); if ("UL".equalsIgnoreCase(tagName) || "OL".equalsIgnoreCase(tagName)) { bodyLayout.layoutList(markupElement); } else { - bodyLayout.layoutRBlock(markupElement); + // bodyLayout.layoutRBlock(markupElement); + bodyLayout.layoutListItem(markupElement); } break; - case DISPLAY_LIST_ITEM: + /*case DISPLAY_LIST_ITEM: bodyLayout.layoutListItem(markupElement); - break; + break;*/ case DISPLAY_TABLE: bodyLayout.layoutRTable(markupElement); break; diff --git a/src/HTML_Renderer/org/lobobrowser/html/style/ComputedJStyleProperties.java b/src/HTML_Renderer/org/lobobrowser/html/style/ComputedJStyleProperties.java index 616540f1..8bde3799 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/style/ComputedJStyleProperties.java +++ b/src/HTML_Renderer/org/lobobrowser/html/style/ComputedJStyleProperties.java @@ -624,8 +624,9 @@ public void setZIndex(final String zIndex) throws DOMException { throw new UnsupportedOperationException(); } + // TODO: Temporary made public @Override - protected NodeData getNodeData() { + public NodeData getNodeData() { return this.nodeData; } } diff --git a/src/HTML_Renderer/org/lobobrowser/html/style/JStyleProperties.java b/src/HTML_Renderer/org/lobobrowser/html/style/JStyleProperties.java index 1a4f917e..a9c5d95c 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/style/JStyleProperties.java +++ b/src/HTML_Renderer/org/lobobrowser/html/style/JStyleProperties.java @@ -651,7 +651,8 @@ public String getFloat() { return helperGetProperty("float"); } - abstract protected NodeData getNodeData(); + // TODO: temporary made public + abstract public NodeData getNodeData(); private static final Pattern inchPattern = Pattern.compile("[0-9]+(.[0-9]+)?in"); diff --git a/src/HTML_Renderer/org/lobobrowser/html/style/LocalJStyleProperties.java b/src/HTML_Renderer/org/lobobrowser/html/style/LocalJStyleProperties.java index 67196cd6..0bdd99af 100644 --- a/src/HTML_Renderer/org/lobobrowser/html/style/LocalJStyleProperties.java +++ b/src/HTML_Renderer/org/lobobrowser/html/style/LocalJStyleProperties.java @@ -631,8 +631,9 @@ public void setZIndex(final String zIndex) throws DOMException { updateInlineStyle("z-index", zIndex); } + // TODO: Temp made public @Override - protected NodeData getNodeData() { + public NodeData getNodeData() { final HTMLElementImpl ele = this.element; final String inlineStyle = ele.getAttribute("style"); if ((inlineStyle != null) && (inlineStyle.length() > 0)) { diff --git a/src/Platform_Core/org/lobobrowser/gui/AbstractBrowserWindow.java b/src/Platform_Core/org/lobobrowser/gui/AbstractBrowserWindow.java index c110d224..ff0b748c 100644 --- a/src/Platform_Core/org/lobobrowser/gui/AbstractBrowserWindow.java +++ b/src/Platform_Core/org/lobobrowser/gui/AbstractBrowserWindow.java @@ -26,11 +26,6 @@ * Browser windows should extend this class. */ public abstract class AbstractBrowserWindow extends JFrame implements BrowserWindow { - /** - * Gets the root {@link FramePanel} of the window. - */ - public abstract FramePanel getTopFramePanel(); - /** * Gets a {@link WindowCallback} instance that receives navigation * notifications. This method may return null. diff --git a/src/Platform_Core/org/lobobrowser/gui/FramePanel.java b/src/Platform_Core/org/lobobrowser/gui/FramePanel.java index 4fceca7b..4dd096a8 100644 --- a/src/Platform_Core/org/lobobrowser/gui/FramePanel.java +++ b/src/Platform_Core/org/lobobrowser/gui/FramePanel.java @@ -110,7 +110,8 @@ public class FramePanel extends JPanel implements NavigatorFrame { private final Object propertiesMonitor = new Object(); private NavigatorFrame openerFrame; - private Window topFrameWindow; + + // private Window topFrameWindow; /** * Constructs a FramePanel specifying a "window" ID. @@ -722,6 +723,11 @@ private void navigate(final NavigationEvent event) { case SELF: this.navigateLocal(event); break; + case NAMED: + // TODO + final NavigatorFrame namedFrame = null; + namedFrame.navigate(url, method, paramInfo, TargetType.SELF, requestType, this); + break; case BLANK: this.open(url, method, paramInfo); break; @@ -1230,13 +1236,14 @@ public void resizeWindowTo(final int width, final int height) { } } + /* public Window getTopFrameWindow() { return topFrameWindow; } public void setTopFrameWindow(final Window topFrameWindow) { this.topFrameWindow = topFrameWindow; - } + }*/ /** * Gets an object that is used to represent the current frame content. For diff --git a/src/Platform_Core/org/lobobrowser/gui/NavigatorWindowImpl.java b/src/Platform_Core/org/lobobrowser/gui/NavigatorWindowImpl.java index 2534e19a..505c1e0d 100644 --- a/src/Platform_Core/org/lobobrowser/gui/NavigatorWindowImpl.java +++ b/src/Platform_Core/org/lobobrowser/gui/NavigatorWindowImpl.java @@ -382,7 +382,8 @@ public void toBack() { } public NavigatorFrame getTopFrame() { - return this.framePanel; + // TODO: This needs to be checked. In some quick tests like loading reddit, things seem to work fine whether we return framePanel or framePanel.getTopFrame() + return this.framePanel.getTopFrame(); } public void statusUpdated(final NavigatorFrame clientletFrame, final String value) { diff --git a/src/Platform_Core/org/lobobrowser/main/Extension.java b/src/Platform_Core/org/lobobrowser/main/Extension.java index 3ca77607..3ec2fb22 100644 --- a/src/Platform_Core/org/lobobrowser/main/Extension.java +++ b/src/Platform_Core/org/lobobrowser/main/Extension.java @@ -278,14 +278,14 @@ protected V doWithClassLoader(final Callable r) { final ClassLoader prevClassLoader = currentThread.getContextClassLoader(); final ClassLoader loader = this.classLoader; if (loader != null) { - currentThread.setContextClassLoader(loader); + // currentThread.setContextClassLoader(loader); } try { return r.call(); } catch (final Exception e) { throw new Error(e); } finally { - currentThread.setContextClassLoader(prevClassLoader); + // currentThread.setContextClassLoader(prevClassLoader); } } diff --git a/src/Platform_Core/org/lobobrowser/request/RequestEngine.java b/src/Platform_Core/org/lobobrowser/request/RequestEngine.java index 3d9ad16c..c8cb9bf0 100644 --- a/src/Platform_Core/org/lobobrowser/request/RequestEngine.java +++ b/src/Platform_Core/org/lobobrowser/request/RequestEngine.java @@ -129,11 +129,14 @@ public String getCookie(final java.net.URL url) { return cookieText.toString(); } - public void setCookie(final URL url, final String cookieSpec) { - try { - this.cookieStore.saveCookie(url.toURI(), cookieSpec); - } catch (final URISyntaxException e) { - throw new RuntimeException(e); + public void setCookie(final URL url, final String cookieSpec, final UserAgentContext uaContext) { + // changed for issue #78 + if (uaContext.isRequestPermitted(new Request(url, RequestKind.Cookie))) { + try { + this.cookieStore.saveCookie(url.toURI(), cookieSpec); + } catch (final URISyntaxException e) { + throw new RuntimeException(e); + } } } @@ -776,7 +779,7 @@ private void processHandler(final RequestHandler rhandler, final int recursionLe hconnection.setInstanceFollowRedirects(false); final int responseCode = hconnection.getResponseCode(); logInfo("run(): ResponseCode=" + responseCode + " for url=" + connectionUrl); - dumpResponseInfo(connection); + // dumpResponseInfo(connection); handleCookies(connectionUrl, hconnection, rhandler); if (responseCode == HttpURLConnection.HTTP_OK) { @@ -905,7 +908,8 @@ private void addCookiesToRequest(final URLConnection connection, final RequestHa final String protocol = connection.getURL().getProtocol(); if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) { final URL url = connection.getURL(); - final URI uri = url.toURI(); + final URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), + url.getRef()); // TODO: optimization #1: list is not required if we directly call our CookieHandler implementation // TODO: optimization #2: even if we use the CookieHandler interface, we can avoid the joining of List entries, since our impl always returns a single element list final Map> cookieHeaders = cookieHandler.get(uri, null); diff --git a/src/Platform_Core/org/lobobrowser/request/SilentUserAgentContextImpl.java b/src/Platform_Core/org/lobobrowser/request/SilentUserAgentContextImpl.java index bb8b92cf..eb8ef66b 100644 --- a/src/Platform_Core/org/lobobrowser/request/SilentUserAgentContextImpl.java +++ b/src/Platform_Core/org/lobobrowser/request/SilentUserAgentContextImpl.java @@ -122,7 +122,8 @@ public boolean isScriptingEnabled() { public void setCookie(final java.net.URL url, final String cookieSpec) { // Requires privileges. - RequestEngine.getInstance().setCookie(url, cookieSpec); + // Changed for issue #78 + RequestEngine.getInstance().setCookie(url, cookieSpec, this); } public Policy getSecurityPolicy() { diff --git a/src/Platform_Core/org/lobobrowser/request/UserAgentContextImpl.java b/src/Platform_Core/org/lobobrowser/request/UserAgentContextImpl.java index 08ada09b..ff0c38a2 100644 --- a/src/Platform_Core/org/lobobrowser/request/UserAgentContextImpl.java +++ b/src/Platform_Core/org/lobobrowser/request/UserAgentContextImpl.java @@ -137,7 +137,8 @@ public boolean isScriptingEnabled() { public void setCookie(final java.net.URL url, final String cookieSpec) { // Requires privileges. - RequestEngine.getInstance().setCookie(url, cookieSpec); + // changed for issue #78 + RequestEngine.getInstance().setCookie(url, cookieSpec, this); } public Policy getSecurityPolicy() { diff --git a/src/Platform_Public_API/org/lobobrowser/ua/TargetType.java b/src/Platform_Public_API/org/lobobrowser/ua/TargetType.java index 6521f768..1abfa146 100644 --- a/src/Platform_Public_API/org/lobobrowser/ua/TargetType.java +++ b/src/Platform_Public_API/org/lobobrowser/ua/TargetType.java @@ -36,5 +36,7 @@ public enum TargetType { /** Document should be opened in the parent frame. */ PARENT, /** Document should be opened in the top frame of the current window. */ - TOP + TOP, + /** Document should be opened in named frame. */ + NAMED } diff --git a/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/BrowserFrameImpl.java b/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/BrowserFrameImpl.java index bcedf015..7902ab10 100644 --- a/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/BrowserFrameImpl.java +++ b/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/BrowserFrameImpl.java @@ -32,6 +32,7 @@ import org.lobobrowser.html.BrowserFrame; import org.lobobrowser.html.HtmlRendererContext; import org.lobobrowser.ua.NavigatorFrame; +import org.lobobrowser.ua.ParameterInfo; import org.lobobrowser.ua.RequestType; import org.lobobrowser.ua.TargetType; @@ -82,4 +83,9 @@ public void setDefaultOverflowX(final int overflowX) { public void setDefaultOverflowY(final int overflowY) { this.frame.setProperty("defaultOverflowY", overflowY); } + + // Trying out a way for a frame's target to be set to an iframe. for issue #96 + public void navigate(final URL url, final String method, final ParameterInfo pinfo, final TargetType targetType, final RequestType form) { + frame.navigate(url, method, pinfo, targetType, form); + } } diff --git a/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/HtmlRendererContextImpl.java b/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/HtmlRendererContextImpl.java index 12bc1b6b..85566cc6 100644 --- a/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/HtmlRendererContextImpl.java +++ b/src/Primary_Extension/org/lobobrowser/primary/clientlets/html/HtmlRendererContextImpl.java @@ -33,6 +33,7 @@ import java.lang.ref.WeakReference; import java.net.MalformedURLException; import java.net.URL; +import java.util.Arrays; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -49,6 +50,7 @@ import org.lobobrowser.html.HtmlRendererContext; import org.lobobrowser.html.domimpl.FrameNode; import org.lobobrowser.html.domimpl.HTMLDocumentImpl; +import org.lobobrowser.html.domimpl.HTMLIFrameElementImpl; import org.lobobrowser.html.domimpl.HTMLImageElementImpl; import org.lobobrowser.html.domimpl.HTMLLinkElementImpl; import org.lobobrowser.html.gui.HtmlPanel; @@ -166,15 +168,35 @@ private static TargetType getTargetType(final String target) { return TargetType.PARENT; } else if ("_top".equalsIgnoreCase(target)) { return TargetType.TOP; + } else if ((target != null) && (target.trim().length() > 0)) { + return TargetType.NAMED; } else { return TargetType.SELF; } } public void submitForm(final String method, final URL url, final String target, final String enctype, final FormInput[] formInputs) { + System.out.println("Submitting form to " + target); final TargetType targetType = HtmlRendererContextImpl.getTargetType(target); - final ParameterInfo pinfo = new LocalParameterInfo(enctype, formInputs); - this.clientletFrame.navigate(url, method, pinfo, targetType, RequestType.FORM); + System.out.println("target type " + targetType); + if (targetType == TargetType.NAMED) { + final HTMLCollection frames = getFrames(); + for (int i = 0; i < frames.getLength(); i++) { + final Node frame = frames.item(i); + if (frame instanceof HTMLIFrameElementImpl) { + final HTMLIFrameElementImpl iframe = (HTMLIFrameElementImpl) frame; + final String name = iframe.getAttribute("name"); + System.out.println("Found iframe with name: " + name); + final ParameterInfo pinfo = new LocalParameterInfo(enctype, formInputs); + iframe.navigate(url, method, pinfo, TargetType.SELF, RequestType.FORM); + return; + } + } + } else { + + final ParameterInfo pinfo = new LocalParameterInfo(enctype, formInputs); + this.clientletFrame.navigate(url, method, pinfo, targetType, RequestType.FORM); + } } public BrowserFrame createBrowserFrame() { @@ -595,6 +617,11 @@ public boolean isText() { } return params; } + + @Override + public String toString() { + return Arrays.toString(formInputs); + } } public void setCursor(final Optional cursorOpt) { diff --git a/src/Primary_Extension/org/lobobrowser/primary/ext/ComponentSource.java b/src/Primary_Extension/org/lobobrowser/primary/ext/ComponentSource.java index f6fdfa1b..3bee7400 100644 --- a/src/Primary_Extension/org/lobobrowser/primary/ext/ComponentSource.java +++ b/src/Primary_Extension/org/lobobrowser/primary/ext/ComponentSource.java @@ -363,10 +363,14 @@ private static boolean isHistoryRequest(final RequestType requestType) { public void documentAccessed(final NavigatorWindowEvent event) { final java.net.URL url = event.getUrl(); + final boolean isRootEvent = event.getNavigatorFrame().getParentFrame() == null; + if (isRootEvent) { - // TODO: Have a better condition for isManageable, or change requestManager to deal with other protocols as well - final boolean isManageable = "http".equals(url.getProtocol()) || "https".equals(url.getProtocol()); - reqManagerButton.getAction().setEnabled(isManageable); + // TODO: Have a better condition for isManageable, or change requestManager to deal with other protocols as well + final boolean isManageable = "http".equals(url.getProtocol()) || "https".equals(url.getProtocol()); + reqManagerButton.getAction().setEnabled(isManageable); + // reqManagerButton.getAction().setEnabled(true); + } if ("GET".equals(event.getMethod()) && isHistoryRequest(event.getRequestType())) { NavigationHistory.getInstance().addAsRecent(url, null);