Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Static Private Member Functions | Static Private Attributes | Friends
nsNativeAppSupportWin Class Reference
Inheritance diagram for nsNativeAppSupportWin:
Inheritance graph
[legend]
Collaboration diagram for nsNativeAppSupportWin:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_NSIOBSERVER
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD 
Start (PRBool *aResult)
NS_IMETHOD Stop (PRBool *aResult)
NS_IMETHOD Quit ()
NS_IMETHOD Enable ()
NS_IMETHOD StartDDE ()
void CheckConsole ()
NS_IMETHOD Start (PRBool *aResult)
NS_IMETHOD Stop (PRBool *aResult)
NS_IMETHOD Quit ()
NS_IMETHOD StartServerMode ()
NS_IMETHOD OnLastWindowClosing ()
NS_IMETHOD SetIsServerMode (PRBool isServerMode)
NS_IMETHOD EnsureProfile (nsICmdLineService *args)
NS_IMETHOD StartDDE ()
void CheckConsole ()
NS_DECL_NSINATIVEAPPSUPPORT
NS_IMETHOD 
CreateSplashScreen (nsISplashScreen **splash)
 NS_IMETHOD_ (nsrefcnt) AddRef()
 NS_IMETHOD_ (nsrefcnt) Release()
NS_IMETHOD QueryInterface (const nsIID &iid, void **p)
boolean start ()
boolean start ()
void enable ()
boolean stop ()
boolean stop ()
void quit ()
void quit ()
void onLastWindowClosing ()
void onLastWindowClosing ()
void ReOpen ()
void ReOpen ()
void ensureProfile (in nsICmdLineService aCmdService)
void showSplashScreen ()
void hideSplashScreen ()
void startServerMode ()
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Public Attributes

nsrefcnt mRefCnt
nsCOMPtr< nsISplashScreenmSplash
PRBool mServerMode
PRBool mShouldShowUI
PRBool mShownTurboDialog
attribute boolean isServerMode
attribute boolean shouldShowUI

Static Public Attributes

static PRBool mLastWindowIsConfirmation = PR_FALSE

Private Types

enum  {
  topicOpenURL, topicActivate, topicCancelProgress, topicVersion,
  topicRegisterViewer, topicUnRegisterViewer, topicGetWindowInfo, topicCount
}
enum  {
  topicOpenURL, topicActivate, topicCancelProgress, topicVersion,
  topicRegisterViewer, topicUnRegisterViewer, topicGetWindowInfo, topicCount
}

Static Private Member Functions

static HDDEDATA CALLBACK HandleDDENotification (UINT uType, UINT uFmt, HCONV hconv, HSZ hsz1, HSZ hsz2, HDDEDATA hdata, ULONG dwData1, ULONG dwData2)
static void HandleCommandLine (const char *aCmdLineString, nsIFile *aWorkingDir, PRUint32 aState)
static void ParseDDEArg (HSZ args, int index, nsCString &string)
static void ParseDDEArg (const char *args, int index, nsCString &aString)
static void ActivateLastWindow ()
static HDDEDATA CreateDDEData (DWORD value)
static HDDEDATA CreateDDEData (LPBYTE value, DWORD len)
static PRBool InitTopicStrings ()
static int FindTopic (HSZ topic)
static nsresult OpenWindow (const char *urlstr, const char *args)
static nsresult OpenBrowserWindow ()
static nsresult ReParent (nsISupports *window, HWND newParent)
static void SetupSysTrayIcon ()
static void RemoveSysTrayIcon ()
static HDDEDATA CALLBACK HandleDDENotification (UINT uType, UINT uFmt, HCONV hconv, HSZ hsz1, HSZ hsz2, HDDEDATA hdata, ULONG dwData1, ULONG dwData2)
static nsresult HandleRequest (LPBYTE request, PRBool newWindow, nsIDOMWindow **aResult)
static void ParseDDEArg (HSZ args, int index, nsCString &string)
static void ParseDDEArg (const char *args, int index, nsCString &aString)
static void ActivateLastWindow ()
static HDDEDATA CreateDDEData (DWORD value)
static HDDEDATA CreateDDEData (LPBYTE value, DWORD len)
static PRBool InitTopicStrings ()
static int FindTopic (HSZ topic)
static nsresult GetCmdLineArgs (LPBYTE request, nsICmdLineService **aResult)
static nsresult OpenWindow (const char *urlstr, const nsAString &aArgs, nsIDOMWindow **aResult)
static nsresult OpenBrowserWindow (const nsAString &aArgs, PRBool newWindow, nsIDOMWindow **aResult)
static nsresult ReParent (nsISupports *window, HWND newParent)
static nsresult GetStartupURL (nsICmdLineService *args, nsCString &taskURL)
static void SetupSysTrayIcon ()
static void RemoveSysTrayIcon ()

Static Private Attributes

static int mConversations = 0
static HSZ mApplication = 0
static HSZ mTopics [topicCount] = { 0 }
static DWORD mInstance = 0
static PRBool mCanHandleRequests = PR_FALSE
static PRBool mSupportingDDEExec = PR_FALSE
static char mMutexName [] = { 0 }
static UINT mTrayRestart = 0
static NOTIFYICONDATA mIconData
static HMENU mTrayIconMenu = 0
static char * mAppName = nameBuffer
static PRBool mInitialWindowActive = PR_FALSE
static PRBool mForceProfileStartup = PR_FALSE

Friends

struct MessageWindow

Detailed Description

Definition at line 305 of file nsNativeAppSupportWin.cpp.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
topicOpenURL 
topicActivate 
topicCancelProgress 
topicVersion 
topicRegisterViewer 
topicUnRegisterViewer 
topicGetWindowInfo 
topicCount 

Definition at line 350 of file nsNativeAppSupportWin.cpp.

         {
        topicOpenURL,
        topicActivate,
        topicCancelProgress,
        topicVersion,
        topicRegisterViewer,
        topicUnRegisterViewer,
        topicGetWindowInfo,
        // Note: Insert new values above this line!!!!!
        topicCount // Count of the number of real topics
    };
anonymous enum [private]
Enumerator:
topicOpenURL 
topicActivate 
topicCancelProgress 
topicVersion 
topicRegisterViewer 
topicUnRegisterViewer 
topicGetWindowInfo 
topicCount 

Definition at line 424 of file nsNativeAppSupportWin.cpp.

         {
        topicOpenURL,
        topicActivate,
        topicCancelProgress,
        topicVersion,
        topicRegisterViewer,
        topicUnRegisterViewer,
        topicGetWindowInfo,
        // Note: Insert new values above this line!!!!!
        topicCount // Count of the number of real topics
    };

Member Function Documentation

Definition at line 1285 of file nsNativeAppSupportWin.cpp.

                                               {
    nsCOMPtr<nsIDOMWindowInternal> navWin;
    GetMostRecentWindow( NS_LITERAL_STRING("navigator:browser").get(), getter_AddRefs( navWin ) );
    if ( navWin ) {
        // Activate that window.
        activateWindow( navWin );
    } else {
        // Need to create a Navigator window, then.
        OpenBrowserWindow();
    }
}

Here is the call graph for this function:

static void nsNativeAppSupportWin::ActivateLastWindow ( ) [static, private]

Definition at line 378 of file nsNativeAppSupportWin.cpp.

                                    {
    for ( int i = 1; i < gArgc; i++ ) {
        if ( strcmp( "-console", gArgv[i] ) == 0
             ||
             strcmp( "/console", gArgv[i] ) == 0 ) {
            // Users wants to make sure we have a console.
            // Try to allocate one.
            BOOL rc = ::AllocConsole();
            if ( rc ) {
                // Console allocated.  Fix it up so that output works in
                // all cases.  See http://support.microsoft.com/support/kb/articles/q105/3/05.asp.

                // stdout
                int hCrt = ::_open_osfhandle( (long)GetStdHandle( STD_OUTPUT_HANDLE ),
                                            _O_TEXT );
                if ( hCrt != -1 ) {
                    FILE *hf = ::_fdopen( hCrt, "w" );
                    if ( hf ) {
                        *stdout = *hf;
#ifdef DEBUG
                        ::fprintf( stdout, "stdout directed to dynamic console\n" );
#endif
                    }
                }

                // stderr
                hCrt = ::_open_osfhandle( (long)::GetStdHandle( STD_ERROR_HANDLE ),
                                          _O_TEXT );
                if ( hCrt != -1 ) {
                    FILE *hf = ::_fdopen( hCrt, "w" );
                    if ( hf ) {
                        *stderr = *hf;
#ifdef DEBUG
                        ::fprintf( stderr, "stderr directed to dynamic console\n" );
#endif
                    }
                }

                // stdin?
                /* Don't bother for now.
                hCrt = ::_open_osfhandle( (long)::GetStdHandle( STD_INPUT_HANDLE ),
                                          _O_TEXT );
                if ( hCrt != -1 ) {
                    FILE *hf = ::_fdopen( hCrt, "r" );
                    if ( hf ) {
                        *stdin = *hf;
                    }
                }
                */
            } else {
                // Failed.  Probably because there already is one.
                // There's little we can do, in any case.
            }

            // Remove the console argument from the command line.
            do {
                gArgv[i] = gArgv[i + 1];
                ++i;
            } while (gArgv[i]);

            --gArgc;

            // Don't bother doing this more than once.
            break;
        }
    }

    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HDDEDATA nsNativeAppSupportWin::CreateDDEData ( DWORD  value) [static, private]

Definition at line 1297 of file nsNativeAppSupportWin.cpp.

                                                           {
    return CreateDDEData( (LPBYTE)&value, sizeof value );
}
HDDEDATA nsNativeAppSupportWin::CreateDDEData ( LPBYTE  value,
DWORD  len 
) [static, private]

Definition at line 1301 of file nsNativeAppSupportWin.cpp.

                                                                       {
    HDDEDATA result = DdeCreateDataHandle( mInstance,
                                           value,
                                           len,
                                           0,
                                           mApplication,
                                           CF_TEXT,
                                           0 );
    return result;
}
static HDDEDATA nsNativeAppSupportWin::CreateDDEData ( DWORD  value) [static, private]
static HDDEDATA nsNativeAppSupportWin::CreateDDEData ( LPBYTE  value,
DWORD  len 
) [static, private]

Definition at line 145 of file nsNativeAppSupportBase.cpp.

                                                                     {
    NS_ENSURE_ARG( splash );
    *splash = 0;
    return NS_CreateSplashScreen( splash );
}

Here is the call graph for this function:

Definition at line 866 of file nsNativeAppSupportWin.cpp.

{
    mCanHandleRequests = PR_TRUE;

    nsCOMPtr<nsIObserverService> obs
        (do_GetService("@mozilla.org/observer-service;1"));
    if (obs) {
        obs->AddObserver(this, "quit-application", PR_FALSE);
    } else {
        NS_ERROR("No observer service?");
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 2111 of file nsNativeAppSupportWin.cpp.

{
  static PRBool firstTime = PR_TRUE;
  if ( firstTime ) {
    firstTime = PR_FALSE;
    // Check pref for whether to set ddeexec subkey entries.
    nsCOMPtr<nsIPrefBranch> prefService( do_GetService( NS_PREFSERVICE_CONTRACTID ) );
    PRBool supportDDEExec = PR_FALSE;
    if ( prefService ) {
        prefService->GetBoolPref( "advanced.system.supportDDEExec", &supportDDEExec );
    }
    if ( supportDDEExec && handlingHTTP() ) {
#if MOZ_DEBUG_DDE
printf( "Setting ddexec subkey entries\n" );
#endif

      DWORD dwDisp;
      HKEY hKey;
      DWORD rc;

      rc = ::RegCreateKeyEx( HKEY_CLASSES_ROOT,
                             "http\\shell\\open\\ddeexec", 0,
                             NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
                             &hKey, &dwDisp );

      if ( REG_SUCCEEDED( rc ) ) {
        // Set ddeexec default value.
        const BYTE ddeexec[] = "\"%1\",,-1,0,,,,";
        ::RegSetValueEx( hKey, "", 0, REG_SZ, ddeexec, sizeof ddeexec );
        ::RegCloseKey( hKey );
      }

      // Set application/topic (while we're running), reset at exit.
      rc = ::RegCreateKeyEx( HKEY_CLASSES_ROOT,
                             "http\\shell\\open\\ddeexec\\application", 0,
                             NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
                             &hKey, &dwDisp );

      if ( REG_SUCCEEDED( rc ) ) {
        ::RegSetValueEx( hKey, "", 0, REG_SZ, (BYTE *) mAppName,
                         ::strlen( mAppName ) + 1 );
        ::RegCloseKey( hKey );
      }

      rc = ::RegCreateKeyEx( HKEY_CLASSES_ROOT,
                             "http\\shell\\open\\ddeexec\\topic", 0,
                             NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
                             &hKey, &dwDisp );

      if ( REG_SUCCEEDED( rc ) ) {
        const BYTE topic[] = "WWW_OpenURL";
        ::RegSetValueEx( hKey, "", 0, REG_SZ, topic, sizeof topic );
        ::RegCloseKey( hKey );
      }

      // Remember we need to undo this.
      mSupportingDDEExec = PR_TRUE;
    }
  }

  nsresult rv;

  nsCOMPtr<nsIProfileInternal> profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv));
  if (NS_FAILED(rv)) return rv;
  nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
  if (NS_FAILED(rv)) return rv;

  // If we have a profile, everything is fine -
  // unless mForceProfileStartup is TRUE. This flag is set when the
  // last window is closed in -turbo mode. When TRUE, it forces the
  // profile UI to come up at the beginning of the next -turbo session
  // even if we currently have a profile.
  PRBool haveProfile;
  rv = profileMgr->IsCurrentProfileAvailable(&haveProfile);
  if (!mForceProfileStartup && NS_SUCCEEDED(rv) && haveProfile)
      return NS_OK;

  // If the profile selection is happening, fail.
  PRBool doingProfileStartup;
  rv = profileMgr->GetIsStartingUp(&doingProfileStartup);
  if (NS_FAILED(rv) || doingProfileStartup) return NS_ERROR_FAILURE;

  // See if profile manager is being suppressed via -silent flag.
  PRBool canInteract = PR_TRUE;
  nsXPIDLCString arg;
  if (NS_SUCCEEDED(args->GetCmdLineValue("-silent", getter_Copies(arg)))) {
    if (!arg.IsEmpty()) {
      canInteract = PR_FALSE;
    }
  }
  rv = appStartup->DoProfileStartup(args, canInteract);

  mForceProfileStartup = PR_FALSE;

  return rv;
}

Here is the call graph for this function:

int nsNativeAppSupportWin::FindTopic ( HSZ  topic) [static, private]

Definition at line 725 of file nsNativeAppSupportWin.cpp.

                                            {
    for ( int i = 0; i < topicCount; i++ ) {
        if ( DdeCmpStringHandles( topic, mTopics[i] ) == 0 ) {
            return i;
        }
    }
    return -1;
}

Here is the call graph for this function:

static int nsNativeAppSupportWin::FindTopic ( HSZ  topic) [static, private]
nsresult nsNativeAppSupportWin::GetCmdLineArgs ( LPBYTE  request,
nsICmdLineService **  aResult 
) [static, private]

Definition at line 1945 of file nsNativeAppSupportWin.cpp.

                                                                                   {
    nsresult rv = NS_OK;

    int justCounting = 1;
    char **argv = 0;
    // Flags, etc.
    int init = 1;
    int between, quoted, bSlashCount;
    int argc;
    char *p;
    nsCAutoString arg;
    // We loop if we've not finished the second pass through.
    while ( 1 ) {
        // Initialize if required.
        if ( init ) {
            p = (char*)request;
            between = 1;
            argc = quoted = bSlashCount = 0;

            init = 0;
        }
        if ( between ) {
            // We are traversing whitespace between args.
            // Check for start of next arg.
            if (  *p != 0 && !isspace( *p ) ) {
                // Start of another arg.
                between = 0;
                arg = "";
                switch ( *p ) {
                    case '\\':
                        // Count the backslash.
                        bSlashCount = 1;
                        break;
                    case '"':
                        // Remember we're inside quotes.
                        quoted = 1;
                        break;
                    default:
                        // Add character to arg.
                        arg += *p;
                        break;
                }
            } else {
                // Another space between args, ignore it.
            }
        } else {
            // We are processing the contents of an argument.
            // Check for whitespace or end.
            if ( *p == 0 || ( !quoted && isspace( *p ) ) ) {
                // Process pending backslashes (interpret them
                // literally since they're not followed by a ").
                while( bSlashCount ) {
                    arg += '\\';
                    bSlashCount--;
                }
                // End current arg.
                if ( !justCounting ) {
                    argv[argc] = new char[ arg.Length() + 1 ];
                    if (!argv[argc]) {
                        rv = NS_ERROR_OUT_OF_MEMORY;
                        break;
                    }
                    strcpy( argv[argc], arg.get() );
                }
                argc++;
                // We're now between args.
                between = 1;
            } else {
                // Still inside argument, process the character.
                switch ( *p ) {
                    case '"':
                        // First, digest preceding backslashes (if any).
                        while ( bSlashCount > 1 ) {
                            // Put one backsplash in arg for each pair.
                            arg += '\\';
                            bSlashCount -= 2;
                        }
                        if ( bSlashCount ) {
                            // Quote is literal.
                            arg += '"';
                            bSlashCount = 0;
                        } else {
                            // Quote starts or ends a quoted section.
                            if ( quoted ) {
                                // Check for special case of consecutive double
                                // quotes inside a quoted section.
                                if ( *(p+1) == '"' ) {
                                    // This implies a literal double-quote.  Fake that
                                    // out by causing next double-quote to look as
                                    // if it was preceded by a backslash.
                                    bSlashCount = 1;
                                } else {
                                    quoted = 0;
                                }
                            } else {
                                quoted = 1;
                            }
                        }
                        break;
                    case '\\':
                        // Add to count.
                        bSlashCount++;
                        break;
                    default:
                        // Accept any preceding backslashes literally.
                        while ( bSlashCount ) {
                            arg += '\\';
                            bSlashCount--;
                        }
                        // Just add next char to the current arg.
                        arg += *p;
                        break;
                }
            }
        }
        // Check for end of input.
        if ( *p ) {
            // Go to next character.
            p++;
        } else {
            // If on first pass, go on to second.
            if ( justCounting ) {
                // Allocate argv array.
                argv = new char*[ argc ];
                if (!argv) {
                    rv = NS_ERROR_OUT_OF_MEMORY;
                    break;
                }
                // Start second pass
                justCounting = 0;
                init = 1;
            } else {
                // Quit.
                break;
            }
        }
    }

    nsCOMPtr<nsIComponentManager> compMgr;
    NS_GetComponentManager(getter_AddRefs(compMgr));
    
    rv = compMgr->CreateInstanceByContractID(
                    NS_COMMANDLINESERVICE_CONTRACTID,
                    nsnull, NS_GET_IID(nsICmdLineService),
                    (void**) aResult);

    if ( NS_FAILED( rv ) || NS_FAILED( ( rv = (*aResult)->Initialize( argc, argv ) ) ) ) {
#if MOZ_DEBUG_DDE
        printf( "Error creating command line service = 0x%08X (argc=%d, argv=0x%08X)\n", (int)rv, (int)argc, (void*)argv );
#endif
    }

    // Cleanup.
    while ( argc ) {
        delete [] argv[ --argc ];
    }
    delete [] argv;

    return rv;
}

Here is the call graph for this function:

static nsresult nsNativeAppSupportWin::GetStartupURL ( nsICmdLineService args,
nsCString taskURL 
) [static, private]
void nsNativeAppSupportWin::HandleCommandLine ( const char *  aCmdLineString,
nsIFile aWorkingDir,
PRUint32  aState 
) [static, private]

Definition at line 1313 of file nsNativeAppSupportWin.cpp.

{
    nsresult rv;

    int justCounting = 1;
    char **argv = 0;
    // Flags, etc.
    int init = 1;
    int between, quoted, bSlashCount;
    int argc;
    const char *p;
    nsCAutoString arg;

    nsCOMPtr<nsICommandLineRunner> cmdLine
        (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
    if (!cmdLine) {
        NS_ERROR("Couldn't create command line!");
        return;
    }

    // Parse command line args according to MS spec
    // (see "Parsing C++ Command-Line Arguments" at
    // http://msdn.microsoft.com/library/devprods/vs6/visualc/vclang/_pluslang_parsing_c.2b2b_.command.2d.line_arguments.htm).
    // We loop if we've not finished the second pass through.
    while ( 1 ) {
        // Initialize if required.
        if ( init ) {
            p = aCmdLineString;
            between = 1;
            argc = quoted = bSlashCount = 0;

            init = 0;
        }
        if ( between ) {
            // We are traversing whitespace between args.
            // Check for start of next arg.
            if (  *p != 0 && !isspace( *p ) ) {
                // Start of another arg.
                between = 0;
                arg = "";
                switch ( *p ) {
                    case '\\':
                        // Count the backslash.
                        bSlashCount = 1;
                        break;
                    case '"':
                        // Remember we're inside quotes.
                        quoted = 1;
                        break;
                    default:
                        // Add character to arg.
                        arg += *p;
                        break;
                }
            } else {
                // Another space between args, ignore it.
            }
        } else {
            // We are processing the contents of an argument.
            // Check for whitespace or end.
            if ( *p == 0 || ( !quoted && isspace( *p ) ) ) {
                // Process pending backslashes (interpret them
                // literally since they're not followed by a ").
                while( bSlashCount ) {
                    arg += '\\';
                    bSlashCount--;
                }
                // End current arg.
                if ( !justCounting ) {
                    argv[argc] = new char[ arg.Length() + 1 ];
                    strcpy( argv[argc], arg.get() );
                }
                argc++;
                // We're now between args.
                between = 1;
            } else {
                // Still inside argument, process the character.
                switch ( *p ) {
                    case '"':
                        // First, digest preceding backslashes (if any).
                        while ( bSlashCount > 1 ) {
                            // Put one backsplash in arg for each pair.
                            arg += '\\';
                            bSlashCount -= 2;
                        }
                        if ( bSlashCount ) {
                            // Quote is literal.
                            arg += '"';
                            bSlashCount = 0;
                        } else {
                            // Quote starts or ends a quoted section.
                            if ( quoted ) {
                                // Check for special case of consecutive double
                                // quotes inside a quoted section.
                                if ( *(p+1) == '"' ) {
                                    // This implies a literal double-quote.  Fake that
                                    // out by causing next double-quote to look as
                                    // if it was preceded by a backslash.
                                    bSlashCount = 1;
                                } else {
                                    quoted = 0;
                                }
                            } else {
                                quoted = 1;
                            }
                        }
                        break;
                    case '\\':
                        // Add to count.
                        bSlashCount++;
                        break;
                    default:
                        // Accept any preceding backslashes literally.
                        while ( bSlashCount ) {
                            arg += '\\';
                            bSlashCount--;
                        }
                        // Just add next char to the current arg.
                        arg += *p;
                        break;
                }
            }
        }
        // Check for end of input.
        if ( *p ) {
            // Go to next character.
            p++;
        } else {
            // If on first pass, go on to second.
            if ( justCounting ) {
                // Allocate argv array.
                argv = new char*[ argc ];

                // Start second pass
                justCounting = 0;
                init = 1;
            } else {
                // Quit.
                break;
            }
        }
    }

    rv = cmdLine->Init(argc, argv, aWorkingDir, aState);

    // Cleanup.
    while ( argc ) {
        delete [] argv[ --argc ];
    }
    delete [] argv;

    if (NS_FAILED(rv)) {
        NS_ERROR("Error initializing command line.");
        return;
    }

    cmdLine->Run();
}

Here is the call graph for this function:

Here is the caller graph for this function:

HDDEDATA CALLBACK nsNativeAppSupportWin::HandleDDENotification ( UINT  uType,
UINT  uFmt,
HCONV  hconv,
HSZ  hsz1,
HSZ  hsz2,
HDDEDATA  hdata,
ULONG  dwData1,
ULONG  dwData2 
) [static, private]

Definition at line 954 of file nsNativeAppSupportWin.cpp.

                                                              { // transaction-specific data

    if (!mCanHandleRequests)
        return 0;


#if MOZ_DEBUG_DDE
    printf( "DDE: uType  =%s\n",      uTypeDesc( uType ).get() );
    printf( "     uFmt   =%u\n",      (unsigned)uFmt );
    printf( "     hconv  =%08x\n",    (int)hconv );
    printf( "     hsz1   =%08x:%s\n", (int)hsz1, hszValue( mInstance, hsz1 ).get() );
    printf( "     hsz2   =%08x:%s\n", (int)hsz2, hszValue( mInstance, hsz2 ).get() );
    printf( "     hdata  =%08x\n",    (int)hdata );
    printf( "     dwData1=%08x\n",    (int)dwData1 );
    printf( "     dwData2=%08x\n",    (int)dwData2 );
#endif

    HDDEDATA result = 0;
    if ( uType & XCLASS_BOOL ) {
        switch ( uType ) {
            case XTYP_CONNECT:
                // Make sure its for our service/topic.
                if ( FindTopic( hsz1 ) != -1 ) {
                    // We support this connection.
                    result = (HDDEDATA)1;
                }
                break;
            case XTYP_CONNECT_CONFIRM:
                // We don't care about the conversation handle, at this point.
                result = (HDDEDATA)1;
                break;
        }
    } else if ( uType & XCLASS_DATA ) {
        if ( uType == XTYP_REQUEST ) {
            switch ( FindTopic( hsz1 ) ) {
                case topicOpenURL: {
                    // Open a given URL...

                    // Get the URL from the first argument in the command.
                    nsCAutoString url;
                    ParseDDEArg(hsz2, 0, url);

                    // Read the 3rd argument in the command to determine if a
                    // new window is to be used.
                    nsCAutoString windowID;
                    ParseDDEArg(hsz2, 2, windowID);
                    // "" means to open the URL in a new window.
                    if ( windowID.Equals( "" ) ) {
                        url.Insert("mozilla -new-window ", 0);
                    }
                    else {
                        url.Insert("mozilla -url ", 0);
                    }

#if MOZ_DEBUG_DDE
                    printf( "Handling dde XTYP_REQUEST request: [%s]...\n", url.get() );
#endif
                    // Now handle it.
                    HandleCommandLine(url.get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);

                    // Return pseudo window ID.
                    result = CreateDDEData( 1 );
                    break;
                }
                case topicGetWindowInfo: {
                    // This topic has to get the current URL, get the current
                    // page title and then format the output into the DDE
                    // return string.  The return value is "URL","Page Title",
                    // "Window ID" however the window ID is not used for this
                    // command, therefore it is returned as a null string

                    // This isn't really a loop.  We just use "break"
                    // statements to bypass the remaining steps when
                    // something goes wrong.
                    do {
                        // Get most recently used Nav window.
                        nsCOMPtr<nsIDOMWindowInternal> navWin;
                        GetMostRecentWindow( NS_LITERAL_STRING( "navigator:browser" ).get(),
                                             getter_AddRefs( navWin ) );
                        if ( !navWin ) {
                            // There is not a window open
                            break;
                        }
                        // Get content window.
                        nsCOMPtr<nsIDOMWindow> content;
                        navWin->GetContent( getter_AddRefs( content ) );
                        if ( !content ) {
                            break;
                        }
                        // Convert that to internal interface.
                        nsCOMPtr<nsIDOMWindowInternal> internalContent( do_QueryInterface( content ) );
                        if ( !internalContent ) {
                            break;
                        }
                        // Get location.
                        nsCOMPtr<nsIDOMLocation> location;
                        internalContent->GetLocation( getter_AddRefs( location ) );
                        if ( !location ) {
                            break;
                        }
                        // Get href for URL.
                        nsAutoString url;
                        if ( NS_FAILED( location->GetHref( url ) ) ) {
                            break;
                        }
                        // Escape any double-quotes.
                        escapeQuotes( url );

                        // Now for the title; first, get the "window" script global object.
                        nsCOMPtr<nsIScriptGlobalObject> scrGlobalObj( do_QueryInterface( internalContent ) );
                        if ( !scrGlobalObj ) {
                            break;
                        }
                        // Then from its doc shell get the base window...
                        nsCOMPtr<nsIBaseWindow> baseWindow =
                            do_QueryInterface( scrGlobalObj->GetDocShell() );
                        if ( !baseWindow ) {
                            break;
                        }
                        // And from the base window we can get the title.
                        nsXPIDLString title;
                        if(!baseWindow) {
                            break;
                        }
                        baseWindow->GetTitle(getter_Copies(title));
                        // Escape any double-quotes in the title.
                        escapeQuotes( title );

                        // Use a string buffer for the output data, first
                        // save a quote.
                        nsCAutoString   outpt( NS_LITERAL_CSTRING("\"") );
                        // Now copy the URL converting the Unicode string
                        // to a single-byte ASCII string
                        nsCAutoString tmpNativeStr;
                        NS_CopyUnicodeToNative( url, tmpNativeStr );
                        outpt.Append( tmpNativeStr );
                        // Add the "," used to separate the URL and the page
                        // title
                        outpt.Append( NS_LITERAL_CSTRING("\",\"") );
                        // Now copy the current page title to the return string
                        NS_CopyUnicodeToNative( title, tmpNativeStr );
                        outpt.Append( tmpNativeStr );
                        // Fill out the return string with the remainin ",""
                        outpt.Append( NS_LITERAL_CSTRING( "\",\"\"" ));

                        // Create a DDE handle to a char string for the data
                        // being returned, this copies and creates a "shared"
                        // copy of the DDE response until the calling APP
                        // reads it and says it can be freed.
                        result = CreateDDEData( (LPBYTE)(const char*)outpt.get(),
                                                outpt.Length() + 1 );
#if MOZ_DEBUG_DDE
                        printf( "WWW_GetWindowInfo->%s\n", outpt.get() );
#endif
                    } while ( PR_FALSE );
                    break;
                }
                case topicActivate: {
                    // Activate a Nav window...
                    nsCAutoString windowID;
                    ParseDDEArg(hsz2, 0, windowID);
                    // 4294967295 is decimal for 0xFFFFFFFF which is also a
                    //   correct value to do that Activate last window stuff
                    if ( windowID.Equals( "-1" ) ||
                         windowID.Equals( "4294967295" ) ) {
                        // We only support activating the most recent window (or a new one).
                        ActivateLastWindow();
                        // Return pseudo window ID.
                        result = CreateDDEData( 1 );
                    }
                    break;
                }
                case topicVersion: {
                    // Return version.  We're restarting at 1.0!
                    DWORD version = 1 << 16; // "1.0"
                    result = CreateDDEData( version );
                    break;
                }
                case topicRegisterViewer: {
                    // Register new viewer (not implemented).
                    result = CreateDDEData( PR_FALSE );
                    break;
                }
                case topicUnRegisterViewer: {
                    // Unregister new viewer (not implemented).
                    result = CreateDDEData( PR_FALSE );
                    break;
                }
                default:
                    break;
            }
        } else if ( uType & XTYP_POKE ) {
            switch ( FindTopic( hsz1 ) ) {
                case topicCancelProgress: {
                    // "Handle" progress cancel (actually, pretty much ignored).
                    result = (HDDEDATA)DDE_FACK;
                    break;
                }
                default:
                    break;
            }
        }
    } else if ( uType & XCLASS_FLAGS ) {
        if ( uType == XTYP_EXECUTE ) {
            // Prove that we received the request.
            DWORD bytes;
            LPBYTE request = DdeAccessData( hdata, &bytes );
#if MOZ_DEBUG_DDE
            printf( "Handling dde request: [%s]...\n", (char*)request );
#endif
            // Default is to open in current window.
            PRBool new_window = PR_FALSE;

            nsCAutoString url;
            ParseDDEArg((const char*) request, 0, url);

            // Read the 3rd argument in the command to determine if a
            // new window is to be used.
            nsCAutoString windowID;
            ParseDDEArg((const char*) request, 2, windowID);

            // "" means to open the URL in a new window.
            if ( windowID.Equals( "" ) ) {
                url.Insert("mozilla -new-window ", 0);
            }
            else {
                url.Insert("mozilla -url ", 0);
            }
#if MOZ_DEBUG_DDE
            printf( "Handling dde XTYP_REQUEST request: [%s]...\n", url.get() );
#endif
            // Now handle it.
            HandleCommandLine(url.get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);

            // Release the data.
            DdeUnaccessData( hdata );
            result = (HDDEDATA)DDE_FACK;
        } else {
            result = (HDDEDATA)DDE_FNOTPROCESSED;
        }
    } else if ( uType & XCLASS_NOTIFICATION ) {
    }
#if MOZ_DEBUG_DDE
    printf( "DDE result=%d (0x%08X)\n", (int)result, (int)result );
#endif
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HDDEDATA CALLBACK nsNativeAppSupportWin::HandleDDENotification ( UINT  uType,
UINT  uFmt,
HCONV  hconv,
HSZ  hsz1,
HSZ  hsz2,
HDDEDATA  hdata,
ULONG  dwData1,
ULONG  dwData2 
) [static, private]
nsresult nsNativeAppSupportWin::HandleRequest ( LPBYTE  request,
PRBool  newWindow,
nsIDOMWindow **  aResult 
) [static, private]

Definition at line 1806 of file nsNativeAppSupportWin.cpp.

                                                                                               {

    // if initial hidden window is still being displayed, we need to ignore requests
    // because such requests might not function properly.  See bug 147223 for details

    if (mInitialWindowActive) {
      return NS_ERROR_FAILURE;
    }

    // Parse command line.

    nsCOMPtr<nsICmdLineService> args;
    nsresult rv;

    rv = GetCmdLineArgs( request, getter_AddRefs( args ) );
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsINativeAppSupport> nativeApp;
    rv = appStartup->GetNativeAppSupport(getter_AddRefs( nativeApp ));
    if (NS_FAILED(rv)) return rv;

    // first see if there is a url
    nsXPIDLCString arg;
    rv = args->GetURLToLoad(getter_Copies(arg));
    if (NS_FAILED(rv)) return rv;

    if (!arg.IsEmpty() ) {
      // Launch browser.
#if MOZ_DEBUG_DDE
      printf( "Launching browser on url [%s]...\n", arg.get() );
#endif
      rv = nativeApp->EnsureProfile(args);
      if (NS_SUCCEEDED(rv)) {
        nsAutoString tmpArg;
        NS_CopyNativeToUnicode( arg, tmpArg );
        rv = OpenBrowserWindow( tmpArg, newWindow, aResult );
      }
      return rv;
    }


    // ok, let's try the -chrome argument
    rv = args->GetCmdLineValue("-chrome", getter_Copies(arg));
    if (NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {
      // Launch chrome.
#if MOZ_DEBUG_DDE
      printf( "Launching chrome url [%s]...\n", arg.get() );
#endif
      rv = nativeApp->EnsureProfile(args);
      if (NS_SUCCEEDED(rv))
        rv = OpenWindow( arg.get(), EmptyString(), aResult );
      return rv;
    }

    // try for the "-profilemanager" argument, in which case we want the
    // profile manager to appear, but only if there are no windows open

    rv = args->GetCmdLineValue( "-profilemanager", getter_Copies(arg));
    if ( NS_SUCCEEDED(rv) && !arg.IsEmpty() ) { // -profilemanager on command line
      nsCOMPtr<nsIDOMWindowInternal> window;
      GetMostRecentWindow(0, getter_AddRefs(window));
      if (!window) { // there are no open windows
        mForceProfileStartup = PR_TRUE;
      }
    }

    // try for the "-kill" argument, to shut down the server
    rv = args->GetCmdLineValue( "-kill", getter_Copies(arg));
    if ( NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {
      // Turn off server mode.
      nsCOMPtr<nsIAppStartup> appStartup
        (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
      if (NS_FAILED(rv)) return rv;

      nsCOMPtr<nsINativeAppSupport> native;
      rv = appStartup->GetNativeAppSupport( getter_AddRefs( native ));
      if (NS_SUCCEEDED(rv)) {
        native->SetIsServerMode( PR_FALSE );

        // close app if there are no more top-level windows.
        rv = appStartup->Quit(nsIAppStartup::eConsiderQuit);
      }

      return rv;
    }

    // check wheather it is a MAPI request.  If yes, don't open any new
    // windows and just return.
    rv = args->GetCmdLineValue(MAPI_STARTUP_ARG, getter_Copies(arg));
    if (NS_SUCCEEDED(rv) && !arg.IsEmpty()) {
      return nativeApp->EnsureProfile(args);
    }

    // Try standard startup's command-line handling logic from nsAppRunner.cpp...

    // Need profile before opening windows.
    rv = nativeApp->EnsureProfile(args);
    if (NS_FAILED(rv)) return rv;

    // This will tell us whether the command line processing opened a window.
    PRBool windowOpened = PR_FALSE;

    // Process command line options.
    rv = DoCommandLines( args, &windowOpened );

    // If a window was opened, then we're done.
    // Note that we keep on trying in the unlikely event of an error.
    if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT || windowOpened) {
      return NS_OK;
    }

    // ok, no idea what the param is.
#if MOZ_DEBUG_DDE
    printf( "Unknown request [%s]\n", (char*) request );
#endif
    // if all else fails, open a browser window
    const char * const contractID =
      "@mozilla.org/commandlinehandler/general-startup;1?type=browser";
    nsCOMPtr<nsICmdLineHandler> handler = do_GetService(contractID, &rv);
    if (NS_FAILED(rv)) return rv;

    nsXPIDLString defaultArgs;
    rv = handler->GetDefaultArgs(getter_Copies(defaultArgs));
    if (NS_FAILED(rv) || defaultArgs.IsEmpty()) return rv;

    // force a new window for a home page group
    if (FindCharInString(defaultArgs, '\n') != kNotFound)
        newWindow = PR_TRUE;

    return OpenBrowserWindow(defaultArgs, newWindow, aResult);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 715 of file nsNativeAppSupportWin.cpp.

                                        {
    for ( int i = 0; i < topicCount; i++ ) {
        if ( !( mTopics[ i ] = DdeCreateStringHandle( mInstance, NS_CONST_CAST(char *,topicNames[ i ]), CP_WINANSI ) ) ) {
            return PR_FALSE;
        }
    }
    return PR_TRUE;
}
static PRBool nsNativeAppSupportWin::InitTopicStrings ( ) [static, private]
void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Definition at line 2644 of file nsNativeAppSupportWin.cpp.

                                           {

    if ( !mServerMode )
        return NS_OK;

    // If the last window closed is our special "turbo" window made
    // in StartServerMode(), don't do anything.
    if ( mInitialWindowActive ) {
        mInitialWindowActive = PR_FALSE;
        mShouldShowUI = PR_TRUE;
        return NS_OK;
    }

    // If the last window closed is our confirmation dialog,
    // don't do anything.
    if ( mLastWindowIsConfirmation ) {
        mLastWindowIsConfirmation = PR_FALSE;
        return NS_OK;
    }


    nsresult rv;

    // If activated by the browser.turbo.singleProfileOnly pref,
    // check for multi-profile situation and turn off turbo mode
    // if there are multiple profiles.
    PRBool singleProfileOnly = PR_FALSE;
    nsCOMPtr<nsIPrefBranch> prefService( do_GetService( NS_PREFSERVICE_CONTRACTID, &rv ) );
    if ( NS_SUCCEEDED( rv ) ) {
        prefService->GetBoolPref( "browser.turbo.singleProfileOnly", &singleProfileOnly );
    }
    if ( singleProfileOnly ) {
        nsCOMPtr<nsIProfile> profileMgr( do_GetService( NS_PROFILE_CONTRACTID, &rv ) );
        if ( NS_SUCCEEDED( rv ) ) {
            PRInt32 profileCount = 0;
            if ( NS_SUCCEEDED( profileMgr->GetProfileCount( &profileCount ) ) &&
                 profileCount > 1 ) {
                // Turn off turbo mode and quit the application.
                SetIsServerMode( PR_FALSE );
                nsCOMPtr<nsIAppStartup> appStartup
                    (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
                if ( NS_SUCCEEDED( rv ) ) {
                    appStartup->Quit(nsIAppStartup::eAttemptQuit);
                }
                return NS_OK;
            }
        }
    }

    if ( !mShownTurboDialog ) {
        PRBool showDialog = PR_TRUE;
        if ( NS_SUCCEEDED( rv ) )
            prefService->GetBoolPref( "browser.turbo.showDialog", &showDialog );

        if ( showDialog ) {
          /* show turbo dialog, unparented. at this point in the application
             shutdown process the last window is largely torn down and
             unsuitable for parenthood.
          */
          nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
          if ( wwatch ) {
              nsCOMPtr<nsIDOMWindow> newWindow;
              mShownTurboDialog = PR_TRUE;
              mLastWindowIsConfirmation = PR_TRUE;
              rv = wwatch->OpenWindow(0, "chrome://navigator/content/turboDialog.xul",
                                      "_blank", "chrome,modal,titlebar,centerscreen,dialog",
                                      0, getter_AddRefs(newWindow));
          }
        }
    }

    nsCOMPtr<nsIAppStartup> appStartup
        (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
    if ( NS_SUCCEEDED( rv ) ) {
        // Instead of staying alive, launch a new instance of the application and then
        // terminate for real.  We take steps to ensure that the new instance will run
        // as a "server process" and not try to pawn off its request back on this
        // instance.

        // Grab mutex.  Process termination will release it.
        Mutex mutexLock = Mutex(mMutexName);
        NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE );

        // Turn off MessageWindow so the other process can't see us.
        MessageWindow mw;
        mw.Destroy();

        // Launch another instance.
        char buffer[ _MAX_PATH ];
        // Same application as this one.
        ::GetModuleFileName( 0, buffer, sizeof buffer );
        // Clean up name so we don't have to worry about enclosing it in quotes.
        ::GetShortPathName( buffer, buffer, sizeof buffer );
        nsCAutoString cmdLine( buffer );
        // The new process must run in turbo mode (no splash screen, no window, etc.).
        cmdLine.Append( " -turbo" );

        // Now do the Win32 stuff...
        STARTUPINFO startupInfo;
        ::GetStartupInfo( &startupInfo );
        PROCESS_INFORMATION processInfo;
        DWORD rc = ::CreateProcess( 0,
                              (LPTSTR)cmdLine.get(),
                              0,
                              0,
                              0,
                              0,
                              0,
                              0,
                              &startupInfo,
                              &processInfo );

        // Turn off turbo mode and quit the application.
        SetIsServerMode( PR_FALSE );
        appStartup->Quit(nsIAppStartup::eAttemptQuit);

        // Done.  This app will now commence shutdown.
    }
    return NS_OK;
}

Here is the call graph for this function:

Definition at line 1561 of file nsNativeAppSupportWin.cpp.

{
    nsresult rv = NS_OK;

    // Open the argument URL in the most recently used Navigator window.
    // If there is no Nav window, open a new one.

    // If at all possible, hand the request off to the most recent
    // browser window.

    nsCOMPtr<nsIDOMWindowInternal> navWin;
    GetMostRecentWindow( NS_LITERAL_STRING( "navigator:browser" ).get(), getter_AddRefs( navWin ) );

    // This isn't really a loop.  We just use "break" statements to fall
    // out to the OpenWindow call when things go awry.
    do {
        // If caller requires a new window, then don't use an existing one.
        if ( !navWin ) {
            // Have to open a new one.
            break;
        }

        nsCOMPtr<nsIBrowserDOMWindow> bwin;
        { // scope a bunch of temporary cruft used to generate bwin
          nsCOMPtr<nsIWebNavigation> navNav( do_GetInterface( navWin ) );
          nsCOMPtr<nsIDocShellTreeItem> navItem( do_QueryInterface( navNav ) );
          if ( navItem ) {
            nsCOMPtr<nsIDocShellTreeItem> rootItem;
            navItem->GetRootTreeItem( getter_AddRefs( rootItem ) );
            nsCOMPtr<nsIDOMWindow> rootWin( do_GetInterface( rootItem ) );
            nsCOMPtr<nsIDOMChromeWindow> chromeWin(do_QueryInterface(rootWin));
            if ( chromeWin )
              chromeWin->GetBrowserDOMWindow( getter_AddRefs ( bwin ) );
          }
        }
        if ( bwin ) {
          nsCOMPtr<nsIURI> uri;
          NS_NewURI( getter_AddRefs( uri ), NS_LITERAL_CSTRING("about:blank"), 0, 0 );
          if ( uri ) {
            nsCOMPtr<nsIDOMWindow> container;
            rv = bwin->OpenURI( uri, 0,
                                nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW,
                                nsIBrowserDOMWindow::OPEN_EXTERNAL,
                                getter_AddRefs( container ) );
            if ( NS_SUCCEEDED( rv ) )
              return NS_OK;
          }
        }

        NS_ERROR("failed to hand off external URL to extant window\n");
    } while ( PR_FALSE );

    // open a new window if caller requested it or if anything above failed

    char* argv[] = { 0 };
    nsCOMPtr<nsICommandLineRunner> cmdLine
        (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
    NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);

    rv = cmdLine->Init(0, argv, nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);
    NS_ENSURE_SUCCESS(rv, rv);

    return cmdLine->Run();
}

Here is the call graph for this function:

nsresult nsNativeAppSupportWin::OpenBrowserWindow ( const nsAString &  aArgs,
PRBool  newWindow,
nsIDOMWindow **  aResult 
) [static, private]

Definition at line 2353 of file nsNativeAppSupportWin.cpp.

{
    nsresult rv = NS_OK;
    // Open the argument URL according to the external link preference.
    // If there is no Nav window, or newWindow is PR_TRUE, open a new one.

    // Get most recently used Nav window.
    nsCOMPtr<nsIDOMWindowInternal> navWin;
    GetMostRecentWindow( NS_LITERAL_STRING( "navigator:browser" ).get(), getter_AddRefs( navWin ) );

    // This isn't really a loop.  We just use "break" statements to fall
    // out to the OpenWindow call when things go awry.
    do {
        // If caller requires a new window, then don't use an existing one.
        if ( newWindow ) {
            break;
        }
        if ( !navWin ) {
            // Have to open a new one.
            break;
        }
        nsCOMPtr<nsIDOMChromeWindow> chromeWin( do_QueryInterface( navWin ) );
        if ( !chromeWin ) {
            break;
        }
        nsCOMPtr<nsIBrowserDOMWindow> bwin;
        chromeWin->GetBrowserDOMWindow( getter_AddRefs( bwin ) );
        if ( !bwin ) {
            break;
        }
        nsCOMPtr<nsIURIFixup> fixup( do_GetService( NS_URIFIXUP_CONTRACTID ) );
        if ( !fixup ) {
            break;
        }
        nsCOMPtr<nsIURI> uri;
        rv = fixup->CreateFixupURI( NS_ConvertUTF16toUTF8( aArgs ),
                                    nsIURIFixup::FIXUP_FLAG_NONE,
                                    getter_AddRefs( uri ) );
        if ( NS_FAILED(rv) || !uri ) {
            break;
        }
        return bwin->OpenURI( uri, nsnull, nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW, nsIBrowserDOMWindow::OPEN_EXTERNAL, aResult );
    } while ( PR_FALSE );

    nsCOMPtr<nsICmdLineHandler> handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv));
    if (NS_FAILED(rv)) return rv;

    nsXPIDLCString chromeUrlForTask;
    rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask));
    if (NS_FAILED(rv)) return rv;

    // Last resort is to open a brand new window.
    return OpenWindow( chromeUrlForTask.get(), aArgs, aResult );
}

Here is the call graph for this function:

nsresult nsNativeAppSupportWin::OpenWindow ( const char *  urlstr,
const char *  args 
) [static, private]

Definition at line 1475 of file nsNativeAppSupportWin.cpp.

                                                                       {

  nsresult rv = NS_ERROR_FAILURE;

  nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
  nsCOMPtr<nsISupportsCString> sarg(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
  if (sarg)
    sarg->SetData(nsDependentCString(args));

  if (wwatch && sarg) {
    nsCOMPtr<nsIDOMWindow> newWindow;
    rv = wwatch->OpenWindow(0, urlstr, "_blank", "chrome,dialog=no,all",
                   sarg, getter_AddRefs(newWindow));
#if MOZ_DEBUG_DDE
  } else {
      printf("Get WindowWatcher (or create string) failed\n");
#endif
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNativeAppSupportWin::OpenWindow ( const char *  urlstr,
const nsAString &  aArgs,
nsIDOMWindow **  aResult 
) [static, private]

Definition at line 2209 of file nsNativeAppSupportWin.cpp.

{

  nsresult rv = NS_ERROR_FAILURE;

  nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
  nsCOMPtr<nsISupportsString>
    sarg(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
  if (sarg)
    sarg->SetData(aArgs);

  if (wwatch && sarg) {
    rv = wwatch->OpenWindow(0, urlstr, "_blank", "chrome,dialog=no,all",
                   sarg, aResult);
#if MOZ_DEBUG_DDE
  } else {
      printf("Get WindowWatcher (or create string) failed\n");
#endif
  }
  return rv;
}

Here is the call graph for this function:

void nsNativeAppSupportWin::ParseDDEArg ( HSZ  args,
int  index,
nsCString string 
) [static, private]

Definition at line 1271 of file nsNativeAppSupportWin.cpp.

                                                                                {
    DWORD argLen = DdeQueryString( mInstance, args, NULL, NULL, CP_WINANSI );
    // there wasn't any string, so return empty string
    if ( !argLen ) return;
    nsCAutoString temp;
    // Ensure result's buffer is sufficiently big.
    temp.SetLength( argLen );
    // Now get the string contents.
    DdeQueryString( mInstance, args, temp.BeginWriting(), temp.Length(), CP_WINANSI );
    // Parse out the given arg.
    ParseDDEArg(temp.get(), index, aString);
    return;
}

Here is the call graph for this function:

void nsNativeAppSupportWin::ParseDDEArg ( const char *  args,
int  index,
nsCString aString 
) [static, private]

Definition at line 1230 of file nsNativeAppSupportWin.cpp.

                                                                                        {
    if ( args ) {
        int argLen = strlen(args);
        nsDependentCString temp(args, argLen);

        // offset points to the comma preceding the desired arg.
        PRInt32 offset = -1;
        // Skip commas till we get to the arg we want.
        while( index-- ) {
            // If this arg is quoted, then go to closing quote.
            offset = advanceToEndOfQuotedArg( args, offset, argLen);
            // Find next comma.
            offset = temp.FindChar( ',', offset );
            if ( offset == kNotFound ) {
                // No more commas, give up.
                aString = args;
                return;
            }
        }
        // The desired argument starts just past the preceding comma,
        // which offset points to, and extends until the following
        // comma (or the end of the string).
        //
        // Since the argument might be enclosed in quotes, we need to
        // deal with that before searching for the terminating comma.
        // We advance offset so it ends up pointing to the start of
        // the argument we want.
        PRInt32 end = advanceToEndOfQuotedArg( args, offset++, argLen );
        // Find next comma (or end of string).
        end = temp.FindChar( ',', end );
        if ( end == kNotFound ) {
            // Arg is the rest of the string.
            end = argLen;
        }
        // Extract result.
        aString.Assign( args + offset, end - offset );
    }
    return;
}

Here is the call graph for this function:

static void nsNativeAppSupportWin::ParseDDEArg ( HSZ  args,
int  index,
nsCString string 
) [static, private]
static void nsNativeAppSupportWin::ParseDDEArg ( const char *  args,
int  index,
nsCString aString 
) [static, private]

Definition at line 169 of file nsNativeAppSupportBase.cpp.

                                                                  {
    nsresult rv = NS_OK;
    if ( p ) {
        *p = 0;
        if ( iid.Equals( NS_GET_IID( nsINativeAppSupport ) ) ) {
            nsINativeAppSupport *result = this;
            *p = result;
            NS_ADDREF( result );
        } else if ( iid.Equals( NS_GET_IID( nsISupports ) ) ) {
            nsISupports *result = NS_STATIC_CAST( nsISupports*, this );
            *p = result;
            NS_ADDREF( result );
        } else {
            rv = NS_NOINTERFACE;
        }
    } else {
        rv = NS_ERROR_NULL_POINTER;
    }
    return rv;
}

Here is the call graph for this function:

Definition at line 826 of file nsNativeAppSupportWin.cpp.

                            {
    // If another process wants to look for the message window, they need
    // to wait to hold the lock, in which case they will not find the
    // window as we will destroy ours under our lock.
    // When the mutex goes off the stack, it is unlocked via destructor.
    Mutex mutexLock(mMutexName);
    NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE);

    // If we've got a message window to receive IPC or new window requests,
    // get rid of it as we are shutting down.
    // Note:  Destroy calls DestroyWindow, which will only work on a window
    //  created by the same thread.
    MessageWindow mw;
    mw.Destroy();

    if ( mInstance ) {
        // Unregister application name.
        DdeNameService( mInstance, mApplication, 0, DNS_UNREGISTER );
        // Clean up strings.
        if ( mApplication ) {
            DdeFreeStringHandle( mInstance, mApplication );
            mApplication = 0;
        }
        for ( int i = 0; i < topicCount; i++ ) {
            if ( mTopics[i] ) {
                DdeFreeStringHandle( mInstance, mTopics[i] );
                mTopics[i] = 0;
            }
        }
        DdeUninitialize( mInstance );
        mInstance = 0;
#if MOZ_DEBUG_DDE
    printf( "DDE server stopped\n" );
#endif
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 2545 of file nsNativeAppSupportWin.cpp.

                                         {
    // Remove the tray icon.
    mTrayRestart = 0;
    ::Shell_NotifyIcon( NIM_DELETE, &mIconData );
    // Delete the menu.
    ::DestroyMenu( mTrayIconMenu );
}

Here is the caller graph for this function:

static void nsNativeAppSupportWin::RemoveSysTrayIcon ( ) [static, private]

Implemented in nsNativeAppSupportMac.

Implemented in nsNativeAppSupportMac.

nsresult nsNativeAppSupportWin::ReParent ( nsISupports *  window,
HWND  newParent 
) [static, private]

Definition at line 2271 of file nsNativeAppSupportWin.cpp.

                                                                     {
    HWND hMainFrame = hwndForDOMWindow( window );
    if ( !hMainFrame ) {
        return NS_ERROR_FAILURE;
    }

    // Filter out WM_SETFOCUS messages while reparenting to
    // other than the desktop.
    //
    // For some reason, Windows generates one and it causes
    // our focus/activation code to assert.
    LONG oldProc = 0;
    if ( newParent ) {
        // Subclass the window.
        oldProc = ::SetWindowLong( hMainFrame,
                                   GWL_WNDPROC,
                                   (LONG)(WNDPROC)focusFilterProc );

        // Store old procedure in window so it is available within
        // focusFilterProc.
        ::SetProp( hMainFrame, procPropertyName, (HANDLE)oldProc );
    }

    // Reset the parent.
    ::SetParent( hMainFrame, newParent );

    // Restore old procedure.
    if ( newParent ) {
        ::SetWindowLong( hMainFrame, GWL_WNDPROC, oldProc );
        ::RemoveProp( hMainFrame, procPropertyName );
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsNativeAppSupportWin::ReParent ( nsISupports *  window,
HWND  newParent 
) [static, private]

Definition at line 2632 of file nsNativeAppSupportWin.cpp.

                                                            {
    // If it is being turned off, remove systray icon.
    if ( mServerMode && !isServerMode ) {
        RemoveSysTrayIcon();
    }
    else if ( !mServerMode && isServerMode) {
        SetupSysTrayIcon();
    }
    return nsNativeAppSupportBase::SetIsServerMode( isServerMode );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2421 of file nsNativeAppSupportWin.cpp.

                                        {
    // Messages go to the hidden window.
    mIconData.hWnd  = (HWND)MessageWindow();

    // Icon is our default application icon.
    mIconData.hIcon =  (HICON)::LoadImage( ::GetModuleHandle( NULL ),
                                           IDI_APPLICATION,
                                           IMAGE_ICON,
                                           ::GetSystemMetrics( SM_CXSMICON ),
                                           ::GetSystemMetrics( SM_CYSMICON ),
                                           NULL );

    // Tooltip is the brand short name.
    mIconData.szTip[0] = 0;
    nsCOMPtr<nsIStringBundleService> svc( do_GetService( NS_STRINGBUNDLE_CONTRACTID ) );
    if ( svc ) {
        nsCOMPtr<nsIStringBundle> brandBundle;
        nsXPIDLString tooltip;
        svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) );
        if ( brandBundle ) {
            brandBundle->GetStringFromName( NS_LITERAL_STRING( "brandShortName" ).get(),
                                            getter_Copies( tooltip ) );
            ::strncpy( mIconData.szTip,
                       NS_LossyConvertUTF16toASCII(tooltip).get(),
                       sizeof mIconData.szTip - 1 );
        }
        // Build menu.
        nsCOMPtr<nsIStringBundle> turboBundle;
        nsCOMPtr<nsIStringBundle> mailBundle;
        svc->CreateBundle( "chrome://navigator/locale/turboMenu.properties",
                           getter_AddRefs( turboBundle ) );
        nsresult rv = svc->CreateBundle( "chrome://messenger/locale/mailTurboMenu.properties",
                                         getter_AddRefs( mailBundle ) );
        PRBool isMail = NS_SUCCEEDED(rv) && mailBundle;
        nsAutoString exitText;
        nsAutoString disableText;
        nsAutoString navigatorText;
        nsAutoString editorText;
        nsAutoString mailText;
        nsAutoString addressbookText;
        nsXPIDLString text;
        if ( turboBundle ) {
            if ( brandBundle ) {
                const PRUnichar* formatStrings[] = { tooltip.get() };
                turboBundle->FormatStringFromName( NS_LITERAL_STRING( "Exit" ).get(), formatStrings, 1,
                                                   getter_Copies( text ) );
                exitText = text;
            }
            turboBundle->GetStringFromName( NS_LITERAL_STRING( "Disable" ).get(),
                                            getter_Copies( text ) );
            disableText = text;
            turboBundle->GetStringFromName( NS_LITERAL_STRING( "Navigator" ).get(),
                                            getter_Copies( text ) );
            navigatorText = text;
            turboBundle->GetStringFromName( NS_LITERAL_STRING( "Editor" ).get(),
                                            getter_Copies( text ) );
            editorText = text;
        }
        if (isMail) {
            mailBundle->GetStringFromName( NS_LITERAL_STRING( "MailNews" ).get(),
                                           getter_Copies( text ) );
            mailText = text;
            mailBundle->GetStringFromName( NS_LITERAL_STRING( "Addressbook" ).get(),
                                           getter_Copies( text ) );
            addressbookText = text;
        }

        if ( exitText.IsEmpty() ) {
            exitText.Assign( NS_LITERAL_STRING( "E&xit " ) );
            exitText.Append( NS_LITERAL_STRING( NS_STRINGIFY(MOZ_APP_DISPLAYNAME) ) );
        }

        if ( disableText.IsEmpty() )
            disableText.Assign( NS_LITERAL_STRING("&Disable Quick Launch") );

        if ( navigatorText.IsEmpty() )
            navigatorText.Assign( NS_LITERAL_STRING("&Navigator") );

        if ( editorText.IsEmpty() )
            editorText.Assign( NS_LITERAL_STRING("&Composer") );

        if ( isMail ) {
            if ( mailText.IsEmpty() )
              mailText.Assign( NS_LITERAL_STRING("&Mail && Newsgroups") );
            if ( addressbookText.IsEmpty() )
              addressbookText.Assign( NS_LITERAL_STRING("&Address Book") );
        }
        // Create menu and add item.
        mTrayIconMenu = ::CreatePopupMenu();
        ::AppendMenuW( mTrayIconMenu, MF_STRING, TURBO_NAVIGATOR, navigatorText.get() );
        if ( ::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) {
            AppendMenuItem( mTrayIconMenu, TURBO_NAVIGATOR, navigatorText );
            if ( isMail )
                AppendMenuItem( mTrayIconMenu, TURBO_MAIL, mailText );
            AppendMenuItem( mTrayIconMenu, TURBO_EDITOR, editorText );
            if ( isMail )
                AppendMenuItem( mTrayIconMenu, TURBO_ADDRESSBOOK, addressbookText );
            ::AppendMenu( mTrayIconMenu, MF_SEPARATOR, NULL, NULL );
            AppendMenuItem( mTrayIconMenu, TURBO_DISABLE, disableText );
            AppendMenuItem( mTrayIconMenu, TURBO_EXIT, exitText );
        }
        else {
            if (isMail)
                ::AppendMenuW( mTrayIconMenu, MF_STRING, TURBO_MAIL, mailText.get() );
            ::AppendMenuW( mTrayIconMenu, MF_STRING, TURBO_EDITOR, editorText.get() );
            if (isMail)
                ::AppendMenuW( mTrayIconMenu, MF_STRING, TURBO_ADDRESSBOOK, addressbookText.get() );
            ::AppendMenuW( mTrayIconMenu, MF_SEPARATOR, NULL, NULL );
            ::AppendMenuW( mTrayIconMenu, MF_STRING, TURBO_DISABLE, disableText.get() );
            ::AppendMenuW( mTrayIconMenu, MF_STRING, TURBO_EXIT, exitText.get() );
        }
    }

    // Add the tray icon.

    /* The tray icon will be removed if explorer restarts. Therefore, we are registering
    the following window message so we know when the taskbar is created. Explorer will send
    this message when explorer restarts.*/
    mTrayRestart = ::RegisterWindowMessage(TEXT("TaskbarCreated"));
    ::Shell_NotifyIcon( NIM_ADD, &mIconData );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void nsNativeAppSupportWin::SetupSysTrayIcon ( ) [static, private]

Definition at line 670 of file nsNativeAppSupportWin.cpp.

                                              {
    NS_ENSURE_ARG( aResult );
    NS_ENSURE_TRUE( mInstance == 0, NS_ERROR_NOT_INITIALIZED );
    NS_ENSURE_STATE( gAppData );

    if (getenv("MOZ_NO_REMOTE"))
    {
        *aResult = PR_TRUE;
        return NS_OK;
    }

    nsresult rv = NS_ERROR_FAILURE;
    *aResult = PR_FALSE;

    // Grab mutex first.

    // Build mutex name from app name.
    ::_snprintf( mMutexName, sizeof mMutexName, "%s%s", gAppData->name, MOZ_STARTUP_MUTEX_NAME );
    Mutex startupLock = Mutex( mMutexName );

    NS_ENSURE_TRUE( startupLock.Lock( MOZ_DDE_START_TIMEOUT ), NS_ERROR_FAILURE );

    // Search for existing message window.
    MessageWindow msgWindow;
    if ( (HWND)msgWindow ) {
        // We are a client process.  Pass request to message window.
        LPTSTR cmd = ::GetCommandLine();
        rv = msgWindow.SendRequest( cmd );
    } else {
        // We will be server.
        rv = msgWindow.Create();
        if ( NS_SUCCEEDED( rv ) ) {
            // Start up DDE server.
            this->StartDDE();
            // Tell caller to spin message loop.
            *aResult = PR_TRUE;
        }
    }

    startupLock.Unlock();

    return rv;
}

Here is the call graph for this function:

Definition at line 758 of file nsNativeAppSupportWin.cpp.

                                {
    NS_ENSURE_TRUE( mInstance == 0, NS_ERROR_NOT_INITIALIZED );

    // Initialize DDE.
    NS_ENSURE_TRUE( DMLERR_NO_ERROR == DdeInitialize( &mInstance,
                                                      nsNativeAppSupportWin::HandleDDENotification,
                                                      APPCLASS_STANDARD,
                                                      0 ),
                    NS_ERROR_FAILURE );

    // Allocate DDE strings.
    NS_ENSURE_TRUE( ( mApplication = DdeCreateStringHandle( mInstance, (char*) gAppData->name, CP_WINANSI ) ) && InitTopicStrings(),
                    NS_ERROR_FAILURE );

    // Next step is to register a DDE service.
    NS_ENSURE_TRUE( DdeNameService( mInstance, mApplication, 0, DNS_REGISTER ), NS_ERROR_FAILURE );

#if MOZ_DEBUG_DDE
    printf( "DDE server started\n" );
#endif

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 2562 of file nsNativeAppSupportWin.cpp.

                                       {

    // Turn on system tray icon.
    SetupSysTrayIcon();

    if (mShouldShowUI) {
        // We dont have to anything anymore. The native UI
        // will create the window
        return NS_OK;
    } else {
        // Sometimes a window will have been opened even though mShouldShowUI is false
        // (e.g., seamonkey -mail -turbo).  Detect that by testing whether there's a
        // window already open.
        nsCOMPtr<nsIDOMWindowInternal> win;
        GetMostRecentWindow( 0, getter_AddRefs( win ) );
        if ( win ) {
            // Window already opened, don't need this special Nav window.
            return NS_OK;
        }
    }

    // Since native UI wont create any window, we create a hidden window
    // so thing work alright.

    // Create some of the objects we'll need.
    nsCOMPtr<nsIWindowWatcher>   ww(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
    nsCOMPtr<nsISupportsString> arg1(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
    nsCOMPtr<nsISupportsString> arg2(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
    if ( !ww || !arg1 || !arg2 ) {
        return NS_OK;
    }

    // Create the array for the arguments.
    nsCOMPtr<nsISupportsArray> argArray = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
    if ( !argArray ) {
        return NS_OK;
    }

    // arg1 is the url to load.
    // arg2 is the string that tells navigator.js to auto-close.
    arg1->SetData( NS_LITERAL_STRING( "about:blank" ) );
    arg2->SetData( NS_LITERAL_STRING( "turbo=yes" ) );

    // Put args into array.
    if ( NS_FAILED( argArray->AppendElement( arg1 ) ) ||
        NS_FAILED( argArray->AppendElement( arg2 ) ) ) {
        return NS_OK;
    }

    // Now open the window.
    nsCOMPtr<nsIDOMWindow> newWindow;
    ww->OpenWindow( 0,
        "chrome://navigator/content",
        "_blank",
        "chrome,dialog=no,toolbar=no",
        argArray,
        getter_AddRefs( newWindow ) );

    if ( !newWindow ) {
        return NS_OK;
    }
    mInitialWindowActive = PR_TRUE;

    // Hide this window by re-parenting it (to ensure it doesn't appear).
    ReParent( newWindow, (HWND)MessageWindow() );

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 784 of file nsNativeAppSupportWin.cpp.

                                             {
    NS_ENSURE_ARG( aResult );
    NS_ENSURE_TRUE( mInstance, NS_ERROR_NOT_INITIALIZED );

    nsresult rv = NS_OK;
    *aResult = PR_TRUE;

    Mutex ddeLock( mMutexName );

    if ( ddeLock.Lock( MOZ_DDE_STOP_TIMEOUT ) ) {
        if ( mConversations == 0 ) {
            this->Quit();
        } else {
            *aResult = PR_FALSE;
        }

        ddeLock.Unlock();
    }
    else {
        // No DDE application name specified, but that's OK.  Just
        // forge ahead.
        *aResult = PR_TRUE;
    }

    return rv;
}

Here is the call graph for this function:


Friends And Related Function Documentation

MessageWindow [friend]

Definition at line 367 of file nsNativeAppSupportWin.cpp.


Member Data Documentation

Definition at line 186 of file nsINativeAppSupport.idl.

Definition at line 362 of file nsNativeAppSupportWin.cpp.

char * nsNativeAppSupportWin::mAppName = nameBuffer [static, private]

Definition at line 440 of file nsNativeAppSupportWin.cpp.

Definition at line 364 of file nsNativeAppSupportWin.cpp.

Definition at line 349 of file nsNativeAppSupportWin.cpp.

Definition at line 442 of file nsNativeAppSupportWin.cpp.

NOTIFYICONDATA nsNativeAppSupportWin::mIconData [static, private]
Initial value:
 { sizeof(NOTIFYICONDATA),
                                                    0,
                                                    1,
                                                    NIF_ICON | NIF_MESSAGE | NIF_TIP,
                                                    WM_USER,
                                                    0,
                                                    0 }

Definition at line 435 of file nsNativeAppSupportWin.cpp.

Definition at line 441 of file nsNativeAppSupportWin.cpp.

DWORD nsNativeAppSupportWin::mInstance = 0 [static, private]

Definition at line 363 of file nsNativeAppSupportWin.cpp.

Definition at line 73 of file nsNativeAppSupportBase.h.

char nsNativeAppSupportWin::mMutexName = { 0 } [static, private]

Definition at line 366 of file nsNativeAppSupportWin.cpp.

Definition at line 68 of file nsNativeAppSupportBase.h.

Definition at line 70 of file nsNativeAppSupportBase.h.

Definition at line 71 of file nsNativeAppSupportBase.h.

Definition at line 72 of file nsNativeAppSupportBase.h.

Definition at line 69 of file nsNativeAppSupportBase.h.

Definition at line 365 of file nsNativeAppSupportWin.cpp.

HSZ nsNativeAppSupportWin::mTopics = { 0 } [static, private]

Definition at line 362 of file nsNativeAppSupportWin.cpp.

Definition at line 436 of file nsNativeAppSupportWin.cpp.

Definition at line 421 of file nsNativeAppSupportWin.cpp.

Definition at line 187 of file nsINativeAppSupport.idl.


The documentation for this class was generated from the following files: