Пример #1
0
    public void handleNavigationRequest(BrowserFieldRequest request) throws Exception {
      String url = request.getURL();

      if (request.getPostData() == null || request.getPostData().length == 0) {
        // String referrer = request.getHeaders().getPropertyValue("referer");
        m_app.addToHistory(url, null);
      }

      PrimaryResourceFetchThread thread =
          new PrimaryResourceFetchThread(url, request.getHeaders(), request.getPostData(), url);
      thread.start();
    }
Пример #2
0
  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;
  }