• Andrew Hodgkinson's avatar
    Now working on source merged with Kevin Bracey's internationalisation support.... · f61afadd
    Andrew Hodgkinson authored
    Now working on source merged with Kevin Bracey's internationalisation support. UNIFONT is undefined in the Make File for now. All Res and
    
    Choices files updated appropriately.
    
    Having sorted out the old Choices and Messages to form Choices, Controls
    and Messages, this build has had the same cleaning up done internally.
    This includes greater consistency in naming schemes and the removal of
    the inconsitent choices items - e.g. Choices file entries saying 'delay
    images' and 'plain backgrounds' where internally all the flags say 'show
    images' and 'show backgrounds'. ChoiceDefs.h and CtrlDefs.h added to
    clarify the meaning of some fields, though usage of these is not 100%
    in the source (there are cases where parameters are passed through to
    functions as ints, and those functions still check these against hard
    coded values rather than the #define stuff).
    
    Fetcher status return bits (connected, sent request, etc.) now reflected
    in status bar. Progress during fetchs to files are reported by %, where
    the size of the object is known. Exceeding 100% drops back to a byte
    counter, in case the estimated size was wrong. The progress counter
    may be updated after specific delays, rather than 'as often as possible',
    to reduce flicker (as requested by D.Brown some time ago).
    
    I've done a small rewrite of the fetch prioritisation scheme in FetchPage.c;
    how well this performs in general use across different processor speeds
    remains to be tested, but certainly it has some advantages. For each small
    fetch window before the rewrite, a 4cs tight loop was entered - this gave a
    noticable and substantial drain to the Desktop performance if more than one
    was opened. Now, several can be up at once with little hit. The actual file
    fetch is on half the priority it was before, with all others taken back
    just a bit - e.g. from 20cs per poll to 15cs per poll for flat out
    reformatting. You don't seem to lose much time on the format in practice,
    and the Desktop feels quite a bit lighter at the same time. There's the
    potential for smoother frameset loading in this scheme, too.
    
    When Shift+Clicking on a link meant you still fetched inside the main
    browser window, several fetches could occur in a frameset - one per frame.
    However, now that you can only do this by clicking on a link that leads to
    non-displayable data - or by turning off the small fetch windows by
    setting UseSmall to 'no' in Choices - a bug where fetchpage_preprocessed
    would stop such fetches as new ones were started was revealed.
    The API to frames_abort_fetching has now been extended to include a
    'stop file spooling too' flag, allowing a fix to be made by having
    fetchpage_preprocess's calls not set this (and it doesn't check the
    savelink flag is unset before proceeding, since frames_abort_fetching
    does that implicitly now).
    
    Had left the RAM transfer buffer at 16 bytes (from testing) accidentally...
    Oops. Upped it to 4K. In addition, when loading data by RAM transfer,
    the browser didn't notice if a RAMFetch bounced during the transfer. It
    would be treated as a 'first' RAMFetch bounce, basically, and try to go to
    file transfer - oops. Fixed.
    f61afadd
Meta 6.71 KB
/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/***************************************************/
/* File   : Meta.c                                 */
/*                                                 */
/* Purpose: Handling META tags.                    */
/*                                                 */
/* Author : A.D.Hodgkinson                         */
/*                                                 */
/* History: 25-Jul-97: Created.                    */
/***************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "swis.h"
#include "flex.h"

#include "HTMLLib.h" /* HTML library API, Which will include html2_ext.h, tags.h and struct.h */

#include "wimp.h"
#include "wimplib.h"
#include "event.h"

#include "svcprint.h"
#include "Global.h"
#include "Utils.h"

#include "Browser.h"
#include "FetchPage.h"

#include "Meta.h"

/* Static function prototypes */

static _kernel_oserror * meta_process_refresh(browser_data * b, HStream * t, const char * content);

/*************************************************/
/* meta_process_tag()                            */
/*                                               */
/* In HTML, META tags can contain a great        */
/* variety of information (so much so that this  */
/* source file is entirely dedicated to them).   */
/* This function is the entry point for dealing  */
/* with a new META tag.                          */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             relevant to the token stream      */
/*             holding the META tag;             */
/*                                               */
/*             Pointer to the token representing */
/*             the META tag.                     */
/*************************************************/

_kernel_oserror * meta_process_tag(browser_data * b, HStream * t)
{
  const char * name;
  const char * equiv;
  const char * content;
  const char * scheme;

  if (!t || !b) return NULL;

  /* Extract information from the token */

  name    = HtmlMETAname      (t);
  equiv   = HtmlMETAhttp_equiv(t);
  content = HtmlMETAcontent   (t);
  scheme  = HtmlMETAscheme    (t);

  /* Work out what to do */

  if (!utils_strcasecmp(equiv, "refresh"))
  {
    /* Refresh - load a new page or reload the current page */
    /* after a certain amount of time                       */

    if (b->client_pull)
    {
      return meta_process_refresh(b, t, content);
    }
  }

  return NULL;
}

/*************************************************/
/* meta_process_refresh()                        */
/*                                               */
/* Handles META tags specify that a page         */
/* refresh (reload) should occur at some time.   */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             relevant to the META tag;         */
/*                                               */
/*             The content string for the tag.   */
/*************************************************/

static _kernel_oserror * meta_process_refresh(browser_data * b, HStream * t, const char * content)
{
  _kernel_oserror * e;
  char            * separator;
  int               time_now;

  if (!content || !b) return NULL;

  /* See if there's any URL specified - else it's the current page that is to be refetched */

  separator = strstr(content, ";");

  /* If we found a separator, skip white space */

  if (separator)
  {
    separator ++;

    while (*separator && *separator < 33) separator++;

    if (!*separator) separator = NULL;
    else
    {
      /* May have a 'url=' before the actual URL */

      if (!utils_strncasecmp(separator, "url", 3))
      {
        char * oldsep = separator;

        separator += 3;

        /* Skip any white space */

        while (*separator && *separator < 33) separator++;

        /* Should be at an '='; if not, sssume 'url' was the URL to fetch! */

        if (*separator != '=') separator = oldsep;
        else
        {
          /* Skip the '=' and any more white space */

          separator ++;
          while (*separator && *separator < 33) separator++;

          /* Should be at the URL now, but make sure... */

          if (!*separator) separator = NULL;
        }
      }
    }
  }

  /* Work out the URL to fetch */

  b->meta_refresh_url = HtmlRelativiseURL(browser_current_url(b),
                                          separator ? separator : "",
                                          t);

  /* Only proceed if HtmlRelativiseURL didn't fail */

  if (b->meta_refresh_url)
  {
    /* Work out what time to fetch at */

    e = _swix(OS_ReadMonotonicTime,
              _OUT(0),

              &time_now);

    if (e) return e;

    b->meta_refresh_at = time_now + atoi(content) * 100; /* (Seconds -> Centiseconds) */

    /* Install the handler */

    register_null_claimant(Wimp_ENull, (WimpEventHandler *) meta_check_refresh, b);
  }

  return NULL;
}

/*************************************************/
/* meta_check_refresh()                          */
/*                                               */
/* After a META tag specifying a page (re)load   */
/* (refresh) has been processed, this null       */
/* handler will initiate the appropriate fetch   */
/* after the appropriate delay.                  */
/*                                               */
/* Paramters are as standard for a Wimp event    */
/* handler.                                      */
/*************************************************/

int meta_check_refresh(int eventcode, WimpPollBlock * b, IdBlock * idb, browser_data * handle)
{
  int time_now;

  _swix(OS_ReadMonotonicTime,
        _OUT(0),

        &time_now);

  /* Exit if we haven't reached the fetch time */

  if (time_now < handle->meta_refresh_at) return 0;

  /* Otherwise, deregister this handler and start the fetch */

  deregister_null_claimant(Wimp_ENull, (WimpEventHandler *) meta_check_refresh, handle);
  handle->meta_refresh_at = 0;

  ChkError(fetchpage_new(handle,
                         handle->meta_refresh_url,
                         1,
                         0));

  handle->meta_refresh_url = NULL;

  return 0;
}