iethread.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "priv.h"
  2. #include <iethread.h>
  3. #include "hnfblock.h"
  4. #ifdef UNIX
  5. #include "unixstuff.h"
  6. #endif
  7. BOOL _GetToken(LPCWSTR *ppszCmdLine, LPWSTR szToken, UINT cchMax)
  8. {
  9.     LPCWSTR pszCmdLine = *ppszCmdLine;
  10.     WCHAR chTerm = L' ';
  11.     if (*pszCmdLine == L'"') {
  12.         chTerm = L'"';
  13.         pszCmdLine++;
  14.     }
  15.     UINT ichToken = 0;
  16.     WCHAR ch;
  17.     while((ch=*pszCmdLine) && (ch != chTerm)) {
  18.         if (ichToken < cchMax-1) {
  19.             szToken[ichToken++] = ch;
  20.         }
  21.         pszCmdLine++;
  22.     }
  23.     szToken[ichToken] = L'';
  24.     if (chTerm == L'"' && ch == L'"') {
  25.         pszCmdLine++;
  26.     }
  27.     // skip trailing spaces
  28.     while(*pszCmdLine == L' ')
  29.         pszCmdLine++;
  30.     *ppszCmdLine = pszCmdLine;
  31.     TraceMsgW(TF_SHDAUTO, "_GetToken returning %s (+%s)", szToken, pszCmdLine);
  32.     return szToken[0];
  33. }
  34. BOOL _CheckForOptionOnCmdLine(LPCWSTR *ppszCmdLine, LPCWSTR pszOption)
  35. {
  36.     LPCWSTR pszCmdLine = *ppszCmdLine;
  37.     int cch = lstrlenW(pszOption);
  38.     if (0 == StrCmpNIW(pszCmdLine, pszOption, cch))
  39.     {
  40.         pszCmdLine+= cch;
  41.         while(*pszCmdLine == L' ')
  42.             pszCmdLine++;
  43.         *ppszCmdLine = pszCmdLine;
  44.         return TRUE;
  45.     }
  46.     return FALSE;
  47. }
  48. BOOL IsCalleeIEAK()
  49. {
  50.     // BUGBUG: this is hack so as to allow IEAK CD install to continue without
  51.     // any security restrictions. If the IEAK CD install window name changes
  52.     // the name change should also reflect here.
  53.     return (FindWindow(TEXT("IECD"), NULL) != NULL);
  54. }
  55. BOOL SHParseIECommandLine(LPCWSTR *ppwszCmdLine, IETHREADPARAM * piei)
  56. {
  57.     ASSERT(ppwszCmdLine);
  58.     ASSERT(*ppwszCmdLine);
  59.     LPCWSTR pszCmdLine = *ppwszCmdLine;
  60. #ifdef UNIX
  61.     if( CheckForInvalidOptions( *ppwszCmdLine ) == FALSE )
  62.     {
  63.         piei->fShouldStart = FALSE;
  64.         return FALSE;
  65.     }
  66.     // Options valid.
  67.     piei->fShouldStart = TRUE;
  68. #endif
  69.     TraceMsg(TF_SHDAUTO, "ParseIECommandLine called with %s", pszCmdLine);
  70.     BOOL fDontLookForPidl = FALSE; // A flag option is set, so don't go looking for an open window 
  71.                                    // with the same pidl
  72.                                    // BUGBUG: (dli) what if there is a window opened with the same flags?
  73.     while (*pszCmdLine == L'-')
  74.     {
  75.         fDontLookForPidl = TRUE;
  76.         
  77.         //Note: (dli)These flags are supposed to be set to FALSE at initialization
  78.         // check if -nohome was passed in!
  79.         //
  80.         if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-slf") && !IsOS(OS_NT5) && IsCalleeIEAK())
  81.             piei->fNoLocalFileWarning = TRUE;
  82.         else if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-nohome"))
  83.             piei->fDontUseHomePage = TRUE;
  84.         else if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-k"))
  85.         {
  86.             piei->fFullScreen = TRUE;
  87.             piei->fNoDragDrop = TRUE;
  88.         }
  89.         else if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-embedding"))
  90.         {
  91.             piei->fAutomation = TRUE;
  92.             // if we're started as an embedding, we don't want to go to our start page
  93.             piei->fDontUseHomePage = TRUE;
  94.         } 
  95. #ifndef UNIX
  96.         else if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-channelband"))
  97.         {
  98.             piei->fDesktopChannel = TRUE;
  99.         } 
  100.         else if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-e")) 
  101.         {
  102.             piei->uFlags |= COF_EXPLORE;
  103.         } 
  104. #else
  105.         else if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-help"))
  106.         {
  107.             piei->fShouldStart = FALSE;
  108.             PrintIEHelp();
  109.             break;
  110.         } 
  111.         else if  (_CheckForOptionOnCmdLine(&pszCmdLine, L"-v") || 
  112.                   _CheckForOptionOnCmdLine(&pszCmdLine, L"-version")) 
  113.         {
  114.             piei->fShouldStart = FALSE;
  115.             PrintIEVersion();
  116.             break;
  117.         } 
  118. #endif
  119.         else if (_CheckForOptionOnCmdLine(&pszCmdLine, L"-root")) 
  120.         {
  121.             ASSERT(piei->pidlRoot==NULL);
  122.             WCHAR szRoot[MAX_PATH];
  123.             if (_GetToken(&pszCmdLine, szRoot, ARRAYSIZE(szRoot))) 
  124.             {
  125.                 CLSID clsid, *pclsid = NULL;
  126.                 
  127.                 TraceMsgW(TF_SHDAUTO, "ParseIECommandLine got token for /root %s", szRoot);
  128.                 if (GUIDFromString(szRoot, &clsid))
  129.                 {
  130.                     pclsid = &clsid;
  131.                     _GetToken(&pszCmdLine, szRoot, ARRAYSIZE(szRoot));
  132.                 }
  133.                 if (szRoot[0]) 
  134.                 {
  135.                     LPITEMIDLIST pidlRoot = ILCreateFromPathW(szRoot);
  136.                     if (pidlRoot) 
  137.                     {
  138.                         piei->pidl = ILRootedCreateIDList(pclsid, pidlRoot);
  139.                         ILFree(pidlRoot);
  140.                     } 
  141.                 }
  142.             }
  143.         }
  144.         else
  145.         {
  146. #ifdef UNIX
  147.             piei->fShouldStart = FALSE;
  148. #endif
  149.             // unknown option..
  150.             fDontLookForPidl = FALSE;
  151.             break;
  152.         }
  153.     }
  154.     *ppwszCmdLine = pszCmdLine;
  155.     
  156.     return fDontLookForPidl;
  157. }
  158. IETHREADPARAM* SHCreateIETHREADPARAM(LPCWSTR pszCmdLineIn, int nCmdShowIn, ITravelLog *ptlIn, IEFreeThreadedHandShake* piehsIn)
  159. {
  160.     IETHREADPARAM *piei = (IETHREADPARAM *)LocalAlloc(LPTR, sizeof(IETHREADPARAM));
  161.     if (piei)
  162.     {
  163.         piei->pszCmdLine = pszCmdLineIn;    // careful, aliased pointer
  164.         piei->nCmdShow = nCmdShowIn;
  165.         piei->ptl = ptlIn;
  166.         piei->piehs = piehsIn;
  167.         if (piehsIn)
  168.             piehsIn->AddRef();
  169.         if (ptlIn)
  170.             ptlIn->AddRef();
  171. #ifdef UNIX
  172.         piei->fShouldStart = TRUE;
  173. #endif
  174. #ifdef NO_MARSHALLING
  175.         piei->fOnIEThread = TRUE;
  176. #endif 
  177.     }
  178.     return piei;
  179. }
  180. IETHREADPARAM* SHCloneIETHREADPARAM(IETHREADPARAM* pieiIn)
  181. {
  182.     IETHREADPARAM *piei = (IETHREADPARAM *)LocalAlloc(LPTR, sizeof(IETHREADPARAM));
  183.     if (piei)
  184.     {
  185.         *piei = *pieiIn;
  186.         // convert aliased pointers into refs
  187.         if (piei->pidl)
  188.             piei->pidl = ILClone(piei->pidl);
  189.     
  190.         if (piei->pidlSelect)
  191.             piei->pidlSelect = ILClone(piei->pidlSelect);
  192.     
  193.         if (piei->pidlRoot)
  194.             piei->pidlRoot = ILClone(piei->pidlRoot);
  195.     
  196.         if (piei->psbCaller)
  197.             piei->psbCaller->AddRef();
  198.     
  199.         if (piei->ptl)
  200.             piei->ptl->Clone(&piei->ptl);
  201.     }
  202.     return piei;
  203. }
  204. void SHDestroyIETHREADPARAM(IETHREADPARAM* piei)
  205. {
  206.     if (piei)
  207.     {
  208.         if (piei->pidl)
  209.             ILFree(piei->pidl);
  210.     
  211.         if (piei->pidlSelect)
  212.             ILFree(piei->pidlSelect);
  213.     
  214.         if (((piei->uFlags & COF_HASHMONITOR) == 0) && piei->pidlRoot)
  215.             ILFree(piei->pidlRoot);
  216.     
  217.         if (piei->piehs)
  218.             piei->piehs->Release();   // note, this is not a COM object, don't ATOMICRELEASE();
  219.         ATOMICRELEASE(piei->psbCaller);
  220.         ATOMICRELEASE(piei->pSplash);
  221.         ATOMICRELEASE(piei->ptl);
  222.         ATOMICRELEASE(piei->punkRefProcess);
  223.         LocalFree(piei);
  224.     }
  225. }