outpt.Append( NS_LossyConvertUCS2toASCII( url ) );
nsCAutoString tmpNativeStr; NS_CopyUnicodeToNative( url, tmpNativeStr ); outpt.Append( tmpNativeStr );
nsNativeAppSupportWin::HandleDDENotification( UINT uType,       // transaction type                                              UINT uFmt,        // clipboard data format                                              HCONV hconv,      // handle to the conversation                                              HSZ hsz1,         // handle to a string                                              HSZ hsz2,         // handle to a string                                              HDDEDATA hdata,   // handle to a global memory object                                              ULONG dwData1,    // transaction-specific data                                              ULONG dwData2 ) { // 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                        outpt.Append( NS_LossyConvertUCS2toASCII( url ) );                        // 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                        outpt.Append( NS_LossyConvertUCS2toASCII( title.get() ));                        // 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;}