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

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

Issue 11292028: Status bar menu added (Closed)
Patch Set: Addressing comments. Actual functionality fixes Created Aug. 1, 2013, 10:28 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
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginClass.h" 3 #include "PluginClass.h"
4 #include "PluginSettings.h" 4 #include "PluginSettings.h"
5 #include "PluginSystem.h" 5 #include "PluginSystem.h"
6 #ifdef SUPPORT_FILTER 6 #ifdef SUPPORT_FILTER
7 #include "PluginFilter.h" 7 #include "PluginFilter.h"
8 #endif 8 #endif
9 #include "PluginMimeFilterClient.h" 9 #include "PluginMimeFilterClient.h"
10 #include "PluginClient.h" 10 #include "PluginClient.h"
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 1222
1223 return fRet; 1223 return fRet;
1224 } 1224 }
1225 1225
1226 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U INT nMenuFlags) 1226 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U INT nMenuFlags)
1227 { 1227 {
1228 CPluginClient* client = CPluginClient::GetInstance(); 1228 CPluginClient* client = CPluginClient::GetInstance();
1229 1229
1230 CPluginSystem* system = CPluginSystem::GetInstance(); 1230 CPluginSystem* system = CPluginSystem::GetInstance();
1231 1231
1232 CString url;
1233 int navigationErrorId = 0;
1234
1235 // Create menu parent window 1232 // Create menu parent window
1236 HWND hMenuWnd = ::CreateWindowEx( 1233 HWND hMenuWnd = ::CreateWindowEx(
1237 NULL, 1234 NULL,
1238 MAKEINTATOM(GetAtomPaneClass()), 1235 MAKEINTATOM(GetAtomPaneClass()),
1239 _T(""), 1236 _T(""),
1240 0, 1237 0,
1241 0,0,0,0, 1238 0,0,0,0,
1242 NULL, 1239 NULL,
1243 NULL, 1240 NULL,
1244 _Module.m_hInst, 1241 _Module.m_hInst,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 else 1273 else
1277 { 1274 {
1278 s_mimeFilter = NULL; 1275 s_mimeFilter = NULL;
1279 1276
1280 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 1277 CPluginClientFactory::ReleaseMimeFilterClientInstance();
1281 } 1278 }
1282 } 1279 }
1283 s_criticalSectionLocal.Unlock(); 1280 s_criticalSectionLocal.Unlock();
1284 } 1281 }
1285 break; 1282 break;
1283 case ID_SETTINGS:
1284 {
1285 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1286 if (browser)
1287 {
1288 VARIANT vFlags;
1289 vFlags.vt = VT_I4;
1290 vFlags.intVal = navOpenInNewTab;
1291
1292 HRESULT hr = browser->Navigate(BString(UserSettingsFileUrl()), &vFlags, NULL, NULL, NULL);
Felix Dahlke 2013/08/02 13:52:58 While we're at it, I think we should store BString
1293 if (FAILED(hr))
1294 {
1295 vFlags.intVal = navOpenInNewWindow;
1296
1297 hr = browser->Navigate(BString(UserSettingsFileUrl()), &vFlags, NULL, NULL, NULL);
1298 if (FAILED(hr))
1299 {
1300 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1301 }
1302 }
1303 }
1304 break;
1305 }
1306 case ID_WHITELISTDOMAIN:
1307 {
1308 CPluginSettings* settings = CPluginSettings::GetInstance();
1309 CString urlString = GetTab()->GetDocumentUrl();
1310 if (client->IsWhitelistedUrl(std::wstring(urlString)))
1311 {
1312 settings->RemoveWhiteListedDomain(ExtractDomain(urlString));
1313
Felix Dahlke 2013/08/02 13:52:58 Superfluous whitespace.
1314 }
1315 else
1316 {
1317 settings->AddWhiteListedDomain(ExtractDomain(urlString));
1318 }
1319 GetBrowser()->Refresh();
1320 }
1286 default: 1321 default:
1287 break; 1322 break;
1288 } 1323 }
1289 1324
1290 // Invalidate and redraw the control 1325 // Invalidate and redraw the control
1291 UpdateStatusBar(); 1326 UpdateStatusBar();
1292
1293 CComQIPtr<IWebBrowser2> browser = GetBrowser();
1294 if (!url.IsEmpty() && browser)
1295 {
1296 VARIANT vFlags;
1297 vFlags.vt = VT_I4;
1298 vFlags.intVal = navOpenInNewTab;
1299
1300 HRESULT hr = browser->Navigate(CComBSTR(url), &vFlags, NULL, NULL, NULL);
1301 if (FAILED(hr))
1302 {
1303 vFlags.intVal = navOpenInNewWindow;
1304
1305 hr = browser->Navigate(CComBSTR(url), &vFlags, NULL, NULL, NULL);
1306 if (FAILED(hr))
1307 {
1308 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, navigationErrorId, "Navigat ion::Failed")
1309 }
1310 }
1311 }
1312 } 1327 }
1313 1328
1314 1329
1315 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) 1330 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url)
1316 { 1331 {
1317 std::wstring ctext; 1332 std::wstring ctext;
1318 1333
1319 s_criticalSectionLocal.Lock(); 1334 s_criticalSectionLocal.Lock();
1320 { 1335 {
1321 #ifdef SUPPORT_WHITELIST 1336 #ifdef SUPPORT_WHITELIST
(...skipping 19 matching lines...) Expand all
1341 miiSep.cbSize = sizeof(MENUITEMINFO); 1356 miiSep.cbSize = sizeof(MENUITEMINFO);
1342 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1357 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1343 miiSep.fType = MFT_SEPARATOR; 1358 miiSep.fType = MFT_SEPARATOR;
1344 1359
1345 CPluginClient* client = CPluginClient::GetInstance(); 1360 CPluginClient* client = CPluginClient::GetInstance();
1346 1361
1347 CPluginSettings* settings = CPluginSettings::GetInstance(); 1362 CPluginSettings* settings = CPluginSettings::GetInstance();
1348 1363
1349 #ifdef SUPPORT_WHITELIST 1364 #ifdef SUPPORT_WHITELIST
1350 { 1365 {
1351 // White list domain 1366 ctext = dictionary->Lookup("menu", "disable-on-site");
Felix Dahlke 2013/08/02 13:52:58 Looks like the indentation is off here.
1352 ctext = dictionary->Lookup("menu", "disable-on-site"); 1367 // Is domain in white list?
1368 ReplaceString(ctext, L"?1?", ExtractDomain(url).GetString());
1369 if (client->IsWhitelistedUrl(std::wstring(GetTab()->GetDocumentUrl())))
1370 {
1371 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1372 }
1373 else
1374 {
1375 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1376 }
1353 fmii.fMask = MIIM_STRING | MIIM_STATE; 1377 fmii.fMask = MIIM_STRING | MIIM_STATE;
1354 fmii.fState = MFS_DISABLED;
1355 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1378 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1356 fmii.cch = ctext.size(); 1379 fmii.cch = ctext.size();
1357 1380
1358 UINT index = WM_WHITELIST_DOMAIN;
1359
1360 ::SetMenuItemInfoW(hMenu, ID_WHITELISTDOMAIN, FALSE, &fmii); 1381 ::SetMenuItemInfoW(hMenu, ID_WHITELISTDOMAIN, FALSE, &fmii);
1361 } 1382 }
1362 #else 1383 #else
1363 { 1384 {
1364 ::DeleteMenu(hMenu, ID_WHITELISTDOMAIN, FALSE); 1385 ::DeleteMenu(hMenu, ID_WHITELISTDOMAIN, FALSE);
1365 } 1386 }
1366 #endif // SUPPORT_WHITELIST 1387 #endif // SUPPORT_WHITELIST
1367 1388
1368 // Plugin enable 1389 // Plugin enable
1390 ctext = dictionary->Lookup("menu", "disable");
1369 if (settings->GetPluginEnabled()) 1391 if (settings->GetPluginEnabled())
1370 { 1392 {
1371 ctext = dictionary->Lookup("menu", "disable"); 1393 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1372 } 1394 }
1373 else 1395 else
1374 { 1396 {
1375 ctext = dictionary->Lookup("menu", "enable"); 1397 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1376 } 1398 }
1377 fmii.fMask = MIIM_STATE | MIIM_STRING; 1399 fmii.fMask = MIIM_STATE | MIIM_STRING;
1378 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED;
1379 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1400 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1380 fmii.cch = ctext.size(); 1401 fmii.cch = ctext.size();
1381 ::SetMenuItemInfoW(hMenu, ID_PLUGIN_ENABLE, FALSE, &fmii); 1402 ::SetMenuItemInfoW(hMenu, ID_PLUGIN_ENABLE, FALSE, &fmii);
1382 1403
1383 // Settings 1404 // Settings
1384 ctext = dictionary->Lookup("menu", "settings"); 1405 ctext = dictionary->Lookup("menu", "settings");
1385 fmii.fMask = MIIM_STATE | MIIM_STRING; 1406 fmii.fMask = MIIM_STATE | MIIM_STRING;
1386 fmii.fState = MFS_ENABLED; 1407 fmii.fState = MFS_ENABLED;
1387 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1408 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1388 fmii.cch = ctext.size(); 1409 fmii.cch = ctext.size();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 { 1592 {
1572 } 1593 }
1573 #ifdef SUPPORT_WHITELIST 1594 #ifdef SUPPORT_WHITELIST
1574 else if (client->IsWhitelistedUrl(std::wstring(url))) 1595 else if (client->IsWhitelistedUrl(std::wstring(url)))
1575 { 1596 {
1576 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1597 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1577 } 1598 }
1578 #endif // SUPPORT_WHITELIST 1599 #endif // SUPPORT_WHITELIST
1579 else 1600 else
1580 { 1601 {
1581 //Deativate adblock icon if adblock limit reached
1582 CPluginSettings* settings = CPluginSettings::GetInstance(); 1602 CPluginSettings* settings = CPluginSettings::GetInstance();
1583 if (!settings->GetPluginEnabled()) {
1584 hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1585 return hIcon;
1586 }
1587 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1603 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1588 } 1604 }
1589 1605
1590 #endif // PRODUCT_ADBLOCKPLUS 1606 #endif // PRODUCT_ADBLOCKPLUS
1591 } 1607 }
1592 1608
1593 return hIcon; 1609 return hIcon;
1594 } 1610 }
1595 1611
1596 1612
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 1714
1699 case WM_LBUTTONUP: 1715 case WM_LBUTTONUP:
1700 case WM_RBUTTONUP: 1716 case WM_RBUTTONUP:
1701 { 1717 {
1702 CString strURL = pClass->GetBrowserUrl(); 1718 CString strURL = pClass->GetBrowserUrl();
1703 if (strURL != pClass->GetTab()->GetDocumentUrl()) 1719 if (strURL != pClass->GetTab()->GetDocumentUrl())
1704 { 1720 {
1705 pClass->GetTab()->SetDocumentUrl(strURL); 1721 pClass->GetTab()->SetDocumentUrl(strURL);
1706 } 1722 }
1707 1723
1708 #ifdef SUPPORT_SHOW_PLUGIN_MENU
1709 // Create menu 1724 // Create menu
1710 HMENU hMenu = pClass->CreatePluginMenu(strURL); 1725 HMENU hMenu = pClass->CreatePluginMenu(strURL);
1711 if (!hMenu) 1726 if (!hMenu)
1712 { 1727 {
1713 return 0; 1728 return 0;
1714 } 1729 }
1715 1730
1716 // Display menu 1731 // Display menu
1717 POINT pt; 1732 POINT pt;
1718 ::GetCursorPos(&pt); 1733 ::GetCursorPos(&pt);
1719 1734
1720 RECT rc; 1735 RECT rc;
1721 ::GetWindowRect(hWnd, &rc); 1736 ::GetWindowRect(hWnd, &rc);
1722 1737
1723 if (rc.left >= 0 && rc.top >= 0) 1738 if (rc.left >= 0 && rc.top >= 0)
1724 { 1739 {
1725 pt.x = rc.left; 1740 pt.x = rc.left;
1726 pt.y = rc.top; 1741 pt.y = rc.top;
1727 } 1742 }
1728 1743
1729 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN); 1744 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN);
1730 #else
1731 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1732 if (browser)
1733 {
1734 VARIANT vFlags;
1735 vFlags.vt = VT_I4;
1736 vFlags.intVal = navOpenInNewTab;
1737
1738 HRESULT hr = browser->Navigate(BString(UserSettingsFileUrl()), &vFlags, NULL, NULL, NULL);
1739 if (FAILED(hr))
1740 {
1741 vFlags.intVal = navOpenInNewWindow;
1742
1743 hr = browser->Navigate(BString(UserSettingsFileUrl()), &vFlags, NULL, NULL, NULL);
1744 if (FAILED(hr))
1745 {
1746 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1747 }
1748 }
1749 }
1750 #endif
1751 } 1745 }
1752 break; 1746 break;
1753 case WM_DESTROY: 1747 case WM_DESTROY:
1754 break; 1748 break;
1755 case SC_CLOSE: 1749 case SC_CLOSE:
1756 break; 1750 break;
1757 1751
1758 case WM_UPDATEUISTATE: 1752 case WM_UPDATEUISTATE:
1759 { 1753 {
1760 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1754 CPluginTab* tab = GetTab(::GetCurrentThreadId());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 } 1894 }
1901 } 1895 }
1902 } 1896 }
1903 1897
1904 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1898 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1905 } 1899 }
1906 1900
1907 return hTabWnd; 1901 return hTabWnd;
1908 1902
1909 } 1903 }
OLDNEW

Powered by Google App Engine
This is Rietveld