webengine/wmlengine/src/wml1x/src/WML1XContentHandler.cpp
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2000 - 2001 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "nw_wml_core.h"
       
    19 #include "nw_wae.h"
       
    20 #include "nwx_ctx.h"
       
    21 #include "nw_scrproxy.h"
       
    22 #include "nw_wml1x_wml1xcontenthandleri.h"
       
    23 #include "nw_wml1x_wml1xapi.h"
       
    24 #include "nw_wmlscriptch_wmlscriptcontenthandler.h"  /* to run Wml Scripts */
       
    25 #include "nw_lmgr_textbox.h"
       
    26 #include "nw_hed_documentrooti.h"
       
    27 #include "nw_hed_appservices.h"
       
    28 #include "nw_hed_contextvisitor.h"
       
    29 #include "nw_hed_inumbercollectori.h"
       
    30 #include "nw_adt_segmentedvector.h"
       
    31 #include "nw_lmgr_cssproperties.h"
       
    32 #include "nw_imagech_epoc32contenthandler.h"
       
    33 #include "nwx_string.h"
       
    34 #include "stdarg.h"
       
    35 #include "nw_lmgr_bidiflowbox.h"
       
    36 #include "nw_wml1x_wml1xdefaultstylesheet.h"
       
    37 #include "nw_image_cannedimages.h"
       
    38 #include "nw_text_ascii.h"
       
    39 #include "nwx_osu.h"
       
    40 #include "wml_url_utils.h"
       
    41 #include "wml_history.h"
       
    42 #include "nw_xmlp_xmlp2wbxml.h"
       
    43 #include "nwx_settings.h"
       
    44 #include "nw_wml1x_wml_1_3_tokens.h"
       
    45 #include "wml_elm_attr.h"
       
    46 #include "wml_task.h"
       
    47 #include "nw_adt_types.h"
       
    48 #include "nw_lmgr_slavepropertylist.h"
       
    49 #include "nw_lmgr_rootbox.h"
       
    50 
       
    51 #include "nw_markup_numbercollector.h"
       
    52 #include "nw_system_optionlist.h"
       
    53 #include "nw_lmgr_imgcontainerbox.h"
       
    54 
       
    55 #include "nw_htmlp_wml_dict.h"
       
    56 #include "nw_htmlp_to_wbxml.h"
       
    57 #include "nwx_osu_file.h"
       
    58 #include "nwx_logger.h"
       
    59 
       
    60 #include <stddef.h>
       
    61 #include "nwx_http_defs.h"
       
    62 #include "GDIDevicecontext.h"
       
    63 #include "BrsrStatusCodes.h"
       
    64 #include "HEDDocumentListener.h"
       
    65 
       
    66 
       
    67 #include "WmlControl.h"
       
    68 
       
    69 /* ------------------------------------------------------------------------- *
       
    70    private methods
       
    71  * ------------------------------------------------------------------------- */
       
    72 /************************************************************************
       
    73   Function: HedToWmlTask
       
    74 
       
    75   Purpose: Converts HED Url request reason to Wml task
       
    76 
       
    77   Parameters: HED reason
       
    78   
       
    79   Return Values: Wml task
       
    80 
       
    81 **************************************************************************/
       
    82 
       
    83 static NW_Wml_Task_e HedToWmlTask(NW_Uint8 reason)
       
    84 {
       
    85   NW_Wml_Task_e ret = GO_TASK;
       
    86 
       
    87   if ((reason == NW_HED_UrlRequest_Reason_DocPrev) ||
       
    88       (reason == NW_HED_UrlRequest_Reason_ShellPrev))
       
    89   {
       
    90     ret= PREV_TASK;
       
    91   }
       
    92 
       
    93   return ret;
       
    94 }
       
    95 /*****************************************************************
       
    96 
       
    97   Name:         GetAlignProp
       
    98 
       
    99   Description:  Looks in Wml img element for the align attr. 
       
   100                 Converts it to the LManager box property values
       
   101     
       
   102   Return Value: NW_TRUE when the align attr is present
       
   103                 Value of the attribute
       
   104 
       
   105 *****************************************************************/
       
   106 static NW_Bool GetAlignProp(NW_Wml1x_ContentHandler_t *thisObj,
       
   107                             NW_Uint16      elId, 
       
   108                             NW_ADT_Token_t *token) 
       
   109 {
       
   110   NW_Bool     align = NW_TRUE;
       
   111   NW_Ucs2     *retString = NULL;
       
   112   TBrowserStatusCode status;
       
   113 
       
   114   status = NW_Wml_GetAttribute(&(thisObj->wmlInterpreter),
       
   115                                elId,
       
   116                                ALIGN_ATTR,
       
   117                                &retString);
       
   118 
       
   119   if (status != KBrsrSuccess || !retString) {
       
   120     align = NW_FALSE;
       
   121     goto funcEnd;
       
   122   }
       
   123 
       
   124   if (!NW_Str_StrcmpConst(retString, WAE_ASC_TOP_STR)) {
       
   125     *token = NW_CSS_PropValue_top;
       
   126   }
       
   127   else if (!NW_Str_StrcmpConst(retString, WAE_ASC_MIDDLE_STR)) {
       
   128     *token = NW_CSS_PropValue_middle;
       
   129   }
       
   130   else if (!NW_Str_StrcmpConst(retString, WAE_ASC_BOTTOM_STR)) {
       
   131     /* map WML bottom to CSS baseline to conform to WML spec. */
       
   132     *token = NW_CSS_PropValue_baseline;
       
   133   }
       
   134   else {
       
   135     align = NW_FALSE;
       
   136   }
       
   137 
       
   138 funcEnd:
       
   139   NW_Str_Delete(retString);
       
   140   return align;
       
   141 }
       
   142 
       
   143 /*****************************************************************
       
   144 
       
   145   Name:         NW_Bool GetVHspaceHWprop
       
   146 
       
   147   Description:  Looks in Wml img element for the vspace, hspace, height, width
       
   148                 attributes. Converts them to the LManager box property values   
       
   149 
       
   150   Return Value: NW_TRUE when the attributes are present.
       
   151                 Value type and value of the attribute
       
   152 
       
   153 *****************************************************************/
       
   154 static NW_Bool GetVHspaceHWprop(NW_Wml1x_ContentHandler_t *thisObj,
       
   155                                 NW_Uint16          elId,
       
   156                                 NW_Wml_Attr_t      tag,
       
   157                                 NW_Int32           *val,
       
   158                                 NW_ADT_ValueType_t *type)
       
   159 {
       
   160   NW_Ucs2     *ptr;
       
   161   TBrowserStatusCode status;
       
   162   NW_Ucs2     *retString = NULL;
       
   163   NW_Bool     ret = NW_TRUE;
       
   164 
       
   165   status = NW_Wml_GetAttribute(&(thisObj->wmlInterpreter),
       
   166                                elId,
       
   167                                tag,
       
   168                                &retString);
       
   169 
       
   170   if (status != KBrsrSuccess || !retString) {
       
   171     ret = NW_FALSE;
       
   172     goto funcEnd;
       
   173   }
       
   174 
       
   175   if ((ptr=NW_Str_Strchr(retString, '%')) != NULL) {
       
   176     *ptr = 0;
       
   177     *type = NW_CSS_ValueType_Percentage;
       
   178   }
       
   179   else {
       
   180     *type = NW_CSS_ValueType_Px;
       
   181   }
       
   182   *val = NW_Str_Atoi(retString);
       
   183  
       
   184 funcEnd:
       
   185   NW_Str_Delete(retString);
       
   186   return ret;
       
   187 }
       
   188 
       
   189 /*****************************************************************
       
   190 
       
   191   Name:         AddImageProperties
       
   192 
       
   193   Description:  when attributes are present it sets box properties 
       
   194                 related to the attributes:
       
   195                 align, vspace, hspace, height, and width  
       
   196 
       
   197   Return Value: <none>
       
   198 *****************************************************************/
       
   199 void AddImageProperties(NW_Wml1x_ContentHandler_t* thisObj,
       
   200                                NW_LMgr_Box_t *box,
       
   201                                NW_LMgr_PropertyValue_t value)
       
   202 {
       
   203   
       
   204   NW_LMgr_Property_t prop;
       
   205   NW_Uint16         elId = NW_UINT16_CAST(value.integer);
       
   206   NW_LMgr_Property_t heightVal;
       
   207   NW_LMgr_Property_t widthVal;
       
   208   NW_LMgr_RootBox_t* rootBox = NULL;
       
   209   CGDIDeviceContext* deviceContext = NULL;
       
   210   const NW_GDI_Rectangle_t* rectangle = NULL;
       
   211   NW_HED_DocumentRoot_t* documentRoot = NULL;
       
   212   
       
   213   /* first must set the element Id on the new box */
       
   214   prop.type = NW_CSS_ValueType_Integer;
       
   215   prop.value = value;
       
   216   NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_elementId, &prop);
       
   217   
       
   218   if (GetAlignProp(thisObj, elId, &prop.value.token)) 
       
   219   {
       
   220     prop.type = NW_CSS_ValueType_Token ;
       
   221     NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_verticalAlign, &prop);
       
   222   }
       
   223 
       
   224   /* get the RootBox from through IDocumentListener interface */
       
   225   documentRoot = (NW_HED_DocumentRoot_t*) NW_HED_DocumentNode_GetRootNode (thisObj);
       
   226   NW_ASSERT( documentRoot != NULL );
       
   227 
       
   228   rootBox = NW_HED_DocumentRoot_GetRootBox( documentRoot );
       
   229   NW_ASSERT(rootBox);
       
   230   deviceContext = NW_LMgr_RootBox_GetDeviceContext (rootBox);
       
   231   rectangle = deviceContext->DisplayBounds();
       
   232 
       
   233   if (GetVHspaceHWprop(thisObj, elId, VSPACE_ATTR, &prop.value.integer, &prop.type)) 
       
   234   {
       
   235     if (prop.type == NW_CSS_ValueType_Percentage) 
       
   236     {
       
   237       prop.value.decimal = (NW_Float32)prop.value.integer;
       
   238       prop.value.integer = (NW_GDI_Metric_t)((prop.value.decimal*rectangle->dimension.height)/100);
       
   239       prop.type = NW_CSS_ValueType_Px;
       
   240     }
       
   241     NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_topPadding,    &prop);
       
   242     NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_bottomPadding, &prop);
       
   243   }
       
   244 
       
   245   if (GetVHspaceHWprop(thisObj, elId, HSPACE_ATTR, &prop.value.integer, &prop.type)) 
       
   246   {
       
   247     if (prop.type == NW_CSS_ValueType_Percentage) 
       
   248     {
       
   249       prop.value.decimal = (NW_Float32)prop.value.integer;
       
   250       prop.value.integer = (NW_GDI_Metric_t)((prop.value.decimal*rectangle->dimension.width)/100);
       
   251       prop.type = NW_CSS_ValueType_Px;
       
   252     }
       
   253     NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_leftPadding, &prop);
       
   254     NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_rightPadding,&prop);
       
   255   }
       
   256   
       
   257   if (GetVHspaceHWprop(thisObj, elId, HEIGHT_ATTR, &heightVal.value.integer, &heightVal.type)) 
       
   258   {
       
   259     if (heightVal.type == NW_CSS_ValueType_Percentage) 
       
   260     {
       
   261       heightVal.value.decimal = (NW_Float32)heightVal.value.integer;
       
   262       heightVal.value.integer = (NW_GDI_Metric_t)((heightVal.value.decimal*rectangle->dimension.height)/100);
       
   263       heightVal.type = NW_CSS_ValueType_Px;
       
   264     }
       
   265     NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_height, &heightVal);
       
   266   }
       
   267 
       
   268   if (GetVHspaceHWprop(thisObj, elId, WIDTH_ATTR, &widthVal.value.integer, &widthVal.type)) 
       
   269   {
       
   270     if (widthVal.type == NW_CSS_ValueType_Percentage) 
       
   271     {
       
   272       widthVal.value.decimal = (NW_Float32)widthVal.value.integer;
       
   273       widthVal.value.integer = (NW_GDI_Metric_t)((widthVal.value.decimal*rectangle->dimension.width)/100);
       
   274       widthVal.type = NW_CSS_ValueType_Px;
       
   275     }
       
   276     NW_LMgr_Box_SetProperty(box, NW_CSS_Prop_width, &widthVal);
       
   277   }
       
   278   
       
   279   return;
       
   280 }
       
   281 
       
   282 /*****************************************************************
       
   283 
       
   284   Name:         LoadSrcImage
       
   285 
       
   286   Description:  Invokes image load for the WML 'src" attribute of
       
   287                 the "img: element.
       
   288 
       
   289   Parameters:   ContentHandler
       
   290                 Wrapper box for the image to be loaded
       
   291                 element Id
       
   292 
       
   293   Return Value: KBrsrSuccess
       
   294                 KBrsrOutOfMemory
       
   295                 KBrsrFailure
       
   296 
       
   297 *****************************************************************/
       
   298 TBrowserStatusCode LoadSrcImage(NW_Wml1x_ContentHandler_t *thisObj,
       
   299                                 NW_Uint16                 elId)
       
   300 {
       
   301   NW_Ucs2               *imageUrl = NULL;
       
   302   TBrowserStatusCode           status;
       
   303   NW_Text_UCS2_t        *urlObj;
       
   304   NW_HED_DocumentRoot_t *documentRoot;
       
   305 
       
   306   status = NW_Wml_GetImageUrl(&(thisObj->wmlInterpreter),
       
   307                                 elId,
       
   308                                 &imageUrl);
       
   309 
       
   310   if (status == KBrsrSuccess) {
       
   311 
       
   312     NW_ASSERT(imageUrl);
       
   313 
       
   314     urlObj = NW_Text_UCS2_New (imageUrl, 0, NW_Text_Flags_TakeOwnership);
       
   315 
       
   316     if (urlObj != NULL) {
       
   317       NW_Uint32 elId32 = elId; 
       
   318       /* get the documentRoot and invoke the Load method */
       
   319       documentRoot =
       
   320         (NW_HED_DocumentRoot_t*)NW_HED_DocumentNode_GetRootNode (thisObj);
       
   321 
       
   322       status =
       
   323         NW_HED_DocumentRoot_StartLoad (documentRoot,
       
   324                                       NW_HED_DocumentNodeOf (thisObj),
       
   325                                       NW_TextOf (urlObj),
       
   326                                       NW_HED_UrlRequest_Reason_DocLoadChild,
       
   327                                       (void*)elId32, NW_UrlRequest_Type_Image,
       
   328 									  NW_CACHE_NORMAL);
       
   329       NW_Object_Delete(urlObj);
       
   330     } else {
       
   331       status = KBrsrOutOfMemory; /* NW_Text_UCS2_New() takes care of deleting string when fails */
       
   332     }
       
   333   }
       
   334   return status;
       
   335 }
       
   336 
       
   337 /*****************************************************************
       
   338 
       
   339   Name:         StripInsecureVariables()
       
   340 
       
   341   Description:  
       
   342 
       
   343   Parameters:   
       
   344 
       
   345   Algorithm:    
       
   346 
       
   347   Return Value: 
       
   348 
       
   349 *****************************************************************/
       
   350 static TBrowserStatusCode StripInsecureVariables (NW_HED_Context_t* context)
       
   351 {
       
   352   static const NW_Ucs2 ecom[] = {'E', 'c', 'o', 'm', '_', 0};
       
   353   NW_Uint32 len = NW_Str_Strlen(ecom);
       
   354   const NW_HED_Context_Variable_t* var;
       
   355   NW_Uint32 i = 0;
       
   356 
       
   357   /* while there is another entry */
       
   358   while ((var = NW_HED_Context_GetEntry (context, i)) != NULL) {
       
   359     /* if the variable's name starts with "Ecom_" remove it -- don't increment i */
       
   360     if (!NW_Str_Strncmp ((NW_Ucs2*) var->name.storage, ecom, len)) {
       
   361       NW_HED_Context_RemoveEntry (context, i);
       
   362     }
       
   363 
       
   364     /* otherwise just increment i */
       
   365     else {
       
   366       i++;
       
   367     }
       
   368   }
       
   369 
       
   370   return KBrsrSuccess;
       
   371 }
       
   372 
       
   373 /*****************************************************************
       
   374 
       
   375   Name:         CopyInGlobalVariables()
       
   376 
       
   377   Description:  
       
   378 
       
   379   Parameters:   
       
   380 
       
   381   Algorithm:    
       
   382 
       
   383   Return Value: 
       
   384 
       
   385 *****************************************************************/
       
   386 static TBrowserStatusCode CopyInGlobalVariables(NW_Wml1x_ContentHandler_t* thisObj)
       
   387 {
       
   388   NW_HED_DocumentRoot_t* docRoot;
       
   389   NW_HED_Context_t* globalContext;
       
   390   TBrowserStatusCode status = KBrsrSuccess;
       
   391 
       
   392   /* get the global context from the doc-root */
       
   393   docRoot =
       
   394     (NW_HED_DocumentRoot_t*)NW_HED_DocumentNode_GetRootNode (thisObj);
       
   395 
       
   396   globalContext = NW_HED_DocumentRoot_GetContext (docRoot, NW_HED_DocumentRoot_ContextGlobalId);
       
   397   NW_ASSERT (globalContext);
       
   398   
       
   399   /* apply the global variables to the wml interpreter */
       
   400   NW_DeckDecoder_ContextToVarList (globalContext, thisObj->wmlInterpreter.var_list,
       
   401       thisObj->wmlInterpreter.mem_segment_general);
       
   402 
       
   403   /* clear the global variable context */
       
   404   NW_HED_Context_Reset (globalContext);
       
   405 
       
   406   return status;
       
   407 }
       
   408   
       
   409 /*****************************************************************
       
   410 
       
   411   Name:         CopyOutGlobalVariables()
       
   412 
       
   413   Description:  
       
   414 
       
   415   Parameters:   
       
   416 
       
   417   Algorithm:    
       
   418 
       
   419   Return Value: 
       
   420 
       
   421 *****************************************************************/
       
   422 static TBrowserStatusCode CopyOutGlobalVariables(NW_Wml1x_ContentHandler_t* thisObj)
       
   423 {
       
   424   NW_HED_DocumentRoot_t* docRoot;
       
   425   NW_HED_Context_t* oldGlobalContext;
       
   426   NW_HED_Context_t* newGlobalContext;
       
   427 
       
   428   /* get the global context from the doc-root */
       
   429   docRoot =
       
   430     (NW_HED_DocumentRoot_t*)NW_HED_DocumentNode_GetRootNode (thisObj);
       
   431   oldGlobalContext = NW_HED_DocumentRoot_GetContext (docRoot, NW_HED_DocumentRoot_ContextGlobalId);
       
   432 
       
   433   /* convert the varlist into a new context */
       
   434   newGlobalContext = NW_DeckDecoder_VarListToContext(thisObj->wmlInterpreter.var_list);
       
   435  
       
   436   /* strip insecure variables */
       
   437   StripInsecureVariables (newGlobalContext);
       
   438 
       
   439   /* replace the old context with the new one */
       
   440   if (newGlobalContext != NULL) {
       
   441     NW_Int8 id;
       
   442 
       
   443     NW_HED_DocumentRoot_RemoveContext (docRoot, NW_HED_DocumentRoot_ContextGlobalId);
       
   444 
       
   445     NW_Object_Delete (oldGlobalContext);
       
   446 
       
   447     id = NW_HED_DocumentRoot_ContextGlobalId;
       
   448     NW_HED_DocumentRoot_AddContext (docRoot, newGlobalContext, &id);
       
   449   }
       
   450 
       
   451   /* otherwise just reset the current old global context */
       
   452   else {
       
   453     NW_HED_Context_Reset (oldGlobalContext);
       
   454   }
       
   455 
       
   456   return KBrsrSuccess;
       
   457 }
       
   458   
       
   459 /*****************************************************************
       
   460 
       
   461   Name:         CopyInTaskVariables()
       
   462 
       
   463   Description:  
       
   464 
       
   465   Parameters:   
       
   466 
       
   467   Algorithm:    
       
   468 
       
   469   Return Value: 
       
   470 
       
   471 *****************************************************************/
       
   472 static TBrowserStatusCode CopyInTaskVariables(NW_Wml1x_ContentHandler_t* thisObj)
       
   473 {
       
   474   NW_HED_DocumentRoot_t* docRoot;
       
   475   NW_HED_Context_t* context;
       
   476   TBrowserStatusCode status = KBrsrSuccess;
       
   477 
       
   478   /* get the global context from the doc-root */
       
   479   docRoot =
       
   480     (NW_HED_DocumentRoot_t*)NW_HED_DocumentNode_GetRootNode (thisObj);
       
   481   NW_ASSERT (docRoot);
       
   482 
       
   483   context = NW_HED_DocumentRoot_GetContext (docRoot, NW_Wml1x_ContentHandler_ContextTaskId);
       
   484   if (context == NULL) {
       
   485     return KBrsrSuccess;
       
   486   }
       
   487   
       
   488   /* apply the global variables to the wml interpreter */
       
   489   NW_DeckDecoder_ContextToVarList (context, thisObj->wmlInterpreter.param_list,
       
   490       thisObj->wmlInterpreter.mem_segment_general);
       
   491 
       
   492   /* clear the global variable context */
       
   493   NW_HED_Context_Reset (context);
       
   494 
       
   495   return status;
       
   496 }
       
   497   
       
   498 
       
   499 /*****************************************************************
       
   500 
       
   501   Name:         CopyOutTaskVariables()
       
   502 
       
   503   Description:  
       
   504 
       
   505   Parameters:   
       
   506 
       
   507   Algorithm:    
       
   508 
       
   509   Return Value: 
       
   510 
       
   511 *****************************************************************/
       
   512 static TBrowserStatusCode CopyOutTaskVariables(NW_Wml1x_ContentHandler_t* thisObj)
       
   513 {
       
   514   NW_HED_DocumentRoot_t* docRoot;
       
   515   NW_HED_Context_t* oldContext;
       
   516   NW_HED_Context_t* newContext;
       
   517 
       
   518   /* get the global context from the doc-root */
       
   519   docRoot =
       
   520     (NW_HED_DocumentRoot_t*)NW_HED_DocumentNode_GetRootNode (thisObj);
       
   521   oldContext = NW_HED_DocumentRoot_GetContext (docRoot, NW_Wml1x_ContentHandler_ContextTaskId);
       
   522 
       
   523   /* convert the varlist into a new context */
       
   524   newContext = NW_DeckDecoder_VarListToContext(thisObj->wmlInterpreter.param_list);
       
   525 
       
   526   /* strip insecure variables */
       
   527   StripInsecureVariables (newContext);
       
   528 
       
   529   /* replace the old context with the new one */
       
   530   if (newContext != NULL) {
       
   531     NW_Int8 id;
       
   532 
       
   533     NW_HED_DocumentRoot_RemoveContext (docRoot, NW_Wml1x_ContentHandler_ContextTaskId);
       
   534 
       
   535     NW_Object_Delete (oldContext);
       
   536 
       
   537     id = NW_Wml1x_ContentHandler_ContextTaskId;
       
   538     NW_HED_DocumentRoot_AddContext (docRoot, newContext, &id);
       
   539   }
       
   540 
       
   541   /* otherwise just reset the current old global context */
       
   542   else {
       
   543     NW_HED_Context_Reset (oldContext);
       
   544   }
       
   545 
       
   546   return KBrsrSuccess;
       
   547 }
       
   548 
       
   549 
       
   550 
       
   551 
       
   552 /****************************************************************************
       
   553 * IMAGE RELATED STATIC MEATHODS
       
   554 *****************************************************************************/
       
   555 
       
   556 /*****************************************************************
       
   557 
       
   558   Name:         GetAltTextBox ()
       
   559 
       
   560   Description:  
       
   561 
       
   562   Parameters:   
       
   563 
       
   564   Algorithm:    
       
   565 
       
   566   Return Value: 
       
   567     
       
   568 *****************************************************************/
       
   569 static 
       
   570 TBrowserStatusCode GetAltTextBox (NW_Wml1x_ContentHandler_t *thisObj,
       
   571                            NW_Uint16                 elId,
       
   572                            NW_LMgr_TextBox_t         **textBox)
       
   573 
       
   574 {
       
   575   NW_Text_t              *altStr = NULL;
       
   576   NW_Ucs2                *retString = NULL;
       
   577   TBrowserStatusCode            ret_status = KBrsrFailure;
       
   578 
       
   579 
       
   580   *textBox = NULL;
       
   581 
       
   582   /* find the 'alt' attribute and get its string value */
       
   583   ret_status = NW_Wml_GetAttribute(&(thisObj->wmlInterpreter),
       
   584                                      elId,
       
   585                                      ALT_ATTR,
       
   586                                      &retString);
       
   587   if (ret_status == KBrsrOutOfMemory)
       
   588     return ret_status;
       
   589   
       
   590   if((ret_status  == KBrsrSuccess) && (retString != NULL)) {
       
   591     /*alt string exists*/
       
   592     altStr = (NW_Text_t*)NW_Text_UCS2_New (retString,
       
   593                                            NW_Str_Strlen(retString), 
       
   594                                            NW_Text_Flags_TakeOwnership);
       
   595     if(altStr == NULL) {
       
   596       return KBrsrOutOfMemory;
       
   597     }
       
   598     
       
   599     /* create a text box with alternative text from "alt" attribute */
       
   600     *textBox = NW_LMgr_TextBox_New(1, altStr);
       
   601 
       
   602     if(*textBox == NULL) {
       
   603       NW_Object_Delete (altStr);
       
   604       return KBrsrOutOfMemory;
       
   605     }  
       
   606 
       
   607   }
       
   608   return ret_status;
       
   609 }
       
   610 
       
   611 /*****************************************************************
       
   612 
       
   613   Name:         HandleInvalidImage()
       
   614 
       
   615   Description:  
       
   616 
       
   617   Parameters:   
       
   618 
       
   619   Algorithm:    
       
   620 
       
   621   Return Value:
       
   622     ret_status = HandleInvalidImage(contentHandler,thisObj,context,response,parentBox);
       
   623 
       
   624   Kimono modification (see HandleImageLoad):
       
   625     Added output parameter (NW_LMgr_Box_t** box)
       
   626 	Removed calls to NodeChanged, NW_Wml1x_ImageWithinAnchorDefaultStyle.
       
   627 	Removed assert on response param.
       
   628 *****************************************************************/
       
   629 TBrowserStatusCode HandleInvalidImage( NW_Wml1x_ContentHandler_t  *thisObj,
       
   630                                                      NW_HED_DocumentNode_t* documentNode,
       
   631                                                      NW_HED_DocumentNode_t* childNode,
       
   632                                NW_Url_Resp_t*             response,
       
   633                                                      void* pElId)
       
   634 {
       
   635   /*image is not valid*/ 
       
   636   NW_LMgr_Box_t*               box = NULL;
       
   637   NW_LMgr_Box_t*               contextBox = NULL;
       
   638   NW_LMgr_BoxVisitor_t         boxVisitor;
       
   639   NW_LMgr_PropertyValue_t      value;  
       
   640   NW_Uint32                    elId32 = (NW_Uint32)pElId;
       
   641   NW_LMgr_Property_t           prop;
       
   642   TBrowserStatusCode            ret_status;
       
   643   NW_LMgr_TextBox_t      *textBox = NULL;
       
   644   NW_HED_ContentHandler_t*   contentHandler;
       
   645 
       
   646   NW_ASSERT( thisObj );  
       
   647   NW_ASSERT( childNode );
       
   648   NW_REQUIRED_PARAM(response);
       
   649   
       
   650   /* for convenience */
       
   651   contentHandler = NW_HED_ContentHandlerOf( childNode );
       
   652 	/*check if we have a valid context*/
       
   653   ret_status = _NW_Wml1x_ContentHandler_GetBoxTree( documentNode, &box );   
       
   654 
       
   655   /* initialize the boxVisitor */
       
   656   value.integer = 0;
       
   657   if( ret_status == KBrsrSuccess && NW_LMgr_BoxVisitor_Initialize (&boxVisitor, NW_LMgr_BoxOf (box)) 
       
   658       == KBrsrSuccess )
       
   659     {
       
   660     while ((box = NW_LMgr_BoxVisitor_NextBox (&boxVisitor, 0)) != NULL) 
       
   661     {
       
   662       if (NW_Object_IsDerivedFrom(box, &NW_LMgr_ImgContainerBox_Class))
       
   663       {
       
   664         (void)NW_LMgr_Box_GetPropertyValue(box, NW_CSS_Prop_elementId, NW_CSS_ValueType_Integer, &value);
       
   665         if (NW_UINT16_CAST(value.integer) == NW_UINT16_CAST(elId32))
       
   666         {
       
   667           /* We found a box that has element Id same as context*/
       
   668           contextBox = box;
       
   669           break;        
       
   670         }
       
   671       }
       
   672     }
       
   673   }
       
   674   /*check for local src attrib */
       
   675   if (NW_ImageCH_Epoc32ContentHandler_GetLoadMode(NW_ImageCH_Epoc32ContentHandlerOf (contentHandler)) == 
       
   676       NW_HED_UrlRequest_LoadLocal) {
       
   677     
       
   678     return LoadSrcImage(thisObj, NW_UINT16_CAST (value.integer));
       
   679   }
       
   680   
       
   681   /* No local src specified display broken canned image with alt text if present */
       
   682   ret_status = NW_HED_DocumentNode_GetBoxTree (contentHandler, &box);
       
   683   if (ret_status != KBrsrSuccess) {
       
   684     UrlLoader_UrlResponseDelete(response);
       
   685     NW_Object_Delete (contentHandler);
       
   686     return ret_status;
       
   687   }    
       
   688   
       
   689   /*Get the alt textBox if it exists*/
       
   690   ret_status = GetAltTextBox (thisObj,NW_UINT16_CAST (value.integer),&textBox);
       
   691   if(ret_status == KBrsrOutOfMemory) {
       
   692     NW_Object_Delete (box);    
       
   693     UrlLoader_UrlResponseDelete(response);
       
   694     NW_Object_Delete (contentHandler);
       
   695     return ret_status;
       
   696   }
       
   697 
       
   698   if ((ret_status == KBrsrSuccess) && (textBox != NULL)) {
       
   699     ret_status = NW_LMgr_ContainerBox_InsertChildAft(contextBox->parent, (NW_LMgr_Box_t*)textBox, contextBox);
       
   700     if(ret_status  == KBrsrOutOfMemory) {
       
   701       NW_Object_Delete (textBox);
       
   702       return ret_status;
       
   703     }
       
   704   }
       
   705   
       
   706   ret_status = NW_LMgr_ContainerBox_InsertChildAft(contextBox->parent, box, contextBox);  
       
   707 
       
   708   if(ret_status == KBrsrSuccess) {
       
   709     
       
   710     AddImageProperties (thisObj, box, value);
       
   711     NW_Wml1x_ImageWithinAnchorDefaultStyle(&prop, box);
       
   712   }
       
   713   NW_Object_Delete(contextBox);
       
   714   return ret_status;
       
   715 }
       
   716 
       
   717 /*****************************************************************
       
   718 
       
   719   Name:         HandleValidImage()
       
   720 
       
   721   Description:  
       
   722 
       
   723   Parameters:   
       
   724 
       
   725   Algorithm:    
       
   726 
       
   727   Return Value: 
       
   728     ret_status = HandleValidImage(contentHandler,thisObj,context,response,parentBox);
       
   729 
       
   730   Kimono modification (see HandleImageLoad):
       
   731     Added output parameter (NW_LMgr_Box_t** box)
       
   732 	Removed calls to NodeChanged, NW_Wml1x_ImageWithinAnchorDefaultStyle.
       
   733 *****************************************************************
       
   734 TBrowserStatusCode HandleValidImage (NW_HED_ContentHandler_t*    contentHandler,
       
   735                               NW_Wml1x_ContentHandler_t*  thisObj,
       
   736                               NW_ADT_Vector_Metric_t      index,
       
   737                               NW_LMgr_PropertyValue_t     imgPropVal,
       
   738                               NW_Url_Resp_t*              response,
       
   739 			                        NW_LMgr_ContainerBox_t*     parentBox,
       
   740 			                        NW_LMgr_Box_t**             box)
       
   741 {
       
   742   TBrowserStatusCode  ret_status;
       
   743 
       
   744   NW_REQUIRED_PARAM(response);
       
   745   NW_ASSERT(contentHandler);
       
   746   NW_ASSERT(box);
       
   747 
       
   748   *box = NULL;
       
   749 
       
   750   ret_status = NW_HED_DocumentNode_GetBoxTree (contentHandler, box);
       
   751   if (ret_status != KBrsrSuccess) {
       
   752     NW_Url_Resp_Delete(response);
       
   753     NW_Object_Delete (contentHandler);
       
   754     return ret_status;
       
   755   }
       
   756   
       
   757   ret_status = NW_LMgr_ContainerBox_InsertChildAt(parentBox, *box, index);
       
   758   
       
   759   if(ret_status == KBrsrSuccess) {  
       
   760     AddImageProperties (thisObj, *box, imgPropVal);
       
   761     NW_Wml1x_ImageWithinAnchorDefaultStyle(&prop, *box);
       
   762   }  
       
   763   
       
   764   return ret_status;
       
   765 }*/
       
   766 
       
   767 
       
   768 
       
   769 /* ------------------------------------------------------------------------- */
       
   770 static
       
   771 NW_Bool
       
   772 NW_Wml1x_ContentHandler_IsIntraDeck (NW_HED_ContentHandler_t *thisObj,
       
   773                                      const NW_Text_UCS2_t    *url)
       
   774 {
       
   775   NW_Text_Length_t urlLength;
       
   776   const NW_Ucs2    *urlStorage        = NULL;
       
   777   const NW_Ucs2    *currentUrlStorage = NULL;
       
   778   NW_Ucs2          *urlBase           = NULL;
       
   779   NW_Ucs2          *currentUrlBase    = NULL;
       
   780   NW_Uint8         urlFreeNeeded      = NW_FALSE;
       
   781   NW_Bool          match              = NW_FALSE;
       
   782 
       
   783   /* pram check */
       
   784   NW_THROWIF_NULL (url);
       
   785 
       
   786   /* get the base urls */
       
   787   NW_THROWIF_NULL (urlStorage = NW_Text_GetUCS2Buffer(url, NW_Text_Flags_Aligned, &urlLength, &urlFreeNeeded));
       
   788 
       
   789   NW_THROWIF_NULL (currentUrlStorage = NW_HED_UrlRequest_GetRawUrl (
       
   790       NW_HED_ContentHandler_GetUrlRequest (thisObj))); /* TODO change this to NW_HED_ContentHandler_GetUrlResponse */
       
   791 
       
   792   NW_THROWIF_ERROR (NW_Url_GetBase(urlStorage, &urlBase));
       
   793   NW_THROWIF_ERROR (NW_Url_GetBase(currentUrlStorage, &currentUrlBase));
       
   794 
       
   795   /* compare the current url with the specified */
       
   796   if (0 == NW_Str_Strcmp(currentUrlBase, urlBase)) {
       
   797       match = NW_TRUE;
       
   798   }
       
   799 
       
   800   /* Fall through */
       
   801 
       
   802   /* Clean up is the same for failure and success */
       
   803 NW_CATCH_ERROR
       
   804   if (urlFreeNeeded) {
       
   805     NW_Str_Delete((NW_Ucs2 *) urlStorage);
       
   806   }
       
   807   NW_Str_Delete((NW_Ucs2 *) urlBase);
       
   808   NW_Str_Delete(currentUrlBase);
       
   809 
       
   810   return match;
       
   811 }
       
   812 
       
   813 /* ------------------------------------------------------------------------- */
       
   814 static
       
   815 TBrowserStatusCode
       
   816 NW_Wml1x_ContentHandler_CreateDocument(NW_Wml1x_ContentHandler_t* thisObj )
       
   817 {
       
   818   TBrowserStatusCode status = KBrsrFailure;
       
   819   NW_Buffer_t* domBuffer = NULL;
       
   820   NW_Bool plainText = NW_FALSE;
       
   821   NW_HED_ContentHandler_t* contentHandler;  
       
   822   NW_HED_DomTree_t* domTree;
       
   823   NW_Bool encodingFound;
       
   824   NW_Uint8 parse_number = 0;
       
   825 
       
   826   NW_LOG0(NW_LOG_LEVEL2, "NW_WML1x_ContentHandler_CreateDocument STARTS.");
       
   827 
       
   828   contentHandler = NW_HED_ContentHandlerOf( thisObj );
       
   829   status = _NW_HED_CompositeContentHandler_ComputeEncoding(NW_HED_CompositeContentHandlerOf(thisObj),
       
   830     contentHandler->response, &encodingFound);
       
   831   if (status != KBrsrSuccess)
       
   832   {
       
   833     return status;
       
   834   }
       
   835 
       
   836 
       
   837   /* convert a plain-text response into a wbxml buffer */
       
   838 htmlp_parse:
       
   839   if(0 == NW_Asc_stricmp((char*)HTTP_text_vnd_wap_wml_string, (char*)contentHandler->response->contentTypeString))
       
   840   {
       
   841     NW_Uint32 line = 0;
       
   842     NW_HED_CharsetConvContext ctx;
       
   843     ctx.contentHandler = NW_HED_CompositeContentHandlerOf(thisObj);
       
   844     ctx.response = contentHandler->response;
       
   845     NW_LOG0(NW_LOG_LEVEL2, "NW_WML1x_ContentHandler_CreateDocument before HtmlToWbxml.");
       
   846     parse_number++;
       
   847     if (!encodingFound) // Automatic settings
       
   848     {
       
   849         status = NW_HTMLP_HtmlToWbxml( contentHandler->response->body, contentHandler->response->charset,
       
   850             contentHandler->response->byteOrder,
       
   851             &domBuffer, &line, NW_Wml_1_3_PublicId, 
       
   852             NW_HTMLP_Get_WML_ElementTableCount(),NW_HTMLP_Get_WML_ElementDescriptionTable(),
       
   853             NW_TRUE, NW_TRUE, &ctx, NW_HED_CompositeContentHandler_CharConvCB, NW_FALSE);
       
   854     }
       
   855     else // Use user selection or BOM
       
   856     {
       
   857     status = NW_HTMLP_HtmlToWbxml( contentHandler->response->body, contentHandler->response->charset, 
       
   858         contentHandler->response->byteOrder,
       
   859         &domBuffer, &line, NW_Wml_1_3_PublicId, 
       
   860         NW_HTMLP_Get_WML_ElementTableCount(),
       
   861         NW_HTMLP_Get_WML_ElementDescriptionTable(),
       
   862         NW_TRUE, NW_FALSE, &ctx, NW_HED_CompositeContentHandler_CharConvCB,
       
   863         NW_FALSE);
       
   864     }
       
   865     NW_LOG0(NW_LOG_LEVEL2, "NW_WML1x_ContentHandler_CreateDocument after HtmlToWbxml.");
       
   866     if (domBuffer)
       
   867       NW_LOG1(NW_LOG_LEVEL2, "NW_WML1x_ContentHandler_CreateDocument, Length of domBuffer %d", domBuffer->length);
       
   868     if (BRSR_STAT_IS_FAILURE(status)) {
       
   869       NW_LOG0(NW_LOG_LEVEL2, "NW_WML1x_ContentHandler_CreateDocument, HtmlToWbxml returns BadContent error.");
       
   870       status = KBrsrXhtmlBadContent;
       
   871     }
       
   872 
       
   873     plainText = NW_TRUE;
       
   874   }
       
   875   else
       
   876   {
       
   877     /* Otherwise stick our wbxml content in a NW_Buffer */
       
   878 
       
   879     /* init our domBuffer */
       
   880     domBuffer = NW_Buffer_New(0);
       
   881 
       
   882     if (domBuffer != NULL && contentHandler->response->body != NULL)
       
   883     {
       
   884       domBuffer->allocatedLength = contentHandler->response->body->allocatedLength;
       
   885       domBuffer->length = contentHandler->response->body->length;
       
   886       domBuffer->data = contentHandler->response->body->data;
       
   887 
       
   888       if( 0 == NW_Asc_stricmp((char*)HTTP_application_wmlc_saved_string, 
       
   889                               (char*)contentHandler->response->contentTypeString) ||
       
   890           0 == NW_Asc_stricmp((char*)HTTP_application_saved_string, 
       
   891                               (char*)contentHandler->response->contentTypeString) )
       
   892       {
       
   893         plainText = NW_TRUE;
       
   894 
       
   895         if(contentHandler->response->charset == HTTP_iso_10646_ucs_2)
       
   896         {
       
   897           /* This block is only used to switch the byte order of domBuffer. Each time the 
       
   898           function NW_HED_DomTree_New is called, the byte order of domBuffer is changed.
       
   899           For a saved page, the domBuffer was saved in the byte order after the change when 
       
   900           this page was loaded from web. So this order is wrong when call function
       
   901           NW_Wml_LoadWmlResp below.  Thus we call NW_HED_DomTree_New here to change the
       
   902           byte order back for saved page loading */
       
   903           domTree = NW_HED_DomTree_New (domBuffer, contentHandler->response->charset, 
       
   904                                         NW_Wml_1_3_PublicId, NULL);
       
   905           if (domTree != NULL)  
       
   906           {
       
   907             /* Orphan the Buffer so it isn't deleted then delete the temp DomTree */
       
   908             domBuffer = NW_HED_DomTree_OrphanDomBuffer (domTree);
       
   909 
       
   910             NW_HED_DomTree_Delete (domTree);
       
   911             domTree = NULL;
       
   912           }
       
   913           /* end of the byte order switch */
       
   914       }
       
   915       }
       
   916 
       
   917      delete contentHandler->response->body;   
       
   918      contentHandler->response->body = NULL;    
       
   919     }
       
   920     else
       
   921     {
       
   922       status = KBrsrOutOfMemory;
       
   923     }
       
   924   }
       
   925 
       
   926   /* transfer ownership of reqUrl, redirected and content to the wml interpreter */
       
   927   if (domBuffer != NULL)
       
   928   {
       
   929     status = NW_Wml_LoadWmlResp(&thisObj->wmlInterpreter, domBuffer, plainText, contentHandler->response);
       
   930 
       
   931     // if the processing of domBuffer failed due to user selecting the wrong encoding,
       
   932     // set the default encoding to latin-1 and set the encodingFound to false so 
       
   933     // charset detection is enabled to find the right charset.
       
   934     // call the htmlp parser again to reparse it.
       
   935     if (status != KBrsrSuccess && encodingFound) 
       
   936       {
       
   937       encodingFound = NW_FALSE;
       
   938       contentHandler->response->charset = HTTP_iso_8859_1;
       
   939       if (parse_number <2)
       
   940         {
       
   941         goto htmlp_parse;
       
   942         }
       
   943       }
       
   944   }
       
   945 
       
   946 #ifdef _DEBUG
       
   947   {
       
   948     NW_HED_DomHelper_t* domHelper;
       
   949     NW_HED_DomTree_t* domTree2;
       
   950 
       
   951     domHelper = NW_Wml1x_ContentHandler_GetDomHelper (thisObj, NULL);
       
   952     domTree2 = NW_Wml1x_ContentHandler_GetDomTree (thisObj);
       
   953 
       
   954     if ((domHelper != NULL) && (domTree2 != NULL))
       
   955     {
       
   956       NW_HED_DomHelper_PrintTree (domHelper, NW_HED_DomTree_GetRootNode (domTree2));
       
   957     }
       
   958   }
       
   959 #endif
       
   960   NW_LOG0(NW_LOG_LEVEL2, "NW_WML1x_ContentHandler_CreateDocument ENDS.");
       
   961 
       
   962   return status;
       
   963 }
       
   964 
       
   965 /* ------------------------------------------------------------------------- *
       
   966    static data
       
   967  * ------------------------------------------------------------------------- */
       
   968 
       
   969 /* ------------------------------------------------------------------------- */
       
   970 const
       
   971 NW_Wml1x_ContentHandler_Class_t NW_Wml1x_ContentHandler_Class = {
       
   972   { /* NW_Object_Core                       */
       
   973     /* super                                */ &NW_HED_CompositeContentHandler_Class,
       
   974     /* queryInterface                       */ _NW_Object_Base_QueryInterface
       
   975   },
       
   976   { /* NW_Object_Base                       */
       
   977     /* interfaceList                        */ _NW_Wml1x_ContentHandler_InterfaceList
       
   978   },
       
   979   { /* NW_Object_Dynamic                    */
       
   980     /* instanceSize                         */ sizeof (NW_Wml1x_ContentHandler_t),
       
   981     /* construct                            */ _NW_Wml1x_ContentHandler_Construct,
       
   982     /* destruct                             */ _NW_Wml1x_ContentHandler_Destruct
       
   983   },
       
   984   { /* NW_HED_DocumentNode                  */
       
   985     /* cancel                               */ _NW_Wml1x_ContentHandler_Cancel,
       
   986     /* partialLoadCallback	                */ NULL,
       
   987     /* initialize                           */ _NW_Wml1x_ContentHandler_Initialize,
       
   988     /* nodeChanged                          */ _NW_HED_DocumentNode_NodeChanged,
       
   989     /* getBoxTree                           */ _NW_Wml1x_ContentHandler_GetBoxTree,
       
   990     /* processEvent                         */ _NW_HED_DocumentNode_ProcessEvent,
       
   991     /* handleError                          */ _NW_HED_DocumentNode_HandleError,
       
   992     /* suspend                              */ _NW_Wml1x_ContentHandler_Suspend,
       
   993     /* resume                               */ _NW_Wml1x_ContentHandler_Resume,
       
   994     /* allLoadsCompleted                    */ _NW_Wml1x_ContentHandler_AllLoadsCompleted,
       
   995     /* intraPageNavigationCompleted         */ _NW_Wml1x_ContentHandler_IntraPageNavigationCompleted,
       
   996     /* loseFocus                            */ _NW_Wml1x_ContentHandler_LoseFocus,
       
   997     /* gainFocus                            */ _NW_Wml1x_ContentHandler_GainFocus,
       
   998     /* handleLoadComplete                   */ _NW_HED_DocumentNode_HandleLoadComplete,
       
   999   },
       
  1000   { /* NW_HED_ContentHandler                */
       
  1001     /* partialNextChunk                     */ _NW_HED_ContentHandler_PartialNextChunk,
       
  1002     /* getTitle                             */ _NW_Wml1x_ContentHandler_GetTitle,
       
  1003     /* getUrl                               */ _NW_HED_ContentHandler_GetURL,
       
  1004     /* resolveUrl                           */ _NW_HED_ContentHandler_ResolveURL,
       
  1005     /* createHistoryEntry                   */ _NW_HED_ContentHandler_CreateHistoryEntry,
       
  1006     /* createIntraHistoryEntry              */ _NW_HED_ContentHandler_CreateIntraDocumentHistoryEntry,
       
  1007     /* newUrlResponse                       */ _NW_HED_ContentHandler_NewUrlResponse,
       
  1008     /* createBoxTree                        */ NULL,
       
  1009     /* handleRequest                        */ _NW_Wml1x_ContentHandler_HandleRequest,
       
  1010     /* featureQuery                         */ _NW_Wml1x_ContentHandler_FeatureQuery,
       
  1011     /* responseComplete                     */ _NW_HED_ContentHandler_ResponseComplete
       
  1012   },
       
  1013   { /* NW_HED_CompositeContentHandler       */
       
  1014     /* documentDisplayed                    */ _NW_HED_CompositeContentHandler_DocumentDisplayed
       
  1015   },
       
  1016   { /* NW_Wml1x_ContentHandler              */
       
  1017     /* unused                               */ NW_Object_Unused
       
  1018   }
       
  1019 };
       
  1020 
       
  1021 /* ------------------------------------------------------------------------- */
       
  1022 const
       
  1023 NW_Object_Class_t* const _NW_Wml1x_ContentHandler_InterfaceList[] = {
       
  1024   &NW_Wml1x_ContentHandler_IWmlBrowserLib_Class,
       
  1025   &NW_Wml1x_ContentHandler_IWmlScriptListener_Class,
       
  1026   &NW_Wml1x_ContentHandler_NumberCollector_Class,
       
  1027   NULL
       
  1028 };
       
  1029 
       
  1030 /* ------------------------------------------------------------------------- */
       
  1031 const
       
  1032 NW_WmlsCh_IWmlBrowserLib_Class_t NW_Wml1x_ContentHandler_IWmlBrowserLib_Class = {
       
  1033   { /* NW_Object_Core           */
       
  1034     /* super                    */ &NW_WmlsCh_IWmlBrowserLib_Class,
       
  1035     /* queryInterface           */ _NW_Object_Interface_QueryInterface
       
  1036   },
       
  1037   { /* NW_Object_Interface      */
       
  1038     /* offset                   */ offsetof (NW_Wml1x_ContentHandler_t, NW_WmlsCh_IWmlBrowserLib)
       
  1039   },
       
  1040   { /* NW_WmlsCh_IWmlBrowserLib */
       
  1041     /* init - setup task var    */ _NW_Wml1x_ContentHandler_IWmlBrowserLib_Init,
       
  1042     /* getVar                   */ _NW_Wml1x_ContentHandler_IWmlBrowserLib_GetVar,
       
  1043     /* setVar                   */ _NW_Wml1x_ContentHandler_IWmlBrowserLib_SetVar,
       
  1044     /* go                       */ _NW_Wml1x_ContentHandler_IWmlBrowserLib_Go,
       
  1045     /* prev                     */ _NW_Wml1x_ContentHandler_IWmlBrowserLib_Prev,
       
  1046     /* newContext               */ _NW_Wml1x_ContentHandler_IWmlBrowserLib_NewContext,
       
  1047     /* refresh                  */ _NW_Wml1x_ContentHandler_IWmlBrowserLib_Refresh
       
  1048   }
       
  1049 };
       
  1050 
       
  1051 /* ------------------------------------------------------------------------- */
       
  1052 const
       
  1053 NW_WmlsCh_IWmlScriptListener_Class_t NW_Wml1x_ContentHandler_IWmlScriptListener_Class = {
       
  1054   { /* NW_Object_Core           */
       
  1055     /* super                    */ &NW_WmlsCh_IWmlScriptListener_Class,
       
  1056     /* queryInterface           */ _NW_Object_Interface_QueryInterface
       
  1057   },
       
  1058   { /* NW_Object_Interface      */
       
  1059     /* offset                   */ offsetof (NW_Wml1x_ContentHandler_t, NW_WmlsCh_IWmlScriptListener)
       
  1060   },
       
  1061   { /* NW_WmlsCh_IWmlBrowserLib */
       
  1062     /* start                    */ _NW_Wml1x_ContentHandler_IWmlScriptListener_Start,
       
  1063     /* finish                   */ _NW_Wml1x_ContentHandler_IWmlScriptListener_Finish,
       
  1064   }
       
  1065 };
       
  1066 
       
  1067 /* ------------------------------------------------------------------------- */
       
  1068 const
       
  1069 NW_Markup_NumberCollector_Class_t NW_Wml1x_ContentHandler_NumberCollector_Class = {
       
  1070   { /* NW_Object_Core            */
       
  1071     /* super                     */ &NW_Markup_NumberCollector_Class,
       
  1072     /* querySecondary            */ _NW_Object_Core_QuerySecondary
       
  1073   },
       
  1074   { /* NW_Object_Secondary       */
       
  1075     /* offset                    */ offsetof (NW_Wml1x_ContentHandler_t,
       
  1076                                               NW_Markup_NumberCollector)
       
  1077   },
       
  1078   { /* NW_Object_Aggregate       */
       
  1079     /* secondaryList             */ _NW_Markup_NumberCollector_SecondaryList,
       
  1080     /* construct                 */ NULL,
       
  1081     /* destruct                  */ NULL
       
  1082   },
       
  1083   { /* NW_Markup_NumberCollector */
       
  1084     /* getBoxTree                */ _NW_Wml1x_ContentHandler_NumberCollector_GetBoxTree,
       
  1085     /* boxIsValid                */ _NW_Markup_NumberCollector_BoxIsValid,
       
  1086     /* getHrefAttr               */ _NW_Wml1x_ContentHandler_NumberCollector_GetHrefAttr,
       
  1087     /* getAltAttr                */ _NW_Wml1x_ContentHandler_NumberCollector_GetAltAttr
       
  1088   }
       
  1089 };
       
  1090 
       
  1091 /* ------------------------------------------------------------------------- *
       
  1092    virtual methods
       
  1093  * ------------------------------------------------------------------------- */
       
  1094 
       
  1095 /*****************************************************************
       
  1096 
       
  1097   Name:         _NW_Wml1x_ContentHandler_Construct()
       
  1098 
       
  1099   Description:  
       
  1100 
       
  1101   Parameters:   
       
  1102 
       
  1103   Algorithm:    
       
  1104 
       
  1105   Return Value: 
       
  1106 
       
  1107 *****************************************************************/
       
  1108 TBrowserStatusCode
       
  1109 _NW_Wml1x_ContentHandler_Construct (NW_Object_Dynamic_t* dynamicObject,
       
  1110                                     va_list* argp)
       
  1111 {
       
  1112   NW_Wml1x_ContentHandler_t     *thisObj;
       
  1113   TBrowserStatusCode                   status = KBrsrSuccess;
       
  1114   const NW_WmlApi_t                   *wml_api;
       
  1115   NW_Ucs2                       *reqUrlCpy;
       
  1116   const NW_Text_t               *url;
       
  1117   NW_LMgr_BidiFlowBox_t*        bidiFlowBox;
       
  1118   const NW_HED_UrlRequest_t*    urlRequest;
       
  1119 
       
  1120   /* for convenience */
       
  1121   thisObj = NW_Wml1x_ContentHandlerOf (dynamicObject);
       
  1122 
       
  1123   /* invoke our superclass constructor */
       
  1124   status = _NW_HED_ContentHandler_Construct (dynamicObject, argp);
       
  1125   if (status != KBrsrSuccess) {
       
  1126     return status;
       
  1127   }
       
  1128 
       
  1129   /* initialize the member variables */
       
  1130 
       
  1131   /* initialize the WML interpreter */
       
  1132   urlRequest = va_arg (*argp, NW_HED_UrlRequest_t*);
       
  1133   NW_ASSERT (urlRequest);
       
  1134   NW_ASSERT (NW_Object_IsInstanceOf (urlRequest, &NW_HED_UrlRequest_Class));
       
  1135 
       
  1136   url = NW_HED_UrlRequest_GetUrl(urlRequest);
       
  1137   reqUrlCpy = NW_Text_GetUCS2Buffer (url, NW_Text_Flags_Copy, NULL, NULL);
       
  1138   
       
  1139   if (reqUrlCpy != NULL) {
       
  1140     wml_api = NW_Api_GetWml1xCB();
       
  1141     NW_ASSERT(wml_api != NULL);
       
  1142     status = NW_Wml_InitFromShell(&thisObj->wmlInterpreter,
       
  1143                           reqUrlCpy, wml_api, thisObj);
       
  1144     NW_Mem_Free(reqUrlCpy);
       
  1145   } else {
       
  1146     status = KBrsrOutOfMemory;
       
  1147   }
       
  1148 
       
  1149   /* create the Wml1x_FormLiaison object */
       
  1150   thisObj->formLiaison = NW_Wml1x_FormLiaison_New (thisObj);
       
  1151 
       
  1152 
       
  1153   /* ensure destructor will not break anything */
       
  1154   thisObj->title = NULL;
       
  1155   /* thisObj->currentBox = NULL; */
       
  1156   thisObj->wmlTimer = NULL;
       
  1157   thisObj->optionMap = NULL;
       
  1158   thisObj->optionItemList = NULL;
       
  1159   thisObj->contextSuspended = NULL;
       
  1160   thisObj->saveddeck = NW_FALSE;
       
  1161   thisObj->histload = NW_FALSE;
       
  1162   thisObj->reload = NW_FALSE;
       
  1163   thisObj->allowTimer = NW_TRUE;
       
  1164 
       
  1165   /* create boxtree here, this fix the bug in this case:
       
  1166 
       
  1167   <wml> 
       
  1168     <template> 
       
  1169       <!-- Template implementation here. --> 
       
  1170       <do type="prev"><prev/></do> 
       
  1171     </template> 
       
  1172     <card id="card1" title="Card #1" newcontext="true"> 
       
  1173       <onevent type="onenterforward">
       
  1174       <go href="opg.wmls#main('card2')"/>
       
  1175       </onevent>
       
  1176     </card>
       
  1177     <card id="card2" title="Card #2"> 
       
  1178       <p> 
       
  1179         Test result: $test
       
  1180         Literal Value: $literal
       
  1181       </p> 
       
  1182     </card>
       
  1183   This WML page cause loading a script page without having any boxtree in the Wml1x Content Handler */
       
  1184     
       
  1185   bidiFlowBox = NW_LMgr_BidiFlowBox_New(0);
       
  1186   NW_HED_ContentHandlerOf (thisObj)->boxTree = NW_LMgr_BoxOf(bidiFlowBox);
       
  1187   thisObj->currentBox = NW_HED_ContentHandlerOf (thisObj)->boxTree;
       
  1188   if (thisObj->currentBox == NULL) {
       
  1189     return KBrsrFailure;
       
  1190   }
       
  1191 
       
  1192   return status;
       
  1193 }
       
  1194 
       
  1195 /*****************************************************************
       
  1196 
       
  1197   Name:         _NW_Wml1x_ContentHandler_Destruct()
       
  1198 
       
  1199   Description:  
       
  1200 
       
  1201   Parameters:   
       
  1202 
       
  1203   Algorithm:    
       
  1204 
       
  1205   Return Value: 
       
  1206 
       
  1207 *****************************************************************/
       
  1208 void
       
  1209 _NW_Wml1x_ContentHandler_Destruct (NW_Object_Dynamic_t* dynamicObject)
       
  1210 {
       
  1211   NW_Wml1x_ContentHandler_t *thisObj;
       
  1212 
       
  1213   /* for convenience */
       
  1214   thisObj = NW_Wml1x_ContentHandlerOf (dynamicObject);
       
  1215 
       
  1216   NW_Object_Delete (thisObj->title);
       
  1217   NW_Object_Delete (thisObj->currentUrl);
       
  1218   NW_Object_Delete (thisObj->optionMap);
       
  1219   NW_Object_Delete (thisObj->formLiaison);
       
  1220 
       
  1221   thisObj->title = NULL;
       
  1222   thisObj->currentUrl    = NULL;
       
  1223   thisObj->optionMap = NULL;
       
  1224   thisObj->formLiaison   = NULL;
       
  1225   
       
  1226   /* ensure that the content handler is suspended */
       
  1227   _NW_Wml1x_ContentHandler_Suspend (NW_HED_DocumentNodeOf (thisObj), NW_TRUE);
       
  1228 
       
  1229   /* unregister with the wae user agent */
       
  1230   TBrowserStatusCode status = NW_Wml_Exit(&thisObj->wmlInterpreter);
       
  1231   NW_ASSERT(status == KBrsrSuccess);
       
  1232 
       
  1233 	/* NW_Object_Delete handles NULL pointer */
       
  1234 	NW_Object_Delete (thisObj->contextSuspended);
       
  1235 }
       
  1236 
       
  1237 /*****************************************************************
       
  1238 
       
  1239   Name:         _NW_Wml1x_ContentHandler_Initialize()
       
  1240 
       
  1241   Description:  
       
  1242 
       
  1243   Parameters:   
       
  1244 
       
  1245   Algorithm:    
       
  1246 
       
  1247   Return Value: 
       
  1248 
       
  1249 *****************************************************************/
       
  1250 TBrowserStatusCode
       
  1251 _NW_Wml1x_ContentHandler_Initialize( NW_HED_DocumentNode_t *documentNode,
       
  1252     TBrowserStatusCode aInitStatus )
       
  1253 {
       
  1254   TBrowserStatusCode               status; 
       
  1255   NW_Wml1x_ContentHandler_t *thisObj;
       
  1256   NW_HED_ContentHandler_t* contentHandler;
       
  1257   const NW_HED_UrlRequest_t *urlRequest;
       
  1258   NW_WaeUsrAgent_t              *wae;
       
  1259 
       
  1260   NW_REQUIRED_PARAM( aInitStatus );
       
  1261 
       
  1262   /* for convenience */
       
  1263   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1264   contentHandler = NW_HED_ContentHandlerOf( thisObj );
       
  1265 
       
  1266   /* register the WML callback with the Wml Interpreter */
       
  1267   wae = (NW_WaeUsrAgent_t*)NW_Ctx_Get(NW_CTX_WML_CORE, 0);
       
  1268   NW_ASSERT(wae != NULL);
       
  1269 
       
  1270   urlRequest = NW_HED_ContentHandler_GetUrlRequest ( thisObj );
       
  1271   NW_ASSERT(urlRequest);
       
  1272   /* 
       
  1273   ** copy the global variables from the document-root.  Don't
       
  1274   ** do this if the request that created the content-handler
       
  1275   ** was started from a shell request, like the goto dialog or
       
  1276   ** hotlist dialog.  See WML June2000 Specification section 10.4. 
       
  1277   */
       
  1278   // ZAL: add comment why it has been moved here from construct
       
  1279   if (NW_HED_UrlRequest_GetReason( urlRequest ) != NW_HED_UrlRequest_Reason_ShellLoad ) 
       
  1280     {
       
  1281     CopyInGlobalVariables (thisObj);
       
  1282 
       
  1283     CopyInTaskVariables (thisObj);
       
  1284     NW_Wml_ApplyTaskVariables(&thisObj->wmlInterpreter);
       
  1285     }
       
  1286 
       
  1287  if( contentHandler->response )
       
  1288    {
       
  1289     /* set the correct saveddeck boolean value */
       
  1290     if( 0 == NW_Asc_stricmp( (char*)HTTP_application_wmlc_saved_string, 
       
  1291 		                         (char*)contentHandler->response->contentTypeString ) ||
       
  1292         0 == NW_Asc_stricmp( (char*)HTTP_application_saved_string, 
       
  1293                              (char*)contentHandler->response->contentTypeString ) )
       
  1294     {
       
  1295       NW_Wml1x_ContentHandler_SetSaveddeck (thisObj, NW_TRUE);
       
  1296     }
       
  1297 
       
  1298     if(NW_HED_UrlRequest_GetReason( urlRequest ) != NW_HED_UrlRequest_Reason_ShellPrev ) 
       
  1299     {
       
  1300       NW_Wml1x_ContentHandler_SetHistload (thisObj, NW_TRUE);
       
  1301     }
       
  1302 
       
  1303     if(NW_HED_UrlRequest_GetReason( urlRequest ) != NW_HED_UrlRequest_Reason_ShellReload ) 
       
  1304     {
       
  1305       NW_Wml1x_ContentHandler_SetReload (thisObj, NW_TRUE);
       
  1306     }
       
  1307 
       
  1308     
       
  1309 	/* initialize the WML interpreter */
       
  1310     NW_HED_DocumentRoot_t* documentRoot = NULL;
       
  1311 	NW_HED_HistoryStack_t* history = NULL;
       
  1312     NW_Uint8 reason = NW_HED_UrlRequest_GetReason(urlRequest);
       
  1313     documentRoot = (NW_HED_DocumentRoot_t*) NW_HED_DocumentNode_GetRootNode (thisObj);
       
  1314     if (documentRoot)
       
  1315         {
       
  1316 	    history = NW_HED_DocumentRoot_GetHistoryStack (documentRoot);
       
  1317         }
       
  1318     if (history)
       
  1319         {
       
  1320         NW_Bool possiblyOEB  = history->iWmlCtrl->HistoryController().possibleWmlOEB();
       
  1321         if (possiblyOEB)
       
  1322             {
       
  1323             reason = NW_HED_UrlRequest_Reason_DocPrev;
       
  1324             history->iWmlCtrl->HistoryController().setPossibleWmlOEB(EFalse);
       
  1325             }
       
  1326         }
       
  1327     /* Set the actual task in Wml */
       
  1328     thisObj->wmlInterpreter.curr_task = HedToWmlTask(reason);
       
  1329 
       
  1330     status = NW_Wae_RegisterWml(wae, &thisObj->wmlInterpreter);
       
  1331 
       
  1332     /* create the DOM document */
       
  1333     status = NW_Wml1x_ContentHandler_CreateDocument (thisObj );
       
  1334 
       
  1335     /* disables small scrren layout */
       
  1336     NW_Settings_SetDisableSmallScreenLayout(NW_TRUE);
       
  1337    }
       
  1338  else
       
  1339    {
       
  1340    status = KBrsrUnexpectedError;
       
  1341    }
       
  1342  // ZAL: why don't we call superclass init just like xhtmlCH does?
       
  1343  // temp
       
  1344  if( status == KBrsrSuccess && contentHandler )
       
  1345    {
       
  1346    contentHandler->initialized = NW_TRUE;
       
  1347    }
       
  1348   return status;
       
  1349 }
       
  1350 
       
  1351 /*****************************************************************
       
  1352 
       
  1353   Name:         _NW_Wml1x_ContentHandler_GetBoxTree()
       
  1354 
       
  1355   Description:  
       
  1356 
       
  1357   Parameters:   
       
  1358 
       
  1359   Algorithm:    
       
  1360 
       
  1361   Return Value: 
       
  1362 
       
  1363 *****************************************************************/
       
  1364 TBrowserStatusCode
       
  1365 _NW_Wml1x_ContentHandler_GetBoxTree (NW_HED_DocumentNode_t* documentNode,
       
  1366                                      NW_LMgr_Box_t** boxTree)
       
  1367 {
       
  1368 
       
  1369   NW_Wml1x_ContentHandler_t* thisObj;
       
  1370 
       
  1371   /* parameter assertion block */
       
  1372   NW_ASSERT (NW_Object_IsInstanceOf (documentNode,
       
  1373                                      &NW_HED_DocumentNode_Class));
       
  1374 
       
  1375   /* for convenience */
       
  1376   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1377 
       
  1378   /* successful completion */
       
  1379   *boxTree = NW_HED_ContentHandlerOf (thisObj)->boxTree;
       
  1380   if (*boxTree == NULL) {
       
  1381     return KBrsrFailure;
       
  1382   }
       
  1383   return KBrsrSuccess;
       
  1384 }
       
  1385 
       
  1386 /*****************************************************************
       
  1387 
       
  1388   Name:         _NW_Wml1x_ContentHandler_Suspend()
       
  1389 
       
  1390   Description:  
       
  1391 
       
  1392   Parameters:   
       
  1393 
       
  1394   Algorithm:    
       
  1395 
       
  1396   Return Value: 
       
  1397 
       
  1398 *****************************************************************/
       
  1399 void
       
  1400 _NW_Wml1x_ContentHandler_Suspend (NW_HED_DocumentNode_t* documentNode, NW_Bool aDestroyBoxTree)
       
  1401 {
       
  1402   NW_Wml1x_ContentHandler_t* thisObj;
       
  1403   NW_WaeUsrAgent_t              *wae;
       
  1404   NW_HED_DocumentRoot_t     *docRoot;
       
  1405 
       
  1406   /* parameter assertion block */
       
  1407   NW_ASSERT (NW_Object_IsInstanceOf (documentNode, &NW_Wml1x_ContentHandler_Class));
       
  1408 
       
  1409   /* for convenience */
       
  1410   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1411 
       
  1412   /* just return if we are already suspended */
       
  1413   if (thisObj->isSuspended == NW_TRUE) {
       
  1414     return;
       
  1415   }
       
  1416 
       
  1417   thisObj->isSuspended = NW_TRUE;
       
  1418 
       
  1419   /* call our super class to suspend the children */
       
  1420   NW_HED_CompositeContentHandler_Class.NW_HED_DocumentNode.
       
  1421     suspend (documentNode, aDestroyBoxTree);
       
  1422 
       
  1423   /* copy the global variables out */
       
  1424   (void) CopyOutGlobalVariables (thisObj);
       
  1425 
       
  1426   /* Copy out task variable */
       
  1427   (void) CopyOutTaskVariables (thisObj);
       
  1428 
       
  1429   /* stop our timers */
       
  1430   if (((thisObj->wmlInterpreter).wml_api != NULL) && 
       
  1431       ((thisObj->wmlInterpreter).wml_api->timer)) {
       
  1432     (void)(thisObj->wmlInterpreter).wml_api->timer->destroy(thisObj);
       
  1433   }
       
  1434 
       
  1435   /* cleanup the dynamic item list in the OptionList */
       
  1436   docRoot =
       
  1437     (NW_HED_DocumentRoot_t*)NW_HED_DocumentNode_GetRootNode (thisObj);
       
  1438 
       
  1439   NW_ASSERT(docRoot->appServices != NULL);
       
  1440 
       
  1441   if (docRoot->appServices->pictureViewApi.initDynList != NULL) {
       
  1442     (docRoot->appServices->pictureViewApi.initDynList)(docRoot->browserApp_Ctx);
       
  1443   }
       
  1444    
       
  1445   if (thisObj->optionItemList != NULL) {
       
  1446     NW_Wml1x_ContentHandler_DeleteOptionItemList(thisObj->optionItemList);
       
  1447     thisObj->optionItemList = NULL;
       
  1448   }
       
  1449   /* unregister wae */
       
  1450   wae = (NW_WaeUsrAgent_t*)NW_Ctx_Get(NW_CTX_WML_CORE, 0);
       
  1451   NW_ASSERT(wae != NULL); 
       
  1452 
       
  1453   TBrowserStatusCode status = NW_Wae_UnRegisterWml(wae);
       
  1454   NW_ASSERT(status == KBrsrSuccess);
       
  1455 }
       
  1456 
       
  1457 /*****************************************************************
       
  1458 
       
  1459   Name:         _NW_Wml1x_ContentHandler_Resume()
       
  1460 
       
  1461   Description:  
       
  1462 
       
  1463   Parameters:   
       
  1464 
       
  1465   Algorithm:    
       
  1466 
       
  1467   Return Value: 
       
  1468 
       
  1469 *****************************************************************/
       
  1470 void
       
  1471 _NW_Wml1x_ContentHandler_Resume (NW_HED_DocumentNode_t* documentNode)
       
  1472 {
       
  1473   NW_Wml1x_ContentHandler_t* thisObj;
       
  1474   NW_WaeUsrAgent_t              *wae;
       
  1475 
       
  1476   /* parameter assertion block */
       
  1477   NW_ASSERT (NW_Object_IsInstanceOf (documentNode, &NW_Wml1x_ContentHandler_Class));
       
  1478 
       
  1479   /* for convenience */
       
  1480   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1481 
       
  1482   /* just return if we are not suspended */
       
  1483   if (thisObj->isSuspended == NW_FALSE) {
       
  1484     return;
       
  1485   }
       
  1486 
       
  1487   thisObj->isSuspended = NW_FALSE;
       
  1488 
       
  1489   /* call our super class to resume the children */
       
  1490   NW_HED_CompositeContentHandler_Class.NW_HED_DocumentNode.
       
  1491       resume (documentNode);
       
  1492 
       
  1493   /* register wae */
       
  1494   wae = (NW_WaeUsrAgent_t*)NW_Ctx_Get(NW_CTX_WML_CORE, 0);
       
  1495   NW_ASSERT(wae != NULL);
       
  1496   (void) NW_Wae_RegisterWml(wae, &thisObj->wmlInterpreter);
       
  1497 
       
  1498   /* tickle the content handler */
       
  1499   TBrowserStatusCode status = NW_Wml_HandleIntraDocRequest (&thisObj->wmlInterpreter, RESTORE_TASK, NW_TRUE, NULL);
       
  1500   NW_ASSERT(status == KBrsrSuccess);
       
  1501 }
       
  1502 
       
  1503 /*****************************************************************
       
  1504 
       
  1505   Name:         _NW_Wml1x_ContentHandler_AllLoadsCompleted()
       
  1506 
       
  1507   Description:  
       
  1508 
       
  1509   Parameters:   
       
  1510 
       
  1511   Algorithm:    
       
  1512 
       
  1513   Return Value: 
       
  1514 
       
  1515 *****************************************************************/
       
  1516 void
       
  1517 _NW_Wml1x_ContentHandler_AllLoadsCompleted (NW_HED_DocumentNode_t* documentNode)
       
  1518 {
       
  1519   NW_Wml1x_ContentHandler_t* thisObj;
       
  1520 
       
  1521   /* parameter assertion block */
       
  1522   NW_ASSERT (NW_Object_IsInstanceOf (documentNode, &NW_Wml1x_ContentHandler_Class));
       
  1523 
       
  1524   /* for convenience */
       
  1525   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1526 
       
  1527   /* call our super class to notify the children */
       
  1528   NW_HED_CompositeContentHandler_Class.NW_HED_DocumentNode.
       
  1529     allLoadsCompleted (documentNode);
       
  1530 
       
  1531   /* TODO here we can start timers, animations, etc. */
       
  1532 
       
  1533   if (thisObj->allowTimer)
       
  1534   {
       
  1535       /* set timer after all loads associated with the pages are completed. 
       
  1536      Exception is when the load was for WmlScript. In this case 
       
  1537          "outstandingLoadCount" is negative value */
       
  1538       if (thisObj->wmlInterpreter.outstandingLoadCount >= 0) {
       
  1539         NW_Wml_HandleTimer (&thisObj->wmlInterpreter);
       
  1540       }
       
  1541   }
       
  1542 }
       
  1543 
       
  1544 /*****************************************************************
       
  1545 
       
  1546   Name:         _NW_Wml1x_ContentHandler_IntraPageNavigationCompleted()
       
  1547 
       
  1548   Description:  
       
  1549 
       
  1550   Parameters:   
       
  1551 
       
  1552   Algorithm:    
       
  1553 
       
  1554   Return Value: 
       
  1555 
       
  1556 *****************************************************************/
       
  1557 TBrowserStatusCode
       
  1558 _NW_Wml1x_ContentHandler_IntraPageNavigationCompleted (NW_HED_DocumentNode_t* documentNode)
       
  1559 {
       
  1560   TBrowserStatusCode status = KBrsrSuccess;
       
  1561   NW_Wml1x_ContentHandler_t* thisObj;
       
  1562 
       
  1563   /* parameter assertion block */
       
  1564   NW_ASSERT (NW_Object_IsInstanceOf (documentNode, &NW_Wml1x_ContentHandler_Class));
       
  1565 
       
  1566   /* for convenience */
       
  1567   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1568 
       
  1569   /* call our super class to notify the children */
       
  1570   status = NW_HED_CompositeContentHandler_Class.NW_HED_DocumentNode.
       
  1571       intraPageNavigationCompleted (documentNode);
       
  1572   
       
  1573   /* set timer after all loads associated with the pages are completed*/
       
  1574   /*lint -e{666} Expression with side effects passed to repeated parameter in macro*/
       
  1575   if(!NW_HED_DocumentRoot_IsLoading(NW_HED_DocumentNode_GetRootNode (documentNode))) {
       
  1576     status = NW_Wml_HandleTimer(&thisObj->wmlInterpreter);
       
  1577   }
       
  1578 
       
  1579 
       
  1580   return status;
       
  1581 }
       
  1582 /*****************************************************************
       
  1583 
       
  1584   Name:         _NW_Wml1x_ContentHandler_LoseFocus()
       
  1585 
       
  1586   Description:  
       
  1587 
       
  1588   Parameters:   
       
  1589 
       
  1590   Algorithm:    
       
  1591 
       
  1592   Return Value: 
       
  1593 
       
  1594 *****************************************************************/
       
  1595 void
       
  1596 _NW_Wml1x_ContentHandler_LoseFocus (NW_HED_DocumentNode_t* documentNode)
       
  1597 {
       
  1598   NW_Wml1x_ContentHandler_t* thisObj;
       
  1599 
       
  1600   /* parameter assertion block */
       
  1601   NW_ASSERT (NW_Object_IsInstanceOf (documentNode, &NW_Wml1x_ContentHandler_Class));
       
  1602 
       
  1603   /* for convenience */
       
  1604   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1605 
       
  1606   /* call our super class to suspend the children */
       
  1607   NW_HED_CompositeContentHandler_Class.NW_HED_DocumentNode.
       
  1608     loseFocus (documentNode);
       
  1609 
       
  1610   /* stop our timers */
       
  1611   if (((thisObj->wmlInterpreter).wml_api != NULL) && 
       
  1612       ((thisObj->wmlInterpreter).wml_api->timer)) {
       
  1613     (void)(thisObj->wmlInterpreter).wml_api->timer->stop(thisObj);
       
  1614   }
       
  1615 }
       
  1616 
       
  1617 /*****************************************************************
       
  1618 
       
  1619   Name:         _NW_Wml1x_ContentHandler_GainFocus()
       
  1620 
       
  1621   Description:  
       
  1622 
       
  1623   Parameters:   
       
  1624 
       
  1625   Algorithm:    
       
  1626 
       
  1627   Return Value: 
       
  1628 
       
  1629 *****************************************************************/
       
  1630 void
       
  1631 _NW_Wml1x_ContentHandler_GainFocus (NW_HED_DocumentNode_t* documentNode)
       
  1632 {
       
  1633   NW_Wml1x_ContentHandler_t* thisObj;
       
  1634 
       
  1635   /* parameter assertion block */
       
  1636   NW_ASSERT (NW_Object_IsInstanceOf (documentNode, &NW_Wml1x_ContentHandler_Class));
       
  1637 
       
  1638   /* for convenience */
       
  1639   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1640 
       
  1641   /* call our super class to resume the children */
       
  1642   NW_HED_CompositeContentHandler_Class.NW_HED_DocumentNode.
       
  1643     gainFocus (documentNode);
       
  1644 
       
  1645   /* stop our timers */
       
  1646   if (((thisObj->wmlInterpreter).wml_api != NULL) && 
       
  1647       ((thisObj->wmlInterpreter).wml_api->timer)) {
       
  1648     (void)(thisObj->wmlInterpreter).wml_api->timer->resume(thisObj);
       
  1649   }
       
  1650 }
       
  1651 
       
  1652 /*****************************************************************
       
  1653 
       
  1654   Name:         _NW_Wml1x_ContentHandler_GetTitle()
       
  1655 
       
  1656   Description:  
       
  1657 
       
  1658   Parameters:   
       
  1659 
       
  1660   Algorithm:    
       
  1661 
       
  1662   Return Value: 
       
  1663 
       
  1664 *****************************************************************/
       
  1665 const NW_Text_t*
       
  1666 _NW_Wml1x_ContentHandler_GetTitle (NW_HED_ContentHandler_t* contentHandler)
       
  1667 {
       
  1668   NW_Wml1x_ContentHandler_t*    thisObj;
       
  1669   NW_Ucs2*                    cardTitle = NULL;
       
  1670   TBrowserStatusCode                   status;
       
  1671 
       
  1672   
       
  1673   /* for convenience */
       
  1674   thisObj = NW_Wml1x_ContentHandlerOf (contentHandler);
       
  1675 
       
  1676   /* we create the title just-in-time */
       
  1677   if (thisObj->title != NULL) {
       
  1678     NW_Object_Delete (thisObj->title);
       
  1679     thisObj->title = NULL;
       
  1680   }
       
  1681 
       
  1682   if(thisObj->wmlInterpreter.decoder != NULL)
       
  1683     {
       
  1684     status = NW_DeckDecoder_GetCardTitle(thisObj->wmlInterpreter.decoder, 
       
  1685       thisObj->wmlInterpreter.var_list, &cardTitle);
       
  1686     if (status == KBrsrSuccess)
       
  1687         {
       
  1688         thisObj->title =
       
  1689         (NW_Text_t*) NW_Text_UCS2_New (cardTitle, 0, NW_Text_Flags_TakeOwnership);
       
  1690         }
       
  1691     }
       
  1692      
       
  1693   return thisObj->title;
       
  1694 }
       
  1695 
       
  1696 /*****************************************************************
       
  1697 
       
  1698   Name:         _NW_Wml1x_ContentHandler_Cancel()
       
  1699 
       
  1700   Description:  
       
  1701 
       
  1702   Parameters:   
       
  1703 
       
  1704   Algorithm:    
       
  1705 
       
  1706   Return Value: 
       
  1707 
       
  1708 *****************************************************************/
       
  1709 TBrowserStatusCode
       
  1710 _NW_Wml1x_ContentHandler_Cancel (NW_HED_DocumentNode_t* documentNode, 
       
  1711 				 NW_HED_CancelType_t cancelType)
       
  1712 {
       
  1713   TBrowserStatusCode                 status  = KBrsrSuccess;
       
  1714   NW_Wml1x_ContentHandler_t*  thisObj = NULL;
       
  1715   NW_HED_DocumentRoot_t*      docRoot = NULL;
       
  1716 
       
  1717   /* parameter assertion block */
       
  1718   NW_ASSERT (NW_Object_IsInstanceOf (documentNode,
       
  1719                                      &NW_Wml1x_ContentHandler_Class));
       
  1720 
       
  1721   /* for convenience */
       
  1722   thisObj = NW_Wml1x_ContentHandlerOf (documentNode);
       
  1723   docRoot = (NW_HED_DocumentRoot_t*) NW_HED_DocumentNode_GetRootNode (thisObj);
       
  1724   
       
  1725   /* We would like to stop all the timer in case of Cancel, except the case
       
  1726      where user initiated the cancel.  User can hit cancel button even where 
       
  1727      there are no pending loads and in that case we don't want to stop the 
       
  1728      timers.  
       
  1729 
       
  1730      Timer in a wml card is started only after all the loads in the page 
       
  1731      complete */
       
  1732   if(cancelType != NW_HED_CancelType_User) {
       
  1733      (void)(thisObj->wmlInterpreter).wml_api->timer->stop(thisObj);
       
  1734   }
       
  1735 
       
  1736   /* if there has been an onEnterForward or onEnterBackward navigation and there is an error, display
       
  1737      the current content (ie, last navigated card).  It is desirable to limit re-rendering the content
       
  1738      to oef error cases only as single navigations have ALREADY rendered the last good card. */
       
  1739   if (docRoot->documentErrorClass != 0 && thisObj->wmlInterpreter.oefNavigation == NW_TRUE) {
       
  1740        NW_Wml_DisplayCard(&(thisObj->wmlInterpreter), NW_FALSE);
       
  1741   }
       
  1742 
       
  1743   status = NW_HED_CompositeContentHandler_Class.NW_HED_DocumentNode.
       
  1744     cancel (documentNode, cancelType);
       
  1745 
       
  1746   return status;
       
  1747 }
       
  1748   
       
  1749 /*****************************************************************
       
  1750 
       
  1751   Name:         _NW_Wml1x_ContentHandler_HandleRequest()
       
  1752 
       
  1753   Description:  Method is called to handle url-requests that are 
       
  1754                 originated outside of wml -- for example the shell.
       
  1755                 Requests that are started from inside of wml, link
       
  1756                 activation, wml-prev, scripts, etc do NOT go through
       
  1757                 this method but instead are handled internally.
       
  1758                 Although both internal and external requests go through
       
  1759                 NW_Wml_HandleIntraDocRequest.
       
  1760 
       
  1761   Parameters:   
       
  1762 
       
  1763   Algorithm:    
       
  1764 
       
  1765   Return Value: 
       
  1766 
       
  1767 *****************************************************************/
       
  1768 TBrowserStatusCode
       
  1769 _NW_Wml1x_ContentHandler_HandleRequest (NW_HED_ContentHandler_t *thisObj,
       
  1770                                         NW_HED_UrlRequest_t     *urlRequest)
       
  1771 {
       
  1772   NW_Wml1x_ContentHandler_t *wmlObj;
       
  1773   NW_Uint8                  reason;
       
  1774   NW_Wml_Task_e             task;
       
  1775   const NW_Ucs2             *url;
       
  1776 
       
  1777   TBrowserStatusCode status = KBrsrFailure;
       
  1778 
       
  1779   NW_ASSERT (NW_Object_IsInstanceOf (thisObj, &NW_Wml1x_ContentHandler_Class));
       
  1780   NW_ASSERT (urlRequest != NULL);
       
  1781 
       
  1782   /* don't handle reload requests here */
       
  1783   if (NW_HED_UrlRequest_GetReason (urlRequest) == NW_HED_UrlRequest_Reason_ShellReload) {
       
  1784     return KBrsrFailure;
       
  1785   }
       
  1786 
       
  1787   /* don't handle post requests here */
       
  1788   if (NW_HED_UrlRequest_GetMethod (urlRequest) == NW_URL_METHOD_POST) {
       
  1789     return KBrsrFailure;
       
  1790   }
       
  1791 
       
  1792   wmlObj = NW_Wml1x_ContentHandlerOf (thisObj);
       
  1793 
       
  1794   /* get the reason and set the task type */
       
  1795   reason = NW_HED_UrlRequest_GetReason(urlRequest);
       
  1796 
       
  1797   /* Make sure that setvar's are executed for _ShellPrev */
       
  1798   if (reason == NW_HED_UrlRequest_Reason_ShellPrev) {
       
  1799     NW_THROWIF_ERROR (status = NW_Wml_ProcessSetvarElements(&wmlObj->wmlInterpreter));
       
  1800   }
       
  1801   
       
  1802   /* if this request is not targeted to this deck or 
       
  1803      no-cache is requested then return failure */
       
  1804   if (urlRequest->cacheMode == NW_CACHE_NOCACHE || 
       
  1805       (NW_Wml1x_ContentHandler_IsIntraDeck (thisObj,
       
  1806         (NW_Text_UCS2_t*)NW_HED_UrlRequest_GetUrl(urlRequest)) == NW_FALSE) || reason == NW_HED_UrlRequest_Reason_ShellLoad ||
       
  1807       reason == NW_HED_UrlRequest_Reason_DocLoad || (urlRequest->loadType == NW_UrlRequest_Type_Image)) {
       
  1808     return KBrsrFailure;
       
  1809   }
       
  1810   
       
  1811   switch (reason) {
       
  1812     case NW_HED_UrlRequest_Reason_ShellPrev:
       
  1813     case NW_HED_UrlRequest_Reason_DocPrev:
       
  1814       task = PREV_TASK;
       
  1815       break;
       
  1816     
       
  1817     case NW_HED_UrlRequest_Reason_RestorePrev:
       
  1818     case NW_HED_UrlRequest_Reason_RestoreNext:
       
  1819       task = RESTORE_TASK;
       
  1820       break;
       
  1821 
       
  1822     default:
       
  1823       task = GO_TASK;
       
  1824       break;
       
  1825   }
       
  1826 
       
  1827   /* get the url */
       
  1828   url = NW_HED_UrlRequest_GetRawUrl (urlRequest);
       
  1829 
       
  1830   NW_THROWIF_ERROR (status = NW_Wml_HandleIntraDocRequest(&wmlObj->wmlInterpreter,
       
  1831       task, NW_HED_UrlRequest_IsHistoricRequest (urlRequest), url));
       
  1832 
       
  1833   return KBrsrSuccess;
       
  1834 
       
  1835 NW_CATCH_ERROR
       
  1836   return status;
       
  1837 }
       
  1838 
       
  1839 /*****************************************************************
       
  1840 
       
  1841   Name:         _NW_Wml1x_ContentHandler_FeatureQuery()
       
  1842 
       
  1843   Description:  Method is called to verify if a particular feature 
       
  1844                 required by this content handler
       
  1845 
       
  1846   Parameters:   
       
  1847 
       
  1848   Algorithm:    
       
  1849 
       
  1850   Return Value: 
       
  1851 
       
  1852 *****************************************************************/
       
  1853 TBrowserStatusCode
       
  1854 _NW_Wml1x_ContentHandler_FeatureQuery (NW_HED_ContentHandler_t *thisObj,
       
  1855                                        NW_HED_ContentHandler_Feature_t featureId)
       
  1856 {
       
  1857   TBrowserStatusCode nwStatus;
       
  1858 
       
  1859   NW_ASSERT (NW_Object_IsInstanceOf (thisObj, &NW_Wml1x_ContentHandler_Class));
       
  1860 	NW_REQUIRED_PARAM(thisObj);
       
  1861 
       
  1862   switch (featureId)
       
  1863   {
       
  1864     case NW_HED_ContentHandler_HitoryPrevUseStale:
       
  1865       nwStatus = KBrsrSuccess;
       
  1866       break;
       
  1867     default:
       
  1868       nwStatus = KBrsrFailure;
       
  1869       break;
       
  1870   }
       
  1871   return nwStatus;
       
  1872 }
       
  1873 /*****************************************************************
       
  1874 
       
  1875   Name:         _NW_Wml1x_ContentHandler_IWmlBrowserLib_Init()
       
  1876 
       
  1877   Description:
       
  1878 
       
  1879   Parameters:   
       
  1880 
       
  1881   Algorithm:    
       
  1882 
       
  1883   Return Value: 
       
  1884 
       
  1885 *****************************************************************/
       
  1886 TBrowserStatusCode
       
  1887 _NW_Wml1x_ContentHandler_IWmlBrowserLib_Init(NW_WmlsCh_IWmlBrowserLib_t *wmlBrowserLib)
       
  1888 {
       
  1889   NW_Wml1x_ContentHandler_t   *thisObj;
       
  1890 
       
  1891   NW_ASSERT(wmlBrowserLib != NULL);
       
  1892   
       
  1893   /* for convenience */
       
  1894   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlBrowserLib);
       
  1895 
       
  1896   if (thisObj != NULL) {
       
  1897     return NW_Wml_ApplyTaskVariables(&thisObj->wmlInterpreter);
       
  1898   } else {
       
  1899     return KBrsrFailure;
       
  1900   }
       
  1901 }
       
  1902 
       
  1903 /*****************************************************************
       
  1904 
       
  1905   Name:         _NW_Wml1x_ContentHandler_IWmlBrowserLib_GetVar()
       
  1906 
       
  1907   Description:  
       
  1908 
       
  1909   Parameters:   
       
  1910 
       
  1911   Algorithm:    
       
  1912 
       
  1913   Return Value: 
       
  1914 
       
  1915 *****************************************************************/
       
  1916 TBrowserStatusCode
       
  1917 _NW_Wml1x_ContentHandler_IWmlBrowserLib_GetVar (NW_WmlsCh_IWmlBrowserLib_t *wmlBrowserLib,
       
  1918                                                 const NW_Ucs2 *var, NW_Ucs2 **ret_string)
       
  1919 {
       
  1920   NW_Wml1x_ContentHandler_t   *thisObj;
       
  1921   TBrowserStatusCode                 status;
       
  1922 
       
  1923   /* for convenience */
       
  1924   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlBrowserLib);
       
  1925 
       
  1926   status = NW_Wml_GetVar(&thisObj->wmlInterpreter, var, ret_string);
       
  1927   
       
  1928   return status;
       
  1929 }
       
  1930 
       
  1931 /*****************************************************************
       
  1932 
       
  1933   Name:         _NW_Wml1x_ContentHandler_IWmlBrowserLib_SetVar()
       
  1934 
       
  1935   Description:  
       
  1936 
       
  1937   Parameters:   
       
  1938 
       
  1939   Algorithm:    
       
  1940 
       
  1941   Return Value: 
       
  1942 
       
  1943 *****************************************************************/
       
  1944 TBrowserStatusCode
       
  1945 _NW_Wml1x_ContentHandler_IWmlBrowserLib_SetVar (NW_WmlsCh_IWmlBrowserLib_t *wmlBrowserLib,
       
  1946                                                 const NW_Ucs2 *var, const NW_Ucs2 *value)
       
  1947 {
       
  1948   NW_Wml1x_ContentHandler_t   *thisObj;
       
  1949 
       
  1950   /* for convenience */
       
  1951   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlBrowserLib);
       
  1952 
       
  1953   return NW_Wml_SetVar(&thisObj->wmlInterpreter, var, value);
       
  1954 }
       
  1955 
       
  1956 /*****************************************************************
       
  1957 
       
  1958   Name:         _NW_Wml1x_ContentHandler_IWmlBrowserLib_Go()
       
  1959 
       
  1960   Description:  
       
  1961 
       
  1962   Parameters:   
       
  1963 
       
  1964   Algorithm:    
       
  1965 
       
  1966   Return Value: 
       
  1967 
       
  1968 *****************************************************************/
       
  1969 TBrowserStatusCode
       
  1970 _NW_Wml1x_ContentHandler_IWmlBrowserLib_Go (NW_WmlsCh_IWmlBrowserLib_t *wmlBrowserLib,
       
  1971                                             const NW_Ucs2 *url, const NW_Ucs2 *param,
       
  1972                                             NW_Http_Header_t *header)
       
  1973 {
       
  1974   NW_Ucs2 *url_cpy = NULL;
       
  1975   NW_Ucs2 *param_cpy = NULL;
       
  1976   NW_Http_Header_t *header_cpy = NULL;
       
  1977   NW_Wml1x_ContentHandler_t   *thisObj;
       
  1978 
       
  1979   /* for convenience */
       
  1980   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlBrowserLib);
       
  1981 
       
  1982   /* make a copy for the wml interpreter */
       
  1983   if (url != NULL) {
       
  1984     url_cpy = NW_Str_Newcpy(url);
       
  1985     if (url_cpy == NULL) {
       
  1986       return KBrsrOutOfMemory;
       
  1987     }
       
  1988   }
       
  1989 
       
  1990   if (param != NULL) {
       
  1991     param_cpy = NW_Str_Newcpy(param);
       
  1992     if (param_cpy == NULL) {
       
  1993       NW_Str_Delete(url_cpy);
       
  1994       return KBrsrOutOfMemory;
       
  1995     }
       
  1996   }
       
  1997 
       
  1998   if (header != NULL) {
       
  1999     //header_cpy = UrlLoader_HeadersCopy(header);
       
  2000     if (header_cpy == NULL) {
       
  2001       NW_Str_Delete(url_cpy);
       
  2002       NW_Str_Delete(param_cpy);
       
  2003       return KBrsrOutOfMemory;
       
  2004     }
       
  2005   }
       
  2006 
       
  2007   NW_Wml_LoadUrl(&thisObj->wmlInterpreter, url_cpy, param_cpy, header_cpy);
       
  2008   return KBrsrSuccess;
       
  2009 }
       
  2010 
       
  2011 /*****************************************************************
       
  2012 
       
  2013   Name:         _NW_Wml1x_ContentHandler_IWmlBrowserLib_Prev()
       
  2014 
       
  2015   Description:  
       
  2016 
       
  2017   Parameters:   
       
  2018 
       
  2019   Algorithm:    
       
  2020 
       
  2021   Return Value: 
       
  2022 
       
  2023 *****************************************************************/
       
  2024 TBrowserStatusCode
       
  2025 _NW_Wml1x_ContentHandler_IWmlBrowserLib_Prev (NW_WmlsCh_IWmlBrowserLib_t *wmlBrowserLib)
       
  2026 {
       
  2027   NW_Wml1x_ContentHandler_t   *thisObj;
       
  2028 
       
  2029   /* for convenience */
       
  2030   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlBrowserLib);
       
  2031 
       
  2032   NW_Wml_LoadPrev(&thisObj->wmlInterpreter);
       
  2033   return KBrsrSuccess;
       
  2034 }
       
  2035 
       
  2036 /*****************************************************************
       
  2037 
       
  2038   Name:         _NW_Wml1x_ContentHandler_IWmlBrowserLib_NewContext()
       
  2039 
       
  2040   Description:  
       
  2041 
       
  2042   Parameters:   
       
  2043 
       
  2044   Algorithm:    
       
  2045 
       
  2046   Return Value: 
       
  2047 
       
  2048 *****************************************************************/
       
  2049 TBrowserStatusCode
       
  2050 _NW_Wml1x_ContentHandler_IWmlBrowserLib_NewContext (NW_WmlsCh_IWmlBrowserLib_t *wmlBrowserLib)
       
  2051 {
       
  2052   NW_Wml1x_ContentHandler_t   *thisObj;
       
  2053 
       
  2054   /* for convenience */
       
  2055   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlBrowserLib);
       
  2056 
       
  2057   NW_Wml_NewContextFromScript(&thisObj->wmlInterpreter);
       
  2058   
       
  2059   return KBrsrSuccess;
       
  2060 }
       
  2061 
       
  2062 /*****************************************************************
       
  2063 
       
  2064   Name:         _NW_Wml1x_ContentHandler_IWmlBrowserLib_Refresh()
       
  2065 
       
  2066   Description:  
       
  2067 
       
  2068   Parameters:   
       
  2069 
       
  2070   Algorithm:    
       
  2071 
       
  2072   Return Value: 
       
  2073 
       
  2074 *****************************************************************/
       
  2075 TBrowserStatusCode
       
  2076 _NW_Wml1x_ContentHandler_IWmlBrowserLib_Refresh (NW_WmlsCh_IWmlBrowserLib_t *wmlBrowserLib)
       
  2077 {
       
  2078   /* Refresh is a NOOP */
       
  2079   NW_REQUIRED_PARAM(wmlBrowserLib);
       
  2080   return KBrsrSuccess;
       
  2081 }
       
  2082 
       
  2083 /*****************************************************************
       
  2084 
       
  2085   Name:         _NW_Wml1x_ContentHandler_IWmlScriptListener_Start()
       
  2086 
       
  2087   Description:  
       
  2088 
       
  2089   Parameters:   
       
  2090 
       
  2091   Algorithm:    
       
  2092 
       
  2093   Return Value: 
       
  2094 
       
  2095 *****************************************************************/
       
  2096 TBrowserStatusCode
       
  2097 _NW_Wml1x_ContentHandler_IWmlScriptListener_Start (NW_WmlsCh_IWmlScriptListener_t *wmlScrListener, 
       
  2098                                                    const NW_Ucs2 *url)
       
  2099 {
       
  2100   NW_Wml1x_ContentHandler_t   *thisObj;
       
  2101   NW_HED_DocumentRoot_t* docRoot = NULL;
       
  2102   void *browserApp = NULL;
       
  2103  
       
  2104   /* for convenience */
       
  2105   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlScrListener);
       
  2106 
       
  2107   /* get the global context from the doc-root */
       
  2108   docRoot = (NW_HED_DocumentRoot_t*) NW_HED_DocumentNode_GetRootNode (thisObj);
       
  2109   if(docRoot == NULL) {
       
  2110     return KBrsrFailure;
       
  2111   }
       
  2112 
       
  2113   browserApp = NW_Ctx_Get(NW_CTX_BROWSER_APP, 0);
       
  2114 
       
  2115   (void)docRoot->appServices->loadProgress_api.start(browserApp, url);
       
  2116 
       
  2117   return KBrsrSuccess;
       
  2118 }
       
  2119 
       
  2120 /*****************************************************************
       
  2121 
       
  2122   Name:         _NW_Wml1x_ContentHandler_IWmlScriptListener_Finish()
       
  2123 
       
  2124   Description:  
       
  2125 
       
  2126   Parameters:   
       
  2127 
       
  2128   Algorithm:    
       
  2129 
       
  2130   Return Value: 
       
  2131 
       
  2132 *****************************************************************/
       
  2133 TBrowserStatusCode
       
  2134 _NW_Wml1x_ContentHandler_IWmlScriptListener_Finish (NW_WmlsCh_IWmlScriptListener_t *wmlScrListener,
       
  2135                                                     const TBrowserStatusCode scrStatus, const NW_Ucs2 *message)
       
  2136 {
       
  2137   NW_Wml1x_ContentHandler_t   *thisObj;
       
  2138   NW_HED_CompositeNode_t*     compositeNode;
       
  2139   NW_HED_DocumentRoot_t       *docRoot = NULL;
       
  2140   NW_HED_DocumentNode_t       *docNode = NULL;
       
  2141   NW_LMgr_RootBox_t           *rootBox = NULL;
       
  2142   NW_HED_ContentHandler_t     *scriptContentHandler = NULL;
       
  2143   NW_Ucs2                     *url = NULL;
       
  2144   void *browserApp = NULL;
       
  2145 
       
  2146   NW_TRY (status) {
       
  2147     NW_REQUIRED_PARAM(message);
       
  2148 
       
  2149     /* for convenience */
       
  2150     thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Interface_GetImplementer (wmlScrListener);
       
  2151     docNode = NW_HED_DocumentNodeOf (thisObj);
       
  2152     /* get the global context from the doc-root */
       
  2153     docRoot = (NW_HED_DocumentRoot_t*) NW_HED_DocumentNode_GetRootNode (docNode);
       
  2154     rootBox = NW_HED_DocumentRoot_GetRootBox (docRoot);
       
  2155 
       
  2156     compositeNode = (NW_HED_CompositeNode_t*)
       
  2157       NW_Object_QueryAggregate (thisObj, &NW_HED_CompositeNode_Class);
       
  2158     NW_ASSERT (compositeNode != NULL);
       
  2159 
       
  2160     scriptContentHandler = (NW_HED_ContentHandler_t*)
       
  2161       NW_HED_CompositeNode_LookupChild (compositeNode,
       
  2162                                         (void*) &NW_WmlScript_ContentHandler_Class);
       
  2163     if (scriptContentHandler != NULL) {
       
  2164       url = NW_Str_Newcpy (NW_WmlScript_ContentHandler_Get_Url (NW_WmlScript_ContentHandlerOf(scriptContentHandler)));
       
  2165       NW_THROW_OOM_ON_NULL (url, status);
       
  2166     }
       
  2167 
       
  2168     /* done with the script content handler, get rid of it */
       
  2169     NW_HED_CompositeNode_DeleteChild (compositeNode,
       
  2170                                       (void*) &NW_WmlScript_ContentHandler_Class);
       
  2171 
       
  2172 	/* reset variable before returning to WML */
       
  2173     rootBox->iYScrollChange = 0;
       
  2174 
       
  2175 	/* 
       
  2176      * Note: Restarting the Wml interpreter could result in navigation to a URL. 
       
  2177      * When the script aborts, the script state on the wml interpreter is not purged.
       
  2178      */
       
  2179     status = NW_Wml_ReStart(&thisObj->wmlInterpreter, scrStatus);
       
  2180 
       
  2181     _NW_THROW_ON_ERROR(status);
       
  2182 
       
  2183   }
       
  2184   NW_CATCH (status) {
       
  2185   }
       
  2186   NW_FINALLY {
       
  2187     browserApp = NW_Ctx_Get(NW_CTX_BROWSER_APP, 0);
       
  2188     if(docRoot == NULL) {
       
  2189       NW_Str_Delete(url);
       
  2190       return KBrsrFailure;
       
  2191     }
       
  2192     (void)docRoot->appServices->loadProgress_api.finish(browserApp, url);
       
  2193     NW_Str_Delete(url);
       
  2194     return status;
       
  2195   } NW_END_TRY
       
  2196 }
       
  2197 
       
  2198 /*****************************************************************
       
  2199 
       
  2200   Name:         NW_Wml1x_ContentHandler_DeleteOptionItemList()
       
  2201 
       
  2202   Description:  
       
  2203 
       
  2204   Parameters:   
       
  2205 
       
  2206   Algorithm:    
       
  2207 
       
  2208   Return Value: 
       
  2209 
       
  2210 *****************************************************************/
       
  2211 TBrowserStatusCode 
       
  2212 NW_Wml1x_ContentHandler_DeleteOptionItemList(NW_Ds_DynamicArray_t *itemList)
       
  2213 {
       
  2214   NW_Uint16 i;
       
  2215   NW_Uint16 numStrings;
       
  2216   NW_Ucs2 *itemString = NULL;
       
  2217 
       
  2218   NW_ASSERT(itemList != NULL);
       
  2219 
       
  2220   numStrings = NW_Ds_DarGetCount(itemList);
       
  2221   for (i = 0; i < numStrings; i++) {
       
  2222     itemString = (NW_Ucs2*)NW_Ds_DarGetElement(itemList, i);
       
  2223     NW_Str_Delete(itemString);
       
  2224   }
       
  2225 
       
  2226   NW_Ds_DarDelete(itemList);
       
  2227 
       
  2228   return KBrsrSuccess;
       
  2229 }
       
  2230 
       
  2231 /* ------------------------------------------------------------------------- */
       
  2232 NW_HED_DomHelper_t*
       
  2233 NW_Wml1x_ContentHandler_GetDomHelper (NW_Wml1x_ContentHandler_t* thisObj,
       
  2234                                       NW_Wml_VarList_t* varList)
       
  2235 {
       
  2236   if (thisObj->wmlInterpreter.decoder != NULL) {
       
  2237     return NW_Wml_Deck_GetDomHelper (thisObj->wmlInterpreter.decoder->domDeck, varList);
       
  2238   }
       
  2239   else {
       
  2240     return NULL;
       
  2241   }
       
  2242 }
       
  2243 
       
  2244 /* ------------------------------------------------------------------------- */
       
  2245 NW_HED_DomTree_t*
       
  2246 NW_Wml1x_ContentHandler_GetDomTree (NW_Wml1x_ContentHandler_t *thisObj)
       
  2247 {
       
  2248   if (thisObj->wmlInterpreter.decoder != NULL) {
       
  2249     return NW_Wml_Deck_GetDomTree (thisObj->wmlInterpreter.decoder->domDeck);
       
  2250   }
       
  2251   else {
       
  2252     return NULL;
       
  2253   }
       
  2254 }
       
  2255 
       
  2256 /* ------------------------------------------------------------------------- *
       
  2257    NW_Markup_NumberCollector methods
       
  2258  * ------------------------------------------------------------------------- */
       
  2259 
       
  2260 /* ------------------------------------------------------------------------- */
       
  2261 NW_LMgr_Box_t*
       
  2262 _NW_Wml1x_ContentHandler_NumberCollector_GetBoxTree (NW_Markup_NumberCollector_t* numberCollector)
       
  2263 {
       
  2264   NW_Wml1x_ContentHandler_t* thisObj;
       
  2265   NW_LMgr_Box_t* boxTree;
       
  2266 
       
  2267   /* parameter assertion block */
       
  2268   NW_ASSERT (NW_Object_IsInstanceOf (numberCollector,
       
  2269                                      &NW_Wml1x_ContentHandler_NumberCollector_Class));
       
  2270 
       
  2271   /* for convenience */
       
  2272   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Aggregate_GetAggregator (numberCollector);
       
  2273   NW_ASSERT (NW_Object_IsInstanceOf (thisObj, &NW_Wml1x_ContentHandler_Class));
       
  2274 
       
  2275   /* return the box tree */
       
  2276   (void)NW_HED_DocumentNode_GetBoxTree (thisObj, &boxTree);
       
  2277   return boxTree;
       
  2278 }
       
  2279 
       
  2280 
       
  2281 NW_Text_t*
       
  2282 _NW_Wml1x_ContentHandler_NumberCollector_GetHrefAttr (NW_Markup_NumberCollector_t* numberCollector,
       
  2283                                                       NW_LMgr_Box_t* box)
       
  2284 {
       
  2285   NW_LMgr_PropertyValue_t      value;
       
  2286   NW_Wml1x_ContentHandler_t* thisObj;
       
  2287   NW_Ucs2     *retString = NULL;
       
  2288   TBrowserStatusCode status = KBrsrFailure;
       
  2289   NW_Text_t* text = NULL;
       
  2290 
       
  2291   /* parameter assertion block */
       
  2292   NW_ASSERT (NW_Object_IsInstanceOf (numberCollector,
       
  2293                                      &NW_Wml1x_ContentHandler_NumberCollector_Class));
       
  2294 
       
  2295   /* for convenience */
       
  2296   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Aggregate_GetAggregator (numberCollector);
       
  2297   NW_ASSERT (NW_Object_IsInstanceOf (thisObj, &NW_Wml1x_ContentHandler_Class));
       
  2298 
       
  2299   value.integer = 0;
       
  2300   (void)NW_LMgr_Box_GetPropertyValue(box, NW_CSS_Prop_elementId, NW_CSS_ValueType_Integer, &value);
       
  2301   status = NW_Wml_GetAttribute(&(thisObj->wmlInterpreter),
       
  2302                                NW_UINT16_CAST(value.integer),
       
  2303                                HREF_ATTR,
       
  2304                                &retString);
       
  2305   if((status  == KBrsrSuccess) && (retString != NULL)) {
       
  2306     /*alt string exists*/
       
  2307     NW_Text_t* retUrl = NULL;
       
  2308                                    
       
  2309     text = (NW_Text_t*)NW_Text_UCS2_New (retString,
       
  2310                                          NW_Str_Strlen(retString), 
       
  2311                                          NW_Text_Flags_TakeOwnership);
       
  2312     if (text)
       
  2313     {
       
  2314       status = NW_HED_ContentHandler_ResolveURL ((NW_HED_ContentHandler_t *)thisObj, text, &retUrl);
       
  2315       if (status == KBrsrSuccess)
       
  2316       {
       
  2317         text = retUrl; /* NW_HED_ContentHandler_ResolveURL handles text and retUrl objects correctly */
       
  2318       }
       
  2319     }
       
  2320   
       
  2321   }
       
  2322   return text;
       
  2323 }
       
  2324 
       
  2325 /* ------------------------------------------------------------------------- */
       
  2326 NW_Text_t*
       
  2327 _NW_Wml1x_ContentHandler_NumberCollector_GetAltAttr (NW_Markup_NumberCollector_t* numberCollector,
       
  2328                                                       NW_LMgr_Box_t* box)
       
  2329 {
       
  2330   NW_LMgr_PropertyValue_t      value;
       
  2331   NW_Wml1x_ContentHandler_t* thisObj;
       
  2332   NW_Ucs2     *retString = NULL;
       
  2333   TBrowserStatusCode status = KBrsrFailure;
       
  2334   NW_Text_t* text = NULL;
       
  2335 
       
  2336   /* parameter assertion block */
       
  2337   NW_ASSERT (NW_Object_IsInstanceOf (numberCollector,
       
  2338                                      &NW_Wml1x_ContentHandler_NumberCollector_Class));
       
  2339 
       
  2340   /* for convenience */
       
  2341   thisObj = (NW_Wml1x_ContentHandler_t*)NW_Object_Aggregate_GetAggregator (numberCollector);
       
  2342   NW_ASSERT (NW_Object_IsInstanceOf (thisObj, &NW_Wml1x_ContentHandler_Class));
       
  2343 
       
  2344   value.integer = 0;
       
  2345   (void)NW_LMgr_Box_GetPropertyValue(box, NW_CSS_Prop_elementId, NW_CSS_ValueType_Integer, &value);
       
  2346   status = NW_Wml_GetAttribute(&(thisObj->wmlInterpreter),
       
  2347                                NW_UINT16_CAST(value.integer),
       
  2348                                ALT_ATTR,
       
  2349                                &retString);
       
  2350   if((status  == KBrsrSuccess) && (retString != NULL)) {
       
  2351     /*alt string exists*/
       
  2352     text = (NW_Text_t*)NW_Text_UCS2_New (retString,
       
  2353                                          NW_Str_Strlen(retString), 
       
  2354                                          NW_Text_Flags_TakeOwnership);
       
  2355   }
       
  2356   return text;
       
  2357 }
       
  2358 /* retrieve the boolean whether content is saved content */
       
  2359 /* ------------------------------------------------------------------------- */
       
  2360 NW_Bool
       
  2361 NW_Wml1x_ContentHandler_IsSaveddeck (NW_Wml1x_ContentHandler_t * thisObj)
       
  2362 {
       
  2363   NW_ASSERT(thisObj);
       
  2364   return thisObj->saveddeck;
       
  2365 }
       
  2366 
       
  2367 /* retrieve the boolean whether content is history load */
       
  2368 /* ------------------------------------------------------------------------- */
       
  2369 NW_Bool
       
  2370 NW_Wml1x_ContentHandler_IsHistload (NW_Wml1x_ContentHandler_t * thisObj)
       
  2371 {
       
  2372   NW_ASSERT(thisObj);
       
  2373   return thisObj->histload;
       
  2374 }
       
  2375 
       
  2376 
       
  2377 /* retrieve the boolean whether content is reload */
       
  2378 /* ------------------------------------------------------------------------- */
       
  2379 NW_Bool
       
  2380 NW_Wml1x_ContentHandler_IsReload (NW_Wml1x_ContentHandler_t * thisObj)
       
  2381 {
       
  2382   NW_ASSERT(thisObj);
       
  2383   return thisObj->reload;
       
  2384 }
       
  2385 
       
  2386 /* set the boolean whether content is the saved content */
       
  2387 /* ------------------------------------------------------------------------- */
       
  2388 TBrowserStatusCode
       
  2389 NW_Wml1x_ContentHandler_SetSaveddeck (NW_Wml1x_ContentHandler_t * thisObj, NW_Bool isSaveddeck)
       
  2390 {
       
  2391   NW_ASSERT(thisObj);
       
  2392   thisObj->saveddeck = isSaveddeck;
       
  2393   return KBrsrSuccess;
       
  2394 }
       
  2395 
       
  2396 /* set the boolean whether content is history load */
       
  2397 /* ------------------------------------------------------------------------- */
       
  2398 TBrowserStatusCode
       
  2399 NW_Wml1x_ContentHandler_SetHistload (NW_Wml1x_ContentHandler_t * thisObj, NW_Bool isHistload)
       
  2400 {
       
  2401   NW_ASSERT(thisObj);
       
  2402   thisObj->histload = isHistload;
       
  2403   return KBrsrSuccess;
       
  2404 }
       
  2405 
       
  2406 /* set the boolean whether content is reload */
       
  2407 /* ------------------------------------------------------------------------- */
       
  2408 TBrowserStatusCode
       
  2409 NW_Wml1x_ContentHandler_SetReload (NW_Wml1x_ContentHandler_t * thisObj, NW_Bool isReload)
       
  2410 {
       
  2411   NW_ASSERT(thisObj);
       
  2412   thisObj->reload = isReload;
       
  2413   return KBrsrSuccess;
       
  2414 }