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; }
public Object eventOccurred(Event event) { int eventId = event.getUID(); switch (eventId) { case Event.EVENT_URL_REQUESTED: { UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event; String absoluteUrl = urlRequestedEvent.getURL(); if (urlRequestedEvent.getPostData() == null || urlRequestedEvent.getPostData().length == 0) m_app.addToHistory(absoluteUrl, null); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread( absoluteUrl, urlRequestedEvent.getHeaders(), urlRequestedEvent.getPostData(), event); thread.start(); 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()) //synchronized (Application.getEventLock()) { _mainScreen.setTitle(newTitle); } } }*/ break; } case Event.EVENT_REDIRECT: { RedirectEvent e = (RedirectEvent) event; String referrer = e.getSourceURL(); String absoluteUrl = e.getLocation(); switch (e.getType()) { case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT: // show redirect message Application.getApplication() .invokeAndWait( new Runnable() { public void run() { Status.show("You are being redirected to a different page..."); } }); 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. m_app.addToHistory(absoluteUrl, referrer); Object eventSource = e.getSource(); if (eventSource instanceof HttpConnection) { referrer = ((HttpConnection) eventSource).getRequestProperty("referer"); } break; } HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setProperty("referer", referrer); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(absoluteUrl, requestHeaders, null, event); thread.start(); break; } case Event.EVENT_CLOSE: // TODO: close the application break; case Event.EVENT_SET_HEADER: case Event.EVENT_SET_HTTP_COOKIE: { String cookie = ((SetHttpCookieEvent) event).getCookie(); String strUrl = ((SetHttpCookieEvent) event).getURL(); m_app.setCookie(strUrl, cookie); /* String response = processAjaxCall(cookie); if (response != null) synchronized (pendingResponses) { pendingResponses.addElement(response); } response = null; cookie = null;*/ break; } case Event.EVENT_HISTORY: // no history support 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; }