Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/plugin/PluginClass.cpp

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Left Patch Set: Created July 29, 2014, 2:45 p.m.
Right Patch Set: Final (?) 2 Created Jan. 5, 2015, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 #ifdef SUPPORT_FILTER
7 #include "PluginFilter.h" 6 #include "PluginFilter.h"
8 #endif
9 #include "PluginMimeFilterClient.h" 7 #include "PluginMimeFilterClient.h"
10 #include "PluginClient.h" 8 #include "PluginClient.h"
11 #include "PluginClientFactory.h" 9 #include "PluginClientFactory.h"
12 #include "PluginMutex.h" 10 #include "PluginMutex.h"
13 #include "sddl.h" 11 #include "sddl.h"
14 #include "PluginUtil.h" 12 #include "PluginUtil.h"
15 #include "PluginUserSettings.h" 13 #include "PluginUserSettings.h"
16 #include "../shared/Utils.h" 14 #include "../shared/Utils.h"
17 #include "../shared/Dictionary.h" 15 #include "../shared/Dictionary.h"
18 #include "../shared/IE_version.h" 16 #include "../shared/IE_version.h"
19 #include <thread> 17 #include <thread>
18 #include <array>
20 19
21 #ifdef DEBUG_HIDE_EL 20 #ifdef DEBUG_HIDE_EL
22 DWORD profileTime = 0; 21 DWORD profileTime = 0;
23 #endif 22 #endif
24 23
25 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); 24 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR);
26 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT); 25 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT);
27 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); 26 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE);
28 27
29 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; 28 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL };
30 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED }; 29 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED };
31 30
32 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; 31 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL;
33 32
34 CLOSETHEMEDATA pfnClose = NULL; 33 CLOSETHEMEDATA pfnClose = NULL;
35 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; 34 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL;
36 OPENTHEMEDATA pfnOpenThemeData = NULL; 35 OPENTHEMEDATA pfnOpenThemeData = NULL;
37 36
38 ATOM CPluginClass::s_atomPaneClass = NULL; 37 ATOM CPluginClass::s_atomPaneClass = NULL;
39 HINSTANCE CPluginClass::s_hUxtheme = NULL; 38 HINSTANCE CPluginClass::s_hUxtheme = NULL;
40 std::set<CPluginClass*> CPluginClass::s_instances; 39 std::set<CPluginClass*> CPluginClass::s_instances;
41 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; 40 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances;
42 41
43 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; 42 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal;
44 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser; 43 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser;
45 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; 44 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow;
46 45
47 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; 46 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2;
48
49 #ifdef SUPPORT_WHITELIST
50 std::map<UINT,CString> CPluginClass::s_menuDomains;
51 #endif
52 47
53 /* 48 /*
54 * Without namespace declaration, the identifier "Rectangle" is ambiguous 49 * Without namespace declaration, the identifier "Rectangle" is ambiguous
55 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx 50 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx
56 */ 51 */
57 namespace AdblockPlus 52 namespace AdblockPlus
58 { 53 {
59 /** 54 /**
60 * Replacement for ATL type CRect. 55 * Replacement for ATL type CRect.
61 */ 56 */
(...skipping 24 matching lines...) Expand all
86 m_hStatusBarWnd = NULL; 81 m_hStatusBarWnd = NULL;
87 m_hPaneWnd = NULL; 82 m_hPaneWnd = NULL;
88 m_nPaneWidth = 0; 83 m_nPaneWidth = 0;
89 m_pWndProcStatus = NULL; 84 m_pWndProcStatus = NULL;
90 m_hTheme = NULL; 85 m_hTheme = NULL;
91 m_isInitializedOk = false; 86 m_isInitializedOk = false;
92 87
93 88
94 m_tab = new CPluginTab(this); 89 m_tab = new CPluginTab(this);
95 90
96 CPluginSystem* system = CPluginSystem::GetInstance(); 91 Dictionary::Create(GetBrowserLanguage());
97
98 std::wstring locale((LPCWSTR)system->GetBrowserLanguage());
99 Dictionary::Create(locale);
100 } 92 }
101 93
102 CPluginClass::~CPluginClass() 94 CPluginClass::~CPluginClass()
103 { 95 {
104 delete m_tab; 96 delete m_tab;
105 } 97 }
106 98
107 99
108 ///////////////////////////////////////////////////////////////////////////// 100 /////////////////////////////////////////////////////////////////////////////
109 // Initialization 101 // Initialization
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 241
250 242
251 // This gets called when a new browser window is created (which also triggers th e 243 // This gets called when a new browser window is created (which also triggers th e
252 // creation of this object). The pointer passed in should be to a IWebBrowser2 244 // creation of this object). The pointer passed in should be to a IWebBrowser2
253 // interface that represents the browser for the window. 245 // interface that represents the browser for the window.
254 // it is also called when a tab is closed, this unknownSite will be null 246 // it is also called when a tab is closed, this unknownSite will be null
255 // so we should handle that it is called this way several times during a session 247 // so we should handle that it is called this way several times during a session
256 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 248 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
257 { 249 {
258 CPluginSettings* settings = CPluginSettings::GetInstance(); 250 CPluginSettings* settings = CPluginSettings::GetInstance();
259 CPluginSystem* system = CPluginSystem::GetInstance();
260 251
261 MULTIPLE_VERSIONS_CHECK(); 252 MULTIPLE_VERSIONS_CHECK();
262 253
263 if (unknownSite) 254 if (unknownSite)
264 { 255 {
265 256
266 DEBUG_GENERAL(L"============================================================ ====================\nNEW TAB UI\n============================================== ==================================") 257 DEBUG_GENERAL(L"============================================================ ====================\nNEW TAB UI\n============================================== ==================================")
267 258
268 HRESULT hr = ::CoInitialize(NULL); 259 HRESULT hr = ::CoInitialize(NULL);
269 if (FAILED(hr)) 260 if (FAILED(hr))
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 { 383 {
393 s_instances.erase(this); 384 s_instances.erase(this);
394 385
395 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId()); 386 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId());
396 if (it != s_threadInstances.end()) 387 if (it != s_threadInstances.end())
397 { 388 {
398 s_threadInstances.erase(it); 389 s_threadInstances.erase(it);
399 } 390 }
400 if (s_instances.empty()) 391 if (s_instances.empty())
401 { 392 {
393 // TODO: Explicitly releasing a resource when a container becomes empty looks like a job better suited for shared_ptr
402 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 394 CPluginClientFactory::ReleaseMimeFilterClientInstance();
403 } 395 }
404 } 396 }
405 s_criticalSectionLocal.Unlock(); 397 s_criticalSectionLocal.Unlock();
406 398
407 // Release browser interface 399 // Release browser interface
408 s_criticalSectionBrowser.Lock(); 400 s_criticalSectionBrowser.Lock();
409 { 401 {
410 m_webBrowser2.Release(); 402 m_webBrowser2.Release();
411 } 403 }
412 s_criticalSectionBrowser.Unlock(); 404 s_criticalSectionBrowser.Unlock();
413 405
414 DEBUG_GENERAL("============================================================= ===================\nNEW TAB UI - END\n========================================= =======================================") 406 DEBUG_GENERAL("============================================================= ===================\nNEW TAB UI - END\n========================================= =======================================")
415 407
416 ::CoUninitialize(); 408 ::CoUninitialize();
417 } 409 }
418 410
419 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); 411 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
420 } 412 }
421 413
422 bool CPluginClass::IsStatusBarEnabled() 414 bool CPluginClass::IsStatusBarEnabled()
423 { 415 {
424 DEBUG_GENERAL("IsStatusBarEnabled start"); 416 DEBUG_GENERAL("IsStatusBarEnabled start");
425 HKEY pHkey; 417 HKEY pHkey;
426 HKEY pHkeySub; 418 HKEY pHkeySub;
427 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); 419 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey);
428 DWORD trueth = 1; 420 DWORD truth = 1;
429 DWORD truethSize = sizeof(DWORD); 421 DWORD truthSize = sizeof(truth);
430 RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\Main", &pHkeySub); 422 RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\Main", &pHkeySub);
431 LONG res = RegQueryValueEx(pHkeySub, L"StatusBarWeb", NULL, NULL, (BYTE*)&true th, &truethSize); 423 LONG res = RegQueryValueEx(pHkeySub, L"StatusBarWeb", NULL, NULL, (BYTE*)&trut h, &truthSize);
432 RegCloseKey(pHkey); 424 RegCloseKey(pHkey);
433 if (res != ERROR_SUCCESS) 425 if (res != ERROR_SUCCESS)
434 { 426 {
435 res = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\MINIE", &p HkeySub); 427 res = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\MINIE", &p HkeySub);
436 if (res == ERROR_SUCCESS) 428 if (res == ERROR_SUCCESS)
437 { 429 {
438 LONG res = RegQueryValueEx(pHkeySub, L"ShowStatusBar", NULL, NULL, (BYTE*) &trueth, &truethSize); 430 LONG res = RegQueryValueEx(pHkeySub, L"ShowStatusBar", NULL, NULL, (BYTE*) &truth, &truthSize);
439 if (res == ERROR_SUCCESS) 431 if (res == ERROR_SUCCESS)
440 { 432 {
441 RegCloseKey(pHkey); 433 RegCloseKey(pHkey);
442 } 434 }
443 } 435 }
444 } 436 }
445 DEBUG_GENERAL("IsStatusBarEnabled end"); 437 DEBUG_GENERAL("IsStatusBarEnabled end");
446 return trueth == 1; 438 return truth == 1;
447 } 439 }
448 440
449 void CPluginClass::ShowStatusBar() 441 void CPluginClass::ShowStatusBar()
450 { 442 {
451 DEBUG_GENERAL("ShowStatusBar start"); 443 DEBUG_GENERAL("ShowStatusBar start");
452 444
453 VARIANT_BOOL isVisible; 445 VARIANT_BOOL isVisible;
454 446
455 447
456 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 448 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
(...skipping 24 matching lines...) Expand all
481 MB_OK); 473 MB_OK);
482 return; 474 return;
483 } 475 }
484 // Ask if a user wants to enable a status bar automatically 476 // Ask if a user wants to enable a status bar automatically
485 LRESULT res = MessageBox((HWND)m_hTabWnd, 477 LRESULT res = MessageBox((HWND)m_hTabWnd,
486 dictionary->Lookup("status-bar", "question").c_str(), 478 dictionary->Lookup("status-bar", "question").c_str(),
487 dictionary->Lookup("status-bar", "title").c_str(), 479 dictionary->Lookup("status-bar", "title").c_str(),
488 MB_YESNO); 480 MB_YESNO);
489 if (res == IDYES) 481 if (res == IDYES)
490 { 482 {
491 DWORD trueth = 1; 483 DWORD truth = 1;
492 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M INIE", &pHkeySub); 484 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M INIE", &pHkeySub);
493 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE *)&trueth, sizeof(DWORD)); 485 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE *)&truth, sizeof(truth));
494 regRes = RegCloseKey(pHkeySub); 486 regRes = RegCloseKey(pHkeySub);
495 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M ain", &pHkeySub); 487 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M ain", &pHkeySub);
496 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE* )&trueth, sizeof(DWORD)); 488 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE* )&truth, sizeof(truth));
497 regRes = RegCloseKey(pHkeySub); 489 regRes = RegCloseKey(pHkeySub);
498 hr = browser->put_StatusBar(TRUE); 490 hr = browser->put_StatusBar(TRUE);
499 if (FAILED(hr)) 491 if (FAILED(hr))
500 { 492 {
501 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, "Class::Enable statusbar"); 493 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, "Class::Enable statusbar");
502 } 494 }
503 CreateStatusBarPane(); 495 CreateStatusBarPane();
504 496
505 // We need to restart the tab now, to enable the status bar properly 497 // We need to restart the tab now, to enable the status bar properly
506 VARIANT vFlags; 498 VARIANT vFlags;
(...skipping 18 matching lines...) Expand all
525 } 517 }
526 } 518 }
527 else 519 else
528 { 520 {
529 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state"); 521 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
530 } 522 }
531 } 523 }
532 DEBUG_GENERAL("ShowStatusBar end"); 524 DEBUG_GENERAL("ShowStatusBar end");
533 } 525 }
534 526
527 /*
528 * #1163 This class is the implementation for method DISPID_BEFORENAVIGATE2 in C PluginClass::Invoke.
529 * - It validates and convertes its own arguments, rather than unifying them in the Invoke body.
530 * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu rn S_OK.
531 */
535 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) 532 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams)
536 { 533 {
537 534
538 if (pDispParams->cArgs < 7) 535 if (pDispParams->cArgs < 7)
539 { 536 {
540 return; 537 return;
541 } 538 }
542 //Register a mime filter if it's not registered yet 539 //Register a mime filter if it's not registered yet
543 if (s_mimeFilter == NULL) 540 if (s_mimeFilter == NULL)
544 { 541 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 584
588 #ifdef ENABLE_DEBUG_RESULT 585 #ifdef ENABLE_DEBUG_RESULT
589 CPluginDebug::DebugResultDomain(url); 586 CPluginDebug::DebugResultDomain(url);
590 #endif 587 #endif
591 588
592 UpdateStatusBar(); 589 UpdateStatusBar();
593 } 590 }
594 else 591 else
595 { 592 {
596 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 593 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
597 594 m_tab->CacheFrame(url);
598 #ifdef SUPPORT_FRAME_CACHING 595 }
599 m_tab->CacheFrame(url); 596 }
600 #endif 597
601 } 598 /*
602 } 599 * #1163 implements behavior for method DISPID_WINDOWSTATECHANGED in CPluginClas s::Invoke
600 * - should validate and convert arguments in Invoke, not here
601 * - does not validate number of arguments before indexing into 'rgvarg'
602 * - does not validate type of argument before using its value
603 */
603 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) 604 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags)
604 { 605 {
605 DEBUG_GENERAL("Tab changed"); 606 DEBUG_GENERAL("Tab changed");
606 bool newtabshown = pDispParams->rgvarg[1].intVal==3; 607 bool newtabshown = pDispParams->rgvarg[1].intVal==3;
607 if (newtabshown) 608 if (newtabshown)
608 { 609 {
609 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); 610 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId());
610 if (it == s_threadInstances.end()) 611 if (it == s_threadInstances.end())
611 { 612 {
612 s_threadInstances[::GetCurrentThreadId()] = this; 613 s_threadInstances[::GetCurrentThreadId()] = this;
613
614
615 if (!m_isInitializedOk) 614 if (!m_isInitializedOk)
616 { 615 {
617 m_isInitializedOk = true; 616 m_isInitializedOk = true;
618 if (!InitObject(true)) 617 InitObject(true);
619 {
620 //» » » » » Unadvice();
621 }
622 UpdateStatusBar(); 618 UpdateStatusBar();
623 } 619 }
624 } 620 }
625 } 621 }
626 notificationMessage.Hide(); 622 notificationMessage.Hide();
627 DEBUG_GENERAL("Tab change end"); 623 DEBUG_GENERAL("Tab change end");
628 return VARIANT_TRUE; 624 return S_OK;
629 } 625 }
630 626
631 // This gets called whenever there's a browser event 627 // This gets called whenever there's a browser event
628 // ENTRY POINT
632 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) 629 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
633 { 630 {
634 WCHAR tmp[256]; 631 try
635 wsprintf(tmp, L"Invoke: %d\n", dispidMember); 632 {
636 DEBUG_GENERAL(tmp); 633 WCHAR tmp[256];
637 switch (dispidMember) 634 wsprintf(tmp, L"Invoke: %d\n", dispidMember);
638 { 635 DEBUG_GENERAL(tmp);
639 636 switch (dispidMember)
640 case DISPID_WINDOWSTATECHANGED: 637 {
641 return OnTabChanged(pDispParams, wFlags); 638 case DISPID_WINDOWSTATECHANGED:
642 break; 639 {
643 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE: 640 // #1163 should validate and convert arguments here
644 return VARIANT_TRUE; 641 return OnTabChanged(pDispParams, wFlags);
645 break; 642 }
646 643
647 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK: 644 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE:
648 return VARIANT_TRUE; 645 break;
649 break; 646
650 647 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK:
651 case DISPID_EVMETH_ONLOAD: 648 break;
652 DEBUG_NAVI("Navi::OnLoad") 649
653 return VARIANT_TRUE; 650 case DISPID_EVMETH_ONLOAD:
654 break; 651 DEBUG_NAVI("Navi::OnLoad")
655 652 break;
656 case DISPID_EVMETH_ONCHANGE: 653
657 return VARIANT_TRUE; 654 case DISPID_EVMETH_ONCHANGE:
658 655 break;
659 case DISPID_EVMETH_ONMOUSEDOWN: 656
660 return VARIANT_TRUE; 657 case DISPID_EVMETH_ONMOUSEDOWN:
661 658 break;
662 case DISPID_EVMETH_ONMOUSEENTER: 659
663 return VARIANT_TRUE; 660 case DISPID_EVMETH_ONMOUSEENTER:
664 661 break;
665 case DISPID_IHTMLIMGELEMENT_START: 662
666 return VARIANT_TRUE; 663 case DISPID_IHTMLIMGELEMENT_START:
667 664 break;
668 case STDDISPID_XOBJ_ERRORUPDATE: 665
669 return VARIANT_TRUE; 666 case STDDISPID_XOBJ_ERRORUPDATE:
670 667 break;
671 case STDDISPID_XOBJ_ONPROPERTYCHANGE: 668
672 return VARIANT_TRUE; 669 case STDDISPID_XOBJ_ONPROPERTYCHANGE:
673 670 break;
674 case DISPID_READYSTATECHANGE: 671
675 DEBUG_NAVI("Navi::ReadyStateChange") 672 case DISPID_READYSTATECHANGE:
676 return VARIANT_TRUE; 673 DEBUG_NAVI("Navi::ReadyStateChange");
677 674 break;
678 case DISPID_BEFORENAVIGATE: 675
679 DEBUG_NAVI("Navi::BeforeNavigate") 676 case DISPID_BEFORENAVIGATE:
680 return VARIANT_TRUE; 677 DEBUG_NAVI("Navi::BeforeNavigate");
681 case DISPID_COMMANDSTATECHANGE: 678 break;
682 if (m_hPaneWnd == NULL) 679
683 { 680 case DISPID_COMMANDSTATECHANGE:
684 CreateStatusBarPane(); 681 if (m_hPaneWnd == NULL)
685 } 682 {
686 else 683 CreateStatusBarPane();
687 { 684 }
685 else
686 {
688 if (AdblockPlus::IE::InstalledMajorVersion() > 6) 687 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
689 { 688 {
690 RECT rect; 689 RECT rect;
691 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); 690 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect);
692 if (rectRes == TRUE) 691 if (rectRes == TRUE)
693 { 692 {
694 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom - rect.top, TRUE); 693 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.botto m - rect.top, TRUE);
695 } 694 }
696 } 695 }
697 } 696 }
698 break; 697 break;
699 case DISPID_STATUSTEXTCHANGE: 698
700 break; 699 case DISPID_STATUSTEXTCHANGE:
701 700 break;
702 case DISPID_BEFORENAVIGATE2: 701
703 BeforeNavigate2(pDispParams); 702 case DISPID_BEFORENAVIGATE2:
704 break; 703 {
705 704 // #1163 should validate and convert parameters here
706 case DISPID_DOWNLOADBEGIN: 705 BeforeNavigate2(pDispParams);
707 { 706 }
708 DEBUG_NAVI("Navi::Download Begin") 707 break;
709 } 708
710 break; 709 case DISPID_DOWNLOADBEGIN:
711 710 {
712 case DISPID_DOWNLOADCOMPLETE: 711 DEBUG_NAVI("Navi::Download Begin")
713 { 712 }
714 DEBUG_NAVI("Navi::Download Complete") 713 break;
715 714
715 case DISPID_DOWNLOADCOMPLETE:
716 {
717 DEBUG_NAVI("Navi::Download Complete");
716 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 718 CComQIPtr<IWebBrowser2> browser = GetBrowser();
717 if (browser) 719 if (browser)
718 { 720 {
719 m_tab->OnDownloadComplete(browser); 721 m_tab->OnDownloadComplete(browser);
720 } 722 }
721 } 723 }
722 break; 724 break;
723 725
724 case DISPID_DOCUMENTCOMPLETE: 726 case DISPID_DOCUMENTCOMPLETE:
725 { 727 {
726 DEBUG_NAVI("Navi::Document Complete") 728 DEBUG_NAVI("Navi::Document Complete");
727
728 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 729 CComQIPtr<IWebBrowser2> browser = GetBrowser();
729 730 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V T_DISPATCH)
730 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH) 731 {
731 { 732 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
732 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; 733 if (pBrowser)
733 if (pBrowser)
734 {
735 CString url;
736 CComBSTR bstrUrl;
737 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0)
738 { 734 {
739 url = bstrUrl; 735 CString url;
740 736 CComBSTR bstrUrl;
741 CPluginClient::UnescapeUrl(url); 737 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen (bstrUrl) > 0)
742 738 {
743 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er)); 739 url = bstrUrl;
740 CPluginClient::UnescapeUrl(url);
741 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBro wser));
742 }
744 } 743 }
745 } 744 }
746 } 745 }
747 } 746 break;
748 break; 747
749 748 case DISPID_ONQUIT:
750 case DISPID_ONQUIT: 749 case DISPID_QUIT:
751 case DISPID_QUIT: 750 {
752 { 751 Unadvice();
753 Unadvice(); 752 }
754 } 753 break;
755 break; 754
756 755 default:
757 default: 756 {
758 { 757 CString did;
759 CString did; 758 did.Format(L"DispId:%u", dispidMember);
760 did.Format(L"DispId:%u", dispidMember); 759
761 760 DEBUG_NAVI(L"Navi::Default " + did)
762 DEBUG_NAVI(L"Navi::Default " + did) 761 }
763 } 762 /*
764 763 * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND.
765 // do nothing 764 * As a conservative initial change, we leave it behaving as before,
766 break; 765 * which is to do nothing and return S_OK.
767 } 766 */
768 767 // do nothing
769 return VARIANT_TRUE; 768 break;
769 }
770 }
771 catch(...)
772 {
773 DEBUG_GENERAL( "Caught unknown exception in CPluginClass::Invoke" );
774 return E_FAIL;
775 }
776 return S_OK;
770 } 777 }
771 778
772 bool CPluginClass::InitObject(bool bBHO) 779 bool CPluginClass::InitObject(bool bBHO)
773 { 780 {
774 DEBUG_GENERAL("InitObject"); 781 DEBUG_GENERAL("InitObject");
775 CPluginSettings* settings = CPluginSettings::GetInstance(); 782 CPluginSettings* settings = CPluginSettings::GetInstance();
776 783
777 if (!settings->GetPluginEnabled()) 784 if (!settings->GetPluginEnabled())
778 { 785 {
779 s_mimeFilter->Unregister(); 786 s_mimeFilter->Unregister();
780 } 787 }
781 788
782 // Load theme module 789 // Load theme module
783 s_criticalSectionLocal.Lock(); 790 s_criticalSectionLocal.Lock();
784 { 791 {
785 if (!s_hUxtheme) 792 if (!s_hUxtheme)
786 { 793 {
787 s_hUxtheme = ::GetModuleHandle(_T("uxtheme.dll")); 794 s_hUxtheme = ::GetModuleHandle(L"uxtheme.dll");
788 if (s_hUxtheme) 795 if (s_hUxtheme)
789 { 796 {
790 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData" ); 797 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData" );
791 if (!pfnClose) 798 if (!pfnClose)
792 { 799 {
793 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_CLOSE, "Class::InitObject - GetProcAddress(CloseThemeData)"); 800 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_CLOSE, "Class::InitObject - GetProcAddress(CloseThemeData)");
794 } 801 }
795 802
796 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem e, "DrawThemeBackground"); 803 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem e, "DrawThemeBackground");
797 if (!pfnDrawThemeBackground) 804 if (!pfnDrawThemeBackground)
(...skipping 13 matching lines...) Expand all
811 } 818 }
812 } 819 }
813 } 820 }
814 s_criticalSectionLocal.Unlock(); 821 s_criticalSectionLocal.Unlock();
815 822
816 // Register pane class 823 // Register pane class
817 if (!GetAtomPaneClass()) 824 if (!GetAtomPaneClass())
818 { 825 {
819 WNDCLASSEX wcex; 826 WNDCLASSEX wcex;
820 827
821 wcex.cbSize = sizeof(WNDCLASSEX); 828 wcex.cbSize = sizeof(wcex);
822 wcex.style = 0; 829 wcex.style = 0;
823 wcex.lpfnWndProc = (WNDPROC)PaneWindowProc; 830 wcex.lpfnWndProc = (WNDPROC)PaneWindowProc;
824 wcex.cbClsExtra = 0; 831 wcex.cbClsExtra = 0;
825 wcex.cbWndExtra = 0; 832 wcex.cbWndExtra = 0;
826 wcex.hInstance = _Module.m_hInst; 833 wcex.hInstance = _Module.m_hInst;
827 wcex.hIcon = NULL; 834 wcex.hIcon = NULL;
828 wcex.hCursor = NULL; 835 wcex.hCursor = NULL;
829 wcex.hbrBackground = NULL; 836 wcex.hbrBackground = NULL;
830 wcex.lpszMenuName = NULL; 837 wcex.lpszMenuName = NULL;
831 wcex.lpszClassName = _T(STATUSBAR_PANE_NAME); 838 wcex.lpszClassName = STATUSBAR_PANE_NAME;
832 wcex.hIconSm = NULL; 839 wcex.hIconSm = NULL;
833 840
834 s_criticalSectionLocal.Lock(); 841 s_criticalSectionLocal.Lock();
835 { 842 {
836 s_atomPaneClass = ::RegisterClassEx(&wcex); 843 s_atomPaneClass = ::RegisterClassEx(&wcex);
837 } 844 }
838 s_criticalSectionLocal.Unlock(); 845 s_criticalSectionLocal.Unlock();
839 846
840 if (!GetAtomPaneClass()) 847 if (!GetAtomPaneClass())
841 { 848 {
842 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx"); 849 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx");
843 return false; 850 return false;
844 } 851 }
845 } 852 }
846 853
847 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); 854 int ieVersion = AdblockPlus::IE::InstalledMajorVersion();
848 // Create status pane 855 // Create status pane
849 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) 856 if (bBHO && ieVersion > 6 && !CreateStatusBarPane())
850 { 857 {
851 return false; 858 return false;
852 } 859 }
853 860
854 if (CPluginClient::GetInstance()->IsFirstRun()) 861 s_criticalSectionLocal.Lock();
862 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2");
863
864 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun();
865 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN _VERSION));
866 // This is the first time ABP was installed
867 // Or ABP was updated from the version that did not support Acceptable Ads (<1 .2)
868 if (isFirstRun || versionCompRes < 0)
855 { 869 {
870 if (!isFirstRun)
871 {
872 CPluginClient::GetInstance()->SetPref(L"displayUpdatePage", true);
873 }
874
856 // IE6 can't be accessed from another thread, execute in current thread 875 // IE6 can't be accessed from another thread, execute in current thread
857 if (ieVersion < 7) 876 if (ieVersion < 7)
858 { 877 {
859 FirstRunThread(); 878 FirstRunThread();
860 } 879 }
861 else 880 else
862 { 881 {
863 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CPluginClass::FirstRunThr ead, NULL, NULL, NULL); 882 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CPluginClass::FirstRunThr ead, NULL, NULL, NULL);
864 } 883 }
865 if ((m_hPaneWnd == NULL) || (!IsStatusBarEnabled())) 884 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun)
866 { 885 {
867 ShowStatusBar(); 886 ShowStatusBar();
868 } 887 }
869 888
870 } 889 // Enable acceptable ads by default
890 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L"");
891 CPluginClient::GetInstance()->AddSubscription(aaUrl);
892 }
893 s_criticalSectionLocal.Unlock();
871 return true; 894 return true;
872 } 895 }
873 896
874 bool CPluginClass::CreateStatusBarPane() 897 bool CPluginClass::CreateStatusBarPane()
875 { 898 {
876 CriticalSection::Lock lock(m_csStatusBar); 899 CriticalSection::Lock lock(m_csStatusBar);
877 900
878 CPluginClient* client = CPluginClient::GetInstance(); 901 CPluginClient* client = CPluginClient::GetInstance();
879 902
880 TCHAR szClassName[MAX_PATH]; 903 std::array<wchar_t, MAX_PATH> className;
881 // Get browser window and url 904 // Get browser window and url
882 HWND hBrowserWnd = GetBrowserHWND(); 905 HWND hBrowserWnd = GetBrowserHWND();
883 if (!hBrowserWnd) 906 if (!hBrowserWnd)
884 { 907 {
885 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::CreateStatusBarPane - No status bar") 908 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::CreateStatusBarPane - No status bar")
886 return false; 909 return false;
887 } 910 }
888 911
889 // Looking for a TabWindowClass window in IE7 912 // Looking for a TabWindowClass window in IE7
890 // the last one should be parent for statusbar 913 // the last one should be parent for statusbar
891 HWND hWndStatusBar = NULL; 914 HWND hWndStatusBar = NULL;
892 915
893 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 916 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
894 UINT amoundOfNewTabs = 0; 917 UINT amoundOfNewTabs = 0;
895 HWND uniqueNewTab = NULL; 918 HWND uniqueNewTab = NULL;
896 while (hTabWnd) 919 while (hTabWnd)
897 { 920 {
898 memset(szClassName, 0, MAX_PATH); 921 className[0] = L'\0';
899 GetClassName(hTabWnd, szClassName, MAX_PATH); 922 // GetClassNameW returns the number of characters without '\0'
900 923 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz e());
901 if (_tcscmp(szClassName, _T("TabWindowClass")) == 0 || _tcscmp(szClassName,_ T("Frame Tab")) == 0) 924
925 if (classNameLength && (wcscmp(className.data(), L"TabWindowClass") == 0 || wcscmp(className.data(), L"Frame Tab") == 0))
902 { 926 {
903 // IE8 support 927 // IE8 support
904 HWND hTabWnd2 = hTabWnd; 928 HWND hTabWnd2 = hTabWnd;
905 if (_tcscmp(szClassName,_T("Frame Tab")) == 0) 929 if (wcscmp(className.data(), L"Frame Tab") == 0)
906 { 930 {
907 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, _T("TabWindowClass"), NULL); 931 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL);
908 } 932 }
909 933
910 if (hTabWnd2) 934 if (hTabWnd2)
911 { 935 {
912 DWORD nProcessId; 936 DWORD nProcessId;
913 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); 937 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
914 if (::GetCurrentProcessId() == nProcessId) 938 if (::GetCurrentProcessId() == nProcessId)
915 { 939 {
916 bool bExistingTab = false; 940 bool bExistingTab = false;
917 941
(...skipping 24 matching lines...) Expand all
942 } 966 }
943 } 967 }
944 } 968 }
945 969
946 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 970 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
947 } 971 }
948 972
949 HWND hWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 973 HWND hWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
950 while (hWnd) 974 while (hWnd)
951 { 975 {
952 memset(szClassName, 0, MAX_PATH); 976 className[0] = L'\0';
953 ::GetClassName(hWnd, szClassName, MAX_PATH); 977 int classNameLength = GetClassNameW(hWnd, className.data(), className.size() );
954 978
955 if (_tcscmp(szClassName,_T("msctls_statusbar32")) == 0) 979 if (classNameLength && wcscmp(className.data(), L"msctls_statusbar32") == 0)
956 { 980 {
957 hWndStatusBar = hWnd; 981 hWndStatusBar = hWnd;
958 break; 982 break;
959 } 983 }
960 984
961 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); 985 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT);
962 } 986 }
963 987
964 if (!hWndStatusBar) 988 if (!hWndStatusBar)
965 { 989 {
(...skipping 18 matching lines...) Expand all
984 #ifdef _DEBUG 1008 #ifdef _DEBUG
985 m_nPaneWidth = 70; 1009 m_nPaneWidth = 70;
986 #else 1010 #else
987 m_nPaneWidth = 22; 1011 m_nPaneWidth = 22;
988 #endif 1012 #endif
989 } 1013 }
990 // Create pane window 1014 // Create pane window
991 HWND hWndNewPane = ::CreateWindowEx( 1015 HWND hWndNewPane = ::CreateWindowEx(
992 NULL, 1016 NULL,
993 MAKEINTATOM(GetAtomPaneClass()), 1017 MAKEINTATOM(GetAtomPaneClass()),
994 _T(""), 1018 L"",
995 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 1019 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
996 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), 1020 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(),
997 hWndStatusBar, 1021 hWndStatusBar,
998 (HMENU)3671, 1022 (HMENU)3671,
999 _Module.m_hInst, 1023 _Module.m_hInst,
1000 NULL); 1024 NULL);
1001 1025
1002 if (!hWndNewPane) 1026 if (!hWndNewPane)
1003 { 1027 {
1004 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx") 1028 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx")
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1166 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1143 1167
1144 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1168 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1145 1169
1146 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); 1170 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);
1147 1171
1148 SetMenuBar(hMenuTrackPopup, url); 1172 SetMenuBar(hMenuTrackPopup, url);
1149 1173
1150 return hMenuTrackPopup; 1174 return hMenuTrackPopup;
1151 } 1175 }
1152 BOOL CreateLowProcess(WCHAR* wszProcessName, WCHAR* cmdLine)
1153 {
1154
1155 BOOL fRet;
1156 HANDLE hToken = NULL;
1157 HANDLE hNewToken = NULL;
1158 PSID pIntegritySid = NULL;
1159 TOKEN_MANDATORY_LABEL TIL = {0};
1160 PROCESS_INFORMATION ProcInfo = {0};
1161 STARTUPINFO StartupInfo = {0};
1162
1163
1164
1165 // Low integrity SID
1166 WCHAR wszIntegritySid[20] = L"S-1-16-4096";
1167
1168
1169 fRet = OpenProcessToken(GetCurrentProcess(),
1170 TOKEN_DUPLICATE |
1171 TOKEN_ADJUST_DEFAULT |
1172 TOKEN_QUERY |
1173 TOKEN_ASSIGN_PRIMARY,
1174 &hToken);
1175
1176 if (!fRet)
1177 {
1178 goto CleanExit;
1179 }
1180
1181 fRet = DuplicateTokenEx(hToken,
1182 0,
1183 NULL,
1184 SecurityImpersonation,
1185 TokenPrimary,
1186 &hNewToken);
1187
1188 if (!fRet)
1189 {
1190 goto CleanExit;
1191 }
1192
1193 fRet = ConvertStringSidToSid(wszIntegritySid, &pIntegritySid);
1194
1195 if (!fRet)
1196 {
1197 goto CleanExit;
1198 }
1199
1200
1201 TIL.Label.Attributes = SE_GROUP_INTEGRITY;
1202 TIL.Label.Sid = pIntegritySid;
1203
1204
1205 //
1206 // Set the process integrity level
1207 //
1208
1209 fRet = SetTokenInformation(hNewToken,
1210 TokenIntegrityLevel,
1211 &TIL,
1212 sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(pIntegritySid));
1213
1214 if (!fRet)
1215 {
1216 goto CleanExit;
1217 }
1218
1219 //
1220 // Create the new process at Low integrity
1221 //
1222
1223 fRet = CreateProcessAsUser(hNewToken,
1224 wszProcessName,
1225 cmdLine,
1226 NULL,
1227 NULL,
1228 FALSE,
1229 0,
1230 NULL,
1231 NULL,
1232 &StartupInfo,
1233 &ProcInfo);
1234
1235
1236 CleanExit:
1237
1238 if (ProcInfo.hProcess != NULL)
1239 {
1240 CloseHandle(ProcInfo.hProcess);
1241 }
1242
1243 if (ProcInfo.hThread != NULL)
1244 {
1245 CloseHandle(ProcInfo.hThread);
1246 }
1247
1248 LocalFree(pIntegritySid);
1249
1250 if (hNewToken != NULL)
1251 {
1252 CloseHandle(hNewToken);
1253 }
1254
1255 if (hToken != NULL)
1256 {
1257 CloseHandle(hToken);
1258 }
1259
1260 return fRet;
1261 }
1262 1176
1263 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U INT nMenuFlags) 1177 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U INT nMenuFlags)
1264 { 1178 {
1265 CPluginClient* client = CPluginClient::GetInstance(); 1179 CPluginClient* client = CPluginClient::GetInstance();
1266
1267 CPluginSystem* system = CPluginSystem::GetInstance();
1268 1180
1269 // Create menu parent window 1181 // Create menu parent window
1270 HWND hMenuWnd = ::CreateWindowEx( 1182 HWND hMenuWnd = ::CreateWindowEx(
1271 NULL, 1183 NULL,
1272 MAKEINTATOM(GetAtomPaneClass()), 1184 MAKEINTATOM(GetAtomPaneClass()),
1273 _T(""), 1185 L"",
1274 0, 1186 0,
1275 0,0,0,0, 1187 0,0,0,0,
1276 NULL, 1188 NULL,
1277 NULL, 1189 NULL,
1278 _Module.m_hInst, 1190 _Module.m_hInst,
1279 NULL); 1191 NULL);
1280 1192
1281 if (!hMenuWnd) 1193 if (!hMenuWnd)
1282 { 1194 {
1283 DestroyMenu(hMenu); 1195 DestroyMenu(hMenu);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1261 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1350 } 1262 }
1351 } 1263 }
1352 } 1264 }
1353 break; 1265 break;
1354 } 1266 }
1355 case ID_MENU_DISABLE_ON_SITE: 1267 case ID_MENU_DISABLE_ON_SITE:
1356 { 1268 {
1357 CPluginSettings* settings = CPluginSettings::GetInstance(); 1269 CPluginSettings* settings = CPluginSettings::GetInstance();
1358 CString urlString = GetTab()->GetDocumentUrl(); 1270 CString urlString = GetTab()->GetDocumentUrl();
1359 if (client->IsWhitelistedUrl(std::wstring(urlString))) 1271 if (client->IsWhitelistedUrl(to_wstring(urlString)))
1360 { 1272 {
1361 settings->RemoveWhiteListedDomain(client->GetHostFromUrl(urlString.GetSt ring()).c_str()); 1273 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w string(urlString))));
1362 } 1274 }
1363 else 1275 else
1364 { 1276 {
1365 settings->AddWhiteListedDomain(client->GetHostFromUrl(urlString.GetStrin g()).c_str()); 1277 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr ing(urlString))));
1366 } 1278 }
1367 GetBrowser()->Refresh(); 1279 GetBrowser()->Refresh();
1368 } 1280 }
1369 default: 1281 default:
1370 break; 1282 break;
1371 } 1283 }
1372 1284
1373 // Invalidate and redraw the control 1285 // Invalidate and redraw the control
1374 UpdateStatusBar(); 1286 UpdateStatusBar();
1375 } 1287 }
1376 1288
1377 1289
1378 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) 1290 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url)
1379 { 1291 {
1380 DEBUG_GENERAL("SetMenuBar"); 1292 DEBUG_GENERAL("SetMenuBar");
1381 1293
1382 std::wstring ctext; 1294 std::wstring ctext;
1383
1384 s_criticalSectionLocal.Lock();
1385 {
1386 #ifdef SUPPORT_WHITELIST
1387 s_menuDomains.clear();
1388 #endif
1389 }
1390 s_criticalSectionLocal.Unlock();
1391
1392
1393 Dictionary* dictionary = Dictionary::GetInstance(); 1295 Dictionary* dictionary = Dictionary::GetInstance();
1394 1296
1395 MENUITEMINFOW fmii; 1297 MENUITEMINFOW fmii = {};
1396 memset(&fmii, 0, sizeof(MENUITEMINFO)); 1298 fmii.cbSize = sizeof(fmii);
1397 fmii.cbSize = sizeof(MENUITEMINFO); 1299
1398 1300 MENUITEMINFOW miiSep = {};
1399 MENUITEMINFOW miiSep; 1301 miiSep.cbSize = sizeof(miiSep);
1400 memset(&miiSep, 0, sizeof(MENUITEMINFO));
1401 miiSep.cbSize = sizeof(MENUITEMINFO);
1402 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1302 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1403 miiSep.fType = MFT_SEPARATOR; 1303 miiSep.fType = MFT_SEPARATOR;
1404 1304
1405 CPluginClient* client = CPluginClient::GetInstance(); 1305 CPluginClient* client = CPluginClient::GetInstance();
1406
1407 CPluginSettings* settings = CPluginSettings::GetInstance(); 1306 CPluginSettings* settings = CPluginSettings::GetInstance();
1408
1409 #ifdef SUPPORT_WHITELIST
1410 { 1307 {
1411 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1308 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1412 // Is domain in white list? 1309 // Is domain in white list?
1413 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url.GetString())); 1310 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url)));
1414 if (client->IsWhitelistedUrl(std::wstring(GetTab()->GetDocumentUrl()))) 1311 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl())))
1415 { 1312 {
1416 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1313 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1417 } 1314 }
1418 else 1315 else
1419 { 1316 {
1420 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1317 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1421 } 1318 }
1422 fmii.fMask = MIIM_STRING | MIIM_STATE; 1319 fmii.fMask = MIIM_STRING | MIIM_STATE;
1423 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1320 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1424 fmii.cch = static_cast<UINT>(ctext.size()); 1321 fmii.cch = static_cast<UINT>(ctext.size());
1425 1322
1426 ::SetMenuItemInfoW(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE, &fmii); 1323 ::SetMenuItemInfoW(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE, &fmii);
1427 } 1324 }
1428 #else
1429 {
1430 ::DeleteMenu(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE);
1431 }
1432 #endif // SUPPORT_WHITELIST
1433 1325
1434 // Plugin update 1326 // Plugin update
1435 ctext = dictionary->Lookup("menu", "menu-update"); 1327 ctext = dictionary->Lookup("menu", "menu-update");
1436 fmii.fMask = MIIM_STATE | MIIM_STRING; 1328 fmii.fMask = MIIM_STATE | MIIM_STRING;
1437 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED; 1329 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED;
1438 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1330 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1439 fmii.cch = static_cast<UINT>(ctext.size()); 1331 fmii.cch = static_cast<UINT>(ctext.size());
1440 ::SetMenuItemInfoW(hMenu, ID_MENU_UPDATE, FALSE, &fmii); 1332 ::SetMenuItemInfoW(hMenu, ID_MENU_UPDATE, FALSE, &fmii);
1441 1333
1442 1334
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 DWORD nProcessId; 1386 DWORD nProcessId;
1495 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); 1387 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId);
1496 1388
1497 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) 1389 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId)
1498 { 1390 {
1499 ::ScreenToClient(hWndToolBar, &pt); 1391 ::ScreenToClient(hWndToolBar, &pt);
1500 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); 1392 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt);
1501 1393
1502 if (nButton > 0) 1394 if (nButton > 0)
1503 { 1395 {
1504 TBBUTTON pTBBtn; 1396 TBBUTTON pTBBtn = {};
1505 memset(&pTBBtn, 0, sizeof(TBBUTTON));
1506 1397
1507 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) 1398 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn))
1508 { 1399 {
1509 RECT rcButton; 1400 RECT rcButton;
1510 nIDCommand = pTBBtn.idCommand; 1401 nIDCommand = pTBBtn.idCommand;
1511 1402
1512 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) 1403 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton))
1513 { 1404 {
1514 pt.x = rcButton.left; 1405 pt.x = rcButton.left;
1515 pt.y = rcButton.bottom; 1406 pt.y = rcButton.bottom;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 1524
1634 HICON CPluginClass::GetStatusBarIcon(const CString& url) 1525 HICON CPluginClass::GetStatusBarIcon(const CString& url)
1635 { 1526 {
1636 // use the disable icon as defualt, if the client doesn't exists 1527 // use the disable icon as defualt, if the client doesn't exists
1637 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1528 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1638 1529
1639 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1530 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1640 if (tab) 1531 if (tab)
1641 { 1532 {
1642 CPluginClient* client = CPluginClient::GetInstance(); 1533 CPluginClient* client = CPluginClient::GetInstance();
1643 1534 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1644 #ifdef PRODUCT_ADBLOCKPLUS 1535 {
1645 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) 1536 if (client->IsWhitelistedUrl(ToWstring(url)))
1646 { 1537 {
1647 } 1538 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1648 #ifdef SUPPORT_WHITELIST 1539 }
1649 else if (client->IsWhitelistedUrl(std::wstring(url))) 1540 else
1650 { 1541 {
1651 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1542 CPluginSettings* settings = CPluginSettings::GetInstance();
1652 } 1543 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1653 #endif // SUPPORT_WHITELIST 1544 }
1654 else 1545 }
1655 { 1546 }
1656 CPluginSettings* settings = CPluginSettings::GetInstance();
1657 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1658 }
1659
1660 #endif // PRODUCT_ADBLOCKPLUS
1661 }
1662
1663 return hIcon; 1547 return hIcon;
1664 } 1548 }
1665 1549
1666 1550
1667 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) 1551 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam)
1668 { 1552 {
1669 // Find tab 1553 // Find tab
1670 CPluginClass *pClass = FindInstance(GetParent(hWnd)); 1554 CPluginClass *pClass = FindInstance(GetParent(hWnd));
1671 if (!pClass) 1555 if (!pClass)
1672 { 1556 {
1673 return ::DefWindowProc(hWnd, message, wParam, lParam); 1557 return ::DefWindowProc(hWnd, message, wParam, lParam);
1674 } 1558 }
1675
1676 CPluginSystem* system = CPluginSystem::GetInstance();
1677 1559
1678 // Process message 1560 // Process message
1679 switch (message) 1561 switch (message)
1680 { 1562 {
1681 1563
1682 case WM_SETCURSOR: 1564 case WM_SETCURSOR:
1683 { 1565 {
1684 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); 1566 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
1685 return TRUE; 1567 return TRUE;
1686 } 1568 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 return icon; 1808 return icon;
1927 } 1809 }
1928 1810
1929 ATOM CPluginClass::GetAtomPaneClass() 1811 ATOM CPluginClass::GetAtomPaneClass()
1930 { 1812 {
1931 return s_atomPaneClass; 1813 return s_atomPaneClass;
1932 } 1814 }
1933 1815
1934 HWND CPluginClass::GetTabHWND() const 1816 HWND CPluginClass::GetTabHWND() const
1935 { 1817 {
1936 1818 std::array<wchar_t, MAX_PATH> className;
1937 TCHAR szClassName[MAX_PATH];
1938 // Get browser window and url 1819 // Get browser window and url
1939 HWND hBrowserWnd = GetBrowserHWND(); 1820 HWND hBrowserWnd = GetBrowserHWND();
1940 if (!hBrowserWnd) 1821 if (!hBrowserWnd)
1941 { 1822 {
1942 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::GetTabWindow - No tab window") 1823 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::GetTabWindow - No tab window")
1943 s_criticalSectionWindow.Unlock(); 1824 s_criticalSectionWindow.Unlock();
1944 1825
1945 return false; 1826 return false;
1946 } 1827 }
1947 1828
1948 // Looking for a TabWindowClass window in IE7 1829 // Looking for a TabWindowClass window in IE7
1949 1830
1950 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 1831 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
1951 while (hTabWnd) 1832 while (hTabWnd)
1952 { 1833 {
1953 memset(szClassName, 0, MAX_PATH); 1834 className[0] = L'\0';
1954 GetClassName(hTabWnd, szClassName, MAX_PATH); 1835 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz e());
1955 1836
1956 if (_tcscmp(szClassName, _T("TabWindowClass")) == 0 || _tcscmp(szClassName,_ T("Frame Tab")) == 0) 1837 if (classNameLength && (wcscmp(className.data(), L"TabWindowClass") == 0 || wcscmp(className.data(), L"Frame Tab") == 0))
1957 { 1838 {
1958 // IE8 support 1839 // IE8 support
1959 HWND hTabWnd2 = hTabWnd; 1840 HWND hTabWnd2 = hTabWnd;
1960 if (_tcscmp(szClassName,_T("Frame Tab")) == 0) 1841 if (wcscmp(className.data(), L"Frame Tab") == 0)
1961 { 1842 {
1962 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, _T("TabWindowClass"), NULL); 1843 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL);
1963 } 1844 }
1964 1845
1965 if (hTabWnd2) 1846 if (hTabWnd2)
1966 { 1847 {
1967 DWORD nProcessId; 1848 DWORD nProcessId;
1968 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); 1849 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
1969 if (::GetCurrentProcessId() == nProcessId) 1850 if (::GetCurrentProcessId() == nProcessId)
1970 { 1851 {
1971 bool bExistingTab = false; 1852 bool bExistingTab = false;
1972 s_criticalSectionLocal.Lock(); 1853 s_criticalSectionLocal.Lock();
(...skipping 21 matching lines...) Expand all
1994 } 1875 }
1995 } 1876 }
1996 } 1877 }
1997 1878
1998 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1879 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1999 } 1880 }
2000 1881
2001 return hTabWnd; 1882 return hTabWnd;
2002 1883
2003 } 1884 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld