Example #1
0
  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();
    }
  }
Example #2
0
  public HttpConnection getResource(RequestedResource resource, BrowserContent referrer) {

    if (resource == null) return null;

    String url = resource.getUrl();
    if (url == null || url.endsWith("/favicon.ico")) return null;

    try {
      if (referrer == null || URI.isLocalData(url) || !m_bLoadImageAsync) {
        boolean bLocalHost = RhodesApp.getInstance().isRhodesAppUrl(url);
        if (bLocalHost && m_connResource != null) {
          com.rho.net.RhoConnection rhoConn =
              (com.rho.net.RhoConnection)
                  ((com.rho.net.bb.NativeBBHttpConnection) m_connResource).getNativeConnection();
          rhoConn.resetUrl(url);

          Utilities.makeConnection(url, resource.getRequestHeaders(), null, m_connResource);
          return m_connResource;
        } else {
          HttpConnection connection =
              Utilities.makeConnection(url, resource.getRequestHeaders(), null, null);
          // if (bLocalHost)
          //	m_connResource = connection;
          return connection;
        }
      } else {
        SecondaryResourceFetchThread.enqueue(resource, referrer);
      }
    } catch (Exception exc) {
      LOG.ERROR("getResource failed.", exc);
    }

    return null;

    /*
     // check if this is cache-only request
     if (resource.isCacheOnly()) {
         // no cache support
         return null;
     }

     String url = resource.getUrl();

     if (url == null) {
         return null;
     }

     try{
      // if referrer is null we must return the connection
      if (referrer == null) {
          HttpConnection connection = Utilities.makeConnection(url, resource.getRequestHeaders(), null);
          return connection;

      } else
      {
    if ( URI.isLocalHost(url) || URI.isLocalData(url))
    {
              HttpConnection connection = Utilities.makeConnection(url, resource.getRequestHeaders(), null);
              return connection;
    }else
    {
           // if referrer is provided we can set up the connection on a separate thread
           SecondaryResourceFetchThread.enqueue(resource, referrer);
    }
      }
     }catch(Exception exc)
     {
     	LOG.ERROR("getResource failed.", exc);
     }

     return null;*/
  }