LEFT | RIGHT |
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-2015 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
19 | 19 |
20 #include "PluginClass.h" | 20 #include "PluginClass.h" |
21 #include "PluginSettings.h" | 21 #include "PluginSettings.h" |
22 #include "PluginSystem.h" | 22 #include "PluginSystem.h" |
23 #include "PluginFilter.h" | 23 #include "PluginFilter.h" |
24 #include "PluginMimeFilterClient.h" | 24 #include "PluginMimeFilterClient.h" |
25 #include "AdblockPlusClient.h" | 25 #include "AdblockPlusClient.h" |
26 #include "PluginClientFactory.h" | 26 #include "PluginClientFactory.h" |
27 #include "PluginUtil.h" | 27 #include "PluginUtil.h" |
28 #include "../shared/Utils.h" | 28 #include "../shared/Utils.h" |
29 #include "../shared/Dictionary.h" | 29 #include "../shared/Dictionary.h" |
30 #include "IeVersion.h" | 30 #include "IeVersion.h" |
31 #include "../shared/Version.h" | 31 #include "../shared/Version.h" |
| 32 #include "Instances.h" |
32 #include <thread> | 33 #include <thread> |
33 #include <array> | 34 #include <array> |
34 | 35 |
35 #ifdef DEBUG_HIDE_EL | 36 #ifdef DEBUG_HIDE_EL |
36 DWORD profileTime = 0; | 37 DWORD profileTime = 0; |
37 #endif | 38 #endif |
38 | 39 |
39 extern CComModule _Module; | 40 extern CComModule _Module; |
40 | 41 |
41 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); | 42 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); |
42 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); | 43 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); |
43 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); | 44 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); |
44 | 45 |
45 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; | 46 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; |
46 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; | 47 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; |
47 uint32_t iconHeight = 32; | 48 uint32_t iconHeight = 32; |
48 uint32_t iconWidth = 32; | 49 uint32_t iconWidth = 32; |
49 | 50 |
50 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; | 51 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; |
51 | 52 |
52 CLOSETHEMEDATA pfnClose = NULL; | 53 CLOSETHEMEDATA pfnClose = NULL; |
53 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; | 54 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; |
54 OPENTHEMEDATA pfnOpenThemeData = NULL; | 55 OPENTHEMEDATA pfnOpenThemeData = NULL; |
55 | 56 |
56 ATOM CPluginClass::s_atomPaneClass = NULL; | 57 ATOM CPluginClass::s_atomPaneClass = NULL; |
57 HINSTANCE CPluginClass::s_hUxtheme = NULL; | 58 HINSTANCE CPluginClass::s_hUxtheme = NULL; |
58 std::set<CPluginClass*> CPluginClass::s_instances; | 59 std::set<CPluginClass*> CPluginClass::s_instances; |
59 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; | |
60 | 60 |
61 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; | 61 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; |
62 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; | 62 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; |
63 | 63 |
64 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; | 64 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; |
| 65 |
| 66 namespace |
| 67 { |
| 68 /** |
| 69 * A synchronized map whose key is always the current thread ID. |
| 70 */ |
| 71 class CurrentThreadMap |
| 72 : public SyncMap<DWORD, CPluginClass*, nullptr> |
| 73 { |
| 74 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base; |
| 75 |
| 76 public: |
| 77 bool AddIfAbsent(CPluginClass* p) |
| 78 { |
| 79 return Base::AddIfAbsent(::GetCurrentThreadId(), p); |
| 80 } |
| 81 |
| 82 bool RemoveAndCheck() |
| 83 { |
| 84 return Base::RemoveIfPresent(::GetCurrentThreadId()); |
| 85 } |
| 86 |
| 87 CPluginClass* Locate() |
| 88 { |
| 89 return Base::Locate(::GetCurrentThreadId()); |
| 90 } |
| 91 }; |
| 92 |
| 93 /** |
| 94 * Map from thread ID's to CPluginClass instances |
| 95 */ |
| 96 CurrentThreadMap threadMap; |
| 97 } |
65 | 98 |
66 /* | 99 /* |
67 * Without namespace declaration, the identifier "Rectangle" is ambiguous | 100 * Without namespace declaration, the identifier "Rectangle" is ambiguous |
68 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85)
.aspx | 101 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85)
.aspx |
69 */ | 102 */ |
70 namespace AdblockPlus | 103 namespace AdblockPlus |
71 { | 104 { |
72 /** | 105 /** |
73 * Replacement for ATL type CRect. | 106 * Replacement for ATL type CRect. |
74 */ | 107 */ |
75 class Rectangle | 108 class Rectangle |
76 : public RECT | 109 : public RECT |
77 { | 110 { |
78 public: | 111 public: |
79 int Height() const | 112 unsigned long Height() const |
80 { | 113 { |
81 return bottom - top; | 114 if (bottom < top) |
82 } | 115 { |
83 | 116 throw std::runtime_error("invariant violation: rectangle bottom < top"); |
84 int Width() const | 117 } |
85 { | 118 return static_cast<unsigned long>(bottom - top); |
86 return right - left; | 119 } |
| 120 |
| 121 unsigned long Width() const |
| 122 { |
| 123 if (right < left) |
| 124 { |
| 125 throw std::runtime_error("invariant violation: rectangle right < left"); |
| 126 } |
| 127 return static_cast<unsigned long>(right - left); |
87 } | 128 } |
88 }; | 129 }; |
89 } | 130 } |
90 | 131 |
91 CPluginClass::CPluginClass() | 132 CPluginClass::CPluginClass() |
92 : m_webBrowser2(nullptr) | 133 : m_webBrowser2(nullptr) |
93 { | 134 { |
94 DEBUG_GENERAL([this]() -> std::wstring | 135 DEBUG_GENERAL([this]() -> std::wstring |
95 { | 136 { |
96 std::wstring s = L"CPluginClass::<constructor>, this = "; | 137 std::wstring s = L"CPluginClass::<constructor>, this = "; |
97 s += ToHexLiteral(this); | 138 s += ToHexLiteral(this); |
98 return s; | 139 return s; |
99 }()); | 140 }()); |
100 | 141 |
101 //Use this line to debug memory leaks | 142 //Use this line to debug memory leaks |
102 // _CrtDumpMemoryLeaks(); | 143 // _CrtDumpMemoryLeaks(); |
103 | 144 |
104 m_isAdvised = false; | 145 m_isAdvised = false; |
105 m_hTabWnd = NULL; | 146 m_hTabWnd = NULL; |
106 m_hStatusBarWnd = NULL; | 147 m_hStatusBarWnd = NULL; |
107 m_hPaneWnd = NULL; | 148 m_hPaneWnd = NULL; |
108 m_nPaneWidth = 0; | 149 m_nPaneWidth = 0; |
109 m_pWndProcStatus = NULL; | 150 m_pWndProcStatus = NULL; |
110 m_hTheme = NULL; | 151 m_hTheme = NULL; |
111 m_isInitializedOk = false; | 152 m_isInitializedOk = false; |
112 | |
113 | |
114 m_tab = new CPluginTab(); | 153 m_tab = new CPluginTab(); |
115 | |
116 Dictionary::Create(GetBrowserLanguage()); | 154 Dictionary::Create(GetBrowserLanguage()); |
117 } | 155 } |
118 | 156 |
119 CPluginClass::~CPluginClass() | 157 CPluginClass::~CPluginClass() |
120 { | 158 { |
121 DEBUG_GENERAL([this]() -> std::wstring | 159 DEBUG_GENERAL([this]() -> std::wstring |
122 { | 160 { |
123 std::wstring s = L"CPluginClass::<destructor>, this = "; | 161 std::wstring s = L"CPluginClass::<destructor>, this = "; |
124 s += ToHexLiteral(this); | 162 s += ToHexLiteral(this); |
125 return s; | 163 return s; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 200 |
163 return browser; | 201 return browser; |
164 } | 202 } |
165 | 203 |
166 std::wstring CPluginClass::GetBrowserUrl() const | 204 std::wstring CPluginClass::GetBrowserUrl() const |
167 { | 205 { |
168 std::wstring url; | 206 std::wstring url; |
169 if (m_webBrowser2) | 207 if (m_webBrowser2) |
170 { | 208 { |
171 CComBSTR bstrURL; | 209 CComBSTR bstrURL; |
172 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL) | 210 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL))) |
173 { | 211 { |
174 url = std::wstring(bstrURL, SysStringLen(bstrURL)); | 212 url = ToWstring(bstrURL); |
175 } | 213 } |
176 } | 214 } |
177 else | 215 else |
178 { | 216 { |
179 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr
owser2 == nullptr"); | 217 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with m_webBrowser2 ==
nullptr (probable invariant violation)"); |
| 218 } |
| 219 if (url.empty()) |
| 220 { |
180 url = m_tab->GetDocumentUrl(); | 221 url = m_tab->GetDocumentUrl(); |
181 } | 222 } |
182 return url; | 223 return url; |
183 } | 224 } |
184 | 225 |
185 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 226 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
186 { | 227 { |
187 if (thisPtr == NULL) | 228 if (thisPtr == NULL) |
188 return 0; | 229 return 0; |
189 if (!((CPluginClass*)thisPtr)->InitObject()) | 230 if (!((CPluginClass*)thisPtr)->InitObject()) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p
ointer to IWebBrowser2*"); | 268 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p
ointer to IWebBrowser2*"); |
228 } | 269 } |
229 DEBUG_GENERAL([this]() -> std::wstring | 270 DEBUG_GENERAL([this]() -> std::wstring |
230 { | 271 { |
231 std::wstringstream ss; | 272 std::wstringstream ss; |
232 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); | 273 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); |
233 ss << L", browser = " << ToHexLiteral(m_webBrowser2); | 274 ss << L", browser = " << ToHexLiteral(m_webBrowser2); |
234 return ss.str(); | 275 return ss.str(); |
235 }()); | 276 }()); |
236 | 277 |
| 278 /* |
| 279 * Add ourselves to the thread map. |
| 280 */ |
| 281 if (!threadMap.AddIfAbsent(this)) |
| 282 { |
| 283 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi
ng entry in thread map"); |
| 284 } |
| 285 |
237 //register the mimefilter | 286 //register the mimefilter |
238 //and only mimefilter | 287 //and only mimefilter |
239 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread | 288 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread |
240 s_criticalSectionLocal.Lock(); | 289 s_criticalSectionLocal.Lock(); |
241 { | 290 { |
242 // Always register on startup, then check if we need to unregister in a
separate thread | 291 // Always register on startup, then check if we need to unregister in a
separate thread |
243 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 292 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
244 s_asyncWebBrowser2 = unknownSite; | 293 s_asyncWebBrowser2 = unknownSite; |
245 s_instances.insert(this); | 294 s_instances.insert(this); |
246 } | 295 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 m_hPaneWnd = NULL; | 349 m_hPaneWnd = NULL; |
301 } | 350 } |
302 | 351 |
303 m_hTabWnd = NULL; | 352 m_hTabWnd = NULL; |
304 m_hStatusBarWnd = NULL; | 353 m_hStatusBarWnd = NULL; |
305 | 354 |
306 // Remove instance from the list, shutdown threads | 355 // Remove instance from the list, shutdown threads |
307 HANDLE hMainThread = NULL; | 356 HANDLE hMainThread = NULL; |
308 HANDLE hTabThread = NULL; | 357 HANDLE hTabThread = NULL; |
309 | 358 |
| 359 if (!threadMap.RemoveAndCheck()) |
| 360 { |
| 361 throw std::logic_error("CPluginClass::SetSite - Missing entry in thread
map"); |
| 362 } |
| 363 |
310 s_criticalSectionLocal.Lock(); | 364 s_criticalSectionLocal.Lock(); |
311 { | 365 { |
312 s_instances.erase(this); | 366 s_instances.erase(this); |
313 | |
314 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge
tCurrentThreadId()); | |
315 if (it != s_threadInstances.end()) | |
316 { | |
317 s_threadInstances.erase(it); | |
318 } | |
319 if (s_instances.empty()) | 367 if (s_instances.empty()) |
320 { | 368 { |
321 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr | 369 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr |
322 CPluginClientFactory::ReleaseMimeFilterClientInstance(); | 370 CPluginClientFactory::ReleaseMimeFilterClientInstance(); |
323 } | 371 } |
324 } | 372 } |
325 s_criticalSectionLocal.Unlock(); | 373 s_criticalSectionLocal.Unlock(); |
326 | 374 |
327 m_webBrowser2 = nullptr; | 375 m_webBrowser2 = nullptr; |
328 | 376 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 { | 514 { |
467 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; | 515 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; |
468 if (!webBrowser) | 516 if (!webBrowser) |
469 { | 517 { |
470 return; | 518 return; |
471 } | 519 } |
472 if (!urlVariant || urlVariant->vt != VT_BSTR) | 520 if (!urlVariant || urlVariant->vt != VT_BSTR) |
473 { | 521 { |
474 return; | 522 return; |
475 } | 523 } |
476 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); | 524 std::wstring url = ToWstring(urlVariant->bstrVal); |
477 | 525 |
478 // If webbrowser2 is equal to top level browser (as set in SetSite), we are | 526 // If webbrowser2 is equal to top level browser (as set in SetSite), we are |
479 // navigating new page | 527 // navigating new page |
480 CPluginClient* client = CPluginClient::GetInstance(); | 528 CPluginClient* client = CPluginClient::GetInstance(); |
481 if (url.find(L"javascript") == 0) | 529 if (url.find(L"javascript") == 0) |
482 { | 530 { |
483 } | 531 } |
484 else if (IsRootBrowser(webBrowser)) | 532 else if (IsRootBrowser(webBrowser)) |
485 { | 533 { |
486 m_tab->OnNavigate(url); | 534 m_tab->OnNavigate(url); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 // Entry point | 593 // Entry point |
546 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) | 594 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) |
547 { | 595 { |
548 try | 596 try |
549 { | 597 { |
550 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); | 598 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); |
551 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) | 599 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) |
552 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA
BLED); | 600 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA
BLED); |
553 if (newtabshown) | 601 if (newtabshown) |
554 { | 602 { |
555 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(
GetCurrentThreadId()); | 603 if (!m_isInitializedOk) |
556 if (it == s_threadInstances.end()) | 604 { |
557 { | 605 m_isInitializedOk = true; |
558 s_threadInstances[::GetCurrentThreadId()] = this; | 606 InitObject(); |
559 if (!m_isInitializedOk) | 607 UpdateStatusBar(); |
560 { | |
561 m_isInitializedOk = true; | |
562 InitObject(); | |
563 UpdateStatusBar(); | |
564 } | |
565 } | 608 } |
566 } | 609 } |
567 notificationMessage.Hide(); | 610 notificationMessage.Hide(); |
568 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end"); | 611 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end"); |
569 } | 612 } |
570 catch (...) | 613 catch (...) |
571 { | 614 { |
572 } | 615 } |
573 } | 616 } |
574 | 617 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 s_criticalSectionLocal.Unlock(); | 1016 s_criticalSectionLocal.Unlock(); |
974 | 1017 |
975 return result; | 1018 return result; |
976 } | 1019 } |
977 | 1020 |
978 CPluginTab* CPluginClass::GetTab() | 1021 CPluginTab* CPluginClass::GetTab() |
979 { | 1022 { |
980 return m_tab; | 1023 return m_tab; |
981 } | 1024 } |
982 | 1025 |
983 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) | 1026 CPluginTab* CPluginClass::GetTabForCurrentThread() |
984 { | 1027 { |
985 CPluginTab* tab = NULL; | 1028 auto p = threadMap.Locate(); |
986 | 1029 return p ? p->m_tab : nullptr; |
987 s_criticalSectionLocal.Lock(); | 1030 } |
988 { | 1031 |
989 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw
ThreadId); | 1032 // Entry point |
990 if (it != s_threadInstances.end()) | |
991 { | |
992 tab = it->second->m_tab; | |
993 } | |
994 } | |
995 s_criticalSectionLocal.Unlock(); | |
996 | |
997 return tab; | |
998 } | |
999 | |
1000 | |
1001 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) | 1033 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) |
1002 { | 1034 { |
1003 if (cCmds == 0) return E_INVALIDARG; | 1035 try |
1004 if (prgCmds == 0) return E_POINTER; | 1036 { |
1005 | 1037 if (cCmds == 0) return E_INVALIDARG; |
1006 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1038 if (prgCmds == 0) return E_POINTER; |
1007 | 1039 |
| 1040 prgCmds[0].cmdf = OLECMDF_ENABLED; |
| 1041 } |
| 1042 catch (...) |
| 1043 { |
| 1044 DEBUG_GENERAL(L"CPluginClass::QueryStatus - exception"); |
| 1045 return E_FAIL; |
| 1046 } |
1008 return S_OK; | 1047 return S_OK; |
1009 } | 1048 } |
1010 | 1049 |
1011 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) | 1050 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) |
1012 { | 1051 { |
1013 DEBUG_GENERAL("CreatePluginMenu"); | 1052 DEBUG_GENERAL("CreatePluginMenu"); |
1014 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1053 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
1015 | 1054 |
1016 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1055 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
1017 | 1056 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 | 1186 |
1148 MENUITEMINFOW miiSep = {}; | 1187 MENUITEMINFOW miiSep = {}; |
1149 miiSep.cbSize = sizeof(miiSep); | 1188 miiSep.cbSize = sizeof(miiSep); |
1150 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 1189 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |
1151 miiSep.fType = MFT_SEPARATOR; | 1190 miiSep.fType = MFT_SEPARATOR; |
1152 | 1191 |
1153 CPluginClient* client = CPluginClient::GetInstance(); | 1192 CPluginClient* client = CPluginClient::GetInstance(); |
1154 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1193 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1155 { | 1194 { |
1156 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 1195 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |
1157 // Is domain in white list? | |
1158 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); | 1196 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); |
1159 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) | 1197 /* |
1160 { | 1198 * The display state of the "disable on this site" menu item depends upon ta
b content |
| 1199 */ |
| 1200 if (!GetTab()->IsPossibleToDisableOnSite()) |
| 1201 { |
| 1202 // Since we can't disable the present content, |
| 1203 // it makes no sense to offer the user an option to block it. |
| 1204 fmii.fState = MFS_UNCHECKED | MFS_DISABLED; |
| 1205 } |
| 1206 else if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) |
| 1207 { |
| 1208 // Domain is in white list, indicated by a check mark |
1161 fmii.fState = MFS_CHECKED | MFS_ENABLED; | 1209 fmii.fState = MFS_CHECKED | MFS_ENABLED; |
1162 } | 1210 } |
1163 else | 1211 else |
1164 { | 1212 { |
1165 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 1213 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |
1166 } | 1214 } |
1167 fmii.fMask = MIIM_STRING | MIIM_STATE; | 1215 fmii.fMask = MIIM_STRING | MIIM_STATE; |
1168 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1216 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1169 fmii.cch = static_cast<UINT>(ctext.size()); | 1217 fmii.cch = static_cast<UINT>(ctext.size()); |
1170 | 1218 |
(...skipping 28 matching lines...) Expand all Loading... |
1199 ctext = dictionary->Lookup("menu", "menu-settings"); | 1247 ctext = dictionary->Lookup("menu", "menu-settings"); |
1200 fmii.fMask = MIIM_STATE | MIIM_STRING; | 1248 fmii.fMask = MIIM_STATE | MIIM_STRING; |
1201 fmii.fState = MFS_ENABLED; | 1249 fmii.fState = MFS_ENABLED; |
1202 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1250 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1203 fmii.cch = static_cast<UINT>(ctext.size()); | 1251 fmii.cch = static_cast<UINT>(ctext.size()); |
1204 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); | 1252 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); |
1205 | 1253 |
1206 return true; | 1254 return true; |
1207 } | 1255 } |
1208 | 1256 |
1209 | 1257 // Entry point |
1210 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) | 1258 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) |
1211 { | 1259 { |
1212 HWND hBrowserWnd = GetBrowserHWND(); | 1260 try |
1213 if (!hBrowserWnd) | 1261 { |
1214 { | 1262 HWND hBrowserWnd = GetBrowserHWND(); |
1215 return E_FAIL; | 1263 if (!hBrowserWnd) |
1216 } | 1264 { |
1217 | 1265 return E_FAIL; |
1218 // Create menu | 1266 } |
1219 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); | 1267 |
1220 if (!hMenu) | 1268 // Create menu |
1221 { | 1269 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); |
1222 return E_FAIL; | 1270 if (!hMenu) |
1223 } | 1271 { |
1224 | 1272 return E_FAIL; |
1225 // Check if button in toolbar was pressed | 1273 } |
1226 int nIDCommand = -1; | 1274 |
1227 BOOL bRightAlign = FALSE; | 1275 // Check if button in toolbar was pressed |
1228 | 1276 int nIDCommand = -1; |
1229 POINT pt; | 1277 BOOL bRightAlign = FALSE; |
1230 GetCursorPos(&pt); | 1278 |
1231 | 1279 POINT pt; |
1232 HWND hWndToolBar = ::WindowFromPoint(pt); | 1280 GetCursorPos(&pt); |
1233 | 1281 |
1234 DWORD nProcessId; | 1282 HWND hWndToolBar = ::WindowFromPoint(pt); |
1235 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | 1283 |
1236 | 1284 DWORD nProcessId; |
1237 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | 1285 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |
1238 { | 1286 |
1239 ::ScreenToClient(hWndToolBar, &pt); | 1287 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |
1240 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | 1288 { |
1241 | 1289 ::ScreenToClient(hWndToolBar, &pt); |
1242 if (nButton > 0) | 1290 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |
1243 { | 1291 |
1244 TBBUTTON pTBBtn = {}; | 1292 if (nButton > 0) |
1245 | 1293 { |
1246 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 1294 TBBUTTON pTBBtn = {}; |
1247 { | 1295 |
1248 RECT rcButton; | 1296 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |
1249 nIDCommand = pTBBtn.idCommand; | 1297 { |
1250 | 1298 RECT rcButton; |
1251 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) | 1299 nIDCommand = pTBBtn.idCommand; |
1252 { | 1300 |
1253 pt.x = rcButton.left; | 1301 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton
)) |
1254 pt.y = rcButton.bottom; | |
1255 ClientToScreen(hWndToolBar, &pt); | |
1256 | |
1257 RECT rcWorkArea; | |
1258 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
1259 if (rcWorkArea.right - pt.x < 150) | |
1260 { | 1302 { |
1261 bRightAlign = TRUE; | 1303 pt.x = rcButton.left; |
1262 pt.x = rcButton.right; | |
1263 pt.y = rcButton.bottom; | 1304 pt.y = rcButton.bottom; |
1264 ClientToScreen(hWndToolBar, &pt); | 1305 ClientToScreen(hWndToolBar, &pt); |
| 1306 |
| 1307 RECT rcWorkArea; |
| 1308 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); |
| 1309 if (rcWorkArea.right - pt.x < 150) |
| 1310 { |
| 1311 bRightAlign = TRUE; |
| 1312 pt.x = rcButton.right; |
| 1313 pt.y = rcButton.bottom; |
| 1314 ClientToScreen(hWndToolBar, &pt); |
| 1315 } |
1265 } | 1316 } |
1266 } | 1317 } |
1267 } | 1318 } |
| 1319 else |
| 1320 { |
| 1321 GetCursorPos(&pt); |
| 1322 } |
| 1323 } |
| 1324 |
| 1325 // Display menu |
| 1326 UINT nFlags = 0; |
| 1327 if (bRightAlign) |
| 1328 { |
| 1329 nFlags |= TPM_RIGHTALIGN; |
1268 } | 1330 } |
1269 else | 1331 else |
1270 { | 1332 { |
1271 GetCursorPos(&pt); | 1333 nFlags |= TPM_LEFTALIGN; |
1272 } | 1334 } |
1273 } | 1335 |
1274 | 1336 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); |
1275 // Display menu | 1337 } |
1276 UINT nFlags = 0; | 1338 catch (...) |
1277 if (bRightAlign) | 1339 { |
1278 { | 1340 // Suppress exception, log only |
1279 nFlags |= TPM_RIGHTALIGN; | 1341 DEBUG_GENERAL(L"CPluginClass::Exec - exception"); |
1280 } | 1342 return E_FAIL; |
1281 else | 1343 } |
1282 { | |
1283 nFlags |= TPM_LEFTALIGN; | |
1284 } | |
1285 | |
1286 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | |
1287 | 1344 |
1288 return S_OK; | 1345 return S_OK; |
1289 } | 1346 } |
1290 | 1347 |
1291 ///////////////////////////////////////////////////////////////////////////// | 1348 // Entry point |
1292 // Window procedures | |
1293 | |
1294 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) | 1349 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) |
1295 { | 1350 { |
1296 // Find tab | 1351 CPluginClass *pClass; |
1297 CPluginClass *pClass = FindInstance(hWnd); | 1352 try |
1298 if (!pClass) | 1353 { |
1299 { | 1354 // Find tab |
1300 return DefWindowProc(hWnd, message, wParam, lParam); | 1355 pClass = FindInstance(hWnd); |
1301 } | 1356 if (!pClass) |
1302 | 1357 { |
1303 // Process message | 1358 /* |
1304 switch (message) | 1359 * Race condition if reached. |
1305 { | 1360 * We did not unhook the window procedure for the status bar when the last
BHO instance using it terminated. |
1306 case SB_SIMPLE: | 1361 * The next best thing is to call the system default window function. |
1307 { | 1362 */ |
1308 ShowWindow(pClass->m_hPaneWnd, !wParam); | 1363 return DefWindowProc(hWnd, message, wParam, lParam); |
| 1364 } |
| 1365 |
| 1366 // Process message |
| 1367 switch (message) |
| 1368 { |
| 1369 case SB_SIMPLE: |
| 1370 { |
| 1371 ShowWindow(pClass->m_hPaneWnd, !wParam); |
| 1372 break; |
| 1373 } |
| 1374 |
| 1375 case WM_SYSCOLORCHANGE: |
| 1376 { |
| 1377 pClass->UpdateTheme(); |
| 1378 break; |
| 1379 } |
| 1380 |
| 1381 case SB_SETPARTS: |
| 1382 { |
| 1383 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) |
| 1384 { |
| 1385 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam,
lParam); |
| 1386 } |
| 1387 |
| 1388 WPARAM nParts = wParam; |
| 1389 if (STATUSBAR_PANE_NUMBER >= nParts) |
| 1390 { |
| 1391 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam,
lParam); |
| 1392 } |
| 1393 |
| 1394 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1)); |
| 1395 LPINT lpParts = (LPINT)LocalLock(hLocal); |
| 1396 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); |
| 1397 |
| 1398 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) |
| 1399 { |
| 1400 lpParts[i] -= pClass->m_nPaneWidth; |
| 1401 } |
| 1402 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w
Param, (LPARAM)lpParts); |
| 1403 |
| 1404 AdblockPlus::Rectangle rcPane; |
| 1405 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); |
| 1406 |
| 1407 AdblockPlus::Rectangle rcClient; |
| 1408 ::GetClientRect(hWnd, &rcClient); |
| 1409 |
| 1410 ::MoveWindow( |
| 1411 pClass->m_hPaneWnd, |
| 1412 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, |
| 1413 0, |
| 1414 pClass->m_nPaneWidth, |
| 1415 rcClient.Height(), |
| 1416 TRUE); |
| 1417 |
| 1418 ::LocalFree(hLocal); |
| 1419 return hRet; |
| 1420 } |
| 1421 |
| 1422 default: |
1309 break; | 1423 break; |
1310 } | 1424 } |
1311 | 1425 } |
1312 case WM_SYSCOLORCHANGE: | 1426 catch (...) |
1313 { | 1427 { |
1314 pClass->UpdateTheme(); | 1428 // Suppress exception. Fall through to default handler. |
1315 break; | 1429 DEBUG_GENERAL(L"CPluginClass::NewStatusProc - exception"); |
1316 } | 1430 } |
1317 | 1431 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara
m); |
1318 case SB_SETPARTS: | |
1319 { | |
1320 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) | |
1321 { | |
1322 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l
Param); | |
1323 } | |
1324 | |
1325 WPARAM nParts = wParam; | |
1326 if (STATUSBAR_PANE_NUMBER >= nParts) | |
1327 { | |
1328 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l
Param); | |
1329 } | |
1330 | |
1331 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); | |
1332 LPINT lpParts = (LPINT)LocalLock(hLocal); | |
1333 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | |
1334 | |
1335 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | |
1336 { | |
1337 lpParts[i] -= pClass->m_nPaneWidth; | |
1338 } | |
1339 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa
ram, (LPARAM)lpParts); | |
1340 | |
1341 AdblockPlus::Rectangle rcPane; | |
1342 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | |
1343 | |
1344 AdblockPlus::Rectangle rcClient; | |
1345 ::GetClientRect(hWnd, &rcClient); | |
1346 | |
1347 ::MoveWindow( | |
1348 pClass->m_hPaneWnd, | |
1349 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | |
1350 0, | |
1351 pClass->m_nPaneWidth, | |
1352 rcClient.Height(), | |
1353 TRUE); | |
1354 | |
1355 ::LocalFree(hLocal); | |
1356 | |
1357 | |
1358 return hRet; | |
1359 } | |
1360 | |
1361 default: | |
1362 break; | |
1363 } | |
1364 | |
1365 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
m, lParam); | |
1366 | |
1367 | |
1368 return result; | |
1369 | |
1370 } | 1432 } |
1371 | 1433 |
1372 | 1434 |
1373 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) | 1435 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1374 { | 1436 { |
1375 // use the disable icon as defualt, if the client doesn't exists | 1437 // use the disable icon as defualt, if the client doesn't exists |
1376 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1438 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1377 | 1439 |
1378 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1440 CPluginTab* tab = GetTabForCurrentThread(); |
1379 if (tab) | 1441 if (tab) |
1380 { | 1442 { |
1381 CPluginClient* client = CPluginClient::GetInstance(); | 1443 CPluginClient* client = CPluginClient::GetInstance(); |
1382 if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 1444 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1383 { | 1445 { |
1384 if (client->IsWhitelistedUrl(url)) | 1446 if (client->IsWhitelistedUrl(url)) |
1385 { | 1447 { |
1386 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1448 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1387 } | 1449 } |
1388 else | 1450 else |
1389 { | 1451 { |
1390 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1452 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1391 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 1453 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1392 } | 1454 } |
1393 } | 1455 } |
1394 } | 1456 } |
1395 return hIcon; | 1457 return hIcon; |
1396 } | 1458 } |
1397 | 1459 |
1398 | 1460 // Entry point |
1399 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP
aram, LPARAM lParam) | 1461 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP
aram, LPARAM lParam) |
1400 { | 1462 { |
1401 // Find tab | 1463 try |
1402 CPluginClass *pClass = FindInstance(GetParent(hWnd)); | 1464 { |
1403 if (!pClass) | 1465 // Find tab |
1404 { | 1466 CPluginClass *pClass = FindInstance(GetParent(hWnd)); |
1405 return ::DefWindowProc(hWnd, message, wParam, lParam); | 1467 if (!pClass) |
1406 } | 1468 { |
1407 | 1469 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1408 // Process message | 1470 } |
1409 switch (message) | 1471 |
1410 { | 1472 // Process message |
1411 | 1473 switch (message) |
1412 case WM_SETCURSOR: | 1474 { |
1413 { | 1475 case WM_SETCURSOR: |
1414 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); | 1476 { |
1415 return TRUE; | 1477 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); |
1416 } | 1478 return TRUE; |
1417 case WM_PAINT: | 1479 } |
1418 { | 1480 case WM_PAINT: |
1419 PAINTSTRUCT ps; | 1481 { |
1420 HDC hDC = ::BeginPaint(hWnd, &ps); | 1482 PAINTSTRUCT ps; |
1421 | 1483 HDC hDC = ::BeginPaint(hWnd, &ps); |
1422 AdblockPlus::Rectangle rcClient; | 1484 |
1423 ::GetClientRect(hWnd, &rcClient); | 1485 AdblockPlus::Rectangle rcClient; |
1424 | 1486 ::GetClientRect(hWnd, &rcClient); |
1425 int nDrawEdge = 0; | 1487 |
1426 | 1488 int nDrawEdge = 0; |
1427 // Old Windows background drawing | 1489 |
1428 if (pClass->m_hTheme == NULL) | 1490 // Old Windows background drawing |
1429 { | 1491 if (pClass->m_hTheme == NULL) |
1430 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); | 1492 { |
1431 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); | 1493 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); |
1432 | 1494 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); |
1433 nDrawEdge = 3; | 1495 |
1434 rcClient.left += 3; | 1496 nDrawEdge = 3; |
1435 | 1497 rcClient.left += 3; |
1436 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); | 1498 |
1437 } | 1499 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); |
1438 // Themed background drawing | 1500 } |
1439 else | 1501 // Themed background drawing |
1440 { | 1502 else |
1441 // Draw background | 1503 { |
1442 if (pfnDrawThemeBackground) | 1504 // Draw background |
1443 { | 1505 if (pfnDrawThemeBackground) |
1444 AdblockPlus::Rectangle rc = rcClient; | |
1445 rc.right -= 2; | |
1446 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); | |
1447 } | |
1448 | |
1449 // Copy separator picture to left side | |
1450 int nHeight = rcClient.Height(); | |
1451 int nWidth = rcClient.Width() - 2; | |
1452 | |
1453 for (int i = 0; i < 2; i++) | |
1454 { | |
1455 for (int j = 0; j < nHeight; j++) | |
1456 { | 1506 { |
1457 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); | 1507 AdblockPlus::Rectangle rc = rcClient; |
1458 | 1508 rc.right -= 2; |
1459 // Ignore black boxes (if source is obscured by other windows) | 1509 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); |
1460 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa
lue(clr) > 8)) | 1510 } |
| 1511 |
| 1512 // Copy separator picture to left side |
| 1513 int nHeight = rcClient.Height(); |
| 1514 int nWidth = rcClient.Width() - 2; |
| 1515 |
| 1516 for (int i = 0; i < 2; i++) |
| 1517 { |
| 1518 for (int j = 0; j < nHeight; j++) |
1461 { | 1519 { |
1462 ::SetPixel(hDC, i, j, clr); | 1520 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); |
| 1521 |
| 1522 // Ignore black boxes (if source is obscured by other windows) |
| 1523 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB
Value(clr) > 8)) |
| 1524 { |
| 1525 ::SetPixel(hDC, i, j, clr); |
| 1526 } |
1463 } | 1527 } |
1464 } | 1528 } |
1465 } | 1529 } |
1466 } | 1530 |
1467 | 1531 // Draw icon |
1468 // Draw icon | 1532 if (CPluginClient::GetInstance()) |
1469 if (CPluginClient::GetInstance()) | 1533 { |
1470 { | 1534 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); |
1471 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); | 1535 |
1472 | 1536 int offx = nDrawEdge; |
1473 int offx = nDrawEdge; | 1537 if (hIcon) |
1474 if (hIcon) | 1538 { |
1475 { | 1539 //Get the RECT for the leftmost pane (the status text pane) |
1476 //Get the RECT for the leftmost pane (the status text pane) | 1540 RECT rect; |
| 1541 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0,
(LPARAM)&rect); |
| 1542 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico
nWidth, iconHeight, NULL, NULL, DI_NORMAL); |
| 1543 offx += iconWidth; |
| 1544 } |
| 1545 #ifdef _DEBUG |
| 1546 // Display version |
| 1547 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT
, 0, 0); |
| 1548 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont); |
| 1549 |
| 1550 AdblockPlus::Rectangle rcText = rcClient; |
| 1551 rcText.left += offx; |
| 1552 ::SetBkMode(hDC, TRANSPARENT); |
| 1553 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_
LEFT | DT_SINGLELINE | DT_VCENTER); |
| 1554 |
| 1555 ::SelectObject(hDC, hOldFont); |
| 1556 #endif // _DEBUG |
| 1557 } |
| 1558 |
| 1559 // Done! |
| 1560 EndPaint(hWnd, &ps); |
| 1561 |
| 1562 return 0; |
| 1563 } |
| 1564 |
| 1565 case WM_LBUTTONUP: |
| 1566 case WM_RBUTTONUP: |
| 1567 { |
| 1568 std::wstring url = pClass->GetBrowserUrl(); |
| 1569 if (url != pClass->GetTab()->GetDocumentUrl()) |
| 1570 { |
| 1571 pClass->GetTab()->SetDocumentUrl(url); |
| 1572 } |
| 1573 |
| 1574 // Create menu |
| 1575 HMENU hMenu = pClass->CreatePluginMenu(url); |
| 1576 if (!hMenu) |
| 1577 { |
| 1578 return 0; |
| 1579 } |
| 1580 |
| 1581 // Display menu |
| 1582 POINT pt; |
| 1583 ::GetCursorPos(&pt); |
| 1584 |
| 1585 RECT rc; |
| 1586 ::GetWindowRect(hWnd, &rc); |
| 1587 |
| 1588 if (rc.left >= 0 && rc.top >= 0) |
| 1589 { |
| 1590 pt.x = rc.left; |
| 1591 pt.y = rc.top; |
| 1592 } |
| 1593 |
| 1594 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN
); |
| 1595 break; |
| 1596 } |
| 1597 case WM_DESTROY: |
| 1598 break; |
| 1599 case SC_CLOSE: |
| 1600 break; |
| 1601 |
| 1602 case WM_UPDATEUISTATE: |
| 1603 { |
| 1604 CPluginTab* tab = GetTabForCurrentThread(); |
| 1605 if (tab) |
| 1606 { |
| 1607 tab->OnActivate(); |
1477 RECT rect; | 1608 RECT rect; |
1478 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (
LPARAM)&rect); | 1609 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1479 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW
idth, iconHeight, NULL, NULL, DI_NORMAL); | 1610 pClass->notificationMessage.MoveToCenter(rect); |
1480 offx += iconWidth; | 1611 } |
1481 } | 1612 if (LOWORD(wParam) == UIS_CLEAR) |
1482 #ifdef _DEBUG | 1613 { |
1483 // Display version | 1614 pClass->notificationMessage.Hide(); |
1484 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT,
0, 0); | 1615 } |
1485 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); | 1616 break; |
1486 | 1617 } |
1487 AdblockPlus::Rectangle rcText = rcClient; | 1618 case WM_WINDOWPOSCHANGING: |
1488 rcText.left += offx; | |
1489 ::SetBkMode(hDC, TRANSPARENT); | |
1490 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT
|DT_SINGLELINE|DT_VCENTER); | |
1491 | |
1492 ::SelectObject(hDC, hOldFont); | |
1493 #endif // _DEBUG | |
1494 } | |
1495 | |
1496 // Done! | |
1497 EndPaint(hWnd, &ps); | |
1498 | |
1499 return 0; | |
1500 } | |
1501 | |
1502 case WM_LBUTTONUP: | |
1503 case WM_RBUTTONUP: | |
1504 { | |
1505 std::wstring url = pClass->GetBrowserUrl(); | |
1506 if (url != pClass->GetTab()->GetDocumentUrl()) | |
1507 { | |
1508 pClass->GetTab()->SetDocumentUrl(url); | |
1509 } | |
1510 | |
1511 // Create menu | |
1512 HMENU hMenu = pClass->CreatePluginMenu(url); | |
1513 if (!hMenu) | |
1514 { | |
1515 return 0; | |
1516 } | |
1517 | |
1518 // Display menu | |
1519 POINT pt; | |
1520 ::GetCursorPos(&pt); | |
1521 | |
1522 RECT rc; | |
1523 ::GetWindowRect(hWnd, &rc); | |
1524 | |
1525 if (rc.left >= 0 && rc.top >= 0) | |
1526 { | |
1527 pt.x = rc.left; | |
1528 pt.y = rc.top; | |
1529 } | |
1530 | |
1531 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN); | |
1532 } | |
1533 break; | |
1534 case WM_DESTROY: | |
1535 break; | |
1536 case SC_CLOSE: | |
1537 break; | |
1538 | |
1539 case WM_UPDATEUISTATE: | |
1540 { | |
1541 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | |
1542 if (tab) | |
1543 { | 1619 { |
1544 RECT rect; | 1620 RECT rect; |
1545 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1621 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1546 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) /
2, rect.top + (rect.bottom - rect.top) / 2); | 1622 if (pClass->notificationMessage.IsVisible()) |
1547 } | 1623 { |
1548 if (LOWORD(wParam) == UIS_CLEAR) | 1624 pClass->notificationMessage.MoveToCenter(rect); |
1549 { | 1625 } |
1550 pClass->notificationMessage.Hide(); | 1626 break; |
1551 } | 1627 } |
1552 } | 1628 case WM_WINDOWPOSCHANGED: |
1553 break; | 1629 { |
1554 case WM_WINDOWPOSCHANGING: | 1630 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); |
1555 { | 1631 if (wndPos->flags & SWP_HIDEWINDOW) |
1556 RECT rect; | 1632 { |
1557 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1633 pClass->notificationMessage.Hide(); |
1558 if (pClass->notificationMessage.IsVisible()) | 1634 } |
1559 { | 1635 break; |
1560 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) /
2, rect.top + (rect.bottom - rect.top) / 2); | 1636 } |
1561 } | 1637 case WM_ALREADY_UP_TO_DATE: |
1562 } | 1638 { |
1563 break; | 1639 Dictionary* dictionary = Dictionary::GetInstance(); |
1564 case WM_WINDOWPOSCHANGED: | 1640 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread
y-up-to-date-text"); |
1565 { | 1641 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea
dy-up-to-date-title"); |
1566 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); | 1642 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle,
TTI_INFO); |
1567 if (wndPos->flags & SWP_HIDEWINDOW) | 1643 break; |
1568 { | 1644 } |
1569 pClass->notificationMessage.Hide(); | 1645 case WM_UPDATE_CHECK_ERROR: |
1570 } | 1646 { |
1571 } | 1647 Dictionary* dictionary = Dictionary::GetInstance(); |
1572 break; | 1648 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex
t"); |
1573 case WM_ALREADY_UP_TO_DATE: | 1649 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti
tle"); |
1574 { | 1650 pClass->notificationMessage.SetTextAndIcon(errorText, errorTitle, TTI_ER
ROR); |
1575 Dictionary* dictionary = Dictionary::GetInstance(); | 1651 break; |
1576 std::wstring upToDateText = dictionary->Lookup("updater", "update-already-
up-to-date-text"); | 1652 } |
1577 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already
-up-to-date-title"); | 1653 case WM_DOWNLOADING_UPDATE: |
1578 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT
I_INFO); | 1654 { |
1579 } | 1655 Dictionary* dictionary = Dictionary::GetInstance(); |
1580 break; | 1656 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin
g-update-text"); |
1581 case WM_UPDATE_CHECK_ERROR: | 1657 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi
ng-update-title"); |
1582 { | 1658 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT
itle, TTI_INFO); |
1583 Dictionary* dictionary = Dictionary::GetInstance(); | 1659 break; |
1584 std::wstring errorText = dictionary->Lookup("updater", "update-error-text"
); | 1660 } |
1585 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl
e"); | 1661 } |
1586 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR
); | 1662 } |
1587 } | 1663 catch (...) |
1588 break; | 1664 { |
1589 case WM_DOWNLOADING_UPDATE: | 1665 // Suppress exception. Fall through to default handler. |
1590 { | 1666 DEBUG_GENERAL(L"CPluginClass::PaneWindowProc - exception"); |
1591 Dictionary* dictionary = Dictionary::GetInstance(); | 1667 } |
1592 std::wstring downloadingText = dictionary->Lookup("updater", "downloading-
update-text"); | 1668 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1593 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading
-update-title"); | |
1594 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit
le, TTI_INFO); | |
1595 } | |
1596 break; | |
1597 } | |
1598 | |
1599 return DefWindowProc(hWnd, message, wParam, lParam); | |
1600 } | 1669 } |
1601 | 1670 |
1602 | 1671 |
1603 void CPluginClass::UpdateStatusBar() | 1672 void CPluginClass::UpdateStatusBar() |
1604 { | 1673 { |
1605 DEBUG_GENERAL("*** Updating statusbar") | 1674 DEBUG_GENERAL("*** Updating statusbar") |
1606 if (m_hPaneWnd == NULL) | 1675 if (m_hPaneWnd == NULL) |
1607 { | 1676 { |
1608 CreateStatusBarPane(); | 1677 CreateStatusBarPane(); |
1609 } | 1678 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 s_criticalSectionLocal.Unlock(); | 1727 s_criticalSectionLocal.Unlock(); |
1659 | 1728 |
1660 return icon; | 1729 return icon; |
1661 } | 1730 } |
1662 | 1731 |
1663 ATOM CPluginClass::GetAtomPaneClass() | 1732 ATOM CPluginClass::GetAtomPaneClass() |
1664 { | 1733 { |
1665 return s_atomPaneClass; | 1734 return s_atomPaneClass; |
1666 } | 1735 } |
1667 | 1736 |
LEFT | RIGHT |