Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
nsNativeAppSupportOS2.cpp File Reference
#include <os2.h>
#include "nsNativeAppSupportBase.h"
#include "nsNativeAppSupportOS2.h"
#include "nsAppRunner.h"
#include "nsXULAppAPI.h"
#include "nsString.h"
#include "nsIBrowserDOMWindow.h"
#include "nsICommandLineRunner.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIDOMWindow.h"
#include "nsIDOMChromeWindow.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsISupportsArray.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIBaseWindow.h"
#include "nsIWidget.h"
#include "nsIAppShellService.h"
#include "nsIProfileInternal.h"
#include "nsIXULWindow.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPromptService.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIDOMLocation.h"
#include "nsIJSContextStack.h"
#include "nsIWebNavigation.h"
#include "nsIWindowMediator.h"
#include <stdlib.h>
#include "prprf.h"

Go to the source code of this file.

Classes

struct  _COPYDATASTRUCT
struct  Mutex
class  nsNativeAppSupportOS2
struct  _DDEMLFN
struct  MessageWindow
class  SafeJSContext

Defines

#define INCL_PM
#define INCL_GPI
#define INCL_DOS
#define INCL_DOSERRORS
#define kMailtoUrlScheme   "mailto:"
#define WM_COPYDATA   (WM_USER + 60)
#define MOZ_DDE_APPLICATION   "Mozilla"
#define MOZ_STARTUP_MUTEX_NAME   "StartupMutex"
#define MOZ_DDE_START_TIMEOUT   30000
#define MOZ_DDE_STOP_TIMEOUT   15000
#define MOZ_DDE_EXEC_TIMEOUT   15000

Typedefs

typedef struct _COPYDATASTRUCT COPYDATASTRUCT
typedef struct _COPYDATASTRUCTPCOPYDATASTRUCT
typedef struct _DDEMLFN DDEMLFN
typedef struct _DDEMLFNPDDEMLFN

Functions

static HWND hwndForDOMWindow (nsISupports *)
static nsresult GetMostRecentWindow (const PRUnichar *aType, nsIDOMWindowInternal **aWindow)
static void activateWindow (nsIDOMWindowInternal *win)
nsresult NS_CreateNativeAppSupport (nsINativeAppSupport **aResult)
 Create the nativeappsupport implementation.
int DdeCmpStringHandles (HSZ hsz1, HSZ hsz2)
char * GetCommandLine ()
BOOL SetupOS2ddeml ()
static void escapeQuotes (nsAString &aString)
static PRInt32 advanceToEndOfQuotedArg (const char *p, PRInt32 offset, PRInt32 len)
PRBool StartOS2App (int aArgc, char **aArgv)

Variables

char szCommandLine [2 *CCHMAXPATH]
const char *const topicNames []
DDEMLFN ddemlfnTable []
static const char sJSStackContractID [] = "@mozilla.org/js/xpc/ContextStack;1"

Class Documentation

struct _COPYDATASTRUCT

Definition at line 100 of file nsNativeAppSupportOS2.cpp.

Class Members
ULONG cbData
CHAR chBuff
ULONG dwData
PVOID lpData
struct _DDEMLFN

Definition at line 478 of file nsNativeAppSupportOS2.cpp.

Class Members
PFN * fn
ULONG ord

Define Documentation

Definition at line 43 of file nsNativeAppSupportOS2.cpp.

Definition at line 44 of file nsNativeAppSupportOS2.cpp.

Definition at line 42 of file nsNativeAppSupportOS2.cpp.

Definition at line 41 of file nsNativeAppSupportOS2.cpp.

#define kMailtoUrlScheme   "mailto:"

Definition at line 94 of file nsNativeAppSupportOS2.cpp.

#define MOZ_DDE_APPLICATION   "Mozilla"

Definition at line 389 of file nsNativeAppSupportOS2.cpp.

Definition at line 393 of file nsNativeAppSupportOS2.cpp.

Definition at line 391 of file nsNativeAppSupportOS2.cpp.

Definition at line 392 of file nsNativeAppSupportOS2.cpp.

#define MOZ_STARTUP_MUTEX_NAME   "StartupMutex"

Definition at line 390 of file nsNativeAppSupportOS2.cpp.

#define WM_COPYDATA   (WM_USER + 60)

Definition at line 107 of file nsNativeAppSupportOS2.cpp.


Typedef Documentation

typedef struct _DDEMLFN DDEMLFN
typedef struct _COPYDATASTRUCT * PCOPYDATASTRUCT
typedef struct _DDEMLFN * PDDEMLFN

Function Documentation

static void activateWindow ( nsIDOMWindowInternal win) [static]

Definition at line 129 of file nsNativeAppSupportOS2.cpp.

                                            {
    // Try to get native window handle.
    HWND hwnd = hwndForDOMWindow( win );
    if ( hwnd ) {

        /* if we are looking at a client window, then we really probably want
         * the frame so that we can manipulate THAT
         */
        LONG id = WinQueryWindowUShort( hwnd, QWS_ID );
        if( id == FID_CLIENT )
        {
           hwnd = WinQueryWindow( hwnd, QW_PARENT );
        }

        // Restore the window in case it is minimized.
        // Use the OS call, if possible.
        WinSetWindowPos( hwnd, 0L, 0L, 0L, 0L, 0L, 
                         SWP_SHOW | SWP_RESTORE | SWP_ACTIVATE );
    } else {
        // Use internal method.
        win->Focus();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRInt32 advanceToEndOfQuotedArg ( const char *  p,
PRInt32  offset,
PRInt32  len 
) [static]

Definition at line 1331 of file nsNativeAppSupportOS2.cpp.

                                                                                     {
    // Check whether the current arg is quoted.
    if ( p[++offset] == '"' ) {
        // Advance past the closing quote.
        while ( offset < len && p[++offset] != '"' ) {
            // If the current character is a backslash, then the
            // next character can't be a *real* '"', so skip it.
            if ( p[offset] == '\\' ) {
                offset++;
            }
        }
    }
    return offset;
}

Here is the caller graph for this function:

int DdeCmpStringHandles ( HSZ  hsz1,
HSZ  hsz2 
)

Definition at line 412 of file nsNativeAppSupportOS2.cpp.

{
  char chhsz1[CCHMAXPATH], chhsz2[CCHMAXPATH];
  int rc = -1;

  /* I am assuming that the strings will never be more that CCHMAXPATH in
   * length.  Safe bet (for now).  To find true length, call WinDdeQueryString
   * and pass in (hsz, NULL, 0L, 0) and it will return iLength.  Passing 0
   * for codepage will use the codepage of the current thread.
   */
  WinDdeQueryString( hsz1, chhsz1, sizeof( chhsz1 ), 0 );
  WinDdeQueryString( hsz2, chhsz2, sizeof( chhsz2 ),0 );

  rc = stricmp( chhsz1, chhsz2 );

  return(rc);
}

Here is the caller graph for this function:

static void escapeQuotes ( nsAString &  aString) [static]

Definition at line 1058 of file nsNativeAppSupportOS2.cpp.

                                               {
    PRInt32 offset = -1;
    while( 1 ) {
       // Find next '"'.
       offset = aString.FindChar( '"', ++offset );
       if ( offset == kNotFound ) {
           // No more quotes, exit.
           break;
       } else {
           // Insert back-slash ahead of the '"'.
           aString.Insert( PRUnichar('\\'), offset );
           // Increment offset because we just inserted a slash
           offset++;
       }
    }
    return;
}

Here is the caller graph for this function:

char* GetCommandLine ( )

Definition at line 431 of file nsNativeAppSupportOS2.cpp.

{
   /* This function is meant to be like the Window's GetCommandLine() function.
    * The value returned by pPIB->pib_pchcmd is of the format:
    * <executable>\0<command line parameters>.  So the first string is the
    * .exe and the second string is what followed on the command line.  Dorky,
    * but I guess it'll have to do.
    */
   PTIB pTIB = NULL;
   PPIB pPIB = NULL;
   APIRET rc = NO_ERROR;
   char *pchParam = NULL;

   rc = DosGetInfoBlocks( &pTIB, &pPIB );
   if( rc == NO_ERROR )
   {
      INT iLen = 0;
      char *pchTemp = NULL;
      pchParam = pPIB->pib_pchcmd;
      strcpy( szCommandLine, pchParam );
      iLen = strlen( pchParam );

      /* szCommandLine[iLen] is '\0', so see what's next.  Probably be another
       * '\0', a space or start of the arguments
       */
      pchTemp = &(pchParam[iLen+1]);

      /* At this point, szCommandLine holds just the program name.  Now we
       * go for the parameters.  If our next value is a space, ignore it
       * and go for the next character
       */
      if( *pchTemp )
      {
         szCommandLine[iLen] = ' ';
         iLen++;
         if( *pchTemp == ' ' )
         {
            pchTemp++;
         }
         strcpy( &(szCommandLine[iLen]), pchTemp );
      }

   }

   return( szCommandLine );
}

Here is the caller graph for this function:

static nsresult GetMostRecentWindow ( const PRUnichar aType,
nsIDOMWindowInternal **  aWindow 
) [static]

Definition at line 115 of file nsNativeAppSupportOS2.cpp.

                                                                            {
    nsresult rv;
    nsCOMPtr<nsIWindowMediator> med( do_GetService( NS_WINDOWMEDIATOR_CONTRACTID, &rv ) );
    if ( NS_FAILED( rv ) )
        return rv;

    if ( med )
        return med->GetMostRecentWindow( aType, aWindow );

    return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HWND hwndForDOMWindow ( nsISupports *  window) [static]

Create the nativeappsupport implementation.

Note:
XPCOMInit has not happened yet.

Definition at line 375 of file nsNativeAppSupportOS2.cpp.

                                                           {
    nsNativeAppSupportOS2 *pNative = new nsNativeAppSupportOS2;
    if (!pNative) return NS_ERROR_OUT_OF_MEMORY;

    // Check for dynamic console creation request.
    pNative->CheckConsole();

    *aResult = pNative;
    NS_ADDREF( *aResult );

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 518 of file nsNativeAppSupportOS2.cpp.

{
    BOOL bRC = FALSE;
    HMODULE hmodDDEML = NULLHANDLE;
    APIRET rc = NO_ERROR;

    rc = DosLoadModule( NULL, 0, "PMDDEML", &hmodDDEML );
    if( rc == NO_ERROR )
    {
       int i;
       /* all of this had better work.  Get ready to be a success! */
       bRC = TRUE;
       for( i=0; ddemlfnTable[i].ord != 0; i++ )
       {
          rc = DosQueryProcAddr( hmodDDEML, ddemlfnTable[i].ord, NULL,
                                 ddemlfnTable[i].fn );
          if( rc != NO_ERROR )
          {
             /* we're horked.  Return rc = horked */
             bRC = FALSE;
             break;
          }
       }
    } /* load PMDDEML */

    return( bRC );
}

Here is the caller graph for this function:

PRBool StartOS2App ( int  aArgc,
char **  aArgv 
)

Definition at line 1766 of file nsNativeAppSupportOS2.cpp.

{
  PRBool    rv = PR_TRUE;
  PPIB      ppib;
  PTIB      ptib;

  DosGetInfoBlocks(&ptib, &ppib);

  // if this isn't a PM session, reset the session type to enable use
  // of PM functions;  if it is PM, see if a VIO session is required
  if (ppib->pib_ultype != SSF_TYPE_PM)
    ppib->pib_ultype = SSF_TYPE_PM;
  else {
    for (int i = 1; i < aArgc; i++ ) {
      char *arg = aArgv[i];
      if (*arg != '-' && *arg != '/')
        continue;
      arg++;
      if (stricmp("?", arg) == 0 ||
        stricmp("h", arg) == 0 ||
        stricmp("v", arg) == 0 ||
        stricmp("help", arg) == 0 ||
        stricmp("version", arg) == 0 ||
        stricmp("console", arg) == 0) {
        rv = PR_FALSE;
        break;
      }
    }
  }

  // if the session type is OK, increase the number of 
  // file handles available to the app, then exit
  if (rv) {
    ULONG    ulMaxFH = 0;
    LONG     ulReqCount = 0;

    DosSetRelMaxFH(&ulReqCount, &ulMaxFH);
    if (ulMaxFH < 256)
      DosSetMaxFH(256);

    return rv;
  }

  // the app has to be restarted in a VIO session
  char        szErrObj[64] = "";
  STARTDATA   x;

  memset(&x, 0, sizeof(x));
  x.Length = sizeof(x);
  (const char* const)(x.PgmTitle) = gAppData->name;
  x.InheritOpt = SSF_INHERTOPT_PARENT;
  x.SessionType = SSF_TYPE_WINDOWABLEVIO;
  x.PgmControl = SSF_CONTROL_NOAUTOCLOSE;
  x.ObjectBuffer = szErrObj;
  x.ObjectBuffLen = sizeof(szErrObj);

  // the f/q exename is the string preceding ppib->pib_pchcmd;
  // the original commandline is the string following it
  char * ptr = ppib->pib_pchcmd - 2;
  while (*ptr)
    ptr--;
  x.PgmName = ptr + 1;
  x.PgmInputs = strchr(ppib->pib_pchcmd, 0) + 1;

  // restart the app;  if this session is in the background, trying
  // to start in the foreground will produce an error, but the app
  // will still start; if DosStartSession has a real failure, forget
  // the console and let the current instance keep running
  ULONG ulSession;
  PID   pid;
  ULONG rc = DosStartSession(&x, &ulSession, &pid);
  if (rc && rc != ERROR_SMG_START_IN_BACKGROUND)
    rv = PR_TRUE;

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
 
{
   { (PFN *)&WinDdeAbandonTransaction   ,100 },
   { (PFN *)&WinDdeAccessData           ,101 },
   { (PFN *)&WinDdeAddData              ,102 },
   { (PFN *)&WinDdeSubmitTransaction    ,103 },
   { (PFN *)&WinDdeCompareStringHandles ,104 },
   { (PFN *)&WinDdeConnect              ,105 },
   { (PFN *)&WinDdeConnectList          ,106 },
   { (PFN *)&WinDdeCreateDataHandle     ,107 },
   { (PFN *)&WinDdeCreateStringHandle   ,108 },
   { (PFN *)&WinDdeDisconnect           ,109 },
   { (PFN *)&WinDdeDisconnectList       ,110 },
   { (PFN *)&WinDdeEnableCallback       ,111 },
   { (PFN *)&WinDdeFreeDataHandle       ,112 },
   { (PFN *)&WinDdeFreeStringHandle     ,113 },
   { (PFN *)&WinDdeGetData              ,114 },
   { (PFN *)&WinDdeInitialize           ,116 },
   { (PFN *)&WinDdeKeepStringHandle     ,117 },
   { (PFN *)&WinDdeNameService          ,118 },
   { (PFN *)&WinDdePostAdvise           ,119 },
   { (PFN *)&WinDdeQueryConvInfo        ,120 },
   { (PFN *)&WinDdeQueryNextServer      ,121 },
   { (PFN *)&WinDdeQueryString          ,122 },
   { (PFN *)&WinDdeReconnect            ,123 },
   { (PFN *)&WinDdeSetUserHandle        ,124 },
   { (PFN *)&WinDdeUninitialize         ,126 },
   { (PFN *)NULL                           ,  0 }
}

Definition at line 484 of file nsNativeAppSupportOS2.cpp.

const char sJSStackContractID[] = "@mozilla.org/js/xpc/ContextStack;1" [static]

Definition at line 1639 of file nsNativeAppSupportOS2.cpp.

char szCommandLine[2 *CCHMAXPATH]

Definition at line 109 of file nsNativeAppSupportOS2.cpp.

Initial value:
 { "WWW_OpenURL",
                                    "WWW_Activate",
                                    "WWW_CancelProgress",
                                    "WWW_Version",
                                    "WWW_RegisterViewer",
                                    "WWW_UnRegisterViewer",
                                    "WWW_GetWindowInfo" }

Definition at line 396 of file nsNativeAppSupportOS2.cpp.