OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "Instances.h" | 33 #include "Instances.h" |
34 #include <thread> | 34 #include <thread> |
35 #include <array> | 35 #include <array> |
36 | 36 |
37 #ifdef DEBUG_HIDE_EL | 37 #ifdef DEBUG_HIDE_EL |
38 DWORD profileTime = 0; | 38 DWORD profileTime = 0; |
39 #endif | 39 #endif |
40 | 40 |
41 extern CComModule _Module; | 41 extern CComModule _Module; |
42 | 42 |
| 43 // Status bar pane number |
| 44 #define STATUSBAR_PANE_NUMBER 2 |
| 45 |
43 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); | 46 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); |
44 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); | 47 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); |
45 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); | 48 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); |
46 | 49 |
47 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; | 50 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; |
48 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; | 51 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; |
49 uint32_t iconHeight = 32; | 52 uint32_t iconHeight = 32; |
50 uint32_t iconWidth = 32; | 53 uint32_t iconWidth = 32; |
51 | 54 |
52 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; | 55 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; |
53 | 56 |
54 CLOSETHEMEDATA pfnClose = NULL; | 57 CLOSETHEMEDATA pfnClose = NULL; |
55 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; | 58 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; |
56 OPENTHEMEDATA pfnOpenThemeData = NULL; | 59 OPENTHEMEDATA pfnOpenThemeData = NULL; |
57 | 60 |
58 ATOM CPluginClass::s_atomPaneClass = NULL; | |
59 HINSTANCE CPluginClass::s_hUxtheme = NULL; | 61 HINSTANCE CPluginClass::s_hUxtheme = NULL; |
60 std::set<CPluginClass*> CPluginClass::s_instances; | 62 std::set<CPluginClass*> CPluginClass::s_instances; |
61 | 63 |
62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; | 64 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; |
63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; | 65 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; |
64 | 66 |
65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; | 67 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; |
66 | 68 |
67 namespace | 69 namespace |
68 { | 70 { |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 695 } |
694 } | 696 } |
695 else | 697 else |
696 { | 698 { |
697 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_U
XTHEME, "Class::InitObject - GetModuleHandle(uxtheme.dll)"); | 699 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_U
XTHEME, "Class::InitObject - GetModuleHandle(uxtheme.dll)"); |
698 } | 700 } |
699 } | 701 } |
700 } | 702 } |
701 s_criticalSectionLocal.Unlock(); | 703 s_criticalSectionLocal.Unlock(); |
702 | 704 |
703 // Register pane class | |
704 if (!GetAtomPaneClass()) | |
705 { | |
706 WNDCLASSEX wcex; | |
707 | |
708 wcex.cbSize = sizeof(wcex); | |
709 wcex.style = 0; | |
710 wcex.lpfnWndProc = (WNDPROC)PaneWindowProc; | |
711 wcex.cbClsExtra = 0; | |
712 wcex.cbWndExtra = 0; | |
713 wcex.hInstance = _Module.m_hInst; | |
714 wcex.hIcon = NULL; | |
715 wcex.hCursor = NULL; | |
716 wcex.hbrBackground = NULL; | |
717 wcex.lpszMenuName = NULL; | |
718 wcex.lpszClassName = STATUSBAR_PANE_NAME; | |
719 wcex.hIconSm = NULL; | |
720 | |
721 s_criticalSectionLocal.Lock(); | |
722 { | |
723 s_atomPaneClass = ::RegisterClassEx(&wcex); | |
724 } | |
725 s_criticalSectionLocal.Unlock(); | |
726 | |
727 if (!GetAtomPaneClass()) | |
728 { | |
729 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE
R_PANE_CLASS, "Class::InitObject - RegisterClassEx"); | |
730 return false; | |
731 } | |
732 } | |
733 | |
734 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); | 705 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); |
735 // Create status pane | 706 // Create status pane |
736 if (ieVersion > 6 && !CreateStatusBarPane()) | 707 if (ieVersion > 6 && !CreateStatusBarPane()) |
737 { | 708 { |
738 return false; | 709 return false; |
739 } | 710 } |
740 | 711 |
741 s_criticalSectionLocal.Lock(); | 712 s_criticalSectionLocal.Lock(); |
742 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie
nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2"); | 713 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie
nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2"); |
743 | 714 |
(...skipping 25 matching lines...) Expand all Loading... |
769 // Enable acceptable ads by default | 740 // Enable acceptable ads by default |
770 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e
xceptionsurl", L""); | 741 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e
xceptionsurl", L""); |
771 CPluginClient::GetInstance()->AddSubscription(aaUrl); | 742 CPluginClient::GetInstance()->AddSubscription(aaUrl); |
772 } | 743 } |
773 s_criticalSectionLocal.Unlock(); | 744 s_criticalSectionLocal.Unlock(); |
774 | 745 |
775 DEBUG_GENERAL("InitObject - end"); | 746 DEBUG_GENERAL("InitObject - end"); |
776 return true; | 747 return true; |
777 } | 748 } |
778 | 749 |
| 750 namespace |
| 751 { |
| 752 /** |
| 753 * Wrapper for Windows API 'SetWindowLongPtr()' to set a new window procedure |
| 754 * |
| 755 * Adds type safety and proper error handling over calling the API function di
rectly. |
| 756 */ |
| 757 DWORD SetWindowProc(HWND window, WNDPROC procedure) |
| 758 { |
| 759 /* |
| 760 * Error handling for 'SetWindowLongPtr()' is not standard. |
| 761 * The method below is as specified by its documentation. |
| 762 */ |
| 763 SetLastError(0); |
| 764 ::SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(procedur
e)); |
| 765 return ::GetLastError(); |
| 766 } |
| 767 } |
| 768 |
779 bool CPluginClass::CreateStatusBarPane() | 769 bool CPluginClass::CreateStatusBarPane() |
780 { | 770 { |
781 CriticalSection::Lock lock(m_csStatusBar); | 771 CriticalSection::Lock lock(m_csStatusBar); |
782 | 772 |
783 CPluginClient* client = CPluginClient::GetInstance(); | 773 CPluginClient* client = CPluginClient::GetInstance(); |
784 | 774 |
785 std::array<wchar_t, MAX_PATH> className; | 775 std::array<wchar_t, MAX_PATH> className; |
786 // Get browser window and url | 776 // Get browser window and url |
787 HWND hBrowserWnd = GetBrowserHWND(); | 777 HWND hBrowserWnd = GetBrowserHWND(); |
788 if (!hBrowserWnd) | 778 if (!hBrowserWnd) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 { | 885 { |
896 #ifdef _DEBUG | 886 #ifdef _DEBUG |
897 m_nPaneWidth = 70; | 887 m_nPaneWidth = 70; |
898 #else | 888 #else |
899 m_nPaneWidth = iconWidth; | 889 m_nPaneWidth = iconWidth; |
900 #endif | 890 #endif |
901 } | 891 } |
902 // Create pane window | 892 // Create pane window |
903 HWND hWndNewPane = ::CreateWindowEx( | 893 HWND hWndNewPane = ::CreateWindowEx( |
904 NULL, | 894 NULL, |
905 MAKEINTATOM(GetAtomPaneClass()), | 895 L"Edit", // predefined system class |
906 L"", | 896 L"ABPStatusBarPane", |
907 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, | 897 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, |
908 rcStatusBar.Width() - 500, 0, m_nPaneWidth, rcStatusBar.Height(), | 898 rcStatusBar.Width() - 500, 0, m_nPaneWidth, rcStatusBar.Height(), |
909 hWndStatusBar, | 899 hWndStatusBar, |
910 (HMENU)3671, | 900 (HMENU)3671, |
911 _Module.m_hInst, | 901 _Module.m_hInst, |
912 NULL); | 902 NULL); |
913 | 903 |
914 if (!hWndNewPane) | 904 if (!hWndNewPane) |
915 { | 905 { |
916 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST
ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx") | 906 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST
ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx") |
917 return false; | 907 return false; |
918 } | 908 } |
919 | 909 |
| 910 // Set window procedure to the one for status bars |
| 911 auto error = SetWindowProc(hWndNewPane, CPluginClass::PaneWindowProc); |
| 912 if (error) |
| 913 { |
| 914 DEBUG_ERROR_LOG(error, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_STATUSBAR_PAN
E, "Class::SetStatusBarPaneWindowProc - SetWindowProc"); |
| 915 ::DestroyWindow(hWndNewPane); |
| 916 return false; |
| 917 } |
| 918 |
920 DEBUG_GENERAL("ABP window created"); | 919 DEBUG_GENERAL("ABP window created"); |
921 m_hTabWnd = hTabWnd; | 920 m_hTabWnd = hTabWnd; |
922 m_hStatusBarWnd = hWndStatusBar; | 921 m_hStatusBarWnd = hWndStatusBar; |
923 m_hPaneWnd = hWndNewPane; | 922 m_hPaneWnd = hWndNewPane; |
924 | 923 |
925 UpdateTheme(); | 924 UpdateTheme(); |
926 | 925 |
927 // Subclass status bar | 926 // Subclass status bar |
928 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA
RAM)(WNDPROC)NewStatusProc); | 927 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA
RAM)(WNDPROC)NewStatusProc); |
929 | 928 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 return hMenuTrackPopup; | 1061 return hMenuTrackPopup; |
1063 } | 1062 } |
1064 | 1063 |
1065 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U
INT nMenuFlags) | 1064 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U
INT nMenuFlags) |
1066 { | 1065 { |
1067 CPluginClient* client = CPluginClient::GetInstance(); | 1066 CPluginClient* client = CPluginClient::GetInstance(); |
1068 | 1067 |
1069 // Create menu parent window | 1068 // Create menu parent window |
1070 HWND hMenuWnd = ::CreateWindowEx( | 1069 HWND hMenuWnd = ::CreateWindowEx( |
1071 NULL, | 1070 NULL, |
1072 MAKEINTATOM(GetAtomPaneClass()), | 1071 L"Edit", // predefined system class |
1073 L"", | 1072 L"ABPStatusBarPopupMenu", |
1074 0, | 1073 0, |
1075 0,0,0,0, | 1074 0,0,0,0, |
1076 NULL, | 1075 NULL, |
1077 NULL, | 1076 NULL, |
1078 _Module.m_hInst, | 1077 _Module.m_hInst, |
1079 NULL); | 1078 NULL); |
1080 | 1079 |
1081 if (!hMenuWnd) | 1080 if (!hMenuWnd) |
1082 { | 1081 { |
1083 DestroyMenu(hMenu); | 1082 DestroyMenu(hMenu); |
1084 return; | 1083 return; |
1085 } | 1084 } |
1086 | 1085 |
| 1086 // Set window procedure to the one for status bars. |
| 1087 auto error = SetWindowProc(hMenuWnd, CPluginClass::PaneWindowProc); |
| 1088 if (error) |
| 1089 { |
| 1090 DEBUG_ERROR_LOG(error, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_STATUSBAR_PAN
E, "Class::DisplayPluginMenu - SetWindowProc"); |
| 1091 ::DestroyWindow(hMenuWnd); |
| 1092 return; |
| 1093 } |
| 1094 |
1087 // Display menu | 1095 // Display menu |
1088 nMenuFlags |= TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON; | 1096 nMenuFlags |= TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON; |
1089 | 1097 |
1090 int nCommand = ::TrackPopupMenu(hMenu, nMenuFlags, pt.x, pt.y, 0, hMenuWnd, 0)
; | 1098 int nCommand = ::TrackPopupMenu(hMenu, nMenuFlags, pt.x, pt.y, 0, hMenuWnd, 0)
; |
1091 | 1099 |
1092 ::DestroyMenu(hMenu); | 1100 ::DestroyMenu(hMenu); |
1093 ::DestroyWindow(hMenuWnd); | 1101 ::DestroyWindow(hMenuWnd); |
1094 | 1102 |
1095 switch (nCommand) | 1103 switch (nCommand) |
1096 { | 1104 { |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_
ICON, "Class::GetIcon - LoadIcon"); | 1730 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_
ICON, "Class::GetIcon - LoadIcon"); |
1723 } | 1731 } |
1724 } | 1732 } |
1725 | 1733 |
1726 icon = s_hIcons[type]; | 1734 icon = s_hIcons[type]; |
1727 } | 1735 } |
1728 s_criticalSectionLocal.Unlock(); | 1736 s_criticalSectionLocal.Unlock(); |
1729 | 1737 |
1730 return icon; | 1738 return icon; |
1731 } | 1739 } |
1732 | |
1733 ATOM CPluginClass::GetAtomPaneClass() | |
1734 { | |
1735 return s_atomPaneClass; | |
1736 } | |
1737 | |
OLD | NEW |