| OLD | NEW |
| 1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
| 2 | 2 |
| 3 #include "PluginClass.h" | 3 #include "PluginClass.h" |
| 4 #include "PluginSettings.h" | 4 #include "PluginSettings.h" |
| 5 #include "PluginSystem.h" | 5 #include "PluginSystem.h" |
| 6 #include "PluginFilter.h" | 6 #include "PluginFilter.h" |
| 7 #include "PluginMimeFilterClient.h" | 7 #include "PluginMimeFilterClient.h" |
| 8 #include "PluginClient.h" | 8 #include "PluginClient.h" |
| 9 #include "PluginClientFactory.h" | 9 #include "PluginClientFactory.h" |
| 10 #include "PluginMutex.h" | 10 #include "PluginMutex.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 | 196 |
| 197 | 197 |
| 198 // This gets called when a new browser window is created (which also triggers th
e | 198 // This gets called when a new browser window is created (which also triggers th
e |
| 199 // creation of this object). The pointer passed in should be to a IWebBrowser2 | 199 // creation of this object). The pointer passed in should be to a IWebBrowser2 |
| 200 // interface that represents the browser for the window. | 200 // interface that represents the browser for the window. |
| 201 // it is also called when a tab is closed, this unknownSite will be null | 201 // it is also called when a tab is closed, this unknownSite will be null |
| 202 // so we should handle that it is called this way several times during a session | 202 // so we should handle that it is called this way several times during a session |
| 203 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) | 203 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) |
| 204 { | 204 { |
| 205 CPluginSettings* settings = CPluginSettings::GetInstance(); | 205 return EntryPointWithHResult([&]()->HRESULT |
| 206 | |
| 207 MULTIPLE_VERSIONS_CHECK(); | |
| 208 | |
| 209 if (unknownSite) | |
| 210 { | 206 { |
| 211 | 207 CPluginSettings* settings = CPluginSettings::GetInstance(); |
| 212 DEBUG_GENERAL(L"============================================================
====================\nNEW TAB UI\n==============================================
==================================") | 208 |
| 213 | 209 MULTIPLE_VERSIONS_CHECK(); |
| 214 HRESULT hr = ::CoInitialize(NULL); | 210 |
| 215 if (FAILED(hr)) | 211 if (unknownSite) |
| 216 { | 212 { |
| 217 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "
Class::SetSite - CoInitialize"); | 213 |
| 218 } | 214 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
====================================") |
| 219 | 215 |
| 220 s_criticalSectionBrowser.Lock(); | 216 HRESULT hr = ::CoInitialize(NULL); |
| 221 { | 217 if (FAILED(hr)) |
| 222 m_webBrowser2 = unknownSite; | |
| 223 } | |
| 224 s_criticalSectionBrowser.Unlock(); | |
| 225 | |
| 226 //register the mimefilter | |
| 227 //and only mimefilter | |
| 228 //on some few computers the mimefilter does not get properly registered when
it is done on another thread | |
| 229 | |
| 230 s_criticalSectionLocal.Lock(); | |
| 231 { | |
| 232 // Always register on startup, then check if we need to unregister in a se
parate thread | |
| 233 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | |
| 234 s_asyncWebBrowser2 = unknownSite; | |
| 235 s_instances.insert(this); | |
| 236 } | |
| 237 s_criticalSectionLocal.Unlock(); | |
| 238 | |
| 239 try | |
| 240 { | |
| 241 // Check if loaded as BHO | |
| 242 auto webBrowser = GetBrowser(); | |
| 243 if (webBrowser) | |
| 244 { | 218 { |
| 245 DEBUG_GENERAL("Loaded as BHO"); | 219 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
"Class::SetSite - CoInitialize"); |
| 246 HRESULT hr = DispEventAdvise(webBrowser); | 220 } |
| 247 if (SUCCEEDED(hr)) | 221 |
| 222 s_criticalSectionBrowser.Lock(); |
| 223 { |
| 224 m_webBrowser2 = unknownSite; |
| 225 } |
| 226 s_criticalSectionBrowser.Unlock(); |
| 227 |
| 228 //register the mimefilter |
| 229 //and only mimefilter |
| 230 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread |
| 231 |
| 232 s_criticalSectionLocal.Lock(); |
| 233 { |
| 234 // Always register on startup, then check if we need to unregister in a
separate thread |
| 235 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
| 236 s_asyncWebBrowser2 = unknownSite; |
| 237 s_instances.insert(this); |
| 238 } |
| 239 s_criticalSectionLocal.Unlock(); |
| 240 |
| 241 try |
| 242 { |
| 243 // Check if loaded as BHO |
| 244 auto webBrowser = GetBrowser(); |
| 245 if (webBrowser) |
| 248 { | 246 { |
| 249 m_isAdvised = true; | 247 DEBUG_GENERAL("Loaded as BHO"); |
| 250 try | 248 HRESULT hr = DispEventAdvise(webBrowser); |
| 249 if (SUCCEEDED(hr)) |
| 251 { | 250 { |
| 252 std::thread startInitObjectThread(StartInitObject, this); | 251 m_isAdvised = true; |
| 253 startInitObjectThread.detach(); // TODO: but actually we should wait
for the thread in the dtr. | 252 try |
| 253 { |
| 254 std::thread startInitObjectThread(StartInitObject, this); |
| 255 startInitObjectThread.detach(); // TODO: but actually we should wa
it for the thread in the dtr. |
| 256 } |
| 257 catch (const std::system_error& ex) |
| 258 { |
| 259 auto errDescription = std::string("Class::Thread - Failed to creat
e StartInitObject thread, ") + |
| 260 ex.code().message() + ex.what(); |
| 261 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERR
OR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str()); |
| 262 } |
| 254 } | 263 } |
| 255 catch (const std::system_error& ex) | 264 else |
| 256 { | 265 { |
| 257 auto errDescription = std::string("Class::Thread - Failed to create
StartInitObject thread, ") + | 266 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV
ICE, "Class::SetSite - Advice"); |
| 258 ex.code().message() + ex.what(); | |
| 259 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR
_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str()); | |
| 260 } | 267 } |
| 261 } | 268 } |
| 262 else | 269 else // Check if loaded as toolbar handler |
| 263 { | 270 { |
| 264 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC
E, "Class::SetSite - Advice"); | 271 DEBUG_GENERAL("Loaded as toolbar handler"); |
| 272 CComPtr<IServiceProvider> pServiceProvider; |
| 273 |
| 274 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); |
| 275 if (SUCCEEDED(hr)) |
| 276 { |
| 277 if (pServiceProvider) |
| 278 { |
| 279 s_criticalSectionBrowser.Lock(); |
| 280 { |
| 281 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp,
&m_webBrowser2); |
| 282 if (SUCCEEDED(hr)) |
| 283 { |
| 284 if (m_webBrowser2) |
| 285 { |
| 286 InitObject(false); |
| 287 } |
| 288 } |
| 289 else |
| 290 { |
| 291 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SI
TE_QUERY_BROWSER, "Class::SetSite - QueryService (IID_IWebBrowserApp)"); |
| 292 } |
| 293 } |
| 294 s_criticalSectionBrowser.Unlock(); |
| 295 } |
| 296 } |
| 297 else |
| 298 { |
| 299 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUE
RY_SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); |
| 300 } |
| 265 } | 301 } |
| 266 } | 302 } |
| 267 else // Check if loaded as toolbar handler | 303 catch (std::runtime_error e) |
| 268 { | 304 { |
| 269 DEBUG_GENERAL("Loaded as toolbar handler"); | 305 DEBUG_ERROR(e.what()); |
| 270 CComPtr<IServiceProvider> pServiceProvider; | 306 Unadvise(); |
| 271 | 307 } |
| 272 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); | 308 } |
| 273 if (SUCCEEDED(hr)) | 309 else |
| 310 { |
| 311 Unadvise(); |
| 312 |
| 313 // Destroy window |
| 314 if (m_pWndProcStatus) |
| 315 { |
| 316 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
dProcStatus); |
| 317 |
| 318 m_pWndProcStatus = NULL; |
| 319 } |
| 320 |
| 321 if (m_hPaneWnd) |
| 322 { |
| 323 DestroyWindow(m_hPaneWnd); |
| 324 m_hPaneWnd = NULL; |
| 325 } |
| 326 |
| 327 m_hTabWnd = NULL; |
| 328 m_hStatusBarWnd = NULL; |
| 329 |
| 330 // Remove instance from the list, shutdown threads |
| 331 HANDLE hMainThread = NULL; |
| 332 HANDLE hTabThread = NULL; |
| 333 |
| 334 s_criticalSectionLocal.Lock(); |
| 335 { |
| 336 s_instances.erase(this); |
| 337 |
| 338 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge
tCurrentThreadId()); |
| 339 if (it != s_threadInstances.end()) |
| 274 { | 340 { |
| 275 if (pServiceProvider) | 341 s_threadInstances.erase(it); |
| 276 { | |
| 277 s_criticalSectionBrowser.Lock(); | |
| 278 { | |
| 279 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, &m
_webBrowser2); | |
| 280 if (SUCCEEDED(hr)) | |
| 281 { | |
| 282 if (m_webBrowser2) | |
| 283 { | |
| 284 InitObject(false); | |
| 285 } | |
| 286 } | |
| 287 else | |
| 288 { | |
| 289 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE
_QUERY_BROWSER, "Class::SetSite - QueryService (IID_IWebBrowserApp)"); | |
| 290 } | |
| 291 } | |
| 292 s_criticalSectionBrowser.Unlock(); | |
| 293 } | |
| 294 } | 342 } |
| 295 else | 343 if (s_instances.empty()) |
| 296 { | 344 { |
| 297 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY
_SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); | 345 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr |
| 346 CPluginClientFactory::ReleaseMimeFilterClientInstance(); |
| 298 } | 347 } |
| 299 } | 348 } |
| 349 s_criticalSectionLocal.Unlock(); |
| 350 |
| 351 // Release browser interface |
| 352 s_criticalSectionBrowser.Lock(); |
| 353 { |
| 354 m_webBrowser2.Release(); |
| 355 } |
| 356 s_criticalSectionBrowser.Unlock(); |
| 357 |
| 358 DEBUG_GENERAL("===========================================================
=====================\nNEW TAB UI - END\n=======================================
=========================================") |
| 359 |
| 360 ::CoUninitialize(); |
| 300 } | 361 } |
| 301 catch (std::runtime_error e) | 362 |
| 302 { | 363 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); |
| 303 DEBUG_ERROR(e.what()); | 364 }); |
| 304 Unadvise(); | |
| 305 } | |
| 306 } | |
| 307 else | |
| 308 { | |
| 309 Unadvise(); | |
| 310 | |
| 311 // Destroy window | |
| 312 if (m_pWndProcStatus) | |
| 313 { | |
| 314 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP
rocStatus); | |
| 315 | |
| 316 m_pWndProcStatus = NULL; | |
| 317 } | |
| 318 | |
| 319 if (m_hPaneWnd) | |
| 320 { | |
| 321 DestroyWindow(m_hPaneWnd); | |
| 322 m_hPaneWnd = NULL; | |
| 323 } | |
| 324 | |
| 325 m_hTabWnd = NULL; | |
| 326 m_hStatusBarWnd = NULL; | |
| 327 | |
| 328 // Remove instance from the list, shutdown threads | |
| 329 HANDLE hMainThread = NULL; | |
| 330 HANDLE hTabThread = NULL; | |
| 331 | |
| 332 s_criticalSectionLocal.Lock(); | |
| 333 { | |
| 334 s_instances.erase(this); | |
| 335 | |
| 336 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC
urrentThreadId()); | |
| 337 if (it != s_threadInstances.end()) | |
| 338 { | |
| 339 s_threadInstances.erase(it); | |
| 340 } | |
| 341 if (s_instances.empty()) | |
| 342 { | |
| 343 // TODO: Explicitly releasing a resource when a container becomes empty
looks like a job better suited for shared_ptr | |
| 344 CPluginClientFactory::ReleaseMimeFilterClientInstance(); | |
| 345 } | |
| 346 } | |
| 347 s_criticalSectionLocal.Unlock(); | |
| 348 | |
| 349 // Release browser interface | |
| 350 s_criticalSectionBrowser.Lock(); | |
| 351 { | |
| 352 m_webBrowser2.Release(); | |
| 353 } | |
| 354 s_criticalSectionBrowser.Unlock(); | |
| 355 | |
| 356 DEBUG_GENERAL("=============================================================
===================\nNEW TAB UI - END\n=========================================
=======================================") | |
| 357 | |
| 358 ::CoUninitialize(); | |
| 359 } | |
| 360 | |
| 361 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); | |
| 362 } | 365 } |
| 363 | 366 |
| 364 bool CPluginClass::IsStatusBarEnabled() | 367 bool CPluginClass::IsStatusBarEnabled() |
| 365 { | 368 { |
| 366 DEBUG_GENERAL("IsStatusBarEnabled start"); | 369 DEBUG_GENERAL("IsStatusBarEnabled start"); |
| 367 HKEY pHkey; | 370 HKEY pHkey; |
| 368 HKEY pHkeySub; | 371 HKEY pHkeySub; |
| 369 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); | 372 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); |
| 370 DWORD truth = 1; | 373 DWORD truth = 1; |
| 371 DWORD truthSize = sizeof(truth); | 374 DWORD truthSize = sizeof(truth); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 479 |
| 477 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2( | 480 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2( |
| 478 /* [in] */ IDispatch* frameBrowserDisp, | 481 /* [in] */ IDispatch* frameBrowserDisp, |
| 479 /* [in] */ VARIANT* urlVariant, | 482 /* [in] */ VARIANT* urlVariant, |
| 480 /* [in] */ VARIANT* /*Flags*/, | 483 /* [in] */ VARIANT* /*Flags*/, |
| 481 /* [in] */ VARIANT* /*TargetFrameName*/, | 484 /* [in] */ VARIANT* /*TargetFrameName*/, |
| 482 /* [in] */ VARIANT* /*PostData*/, | 485 /* [in] */ VARIANT* /*PostData*/, |
| 483 /* [in] */ VARIANT* /*Headers*/, | 486 /* [in] */ VARIANT* /*Headers*/, |
| 484 /* [in, out] */ VARIANT_BOOL* /*Cancel*/) | 487 /* [in, out] */ VARIANT_BOOL* /*Cancel*/) |
| 485 { | 488 { |
| 486 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; | 489 EntryPoint([&] |
| 487 if (!webBrowser) | |
| 488 { | 490 { |
| 489 return; | 491 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; |
| 490 } | 492 if (!webBrowser) |
| 491 | 493 { |
| 492 if (!urlVariant || urlVariant->vt != VT_BSTR) | 494 return; |
| 493 { | 495 } |
| 494 return; | 496 |
| 495 } | 497 if (!urlVariant || urlVariant->vt != VT_BSTR) |
| 496 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); | 498 { |
| 497 UnescapeUrl(url); | 499 return; |
| 498 | 500 } |
| 499 //Register a mime filter if it's not registered yet | 501 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); |
| 500 if (s_mimeFilter == NULL) | 502 UnescapeUrl(url); |
| 501 { | 503 |
| 502 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 504 //Register a mime filter if it's not registered yet |
| 503 } | 505 if (s_mimeFilter == NULL) |
| 504 | 506 { |
| 505 CString urlCString = ToCString(url); | 507 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
| 506 | 508 } |
| 507 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na
vigating new page | 509 |
| 508 CPluginClient* client = CPluginClient::GetInstance(); | 510 CString urlCString = ToCString(url); |
| 509 | 511 |
| 510 if (urlCString.Find(L"javascript") == 0) | 512 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
navigating new page |
| 511 { | 513 CPluginClient* client = CPluginClient::GetInstance(); |
| 512 } | 514 |
| 513 else if (GetBrowser().IsEqualObject(webBrowser)) | 515 if (urlCString.Find(L"javascript") == 0) |
| 514 { | 516 { |
| 515 m_tab->OnNavigate(urlCString); | 517 } |
| 516 | 518 else if (GetBrowser().IsEqualObject(webBrowser)) |
| 517 DEBUG_GENERAL(L"============================================================
====================\nBegin main navigation url:" + urlCString + "\n============
====================================================================") | 519 { |
| 518 | 520 m_tab->OnNavigate(urlCString); |
| 521 |
| 522 DEBUG_GENERAL(L"==========================================================
======================\nBegin main navigation url:" + urlCString + "\n==========
======================================================================") |
| 523 |
| 519 #ifdef ENABLE_DEBUG_RESULT | 524 #ifdef ENABLE_DEBUG_RESULT |
| 520 CPluginDebug::DebugResultDomain(urlCString); | 525 CPluginDebug::DebugResultDomain(urlCString); |
| 521 #endif | 526 #endif |
| 522 | 527 |
| 523 UpdateStatusBar(); | 528 UpdateStatusBar(); |
| 524 } | 529 } |
| 525 else | 530 else |
| 526 { | 531 { |
| 527 DEBUG_NAVI(L"Navi::Begin navigation url:" + urlCString) | 532 DEBUG_NAVI(L"Navi::Begin navigation url:" + urlCString) |
| 528 m_tab->CacheFrame(urlCString); | 533 m_tab->CacheFrame(urlCString); |
| 529 } | 534 } |
| 535 }); |
| 530 } | 536 } |
| 531 | 537 |
| 532 void STDMETHODCALLTYPE CPluginClass::OnDownloadBegin() | 538 void STDMETHODCALLTYPE CPluginClass::OnDownloadBegin() |
| 533 { | 539 { |
| 534 DEBUG_NAVI("Navi::Download Begin") | 540 EntryPoint([&] |
| 541 { |
| 542 DEBUG_NAVI("Navi::Download Begin") |
| 543 }); |
| 535 } | 544 } |
| 536 | 545 |
| 537 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() | 546 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() |
| 538 { | 547 { |
| 539 DEBUG_NAVI("Navi::Download Complete") | 548 EntryPoint([&] |
| 540 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); | |
| 541 if (browser) | |
| 542 { | 549 { |
| 543 m_tab->OnDownloadComplete(browser); | 550 DEBUG_NAVI("Navi::Download Complete") |
| 544 } | 551 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); |
| 552 if (browser) |
| 553 { |
| 554 m_tab->OnDownloadComplete(browser); |
| 555 } |
| 556 }); |
| 545 } | 557 } |
| 546 | 558 |
| 547 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD
isp, VARIANT* /*urlOrPidl*/) | 559 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD
isp, VARIANT* /*urlOrPidl*/) |
| 548 { | 560 { |
| 549 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; | 561 EntryPoint([&] |
| 550 if (!webBrowser2) | |
| 551 { | 562 { |
| 552 return; | 563 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; |
| 553 } | 564 if (!webBrowser2) |
| 554 ATL::CString frameSrc; | 565 { |
| 555 ATL::CComBSTR locationUrl; | 566 return; |
| 556 if (FAILED(webBrowser2->get_LocationURL(&locationUrl)) && !!locationUrl) | 567 } |
| 557 { | 568 ATL::CString frameSrc; |
| 558 return; | 569 ATL::CComBSTR locationUrl; |
| 559 } | 570 if (FAILED(webBrowser2->get_LocationURL(&locationUrl)) && !!locationUrl) |
| 560 frameSrc = locationUrl; | 571 { |
| 561 CPluginClient::UnescapeUrl(frameSrc); | 572 return; |
| 562 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); | 573 } |
| 563 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser); | 574 frameSrc = locationUrl; |
| 575 CPluginClient::UnescapeUrl(frameSrc); |
| 576 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); |
| 577 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser); |
| 578 }); |
| 564 } | 579 } |
| 565 | 580 |
| 566 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) | 581 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) |
| 567 { | 582 { |
| 568 DEBUG_GENERAL("Tab changed"); | 583 EntryPoint([&] |
| 569 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLEC
MDIDF_WINDOWSTATE_ENABLED) | |
| 570 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WIN
DOWSTATE_ENABLED); | |
| 571 if (newtabshown) | |
| 572 { | 584 { |
| 573 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge
tCurrentThreadId()); | 585 DEBUG_GENERAL("Tab changed"); |
| 574 if (it == s_threadInstances.end()) | 586 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) |
| 587 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_W
INDOWSTATE_ENABLED); |
| 588 if (newtabshown) |
| 575 { | 589 { |
| 576 s_threadInstances[::GetCurrentThreadId()] = this; | 590 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(
GetCurrentThreadId()); |
| 577 if (!m_isInitializedOk) | 591 if (it == s_threadInstances.end()) |
| 578 { | 592 { |
| 579 m_isInitializedOk = true; | 593 s_threadInstances[::GetCurrentThreadId()] = this; |
| 580 InitObject(true); | 594 if (!m_isInitializedOk) |
| 581 UpdateStatusBar(); | 595 { |
| 596 m_isInitializedOk = true; |
| 597 InitObject(true); |
| 598 UpdateStatusBar(); |
| 599 } |
| 582 } | 600 } |
| 583 } | 601 } |
| 584 } | 602 notificationMessage.Hide(); |
| 585 notificationMessage.Hide(); | 603 DEBUG_GENERAL("Tab change end"); |
| 586 DEBUG_GENERAL("Tab change end"); | 604 }); |
| 587 } | 605 } |
| 588 | 606 |
| 589 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI
ANT_BOOL /*enable*/) | 607 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI
ANT_BOOL /*enable*/) |
| 590 { | 608 { |
| 591 if (m_hPaneWnd == NULL) | 609 EntryPoint([&] |
| 592 { | 610 { |
| 593 CreateStatusBarPane(); | 611 if (m_hPaneWnd == NULL) |
| 594 } | |
| 595 else | |
| 596 { | |
| 597 if (AdblockPlus::IE::InstalledMajorVersion() > 6) | |
| 598 { | 612 { |
| 599 RECT rect; | 613 CreateStatusBarPane(); |
| 600 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); | 614 } |
| 601 if (rectRes == TRUE) | 615 else |
| 616 { |
| 617 if (AdblockPlus::IE::InstalledMajorVersion() > 6) |
| 602 { | 618 { |
| 603 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom -
rect.top, TRUE); | 619 RECT rect; |
| 620 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); |
| 621 if (rectRes == TRUE) |
| 622 { |
| 623 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom
- rect.top, TRUE); |
| 624 } |
| 604 } | 625 } |
| 605 } | 626 } |
| 606 } | 627 }); |
| 607 } | 628 } |
| 608 | 629 |
| 609 bool CPluginClass::InitObject(bool bBHO) | 630 bool CPluginClass::InitObject(bool bBHO) |
| 610 { | 631 { |
| 611 DEBUG_GENERAL("InitObject"); | 632 DEBUG_GENERAL("InitObject"); |
| 612 CPluginSettings* settings = CPluginSettings::GetInstance(); | 633 CPluginSettings* settings = CPluginSettings::GetInstance(); |
| 613 | 634 |
| 614 if (!settings->GetPluginEnabled()) | 635 if (!settings->GetPluginEnabled()) |
| 615 { | 636 { |
| 616 s_mimeFilter->Unregister(); | 637 s_mimeFilter->Unregister(); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 } | 996 } |
| 976 } | 997 } |
| 977 s_criticalSectionLocal.Unlock(); | 998 s_criticalSectionLocal.Unlock(); |
| 978 | 999 |
| 979 return tab; | 1000 return tab; |
| 980 } | 1001 } |
| 981 | 1002 |
| 982 | 1003 |
| 983 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) | 1004 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) |
| 984 { | 1005 { |
| 985 if (cCmds == 0) return E_INVALIDARG; | 1006 return EntryPointWithHResult([&]()->HRESULT |
| 986 if (prgCmds == 0) return E_POINTER; | 1007 { |
| 987 | 1008 if (cCmds == 0) return E_INVALIDARG; |
| 988 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1009 if (prgCmds == 0) return E_POINTER; |
| 989 | 1010 |
| 990 return S_OK; | 1011 prgCmds[0].cmdf = OLECMDF_ENABLED; |
| 1012 |
| 1013 return S_OK; |
| 1014 }); |
| 991 } | 1015 } |
| 992 | 1016 |
| 993 HMENU CPluginClass::CreatePluginMenu(const CString& url) | 1017 HMENU CPluginClass::CreatePluginMenu(const CString& url) |
| 994 { | 1018 { |
| 995 DEBUG_GENERAL("CreatePluginMenu"); | 1019 DEBUG_GENERAL("CreatePluginMenu"); |
| 996 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1020 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
| 997 | 1021 |
| 998 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1022 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
| 999 | 1023 |
| 1000 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); | 1024 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1209 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
| 1186 fmii.cch = static_cast<UINT>(ctext.size()); | 1210 fmii.cch = static_cast<UINT>(ctext.size()); |
| 1187 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); | 1211 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); |
| 1188 | 1212 |
| 1189 return true; | 1213 return true; |
| 1190 } | 1214 } |
| 1191 | 1215 |
| 1192 | 1216 |
| 1193 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) | 1217 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) |
| 1194 { | 1218 { |
| 1195 HWND hBrowserWnd = GetBrowserHWND(); | 1219 return EntryPointWithHResult([&]()->HRESULT |
| 1196 if (!hBrowserWnd) | |
| 1197 { | 1220 { |
| 1198 return E_FAIL; | 1221 HWND hBrowserWnd = GetBrowserHWND(); |
| 1199 } | 1222 if (!hBrowserWnd) |
| 1200 | |
| 1201 // Create menu | |
| 1202 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); | |
| 1203 if (!hMenu) | |
| 1204 { | |
| 1205 return E_FAIL; | |
| 1206 } | |
| 1207 | |
| 1208 // Check if button in toolbar was pressed | |
| 1209 int nIDCommand = -1; | |
| 1210 BOOL bRightAlign = FALSE; | |
| 1211 | |
| 1212 POINT pt; | |
| 1213 GetCursorPos(&pt); | |
| 1214 | |
| 1215 HWND hWndToolBar = ::WindowFromPoint(pt); | |
| 1216 | |
| 1217 DWORD nProcessId; | |
| 1218 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | |
| 1219 | |
| 1220 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | |
| 1221 { | |
| 1222 ::ScreenToClient(hWndToolBar, &pt); | |
| 1223 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | |
| 1224 | |
| 1225 if (nButton > 0) | |
| 1226 { | 1223 { |
| 1227 TBBUTTON pTBBtn = {}; | 1224 return E_FAIL; |
| 1228 | 1225 } |
| 1229 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 1226 |
| 1227 // Create menu |
| 1228 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); |
| 1229 if (!hMenu) |
| 1230 { |
| 1231 return E_FAIL; |
| 1232 } |
| 1233 |
| 1234 // Check if button in toolbar was pressed |
| 1235 int nIDCommand = -1; |
| 1236 BOOL bRightAlign = FALSE; |
| 1237 |
| 1238 POINT pt; |
| 1239 GetCursorPos(&pt); |
| 1240 |
| 1241 HWND hWndToolBar = ::WindowFromPoint(pt); |
| 1242 |
| 1243 DWORD nProcessId; |
| 1244 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |
| 1245 |
| 1246 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |
| 1247 { |
| 1248 ::ScreenToClient(hWndToolBar, &pt); |
| 1249 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |
| 1250 |
| 1251 if (nButton > 0) |
| 1230 { | 1252 { |
| 1231 RECT rcButton; | 1253 TBBUTTON pTBBtn = {}; |
| 1232 nIDCommand = pTBBtn.idCommand; | 1254 |
| 1233 | 1255 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |
| 1234 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) | |
| 1235 { | 1256 { |
| 1236 pt.x = rcButton.left; | 1257 RECT rcButton; |
| 1237 pt.y = rcButton.bottom; | 1258 nIDCommand = pTBBtn.idCommand; |
| 1238 ClientToScreen(hWndToolBar, &pt); | 1259 |
| 1239 | 1260 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton
)) |
| 1240 RECT rcWorkArea; | |
| 1241 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
| 1242 if (rcWorkArea.right - pt.x < 150) | |
| 1243 { | 1261 { |
| 1244 bRightAlign = TRUE; | 1262 pt.x = rcButton.left; |
| 1245 pt.x = rcButton.right; | |
| 1246 pt.y = rcButton.bottom; | 1263 pt.y = rcButton.bottom; |
| 1247 ClientToScreen(hWndToolBar, &pt); | 1264 ClientToScreen(hWndToolBar, &pt); |
| 1265 |
| 1266 RECT rcWorkArea; |
| 1267 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); |
| 1268 if (rcWorkArea.right - pt.x < 150) |
| 1269 { |
| 1270 bRightAlign = TRUE; |
| 1271 pt.x = rcButton.right; |
| 1272 pt.y = rcButton.bottom; |
| 1273 ClientToScreen(hWndToolBar, &pt); |
| 1274 } |
| 1248 } | 1275 } |
| 1249 } | 1276 } |
| 1250 } | 1277 } |
| 1278 else |
| 1279 { |
| 1280 GetCursorPos(&pt); |
| 1281 } |
| 1282 } |
| 1283 |
| 1284 // Display menu |
| 1285 UINT nFlags = 0; |
| 1286 if (bRightAlign) |
| 1287 { |
| 1288 nFlags |= TPM_RIGHTALIGN; |
| 1251 } | 1289 } |
| 1252 else | 1290 else |
| 1253 { | 1291 { |
| 1254 GetCursorPos(&pt); | 1292 nFlags |= TPM_LEFTALIGN; |
| 1255 } | 1293 } |
| 1256 } | 1294 |
| 1257 | 1295 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); |
| 1258 // Display menu | 1296 |
| 1259 UINT nFlags = 0; | 1297 return S_OK; |
| 1260 if (bRightAlign) | 1298 }); |
| 1261 { | |
| 1262 nFlags |= TPM_RIGHTALIGN; | |
| 1263 } | |
| 1264 else | |
| 1265 { | |
| 1266 nFlags |= TPM_LEFTALIGN; | |
| 1267 } | |
| 1268 | |
| 1269 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | |
| 1270 | |
| 1271 return S_OK; | |
| 1272 } | 1299 } |
| 1273 | 1300 |
| 1274 ///////////////////////////////////////////////////////////////////////////// | 1301 ///////////////////////////////////////////////////////////////////////////// |
| 1275 // Window procedures | 1302 // Window procedures |
| 1276 | 1303 |
| 1277 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) | 1304 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) |
| 1278 { | 1305 { |
| 1279 // Find tab | 1306 // Find tab |
| 1280 CPluginClass *pClass = FindInstance(hWnd); | 1307 CPluginClass *pClass = FindInstance(hWnd); |
| 1281 if (!pClass) | 1308 if (!pClass) |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 CreateStatusBarPane(); | 1616 CreateStatusBarPane(); |
| 1590 } | 1617 } |
| 1591 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) | 1618 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) |
| 1592 { | 1619 { |
| 1593 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
ATE_STATUSBAR, "Class::Invalidate statusbar"); | 1620 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
ATE_STATUSBAR, "Class::Invalidate statusbar"); |
| 1594 } | 1621 } |
| 1595 } | 1622 } |
| 1596 | 1623 |
| 1597 void STDMETHODCALLTYPE CPluginClass::OnOnQuit() | 1624 void STDMETHODCALLTYPE CPluginClass::OnOnQuit() |
| 1598 { | 1625 { |
| 1599 Unadvise(); | 1626 EntryPoint([&] |
| 1627 { |
| 1628 Unadvise(); |
| 1629 }); |
| 1600 } | 1630 } |
| 1601 | 1631 |
| 1602 void CPluginClass::Unadvise() | 1632 void CPluginClass::Unadvise() |
| 1603 { | 1633 { |
| 1604 s_criticalSectionLocal.Lock(); | 1634 s_criticalSectionLocal.Lock(); |
| 1605 { | 1635 { |
| 1606 if (m_isAdvised) | 1636 if (m_isAdvised) |
| 1607 { | 1637 { |
| 1608 HRESULT hr = DispEventUnadvise(GetBrowser()); | 1638 HRESULT hr = DispEventUnadvise(GetBrowser()); |
| 1609 if (FAILED(hr)) | 1639 if (FAILED(hr)) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 } | 1735 } |
| 1706 } | 1736 } |
| 1707 } | 1737 } |
| 1708 | 1738 |
| 1709 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 1739 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |
| 1710 } | 1740 } |
| 1711 | 1741 |
| 1712 return hTabWnd; | 1742 return hTabWnd; |
| 1713 | 1743 |
| 1714 } | 1744 } |
| OLD | NEW |