1
0

HTMLContainer2.cpp 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
  1. #include "./HTMLContainer2.h"
  2. #include "../winamp/wa_ipc.h"
  3. #include "CGlobalAtom.h"
  4. #include <exdisp.h>
  5. #include <mshtmdid.h>
  6. #include <mshtml.h>
  7. #include <exdispid.h>
  8. #include <urlmon.h>
  9. #include <Wininet.h>
  10. #include <shlwapi.h>
  11. #include <strsafe.h>
  12. #ifndef GetWindowStyle
  13. #define GetWindowStyle(__hwnd) ((UINT)GetWindowLongPtrW((__hwnd), GWL_STYLE))
  14. #endif //GetWindowStyle
  15. #ifndef GetWindowStyleEx
  16. #define GetWindowStyleEx(__hwnd) ((UINT)GetWindowLongPtrW((__hwnd), GWL_EXSTYLE))
  17. #endif // GetWindowStyleEx
  18. static UINT WM_REDIRECTNAVIGATE = 0;
  19. #ifndef DISPID_NEWWINDOW3
  20. #define DISPID_NEWWINDOW3 273
  21. #endif
  22. static CGlobalAtom WNDPROP_SCCTRLW(L"SCCTRL");
  23. static UINT WINAMP_WM_DIRECT_MOUSE_WHEEL = WM_NULL;
  24. #define REGISTRY_FEATURE_CONTROL L"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl"
  25. #define REGISTRY_FEATURE_USE_LEGACY_JSCRIPT (REGISTRY_FEATURE_CONTROL L"\\FEATURE_USE_LEGACY_JSCRIPT")
  26. #ifndef LONGX86
  27. #ifdef _WIN64
  28. #define LONGX86 LONG_PTR
  29. #else /*_WIN64*/
  30. #define LONGX86 LONG
  31. #endif /*_WIN64*/
  32. #endif // LONGX86
  33. #ifndef CSTR_INVARIANT
  34. #define CSTR_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)
  35. #endif //CSTR_INVARIANT
  36. #define IS_EQUALCLASS(__class1, __class2)\
  37. (CSTR_EQUAL == CompareStringW(CSTR_INVARIANT, NORM_IGNORECASE, __class1, -1, __class2, -1))
  38. #define DEFAULT_HOSTBKCOLOR 0x00FFFFFF
  39. #define DEFAULT_DOCHOSTUIFLAGS (DOCHOSTUIFLAG_NO3DOUTERBORDER | \
  40. DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION | \
  41. DOCHOSTUIFLAG_NO3DBORDER | \
  42. DOCHOSTUIDBLCLK_DEFAULT | \
  43. 0)
  44. #define DEFAULT_DOWNLOADFLAGS (DLCTL_DLIMAGES | \
  45. DLCTL_VIDEOS | \
  46. DLCTL_PRAGMA_NO_CACHE | \
  47. 0)
  48. #define CF_DISABLEBEFORENAVFILTER 0x00000002
  49. typedef struct __RMNAVIGATE2
  50. {
  51. VARIANT URL;
  52. VARIANT Flags;
  53. VARIANT TargetFrameName;
  54. VARIANT PostData;
  55. VARIANT Headers;
  56. }RMNAVIGATE2;
  57. typedef struct __RMNAVIGATETONAME
  58. {
  59. BSTR url;
  60. UINT flags;
  61. } RMNAVIGATETONAME;
  62. typedef struct _IECURSOR
  63. {
  64. INT nSysId;
  65. HCURSOR hSys;
  66. HCURSOR hUser;
  67. } IECURSOR;
  68. static INT bIsVistaOrHigher = -1;
  69. typedef struct __LIBHDR LIBHDR;
  70. typedef BOOL (WINAPI *LIBRARYLOADER)(LIBHDR* /*header*/);
  71. typedef struct __LIBHDR
  72. {
  73. HMODULE hMod;
  74. LPCWSTR name;
  75. LIBRARYLOADER loader;
  76. size_t size;
  77. } LIBHDR;
  78. typedef struct __LIBWININET
  79. {
  80. LIBHDR hdr;
  81. typedef BOOL (WINAPI *INTERNETCRACKURL)(LPCWSTR /*lpszUrl*/, DWORD /*dwUrlLength*/, DWORD /*dwFlags*/, URL_COMPONENTSW* /*lpUrlComponents*/);
  82. INTERNETCRACKURL InternetCrackUrl;
  83. static BOOL CALLBACK Loader(LIBHDR *pHdr)
  84. {
  85. LIBWININET *lib = (LIBWININET*)pHdr;
  86. lib->InternetCrackUrl = (LIBWININET::INTERNETCRACKURL)GetProcAddress(pHdr->hMod, "InternetCrackUrlW");
  87. return TRUE;
  88. }
  89. } LIBWININET;
  90. typedef struct __LIBURLMON
  91. {
  92. LIBHDR hdr;
  93. typedef HRESULT (WINAPI *COINTERNETSETFEATUREENABLED)(INTERNETFEATURELIST /*FeatureEntry*/, DWORD /*dwFlags*/, BOOL /*fEnable*/);
  94. typedef HRESULT (WINAPI *COINTERNETISFEATUREENABLED)(INTERNETFEATURELIST /*FeatureEntry*/, DWORD /*dwFlags*/);
  95. COINTERNETSETFEATUREENABLED CoInternetSetFeatureEnabled;
  96. COINTERNETISFEATUREENABLED CoInternetIsFeatureEnabled;
  97. static BOOL CALLBACK Loader(LIBHDR *pHdr)
  98. {
  99. LIBURLMON *lib = (LIBURLMON*)pHdr;
  100. lib->CoInternetSetFeatureEnabled = (LIBURLMON::COINTERNETSETFEATUREENABLED)GetProcAddress(pHdr->hMod, "CoInternetSetFeatureEnabled");
  101. lib->CoInternetIsFeatureEnabled = (LIBURLMON::COINTERNETISFEATUREENABLED)GetProcAddress(pHdr->hMod, "CoInternetIsFeatureEnabled");
  102. return TRUE;
  103. }
  104. } LIBURLMON;
  105. static LIBWININET libWininet = { { NULL, L"WinInet.dll", LIBWININET::Loader, sizeof(LIBWININET)}, NULL, };
  106. static LIBURLMON libUrlmon = { { NULL, L"UrlMon.dll", LIBURLMON::Loader, sizeof(LIBURLMON)}, NULL, };
  107. static LIBHDR* szLibrary[] = { (LIBHDR*)&libWininet, (LIBHDR*)&libUrlmon };
  108. BOOL HTMLContainer2_Initialize()
  109. {
  110. for(size_t i = 0; i < ARRAYSIZE(szLibrary); i++)
  111. {
  112. if (NULL == szLibrary[i]->hMod)
  113. {
  114. size_t size = szLibrary[i]->size - sizeof(LIBHDR);
  115. ZeroMemory((BYTE*)szLibrary[i] + sizeof(LIBHDR), size);
  116. }
  117. }
  118. return TRUE;
  119. }
  120. BOOL HTMLContainer2_Uninitialize()
  121. {
  122. for(size_t i = 0; i < ARRAYSIZE(szLibrary); i++)
  123. {
  124. if (NULL != szLibrary[i]->hMod)
  125. {
  126. FreeLibrary(szLibrary[i]->hMod);
  127. szLibrary[i]->hMod = NULL;
  128. }
  129. size_t size = szLibrary[i]->size - sizeof(LIBHDR);
  130. ZeroMemory((BYTE*)szLibrary[i] + sizeof(LIBHDR), size);
  131. }
  132. return TRUE;
  133. }
  134. BOOL HTMLContainer2_LoadLibray(LIBHDR *libraryHeader)
  135. {
  136. if (NULL == libraryHeader)
  137. return FALSE;
  138. if (NULL != libraryHeader->hMod)
  139. return TRUE;
  140. libraryHeader->hMod = LoadLibraryW(libraryHeader->name);
  141. if (NULL == libraryHeader->hMod)
  142. return FALSE;
  143. return (NULL != libraryHeader->loader) ?
  144. libraryHeader->loader(libraryHeader) :
  145. TRUE;
  146. }
  147. static BOOL SublassControl_IsAttached(HWND hwnd);
  148. static BOOL SubclassControl_Attach(HWND hControl, HTMLContainer2 *pContainer);
  149. // uncomment if you ever want to use mozilla instead of IE
  150. // change the CLSID_WebBrowser in the constructor below to CLSID_MozillaBrowser
  151. // but window.external from javascript doesn't work :(
  152. static const CLSID CLSID_MozillaBrowser=
  153. { 0x1339B54C, 0x3453, 0x11D2, { 0x93, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
  154. HTMLContainer2::HTMLContainer2(HWND waWindow, HWND hwndParent) :
  155. ref(1), pUnk(NULL), hParent(hwndParent), dwCookie(0),
  156. dwFlags(0), fnBrwoserCB(NULL) ,userData(NULL),
  157. bNavigating(FALSE), hCursors(NULL), nCursors(0),
  158. ensureChakraLoaded(TRUE), winampWindow(waWindow)
  159. {
  160. if (NULL == hParent || FALSE == GetClientRect(hParent, &rect))
  161. SetRectEmpty(&rect);
  162. if (-1 == bIsVistaOrHigher)
  163. {
  164. OSVERSIONINFO os;
  165. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  166. bIsVistaOrHigher = (GetVersionEx(&os) && os.dwMajorVersion >= 6);
  167. }
  168. }
  169. HTMLContainer2::~HTMLContainer2(void)
  170. {
  171. if (NULL != fnBrwoserCB)
  172. fnBrwoserCB(this, DISPID_DESTRUCTOR, NULL, userData);
  173. if (hCursors)
  174. {
  175. HCURSOR hc;
  176. for(int i = 0; i < nCursors; i++)
  177. {
  178. hc = ((IECURSOR*)hCursors)[i].hUser;
  179. if (hc) DestroyCursor(hc);
  180. }
  181. free(hCursors);
  182. }
  183. }
  184. STDMETHODIMP HTMLContainer2::Initialize(void)
  185. {
  186. IOleObject *pioo = NULL;
  187. IConnectionPoint *pcp = NULL;
  188. IConnectionPointContainer *pcpc = NULL;
  189. HRESULT hr = CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC, IID_IUnknown, (PVOID*)&pUnk);
  190. if (FAILED(hr))
  191. return hr;
  192. hr = pUnk->QueryInterface(IID_IOleObject, (PVOID*)&pioo);
  193. if (SUCCEEDED(hr))
  194. {
  195. DWORD dwFlags = 0;
  196. if (FAILED(pioo->GetMiscStatus(DVASPECT_CONTENT, &dwFlags)))
  197. dwFlags = 0;
  198. if (0 != (OLEMISC_SETCLIENTSITEFIRST & dwFlags))
  199. {
  200. IOleClientSite *pClientSite = NULL;
  201. hr = QueryInterface(IID_IOleClientSite, (void**)&pClientSite);
  202. if (SUCCEEDED(hr))
  203. {
  204. pioo->SetClientSite(pClientSite);
  205. pioo->SetHostNames(L"NullsoftHtmlContainer2", NULL);
  206. if(NULL == hParent || FALSE == GetClientRect(hParent, &rect))
  207. SetRectEmpty(&rect);
  208. pioo->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pClientSite, 0, hParent, &rect);
  209. pClientSite->Release();
  210. }
  211. }
  212. pioo->Release();
  213. HWND hHost = GetHostHWND();
  214. if (IsWindow(hHost))
  215. {
  216. SubclassControl_Attach(hHost, this);
  217. }
  218. }
  219. if (FAILED(hr)) return hr;
  220. hr = pUnk->QueryInterface(IID_IConnectionPointContainer, (PVOID*)&pcpc);
  221. if (SUCCEEDED (hr))
  222. {
  223. hr = pcpc->FindConnectionPoint(DIID_DWebBrowserEvents2, &pcp);
  224. if (SUCCEEDED(hr))
  225. {
  226. hr = pcp->Advise(static_cast<IDispatch*>(this), &dwCookie);
  227. if (FAILED(hr)) dwCookie = 0;
  228. pcp->Release();
  229. }
  230. pcpc->Release();
  231. }
  232. return hr;
  233. }
  234. STDMETHODIMP HTMLContainer2::Finish(void)
  235. {
  236. if (!pUnk) return S_OK;
  237. AddRef();
  238. UnadviseBrowserEvents();
  239. IOleObject *pioo = NULL;
  240. IOleInPlaceObject *pipo = NULL;
  241. HRESULT hr = pUnk->QueryInterface(IID_IOleInPlaceObject, (PVOID*)&pipo);
  242. if (SUCCEEDED(hr))
  243. {
  244. pipo->InPlaceDeactivate();
  245. pipo->UIDeactivate();
  246. pipo->Release();
  247. }
  248. hr = pUnk->QueryInterface(IID_IOleObject, (PVOID*)&pioo);
  249. if (SUCCEEDED(hr))
  250. {
  251. pioo->Close(OLECLOSE_NOSAVE);
  252. pioo->SetClientSite(NULL);
  253. pioo->Release();
  254. }
  255. ULONG r = pUnk->Release();
  256. pUnk = NULL;
  257. Release();
  258. return hr;
  259. }
  260. STDMETHODIMP HTMLContainer2::QueryInterface(REFIID riid, PVOID *ppvObject)
  261. {
  262. if (!ppvObject)
  263. return E_POINTER;
  264. if (IsEqualIID(riid, IID_IOleClientSite))
  265. *ppvObject = (IOleClientSite*)this;
  266. else if (IsEqualIID(riid, IID_IOleInPlaceSite))
  267. *ppvObject = (IOleInPlaceSite*)this;
  268. else if (IsEqualIID(riid, IID_IOleInPlaceFrame))
  269. *ppvObject = (IOleInPlaceFrame*)this;
  270. else if (IsEqualIID(riid, IID_IOleInPlaceUIWindow))
  271. *ppvObject = (IOleInPlaceUIWindow*)this;
  272. else if (IsEqualIID(riid, IID_IOleControlSite))
  273. *ppvObject = (IOleControlSite*)this;
  274. else if (IsEqualIID(riid, IID_IOleWindow))
  275. *ppvObject = reinterpret_cast<IOleWindow*>(this);
  276. else if (IsEqualIID(riid, IID_IDispatch))
  277. *ppvObject = (IDispatch*)this;
  278. else if (IsEqualIID(riid, IID_IUnknown))
  279. *ppvObject = reinterpret_cast<IUnknown*>(this);
  280. else if (IsEqualIID(riid, IID_IDocHostUIHandler))
  281. *ppvObject = (IDocHostUIHandler*)this;
  282. else if (IsEqualIID(riid, IID_IDocHostUIHandler2))
  283. *ppvObject = (IDocHostUIHandler2*)this;
  284. else if (IsEqualIID(riid, IID_IDocHostShowUI))
  285. *ppvObject = (IDocHostShowUI*)this;
  286. else if (IsEqualIID(riid, IID_IOleCommandTarget))
  287. *ppvObject = (IOleCommandTarget*)this;
  288. else if (IsEqualIID(riid, IID_IServiceProvider))
  289. *ppvObject = (IServiceProvider*)this;
  290. else
  291. {
  292. *ppvObject = NULL;
  293. return E_NOINTERFACE;
  294. }
  295. AddRef();
  296. return S_OK;
  297. }
  298. ULONG HTMLContainer2::AddRef(void)
  299. {
  300. return InterlockedIncrement(&ref);
  301. }
  302. ULONG HTMLContainer2::Release(void)
  303. {
  304. if (0 == ref)
  305. return ref;
  306. LONG r = InterlockedDecrement(&ref);
  307. if (0 == r)
  308. delete(this);
  309. return r;
  310. }
  311. STDMETHODIMP HTMLContainer2::SaveObject()
  312. {
  313. return E_NOTIMPL;
  314. }
  315. STDMETHODIMP HTMLContainer2::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER * ppMk)
  316. {
  317. *ppMk = NULL;
  318. return E_NOTIMPL;
  319. }
  320. STDMETHODIMP HTMLContainer2::GetContainer(LPOLECONTAINER * ppContainer)
  321. {
  322. *ppContainer = NULL;
  323. return E_NOINTERFACE;
  324. }
  325. STDMETHODIMP HTMLContainer2::ShowObject()
  326. {
  327. return S_OK;
  328. }
  329. STDMETHODIMP HTMLContainer2::OnShowWindow(BOOL fShow)
  330. {
  331. return E_NOTIMPL;
  332. }
  333. STDMETHODIMP HTMLContainer2::RequestNewObjectLayout()
  334. {
  335. return E_NOTIMPL;
  336. }
  337. STDMETHODIMP HTMLContainer2::GetWindow(HWND * lphwnd)
  338. {
  339. if (NULL != hParent && IsWindow(hParent))
  340. {
  341. *lphwnd = hParent;
  342. return S_OK;
  343. }
  344. else
  345. {
  346. *lphwnd = NULL;
  347. return E_FAIL;
  348. }
  349. }
  350. STDMETHODIMP HTMLContainer2::ContextSensitiveHelp(BOOL fEnterMode)
  351. {
  352. return E_NOTIMPL;
  353. }
  354. STDMETHODIMP HTMLContainer2::CanInPlaceActivate(void)
  355. {
  356. return S_OK;
  357. }
  358. STDMETHODIMP HTMLContainer2::OnInPlaceActivate(void)
  359. {
  360. return S_OK;
  361. }
  362. STDMETHODIMP HTMLContainer2::OnUIActivate(void)
  363. {
  364. return S_OK;
  365. }
  366. STDMETHODIMP HTMLContainer2::GetWindowContext(IOleInPlaceFrame ** ppFrame, IOleInPlaceUIWindow ** ppIIPUIWin,
  367. LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  368. {
  369. if (FAILED(QueryInterface(IID_IOleInPlaceFrame, (void**)ppFrame)))
  370. *ppFrame = NULL;
  371. *ppIIPUIWin = NULL;
  372. CopyRect(lprcPosRect, &rect);
  373. CopyRect(lprcClipRect, &rect);
  374. lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
  375. lpFrameInfo->fMDIApp = FALSE;
  376. lpFrameInfo->hwndFrame = hParent;
  377. lpFrameInfo->haccel = NULL;
  378. lpFrameInfo->cAccelEntries = 0;
  379. return S_OK;
  380. }
  381. STDMETHODIMP HTMLContainer2::Scroll(SIZE scrollExtent)
  382. {
  383. return E_NOTIMPL;
  384. }
  385. STDMETHODIMP HTMLContainer2::OnUIDeactivate(BOOL fUndoable)
  386. {
  387. return S_OK;
  388. }
  389. STDMETHODIMP HTMLContainer2::OnInPlaceDeactivate(void)
  390. {
  391. return S_OK;
  392. }
  393. STDMETHODIMP HTMLContainer2::DiscardUndoState(void)
  394. {
  395. return E_NOTIMPL;
  396. }
  397. STDMETHODIMP HTMLContainer2::DeactivateAndUndo(void)
  398. {
  399. return E_NOTIMPL;
  400. }
  401. STDMETHODIMP HTMLContainer2::OnPosRectChange(LPCRECT lprcPosRect)
  402. {
  403. return S_OK;
  404. }
  405. STDMETHODIMP HTMLContainer2::InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
  406. {
  407. return E_NOTIMPL;
  408. }
  409. STDMETHODIMP HTMLContainer2::SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
  410. {
  411. return E_NOTIMPL;
  412. }
  413. STDMETHODIMP HTMLContainer2::RemoveMenus(HMENU hmenuShared)
  414. {
  415. return E_NOTIMPL;
  416. }
  417. STDMETHODIMP HTMLContainer2::SetStatusText(LPCOLESTR pszStatusText)
  418. {
  419. return S_OK;
  420. }
  421. STDMETHODIMP HTMLContainer2::TranslateAccelerator(LPMSG lpmsg, WORD wID)
  422. {
  423. return S_OK;
  424. }
  425. STDMETHODIMP HTMLContainer2::EnableModeless(BOOL fEnable)
  426. {
  427. return E_NOTIMPL;
  428. }
  429. STDMETHODIMP HTMLContainer2::OnControlInfoChanged()
  430. {
  431. return E_NOTIMPL;
  432. }
  433. STDMETHODIMP HTMLContainer2::LockInPlaceActive(BOOL fLock)
  434. {
  435. return E_NOTIMPL;
  436. }
  437. STDMETHODIMP HTMLContainer2::GetExtendedControl(IDispatch **ppDisp)
  438. {
  439. if (ppDisp == NULL)
  440. return E_INVALIDARG;
  441. *ppDisp = (IDispatch *)this;
  442. (*ppDisp)->AddRef();
  443. return S_OK;
  444. }
  445. STDMETHODIMP HTMLContainer2::TransformCoords(POINTL *pptlHimetric, POINTF *pptfContainer, DWORD dwFlags)
  446. {
  447. return E_NOTIMPL;
  448. }
  449. STDMETHODIMP HTMLContainer2::TranslateAccelerator(LPMSG pMsg, DWORD grfModifiers)
  450. {
  451. return S_FALSE;
  452. }
  453. STDMETHODIMP HTMLContainer2::OnFocus(BOOL fGotFocus)
  454. {
  455. return S_OK;
  456. }
  457. STDMETHODIMP HTMLContainer2::ShowPropertyFrame(void)
  458. {
  459. return E_NOTIMPL;
  460. }
  461. STDMETHODIMP HTMLContainer2::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  462. {
  463. *rgdispid = DISPID_UNKNOWN;
  464. return DISP_E_UNKNOWNNAME;
  465. }
  466. STDMETHODIMP HTMLContainer2::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  467. {
  468. return E_NOTIMPL;
  469. }
  470. STDMETHODIMP HTMLContainer2::GetTypeInfoCount(unsigned int FAR * pctinfo)
  471. {
  472. return E_NOTIMPL;
  473. }
  474. static HRESULT HTMLContainer2_OnShowUiElementHelper(HTMLContainer2 *instance, UINT elementId, DISPPARAMS *pDispParams)
  475. {
  476. if (NULL == pDispParams) return E_UNEXPECTED;
  477. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  478. if (VT_BOOL != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  479. instance->OnShowUiElement(elementId, pDispParams->rgvarg[0].boolVal);
  480. return S_OK;
  481. }
  482. STDMETHODIMP HTMLContainer2::Invoke(DISPID dispId, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pDispParams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  483. {
  484. if (fnBrwoserCB && fnBrwoserCB(this, dispId, pDispParams, userData))
  485. {
  486. return DISP_E_MEMBERNOTFOUND;
  487. }
  488. switch (dispId)
  489. {
  490. case DISPID_BEFORENAVIGATE2:
  491. if(7 == pDispParams->cArgs)
  492. {
  493. OnBeforeNavigate(pDispParams->rgvarg[6].pdispVal, pDispParams->rgvarg[5].pvarVal,
  494. pDispParams->rgvarg[4].pvarVal, pDispParams->rgvarg[3].pvarVal,
  495. pDispParams->rgvarg[2].pvarVal, pDispParams->rgvarg[1].pvarVal,
  496. pDispParams->rgvarg[0].pboolVal);
  497. return S_OK;
  498. }
  499. break;
  500. case DISPID_NAVIGATEERROR:
  501. if (200 == pDispParams->rgvarg[1].pvarVal->lVal)
  502. {
  503. *pDispParams->rgvarg[0].pboolVal = VARIANT_TRUE;
  504. }
  505. if (5 == pDispParams->cArgs)
  506. {
  507. OnNavigateError(pDispParams->rgvarg[4].pdispVal, pDispParams->rgvarg[3].pvarVal,
  508. pDispParams->rgvarg[2].pvarVal, pDispParams->rgvarg[1].pvarVal,
  509. pDispParams->rgvarg[0].pboolVal);
  510. return S_OK;
  511. }
  512. break;
  513. case DISPID_NAVIGATECOMPLETE2:
  514. if (2 == pDispParams->cArgs)
  515. {
  516. OnNavigateComplete(pDispParams->rgvarg[1].pdispVal, pDispParams->rgvarg[0].pvarVal);
  517. return S_OK;
  518. }
  519. break;
  520. case DISPID_DOCUMENTCOMPLETE:
  521. if (2 == pDispParams->cArgs)
  522. {
  523. OnDocumentComplete(pDispParams->rgvarg[1].pdispVal, pDispParams->rgvarg[0].pvarVal);
  524. }
  525. if (NULL != pUnk)
  526. {
  527. IWebBrowser2 *pWeb1 = NULL, *pWeb2 = NULL;
  528. if (FAILED(GetIWebBrowser2(&pWeb1)))
  529. pWeb1 = NULL;
  530. if (pDispParams->cArgs < 2 ||
  531. NULL == pDispParams->rgvarg[1].pdispVal ||
  532. FAILED(pDispParams->rgvarg[1].pdispVal->QueryInterface(IID_IWebBrowser2, (void**)&pWeb2)))
  533. {
  534. pWeb2 = NULL;
  535. }
  536. if (NULL != pWeb1) pWeb1->Release();
  537. if (NULL != pWeb2) pWeb2->Release();
  538. if (NULL != pWeb1 && pWeb1 == pWeb2)
  539. OnDocumentReady(pDispParams->rgvarg[1].pdispVal, pDispParams->rgvarg[0].pvarVal);
  540. }
  541. return S_OK;
  542. case DISPID_DOWNLOADBEGIN:
  543. OnDownloadBegin();
  544. return S_OK;
  545. case DISPID_DOWNLOADCOMPLETE:
  546. OnDownloadComplete();
  547. return S_OK;
  548. case DISPID_FILEDOWNLOAD:
  549. if (2 == pDispParams->cArgs)
  550. {
  551. OnFileDownload(pDispParams->rgvarg[1].pboolVal, pDispParams->rgvarg[0].pboolVal);
  552. return S_OK;
  553. }
  554. break;
  555. case DISPID_NEWWINDOW2:
  556. if (2 == pDispParams->cArgs)
  557. {
  558. OnNewWindow2(pDispParams->rgvarg[1].ppdispVal, pDispParams->rgvarg[0].pboolVal);
  559. return S_OK;
  560. }
  561. break;
  562. case DISPID_NEWWINDOW3:
  563. if (5 != pDispParams->cArgs)
  564. return DISP_E_BADPARAMCOUNT;
  565. if ((VT_DISPATCH | VT_BYREF) != pDispParams->rgvarg[4].vt ||
  566. (VT_BOOL | VT_BYREF) != pDispParams->rgvarg[3].vt ||
  567. VT_I4 != pDispParams->rgvarg[2].vt ||
  568. VT_BSTR != pDispParams->rgvarg[1].vt ||
  569. VT_BSTR != pDispParams->rgvarg[0].vt)
  570. {
  571. return DISP_E_BADVARTYPE;
  572. }
  573. OnNewWindow3(pDispParams->rgvarg[4].ppdispVal, pDispParams->rgvarg[3].pboolVal,
  574. pDispParams->rgvarg[2].intVal, pDispParams->rgvarg[1].bstrVal, pDispParams->rgvarg[0].bstrVal);
  575. return S_OK;
  576. case DISPID_PROGRESSCHANGE:
  577. if (2 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  578. if (VT_I4 != pDispParams->rgvarg[1].vt ||
  579. VT_I4 != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  580. OnProgressChange(pDispParams->rgvarg[1].lVal, pDispParams->rgvarg[0].lVal);
  581. return S_OK;
  582. case DISPID_STATUSTEXTCHANGE:
  583. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  584. if (VT_BSTR != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  585. OnStatusTextChange(pDispParams->rgvarg[0].bstrVal);
  586. return S_OK;
  587. case DISPID_AMBIENT_USERAGENT:
  588. pvarResult->vt = VT_BSTR;
  589. pvarResult->bstrVal = SysAllocString(OnGetUserAgent());
  590. if (NULL != pvarResult->bstrVal)
  591. return S_OK;
  592. break;
  593. case DISPID_AMBIENT_DLCONTROL:
  594. pvarResult->vt = VT_I4;
  595. pvarResult->lVal = OnGetDownlodFlags();
  596. return S_OK;
  597. case DISPID_COMMANDSTATECHANGE:
  598. if (2 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  599. if (VT_I4 != pDispParams->rgvarg[1].vt ||
  600. VT_BOOL != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  601. OnCommandStateChange(pDispParams->rgvarg[1].lVal, pDispParams->rgvarg[0].boolVal);
  602. return S_OK;
  603. case DISPID_SETSECURELOCKICON:
  604. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  605. if (VT_I4 != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  606. OnSetSecureLockIcon(pDispParams->rgvarg[0].lVal);
  607. return S_OK;
  608. case DISPID_TITLECHANGE:
  609. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  610. if (VT_BSTR != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  611. OnTitleChange(pDispParams->rgvarg[0].bstrVal);
  612. return S_OK;
  613. case DISPID_ONVISIBLE:
  614. if(1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  615. if (VT_BOOL != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  616. OnVisibleChange(pDispParams->rgvarg[0].boolVal);
  617. return S_OK;
  618. case DISPID_WINDOWCLOSING:
  619. if (2 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  620. if (VT_BOOL != pDispParams->rgvarg[1].vt ||
  621. (VT_BOOL|VT_BYREF) != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  622. OnWindowClosing(pDispParams->rgvarg[1].boolVal, pDispParams->rgvarg[0].pboolVal);
  623. return S_OK;
  624. case DISPID_ONTOOLBAR: return HTMLContainer2_OnShowUiElementHelper(this, uiToolbar, pDispParams);
  625. case DISPID_ONMENUBAR: return HTMLContainer2_OnShowUiElementHelper(this, uiMenubar, pDispParams);
  626. case DISPID_ONSTATUSBAR: return HTMLContainer2_OnShowUiElementHelper(this, uiStatusbar, pDispParams);
  627. case DISPID_ONADDRESSBAR: return HTMLContainer2_OnShowUiElementHelper(this, uiAddressbar, pDispParams);
  628. case DISPID_ONFULLSCREEN:
  629. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  630. if (VT_BOOL != pDispParams->rgvarg[0].vt) DISP_E_BADVARTYPE;
  631. OnEnableFullscreen(pDispParams->rgvarg[0].boolVal);
  632. return S_OK;
  633. case DISPID_WINDOWSETRESIZABLE:
  634. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  635. if (VT_BOOL != pDispParams->rgvarg[0].vt) DISP_E_BADVARTYPE;
  636. OnWindowSetResizable(pDispParams->rgvarg[0].boolVal);
  637. return S_OK;
  638. case DISPID_CLIENTTOHOSTWINDOW:
  639. if (2 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  640. if ((VT_BYREF|VT_I4) != pDispParams->rgvarg[1].vt ||
  641. (VT_BYREF|VT_I4) != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  642. OnClientToHostWindow(pDispParams->rgvarg[1].plVal, pDispParams->rgvarg[0].plVal);
  643. return S_OK;
  644. case DISPID_WINDOWSETLEFT:
  645. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  646. if (VT_I4 != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  647. OnSetWindowPos(wndLeft, pDispParams->rgvarg[0].lVal, 0, 0, 0);
  648. return S_OK;
  649. case DISPID_WINDOWSETTOP:
  650. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  651. if (VT_I4 != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  652. OnSetWindowPos(wndTop, 0, pDispParams->rgvarg[0].lVal, 0, 0);
  653. return S_OK;
  654. case DISPID_WINDOWSETWIDTH:
  655. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  656. if (VT_I4 != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  657. OnSetWindowPos(wndWidth, 0, 0, pDispParams->rgvarg[0].lVal, 0);
  658. return S_OK;
  659. case DISPID_WINDOWSETHEIGHT:
  660. if (1 != pDispParams->cArgs) return DISP_E_BADPARAMCOUNT;
  661. if (VT_I4 != pDispParams->rgvarg[0].vt) return DISP_E_BADVARTYPE;
  662. OnSetWindowPos(wndHeight, 0, 0, 0, pDispParams->rgvarg[0].lVal);
  663. return S_OK;
  664. }
  665. return DISP_E_MEMBERNOTFOUND;
  666. }
  667. STDMETHODIMP HTMLContainer2::SetLocation(int x, int y, int width, int height)
  668. {
  669. if (!pUnk) return E_NOINTERFACE;
  670. SetRect(&rect, x, y, x + width, y + height);
  671. IOleInPlaceObject *pipo = NULL;
  672. HRESULT hr = pUnk->QueryInterface(IID_IOleInPlaceObject, (PVOID*)&pipo);
  673. if (SUCCEEDED(hr))
  674. {
  675. hr = pipo->SetObjectRects(&rect, &rect);
  676. pipo->Release();
  677. }
  678. return hr;
  679. }
  680. STDMETHODIMP HTMLContainer2::GetBorder(LPRECT lprectBorder)
  681. {
  682. return E_NOTIMPL;
  683. }
  684. STDMETHODIMP HTMLContainer2::RequestBorderSpace(LPCBORDERWIDTHS lpborderwidths)
  685. {
  686. return E_NOTIMPL;
  687. }
  688. STDMETHODIMP HTMLContainer2::SetBorderSpace(LPCBORDERWIDTHS lpborderwidths)
  689. {
  690. return E_NOTIMPL;
  691. }
  692. STDMETHODIMP HTMLContainer2::SetActiveObject(IOleInPlaceActiveObject * pActiveObject, LPCOLESTR lpszObjName)
  693. {
  694. return E_NOTIMPL;
  695. }
  696. STDMETHODIMP HTMLContainer2::SetFocus(BOOL fFocused)
  697. {
  698. if (NULL == pUnk)
  699. return E_NOINTERFACE;
  700. if (FALSE != fFocused)
  701. {
  702. IOleObject *pioo = NULL;
  703. if (SUCCEEDED(pUnk->QueryInterface(IID_IOleObject, (PVOID*)&pioo)))
  704. {
  705. pioo->DoVerb(OLEIVERB_UIACTIVATE, NULL, this, 0, hParent, &rect);
  706. pioo->Release();
  707. }
  708. }
  709. else
  710. {
  711. IOleInPlaceObject *pipo = NULL;
  712. if (SUCCEEDED(pUnk->QueryInterface(IID_IOleInPlaceObject, (void**)&pipo)))
  713. {
  714. pipo->UIDeactivate();
  715. pipo->Release();
  716. }
  717. }
  718. return S_OK;
  719. }
  720. BOOL HTMLContainer2::TranslateKey(LPMSG pMsg)
  721. {
  722. if (!pUnk) return FALSE;
  723. IOleInPlaceActiveObject *pao = NULL;
  724. HRESULT hr = pUnk->QueryInterface(IID_IOleInPlaceActiveObject, (PVOID*)&pao);
  725. if (SUCCEEDED(hr))
  726. {
  727. hr = pao->TranslateAccelerator(pMsg);
  728. pao->Release();
  729. }
  730. return (S_OK == hr);
  731. }
  732. STDMETHODIMP HTMLContainer2::ShowHelp(HWND hwnd, LPOLESTR pszHelpFile, UINT uCommand, DWORD dwData, POINT ptMouse, IDispatch *pDispatchObjectHit)
  733. {
  734. return S_FALSE;
  735. }
  736. STDMETHODIMP HTMLContainer2::ShowMessage(HWND hwnd, LPOLESTR lpstrText, LPOLESTR lpstrCaption, DWORD dwType, LPOLESTR lpstrHelpFile, DWORD dwHelpContext, LRESULT *plResult)
  737. {
  738. return S_FALSE;
  739. }
  740. // ***********************************************************************
  741. // IDocHostUIHandler
  742. // ***********************************************************************
  743. STDMETHODIMP HTMLContainer2::ShowContextMenu(DWORD dwID, POINT __RPC_FAR *ppt, IUnknown __RPC_FAR *pcmdtReserved, IDispatch __RPC_FAR *pdispReserved)
  744. {
  745. return S_FALSE;
  746. }
  747. STDMETHODIMP HTMLContainer2::GetHostInfo(DOCHOSTUIINFO __RPC_FAR *pInfo)
  748. {
  749. pInfo->cbSize = sizeof(DOCHOSTUIINFO);
  750. pInfo->dwFlags = OnGetHostInfoFlags();
  751. pInfo->pchHostCss = OnGetHostCSS();
  752. pInfo->pchHostNS = OnGetHostNamespace();
  753. return S_OK;
  754. }
  755. STDMETHODIMP HTMLContainer2::ShowUI(DWORD dwID, IOleInPlaceActiveObject __RPC_FAR *pActiveObject, IOleCommandTarget __RPC_FAR *pCommandTarget, IOleInPlaceFrame __RPC_FAR *pFrame, IOleInPlaceUIWindow __RPC_FAR *pDoc)
  756. {
  757. return S_FALSE;
  758. }
  759. STDMETHODIMP HTMLContainer2::HideUI(void)
  760. {
  761. return E_NOTIMPL;
  762. }
  763. STDMETHODIMP HTMLContainer2::UpdateUI(void)
  764. {
  765. return E_NOTIMPL;
  766. }
  767. STDMETHODIMP HTMLContainer2::OnDocWindowActivate(BOOL fActivate)
  768. {
  769. return E_NOTIMPL;
  770. }
  771. STDMETHODIMP HTMLContainer2::OnFrameWindowActivate(BOOL fActivate)
  772. {
  773. return E_NOTIMPL;
  774. }
  775. STDMETHODIMP HTMLContainer2::ResizeBorder(LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR *pUIWindow, BOOL fRameWindow)
  776. {
  777. return E_NOTIMPL;
  778. }
  779. STDMETHODIMP HTMLContainer2::TranslateAccelerator(LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID)
  780. {
  781. if ((0x8000 & GetAsyncKeyState(VK_MENU)) || (0x8000 & GetAsyncKeyState(VK_CONTROL)))
  782. {
  783. if (NULL != hParent && IsWindow(hParent) &&
  784. PostMessageW(hParent, lpMsg->message, lpMsg->wParam, lpMsg->lParam))
  785. {
  786. return S_OK;
  787. }
  788. }
  789. return E_NOTIMPL;
  790. }
  791. STDMETHODIMP HTMLContainer2::GetOptionKeyPath(LPOLESTR __RPC_FAR *pchKey, DWORD dw)
  792. {
  793. *pchKey = NULL;
  794. return E_NOTIMPL;
  795. }
  796. STDMETHODIMP HTMLContainer2::GetDropTarget(IDropTarget __RPC_FAR *pDropTarget, IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget)
  797. {
  798. return E_NOTIMPL;
  799. }
  800. STDMETHODIMP HTMLContainer2::GetExternal(IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
  801. {
  802. *ppDispatch = NULL;
  803. return E_NOTIMPL;
  804. }
  805. STDMETHODIMP HTMLContainer2::TranslateUrl(DWORD dwTranslate, OLECHAR __RPC_FAR *pchURLIn, OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut)
  806. {
  807. *ppchURLOut = NULL;
  808. return E_NOTIMPL;
  809. }
  810. STDMETHODIMP HTMLContainer2::FilterDataObject(IDataObject __RPC_FAR *pDO, IDataObject __RPC_FAR *__RPC_FAR *ppDORet)
  811. {
  812. *ppDORet = NULL;
  813. return S_FALSE;
  814. }
  815. STDMETHODIMP HTMLContainer2::GetOverrideKeyPath(LPOLESTR __RPC_FAR *pchKey, DWORD dw)
  816. {
  817. *pchKey = NULL;
  818. return S_FALSE;
  819. }
  820. STDMETHODIMP HTMLContainer2::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD *prgCmds, OLECMDTEXT *pCmdText)
  821. {
  822. return OLECMDERR_E_NOTSUPPORTED;
  823. }
  824. STDMETHODIMP HTMLContainer2::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, VARIANTARG *pvaIn, VARIANTARG *pvaOut)
  825. {
  826. return OLECMDERR_E_UNKNOWNGROUP;
  827. }
  828. STDMETHODIMP HTMLContainer2::QueryService(REFGUID guidService, REFIID riid, void **ppv)
  829. {
  830. return E_NOINTERFACE;
  831. }
  832. HRESULT HTMLContainer2::GetIUnknown(IUnknown **ppUnk)
  833. {
  834. if (!pUnk)
  835. {
  836. *ppUnk = NULL;
  837. return E_NOINTERFACE;
  838. }
  839. pUnk->AddRef();
  840. *ppUnk = pUnk;
  841. return S_OK;
  842. }
  843. HRESULT HTMLContainer2::GetIDispatch(IDispatch **ppDisp)
  844. {
  845. *ppDisp = NULL;
  846. return (pUnk) ? pUnk->QueryInterface(IID_IDispatch, (PVOID*)ppDisp) : E_NOINTERFACE;
  847. }
  848. HRESULT HTMLContainer2::GetIWebBrowser2(IWebBrowser2 **ppWeb2)
  849. {
  850. *ppWeb2 = NULL;
  851. return (pUnk) ? pUnk->QueryInterface(IID_IWebBrowser2, (PVOID*)ppWeb2) : E_NOINTERFACE;
  852. }
  853. HWND HTMLContainer2::GetHostHWND(void)
  854. {
  855. if (NULL == pUnk) return NULL;
  856. HWND hwndHost = NULL;
  857. IOleInPlaceObject *pipo = NULL;
  858. HRESULT hr = pUnk->QueryInterface(IID_IOleInPlaceObject, (PVOID *)&pipo);
  859. if (SUCCEEDED(hr))
  860. {
  861. hr = pipo->GetWindow(&hwndHost);
  862. if (FAILED(hr)) hwndHost = NULL;
  863. pipo->Release();
  864. }
  865. return hwndHost;
  866. }
  867. HWND HTMLContainer2::GetParentHWND(void)
  868. {
  869. return hParent;
  870. }
  871. STDMETHODIMP HTMLContainer2::UnadviseBrowserEvents()
  872. {
  873. if (0 == dwCookie)
  874. return S_OK;
  875. IConnectionPoint *pcp = NULL;
  876. IConnectionPointContainer *pcpc = NULL;
  877. HRESULT hr = pUnk->QueryInterface(IID_IConnectionPointContainer, (PVOID*)&pcpc);
  878. if (SUCCEEDED (hr))
  879. {
  880. hr = pcpc->FindConnectionPoint(DIID_DWebBrowserEvents2, &pcp);
  881. if (SUCCEEDED(hr))
  882. {
  883. hr = pcp->Unadvise(dwCookie);
  884. if (SUCCEEDED(hr))
  885. {
  886. dwCookie = 0;
  887. }
  888. pcp->Release();
  889. }
  890. pcpc->Release();
  891. }
  892. return hr;
  893. }
  894. HRESULT HTMLContainer2::PostRedirectMessage(UINT messageId, LPARAM param)
  895. {
  896. HWND hHost = GetHostHWND();
  897. if (NULL == hHost) return E_HANDLE;
  898. if (FALSE == SublassControl_IsAttached(hHost)) return E_NOTIMPL;
  899. if (0 == WM_REDIRECTNAVIGATE)
  900. {
  901. WM_REDIRECTNAVIGATE = RegisterWindowMessageW(L"htmlContainterRedirectNavigate");
  902. if (0 == WM_REDIRECTNAVIGATE) return E_UNEXPECTED;
  903. }
  904. if (FALSE == PostMessageW(hHost, WM_REDIRECTNAVIGATE, (WPARAM)messageId, param))
  905. {
  906. DWORD errorCode = GetLastError();
  907. return HRESULT_FROM_WIN32(errorCode);
  908. }
  909. return S_OK;
  910. }
  911. HRESULT HTMLContainer2::NavigateEx(IWebBrowser2 *pWeb2, VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
  912. {
  913. HRESULT hr;
  914. if (NULL == pWeb2)
  915. return E_NOINTERFACE;
  916. pWeb2->AddRef();
  917. VARIANT vtHeader;
  918. BOOL performNavigate = TRUE;
  919. VariantInit(&vtHeader);
  920. LPCWSTR pszUserAgent = OnGetUserAgent();
  921. if (!Headers && NULL != pszUserAgent && L'\0' != *pszUserAgent)
  922. {
  923. wchar_t szBuffer[256] = {0};
  924. if (SUCCEEDED(StringCchPrintfW(szBuffer, ARRAYSIZE(szBuffer), L"User-Agent: %s", pszUserAgent)))
  925. {
  926. V_VT(&vtHeader) = VT_BSTR;
  927. vtHeader.bstrVal = SysAllocString(szBuffer);
  928. Headers = &vtHeader;
  929. }
  930. }
  931. if (FALSE != ensureChakraLoaded)
  932. {
  933. if (NULL == GetModuleHandleW(L"mshtml.dll"))
  934. {
  935. HKEY hKey = NULL;
  936. unsigned long disposition = 0;
  937. long createResult = 0;
  938. wchar_t processName[2*MAX_PATH] = {0};
  939. HANDLE lock = CreateMutexW(NULL, FALSE, L"HTMLContainer2::ChakraEnabler");
  940. if (NULL != lock)
  941. WaitForSingleObject(lock, INFINITE);
  942. createResult = RegCreateKeyExW(HKEY_CURRENT_USER, REGISTRY_FEATURE_USE_LEGACY_JSCRIPT,
  943. NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE,
  944. NULL, &hKey, &disposition);
  945. if (ERROR_SUCCESS == createResult)
  946. {
  947. unsigned long featureEnabled = 0;
  948. if (0 != GetModuleFileNameW(NULL, processName, ARRAYSIZE(processName)))
  949. {
  950. featureEnabled = 0;
  951. PathStripPathW(processName);
  952. RegSetValueExW(hKey, processName, 0, REG_DWORD, (const BYTE*)&featureEnabled, sizeof(unsigned long));
  953. hr = pWeb2->Navigate2(URL, Flags, TargetFrameName, PostData, Headers);
  954. performNavigate = FALSE;
  955. RegDeleteValueW(hKey, processName);
  956. }
  957. RegCloseKey(hKey);
  958. }
  959. if (NULL != lock)
  960. {
  961. ReleaseMutex(lock);
  962. CloseHandle(lock);
  963. }
  964. }
  965. ensureChakraLoaded = FALSE;
  966. }
  967. if (FALSE != performNavigate)
  968. hr = pWeb2->Navigate2(URL, Flags, TargetFrameName, PostData, Headers);
  969. VariantClear(&vtHeader);
  970. pWeb2->Release();
  971. return hr;
  972. }
  973. HRESULT HTMLContainer2::Navigate2(VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
  974. {
  975. if (NULL == pUnk)
  976. return E_NOINTERFACE;
  977. IWebBrowser2 *pWeb2 = NULL;
  978. HRESULT hr = pUnk->QueryInterface(IID_IWebBrowser2, (LPVOID*)&pWeb2);
  979. if(SUCCEEDED(hr))
  980. {
  981. hr = NavigateEx(pWeb2, URL, Flags, TargetFrameName, PostData, Headers);
  982. pWeb2->Release();
  983. }
  984. return hr;
  985. }
  986. HRESULT HTMLContainer2::PostNavigate2(VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
  987. {
  988. RMNAVIGATE2 *param = (RMNAVIGATE2*)calloc(1, sizeof(RMNAVIGATE2));
  989. if (NULL == param) return E_OUTOFMEMORY;
  990. VariantInit(&param->URL);
  991. VariantInit(&param->Flags);
  992. VariantInit(&param->TargetFrameName);
  993. VariantInit(&param->PostData);
  994. VariantInit(&param->Headers);
  995. if (NULL != URL) VariantCopyInd(&param->URL, URL);
  996. if (NULL != Flags) VariantCopyInd(&param->Flags, Flags);
  997. if (NULL != TargetFrameName) VariantCopyInd(&param->TargetFrameName, TargetFrameName);
  998. if (NULL != PostData) VariantCopyInd(&param->PostData, PostData);
  999. if (NULL != Headers) VariantCopyInd(&param->Headers, Headers);
  1000. HRESULT hr = PostRedirectMessage(HTMLContainer2::msgNavigate2, (LPARAM)param);
  1001. if (FAILED(hr))
  1002. {
  1003. VariantClear(&param->URL);
  1004. VariantClear(&param->Flags);
  1005. VariantClear(&param->TargetFrameName);
  1006. VariantClear(&param->PostData);
  1007. VariantClear(&param->Headers);
  1008. free(param);
  1009. }
  1010. return hr;
  1011. }
  1012. HRESULT HTMLContainer2::NavigateToNameEx(IWebBrowser2 *pWeb2, LPCWSTR pszUrl, UINT fFlags)
  1013. {
  1014. VARIANT Flags;
  1015. VARIANT URL;
  1016. if (NULL == pszUrl || L'\0' == *pszUrl)
  1017. {
  1018. pszUrl = L"about:blank";
  1019. }
  1020. VariantInit(&Flags);
  1021. V_VT(&Flags) = VT_I4;
  1022. V_I4(&Flags) = fFlags;
  1023. VariantInit(&URL);
  1024. V_VT(&URL) = VT_BSTR;
  1025. URL.bstrVal = SysAllocString(pszUrl);
  1026. HRESULT hr = (NULL != URL.bstrVal) ? NavigateEx(pWeb2, &URL, &Flags, NULL, NULL, NULL) : E_FAIL;
  1027. VariantClear(&URL);
  1028. VariantClear(&Flags);
  1029. return hr;
  1030. }
  1031. HRESULT HTMLContainer2::NavigateToName(LPCWSTR pszUrl, UINT fFlags)
  1032. {
  1033. if (NULL == pUnk)
  1034. return E_NOINTERFACE;
  1035. IWebBrowser2 *pWeb2 = NULL;
  1036. HRESULT hr = pUnk->QueryInterface(IID_IWebBrowser2, (LPVOID*)&pWeb2);
  1037. if(SUCCEEDED(hr))
  1038. {
  1039. hr = NavigateToNameEx(pWeb2, pszUrl, fFlags);
  1040. pWeb2->Release();
  1041. }
  1042. return hr;
  1043. }
  1044. HRESULT HTMLContainer2::PostNavigateToName(LPCWSTR pszUrl, UINT fFlags)
  1045. {
  1046. RMNAVIGATETONAME *param = (RMNAVIGATETONAME*)calloc(1, sizeof(RMNAVIGATETONAME));
  1047. if (NULL == param) return E_OUTOFMEMORY;
  1048. param->url = SysAllocString(pszUrl);
  1049. param->flags = fFlags;
  1050. HRESULT hr = PostRedirectMessage(HTMLContainer2::msgNavigateToName, (LPARAM)param);
  1051. if (FAILED(hr))
  1052. {
  1053. SysFreeString(param->url);
  1054. free(param);
  1055. }
  1056. return hr;
  1057. }
  1058. HRESULT HTMLContainer2::WriteHTML(LPCWSTR pszHTML)
  1059. {
  1060. BSTR data = SysAllocString(pszHTML);
  1061. if (NULL == data && NULL != pszHTML)
  1062. return E_OUTOFMEMORY;
  1063. HRESULT hr = WriteDocument(data);
  1064. if (FAILED(hr))
  1065. {
  1066. SysFreeString(data);
  1067. }
  1068. return hr;
  1069. }
  1070. HRESULT HTMLContainer2::WriteDocument(BSTR data)
  1071. {
  1072. IWebBrowser2 *pWeb2 = NULL;
  1073. HRESULT hr = GetIWebBrowser2(&pWeb2);
  1074. if (FAILED(hr)) return hr;
  1075. IDispatch *pDisp = NULL;
  1076. hr = pWeb2->get_Document(&pDisp);
  1077. if (S_OK == hr)
  1078. {
  1079. IHTMLDocument2 *pDoc = NULL;
  1080. hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  1081. if (SUCCEEDED(hr))
  1082. {
  1083. SAFEARRAY *array = SafeArrayCreateVector(VT_VARIANT, 0, 1);
  1084. if (NULL != array)
  1085. {
  1086. VARIANT *item = NULL;
  1087. hr = SafeArrayAccessData(array, (void**)&item);
  1088. if (SUCCEEDED(hr))
  1089. {
  1090. VariantInit(item);
  1091. V_VT(item) = VT_BSTR;
  1092. V_BSTR(item) = data;
  1093. hr = pDoc->write(array);
  1094. pDoc->close();
  1095. if (FAILED(hr))
  1096. V_BSTR(item) = NULL;
  1097. SafeArrayUnaccessData(array);
  1098. }
  1099. SafeArrayDestroy(array);
  1100. }
  1101. else
  1102. {
  1103. hr = E_OUTOFMEMORY;
  1104. }
  1105. pDoc->Release();
  1106. }
  1107. pDisp->Release();
  1108. }
  1109. pWeb2->Release();
  1110. return hr;
  1111. }
  1112. COLORREF HTMLContainer2::OnGetHostBkColor(void)
  1113. {
  1114. return DEFAULT_HOSTBKCOLOR;
  1115. }
  1116. DWORD HTMLContainer2::OnGetHostInfoFlags(void)
  1117. {
  1118. return DEFAULT_DOCHOSTUIFLAGS;
  1119. }
  1120. OLECHAR *HTMLContainer2::OnGetHostCSS(void)
  1121. {
  1122. return NULL;
  1123. }
  1124. OLECHAR *HTMLContainer2::OnGetHostNamespace(void)
  1125. {
  1126. return NULL;
  1127. }
  1128. DWORD HTMLContainer2::OnGetDownlodFlags(void)
  1129. {
  1130. return DEFAULT_DOWNLOADFLAGS;
  1131. }
  1132. LPCWSTR HTMLContainer2::OnGetUserAgent(void)
  1133. {
  1134. return NULL;
  1135. }
  1136. HRESULT HTMLContainer2::InvokeScriptFunction(LPCWSTR pszFuncName, LCID lcid, DISPPARAMS FAR *pDispParams, VARIANT FAR *pVarResult, EXCEPINFO FAR *pExcepInfo, UINT FAR *puArgErr)
  1137. {
  1138. IWebBrowser2 *pWeb2 = NULL;
  1139. IDispatch *pDisp = NULL;
  1140. IDispatch *pDispScript = NULL;
  1141. IHTMLDocument2 *pDoc = NULL;
  1142. DISPID dispid;
  1143. HRESULT hr = GetIWebBrowser2(&pWeb2);
  1144. if (SUCCEEDED(hr))
  1145. {
  1146. hr = pWeb2->get_Document(&pDisp);
  1147. if (SUCCEEDED(hr))
  1148. {
  1149. hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  1150. if (SUCCEEDED(hr))
  1151. {
  1152. hr = pDoc->get_Script(&pDispScript);
  1153. if (SUCCEEDED(hr))
  1154. {
  1155. hr = pDispScript->GetIDsOfNames(IID_NULL, (LPWSTR*)&pszFuncName, 1, lcid, &dispid);
  1156. if (SUCCEEDED(hr))
  1157. {
  1158. hr = pDispScript->Invoke(dispid, IID_NULL, lcid, DISPATCH_METHOD, pDispParams, pVarResult, pExcepInfo, puArgErr);
  1159. }
  1160. pDispScript->Release();
  1161. }
  1162. pDoc->Release();
  1163. }
  1164. pDisp->Release();
  1165. }
  1166. pWeb2->Release();
  1167. }
  1168. return hr;
  1169. }
  1170. BROWSERCB HTMLContainer2::RegisterBrowserEventCB(BROWSERCB fnBrowserCB, LPVOID pUserData)
  1171. {
  1172. BROWSERCB fnTemp = this->fnBrwoserCB;
  1173. this->fnBrwoserCB = fnBrowserCB;
  1174. this->userData = pUserData;
  1175. return fnTemp;
  1176. }
  1177. DWORD HTMLContainer2::GetContainerStyle(void)
  1178. {
  1179. return CSTYLE_NORMAL;
  1180. }
  1181. HRESULT HTMLContainer2::IsFrameset(IWebBrowser2 *pWeb2)
  1182. {
  1183. if (NULL == pWeb2)
  1184. return E_INVALIDARG;
  1185. IDispatch *pDocDisp = NULL;
  1186. HRESULT hr = pWeb2->get_Document(&pDocDisp);
  1187. if (SUCCEEDED(hr) && NULL != pDocDisp)
  1188. {
  1189. IHTMLDocument2 *pDoc = NULL;
  1190. hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  1191. if (SUCCEEDED(hr) && NULL != pDoc)
  1192. {
  1193. IHTMLElement *pElement = NULL;
  1194. if (SUCCEEDED(pDoc->get_body(&pElement)) && NULL != pElement)
  1195. {
  1196. IHTMLBodyElement* pBodyElement = NULL;
  1197. if (SUCCEEDED(pElement->QueryInterface(IID_IHTMLBodyElement, (void**)&pBodyElement)))
  1198. {
  1199. hr = S_FALSE;
  1200. }
  1201. pElement->Release();
  1202. }
  1203. pDoc->Release();
  1204. }
  1205. pDocDisp->Release();
  1206. }
  1207. return hr;
  1208. }
  1209. HRESULT HTMLContainer2::GetFramesCount(IWebBrowser2 *pWeb2, INT *frameCount)
  1210. {
  1211. if (NULL == frameCount)
  1212. return E_POINTER;
  1213. *frameCount = 0;
  1214. if(NULL == pWeb2)
  1215. return E_INVALIDARG;
  1216. IDispatch *pDocDisp = NULL;
  1217. HRESULT hr = pWeb2->get_Document(&pDocDisp);
  1218. if (SUCCEEDED(hr) && NULL != pDocDisp)
  1219. {
  1220. IOleContainer *pContainer = NULL;
  1221. hr = pDocDisp->QueryInterface(IID_IOleContainer, (void**)&pContainer);
  1222. if (SUCCEEDED(hr))
  1223. {
  1224. IEnumUnknown* pEnumerator = NULL;
  1225. hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);
  1226. if (SUCCEEDED(hr))
  1227. {
  1228. IUnknown* pUnknown = NULL;
  1229. ULONG uFetched = 0;
  1230. for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnknown, &uFetched); i++)
  1231. {
  1232. IWebBrowser2* pBrowser = NULL;
  1233. if (SUCCEEDED(pUnknown->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser)))
  1234. {
  1235. if (S_OK == IsFrameset(pBrowser))
  1236. {
  1237. INT f = 0;
  1238. if (SUCCEEDED(GetFramesCount(pBrowser, &f)))
  1239. *frameCount += f;
  1240. }
  1241. else
  1242. {
  1243. (*frameCount)++;
  1244. }
  1245. pBrowser->Release();
  1246. }
  1247. pUnknown->Release();
  1248. }
  1249. pEnumerator->Release();
  1250. }
  1251. pContainer->Release();
  1252. }
  1253. pDocDisp->Release();
  1254. }
  1255. return hr;
  1256. }
  1257. BOOL HTMLContainer2::ValidateURLHost(LPCWSTR pszUrl)
  1258. {
  1259. if (NULL == libWininet.InternetCrackUrl)
  1260. {
  1261. HTMLContainer2_LoadLibray((LIBHDR*)&libWininet);
  1262. if (NULL == libWininet.InternetCrackUrl)
  1263. {
  1264. return TRUE;
  1265. }
  1266. }
  1267. if (NULL == pszUrl || L'\0' == *pszUrl)
  1268. return FALSE;
  1269. URL_COMPONENTSW uc;
  1270. WCHAR szHost[2048] = {0};
  1271. ZeroMemory(&uc, sizeof(URL_COMPONENTSW));
  1272. uc.dwStructSize = sizeof(URL_COMPONENTSW);
  1273. uc.lpszHostName = szHost;
  1274. uc.dwHostNameLength = ARRAYSIZE(szHost);
  1275. if (FALSE == libWininet.InternetCrackUrl(pszUrl, 0, NULL, &uc))
  1276. {
  1277. // ERROR_INTERNET_INVALID_URL
  1278. DWORD error = GetLastError();
  1279. BSTR version = NULL;
  1280. if (SUCCEEDED(GetAppVersion(&version)) && NULL != version)
  1281. {
  1282. if (NULL != StrStrIW(version, L"MSIE 6.0"))
  1283. {
  1284. LPCWSTR c = pszUrl;
  1285. while(c && L'\0' != *c)
  1286. {
  1287. if (L'?' == *c)
  1288. {
  1289. WCHAR szTemp[2048] = {0};
  1290. if (SUCCEEDED(StringCchCopyNW(szTemp, ARRAYSIZE(szTemp), pszUrl, (c - pszUrl))) &&
  1291. FALSE != libWininet.InternetCrackUrl(szTemp, 0, NULL, &uc))
  1292. {
  1293. error = ERROR_SUCCESS;
  1294. }
  1295. break;
  1296. }
  1297. c++;
  1298. }
  1299. }
  1300. SysFreeString(version);
  1301. }
  1302. if (ERROR_SUCCESS != error)
  1303. return FALSE;
  1304. }
  1305. if (0 == uc.dwHostNameLength)
  1306. return TRUE;
  1307. switch(uc.nScheme)
  1308. {
  1309. case INTERNET_SCHEME_PARTIAL:
  1310. case INTERNET_SCHEME_DEFAULT:
  1311. case INTERNET_SCHEME_FTP:
  1312. case INTERNET_SCHEME_GOPHER:
  1313. case INTERNET_SCHEME_HTTP:
  1314. case INTERNET_SCHEME_HTTPS:
  1315. {
  1316. LPCWSTR block = uc.lpszHostName;
  1317. LPCWSTR end = block + uc.dwHostNameLength;
  1318. LPCWSTR cursor = block;
  1319. for(;;)
  1320. {
  1321. if (cursor == end || L'.' == *cursor)
  1322. {
  1323. if (block == cursor && end != cursor)
  1324. return FALSE;
  1325. if (end == cursor)
  1326. return TRUE;
  1327. }
  1328. cursor++;
  1329. }
  1330. }
  1331. break;
  1332. case INTERNET_SCHEME_RES:
  1333. case INTERNET_SCHEME_FILE:
  1334. if (CSTR_EQUAL == CompareStringW(CSTR_INVARIANT, 0, L"shdoclc", -1, uc.lpszHostName, -1))
  1335. {
  1336. if (NULL != StrStrIW(pszUrl, L"syntax.htm"))
  1337. {
  1338. return FALSE;
  1339. }
  1340. }
  1341. break;
  1342. }
  1343. return TRUE;
  1344. }
  1345. HRESULT HTMLContainer2::GetAppVersion(BSTR *p)
  1346. {
  1347. if (NULL == p)
  1348. return E_POINTER;
  1349. IWebBrowser2 *pWeb2 = NULL;
  1350. HRESULT hr = GetIWebBrowser2(&pWeb2);
  1351. if (FAILED(hr)) return hr;
  1352. IDispatch *pDispatch = NULL;
  1353. hr = pWeb2->get_Document(&pDispatch);
  1354. if (NULL == pDispatch) hr = E_FAIL;
  1355. if (SUCCEEDED(hr))
  1356. {
  1357. IHTMLDocument2 *pDoc = NULL;
  1358. hr = pDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  1359. if (SUCCEEDED(hr))
  1360. {
  1361. IHTMLWindow2 *pWnd = NULL;
  1362. hr = pDoc->get_parentWindow(&pWnd);
  1363. if (NULL == pWnd) hr = E_FAIL;
  1364. if (SUCCEEDED(hr))
  1365. {
  1366. IOmNavigator *pNavigator = NULL;
  1367. hr = pWnd->get_navigator(&pNavigator);
  1368. if (NULL == pNavigator) hr = E_FAIL;
  1369. if (SUCCEEDED(hr))
  1370. {
  1371. hr = pNavigator->get_appVersion(p);
  1372. pNavigator->Release();
  1373. }
  1374. pWnd->Release();
  1375. }
  1376. pDoc->Release();
  1377. }
  1378. pDispatch->Release();
  1379. }
  1380. pWeb2->Release();
  1381. return hr;
  1382. }
  1383. HRESULT HTMLContainer2::GetUserAgent(BSTR *p)
  1384. {
  1385. if (NULL == p)
  1386. return E_POINTER;
  1387. IWebBrowser2 *pWeb2 = NULL;
  1388. HRESULT hr = GetIWebBrowser2(&pWeb2);
  1389. if (FAILED(hr)) return hr;
  1390. IDispatch *pDispatch = NULL;
  1391. hr = pWeb2->get_Document(&pDispatch);
  1392. if (NULL == pDispatch) hr = E_FAIL;
  1393. if (SUCCEEDED(hr))
  1394. {
  1395. IHTMLDocument2 *pDoc = NULL;
  1396. hr = pDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  1397. if (SUCCEEDED(hr))
  1398. {
  1399. IHTMLWindow2 *pWnd = NULL;
  1400. hr = pDoc->get_parentWindow(&pWnd);
  1401. if (NULL == pWnd) hr = E_FAIL;
  1402. if (SUCCEEDED(hr))
  1403. {
  1404. IOmNavigator *pNavigator = NULL;
  1405. hr = pWnd->get_navigator(&pNavigator);
  1406. if (NULL == pNavigator) hr = E_FAIL;
  1407. if (SUCCEEDED(hr))
  1408. {
  1409. hr = pNavigator->get_userAgent(p);
  1410. pNavigator->Release();
  1411. }
  1412. pWnd->Release();
  1413. }
  1414. pDoc->Release();
  1415. }
  1416. pDispatch->Release();
  1417. }
  1418. pWeb2->Release();
  1419. return hr;
  1420. }
  1421. void HTMLContainer2::OnBeforeNavigate(IDispatch *pDispatch, VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers, VARIANT_BOOL *Cancel)
  1422. {
  1423. if (0 == (CF_DISABLEBEFORENAVFILTER & dwFlags))
  1424. {
  1425. // follow the Winamp internet preferences options
  1426. if (!SendMessageW(winampWindow, WM_WA_IPC, 0, IPC_INETAVAILABLE))
  1427. {
  1428. LPCWSTR pszTemplate = L"res://";
  1429. LPCWSTR pszEntry = StrStrIW(URL->bstrVal, pszTemplate);
  1430. if (NULL == pszEntry)
  1431. {
  1432. if (StrCmpNIW(URL->bstrVal, L"about:blank", 11) && StrCmpNIW(URL->bstrVal, L"javascript:", 11))
  1433. {
  1434. *Cancel = ((VARIANT_BOOL)-2);
  1435. dwFlags |= CF_DISABLEBEFORENAVFILTER;
  1436. OnNavigateCancelled(NULL, Cancel);
  1437. dwFlags &= ~CF_DISABLEBEFORENAVFILTER;
  1438. if (NULL != Cancel && VARIANT_TRUE == *Cancel)
  1439. return;
  1440. }
  1441. }
  1442. }
  1443. if (FALSE == ValidateURLHost(URL->bstrVal))
  1444. {
  1445. VARIANT StatusCode;
  1446. VariantInit(&StatusCode);
  1447. V_VT(&StatusCode) = VT_I4;
  1448. V_I4(&StatusCode) = INET_E_INVALID_URL;
  1449. dwFlags |= CF_DISABLEBEFORENAVFILTER;
  1450. *Cancel = VARIANT_TRUE;
  1451. OnNavigateError(pDispatch, URL, TargetFrameName, &StatusCode, Cancel);
  1452. Navigate2(URL, NULL, TargetFrameName, NULL, NULL);
  1453. dwFlags &= ~CF_DISABLEBEFORENAVFILTER;
  1454. if (NULL != Cancel && VARIANT_TRUE == *Cancel)
  1455. return;
  1456. }
  1457. IWebBrowser2 *pWebMine = NULL, *pWebFrame = NULL;
  1458. if (FAILED(GetIWebBrowser2(&pWebMine)))
  1459. pWebMine = NULL;
  1460. if (NULL == pDispatch ||
  1461. FAILED(pDispatch->QueryInterface(IID_IWebBrowser2, (void**)&pWebFrame)))
  1462. {
  1463. pWebFrame = NULL;
  1464. }
  1465. if (NULL != pWebMine) pWebMine->Release();
  1466. if (NULL != pWebFrame) pWebFrame->Release();
  1467. if (NULL != pWebMine && pWebMine == pWebFrame && NULL != URL && VT_BSTR == URL->vt && NULL != URL->bstrVal)
  1468. {
  1469. LPCWSTR pszTemplate = L"navcancl.htm#";
  1470. LPCWSTR pszEntry = StrStrIW(URL->bstrVal, pszTemplate);
  1471. if (NULL != pszEntry)
  1472. {
  1473. dwFlags |= CF_DISABLEBEFORENAVFILTER;
  1474. OnNavigateCancelled(pszEntry + lstrlenW(pszTemplate), Cancel);
  1475. dwFlags &= ~CF_DISABLEBEFORENAVFILTER;
  1476. if (NULL != Cancel && VARIANT_TRUE == *Cancel)
  1477. return;
  1478. }
  1479. }
  1480. }
  1481. }
  1482. STDMETHODIMP HTMLContainer2::RegisterBrowserCursor(INT nSysCurID, HCURSOR hCurToUse)
  1483. {
  1484. IECURSOR *pCursor = (IECURSOR*)hCursors;
  1485. if (pCursor)
  1486. {
  1487. for (int i =0; i < nCursors; i++)
  1488. {
  1489. if (pCursor[i].nSysId == nSysCurID)
  1490. {
  1491. if (pCursor[i].hUser) DestroyCursor(pCursor[i].hUser);
  1492. pCursor[i].hSys = NULL;
  1493. if (hCurToUse) pCursor[i].hUser = hCurToUse;
  1494. else
  1495. {
  1496. MoveMemory(&pCursor[i], &pCursor[i + 1], sizeof(IECURSOR)*(nCursors - i - 1));
  1497. nCursors--;
  1498. if (!nCursors)
  1499. {
  1500. free(hCursors);
  1501. hCursors = NULL;
  1502. }
  1503. VOID* data = realloc(hCursors, sizeof(IECURSOR)*nCursors);
  1504. if (data) hCursors = data;
  1505. else return E_OUTOFMEMORY;
  1506. }
  1507. return S_OK;
  1508. }
  1509. }
  1510. }
  1511. if (hCurToUse)
  1512. {
  1513. VOID *data = realloc(hCursors, sizeof(IECURSOR)*(nCursors + 1));
  1514. if (!data) return E_OUTOFMEMORY;
  1515. hCursors = data;
  1516. pCursor = (IECURSOR*)hCursors;
  1517. pCursor[nCursors].nSysId = nSysCurID;
  1518. pCursor[nCursors].hSys = NULL;
  1519. pCursor[nCursors].hUser = hCurToUse;
  1520. nCursors++;
  1521. }
  1522. return S_OK;
  1523. }
  1524. HRESULT HTMLContainer2::InternetSetFeatureEnabled(INTERNETFEATURELIST FeatureEntry, DWORD dwFlags, BOOL fEnable)
  1525. {
  1526. if (NULL == libUrlmon.CoInternetSetFeatureEnabled)
  1527. {
  1528. HTMLContainer2_LoadLibray((LIBHDR*)&libUrlmon);
  1529. if (NULL == libUrlmon.CoInternetSetFeatureEnabled)
  1530. {
  1531. return E_FAIL;
  1532. }
  1533. }
  1534. return libUrlmon.CoInternetSetFeatureEnabled(FeatureEntry, dwFlags, fEnable);
  1535. }
  1536. HRESULT HTMLContainer2::InternetIsFeatureEnabled(INTERNETFEATURELIST FeatureEntry, DWORD dwFlags)
  1537. {
  1538. if (NULL == libUrlmon.CoInternetIsFeatureEnabled)
  1539. {
  1540. HTMLContainer2_LoadLibray((LIBHDR*)&libUrlmon);
  1541. if (NULL == libUrlmon.CoInternetIsFeatureEnabled)
  1542. {
  1543. return E_FAIL;
  1544. }
  1545. }
  1546. return libUrlmon.CoInternetIsFeatureEnabled(FeatureEntry, dwFlags);
  1547. }
  1548. void HTMLContainer2::ProcessRedirectedMessage(HWND hwnd, UINT messageId, LPARAM param)
  1549. {
  1550. switch(messageId)
  1551. {
  1552. case HTMLContainer2::msgNavigate2:
  1553. {
  1554. RMNAVIGATE2 *pnp = (RMNAVIGATE2*)param;
  1555. if (NULL != pnp)
  1556. {
  1557. Navigate2(&pnp->URL, &pnp->Flags, NULL, NULL, &pnp->Headers);
  1558. VariantClear(&pnp->URL);
  1559. VariantClear(&pnp->Flags);
  1560. VariantClear(&pnp->TargetFrameName);
  1561. VariantClear(&pnp->PostData);
  1562. VariantClear(&pnp->Headers);
  1563. free(pnp);
  1564. }
  1565. }
  1566. break;
  1567. case HTMLContainer2::msgNavigateToName:
  1568. {
  1569. RMNAVIGATETONAME *pntn = (RMNAVIGATETONAME*)param;
  1570. if (NULL != pntn)
  1571. {
  1572. NavigateToName(pntn->url, pntn->flags);
  1573. free(pntn);
  1574. }
  1575. }
  1576. break;
  1577. }
  1578. }
  1579. #define SUBCLASS_UNKNOWN 0
  1580. #define SUBCLASS_EMBED 1
  1581. #define SUBCLASS_DOCOBJECT 2
  1582. #define SUBCLASS_IESERVER 3
  1583. typedef struct __SUBCLASSCTRL
  1584. {
  1585. UINT type;
  1586. WNDPROC originalProc;
  1587. HTMLContainer2 *container;
  1588. } SUBCLASSCTRL;
  1589. static LRESULT SubclassControl_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1590. {
  1591. SUBCLASSCTRL *psc = (SUBCLASSCTRL*)GetPropW(hwnd, WNDPROP_SCCTRLW);
  1592. if (NULL == psc || NULL == psc->originalProc)
  1593. return DefWindowProcW(hwnd, uMsg, wParam, lParam);
  1594. switch(uMsg)
  1595. {
  1596. case WM_NCDESTROY:
  1597. case WM_DESTROY: // detach
  1598. RemovePropW(hwnd, WNDPROP_SCCTRLW);
  1599. SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)psc->originalProc);
  1600. CallWindowProcW(psc->originalProc, hwnd, uMsg, wParam, lParam);
  1601. free(psc);
  1602. return 0;
  1603. case WM_ERASEBKGND:
  1604. if( NULL != wParam &&
  1605. NULL != psc->container &&
  1606. (SUBCLASS_EMBED == psc->type || SUBCLASS_DOCOBJECT == psc->type))
  1607. {
  1608. HWND hChild = GetWindow(hwnd, GW_CHILD);
  1609. if (NULL == hChild || 0 == (WS_VISIBLE & GetWindowLongPtrW(hChild, GWL_STYLE)))
  1610. {
  1611. RECT paintRect;
  1612. if (FALSE != GetUpdateRect(hwnd, &paintRect, FALSE) ||
  1613. FALSE != GetClientRect(hwnd, &paintRect))
  1614. {
  1615. SetBkColor((HDC)wParam, psc->container->OnGetHostBkColor());
  1616. ExtTextOutW((HDC)wParam, 0, 0, ETO_OPAQUE, &paintRect, NULL, 0, NULL);
  1617. }
  1618. }
  1619. }
  1620. return 1;
  1621. case WM_SETFOCUS:
  1622. if (SUBCLASS_IESERVER == psc->type)
  1623. {
  1624. if (NULL != psc->container)
  1625. psc->container->SetFocus(TRUE);
  1626. }
  1627. else
  1628. {
  1629. HWND hFocus = (HWND)wParam;
  1630. if (NULL != hFocus && IsWindowEnabled(hFocus))
  1631. {
  1632. HWND hRoot = GetAncestor(hwnd, GA_ROOT);
  1633. if (hFocus == hRoot || IsChild(hRoot, hFocus))
  1634. {
  1635. SetFocus(hFocus);
  1636. return 0;
  1637. }
  1638. }
  1639. }
  1640. break;
  1641. case WM_KILLFOCUS:
  1642. if (SUBCLASS_IESERVER == psc->type && NULL != psc->container)
  1643. {
  1644. psc->container->SetFocus(FALSE);
  1645. }
  1646. break;
  1647. case WM_PARENTNOTIFY:
  1648. if ((SUBCLASS_EMBED == psc->type || SUBCLASS_DOCOBJECT == psc->type) &&
  1649. WM_CREATE == LOWORD(wParam) && 0L != lParam)
  1650. {
  1651. SubclassControl_Attach((HWND)lParam, psc->container);
  1652. }
  1653. if (SUBCLASS_EMBED == psc->type && WM_DESTROY == LOWORD(wParam) && NULL != lParam)
  1654. {
  1655. HWND hChild = (HWND)lParam;
  1656. WCHAR szClass[64] = {0};
  1657. if (0 != GetClassNameW(hChild, szClass, ARRAYSIZE(szClass)) &&
  1658. IS_EQUALCLASS(szClass, L"Shell DocObject View"))
  1659. {
  1660. HWND hPrimary = FindWindowExW(hwnd, NULL, L"Shell DocObject View", NULL);
  1661. if (hPrimary != NULL && hPrimary != hChild)
  1662. {
  1663. if(NULL != psc->container)
  1664. psc->container->OnClosePopupInternal();
  1665. }
  1666. }
  1667. }
  1668. break;
  1669. case WM_SETCURSOR:
  1670. if (SUBCLASS_IESERVER == psc->type && FALSE == bIsVistaOrHigher &&
  1671. NULL != psc->container && psc->container->nCursors)
  1672. {
  1673. ShowCursor(FALSE);
  1674. CallWindowProcW(psc->originalProc, hwnd, uMsg, wParam, lParam);
  1675. HCURSOR hCur = GetCursor();
  1676. IECURSOR *pCur = (IECURSOR*)(psc->container->hCursors);
  1677. for( int i= psc->container->nCursors -1; i > -1 ; i--)
  1678. {
  1679. if (NULL == pCur[i].hSys)
  1680. pCur[i].hSys = LoadCursor(NULL, MAKEINTRESOURCE(pCur[i].nSysId));
  1681. if (pCur[i].hSys == hCur)
  1682. {
  1683. if (NULL != pCur[i].hUser)
  1684. SetCursor(pCur[i].hUser);
  1685. break;
  1686. }
  1687. }
  1688. ShowCursor(TRUE);
  1689. return TRUE;
  1690. }
  1691. break;
  1692. case WM_CONTEXTMENU:
  1693. if (NULL != psc->container)
  1694. {
  1695. HANDLE hook = psc->container->InitializePopupHook(hwnd, uMsg, wParam, lParam);
  1696. if (NULL != hook)
  1697. {
  1698. LRESULT result = CallWindowProcW(psc->originalProc, hwnd, uMsg, wParam, lParam);
  1699. psc->container->DeletePopupHook(hook);
  1700. return result;
  1701. }
  1702. }
  1703. break;
  1704. case WM_INITMENUPOPUP:
  1705. if (NULL != psc->container)
  1706. {
  1707. psc->container->InitializeMenuPopup(hwnd, (HMENU)wParam, LOWORD(lParam), HIWORD(lParam));
  1708. }
  1709. break;
  1710. case WM_INPUTLANGCHANGEREQUEST:
  1711. if (SUBCLASS_IESERVER == psc->type &&
  1712. NULL != psc->container &&
  1713. FALSE != psc->container->InputLangChangeRequest(hwnd, (UINT)wParam, (HKL)lParam))
  1714. {
  1715. return 0;
  1716. }
  1717. break;
  1718. case WM_INPUTLANGCHANGE:
  1719. if (SUBCLASS_IESERVER == psc->type && NULL != psc->container)
  1720. psc->container->InputLangChange((UINT)wParam, (HKL)lParam);
  1721. break;
  1722. }
  1723. if (0 != WM_REDIRECTNAVIGATE && WM_REDIRECTNAVIGATE == uMsg)
  1724. {
  1725. if(SUBCLASS_EMBED == psc->type && NULL != psc->container)
  1726. psc->container->ProcessRedirectedMessage(hwnd, (UINT)wParam, lParam);
  1727. return TRUE;
  1728. }
  1729. if (WINAMP_WM_DIRECT_MOUSE_WHEEL == uMsg &&
  1730. WM_NULL != WINAMP_WM_DIRECT_MOUSE_WHEEL)
  1731. {
  1732. ReplyMessage(TRUE);
  1733. SendMessageW(hwnd, WM_MOUSEWHEEL, wParam, lParam);
  1734. return TRUE;
  1735. }
  1736. return CallWindowProcW(psc->originalProc, hwnd, uMsg, wParam, lParam);
  1737. }
  1738. static BOOL SublassControl_IsAttached(HWND hwnd)
  1739. {
  1740. SUBCLASSCTRL *psc = (SUBCLASSCTRL*)GetPropW(hwnd, WNDPROP_SCCTRLW);
  1741. return (NULL != psc);
  1742. }
  1743. static BOOL SubclassControl_Attach(HWND hControl, HTMLContainer2 *pContainer)
  1744. {
  1745. if (NULL == hControl || FALSE == IsWindow(hControl))
  1746. return FALSE;
  1747. SUBCLASSCTRL *psc = (SUBCLASSCTRL*)GetPropW(hControl, WNDPROP_SCCTRLW);
  1748. if (NULL != psc) return TRUE;
  1749. UINT controlType = SUBCLASS_UNKNOWN;
  1750. if (WM_NULL == WINAMP_WM_DIRECT_MOUSE_WHEEL)
  1751. WINAMP_WM_DIRECT_MOUSE_WHEEL = RegisterWindowMessageW(L"WINAMP_WM_DIRECT_MOUSE_WHEEL");
  1752. WCHAR szClass[128] = {0};
  1753. if (!GetClassNameW(hControl, szClass, ARRAYSIZE(szClass)))
  1754. return FALSE;
  1755. if (IS_EQUALCLASS(szClass, L"Shell Embedding")) controlType = SUBCLASS_EMBED;
  1756. else if (IS_EQUALCLASS(szClass, L"Shell DocObject View")) controlType = SUBCLASS_DOCOBJECT;
  1757. else if (IS_EQUALCLASS(szClass, L"Internet Explorer_Server")) controlType = SUBCLASS_IESERVER;
  1758. if (SUBCLASS_UNKNOWN == controlType)
  1759. return FALSE;
  1760. if (SUBCLASS_IESERVER != controlType)
  1761. {
  1762. DWORD styleEx = GetWindowStyleEx(hControl);
  1763. SetWindowLongPtrW(hControl, GWL_EXSTYLE, styleEx | WS_EX_CONTROLPARENT);
  1764. }
  1765. else
  1766. {
  1767. DWORD style = GetWindowStyle(hControl);
  1768. SetWindowLongPtrW(hControl, GWL_STYLE, style | WS_TABSTOP);
  1769. }
  1770. psc = (SUBCLASSCTRL*)calloc(1, sizeof(SUBCLASSCTRL));
  1771. if (NULL == psc) return FALSE;
  1772. psc->container = pContainer;
  1773. psc->type = controlType;
  1774. psc->originalProc = (WNDPROC)(LONG_PTR)SetWindowLongPtrW(hControl, GWLP_WNDPROC, (LONGX86)(LONG_PTR)SubclassControl_WindowProc);
  1775. if (NULL == psc->originalProc ||
  1776. FALSE == SetPropW(hControl, WNDPROP_SCCTRLW, psc))
  1777. {
  1778. if (NULL != psc->originalProc)
  1779. SetWindowLongPtrW(hControl, GWLP_WNDPROC, (LONGX86)(LONG_PTR)psc->originalProc);
  1780. free(psc);
  1781. return FALSE;
  1782. }
  1783. return TRUE;
  1784. }