Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.5 KiB

  1. #include "iexplore.h"
  2. #include "unixstuff.h"
  3. //
  4. // BOOL ConnectRemoteIE(LPTSTR pszCommandLine)
  5. //
  6. // This function will be called when -remote parameter is specified during the
  7. // invokation of IE. That's the same format as Netscape uses, see
  8. // http://home.netscape.com/newsref/std/x-remote.html.
  9. // For now, the only special action supported is openURL(URL), because we need
  10. // it for the NetShow. We just put it as the URL was specified as iexplorer
  11. // param. To be done - connection to the existent browser.
  12. // Returns TRUE if succeed to connect to the existent browser.
  13. //
  14. #define c_szSpace TEXT(' ')
  15. static BOOL IsOpenURL(LPCTSTR pszBeginCommand, LPCTSTR pszEndCommand, LPTSTR pszURL)
  16. {
  17. const TCHAR c_szOpenURL[] = TEXT("openURL");
  18. const TCHAR c_szLBracket = TEXT('(');
  19. const TCHAR c_szRBracket = TEXT(')');
  20. const TCHAR c_szSQuote = TEXT('\'');
  21. const TCHAR c_szDQuote = TEXT('\"');
  22. LPCTSTR pszBeginURL, pszEndURL;
  23. BOOL bRet = TRUE;
  24. // Skip the leading/trailing spaces.
  25. while (*pszBeginCommand == c_szSpace) pszBeginCommand++;
  26. while ((*pszEndCommand == c_szSpace) && (pszBeginCommand <= pszEndCommand))
  27. pszEndCommand--;
  28. // Now, parse the value and replace in the cmd line,
  29. // if there is openURL there. More formats later...
  30. if (StrCmpNI(pszBeginCommand, c_szOpenURL, lstrlen(c_szOpenURL)) ||
  31. (*pszEndCommand != c_szRBracket)) {
  32. pszBeginURL = pszBeginCommand;
  33. bRet = FALSE;
  34. pszEndURL = pszEndCommand;
  35. }
  36. else{
  37. pszBeginURL = pszBeginCommand+lstrlen(c_szOpenURL);
  38. while (*pszBeginURL == c_szSpace) pszBeginURL++;
  39. if ((*pszBeginURL != c_szLBracket) ||
  40. (pszBeginURL == pszEndCommand-1)) {
  41. pszURL[0] = '\0';
  42. return FALSE;
  43. }
  44. pszBeginURL++;
  45. pszEndURL = pszEndCommand-1;
  46. }
  47. // Skip the leading/trailing spaces.
  48. while (*pszBeginURL == c_szSpace) pszBeginURL++;
  49. while (*pszEndURL == c_szSpace) pszEndURL--;
  50. // Take off quotes.
  51. if (((*pszBeginURL == c_szSQuote) && (*pszEndURL == c_szSQuote)) ||
  52. ((*pszBeginURL == c_szDQuote) && (*pszEndURL == c_szDQuote))) {
  53. while (*pszBeginURL == c_szSpace) pszBeginURL++;
  54. while (*pszEndURL == c_szSpace) pszEndURL--;
  55. if (pszBeginURL >= pszEndURL) {
  56. pszURL[0] = '\0';
  57. return FALSE;
  58. }
  59. }
  60. StrCpyN(pszURL, pszBeginURL, (pszEndURL-pszBeginURL)/sizeof(TCHAR) +2);
  61. if (bRet)
  62. bRet = pszURL[0];
  63. return bRet;
  64. }
  65. static BOOL ConnectExistentIE(LPCTSTR pszURL, HINSTANCE hInstance)
  66. {
  67. HWND hwnd;
  68. if (hwnd = FindWindow(IEREMOTECLASS, NULL))
  69. {
  70. COPYDATASTRUCT cds;
  71. cds.dwData = IEREMOTE_CMDLINE;
  72. cds.cbData = pszURL ? (lstrlen(pszURL)+1)*sizeof(TCHAR) : 0;
  73. cds.lpData = pszURL;
  74. SetForegroundWindow(hwnd);
  75. SendMessage(hwnd, WM_COPYDATA, (WPARAM)WMC_DISPATCH, (LPARAM)&cds);
  76. ExitProcess(0);
  77. }
  78. return FALSE;
  79. }
  80. BOOL ConnectRemoteIE(LPTSTR pszCmdLine, HINSTANCE hInstance)
  81. {
  82. const TCHAR c_szDblQuote = TEXT('"');
  83. const TCHAR c_szQuote = TEXT('\'');
  84. LPTSTR pszBeginRemote, pszEndRemote;
  85. LPTSTR pszBeginCommand, pszEndCommand;
  86. TCHAR szURL[INTERNET_MAX_URL_LENGTH];
  87. TCHAR szRestCmdLine[INTERNET_MAX_URL_LENGTH * 2];
  88. // If we start with a quote, finish with a quote.
  89. // If we start with something else, finish 1 symbol before space
  90. // or end of string.
  91. pszBeginRemote = pszBeginCommand = pszCmdLine;
  92. if (*pszBeginCommand == c_szQuote || *pszBeginCommand == c_szDblQuote) {
  93. pszEndRemote = pszEndCommand = StrChr(pszBeginCommand+1, (WORD)(*pszBeginCommand));
  94. pszBeginCommand++;
  95. }
  96. else {
  97. pszEndCommand = StrChr(pszBeginCommand, (WORD)c_szSpace);
  98. if (pszEndCommand == NULL)
  99. pszEndCommand = pszBeginCommand+lstrlen(pszBeginCommand);
  100. pszEndRemote = pszEndCommand-1;
  101. }
  102. if ((pszEndCommand == NULL) || (lstrlen(pszBeginCommand) <= 1))
  103. return FALSE;
  104. pszEndCommand--;
  105. //
  106. // Now, check the remote command and execute.
  107. // For now, we just replace the URL in the cmd line,
  108. // if there is openURL there. More formats later...
  109. IsOpenURL(pszBeginCommand, pszEndCommand, szURL);
  110. if (ConnectExistentIE(szURL, hInstance))
  111. return TRUE;
  112. StrCpyN(szRestCmdLine, pszEndRemote+1, ARRAYSIZE(szRestCmdLine));
  113. *pszBeginRemote = '\0';
  114. StrCat(pszCmdLine, szURL);
  115. StrCat(pszCmdLine, szRestCmdLine);
  116. // No connection with an existent IE was done.
  117. return FALSE;
  118. }
  119. #if 0
  120. #define WMC_UNIX_NEWWINDOW (WM_USER + 0x0400)
  121. BOOL RemoteIENewWindow(LPTSTR pszCmdLine)
  122. {
  123. HWND hwnd;
  124. LPTSTR pszCurrent = pszCmdLine;
  125. while (*pszCurrent == TEXT(' '))
  126. pszCurrent++;
  127. if (*pszCurrent == TEXT('-'))
  128. return FALSE;
  129. if (hwnd = FindWindow(IEREMOTECLASS, NULL))
  130. {
  131. COPYDATASTRUCT cds;
  132. cds.dwData = IEREMOTE_CMDLINE;
  133. cds.cbData = pszCmdLine ? (lstrlen(pszCmdLine)+1)*sizeof(TCHAR) : 0;
  134. cds.lpData = pszCmdLine;
  135. SetForegroundWindow(hwnd);
  136. SendMessage(hwnd, WM_COPYDATA, (WPARAM)WMC_UNIX_NEWWINDOW, (LPARAM)&cds);
  137. printf("Opening a new window in the currently running Internet Explorer.\n");
  138. printf("To start a new instance of Internet Explorer, type \"iexplorer -new\".\n");
  139. return TRUE;
  140. }
  141. return FALSE;
  142. }
  143. #endif
  144. // Entry point for Mainwin is WinMain so create this function and call
  145. // ModuleEntry() from here.
  146. #if defined(MAINWIN)
  147. EXTERN_C int _stdcall ModuleEntry(void);
  148. EXTERN_C int WINAPI WinMain( HINSTANCE hinst, HINSTANCE hprev, LPSTR lpcmdline, int cmd )
  149. {
  150. return ModuleEntry ();
  151. }
  152. #endif