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

Side by Side Diff: src/plugin/PluginClass.cpp

Issue 29332959: Issue #1173 - Protect more entry points with try-catch blocks (Closed)
Patch Set: rebase only Created Jan. 5, 2016, 3:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 if (it != s_threadInstances.end()) 991 if (it != s_threadInstances.end())
992 { 992 {
993 tab = it->second->m_tab; 993 tab = it->second->m_tab;
994 } 994 }
995 } 995 }
996 s_criticalSectionLocal.Unlock(); 996 s_criticalSectionLocal.Unlock();
997 997
998 return tab; 998 return tab;
999 } 999 }
1000 1000
1001 1001 // Entry point
1002 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1002 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1003 { 1003 {
1004 if (cCmds == 0) return E_INVALIDARG; 1004 try
1005 if (prgCmds == 0) return E_POINTER; 1005 {
1006 if (cCmds == 0) return E_INVALIDARG;
1007 if (prgCmds == 0) return E_POINTER;
1006 1008
1007 prgCmds[0].cmdf = OLECMDF_ENABLED; 1009 prgCmds[0].cmdf = OLECMDF_ENABLED;
1008 1010 }
1011 catch (...)
1012 {
1013 return E_FAIL;
1014 }
1009 return S_OK; 1015 return S_OK;
1010 } 1016 }
1011 1017
1012 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) 1018 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
1013 { 1019 {
1014 DEBUG_GENERAL("CreatePluginMenu"); 1020 DEBUG_GENERAL("CreatePluginMenu");
1015 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1021 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1016 1022
1017 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1023 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1018 1024
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 ctext = dictionary->Lookup("menu", "menu-settings"); 1206 ctext = dictionary->Lookup("menu", "menu-settings");
1201 fmii.fMask = MIIM_STATE | MIIM_STRING; 1207 fmii.fMask = MIIM_STATE | MIIM_STRING;
1202 fmii.fState = MFS_ENABLED; 1208 fmii.fState = MFS_ENABLED;
1203 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1209 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1204 fmii.cch = static_cast<UINT>(ctext.size()); 1210 fmii.cch = static_cast<UINT>(ctext.size());
1205 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); 1211 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii);
1206 1212
1207 return true; 1213 return true;
1208 } 1214 }
1209 1215
1210 1216 // Entry point
1211 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) 1217 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*)
1212 { 1218 {
1213 HWND hBrowserWnd = GetBrowserHWND(); 1219 try
1214 if (!hBrowserWnd)
1215 { 1220 {
1216 return E_FAIL; 1221 HWND hBrowserWnd = GetBrowserHWND();
1217 } 1222 if (!hBrowserWnd)
1223 {
1224 return E_FAIL;
1225 }
1218 1226
1219 // Create menu 1227 // Create menu
1220 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); 1228 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl());
1221 if (!hMenu) 1229 if (!hMenu)
1222 { 1230 {
1223 return E_FAIL; 1231 return E_FAIL;
1224 } 1232 }
1225 1233
1226 // Check if button in toolbar was pressed 1234 // Check if button in toolbar was pressed
1227 int nIDCommand = -1; 1235 int nIDCommand = -1;
1228 BOOL bRightAlign = FALSE; 1236 BOOL bRightAlign = FALSE;
1229 1237
1230 POINT pt; 1238 POINT pt;
1231 GetCursorPos(&pt); 1239 GetCursorPos(&pt);
1232 1240
1233 HWND hWndToolBar = ::WindowFromPoint(pt); 1241 HWND hWndToolBar = ::WindowFromPoint(pt);
1234 1242
1235 DWORD nProcessId; 1243 DWORD nProcessId;
1236 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); 1244 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId);
1237 1245
1238 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) 1246 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId)
1239 { 1247 {
1240 ::ScreenToClient(hWndToolBar, &pt); 1248 ::ScreenToClient(hWndToolBar, &pt);
1241 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); 1249 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt);
1242 1250
1243 if (nButton > 0) 1251 if (nButton > 0)
1244 { 1252 {
1245 TBBUTTON pTBBtn = {}; 1253 TBBUTTON pTBBtn = {};
1246 1254
1247 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) 1255 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn))
1248 { 1256 {
1249 RECT rcButton; 1257 RECT rcButton;
1250 nIDCommand = pTBBtn.idCommand; 1258 nIDCommand = pTBBtn.idCommand;
1251 1259
1252 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) 1260 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton ))
1253 {
1254 pt.x = rcButton.left;
1255 pt.y = rcButton.bottom;
1256 ClientToScreen(hWndToolBar, &pt);
1257
1258 RECT rcWorkArea;
1259 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0);
1260 if (rcWorkArea.right - pt.x < 150)
1261 { 1261 {
1262 bRightAlign = TRUE; 1262 pt.x = rcButton.left;
1263 pt.x = rcButton.right;
1264 pt.y = rcButton.bottom; 1263 pt.y = rcButton.bottom;
1265 ClientToScreen(hWndToolBar, &pt); 1264 ClientToScreen(hWndToolBar, &pt);
1265
1266 RECT rcWorkArea;
1267 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0);
1268 if (rcWorkArea.right - pt.x < 150)
1269 {
1270 bRightAlign = TRUE;
1271 pt.x = rcButton.right;
1272 pt.y = rcButton.bottom;
1273 ClientToScreen(hWndToolBar, &pt);
1274 }
1266 } 1275 }
1267 } 1276 }
1268 } 1277 }
1278 else
1279 {
1280 GetCursorPos(&pt);
1281 }
1282 }
1283
1284 // Display menu
1285 UINT nFlags = 0;
1286 if (bRightAlign)
1287 {
1288 nFlags |= TPM_RIGHTALIGN;
1269 } 1289 }
1270 else 1290 else
1271 { 1291 {
1272 GetCursorPos(&pt); 1292 nFlags |= TPM_LEFTALIGN;
1273 } 1293 }
1294
1295 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags);
1274 } 1296 }
1275 1297 catch (...)
1276 // Display menu
1277 UINT nFlags = 0;
1278 if (bRightAlign)
1279 { 1298 {
1280 nFlags |= TPM_RIGHTALIGN; 1299 return E_FAIL; // Suppress exceptions, should log
1281 } 1300 }
1282 else
1283 {
1284 nFlags |= TPM_LEFTALIGN;
1285 }
1286
1287 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags);
1288 1301
1289 return S_OK; 1302 return S_OK;
1290 } 1303 }
1291 1304
1292 ///////////////////////////////////////////////////////////////////////////// 1305 // Entry point
1293 // Window procedures
1294
1295 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) 1306 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam)
1296 { 1307 {
1297 // Find tab 1308 CPluginClass *pClass;
1298 CPluginClass *pClass = FindInstance(hWnd); 1309 try
1299 if (!pClass)
1300 { 1310 {
1301 return DefWindowProc(hWnd, message, wParam, lParam); 1311 // Find tab
1302 } 1312 pClass = FindInstance(hWnd);
1313 if (!pClass)
1314 {
1315 /*
1316 * Race condition if reached.
1317 * We did not unhook the window procedure for the status bar when the last BHO instance using it terminated.
1318 * The next best thing is to call the system default window function.
1319 */
1320 return DefWindowProc(hWnd, message, wParam, lParam);
1321 }
1303 1322
1304 // Process message 1323 // Process message
1305 switch (message) 1324 switch (message)
1306 {
1307 case SB_SIMPLE:
1308 { 1325 {
1309 ShowWindow(pClass->m_hPaneWnd, !wParam); 1326 case SB_SIMPLE:
1327 {
1328 ShowWindow(pClass->m_hPaneWnd, !wParam);
1329 break;
1330 }
1331
1332 case WM_SYSCOLORCHANGE:
1333 {
1334 pClass->UpdateTheme();
1335 break;
1336 }
1337
1338 case SB_SETPARTS:
1339 {
1340 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd))
1341 {
1342 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1343 }
1344
1345 WPARAM nParts = wParam;
1346 if (STATUSBAR_PANE_NUMBER >= nParts)
1347 {
1348 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1349 }
1350
1351 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1));
1352 LPINT lpParts = (LPINT)LocalLock(hLocal);
1353 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1354
1355 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1356 {
1357 lpParts[i] -= pClass->m_nPaneWidth;
1358 }
1359 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w Param, (LPARAM)lpParts);
1360
1361 AdblockPlus::Rectangle rcPane;
1362 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1363
1364 AdblockPlus::Rectangle rcClient;
1365 ::GetClientRect(hWnd, &rcClient);
1366
1367 ::MoveWindow(
1368 pClass->m_hPaneWnd,
1369 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1370 0,
1371 pClass->m_nPaneWidth,
1372 rcClient.Height(),
1373 TRUE);
1374
1375 ::LocalFree(hLocal);
1376 return hRet;
1377 }
1378
1379 default:
1310 break; 1380 break;
1311 } 1381 }
1312
1313 case WM_SYSCOLORCHANGE:
1314 {
1315 pClass->UpdateTheme();
1316 break;
1317 }
1318
1319 case SB_SETPARTS:
1320 {
1321 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd))
1322 {
1323 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param);
1324 }
1325
1326 WPARAM nParts = wParam;
1327 if (STATUSBAR_PANE_NUMBER >= nParts)
1328 {
1329 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param);
1330 }
1331
1332 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1));
1333 LPINT lpParts = (LPINT)LocalLock(hLocal);
1334 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1335
1336 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1337 {
1338 lpParts[i] -= pClass->m_nPaneWidth;
1339 }
1340 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts);
1341
1342 AdblockPlus::Rectangle rcPane;
1343 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1344
1345 AdblockPlus::Rectangle rcClient;
1346 ::GetClientRect(hWnd, &rcClient);
1347
1348 ::MoveWindow(
1349 pClass->m_hPaneWnd,
1350 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1351 0,
1352 pClass->m_nPaneWidth,
1353 rcClient.Height(),
1354 TRUE);
1355
1356 ::LocalFree(hLocal);
1357
1358
1359 return hRet;
1360 }
1361
1362 default:
1363 break;
1364 } 1382 }
1365 1383 catch (...)
1366 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); 1384 {
1367 1385 // Suppress exception. Fall through to default handler.
1368 1386 }
1369 return result; 1387 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m);
1370
1371 } 1388 }
1372 1389
1373 1390
1374 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) 1391 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1375 { 1392 {
1376 // use the disable icon as defualt, if the client doesn't exists 1393 // use the disable icon as defualt, if the client doesn't exists
1377 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1394 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1378 1395
1379 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1396 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1380 if (tab) 1397 if (tab)
1381 { 1398 {
1382 CPluginClient* client = CPluginClient::GetInstance(); 1399 CPluginClient* client = CPluginClient::GetInstance();
1383 if (CPluginSettings::GetInstance()->IsPluginEnabled()) 1400 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1384 { 1401 {
1385 if (client->IsWhitelistedUrl(url)) 1402 if (client->IsWhitelistedUrl(url))
1386 { 1403 {
1387 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1404 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1388 } 1405 }
1389 else 1406 else
1390 { 1407 {
1391 CPluginSettings* settings = CPluginSettings::GetInstance(); 1408 CPluginSettings* settings = CPluginSettings::GetInstance();
1392 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1409 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1393 } 1410 }
1394 } 1411 }
1395 } 1412 }
1396 return hIcon; 1413 return hIcon;
1397 } 1414 }
1398 1415
1399 1416 // Entry point
1400 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) 1417 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam)
1401 { 1418 {
1402 // Find tab 1419 try
1403 CPluginClass *pClass = FindInstance(GetParent(hWnd));
1404 if (!pClass)
1405 { 1420 {
1406 return ::DefWindowProc(hWnd, message, wParam, lParam); 1421 // Find tab
1407 } 1422 CPluginClass *pClass = FindInstance(GetParent(hWnd));
1408 1423 if (!pClass)
1409 // Process message
1410 switch (message)
1411 {
1412
1413 case WM_SETCURSOR:
1414 { 1424 {
1415 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); 1425 return ::DefWindowProc(hWnd, message, wParam, lParam);
1416 return TRUE;
1417 } 1426 }
1418 case WM_PAINT: 1427
1428 // Process message
1429 switch (message)
1419 { 1430 {
1420 PAINTSTRUCT ps; 1431 case WM_SETCURSOR:
1421 HDC hDC = ::BeginPaint(hWnd, &ps); 1432 {
1422 1433 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
1423 AdblockPlus::Rectangle rcClient; 1434 return TRUE;
1424 ::GetClientRect(hWnd, &rcClient); 1435 }
1425 1436 case WM_PAINT:
1426 int nDrawEdge = 0; 1437 {
1427 1438 PAINTSTRUCT ps;
1428 // Old Windows background drawing 1439 HDC hDC = ::BeginPaint(hWnd, &ps);
1429 if (pClass->m_hTheme == NULL) 1440
1430 { 1441 AdblockPlus::Rectangle rcClient;
1431 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); 1442 ::GetClientRect(hWnd, &rcClient);
1432 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); 1443
1433 1444 int nDrawEdge = 0;
1434 nDrawEdge = 3; 1445
1435 rcClient.left += 3; 1446 // Old Windows background drawing
1436 1447 if (pClass->m_hTheme == NULL)
1437 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); 1448 {
1438 } 1449 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1));
1439 // Themed background drawing 1450 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT);
1440 else 1451
1441 { 1452 nDrawEdge = 3;
1442 // Draw background 1453 rcClient.left += 3;
1443 if (pfnDrawThemeBackground) 1454
1444 { 1455 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT);
1445 AdblockPlus::Rectangle rc = rcClient; 1456 }
1446 rc.right -= 2; 1457 // Themed background drawing
1447 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); 1458 else
1448 } 1459 {
1449 1460 // Draw background
1450 // Copy separator picture to left side 1461 if (pfnDrawThemeBackground)
1451 int nHeight = rcClient.Height();
1452 int nWidth = rcClient.Width() - 2;
1453
1454 for (int i = 0; i < 2; i++)
1455 {
1456 for (int j = 0; j < nHeight; j++)
1457 { 1462 {
1458 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); 1463 AdblockPlus::Rectangle rc = rcClient;
1459 1464 rc.right -= 2;
1460 // Ignore black boxes (if source is obscured by other windows) 1465 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1461 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) 1466 }
1467
1468 // Copy separator picture to left side
1469 int nHeight = rcClient.Height();
1470 int nWidth = rcClient.Width() - 2;
1471
1472 for (int i = 0; i < 2; i++)
1473 {
1474 for (int j = 0; j < nHeight; j++)
1462 { 1475 {
1463 ::SetPixel(hDC, i, j, clr); 1476 COLORREF clr = ::GetPixel(hDC, i + nWidth, j);
1477
1478 // Ignore black boxes (if source is obscured by other windows)
1479 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB Value(clr) > 8))
1480 {
1481 ::SetPixel(hDC, i, j, clr);
1482 }
1464 } 1483 }
1465 } 1484 }
1466 } 1485 }
1467 } 1486
1468 1487 // Draw icon
1469 // Draw icon 1488 if (CPluginClient::GetInstance())
1470 if (CPluginClient::GetInstance()) 1489 {
1471 { 1490 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1472 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); 1491
1473 1492 int offx = nDrawEdge;
1474 int offx = nDrawEdge; 1493 if (hIcon)
1475 if (hIcon) 1494 {
1476 { 1495 //Get the RECT for the leftmost pane (the status text pane)
1477 //Get the RECT for the leftmost pane (the status text pane) 1496 RECT rect;
1497 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&rect);
1498 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico nWidth, iconHeight, NULL, NULL, DI_NORMAL);
1499 offx += iconWidth;
1500 }
1501 #ifdef _DEBUG
1502 // Display version
1503 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT , 0, 0);
1504 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont);
1505
1506 AdblockPlus::Rectangle rcText = rcClient;
1507 rcText.left += offx;
1508 ::SetBkMode(hDC, TRANSPARENT);
1509 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_ LEFT | DT_SINGLELINE | DT_VCENTER);
1510
1511 ::SelectObject(hDC, hOldFont);
1512 #endif // _DEBUG
1513 }
1514
1515 // Done!
1516 EndPaint(hWnd, &ps);
1517
1518 return 0;
1519 }
1520
1521 case WM_LBUTTONUP:
1522 case WM_RBUTTONUP:
1523 {
1524 std::wstring url = pClass->GetBrowserUrl();
1525 if (url != pClass->GetTab()->GetDocumentUrl())
1526 {
1527 pClass->GetTab()->SetDocumentUrl(url);
1528 }
1529
1530 // Create menu
1531 HMENU hMenu = pClass->CreatePluginMenu(url);
1532 if (!hMenu)
1533 {
1534 return 0;
1535 }
1536
1537 // Display menu
1538 POINT pt;
1539 ::GetCursorPos(&pt);
1540
1541 RECT rc;
1542 ::GetWindowRect(hWnd, &rc);
1543
1544 if (rc.left >= 0 && rc.top >= 0)
1545 {
1546 pt.x = rc.left;
1547 pt.y = rc.top;
1548 }
1549
1550 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN );
1551 break;
1552 }
1553 case WM_DESTROY:
1554 break;
1555 case SC_CLOSE:
1556 break;
1557
1558 case WM_UPDATEUISTATE:
1559 {
1560 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1561 if (tab)
1562 {
1563 tab->OnActivate();
1478 RECT rect; 1564 RECT rect;
1479 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, ( LPARAM)&rect); 1565 GetWindowRect(pClass->m_hPaneWnd, &rect);
1480 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW idth, iconHeight, NULL, NULL, DI_NORMAL); 1566 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
1481 offx += iconWidth; 1567 }
1482 } 1568 if (LOWORD(wParam) == UIS_CLEAR)
1483 #ifdef _DEBUG 1569 {
1484 // Display version 1570 pClass->notificationMessage.Hide();
1485 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1571 }
1486 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); 1572 break;
1487 1573 }
1488 AdblockPlus::Rectangle rcText = rcClient; 1574 case WM_WINDOWPOSCHANGING:
1489 rcText.left += offx; 1575 {
1490 ::SetBkMode(hDC, TRANSPARENT);
1491 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER);
1492
1493 ::SelectObject(hDC, hOldFont);
1494 #endif // _DEBUG
1495 }
1496
1497 // Done!
1498 EndPaint(hWnd, &ps);
1499
1500 return 0;
1501 }
1502
1503 case WM_LBUTTONUP:
1504 case WM_RBUTTONUP:
1505 {
1506 std::wstring url = pClass->GetBrowserUrl();
1507 if (url != pClass->GetTab()->GetDocumentUrl())
1508 {
1509 pClass->GetTab()->SetDocumentUrl(url);
1510 }
1511
1512 // Create menu
1513 HMENU hMenu = pClass->CreatePluginMenu(url);
1514 if (!hMenu)
1515 {
1516 return 0;
1517 }
1518
1519 // Display menu
1520 POINT pt;
1521 ::GetCursorPos(&pt);
1522
1523 RECT rc;
1524 ::GetWindowRect(hWnd, &rc);
1525
1526 if (rc.left >= 0 && rc.top >= 0)
1527 {
1528 pt.x = rc.left;
1529 pt.y = rc.top;
1530 }
1531
1532 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN);
1533 }
1534 break;
1535 case WM_DESTROY:
1536 break;
1537 case SC_CLOSE:
1538 break;
1539
1540 case WM_UPDATEUISTATE:
1541 {
1542 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1543 if (tab)
1544 {
1545 tab->OnActivate();
1546 RECT rect; 1576 RECT rect;
1547 GetWindowRect(pClass->m_hPaneWnd, &rect); 1577 GetWindowRect(pClass->m_hPaneWnd, &rect);
1548 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); 1578 if (pClass->notificationMessage.IsVisible())
1549 } 1579 {
1550 if (LOWORD(wParam) == UIS_CLEAR) 1580 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
1551 { 1581 }
1552 pClass->notificationMessage.Hide(); 1582 break;
1583 }
1584 case WM_WINDOWPOSCHANGED:
1585 {
1586 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam);
1587 if (wndPos->flags & SWP_HIDEWINDOW)
1588 {
1589 pClass->notificationMessage.Hide();
1590 }
1591 break;
1592 }
1593 case WM_ALREADY_UP_TO_DATE:
1594 {
1595 Dictionary* dictionary = Dictionary::GetInstance();
1596 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread y-up-to-date-text");
1597 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea dy-up-to-date-title");
1598 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TTI_INFO);
1599 break;
1600 }
1601 case WM_UPDATE_CHECK_ERROR:
1602 {
1603 Dictionary* dictionary = Dictionary::GetInstance();
1604 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex t");
1605 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti tle");
1606 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERR OR);
1607 break;
1608 }
1609 case WM_DOWNLOADING_UPDATE:
1610 {
1611 Dictionary* dictionary = Dictionary::GetInstance();
1612 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin g-update-text");
1613 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi ng-update-title");
1614 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT itle, TTI_INFO);
1615 break;
1553 } 1616 }
1554 } 1617 }
1555 break;
1556 case WM_WINDOWPOSCHANGING:
1557 {
1558 RECT rect;
1559 GetWindowRect(pClass->m_hPaneWnd, &rect);
1560 if (pClass->notificationMessage.IsVisible())
1561 {
1562 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
1563 }
1564 }
1565 break;
1566 case WM_WINDOWPOSCHANGED:
1567 {
1568 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam);
1569 if (wndPos->flags & SWP_HIDEWINDOW)
1570 {
1571 pClass->notificationMessage.Hide();
1572 }
1573 }
1574 break;
1575 case WM_ALREADY_UP_TO_DATE:
1576 {
1577 Dictionary* dictionary = Dictionary::GetInstance();
1578 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text");
1579 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title");
1580 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT I_INFO);
1581 }
1582 break;
1583 case WM_UPDATE_CHECK_ERROR:
1584 {
1585 Dictionary* dictionary = Dictionary::GetInstance();
1586 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" );
1587 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e");
1588 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR );
1589 }
1590 break;
1591 case WM_DOWNLOADING_UPDATE:
1592 {
1593 Dictionary* dictionary = Dictionary::GetInstance();
1594 std::wstring downloadingText = dictionary->Lookup("updater", "downloading- update-text");
1595 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading -update-title");
1596 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit le, TTI_INFO);
1597 }
1598 break;
1599 } 1618 }
1600 1619 catch (...)
1601 return DefWindowProc(hWnd, message, wParam, lParam); 1620 {
1621 // Suppress exception. Fall through to default handler.
1622 }
1623 return ::DefWindowProc(hWnd, message, wParam, lParam);
1602 } 1624 }
1603 1625
1604 1626
1605 void CPluginClass::UpdateStatusBar() 1627 void CPluginClass::UpdateStatusBar()
1606 { 1628 {
1607 DEBUG_GENERAL("*** Updating statusbar") 1629 DEBUG_GENERAL("*** Updating statusbar")
1608 if (m_hPaneWnd == NULL) 1630 if (m_hPaneWnd == NULL)
1609 { 1631 {
1610 CreateStatusBarPane(); 1632 CreateStatusBarPane();
1611 } 1633 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 s_criticalSectionLocal.Unlock(); 1682 s_criticalSectionLocal.Unlock();
1661 1683
1662 return icon; 1684 return icon;
1663 } 1685 }
1664 1686
1665 ATOM CPluginClass::GetAtomPaneClass() 1687 ATOM CPluginClass::GetAtomPaneClass()
1666 { 1688 {
1667 return s_atomPaneClass; 1689 return s_atomPaneClass;
1668 } 1690 }
1669 1691
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld