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

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

Issue 29332959: Issue #1173 - Protect more entry points with try-catch blocks (Closed)
Left Patch Set: Created Dec. 22, 2015, 2:13 p.m.
Right Patch Set: Add log messages in new exception handlers Created Jan. 5, 2016, 3:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2015 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 int Width() const 85 int Width() const
86 { 86 {
87 return right - left; 87 return right - left;
88 } 88 }
89 }; 89 };
90 } 90 }
91 91
92 CPluginClass::CPluginClass() 92 CPluginClass::CPluginClass()
93 : m_webBrowser2(nullptr) 93 : m_webBrowser2(nullptr)
94 { 94 {
95 DEBUG_GENERAL([this]() -> std::wstring
96 {
97 std::wstring s = L"CPluginClass::<constructor>, this = ";
98 s += ToHexLiteral(this);
99 return s;
100 }());
101
95 //Use this line to debug memory leaks 102 //Use this line to debug memory leaks
96 // _CrtDumpMemoryLeaks(); 103 // _CrtDumpMemoryLeaks();
97 104
98 m_isAdvised = false; 105 m_isAdvised = false;
99 m_hTabWnd = NULL; 106 m_hTabWnd = NULL;
100 m_hStatusBarWnd = NULL; 107 m_hStatusBarWnd = NULL;
101 m_hPaneWnd = NULL; 108 m_hPaneWnd = NULL;
102 m_nPaneWidth = 0; 109 m_nPaneWidth = 0;
103 m_pWndProcStatus = NULL; 110 m_pWndProcStatus = NULL;
104 m_hTheme = NULL; 111 m_hTheme = NULL;
105 m_isInitializedOk = false; 112 m_isInitializedOk = false;
106 113
107 114
108 m_tab = new CPluginTab(this); 115 m_tab = new CPluginTab();
109 116
110 Dictionary::Create(GetBrowserLanguage()); 117 Dictionary::Create(GetBrowserLanguage());
111 } 118 }
112 119
113 CPluginClass::~CPluginClass() 120 CPluginClass::~CPluginClass()
114 { 121 {
122 DEBUG_GENERAL([this]() -> std::wstring
123 {
124 std::wstring s = L"CPluginClass::<destructor>, this = ";
125 s += ToHexLiteral(this);
126 return s;
127 }());
128
115 delete m_tab; 129 delete m_tab;
116 } 130 }
117 131
118 HWND CPluginClass::GetBrowserHWND() const 132 HWND CPluginClass::GetBrowserHWND() const
119 { 133 {
120 if (!m_webBrowser2) 134 if (!m_webBrowser2)
121 { 135 {
122 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr"); 136 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr");
123 return nullptr; 137 return nullptr;
124 } 138 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE 204 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE
191 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor, 205 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor,
192 * but it is not a proper substitute for one. 206 * but it is not a proper substitute for one.
193 */ 207 */
194 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 208 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
195 { 209 {
196 try 210 try
197 { 211 {
198 if (unknownSite) 212 if (unknownSite)
199 { 213 {
200 214 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================");
201 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
202 215
203 HRESULT hr = ::CoInitialize(NULL); 216 HRESULT hr = ::CoInitialize(NULL);
204 if (FAILED(hr)) 217 if (FAILED(hr))
205 { 218 {
206 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 219 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
207 } 220 }
208 221
209 /* 222 /*
210 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2. 223 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2.
211 */ 224 */
212 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); 225 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite);
213 if (!m_webBrowser2) 226 if (!m_webBrowser2)
214 { 227 {
215 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*"); 228 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*");
216 } 229 }
230 DEBUG_GENERAL([this]() -> std::wstring
231 {
232 std::wstringstream ss;
233 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
234 ss << L", browser = " << ToHexLiteral(m_webBrowser2);
235 return ss.str();
236 }());
217 237
218 //register the mimefilter 238 //register the mimefilter
219 //and only mimefilter 239 //and only mimefilter
220 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 240 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
221 s_criticalSectionLocal.Lock(); 241 s_criticalSectionLocal.Lock();
222 { 242 {
223 // Always register on startup, then check if we need to unregister in a separate thread 243 // Always register on startup, then check if we need to unregister in a separate thread
224 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 244 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
225 s_asyncWebBrowser2 = unknownSite; 245 s_asyncWebBrowser2 = unknownSite;
226 s_instances.insert(this); 246 s_instances.insert(this);
227 } 247 }
228 s_criticalSectionLocal.Unlock(); 248 s_criticalSectionLocal.Unlock();
229 249
230 try 250 try
231 { 251 {
232 DEBUG_GENERAL("Loaded as BHO");
233 HRESULT hr = DispEventAdvise(m_webBrowser2); 252 HRESULT hr = DispEventAdvise(m_webBrowser2);
234 if (SUCCEEDED(hr)) 253 if (SUCCEEDED(hr))
235 { 254 {
236 m_isAdvised = true; 255 m_isAdvised = true;
237 try 256 try
238 { 257 {
239 std::thread startInitObjectThread(StartInitObject, this); 258 std::thread startInitObjectThread(StartInitObject, this);
240 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr. 259 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
241 } 260 }
242 catch (const std::system_error& ex) 261 catch (const std::system_error& ex)
243 { 262 {
244 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, 263 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS,
245 "Class::Thread - Failed to create StartInitObject thread"); 264 "Class::Thread - Failed to create StartInitObject thread");
246 } 265 }
247 } 266 }
248 else 267 else
249 { 268 {
250 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise"); 269 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
251 } 270 }
252 } 271 }
253 catch (const std::runtime_error& ex) 272 catch (const std::runtime_error& ex)
254 { 273 {
255 DEBUG_EXCEPTION(ex); 274 DEBUG_EXCEPTION(ex);
256 Unadvise(); 275 Unadvise();
257 } 276 }
258 } 277 }
259 else 278 else
260 { 279 {
280 DEBUG_GENERAL([this]() -> std::wstring
281 {
282 std::wstringstream ss;
283 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
284 ss << L", browser = nullptr";
285 return ss.str();
286 }());
287
261 Unadvise(); 288 Unadvise();
262 289
263 // Destroy window 290 // Destroy window
264 if (m_pWndProcStatus) 291 if (m_pWndProcStatus)
265 { 292 {
266 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus); 293 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus);
267 294
268 m_pWndProcStatus = NULL; 295 m_pWndProcStatus = NULL;
269 } 296 }
270 297
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 { 1003 {
977 try 1004 try
978 { 1005 {
979 if (cCmds == 0) return E_INVALIDARG; 1006 if (cCmds == 0) return E_INVALIDARG;
980 if (prgCmds == 0) return E_POINTER; 1007 if (prgCmds == 0) return E_POINTER;
981 1008
982 prgCmds[0].cmdf = OLECMDF_ENABLED; 1009 prgCmds[0].cmdf = OLECMDF_ENABLED;
983 } 1010 }
984 catch (...) 1011 catch (...)
985 { 1012 {
1013 DEBUG_GENERAL(L"CPluginClass::QueryStatus - exception");
986 return E_FAIL; 1014 return E_FAIL;
987 } 1015 }
988 return S_OK; 1016 return S_OK;
989 } 1017 }
990 1018
991 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) 1019 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
992 { 1020 {
993 DEBUG_GENERAL("CreatePluginMenu"); 1021 DEBUG_GENERAL("CreatePluginMenu");
994 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1022 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
995 1023
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1290 }
1263 else 1291 else
1264 { 1292 {
1265 nFlags |= TPM_LEFTALIGN; 1293 nFlags |= TPM_LEFTALIGN;
1266 } 1294 }
1267 1295
1268 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); 1296 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags);
1269 } 1297 }
1270 catch (...) 1298 catch (...)
1271 { 1299 {
1272 return E_FAIL; // 1300 // Suppress exception, log only
Oleksandr 2016/01/04 10:46:13 Nit: there was a comment intended here?
Eric 2016/01/04 16:44:24 Yes. Added.
1301 DEBUG_GENERAL(L"CPluginClass::Exec - exception");
1302 return E_FAIL;
1273 } 1303 }
1274 1304
1275 return S_OK; 1305 return S_OK;
1276 } 1306 }
1277 1307
1278 // Entry point 1308 // Entry point
1279 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) 1309 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam)
1280 { 1310 {
1311 CPluginClass *pClass;
1281 try 1312 try
1282 { 1313 {
1283 // Find tab 1314 // Find tab
1284 CPluginClass *pClass = FindInstance(hWnd); 1315 pClass = FindInstance(hWnd);
1285 if (!pClass) 1316 if (!pClass)
1286 { 1317 {
1318 /*
1319 * Race condition if reached.
1320 * We did not unhook the window procedure for the status bar when the last BHO instance using it terminated.
1321 * The next best thing is to call the system default window function.
1322 */
1287 return DefWindowProc(hWnd, message, wParam, lParam); 1323 return DefWindowProc(hWnd, message, wParam, lParam);
Eric 2016/01/04 16:44:24 Race condition here.
1288 } 1324 }
1289 1325
1290 // Process message 1326 // Process message
1291 switch (message) 1327 switch (message)
1292 { 1328 {
1293 case SB_SIMPLE: 1329 case SB_SIMPLE:
1294 { 1330 {
1295 ShowWindow(pClass->m_hPaneWnd, !wParam); 1331 ShowWindow(pClass->m_hPaneWnd, !wParam);
1296 break; 1332 break;
1297 } 1333 }
1298 1334
1299 case WM_SYSCOLORCHANGE: 1335 case WM_SYSCOLORCHANGE:
1300 { 1336 {
1301 pClass->UpdateTheme(); 1337 pClass->UpdateTheme();
1302 break; 1338 break;
1303 } 1339 }
1304 1340
1305 case SB_SETPARTS: 1341 case SB_SETPARTS:
1306 { 1342 {
1307 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) 1343 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd))
1308 { 1344 {
1309 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param); 1345 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1310 } 1346 }
1311 1347
1312 WPARAM nParts = wParam; 1348 WPARAM nParts = wParam;
1313 if (STATUSBAR_PANE_NUMBER >= nParts) 1349 if (STATUSBAR_PANE_NUMBER >= nParts)
1314 { 1350 {
1315 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param); 1351 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1316 } 1352 }
1317 1353
1318 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1)); 1354 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1));
1319 LPINT lpParts = (LPINT)LocalLock(hLocal); 1355 LPINT lpParts = (LPINT)LocalLock(hLocal);
1320 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); 1356 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1321 1357
1322 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) 1358 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1323 { 1359 {
1324 lpParts[i] -= pClass->m_nPaneWidth; 1360 lpParts[i] -= pClass->m_nPaneWidth;
1325 } 1361 }
1326 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts); 1362 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w Param, (LPARAM)lpParts);
1327 1363
1328 AdblockPlus::Rectangle rcPane; 1364 AdblockPlus::Rectangle rcPane;
1329 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); 1365 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1330 1366
1331 AdblockPlus::Rectangle rcClient; 1367 AdblockPlus::Rectangle rcClient;
1332 ::GetClientRect(hWnd, &rcClient); 1368 ::GetClientRect(hWnd, &rcClient);
1333 1369
1334 ::MoveWindow( 1370 ::MoveWindow(
1335 pClass->m_hPaneWnd, 1371 pClass->m_hPaneWnd,
1336 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, 1372 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1337 0, 1373 0,
1338 pClass->m_nPaneWidth, 1374 pClass->m_nPaneWidth,
1339 rcClient.Height(), 1375 rcClient.Height(),
1340 TRUE); 1376 TRUE);
1341 1377
1342 ::LocalFree(hLocal); 1378 ::LocalFree(hLocal);
1343 1379 return hRet;
1344 1380 }
1345 return hRet;
1346 }
1347 1381
1348 default: 1382 default:
1349 break; 1383 break;
1350 } 1384 }
1351
1352 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, lParam);
1353
1354
1355 return result;
1356 } 1385 }
1357 catch (...) 1386 catch (...)
1358 { 1387 {
1359 return E_FAIL; 1388 // Suppress exception. Fall through to default handler.
Oleksandr 2016/01/04 10:46:13 I think we should call: return DefWindowProc(hWnd,
sergei 2016/01/04 11:27:36 It's better to use CallWindowProc instead of DefWi
Eric 2016/01/04 16:44:24 Sergei's right. This observation also points out
1360 } 1389 DEBUG_GENERAL(L"CPluginClass::NewStatusProc - exception");
1390 }
1391 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m);
1361 } 1392 }
1362 1393
1363 1394
1364 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) 1395 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1365 { 1396 {
1366 // use the disable icon as defualt, if the client doesn't exists 1397 // use the disable icon as defualt, if the client doesn't exists
1367 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1398 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1368 1399
1369 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1400 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1370 if (tab) 1401 if (tab)
(...skipping 23 matching lines...) Expand all
1394 // Find tab 1425 // Find tab
1395 CPluginClass *pClass = FindInstance(GetParent(hWnd)); 1426 CPluginClass *pClass = FindInstance(GetParent(hWnd));
1396 if (!pClass) 1427 if (!pClass)
1397 { 1428 {
1398 return ::DefWindowProc(hWnd, message, wParam, lParam); 1429 return ::DefWindowProc(hWnd, message, wParam, lParam);
1399 } 1430 }
1400 1431
1401 // Process message 1432 // Process message
1402 switch (message) 1433 switch (message)
1403 { 1434 {
1404
1405 case WM_SETCURSOR: 1435 case WM_SETCURSOR:
1406 { 1436 {
1407 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); 1437 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
1408 return TRUE; 1438 return TRUE;
1409 } 1439 }
1410 case WM_PAINT: 1440 case WM_PAINT:
1411 { 1441 {
1412 PAINTSTRUCT ps; 1442 PAINTSTRUCT ps;
1413 HDC hDC = ::BeginPaint(hWnd, &ps); 1443 HDC hDC = ::BeginPaint(hWnd, &ps);
1414 1444
1415 AdblockPlus::Rectangle rcClient; 1445 AdblockPlus::Rectangle rcClient;
1416 ::GetClientRect(hWnd, &rcClient); 1446 ::GetClientRect(hWnd, &rcClient);
1417 1447
1418 int nDrawEdge = 0; 1448 int nDrawEdge = 0;
1419 1449
1420 // Old Windows background drawing 1450 // Old Windows background drawing
1421 if (pClass->m_hTheme == NULL) 1451 if (pClass->m_hTheme == NULL)
1422 { 1452 {
1423 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); 1453 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1));
1424 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); 1454 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT);
1425 1455
1426 nDrawEdge = 3; 1456 nDrawEdge = 3;
1427 rcClient.left += 3; 1457 rcClient.left += 3;
1428 1458
1429 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); 1459 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT);
1430 } 1460 }
1431 // Themed background drawing 1461 // Themed background drawing
1432 else 1462 else
1433 { 1463 {
1434 // Draw background 1464 // Draw background
1435 if (pfnDrawThemeBackground) 1465 if (pfnDrawThemeBackground)
1436 {
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 { 1466 {
1450 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); 1467 AdblockPlus::Rectangle rc = rcClient;
1451 1468 rc.right -= 2;
1452 // Ignore black boxes (if source is obscured by other windows) 1469 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1453 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) 1470 }
1471
1472 // Copy separator picture to left side
1473 int nHeight = rcClient.Height();
1474 int nWidth = rcClient.Width() - 2;
1475
1476 for (int i = 0; i < 2; i++)
1477 {
1478 for (int j = 0; j < nHeight; j++)
1454 { 1479 {
1455 ::SetPixel(hDC, i, j, clr); 1480 COLORREF clr = ::GetPixel(hDC, i + nWidth, j);
1481
1482 // Ignore black boxes (if source is obscured by other windows)
1483 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB Value(clr) > 8))
1484 {
1485 ::SetPixel(hDC, i, j, clr);
1486 }
1456 } 1487 }
1457 } 1488 }
1458 } 1489 }
1459 } 1490
1460 1491 // Draw icon
1461 // Draw icon 1492 if (CPluginClient::GetInstance())
1462 if (CPluginClient::GetInstance()) 1493 {
1463 { 1494 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1464 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); 1495
1465 1496 int offx = nDrawEdge;
1466 int offx = nDrawEdge; 1497 if (hIcon)
1467 if (hIcon) 1498 {
1468 { 1499 //Get the RECT for the leftmost pane (the status text pane)
1469 //Get the RECT for the leftmost pane (the status text pane) 1500 RECT rect;
1470 RECT rect; 1501 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&rect);
1471 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, ( LPARAM)&rect); 1502 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico nWidth, iconHeight, NULL, NULL, DI_NORMAL);
1472 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW idth, iconHeight, NULL, NULL, DI_NORMAL); 1503 offx += iconWidth;
1473 offx += iconWidth; 1504 }
1474 }
1475 #ifdef _DEBUG 1505 #ifdef _DEBUG
1476 // Display version 1506 // Display version
1477 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1507 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT , 0, 0);
1478 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont); 1508 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont);
1479 1509
1480 AdblockPlus::Rectangle rcText = rcClient; 1510 AdblockPlus::Rectangle rcText = rcClient;
1481 rcText.left += offx; 1511 rcText.left += offx;
1482 ::SetBkMode(hDC, TRANSPARENT); 1512 ::SetBkMode(hDC, TRANSPARENT);
1483 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_LE FT | DT_SINGLELINE | DT_VCENTER); 1513 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_ LEFT | DT_SINGLELINE | DT_VCENTER);
1484 1514
1485 ::SelectObject(hDC, hOldFont); 1515 ::SelectObject(hDC, hOldFont);
1486 #endif // _DEBUG 1516 #endif // _DEBUG
1487 } 1517 }
1488 1518
1489 // Done! 1519 // Done!
1490 EndPaint(hWnd, &ps); 1520 EndPaint(hWnd, &ps);
1491 1521
1492 return 0; 1522 return 0;
1493 } 1523 }
1494 1524
1495 case WM_LBUTTONUP: 1525 case WM_LBUTTONUP:
1496 case WM_RBUTTONUP: 1526 case WM_RBUTTONUP:
1497 { 1527 {
1498 std::wstring url = pClass->GetBrowserUrl(); 1528 std::wstring url = pClass->GetBrowserUrl();
1499 if (url != pClass->GetTab()->GetDocumentUrl()) 1529 if (url != pClass->GetTab()->GetDocumentUrl())
1500 { 1530 {
1501 pClass->GetTab()->SetDocumentUrl(url); 1531 pClass->GetTab()->SetDocumentUrl(url);
1502 } 1532 }
1503 1533
1504 // Create menu 1534 // Create menu
1505 HMENU hMenu = pClass->CreatePluginMenu(url); 1535 HMENU hMenu = pClass->CreatePluginMenu(url);
1506 if (!hMenu) 1536 if (!hMenu)
1507 { 1537 {
1508 return 0; 1538 return 0;
1509 } 1539 }
1510 1540
1511 // Display menu 1541 // Display menu
1512 POINT pt; 1542 POINT pt;
1513 ::GetCursorPos(&pt); 1543 ::GetCursorPos(&pt);
1514 1544
1515 RECT rc; 1545 RECT rc;
1516 ::GetWindowRect(hWnd, &rc); 1546 ::GetWindowRect(hWnd, &rc);
1517 1547
1518 if (rc.left >= 0 && rc.top >= 0) 1548 if (rc.left >= 0 && rc.top >= 0)
1519 { 1549 {
1520 pt.x = rc.left; 1550 pt.x = rc.left;
1521 pt.y = rc.top; 1551 pt.y = rc.top;
1522 } 1552 }
1523 1553
1524 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN); 1554 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN );
1525 } 1555 break;
1526 break; 1556 }
1527 case WM_DESTROY: 1557 case WM_DESTROY:
1528 break; 1558 break;
1529 case SC_CLOSE: 1559 case SC_CLOSE:
1530 break; 1560 break;
1531 1561
1532 case WM_UPDATEUISTATE: 1562 case WM_UPDATEUISTATE:
1533 { 1563 {
1534 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1564 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1535 if (tab) 1565 if (tab)
1536 { 1566 {
1537 tab->OnActivate(); 1567 tab->OnActivate();
1568 RECT rect;
1569 GetWindowRect(pClass->m_hPaneWnd, &rect);
1570 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
1571 }
1572 if (LOWORD(wParam) == UIS_CLEAR)
1573 {
1574 pClass->notificationMessage.Hide();
1575 }
1576 break;
1577 }
1578 case WM_WINDOWPOSCHANGING:
1579 {
1538 RECT rect; 1580 RECT rect;
1539 GetWindowRect(pClass->m_hPaneWnd, &rect); 1581 GetWindowRect(pClass->m_hPaneWnd, &rect);
1540 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); 1582 if (pClass->notificationMessage.IsVisible())
1541 } 1583 {
1542 if (LOWORD(wParam) == UIS_CLEAR) 1584 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
1543 { 1585 }
1544 pClass->notificationMessage.Hide(); 1586 break;
1545 } 1587 }
1546 }
1547 break;
1548 case WM_WINDOWPOSCHANGING:
1549 {
1550 RECT rect;
1551 GetWindowRect(pClass->m_hPaneWnd, &rect);
1552 if (pClass->notificationMessage.IsVisible())
1553 {
1554 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
1555 }
1556 }
1557 break;
1558 case WM_WINDOWPOSCHANGED: 1588 case WM_WINDOWPOSCHANGED:
1559 { 1589 {
1560 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); 1590 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam);
1561 if (wndPos->flags & SWP_HIDEWINDOW) 1591 if (wndPos->flags & SWP_HIDEWINDOW)
1562 { 1592 {
1563 pClass->notificationMessage.Hide(); 1593 pClass->notificationMessage.Hide();
1564 } 1594 }
1565 } 1595 break;
1566 break; 1596 }
1567 case WM_ALREADY_UP_TO_DATE: 1597 case WM_ALREADY_UP_TO_DATE:
1568 { 1598 {
1569 Dictionary* dictionary = Dictionary::GetInstance(); 1599 Dictionary* dictionary = Dictionary::GetInstance();
1570 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); 1600 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread y-up-to-date-text");
1571 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title"); 1601 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea dy-up-to-date-title");
1572 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT I_INFO); 1602 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TTI_INFO);
1573 } 1603 break;
1574 break; 1604 }
1575 case WM_UPDATE_CHECK_ERROR: 1605 case WM_UPDATE_CHECK_ERROR:
1576 { 1606 {
1577 Dictionary* dictionary = Dictionary::GetInstance(); 1607 Dictionary* dictionary = Dictionary::GetInstance();
1578 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); 1608 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex t");
1579 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); 1609 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti tle");
1580 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR ); 1610 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERR OR);
1581 } 1611 break;
1582 break; 1612 }
1583 case WM_DOWNLOADING_UPDATE: 1613 case WM_DOWNLOADING_UPDATE:
1584 { 1614 {
1585 Dictionary* dictionary = Dictionary::GetInstance(); 1615 Dictionary* dictionary = Dictionary::GetInstance();
1586 std::wstring downloadingText = dictionary->Lookup("updater", "downloading- update-text"); 1616 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin g-update-text");
1587 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading -update-title"); 1617 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi ng-update-title");
1588 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit le, TTI_INFO); 1618 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT itle, TTI_INFO);
1589 } 1619 break;
1590 break; 1620 }
1591 } 1621 }
1592
1593 return DefWindowProc(hWnd, message, wParam, lParam);
1594 } 1622 }
1595 catch (...) 1623 catch (...)
1596 { 1624 {
1597 return E_FAIL; 1625 // Suppress exception. Fall through to default handler.
Oleksandr 2016/01/04 10:46:13 Same here. I think we should do 'return DefWindowP
Eric 2016/01/04 16:44:24 Done. Replace with a comment. Moved call to 'DefW
1598 } 1626 DEBUG_GENERAL(L"CPluginClass::PaneWindowProc - exception");
1627 }
1628 return ::DefWindowProc(hWnd, message, wParam, lParam);
1599 } 1629 }
1600 1630
1601 1631
1602 void CPluginClass::UpdateStatusBar() 1632 void CPluginClass::UpdateStatusBar()
1603 { 1633 {
1604 DEBUG_GENERAL("*** Updating statusbar") 1634 DEBUG_GENERAL("*** Updating statusbar")
1605 if (m_hPaneWnd == NULL) 1635 if (m_hPaneWnd == NULL)
1606 { 1636 {
1607 CreateStatusBarPane(); 1637 CreateStatusBarPane();
1608 } 1638 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 s_criticalSectionLocal.Unlock(); 1687 s_criticalSectionLocal.Unlock();
1658 1688
1659 return icon; 1689 return icon;
1660 } 1690 }
1661 1691
1662 ATOM CPluginClass::GetAtomPaneClass() 1692 ATOM CPluginClass::GetAtomPaneClass()
1663 { 1693 {
1664 return s_atomPaneClass; 1694 return s_atomPaneClass;
1665 } 1695 }
1666 1696
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld