Left: | ||
Right: |
OLD | NEW |
---|---|
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 #include "PluginFilter.h" | 6 #include "PluginFilter.h" |
7 #include "PluginMimeFilterClient.h" | 7 #include "PluginMimeFilterClient.h" |
8 #include "PluginClient.h" | 8 #include "PluginClient.h" |
9 #include "PluginClientFactory.h" | 9 #include "PluginClientFactory.h" |
10 #include "PluginMutex.h" | 10 #include "PluginMutex.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 | 195 |
196 s_criticalSectionLocal.Lock(); | 196 s_criticalSectionLocal.Lock(); |
197 { | 197 { |
198 browser = s_asyncWebBrowser2; | 198 browser = s_asyncWebBrowser2; |
199 } | 199 } |
200 s_criticalSectionLocal.Unlock(); | 200 s_criticalSectionLocal.Unlock(); |
201 | 201 |
202 return browser; | 202 return browser; |
203 } | 203 } |
204 | 204 |
205 CString CPluginClass::GetBrowserUrl() const | 205 std::wstring CPluginClass::GetBrowserUrl() const |
206 { | 206 { |
207 CString url; | 207 std::wstring url; |
208 | |
209 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 208 CComQIPtr<IWebBrowser2> browser = GetBrowser(); |
210 if (browser) | 209 if (browser) |
211 { | 210 { |
212 CComBSTR bstrURL; | 211 BSTR bstrURL; |
sergei
2014/10/17 10:10:12
Why is ATL::CComBSTR replaced by BSTR? Looks like
Eric
2014/10/20 02:36:01
Because we don't need CComBSTR here. The only reas
sergei
2014/10/21 09:45:17
Sorry, I don't understand about which mystery your
Eric
2014/10/21 17:19:52
That's because there is no mystery.
I take it, th
Oleksandr
2015/01/05 11:55:40
Let's move back to this specific code change. As I
Eric
2015/01/05 16:18:26
Done.
| |
213 | 212 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) |
214 if (SUCCEEDED(browser->get_LocationURL(&bstrURL))) | |
215 { | 213 { |
216 url = bstrURL; | 214 url = std::wstring(bstrURL, SysStringLen(bstrURL)); |
217 CPluginClient::UnescapeUrl(url); | 215 SysFreeString(bstrURL); |
216 UnescapeUrl(url); | |
218 } | 217 } |
219 } | 218 } |
220 else | 219 else |
221 { | 220 { |
222 url = m_tab->GetDocumentUrl(); | 221 url = m_tab->GetDocumentUrl(); |
223 } | 222 } |
224 | |
225 return url; | 223 return url; |
226 } | 224 } |
227 | 225 |
228 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 226 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
229 { | 227 { |
230 if (thisPtr == NULL) | 228 if (thisPtr == NULL) |
231 return 0; | 229 return 0; |
232 if (!((CPluginClass*)thisPtr)->InitObject(true)) | 230 if (!((CPluginClass*)thisPtr)->InitObject(true)) |
233 { | 231 { |
234 ((CPluginClass*)thisPtr)->Unadvice(); | 232 ((CPluginClass*)thisPtr)->Unadvice(); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 { | 540 { |
543 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; | 541 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; |
544 } | 542 } |
545 else | 543 else |
546 { | 544 { |
547 // Wrong type, return. | 545 // Wrong type, return. |
548 return; | 546 return; |
549 } | 547 } |
550 | 548 |
551 // Get the URL | 549 // Get the URL |
552 CString url; | 550 std::wstring url; |
553 vt = pDispParams->rgvarg[5].vt; | 551 auto arg = pDispParams->rgvarg[5]; |
sergei
2014/10/17 10:10:12
I would prefer `const auto&` here.
Eric
2014/10/20 02:36:01
OK.
| |
554 if (vt == VT_BYREF + VT_VARIANT) | 552 vt = arg.vt; |
553 if (vt == VT_BYREF + VT_VARIANT && arg.pvarVal->vt == VT_BSTR) | |
sergei
2014/10/17 10:10:12
'+' here looks unusual, despite it works, I think
Eric
2014/10/20 02:36:01
It's out of scope, but it's also trivial.
Done.
| |
555 { | 554 { |
556 url = pDispParams->rgvarg[5].pvarVal->bstrVal; | 555 BSTR b = arg.pvarVal->bstrVal; |
557 | 556 if (b) { |
558 CPluginClient::UnescapeUrl(url); | 557 url = std::wstring(b, SysStringLen(b)); |
558 SysFreeString(b); | |
sergei
2014/10/17 10:10:12
It's not allowed to modify arguments, especially b
Eric
2014/10/20 02:36:01
Brain fart. Forgot that this was deriving from IDi
| |
559 UnescapeUrl(url); | |
560 } | |
559 } | 561 } |
560 else | 562 else |
561 { | 563 { |
562 // Wrong type, return. | 564 // Wrong type, return. |
563 return; | 565 return; |
564 } | 566 } |
565 | 567 |
566 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page | 568 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page |
567 CPluginClient* client = CPluginClient::GetInstance(); | 569 CPluginClient* client = CPluginClient::GetInstance(); |
568 | 570 CString urlLegacy = ToCString(url); |
569 if (url.Find(L"javascript") == 0) | 571 if (urlLegacy.Find(L"javascript") == 0) |
570 { | 572 { |
571 } | 573 } |
572 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) | 574 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) |
573 { | 575 { |
574 m_tab->OnNavigate(url); | 576 m_tab->OnNavigate(url); |
575 | 577 |
576 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + url + "\n=================== =============================================================") | 578 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + urlLegacy + "\n============= ===================================================================") |
577 | 579 |
578 #ifdef ENABLE_DEBUG_RESULT | 580 #ifdef ENABLE_DEBUG_RESULT |
579 CPluginDebug::DebugResultDomain(url); | 581 CPluginDebug::DebugResultDomain(urlLegacy); |
580 #endif | 582 #endif |
581 | 583 |
582 UpdateStatusBar(); | 584 UpdateStatusBar(); |
583 } | 585 } |
584 else | 586 else |
585 { | 587 { |
586 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) | 588 DEBUG_NAVI(L"Navi::Begin navigation url:" + urlLegacy) |
587 m_tab->CacheFrame(url); | 589 m_tab->CacheFrame(url); |
588 } | 590 } |
589 } | 591 } |
592 | |
590 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) | 593 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) |
591 { | 594 { |
592 DEBUG_GENERAL("Tab changed"); | 595 DEBUG_GENERAL("Tab changed"); |
593 bool newtabshown = pDispParams->rgvarg[1].intVal==3; | 596 bool newtabshown = pDispParams->rgvarg[1].intVal==3; |
594 if (newtabshown) | 597 if (newtabshown) |
595 { | 598 { |
596 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); | 599 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); |
597 if (it == s_threadInstances.end()) | 600 if (it == s_threadInstances.end()) |
598 { | 601 { |
599 s_threadInstances[::GetCurrentThreadId()] = this; | 602 s_threadInstances[::GetCurrentThreadId()] = this; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 { | 715 { |
713 DEBUG_NAVI("Navi::Document Complete") | 716 DEBUG_NAVI("Navi::Document Complete") |
714 | 717 |
715 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 718 CComQIPtr<IWebBrowser2> browser = GetBrowser(); |
716 | 719 |
717 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH) | 720 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH) |
718 { | 721 { |
719 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; | 722 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; |
720 if (pBrowser) | 723 if (pBrowser) |
721 { | 724 { |
722 CString url; | 725 BSTR bstrUrl; |
sergei
2014/10/17 10:10:12
Again CComBSTR is replaced by BSTR.
Eric
2014/10/20 02:36:01
And for the same reasons I stated above.
| |
723 CComBSTR bstrUrl; | |
724 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0) | 726 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0) |
725 { | 727 { |
726 url = bstrUrl; | 728 std::wstring url(bstrUrl, SysStringLen(bstrUrl)); |
727 | 729 SysFreeString(bstrUrl); |
728 CPluginClient::UnescapeUrl(url); | 730 UnescapeUrl(url); |
729 | |
730 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er)); | 731 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er)); |
731 } | 732 } |
732 } | 733 } |
733 } | 734 } |
734 } | 735 } |
735 break; | 736 break; |
736 | 737 |
737 case DISPID_ONQUIT: | 738 case DISPID_ONQUIT: |
738 case DISPID_QUIT: | 739 case DISPID_QUIT: |
739 { | 740 { |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1133 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) | 1134 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) |
1134 { | 1135 { |
1135 if (cCmds == 0) return E_INVALIDARG; | 1136 if (cCmds == 0) return E_INVALIDARG; |
1136 if (prgCmds == 0) return E_POINTER; | 1137 if (prgCmds == 0) return E_POINTER; |
1137 | 1138 |
1138 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1139 prgCmds[0].cmdf = OLECMDF_ENABLED; |
1139 | 1140 |
1140 return S_OK; | 1141 return S_OK; |
1141 } | 1142 } |
1142 | 1143 |
1143 HMENU CPluginClass::CreatePluginMenu(const CString& url) | 1144 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) |
1144 { | 1145 { |
1145 DEBUG_GENERAL("CreatePluginMenu"); | 1146 DEBUG_GENERAL("CreatePluginMenu"); |
1146 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1147 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
1147 | 1148 |
1148 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1149 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
1149 | 1150 |
1150 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); | 1151 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); |
1151 | 1152 |
1152 SetMenuBar(hMenuTrackPopup, url); | 1153 SetMenuBar(hMenuTrackPopup, url); |
1153 | 1154 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1350 { | 1351 { |
1351 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") | 1352 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") |
1352 } | 1353 } |
1353 } | 1354 } |
1354 } | 1355 } |
1355 break; | 1356 break; |
1356 } | 1357 } |
1357 case ID_MENU_DISABLE_ON_SITE: | 1358 case ID_MENU_DISABLE_ON_SITE: |
1358 { | 1359 { |
1359 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1360 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1360 CString urlString = GetTab()->GetDocumentUrl(); | 1361 std::wstring urlString = GetTab()->GetDocumentUrl(); |
1361 if (client->IsWhitelistedUrl(to_wstring(urlString))) | 1362 if (client->IsWhitelistedUrl(urlString)) |
1362 { | 1363 { |
1363 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w string(urlString)))); | 1364 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(urlS tring))); |
1364 } | 1365 } |
1365 else | 1366 else |
1366 { | 1367 { |
1367 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr ing(urlString)))); | 1368 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(urlStri ng))); |
1368 } | 1369 } |
1369 GetBrowser()->Refresh(); | 1370 GetBrowser()->Refresh(); |
1370 } | 1371 } |
1371 default: | 1372 default: |
1372 break; | 1373 break; |
1373 } | 1374 } |
1374 | 1375 |
1375 // Invalidate and redraw the control | 1376 // Invalidate and redraw the control |
1376 UpdateStatusBar(); | 1377 UpdateStatusBar(); |
1377 } | 1378 } |
1378 | 1379 |
1379 | 1380 |
1380 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) | 1381 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url) |
1381 { | 1382 { |
1382 DEBUG_GENERAL("SetMenuBar"); | 1383 DEBUG_GENERAL("SetMenuBar"); |
1383 | 1384 |
1384 std::wstring ctext; | 1385 std::wstring ctext; |
1385 | 1386 |
1386 s_criticalSectionLocal.Lock(); | 1387 s_criticalSectionLocal.Lock(); |
1387 { | 1388 { |
1388 s_menuDomains.clear(); | 1389 s_menuDomains.clear(); |
1389 } | 1390 } |
1390 s_criticalSectionLocal.Unlock(); | 1391 s_criticalSectionLocal.Unlock(); |
1391 | 1392 |
1392 Dictionary* dictionary = Dictionary::GetInstance(); | 1393 Dictionary* dictionary = Dictionary::GetInstance(); |
1393 | 1394 |
1394 MENUITEMINFOW fmii; | 1395 MENUITEMINFOW fmii; |
1395 memset(&fmii, 0, sizeof(MENUITEMINFO)); | 1396 memset(&fmii, 0, sizeof(MENUITEMINFO)); |
1396 fmii.cbSize = sizeof(MENUITEMINFO); | 1397 fmii.cbSize = sizeof(MENUITEMINFO); |
1397 | 1398 |
1398 MENUITEMINFOW miiSep; | 1399 MENUITEMINFOW miiSep; |
1399 memset(&miiSep, 0, sizeof(MENUITEMINFO)); | 1400 memset(&miiSep, 0, sizeof(MENUITEMINFO)); |
1400 miiSep.cbSize = sizeof(MENUITEMINFO); | 1401 miiSep.cbSize = sizeof(MENUITEMINFO); |
1401 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 1402 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |
1402 miiSep.fType = MFT_SEPARATOR; | 1403 miiSep.fType = MFT_SEPARATOR; |
1403 | 1404 |
1404 CPluginClient* client = CPluginClient::GetInstance(); | 1405 CPluginClient* client = CPluginClient::GetInstance(); |
1405 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1406 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1406 { | 1407 { |
1407 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 1408 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |
1408 // Is domain in white list? | 1409 // Is domain in white list? |
1409 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); | 1410 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); |
1410 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) | 1411 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) |
1411 { | 1412 { |
1412 fmii.fState = MFS_CHECKED | MFS_ENABLED; | 1413 fmii.fState = MFS_CHECKED | MFS_ENABLED; |
1413 } | 1414 } |
1414 else | 1415 else |
1415 { | 1416 { |
1416 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 1417 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |
1417 } | 1418 } |
1418 fmii.fMask = MIIM_STRING | MIIM_STATE; | 1419 fmii.fMask = MIIM_STRING | MIIM_STATE; |
1419 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1420 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1420 fmii.cch = static_cast<UINT>(ctext.size()); | 1421 fmii.cch = static_cast<UINT>(ctext.size()); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1615 } | 1616 } |
1616 | 1617 |
1617 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); | 1618 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); |
1618 | 1619 |
1619 | 1620 |
1620 return result; | 1621 return result; |
1621 | 1622 |
1622 } | 1623 } |
1623 | 1624 |
1624 | 1625 |
1625 HICON CPluginClass::GetStatusBarIcon(const CString& url) | 1626 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1626 { | 1627 { |
1627 // use the disable icon as defualt, if the client doesn't exists | 1628 // use the disable icon as defualt, if the client doesn't exists |
1628 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1629 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1629 | 1630 |
1630 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1631 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
1631 if (tab) | 1632 if (tab) |
1632 { | 1633 { |
1633 CPluginClient* client = CPluginClient::GetInstance(); | 1634 CPluginClient* client = CPluginClient::GetInstance(); |
1634 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) | 1635 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) |
1635 { | 1636 { |
1636 } | 1637 } |
1637 else if (client->IsWhitelistedUrl(to_wstring(url))) | 1638 else if (client->IsWhitelistedUrl(url)) |
1638 { | 1639 { |
1639 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1640 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1640 } | 1641 } |
1641 else | 1642 else |
1642 { | 1643 { |
1643 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1644 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1644 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 1645 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1645 } | 1646 } |
1646 } | 1647 } |
1647 return hIcon; | 1648 return hIcon; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1744 | 1745 |
1745 // Done! | 1746 // Done! |
1746 EndPaint(hWnd, &ps); | 1747 EndPaint(hWnd, &ps); |
1747 | 1748 |
1748 return 0; | 1749 return 0; |
1749 } | 1750 } |
1750 | 1751 |
1751 case WM_LBUTTONUP: | 1752 case WM_LBUTTONUP: |
1752 case WM_RBUTTONUP: | 1753 case WM_RBUTTONUP: |
1753 { | 1754 { |
1754 CString strURL = pClass->GetBrowserUrl(); | 1755 std::wstring url = pClass->GetBrowserUrl(); |
1755 if (strURL != pClass->GetTab()->GetDocumentUrl()) | 1756 if (url != pClass->GetTab()->GetDocumentUrl()) |
1756 { | 1757 { |
1757 pClass->GetTab()->SetDocumentUrl(strURL); | 1758 pClass->GetTab()->SetDocumentUrl(url); |
1758 } | 1759 } |
1759 | 1760 |
1760 // Create menu | 1761 // Create menu |
1761 HMENU hMenu = pClass->CreatePluginMenu(strURL); | 1762 HMENU hMenu = pClass->CreatePluginMenu(url); |
1762 if (!hMenu) | 1763 if (!hMenu) |
1763 { | 1764 { |
1764 return 0; | 1765 return 0; |
1765 } | 1766 } |
1766 | 1767 |
1767 // Display menu | 1768 // Display menu |
1768 POINT pt; | 1769 POINT pt; |
1769 ::GetCursorPos(&pt); | 1770 ::GetCursorPos(&pt); |
1770 | 1771 |
1771 RECT rc; | 1772 RECT rc; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1975 } | 1976 } |
1976 } | 1977 } |
1977 } | 1978 } |
1978 | 1979 |
1979 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 1980 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |
1980 } | 1981 } |
1981 | 1982 |
1982 return hTabWnd; | 1983 return hTabWnd; |
1983 | 1984 |
1984 } | 1985 } |
OLD | NEW |