public void processConnection(HttpConnection connection, Object e) { BrowserContent browserContent = null; try { if (connection.getResponseCode() != HttpConnection.HTTP_NOT_MODIFIED) browserContent = _renderingSession.getBrowserContent(connection, this, (Event) e); if (browserContent != null) { browserContent.finishLoading(); Field field = browserContent.getDisplayableContent(); if (field != null) { synchronized (Application.getEventLock()) { m_oMainScreen.deleteAll(); m_oMainScreen.add(field); /*if ( m_oMainScreen.getFieldCount() > 0 ) { Field old = m_oMainScreen.getField(0); m_oMainScreen.add(field); m_oMainScreen.delete(old); }else m_oMainScreen.add(field);*/ /* _mainScreen.doPaint(); if ( e == null ) {//This should awake screen in case of long network response KeyCodeEvent inject1 = new KeyCodeEvent( KeyCodeEvent.KEY_DOWN, (char)Keypad.KEY_ESCAPE, 0); KeyCodeEvent inject2 = new KeyCodeEvent( KeyCodeEvent.KEY_UP, (char)Keypad.KEY_ESCAPE, 0); inject1.post(); inject2.post(); m_bSkipKeyPress = true; }*/ } } } } catch (Exception re) { LOG.ERROR("processConnection failed.", re); } finally { SecondaryResourceFetchThread.doneAddingImages(); } }
/** * Processes a new HttpConnection object to instantiate a new browser Field (aka WebView) object, * and then resets the screen to the newly-created Field. * * @param connection * @param e */ public void processConnection(HttpConnection connection, Event e) { // Cancel previous request. if (_currentConnection != null) { try { _currentConnection.close(); } catch (IOException e1) { } } // Clear out pending responses. synchronized (pendingResponses) { pendingResponses.removeAllElements(); } // Cancel any XHRs happening. commandManager.stopXHR(); _currentConnection = connection; BrowserContent browserContent = null; Field field = null; try { browserContent = _renderingSession.getBrowserContent(connection, this, e); if (browserContent != null) { field = browserContent.getDisplayableContent(); if (field != null) { synchronized (Application.getEventLock()) { _mainScreen.deleteAll(); _mainScreen.add(field); } } browserContent.finishLoading(); } } catch (RenderingException re) { } finally { browserContent = null; field = null; // Manually call the garbage collector to clean up all of leftover objects and free up the // nulled object handles. System.gc(); } }
public void run() { while (true) { if (_done) { // check if we are done requesting images synchronized (_syncObject) { synchronized (_imageQueue) { if (_imageQueue.size() == 0) { _currentThread = null; break; } } } } RequestedResource resource = null; // request next image synchronized (_imageQueue) { if (_imageQueue.size() > 0) { resource = (RequestedResource) _imageQueue.elementAt(0); _imageQueue.removeElementAt(0); } } if (resource != null) { HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null); resource.setHttpConnection(connection); // signal to the browser field that resource is ready if (_browserField != null) { _browserField.resourceReady(resource); } } } }
public Object eventOccurred(final Event event) { int eventId = event.getUID(); switch (eventId) { case Event.EVENT_REDIRECT: { RedirectEvent e = (RedirectEvent) event; String referrer = e.getSourceURL(); switch (e.getType()) { case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT: // Show redirect message. Application.getApplication() .invokeAndWait( new Runnable() { public void run() { Status.show(REDIRECT_MSG); } }); break; case RedirectEvent.TYPE_JAVASCRIPT: break; case RedirectEvent.TYPE_META: // MSIE and Mozilla don't send a Referer for META Refresh. referrer = null; break; case RedirectEvent.TYPE_300_REDIRECT: // MSIE, Mozilla, and Opera all send the original request's Referer as the Referer for // the new request. Object eventSource = e.getSource(); if (eventSource instanceof HttpConnection) { referrer = ((HttpConnection) eventSource).getRequestProperty(REFERER); } eventSource = null; break; } // Create the request, populate header with referrer and fire off the request. HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setProperty(REFERER, referrer); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(e.getLocation(), requestHeaders, null, event, this); thread.start(); e = null; referrer = null; requestHeaders = null; break; } case Event.EVENT_URL_REQUESTED: { UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event; String url = urlRequestedEvent.getURL(); HttpHeaders header = urlRequestedEvent.getHeaders(); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread( url, header, urlRequestedEvent.getPostData(), event, this); thread.start(); urlRequestedEvent = null; url = null; header = null; break; } case Event.EVENT_BROWSER_CONTENT_CHANGED: { // Browser field title might have changed update title. BrowserContentChangedEvent browserContentChangedEvent = (BrowserContentChangedEvent) event; if (browserContentChangedEvent.getSource() instanceof BrowserContent) { BrowserContent browserField = (BrowserContent) browserContentChangedEvent.getSource(); String newTitle = browserField.getTitle(); if (newTitle != null) { synchronized (getAppEventLock()) { _mainScreen.setTitle(newTitle); } } browserField = null; newTitle = null; } browserContentChangedEvent = null; break; } case Event.EVENT_CLOSE: // TODO: close the application break; case Event.EVENT_SET_HEADER: // No cache support. case Event.EVENT_SET_HTTP_COOKIE: String cookie = ((SetHttpCookieEvent) event).getCookie(); if (cookie.startsWith(PHONEGAP_PROTOCOL)) { String response = commandManager.processInstruction(cookie); if ((response != null) && (response.trim().length() > 0)) { pendingResponses.addElement(response); } response = null; } cookie = null; break; case Event.EVENT_HISTORY: // TODO: No history support.. but we added our own history stack // implementation in ConnectionManager. Can we hook it up - then we'd have // access to window.history :o case Event.EVENT_EXECUTING_SCRIPT: // No progress bar is supported. case Event.EVENT_FULL_WINDOW: // No full window support. case Event.EVENT_STOP: // No stop loading support. default: } return null; }