Left: | ||
Right: |
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 * |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 ATOM CPluginClass::s_atomPaneClass = NULL; | 58 ATOM CPluginClass::s_atomPaneClass = NULL; |
59 HINSTANCE CPluginClass::s_hUxtheme = NULL; | 59 HINSTANCE CPluginClass::s_hUxtheme = NULL; |
60 std::set<CPluginClass*> CPluginClass::s_instances; | 60 std::set<CPluginClass*> CPluginClass::s_instances; |
61 | 61 |
62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; | 62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; |
63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; | 63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; |
64 | 64 |
65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; | 65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; |
66 | 66 |
67 | 67 namespace |
sergei
2016/02/01 15:50:43
Why not to put it into anonymous namespace?
Eric
2016/02/03 17:17:05
OK.
| |
68 /** | 68 { |
69 * A synchronized map whose key is always the current thread ID. | 69 /** |
70 */ | 70 * A synchronized map whose key is always the current thread ID. |
71 class CurrentThreadMap | 71 */ |
72 : public SyncMap<DWORD, CPluginClass*, nullptr> | 72 class CurrentThreadMap |
73 { | 73 : public SyncMap<DWORD, CPluginClass*, nullptr> |
74 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base; | 74 { |
75 | 75 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base; |
76 public: | 76 |
77 bool AddIfAbsent(CPluginClass* p) | 77 public: |
78 { | 78 bool AddIfAbsent(CPluginClass* p) |
79 return Base::AddIfAbsent(::GetCurrentThreadId(), p); | 79 { |
80 } | 80 return Base::AddIfAbsent(::GetCurrentThreadId(), p); |
81 | 81 } |
82 bool RemoveAndCheck() | 82 |
83 { | 83 bool RemoveAndCheck() |
84 return Base::RemoveAndCheck(::GetCurrentThreadId()); | 84 { |
85 } | 85 return Base::RemoveIfPresent(::GetCurrentThreadId()); |
86 | 86 } |
87 CPluginClass* Locate() | 87 |
88 { | 88 CPluginClass* Locate() |
89 return Base::Locate(::GetCurrentThreadId()); | 89 { |
90 } | 90 return Base::Locate(::GetCurrentThreadId()); |
91 }; | 91 } |
92 | 92 }; |
93 /** | 93 |
94 * Map from thread ID's to CPluginClass instances | 94 /** |
95 */ | 95 * Map from thread ID's to CPluginClass instances |
96 CurrentThreadMap threadMap; | 96 */ |
sergei
2016/02/01 15:50:43
Off topic: Still a global variable. When will we s
Eric
2016/02/03 17:17:05
The map from threads to BHO instances is inherentl
| |
97 CurrentThreadMap threadMap; | |
98 } | |
97 | 99 |
98 /* | 100 /* |
99 * Without namespace declaration, the identifier "Rectangle" is ambiguous | 101 * Without namespace declaration, the identifier "Rectangle" is ambiguous |
100 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx | 102 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx |
101 */ | 103 */ |
102 namespace AdblockPlus | 104 namespace AdblockPlus |
103 { | 105 { |
104 /** | 106 /** |
105 * Replacement for ATL type CRect. | 107 * Replacement for ATL type CRect. |
106 */ | 108 */ |
107 class Rectangle | 109 class Rectangle |
108 : public RECT | 110 : public RECT |
109 { | 111 { |
110 public: | 112 public: |
111 int Height() const | 113 unsigned long Height() const |
112 { | 114 { |
113 return bottom - top; | 115 if (bottom < top) |
114 } | 116 { |
115 | 117 throw std::runtime_error("invariant violation: rectangle bottom < top"); |
116 int Width() const | 118 } |
117 { | 119 return static_cast<unsigned long>(bottom - top); |
118 return right - left; | 120 } |
121 | |
122 unsigned long Width() const | |
123 { | |
124 if (right < left) | |
125 { | |
126 throw std::runtime_error("invariant violation: rectangle right < left"); | |
127 } | |
128 return static_cast<unsigned long>(right - left); | |
119 } | 129 } |
120 }; | 130 }; |
121 } | 131 } |
122 | 132 |
123 CPluginClass::CPluginClass() | 133 CPluginClass::CPluginClass() |
124 : m_webBrowser2(nullptr) | 134 : m_webBrowser2(nullptr) |
125 { | 135 { |
136 DEBUG_GENERAL([this]() -> std::wstring | |
137 { | |
138 std::wstring s = L"CPluginClass::<constructor>, this = "; | |
139 s += ToHexLiteral(this); | |
140 return s; | |
141 }()); | |
142 | |
126 //Use this line to debug memory leaks | 143 //Use this line to debug memory leaks |
127 // _CrtDumpMemoryLeaks(); | 144 // _CrtDumpMemoryLeaks(); |
128 | 145 |
129 m_isAdvised = false; | 146 m_isAdvised = false; |
130 m_hTabWnd = NULL; | 147 m_hTabWnd = NULL; |
131 m_hStatusBarWnd = NULL; | 148 m_hStatusBarWnd = NULL; |
132 m_hPaneWnd = NULL; | 149 m_hPaneWnd = NULL; |
133 m_nPaneWidth = 0; | 150 m_nPaneWidth = 0; |
134 m_pWndProcStatus = NULL; | 151 m_pWndProcStatus = NULL; |
135 m_hTheme = NULL; | 152 m_hTheme = NULL; |
136 m_isInitializedOk = false; | 153 m_isInitializedOk = false; |
137 m_tab = new CPluginTab(this); | 154 m_tab = new CPluginTab(); |
138 Dictionary::Create(GetBrowserLanguage()); | 155 Dictionary::Create(GetBrowserLanguage()); |
139 } | 156 } |
140 | 157 |
141 CPluginClass::~CPluginClass() | 158 CPluginClass::~CPluginClass() |
142 { | 159 { |
160 DEBUG_GENERAL([this]() -> std::wstring | |
161 { | |
162 std::wstring s = L"CPluginClass::<destructor>, this = "; | |
163 s += ToHexLiteral(this); | |
164 return s; | |
165 }()); | |
166 | |
143 delete m_tab; | 167 delete m_tab; |
144 } | 168 } |
145 | 169 |
146 HWND CPluginClass::GetBrowserHWND() const | 170 HWND CPluginClass::GetBrowserHWND() const |
147 { | 171 { |
148 if (!m_webBrowser2) | 172 if (!m_webBrowser2) |
149 { | 173 { |
150 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr"); | 174 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr"); |
151 return nullptr; | 175 return nullptr; |
152 } | 176 } |
(...skipping 24 matching lines...) Expand all Loading... | |
177 | 201 |
178 return browser; | 202 return browser; |
179 } | 203 } |
180 | 204 |
181 std::wstring CPluginClass::GetBrowserUrl() const | 205 std::wstring CPluginClass::GetBrowserUrl() const |
182 { | 206 { |
183 std::wstring url; | 207 std::wstring url; |
184 if (m_webBrowser2) | 208 if (m_webBrowser2) |
185 { | 209 { |
186 CComBSTR bstrURL; | 210 CComBSTR bstrURL; |
187 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL) | 211 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL))) |
188 { | 212 { |
189 url = std::wstring(bstrURL, SysStringLen(bstrURL)); | 213 url = ToWstring(bstrURL); |
190 } | 214 } |
191 } | 215 } |
192 else | 216 else |
193 { | 217 { |
194 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr owser2 == nullptr"); | 218 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with m_webBrowser2 == nullptr (probable invariant violation)"); |
219 } | |
220 if (url.empty()) | |
221 { | |
195 url = m_tab->GetDocumentUrl(); | 222 url = m_tab->GetDocumentUrl(); |
196 } | 223 } |
197 return url; | 224 return url; |
198 } | 225 } |
199 | 226 |
200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 227 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
201 { | 228 { |
202 if (thisPtr == NULL) | 229 if (thisPtr == NULL) |
203 return 0; | 230 return 0; |
204 if (!((CPluginClass*)thisPtr)->InitObject()) | 231 if (!((CPluginClass*)thisPtr)->InitObject()) |
(...skipping 13 matching lines...) Expand all Loading... | |
218 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE | 245 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE |
219 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor, | 246 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor, |
220 * but it is not a proper substitute for one. | 247 * but it is not a proper substitute for one. |
221 */ | 248 */ |
222 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) | 249 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) |
223 { | 250 { |
224 try | 251 try |
225 { | 252 { |
226 if (unknownSite) | 253 if (unknownSite) |
227 { | 254 { |
228 | 255 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ===================================="); |
229 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================") | |
230 | 256 |
231 HRESULT hr = ::CoInitialize(NULL); | 257 HRESULT hr = ::CoInitialize(NULL); |
232 if (FAILED(hr)) | 258 if (FAILED(hr)) |
233 { | 259 { |
234 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); | 260 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); |
235 } | 261 } |
236 | 262 |
237 /* | 263 /* |
238 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2. | 264 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2. |
239 */ | 265 */ |
240 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); | 266 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); |
241 if (!m_webBrowser2) | 267 if (!m_webBrowser2) |
242 { | 268 { |
243 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*"); | 269 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*"); |
244 } | 270 } |
271 DEBUG_GENERAL([this]() -> std::wstring | |
272 { | |
273 std::wstringstream ss; | |
274 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); | |
275 ss << L", browser = " << ToHexLiteral(m_webBrowser2); | |
276 return ss.str(); | |
277 }()); | |
245 | 278 |
246 /* | 279 /* |
247 * Add ourselves to the thread map. | 280 * Add ourselves to the thread map. |
248 */ | 281 */ |
249 if (!threadMap.AddIfAbsent(this)) | 282 if (!threadMap.AddIfAbsent(this)) |
250 { | 283 { |
251 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi ng entry in thread map"); | 284 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi ng entry in thread map"); |
sergei
2016/02/01 15:50:43
That looks suspicious. It can happen that two inst
Eric
2016/02/03 17:17:05
Actually, that cannot happen.
| |
252 } | 285 } |
253 | 286 |
254 //register the mimefilter | 287 //register the mimefilter |
255 //and only mimefilter | 288 //and only mimefilter |
256 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread | 289 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread |
257 s_criticalSectionLocal.Lock(); | 290 s_criticalSectionLocal.Lock(); |
258 { | 291 { |
259 // Always register on startup, then check if we need to unregister in a separate thread | 292 // Always register on startup, then check if we need to unregister in a separate thread |
260 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 293 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
261 s_asyncWebBrowser2 = unknownSite; | 294 s_asyncWebBrowser2 = unknownSite; |
262 s_instances.insert(this); | 295 s_instances.insert(this); |
263 } | 296 } |
264 s_criticalSectionLocal.Unlock(); | 297 s_criticalSectionLocal.Unlock(); |
265 | 298 |
266 try | 299 try |
267 { | 300 { |
268 DEBUG_GENERAL("Loaded as BHO"); | |
269 HRESULT hr = DispEventAdvise(m_webBrowser2); | 301 HRESULT hr = DispEventAdvise(m_webBrowser2); |
270 if (SUCCEEDED(hr)) | 302 if (SUCCEEDED(hr)) |
271 { | 303 { |
272 m_isAdvised = true; | 304 m_isAdvised = true; |
273 try | 305 try |
274 { | 306 { |
275 std::thread startInitObjectThread(StartInitObject, this); | 307 std::thread startInitObjectThread(StartInitObject, this); |
276 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr. | 308 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr. |
277 } | 309 } |
278 catch (const std::system_error& ex) | 310 catch (const std::system_error& ex) |
279 { | 311 { |
280 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, | 312 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, |
281 "Class::Thread - Failed to create StartInitObject thread"); | 313 "Class::Thread - Failed to create StartInitObject thread"); |
282 } | 314 } |
283 } | 315 } |
284 else | 316 else |
285 { | 317 { |
286 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise"); | 318 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise"); |
287 } | 319 } |
288 } | 320 } |
289 catch (const std::runtime_error& ex) | 321 catch (const std::runtime_error& ex) |
290 { | 322 { |
291 DEBUG_EXCEPTION(ex); | 323 DEBUG_EXCEPTION(ex); |
292 Unadvise(); | 324 Unadvise(); |
293 } | 325 } |
294 } | 326 } |
295 else | 327 else |
296 { | 328 { |
329 DEBUG_GENERAL([this]() -> std::wstring | |
330 { | |
331 std::wstringstream ss; | |
332 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); | |
333 ss << L", browser = nullptr"; | |
334 return ss.str(); | |
335 }()); | |
336 | |
297 Unadvise(); | 337 Unadvise(); |
298 | 338 |
299 // Destroy window | 339 // Destroy window |
300 if (m_pWndProcStatus) | 340 if (m_pWndProcStatus) |
301 { | 341 { |
302 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus); | 342 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus); |
303 | 343 |
304 m_pWndProcStatus = NULL; | 344 m_pWndProcStatus = NULL; |
305 } | 345 } |
306 | 346 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 { | 515 { |
476 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; | 516 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; |
477 if (!webBrowser) | 517 if (!webBrowser) |
478 { | 518 { |
479 return; | 519 return; |
480 } | 520 } |
481 if (!urlVariant || urlVariant->vt != VT_BSTR) | 521 if (!urlVariant || urlVariant->vt != VT_BSTR) |
482 { | 522 { |
483 return; | 523 return; |
484 } | 524 } |
485 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); | 525 std::wstring url = ToWstring(urlVariant->bstrVal); |
486 | 526 |
487 // If webbrowser2 is equal to top level browser (as set in SetSite), we are | 527 // If webbrowser2 is equal to top level browser (as set in SetSite), we are |
488 // navigating new page | 528 // navigating new page |
489 CPluginClient* client = CPluginClient::GetInstance(); | 529 CPluginClient* client = CPluginClient::GetInstance(); |
490 if (url.find(L"javascript") == 0) | 530 if (url.find(L"javascript") == 0) |
491 { | 531 { |
492 } | 532 } |
493 else if (IsRootBrowser(webBrowser)) | 533 else if (IsRootBrowser(webBrowser)) |
494 { | 534 { |
495 m_tab->OnNavigate(url); | 535 m_tab->OnNavigate(url); |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 s_criticalSectionLocal.Unlock(); | 1017 s_criticalSectionLocal.Unlock(); |
978 | 1018 |
979 return result; | 1019 return result; |
980 } | 1020 } |
981 | 1021 |
982 CPluginTab* CPluginClass::GetTab() | 1022 CPluginTab* CPluginClass::GetTab() |
983 { | 1023 { |
984 return m_tab; | 1024 return m_tab; |
985 } | 1025 } |
986 | 1026 |
987 CPluginTab* CPluginClass::GetTabCurrentThread() | 1027 CPluginTab* CPluginClass::GetTabForCurrentThread() |
988 { | 1028 { |
989 auto p = threadMap.Locate(); | 1029 auto p = threadMap.Locate(); |
990 return p ? p->m_tab : nullptr; | 1030 return p ? p->m_tab : nullptr; |
991 } | 1031 } |
992 | 1032 |
993 | 1033 // Entry point |
994 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) | 1034 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) |
995 { | 1035 { |
996 if (cCmds == 0) return E_INVALIDARG; | 1036 try |
997 if (prgCmds == 0) return E_POINTER; | 1037 { |
998 | 1038 if (cCmds == 0) return E_INVALIDARG; |
999 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1039 if (prgCmds == 0) return E_POINTER; |
1000 | 1040 |
1041 prgCmds[0].cmdf = OLECMDF_ENABLED; | |
1042 } | |
1043 catch (...) | |
1044 { | |
1045 DEBUG_GENERAL(L"CPluginClass::QueryStatus - exception"); | |
1046 return E_FAIL; | |
1047 } | |
1001 return S_OK; | 1048 return S_OK; |
1002 } | 1049 } |
1003 | 1050 |
1004 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) | 1051 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) |
1005 { | 1052 { |
1006 DEBUG_GENERAL("CreatePluginMenu"); | 1053 DEBUG_GENERAL("CreatePluginMenu"); |
1007 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1054 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
1008 | 1055 |
1009 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1056 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
1010 | 1057 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1140 | 1187 |
1141 MENUITEMINFOW miiSep = {}; | 1188 MENUITEMINFOW miiSep = {}; |
1142 miiSep.cbSize = sizeof(miiSep); | 1189 miiSep.cbSize = sizeof(miiSep); |
1143 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 1190 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |
1144 miiSep.fType = MFT_SEPARATOR; | 1191 miiSep.fType = MFT_SEPARATOR; |
1145 | 1192 |
1146 CPluginClient* client = CPluginClient::GetInstance(); | 1193 CPluginClient* client = CPluginClient::GetInstance(); |
1147 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1194 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1148 { | 1195 { |
1149 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 1196 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |
1150 // Is domain in white list? | |
1151 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); | 1197 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); |
1152 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) | 1198 /* |
1153 { | 1199 * The display state of the "disable on this site" menu item depends upon ta b content |
1200 */ | |
1201 if (!GetTab()->IsPossibleToDisableOnSite()) | |
1202 { | |
1203 // Since we can't disable the present content, | |
1204 // it makes no sense to offer the user an option to block it. | |
1205 fmii.fState = MFS_UNCHECKED | MFS_DISABLED; | |
1206 } | |
1207 else if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) | |
1208 { | |
1209 // Domain is in white list, indicated by a check mark | |
1154 fmii.fState = MFS_CHECKED | MFS_ENABLED; | 1210 fmii.fState = MFS_CHECKED | MFS_ENABLED; |
1155 } | 1211 } |
1156 else | 1212 else |
1157 { | 1213 { |
1158 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 1214 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |
1159 } | 1215 } |
1160 fmii.fMask = MIIM_STRING | MIIM_STATE; | 1216 fmii.fMask = MIIM_STRING | MIIM_STATE; |
1161 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1217 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1162 fmii.cch = static_cast<UINT>(ctext.size()); | 1218 fmii.cch = static_cast<UINT>(ctext.size()); |
1163 | 1219 |
(...skipping 28 matching lines...) Expand all Loading... | |
1192 ctext = dictionary->Lookup("menu", "menu-settings"); | 1248 ctext = dictionary->Lookup("menu", "menu-settings"); |
1193 fmii.fMask = MIIM_STATE | MIIM_STRING; | 1249 fmii.fMask = MIIM_STATE | MIIM_STRING; |
1194 fmii.fState = MFS_ENABLED; | 1250 fmii.fState = MFS_ENABLED; |
1195 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1251 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1196 fmii.cch = static_cast<UINT>(ctext.size()); | 1252 fmii.cch = static_cast<UINT>(ctext.size()); |
1197 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); | 1253 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); |
1198 | 1254 |
1199 return true; | 1255 return true; |
1200 } | 1256 } |
1201 | 1257 |
1202 | 1258 // Entry point |
1203 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) | 1259 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) |
1204 { | 1260 { |
1205 HWND hBrowserWnd = GetBrowserHWND(); | 1261 try |
1206 if (!hBrowserWnd) | 1262 { |
1207 { | 1263 HWND hBrowserWnd = GetBrowserHWND(); |
1208 return E_FAIL; | 1264 if (!hBrowserWnd) |
1209 } | 1265 { |
1210 | 1266 return E_FAIL; |
1211 // Create menu | 1267 } |
1212 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); | 1268 |
1213 if (!hMenu) | 1269 // Create menu |
1214 { | 1270 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); |
1215 return E_FAIL; | 1271 if (!hMenu) |
1216 } | 1272 { |
1217 | 1273 return E_FAIL; |
1218 // Check if button in toolbar was pressed | 1274 } |
1219 int nIDCommand = -1; | 1275 |
1220 BOOL bRightAlign = FALSE; | 1276 // Check if button in toolbar was pressed |
1221 | 1277 int nIDCommand = -1; |
1222 POINT pt; | 1278 BOOL bRightAlign = FALSE; |
1223 GetCursorPos(&pt); | 1279 |
1224 | 1280 POINT pt; |
1225 HWND hWndToolBar = ::WindowFromPoint(pt); | 1281 GetCursorPos(&pt); |
1226 | 1282 |
1227 DWORD nProcessId; | 1283 HWND hWndToolBar = ::WindowFromPoint(pt); |
1228 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | 1284 |
1229 | 1285 DWORD nProcessId; |
1230 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | 1286 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |
1231 { | 1287 |
1232 ::ScreenToClient(hWndToolBar, &pt); | 1288 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |
1233 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | 1289 { |
1234 | 1290 ::ScreenToClient(hWndToolBar, &pt); |
1235 if (nButton > 0) | 1291 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |
1236 { | 1292 |
1237 TBBUTTON pTBBtn = {}; | 1293 if (nButton > 0) |
1238 | 1294 { |
1239 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 1295 TBBUTTON pTBBtn = {}; |
1240 { | 1296 |
1241 RECT rcButton; | 1297 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |
1242 nIDCommand = pTBBtn.idCommand; | 1298 { |
1243 | 1299 RECT rcButton; |
1244 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) | 1300 nIDCommand = pTBBtn.idCommand; |
1245 { | 1301 |
1246 pt.x = rcButton.left; | 1302 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton )) |
1247 pt.y = rcButton.bottom; | |
1248 ClientToScreen(hWndToolBar, &pt); | |
1249 | |
1250 RECT rcWorkArea; | |
1251 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
1252 if (rcWorkArea.right - pt.x < 150) | |
1253 { | 1303 { |
1254 bRightAlign = TRUE; | 1304 pt.x = rcButton.left; |
1255 pt.x = rcButton.right; | |
1256 pt.y = rcButton.bottom; | 1305 pt.y = rcButton.bottom; |
1257 ClientToScreen(hWndToolBar, &pt); | 1306 ClientToScreen(hWndToolBar, &pt); |
1307 | |
1308 RECT rcWorkArea; | |
1309 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
1310 if (rcWorkArea.right - pt.x < 150) | |
1311 { | |
1312 bRightAlign = TRUE; | |
1313 pt.x = rcButton.right; | |
1314 pt.y = rcButton.bottom; | |
1315 ClientToScreen(hWndToolBar, &pt); | |
1316 } | |
1258 } | 1317 } |
1259 } | 1318 } |
1260 } | 1319 } |
1320 else | |
1321 { | |
1322 GetCursorPos(&pt); | |
1323 } | |
1324 } | |
1325 | |
1326 // Display menu | |
1327 UINT nFlags = 0; | |
1328 if (bRightAlign) | |
1329 { | |
1330 nFlags |= TPM_RIGHTALIGN; | |
1261 } | 1331 } |
1262 else | 1332 else |
1263 { | 1333 { |
1264 GetCursorPos(&pt); | 1334 nFlags |= TPM_LEFTALIGN; |
1265 } | 1335 } |
1266 } | 1336 |
1267 | 1337 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); |
1268 // Display menu | 1338 } |
1269 UINT nFlags = 0; | 1339 catch (...) |
1270 if (bRightAlign) | 1340 { |
1271 { | 1341 // Suppress exception, log only |
1272 nFlags |= TPM_RIGHTALIGN; | 1342 DEBUG_GENERAL(L"CPluginClass::Exec - exception"); |
1273 } | 1343 return E_FAIL; |
1274 else | 1344 } |
1275 { | |
1276 nFlags |= TPM_LEFTALIGN; | |
1277 } | |
1278 | |
1279 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | |
1280 | 1345 |
1281 return S_OK; | 1346 return S_OK; |
1282 } | 1347 } |
1283 | 1348 |
1284 ///////////////////////////////////////////////////////////////////////////// | 1349 // Entry point |
1285 // Window procedures | |
1286 | |
1287 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) | 1350 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) |
1288 { | 1351 { |
1289 // Find tab | 1352 CPluginClass *pClass; |
1290 CPluginClass *pClass = FindInstance(hWnd); | 1353 try |
1291 if (!pClass) | 1354 { |
1292 { | 1355 // Find tab |
1293 return DefWindowProc(hWnd, message, wParam, lParam); | 1356 pClass = FindInstance(hWnd); |
1294 } | 1357 if (!pClass) |
1295 | 1358 { |
1296 // Process message | 1359 /* |
1297 switch (message) | 1360 * Race condition if reached. |
1298 { | 1361 * We did not unhook the window procedure for the status bar when the last BHO instance using it terminated. |
1299 case SB_SIMPLE: | 1362 * The next best thing is to call the system default window function. |
1300 { | 1363 */ |
1301 ShowWindow(pClass->m_hPaneWnd, !wParam); | 1364 return DefWindowProc(hWnd, message, wParam, lParam); |
1365 } | |
1366 | |
1367 // Process message | |
1368 switch (message) | |
1369 { | |
1370 case SB_SIMPLE: | |
1371 { | |
1372 ShowWindow(pClass->m_hPaneWnd, !wParam); | |
1373 break; | |
1374 } | |
1375 | |
1376 case WM_SYSCOLORCHANGE: | |
1377 { | |
1378 pClass->UpdateTheme(); | |
1379 break; | |
1380 } | |
1381 | |
1382 case SB_SETPARTS: | |
1383 { | |
1384 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) | |
1385 { | |
1386 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam); | |
1387 } | |
1388 | |
1389 WPARAM nParts = wParam; | |
1390 if (STATUSBAR_PANE_NUMBER >= nParts) | |
1391 { | |
1392 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam); | |
1393 } | |
1394 | |
1395 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1)); | |
1396 LPINT lpParts = (LPINT)LocalLock(hLocal); | |
1397 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | |
1398 | |
1399 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | |
1400 { | |
1401 lpParts[i] -= pClass->m_nPaneWidth; | |
1402 } | |
1403 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w Param, (LPARAM)lpParts); | |
1404 | |
1405 AdblockPlus::Rectangle rcPane; | |
1406 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | |
1407 | |
1408 AdblockPlus::Rectangle rcClient; | |
1409 ::GetClientRect(hWnd, &rcClient); | |
1410 | |
1411 ::MoveWindow( | |
1412 pClass->m_hPaneWnd, | |
1413 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | |
1414 0, | |
1415 pClass->m_nPaneWidth, | |
1416 rcClient.Height(), | |
1417 TRUE); | |
1418 | |
1419 ::LocalFree(hLocal); | |
1420 return hRet; | |
1421 } | |
1422 | |
1423 default: | |
1302 break; | 1424 break; |
1303 } | 1425 } |
1304 | 1426 } |
1305 case WM_SYSCOLORCHANGE: | 1427 catch (...) |
1306 { | 1428 { |
1307 pClass->UpdateTheme(); | 1429 // Suppress exception. Fall through to default handler. |
1308 break; | 1430 DEBUG_GENERAL(L"CPluginClass::NewStatusProc - exception"); |
1309 } | 1431 } |
1310 | 1432 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m); |
1311 case SB_SETPARTS: | |
1312 { | |
1313 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) | |
1314 { | |
1315 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param); | |
1316 } | |
1317 | |
1318 WPARAM nParts = wParam; | |
1319 if (STATUSBAR_PANE_NUMBER >= nParts) | |
1320 { | |
1321 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param); | |
1322 } | |
1323 | |
1324 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); | |
1325 LPINT lpParts = (LPINT)LocalLock(hLocal); | |
1326 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | |
1327 | |
1328 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | |
1329 { | |
1330 lpParts[i] -= pClass->m_nPaneWidth; | |
1331 } | |
1332 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts); | |
1333 | |
1334 AdblockPlus::Rectangle rcPane; | |
1335 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | |
1336 | |
1337 AdblockPlus::Rectangle rcClient; | |
1338 ::GetClientRect(hWnd, &rcClient); | |
1339 | |
1340 ::MoveWindow( | |
1341 pClass->m_hPaneWnd, | |
1342 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | |
1343 0, | |
1344 pClass->m_nPaneWidth, | |
1345 rcClient.Height(), | |
1346 TRUE); | |
1347 | |
1348 ::LocalFree(hLocal); | |
1349 | |
1350 | |
1351 return hRet; | |
1352 } | |
1353 | |
1354 default: | |
1355 break; | |
1356 } | |
1357 | |
1358 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); | |
1359 | |
1360 | |
1361 return result; | |
1362 | |
1363 } | 1433 } |
1364 | 1434 |
1365 | 1435 |
1366 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) | 1436 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1367 { | 1437 { |
1368 // use the disable icon as defualt, if the client doesn't exists | 1438 // use the disable icon as defualt, if the client doesn't exists |
1369 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1439 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1370 | 1440 |
1371 CPluginTab* tab = GetTabCurrentThread(); | 1441 CPluginTab* tab = GetTabForCurrentThread(); |
1372 if (tab) | 1442 if (tab) |
1373 { | 1443 { |
1374 CPluginClient* client = CPluginClient::GetInstance(); | 1444 CPluginClient* client = CPluginClient::GetInstance(); |
1375 if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 1445 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1376 { | 1446 { |
1377 if (client->IsWhitelistedUrl(url)) | 1447 if (client->IsWhitelistedUrl(url)) |
1378 { | 1448 { |
1379 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1449 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1380 } | 1450 } |
1381 else | 1451 else |
1382 { | 1452 { |
1383 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1453 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1384 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 1454 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1385 } | 1455 } |
1386 } | 1456 } |
1387 } | 1457 } |
1388 return hIcon; | 1458 return hIcon; |
1389 } | 1459 } |
1390 | 1460 |
1391 | 1461 // Entry point |
1392 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) | 1462 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) |
1393 { | 1463 { |
1394 // Find tab | 1464 try |
1395 CPluginClass *pClass = FindInstance(GetParent(hWnd)); | 1465 { |
1396 if (!pClass) | 1466 // Find tab |
1397 { | 1467 CPluginClass *pClass = FindInstance(GetParent(hWnd)); |
1398 return ::DefWindowProc(hWnd, message, wParam, lParam); | 1468 if (!pClass) |
1399 } | 1469 { |
1400 | 1470 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1401 // Process message | 1471 } |
1402 switch (message) | 1472 |
1403 { | 1473 // Process message |
1404 | 1474 switch (message) |
1405 case WM_SETCURSOR: | 1475 { |
1406 { | 1476 case WM_SETCURSOR: |
1407 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); | 1477 { |
1408 return TRUE; | 1478 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); |
1409 } | 1479 return TRUE; |
1410 case WM_PAINT: | 1480 } |
1411 { | 1481 case WM_PAINT: |
1412 PAINTSTRUCT ps; | 1482 { |
1413 HDC hDC = ::BeginPaint(hWnd, &ps); | 1483 PAINTSTRUCT ps; |
1414 | 1484 HDC hDC = ::BeginPaint(hWnd, &ps); |
1415 AdblockPlus::Rectangle rcClient; | 1485 |
1416 ::GetClientRect(hWnd, &rcClient); | 1486 AdblockPlus::Rectangle rcClient; |
1417 | 1487 ::GetClientRect(hWnd, &rcClient); |
1418 int nDrawEdge = 0; | 1488 |
1419 | 1489 int nDrawEdge = 0; |
1420 // Old Windows background drawing | 1490 |
1421 if (pClass->m_hTheme == NULL) | 1491 // Old Windows background drawing |
1422 { | 1492 if (pClass->m_hTheme == NULL) |
1423 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); | 1493 { |
1424 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); | 1494 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); |
1425 | 1495 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); |
1426 nDrawEdge = 3; | 1496 |
1427 rcClient.left += 3; | 1497 nDrawEdge = 3; |
1428 | 1498 rcClient.left += 3; |
1429 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); | 1499 |
1430 } | 1500 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); |
1431 // Themed background drawing | 1501 } |
1432 else | 1502 // Themed background drawing |
1433 { | 1503 else |
1434 // Draw background | 1504 { |
1435 if (pfnDrawThemeBackground) | 1505 // Draw background |
1436 { | 1506 if (pfnDrawThemeBackground) |
1437 AdblockPlus::Rectangle rc = rcClient; | |
1438 rc.right -= 2; | |
1439 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); | |
1440 } | |
1441 | |
1442 // Copy separator picture to left side | |
1443 int nHeight = rcClient.Height(); | |
1444 int nWidth = rcClient.Width() - 2; | |
1445 | |
1446 for (int i = 0; i < 2; i++) | |
1447 { | |
1448 for (int j = 0; j < nHeight; j++) | |
1449 { | 1507 { |
1450 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); | 1508 AdblockPlus::Rectangle rc = rcClient; |
1451 | 1509 rc.right -= 2; |
1452 // Ignore black boxes (if source is obscured by other windows) | 1510 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); |
1453 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) | 1511 } |
1512 | |
1513 // Copy separator picture to left side | |
1514 int nHeight = rcClient.Height(); | |
1515 int nWidth = rcClient.Width() - 2; | |
1516 | |
1517 for (int i = 0; i < 2; i++) | |
1518 { | |
1519 for (int j = 0; j < nHeight; j++) | |
1454 { | 1520 { |
1455 ::SetPixel(hDC, i, j, clr); | 1521 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); |
1522 | |
1523 // Ignore black boxes (if source is obscured by other windows) | |
1524 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB Value(clr) > 8)) | |
1525 { | |
1526 ::SetPixel(hDC, i, j, clr); | |
1527 } | |
1456 } | 1528 } |
1457 } | 1529 } |
1458 } | 1530 } |
1459 } | 1531 |
1460 | 1532 // Draw icon |
1461 // Draw icon | 1533 if (CPluginClient::GetInstance()) |
1462 if (CPluginClient::GetInstance()) | 1534 { |
1463 { | 1535 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); |
1464 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); | 1536 |
1465 | 1537 int offx = nDrawEdge; |
1466 int offx = nDrawEdge; | 1538 if (hIcon) |
1467 if (hIcon) | 1539 { |
1468 { | 1540 //Get the RECT for the leftmost pane (the status text pane) |
1469 //Get the RECT for the leftmost pane (the status text pane) | 1541 RECT rect; |
1542 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&rect); | |
1543 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico nWidth, iconHeight, NULL, NULL, DI_NORMAL); | |
1544 offx += iconWidth; | |
1545 } | |
1546 #ifdef _DEBUG | |
1547 // Display version | |
1548 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT , 0, 0); | |
1549 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont); | |
1550 | |
1551 AdblockPlus::Rectangle rcText = rcClient; | |
1552 rcText.left += offx; | |
1553 ::SetBkMode(hDC, TRANSPARENT); | |
1554 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_ LEFT | DT_SINGLELINE | DT_VCENTER); | |
1555 | |
1556 ::SelectObject(hDC, hOldFont); | |
1557 #endif // _DEBUG | |
1558 } | |
1559 | |
1560 // Done! | |
1561 EndPaint(hWnd, &ps); | |
1562 | |
1563 return 0; | |
1564 } | |
1565 | |
1566 case WM_LBUTTONUP: | |
1567 case WM_RBUTTONUP: | |
1568 { | |
1569 std::wstring url = pClass->GetBrowserUrl(); | |
1570 if (url != pClass->GetTab()->GetDocumentUrl()) | |
1571 { | |
1572 pClass->GetTab()->SetDocumentUrl(url); | |
1573 } | |
1574 | |
1575 // Create menu | |
1576 HMENU hMenu = pClass->CreatePluginMenu(url); | |
1577 if (!hMenu) | |
1578 { | |
1579 return 0; | |
1580 } | |
1581 | |
1582 // Display menu | |
1583 POINT pt; | |
1584 ::GetCursorPos(&pt); | |
1585 | |
1586 RECT rc; | |
1587 ::GetWindowRect(hWnd, &rc); | |
1588 | |
1589 if (rc.left >= 0 && rc.top >= 0) | |
1590 { | |
1591 pt.x = rc.left; | |
1592 pt.y = rc.top; | |
1593 } | |
1594 | |
1595 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN ); | |
1596 break; | |
1597 } | |
1598 case WM_DESTROY: | |
1599 break; | |
1600 case SC_CLOSE: | |
1601 break; | |
1602 | |
1603 case WM_UPDATEUISTATE: | |
1604 { | |
1605 CPluginTab* tab = GetTabForCurrentThread(); | |
1606 if (tab) | |
1607 { | |
1608 tab->OnActivate(); | |
1470 RECT rect; | 1609 RECT rect; |
1471 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, ( LPARAM)&rect); | 1610 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1472 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW idth, iconHeight, NULL, NULL, DI_NORMAL); | 1611 pClass->notificationMessage.MoveToCenter(rect); |
1473 offx += iconWidth; | 1612 } |
1474 } | 1613 if (LOWORD(wParam) == UIS_CLEAR) |
1475 #ifdef _DEBUG | 1614 { |
1476 // Display version | 1615 pClass->notificationMessage.Hide(); |
1477 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); | 1616 } |
1478 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); | 1617 break; |
1479 | 1618 } |
1480 AdblockPlus::Rectangle rcText = rcClient; | 1619 case WM_WINDOWPOSCHANGING: |
1481 rcText.left += offx; | 1620 { |
1482 ::SetBkMode(hDC, TRANSPARENT); | |
1483 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER); | |
1484 | |
1485 ::SelectObject(hDC, hOldFont); | |
1486 #endif // _DEBUG | |
1487 } | |
1488 | |
1489 // Done! | |
1490 EndPaint(hWnd, &ps); | |
1491 | |
1492 return 0; | |
1493 } | |
1494 | |
1495 case WM_LBUTTONUP: | |
1496 case WM_RBUTTONUP: | |
1497 { | |
1498 std::wstring url = pClass->GetBrowserUrl(); | |
1499 if (url != pClass->GetTab()->GetDocumentUrl()) | |
1500 { | |
1501 pClass->GetTab()->SetDocumentUrl(url); | |
1502 } | |
1503 | |
1504 // Create menu | |
1505 HMENU hMenu = pClass->CreatePluginMenu(url); | |
1506 if (!hMenu) | |
1507 { | |
1508 return 0; | |
1509 } | |
1510 | |
1511 // Display menu | |
1512 POINT pt; | |
1513 ::GetCursorPos(&pt); | |
1514 | |
1515 RECT rc; | |
1516 ::GetWindowRect(hWnd, &rc); | |
1517 | |
1518 if (rc.left >= 0 && rc.top >= 0) | |
1519 { | |
1520 pt.x = rc.left; | |
1521 pt.y = rc.top; | |
1522 } | |
1523 | |
1524 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN); | |
1525 } | |
1526 break; | |
1527 case WM_DESTROY: | |
1528 break; | |
1529 case SC_CLOSE: | |
1530 break; | |
1531 | |
1532 case WM_UPDATEUISTATE: | |
1533 { | |
1534 CPluginTab* tab = GetTabCurrentThread(); | |
1535 if (tab) | |
1536 { | |
1537 tab->OnActivate(); | |
1538 RECT rect; | 1621 RECT rect; |
1539 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1622 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1540 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); | 1623 if (pClass->notificationMessage.IsVisible()) |
1541 } | 1624 { |
1542 if (LOWORD(wParam) == UIS_CLEAR) | 1625 pClass->notificationMessage.MoveToCenter(rect); |
1543 { | 1626 } |
1544 pClass->notificationMessage.Hide(); | 1627 break; |
1545 } | 1628 } |
1546 } | 1629 case WM_WINDOWPOSCHANGED: |
1547 break; | 1630 { |
1548 case WM_WINDOWPOSCHANGING: | 1631 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); |
1549 { | 1632 if (wndPos->flags & SWP_HIDEWINDOW) |
1550 RECT rect; | 1633 { |
1551 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1634 pClass->notificationMessage.Hide(); |
1552 if (pClass->notificationMessage.IsVisible()) | 1635 } |
1553 { | 1636 break; |
1554 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); | 1637 } |
1555 } | 1638 case WM_ALREADY_UP_TO_DATE: |
1556 } | 1639 { |
1557 break; | 1640 Dictionary* dictionary = Dictionary::GetInstance(); |
1558 case WM_WINDOWPOSCHANGED: | 1641 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread y-up-to-date-text"); |
1559 { | 1642 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea dy-up-to-date-title"); |
1560 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); | 1643 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TTI_INFO); |
1561 if (wndPos->flags & SWP_HIDEWINDOW) | 1644 break; |
1562 { | 1645 } |
1563 pClass->notificationMessage.Hide(); | 1646 case WM_UPDATE_CHECK_ERROR: |
1564 } | 1647 { |
1565 } | 1648 Dictionary* dictionary = Dictionary::GetInstance(); |
1566 break; | 1649 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex t"); |
1567 case WM_ALREADY_UP_TO_DATE: | 1650 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti tle"); |
1568 { | 1651 pClass->notificationMessage.SetTextAndIcon(errorText, errorTitle, TTI_ER ROR); |
1569 Dictionary* dictionary = Dictionary::GetInstance(); | 1652 break; |
1570 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); | 1653 } |
1571 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title"); | 1654 case WM_DOWNLOADING_UPDATE: |
1572 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT I_INFO); | 1655 { |
1573 } | 1656 Dictionary* dictionary = Dictionary::GetInstance(); |
1574 break; | 1657 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin g-update-text"); |
1575 case WM_UPDATE_CHECK_ERROR: | 1658 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi ng-update-title"); |
1576 { | 1659 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT itle, TTI_INFO); |
1577 Dictionary* dictionary = Dictionary::GetInstance(); | 1660 break; |
1578 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); | 1661 } |
1579 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); | 1662 } |
1580 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR ); | 1663 } |
1581 } | 1664 catch (...) |
1582 break; | 1665 { |
1583 case WM_DOWNLOADING_UPDATE: | 1666 // Suppress exception. Fall through to default handler. |
1584 { | 1667 DEBUG_GENERAL(L"CPluginClass::PaneWindowProc - exception"); |
1585 Dictionary* dictionary = Dictionary::GetInstance(); | 1668 } |
1586 std::wstring downloadingText = dictionary->Lookup("updater", "downloading- update-text"); | 1669 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1587 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading -update-title"); | |
1588 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit le, TTI_INFO); | |
1589 } | |
1590 break; | |
1591 } | |
1592 | |
1593 return DefWindowProc(hWnd, message, wParam, lParam); | |
1594 } | 1670 } |
1595 | 1671 |
1596 | 1672 |
1597 void CPluginClass::UpdateStatusBar() | 1673 void CPluginClass::UpdateStatusBar() |
1598 { | 1674 { |
1599 DEBUG_GENERAL("*** Updating statusbar") | 1675 DEBUG_GENERAL("*** Updating statusbar") |
1600 if (m_hPaneWnd == NULL) | 1676 if (m_hPaneWnd == NULL) |
1601 { | 1677 { |
1602 CreateStatusBarPane(); | 1678 CreateStatusBarPane(); |
1603 } | 1679 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 s_criticalSectionLocal.Unlock(); | 1728 s_criticalSectionLocal.Unlock(); |
1653 | 1729 |
1654 return icon; | 1730 return icon; |
1655 } | 1731 } |
1656 | 1732 |
1657 ATOM CPluginClass::GetAtomPaneClass() | 1733 ATOM CPluginClass::GetAtomPaneClass() |
1658 { | 1734 { |
1659 return s_atomPaneClass; | 1735 return s_atomPaneClass; |
1660 } | 1736 } |
1661 | 1737 |
LEFT | RIGHT |