/** * Creates a web client instance using the browser version returned by * {@link BrowserVersion#getDefault()}. */ public WebClient() { this(BrowserVersion.getDefault()); }
workPiece_ = new BrowserVersion(version.getBrowserVersionNumeric(), version.getNickname()); setApplicationVersion(version.getApplicationVersion()) .setUserAgent(version.getUserAgent()) .setApplicationName(version.getApplicationName()) .setApplicationCodeName(version.getApplicationCodeName()) .setApplicationMinorVersion(version.getApplicationMinorVersion()) .setVendor(version.getVendor()) .setBrowserLanguage(version.getBrowserLanguage()) .setCpuClass(version.getCpuClass()) .setOnLine(version.isOnLine()) .setPlatform(version.getPlatform()) .setSystemLanguage(version.getSystemLanguage()) .setSystemTimezone(version.getSystemTimezone()) .setUserLanguage(version.getUserLanguage()); workPiece_.buildId_ = version.getBuildId(); workPiece_.productSub_ = version.getProductSub(); workPiece_.htmlAcceptHeader_ = version.getHtmlAcceptHeader(); workPiece_.imgAcceptHeader_ = version.getImgAcceptHeader(); workPiece_.cssAcceptHeader_ = version.getCssAcceptHeader(); workPiece_.scriptAcceptHeader_ = version.getScriptAcceptHeader(); workPiece_.xmlHttpRequestAcceptHeader_ = version.getXmlHttpRequestAcceptHeader(); workPiece_.headerNamesOrdered_ = version.getHeaderNamesOrdered(); workPiece_.fontHeights_ = version.fontHeights_; for (final PluginConfiguration pluginConf : version.getPlugins()) { workPiece_.plugins_.add(pluginConf.clone());
/** * {@inheritDoc} */ @Override public Page mouseOver(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { final SgmlPage page = getPage(); if (page.getWebClient().getBrowserVersion().hasFeature(EVENT_ONMOUSEOVER_NEVER_FOR_SELECT_OPTION)) { return page; } return super.mouseOver(shiftKey, ctrlKey, altKey, button); }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * @return whether or not this version version 52 of a Firefox browser */ public boolean isFirefox52() { return isFirefox() && getBrowserVersionNumeric() == 52; }
static BrowserConfiguration getMatchingConfiguration( final BrowserVersion browserVersion, final BrowserConfiguration[] browserConfigurations) { for (final BrowserConfiguration browserConfiguration : browserConfigurations) { if (browserVersion.getNickname().startsWith(browserConfiguration.browserFamily_) && browserVersion.getBrowserVersionNumeric() >= browserConfiguration.minVersionNumber_ && browserVersion.getBrowserVersionNumeric() <= browserConfiguration.maxVersionNumber_) { return browserConfiguration; } } return null; }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * @param href the href * @param page the HtmlPage * @return the calculated target url. * @throws MalformedURLException if an IO error occurs */ public static URL getTargetUrl(final String href, final HtmlPage page) throws MalformedURLException { URL url = page.getFullyQualifiedUrl(href); // fix for empty url if (StringUtils.isEmpty(href)) { final boolean dropFilename = page.getWebClient().getBrowserVersion() .hasFeature(ANCHOR_EMPTY_HREF_NO_FILENAME); if (dropFilename) { String path = url.getPath(); path = path.substring(0, path.lastIndexOf('/') + 1); url = UrlUtils.getUrlWithNewPath(url, path); url = UrlUtils.getUrlWithNewRef(url, null); } else { url = UrlUtils.getUrlWithNewRef(url, null); } } return url; }
/** * <p><span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span></p> * * Opens a new dialog window. * @param url the URL of the document to load and display * @param opener the web window that is opening the dialog * @param dialogArguments the object to make available inside the dialog via <tt>window.dialogArguments</tt> * @return the new dialog window * @throws IOException if there is an IO error */ public DialogWindow openDialogWindow(final URL url, final WebWindow opener, final Object dialogArguments) throws IOException { WebAssert.notNull("url", url); WebAssert.notNull("opener", opener); final DialogWindow window = new DialogWindow(this, dialogArguments); fireWindowOpened(new WebWindowEvent(window, WebWindowEvent.OPEN, null, null)); final HtmlPage openerPage = (HtmlPage) opener.getEnclosedPage(); final WebRequest request = new WebRequest(url, getBrowserVersion().getHtmlAcceptHeader()); request.setCharset(StandardCharsets.UTF_8); if (getBrowserVersion().hasFeature(DIALOGWINDOW_REFERER) && openerPage != null) { final String referer = openerPage.getUrl().toExternalForm(); request.setAdditionalHeader(HttpHeader.REFERER, referer); } getPage(window, request); return window; }
final WebWindow window = openTargetWindow(opener, windowName, TARGET_BLANK); final HtmlPage openerPage = (HtmlPage) opener.getEnclosedPage(); if (url != null) { try { final WebRequest request = new WebRequest(url, getBrowserVersion().getHtmlAcceptHeader()); request.setCharset(StandardCharsets.UTF_8); if (getBrowserVersion().hasFeature(DIALOGWINDOW_REFERER) && openerPage != null) { final String referer = openerPage.getUrl().toExternalForm(); request.setAdditionalHeader(HttpHeader.REFERER, referer);
/** * Returns the value of the property {@code action}. * @return the value of this property */ @JsxGetter public String getAction() { final String action = getHtmlForm().getActionAttribute(); if (action != DomElement.ATTRIBUTE_NOT_DEFINED && action.length() == 0 && getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY)) { return action; } if (action == DomElement.ATTRIBUTE_NOT_DEFINED && !getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_NOT_DEFINED)) { return action; } try { return ((HtmlPage) getHtmlForm().getPage()).getFullyQualifiedUrl(action).toExternalForm(); } catch (final MalformedURLException e) { // nothing, return action attribute } return action; }
super(createConfiguration(node.getPage().getWebClient().getBrowserVersion())); page_ = (HtmlPage) node.getPage(); for (final Node ancestor : currentNode_.getAncestors()) { stack_.push((DomNode) ancestor); final WebClient webClient = page_.getWebClient(); final HTMLParserListener listener = webClient.getHTMLParserListener(); final boolean reportErrors = listener != null; if (reportErrors) { setFeature(FEATURE_AUGMENTATIONS, true); setProperty("http://cyberneko.org/html/properties/names/elems", "default"); if (!webClient.getBrowserVersion().hasFeature(HTML_ATTRIBUTE_LOWER_CASE)) { setProperty("http://cyberneko.org/html/properties/names/attrs", "no-change");
/** * {@inheritDoc} */ @Override @JsxGetter({CHROME, FF}) public String getAlinkColor() { String color = getPage().getBody().getAttribute("aLink"); if (color == DomElement.ATTRIBUTE_NOT_DEFINED && getBrowserVersion().hasFeature(HTMLDOCUMENT_COLOR)) { color = "#0000ff"; } if (getBrowserVersion().hasFeature(HTML_COLOR_EXPAND_ZERO) && "#0".equals(color)) { color = "#000000"; } return color; }
/** * Returns the {@code doNotTrack} property. * @return the {@code doNotTrack} property */ @JsxGetter({CHROME, FF}) public Object getDoNotTrack() { final WebClient client = getWindow().getWebWindow().getWebClient(); if (client.getOptions().isDoNotTrackEnabled()) { return 1; } if (client.getBrowserVersion().hasFeature(JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED)) { return "unspecified"; } return null; }
/** * Submits the form (at the end of the current script execution). */ @JsxFunction public void submit() { final HtmlPage page = (HtmlPage) getDomNodeOrDie().getPage(); final WebClient webClient = page.getWebClient(); final String action = getHtmlForm().getActionAttribute().trim(); if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { final String js = action.substring(JavaScriptURLConnection.JAVASCRIPT_PREFIX.length()); webClient.getJavaScriptEngine().execute(page, js, "Form action", 0); } else { // download should be done ASAP, response will be loaded into a window later final WebRequest request = getHtmlForm().getWebRequest(null); final String target = page.getResolvedTarget(getTarget()); final boolean forceDownload = webClient.getBrowserVersion().hasFeature(JS_FORM_SUBMIT_FORCES_DOWNLOAD); final boolean checkHash = !webClient.getBrowserVersion().hasFeature(FORM_SUBMISSION_DOWNLOWDS_ALSO_IF_ONLY_HASH_CHANGED); webClient.download(page.getEnclosingWindow(), target, request, checkHash, forceDownload, "JS form.submit()"); } }
if (page_.isParsingHtmlSnippet() && (tagLower.equals("html") || tagLower.equals("body"))) { return; parsingInnerHead_ = false; if (tagLower.equals("head") || page_.getWebClient().getBrowserVersion().hasFeature( BrowserVersionFeatures.IGNORE_CONTENTS_OF_INNER_HEAD)) { return; previousNode.setEndLocation(locator_.getLineNumber(), locator_.getColumnNumber()); final boolean postponed = page_.isParsingInlineHtmlSnippet(); previousNode.onAllChildrenAddedToPage(postponed);
/** * Sets the value of the {@code type} property. * @param type the value of the {@code type} property */ protected void setType(final String type) { final boolean acceptArbitraryValues = getBrowserVersion().hasFeature(JS_TYPE_ACCEPTS_ARBITRARY_VALUES); if (acceptArbitraryValues || "1".equals(type) || "a".equals(type) || "A".equals(type) || "i".equals(type) || "I".equals(type)) { getDomNodeOrDie().setAttribute("type", type); return; } throw Context.reportRuntimeError("Cannot set the type property to invalid value: '" + type + "'"); } }
/** * Sets the value of the {@code span} property. * @param span the value of the {@code span} property */ @JsxSetter public void setSpan(final Object span) { final double d = Context.toNumber(span); int i = (int) d; if (i < 1) { if (getBrowserVersion().hasFeature(JS_TABLE_SPAN_THROWS_EXCEPTION_IF_INVALID)) { final Exception e = new Exception("Cannot set the span property to invalid value: " + span); Context.throwAsScriptRuntimeEx(e); } else { i = 1; } } getDomNodeOrDie().setAttribute("span", Integer.toString(i)); }
/** * <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); }
final HtmlPage page = (HtmlPage) domNode.getPage(); result = getFrameWindowByName(page, name); final HtmlElement htmlElement = page.getHtmlElementById(name); if (getBrowserVersion().hasFeature(JS_WINDOW_FRAME_BY_ID_RETURNS_WINDOW) && htmlElement instanceof HtmlFrame) { final HtmlFrame frame = (HtmlFrame) htmlElement;
/** * {@inheritDoc} */ @Override public void setSelectionStart(int selectionStart) { if (selectionStart < 0 && element_.getPage().getEnclosingWindow().getWebClient() .getBrowserVersion().hasFeature(JS_INPUT_IGNORE_NEGATIVE_SELECTION_START)) { return; } final int length = element_.getText().length(); selectionStart = Math.max(0, Math.min(selectionStart, length)); selection_.setStart(element_, selectionStart); if (selection_.getEndOffset() < selectionStart) { selection_.setEnd(element_, selectionStart); } }
/** * {@inheritDoc} */ @Override public Scriptable construct(final Context cx, final Scriptable scope, final Object[] args) { if (!getBrowserVersion().hasFeature(JS_FORM_USABLE_AS_FUNCTION)) { throw Context.reportRuntimeError("Not a function."); } return null; }