/** {@inheritDoc} */ @Override public void dispatchLoadEvent( final long frame, final int state, String url, String contentType, double progress, int errorCode) { final Settings settings = SettingsManager.settings(); if (settings == null) { throw new RuntimeException("Request made after browser closed. Ignoring..."); } synchronized (statusCode) { if (state == LoadListenerClient.PAGE_STARTED) { contextItem.resetFrameId(frame); if (settings.logJavascript()) { JavascriptLog.attach(Accessor.getPageFor(contextItem.engine.get()), frame); } } contextItem.addFrameId(frame); if (state == LoadListenerClient.PAGE_STARTED || state == LoadListenerClient.PAGE_REDIRECTED || state == LoadListenerClient.DOCUMENT_AVAILABLE) { if (contextItem.currentFrameId() == frame) { if (state == LoadListenerClient.PAGE_STARTED) { StatusMonitor.instance().clearStatusMonitor(); } resetStatusCode(false); resources.put(frame + url, System.currentTimeMillis()); statusMonitor.startStatusMonitor(url); } statusMonitor.addPrimaryDocument(url); } else if (statusCode.get() == 0 && contextItem.currentFrameId() == frame && (state == LoadListenerClient.PAGE_FINISHED || state == LoadListenerClient.LOAD_STOPPED || state == LoadListenerClient.LOAD_FAILED)) { final int newStatusCode = statusMonitor.stopStatusMonitor(url); resources.remove(frame + url); Thread thread = new Thread(new AjaxListener(newStatusCode, statusCode, resources, timeoutMS.get())); ajaxListeners.add(thread); thread.start(); } } if (settings.logTrace()) { trace("Page", frame, state, url, contentType, progress, errorCode); } }
HttpListener(ContextItem contextItem, AtomicInteger statusCode, AtomicLong timeoutMS) { this.contextItem = contextItem; this.statusCode = statusCode; this.timeoutMS = timeoutMS; this.statusMonitor = StatusMonitor.instance(); this.logs = LogsServer.instance(); }
/** {@inheritDoc} */ @Override public void dispatchResourceLoadEvent( long frame, int state, String url, String contentType, double progress, int errorCode) { final Settings settings = SettingsManager.settings(); if (settings == null) { throw new RuntimeException("Request made after browser closed. Ignoring..."); } synchronized (statusCode) { if (url.startsWith("http://") || url.startsWith("https://")) { if (state == LoadListenerClient.RESOURCE_STARTED) { resources.put(frame + url, System.currentTimeMillis()); } else if (state == LoadListenerClient.RESOURCE_FINISHED || state == LoadListenerClient.RESOURCE_FAILED) { String original = null; original = statusMonitor.originalFromRedirect(url); resources.remove(frame + url); if (original != null) { resources.remove(frame + original); } } } } if ((settings.logTrace()) && (url.startsWith("http://") || url.startsWith("https://"))) { trace("Rsrc", frame, state, url, contentType, progress, errorCode); } }