/** * Handles the cookies specified in meta tags, * like <tt><meta http-equiv='set-cookie' content='webm=none; path=/;'></tt>. */ protected void performSetCookie() { final SgmlPage page = getPage(); final WebClient client = page.getWebClient(); final URL url = page.getUrl(); client.addCookie(getContentAttribute(), url, this); }
/** * Creates a clone of this instance, and clears cached state * to be not shared with the original. * * @return a clone of this instance */ @Override protected HtmlPage clone() { final HtmlPage result = (HtmlPage) super.clone(); result.elementWithFocus_ = null; result.idMap_ = new HashMap<String, List<HtmlElement>>(); result.nameMap_ = new HashMap<String, List<HtmlElement>>(); return result; }
private boolean isQuirksDocType() { final DocumentType docType = getPage().getDoctype(); if (docType != null) { final String systemId = docType.getSystemId(); if (systemId != null) { if ("http://www.w3.org/TR/html4/strict.dtd".equals(systemId)) { return false; } if ("http://www.w3.org/TR/html4/loose.dtd".equals(systemId)) { final String publicId = docType.getPublicId(); if ("-//W3C//DTD HTML 4.01 Transitional//EN".equals(publicId)) { return false; } } if ("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd".equals(systemId) || "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd".equals(systemId)) { return false; } } else if (docType.getPublicId() == null) { return docType.getName() == null; } } return true; }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * Helper for a common call sequence. * @param feature the feature to check * @return {@code true} if the currently emulated browser has this feature. */ public boolean hasFeature(final BrowserVersionFeatures feature) { return getPage().getWebClient().getBrowserVersion().hasFeature(feature); }
/** * {@inheritDoc} */ @Override public HtmlElement getDocumentElement() { return (HtmlElement) super.getDocumentElement(); }
/** * Creates a new document fragment. * @return a newly created document fragment */ public Object jsxFunction_createDocumentFragment() { final DomDocumentFragment fragment = getDomNodeOrDie().getPage().createDomDocumentFragment(); final DocumentFragment node = new DocumentFragment(); node.setParentScope(getParentScope()); node.setPrototype(getPrototype(node.getClass())); node.setDomNode(fragment); return getScriptableFor(fragment); }
/** * Creates a new HTML element with the given tag name, and name. * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name of the element type to instantiate * @return the new element or NOT_FOUND if the tag is not supported */ private Object createElementNS(final String namespaceURI, final String qualifiedName) { final org.w3c.dom.Element element; if ("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul".equals(namespaceURI)) { throw Context.reportRuntimeError("XUL not available"); } else if (HTMLParser.XHTML_NAMESPACE.equals(namespaceURI) || HTMLParser.SVG_NAMESPACE.equals(namespaceURI)) { element = getPage().createElementNS(namespaceURI, qualifiedName); } else { element = new DomElement(namespaceURI, qualifiedName, getPage(), null); } return getScriptableFor(element); }
final DomElement domElement = (DomElement) getPage().createElement(tagName); final Object jsElement = getScriptableFor(domElement);
/** * {@inheritDoc} */ @Override public HtmlPage cloneNode(final boolean deep) { // we need the ScriptObject clone before cloning the kids. final HtmlPage result = (HtmlPage) super.cloneNode(false); final SimpleScriptable jsObjClone = ((SimpleScriptable) getScriptableObject()).clone(); jsObjClone.setDomNode(result); // if deep, clone the kids too, and re initialize parts of the clone if (deep) { synchronized (lock_) { result.attributeListeners_ = null; } result.selectionRanges_ = new ArrayList<>(3); result.afterLoadActions_ = new ArrayList<>(); result.frameElements_ = new TreeSet<>(documentPositionComparator); for (DomNode child = getFirstChild(); child != null; child = child.getNextSibling()) { result.appendChild(child.cloneNode(true)); } } return result; }
/** * {@inheritDoc} */ @Override protected void checkChildHierarchy(final org.w3c.dom.Node newChild) throws DOMException { if (newChild instanceof Element) { if (getDocumentElement() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child Element."); } } else if (newChild instanceof DocumentType) { if (getDoctype() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child DocumentType."); } } else if (!(newChild instanceof Comment || newChild instanceof ProcessingInstruction)) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may not have a child of this type: " + newChild.getNodeType()); } super.checkChildHierarchy(newChild); }
page.addDomChangeListener(listener); if (page.isHtmlPage()) { ((HtmlPage) page).addHtmlAttributeChangeListener(listener); ((HtmlPage) page).addAutoCloseable(this);
page.addDomChangeListener(listener);
/** * {@inheritDoc} */ @Override public DisplayStyle getDefaultStyleDisplay() { if (getPage().getWebClient().getBrowserVersion().hasFeature(SLOT_CONTENTS)) { return DisplayStyle.CONTENTS; } return DisplayStyle.INLINE; } }
/** * {@inheritDoc} */ @Override public HtmlElement getDocumentElement() { return (HtmlElement) super.getDocumentElement(); }
/** * Creates a new document fragment. * @return a newly created document fragment */ public Object jsxFunction_createDocumentFragment() { final DomDocumentFragment fragment = getDomNodeOrDie().getPage().createDomDocumentFragment(); final DocumentFragment node = new DocumentFragment(); node.setParentScope(getParentScope()); node.setPrototype(getPrototype(node.getClass())); node.setDomNode(fragment); return getScriptableFor(fragment); }
/** * Creates a new HTML element with the given tag name, and name. * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name of the element type to instantiate * @return the new element or NOT_FOUND if the tag is not supported */ private Object createElementNS(final String namespaceURI, final String qualifiedName) { final org.w3c.dom.Element element; if ("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul".equals(namespaceURI)) { throw Context.reportRuntimeError("XUL not available"); } else if (HTMLParser.XHTML_NAMESPACE.equals(namespaceURI) || HTMLParser.SVG_NAMESPACE.equals(namespaceURI)) { element = getPage().createElementNS(namespaceURI, qualifiedName); } else { element = new DomElement(namespaceURI, qualifiedName, getPage(), null); } return getScriptableFor(element); }
final org.w3c.dom.Element element = page.createElement(tagName); final Object jsElement = getScriptableFor(element);
/** * {@inheritDoc} */ @Override public HtmlPage cloneNode(final boolean deep) { // we need the ScriptObject clone before cloning the kids. final HtmlPage result = (HtmlPage) super.cloneNode(false); final SimpleScriptable jsObjClone = ((SimpleScriptable) getScriptableObject()).clone(); jsObjClone.setDomNode(result); // if deep, clone the kids too, and re initialize parts of the clone if (deep) { synchronized (lock_) { result.attributeListeners_ = null; } result.selectionRanges_ = new ArrayList<>(3); result.afterLoadActions_ = new ArrayList<>(); result.frameElements_ = new TreeSet<>(documentPositionComparator); for (DomNode child = getFirstChild(); child != null; child = child.getNextSibling()) { result.appendChild(child.cloneNode(true)); } } return result; }
/** * {@inheritDoc} */ @Override protected void checkChildHierarchy(final org.w3c.dom.Node newChild) throws DOMException { if (newChild instanceof Element) { if (getDocumentElement() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child Element."); } } else if (newChild instanceof DocumentType) { if (getDoctype() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child DocumentType."); } } else if (!((newChild instanceof Comment) || (newChild instanceof ProcessingInstruction))) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may not have a child of this type: " + newChild.getNodeType()); } super.checkChildHierarchy(newChild); }
page.addDomChangeListener(listener); if (page.isHtmlPage()) { ((HtmlPage) page).addHtmlAttributeChangeListener(listener); ((HtmlPage) page).addAutoCloseable(this);