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

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

Issue 4912420225024000: Issue #1234 - Convert strings associated with URL's (Closed)
Patch Set: Created Oct. 21, 2014, 5:18 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 | « src/plugin/PluginClass.h ('k') | src/plugin/PluginDebug.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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;
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
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 const auto& arg = pDispParams->rgvarg[5];
554 if (vt == VT_BYREF + VT_VARIANT) 552 vt = arg.vt;
553 if (vt == (VT_BYREF | VT_VARIANT) && arg.pvarVal->vt == VT_BSTR)
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 UnescapeUrl(url);
559 }
559 } 560 }
560 else 561 else
561 { 562 {
562 // Wrong type, return. 563 // Wrong type, return.
563 return; 564 return;
564 } 565 }
565 566
566 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page 567 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page
567 CPluginClient* client = CPluginClient::GetInstance(); 568 CPluginClient* client = CPluginClient::GetInstance();
568 569 CString urlLegacy = ToCString(url);
569 if (url.Find(L"javascript") == 0) 570 if (urlLegacy.Find(L"javascript") == 0)
570 { 571 {
571 } 572 }
572 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) 573 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr))
573 { 574 {
574 m_tab->OnNavigate(url); 575 m_tab->OnNavigate(url);
575 576
576 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + url + "\n=================== =============================================================") 577 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + urlLegacy + "\n============= ===================================================================")
577 578
578 #ifdef ENABLE_DEBUG_RESULT 579 #ifdef ENABLE_DEBUG_RESULT
579 CPluginDebug::DebugResultDomain(url); 580 CPluginDebug::DebugResultDomain(urlLegacy);
580 #endif 581 #endif
581 582
582 UpdateStatusBar(); 583 UpdateStatusBar();
583 } 584 }
584 else 585 else
585 { 586 {
586 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 587 DEBUG_NAVI(L"Navi::Begin navigation url:" + urlLegacy)
587 m_tab->CacheFrame(url); 588 m_tab->CacheFrame(url);
588 } 589 }
589 } 590 }
591
590 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) 592 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags)
591 { 593 {
592 DEBUG_GENERAL("Tab changed"); 594 DEBUG_GENERAL("Tab changed");
593 bool newtabshown = pDispParams->rgvarg[1].intVal==3; 595 bool newtabshown = pDispParams->rgvarg[1].intVal==3;
594 if (newtabshown) 596 if (newtabshown)
595 { 597 {
596 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); 598 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId());
597 if (it == s_threadInstances.end()) 599 if (it == s_threadInstances.end())
598 { 600 {
599 s_threadInstances[::GetCurrentThreadId()] = this; 601 s_threadInstances[::GetCurrentThreadId()] = this;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 { 714 {
713 DEBUG_NAVI("Navi::Document Complete") 715 DEBUG_NAVI("Navi::Document Complete")
714 716
715 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 717 CComQIPtr<IWebBrowser2> browser = GetBrowser();
716 718
717 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH) 719 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH)
718 { 720 {
719 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; 721 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
720 if (pBrowser) 722 if (pBrowser)
721 { 723 {
722 CString url; 724 BSTR bstrUrl;
723 CComBSTR bstrUrl;
724 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0) 725 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0)
725 { 726 {
726 url = bstrUrl; 727 std::wstring url(bstrUrl, SysStringLen(bstrUrl));
727 728 SysFreeString(bstrUrl);
728 CPluginClient::UnescapeUrl(url); 729 UnescapeUrl(url);
729
730 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er)); 730 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er));
731 } 731 }
732 } 732 }
733 } 733 }
734 } 734 }
735 break; 735 break;
736 736
737 case DISPID_ONQUIT: 737 case DISPID_ONQUIT:
738 case DISPID_QUIT: 738 case DISPID_QUIT:
739 { 739 {
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1133 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1134 { 1134 {
1135 if (cCmds == 0) return E_INVALIDARG; 1135 if (cCmds == 0) return E_INVALIDARG;
1136 if (prgCmds == 0) return E_POINTER; 1136 if (prgCmds == 0) return E_POINTER;
1137 1137
1138 prgCmds[0].cmdf = OLECMDF_ENABLED; 1138 prgCmds[0].cmdf = OLECMDF_ENABLED;
1139 1139
1140 return S_OK; 1140 return S_OK;
1141 } 1141 }
1142 1142
1143 HMENU CPluginClass::CreatePluginMenu(const CString& url) 1143 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
1144 { 1144 {
1145 DEBUG_GENERAL("CreatePluginMenu"); 1145 DEBUG_GENERAL("CreatePluginMenu");
1146 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1146 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1147 1147
1148 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1148 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1149 1149
1150 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); 1150 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);
1151 1151
1152 SetMenuBar(hMenuTrackPopup, url); 1152 SetMenuBar(hMenuTrackPopup, url);
1153 1153
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 { 1350 {
1351 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1351 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1352 } 1352 }
1353 } 1353 }
1354 } 1354 }
1355 break; 1355 break;
1356 } 1356 }
1357 case ID_MENU_DISABLE_ON_SITE: 1357 case ID_MENU_DISABLE_ON_SITE:
1358 { 1358 {
1359 CPluginSettings* settings = CPluginSettings::GetInstance(); 1359 CPluginSettings* settings = CPluginSettings::GetInstance();
1360 CString urlString = GetTab()->GetDocumentUrl(); 1360 std::wstring urlString = GetTab()->GetDocumentUrl();
1361 if (client->IsWhitelistedUrl(to_wstring(urlString))) 1361 if (client->IsWhitelistedUrl(urlString))
1362 { 1362 {
1363 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w string(urlString)))); 1363 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(urlS tring)));
1364 } 1364 }
1365 else 1365 else
1366 { 1366 {
1367 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr ing(urlString)))); 1367 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(urlStri ng)));
1368 } 1368 }
1369 GetBrowser()->Refresh(); 1369 GetBrowser()->Refresh();
1370 } 1370 }
1371 default: 1371 default:
1372 break; 1372 break;
1373 } 1373 }
1374 1374
1375 // Invalidate and redraw the control 1375 // Invalidate and redraw the control
1376 UpdateStatusBar(); 1376 UpdateStatusBar();
1377 } 1377 }
1378 1378
1379 1379
1380 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) 1380 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url)
1381 { 1381 {
1382 DEBUG_GENERAL("SetMenuBar"); 1382 DEBUG_GENERAL("SetMenuBar");
1383 1383
1384 std::wstring ctext; 1384 std::wstring ctext;
1385 1385
1386 s_criticalSectionLocal.Lock(); 1386 s_criticalSectionLocal.Lock();
1387 { 1387 {
1388 s_menuDomains.clear(); 1388 s_menuDomains.clear();
1389 } 1389 }
1390 s_criticalSectionLocal.Unlock(); 1390 s_criticalSectionLocal.Unlock();
1391 1391
1392 Dictionary* dictionary = Dictionary::GetInstance(); 1392 Dictionary* dictionary = Dictionary::GetInstance();
1393 1393
1394 MENUITEMINFOW fmii; 1394 MENUITEMINFOW fmii;
1395 memset(&fmii, 0, sizeof(MENUITEMINFO)); 1395 memset(&fmii, 0, sizeof(MENUITEMINFO));
1396 fmii.cbSize = sizeof(MENUITEMINFO); 1396 fmii.cbSize = sizeof(MENUITEMINFO);
1397 1397
1398 MENUITEMINFOW miiSep; 1398 MENUITEMINFOW miiSep;
1399 memset(&miiSep, 0, sizeof(MENUITEMINFO)); 1399 memset(&miiSep, 0, sizeof(MENUITEMINFO));
1400 miiSep.cbSize = sizeof(MENUITEMINFO); 1400 miiSep.cbSize = sizeof(MENUITEMINFO);
1401 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1401 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1402 miiSep.fType = MFT_SEPARATOR; 1402 miiSep.fType = MFT_SEPARATOR;
1403 1403
1404 CPluginClient* client = CPluginClient::GetInstance(); 1404 CPluginClient* client = CPluginClient::GetInstance();
1405 CPluginSettings* settings = CPluginSettings::GetInstance(); 1405 CPluginSettings* settings = CPluginSettings::GetInstance();
1406 { 1406 {
1407 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1407 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1408 // Is domain in white list? 1408 // Is domain in white list?
1409 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); 1409 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url));
1410 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) 1410 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl()))
1411 { 1411 {
1412 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1412 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1413 } 1413 }
1414 else 1414 else
1415 { 1415 {
1416 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1416 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1417 } 1417 }
1418 fmii.fMask = MIIM_STRING | MIIM_STATE; 1418 fmii.fMask = MIIM_STRING | MIIM_STATE;
1419 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1419 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1420 fmii.cch = static_cast<UINT>(ctext.size()); 1420 fmii.cch = static_cast<UINT>(ctext.size());
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 } 1615 }
1616 1616
1617 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); 1617 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1618 1618
1619 1619
1620 return result; 1620 return result;
1621 1621
1622 } 1622 }
1623 1623
1624 1624
1625 HICON CPluginClass::GetStatusBarIcon(const CString& url) 1625 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1626 { 1626 {
1627 // use the disable icon as defualt, if the client doesn't exists 1627 // use the disable icon as defualt, if the client doesn't exists
1628 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1628 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1629 1629
1630 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1630 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1631 if (tab) 1631 if (tab)
1632 { 1632 {
1633 CPluginClient* client = CPluginClient::GetInstance(); 1633 CPluginClient* client = CPluginClient::GetInstance();
1634 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) 1634 if (!CPluginSettings::GetInstance()->IsPluginEnabled())
1635 { 1635 {
1636 } 1636 }
1637 else if (client->IsWhitelistedUrl(to_wstring(url))) 1637 else if (client->IsWhitelistedUrl(url))
1638 { 1638 {
1639 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1639 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1640 } 1640 }
1641 else 1641 else
1642 { 1642 {
1643 CPluginSettings* settings = CPluginSettings::GetInstance(); 1643 CPluginSettings* settings = CPluginSettings::GetInstance();
1644 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1644 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1645 } 1645 }
1646 } 1646 }
1647 return hIcon; 1647 return hIcon;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 1744
1745 // Done! 1745 // Done!
1746 EndPaint(hWnd, &ps); 1746 EndPaint(hWnd, &ps);
1747 1747
1748 return 0; 1748 return 0;
1749 } 1749 }
1750 1750
1751 case WM_LBUTTONUP: 1751 case WM_LBUTTONUP:
1752 case WM_RBUTTONUP: 1752 case WM_RBUTTONUP:
1753 { 1753 {
1754 CString strURL = pClass->GetBrowserUrl(); 1754 std::wstring url = pClass->GetBrowserUrl();
1755 if (strURL != pClass->GetTab()->GetDocumentUrl()) 1755 if (url != pClass->GetTab()->GetDocumentUrl())
1756 { 1756 {
1757 pClass->GetTab()->SetDocumentUrl(strURL); 1757 pClass->GetTab()->SetDocumentUrl(url);
1758 } 1758 }
1759 1759
1760 // Create menu 1760 // Create menu
1761 HMENU hMenu = pClass->CreatePluginMenu(strURL); 1761 HMENU hMenu = pClass->CreatePluginMenu(url);
1762 if (!hMenu) 1762 if (!hMenu)
1763 { 1763 {
1764 return 0; 1764 return 0;
1765 } 1765 }
1766 1766
1767 // Display menu 1767 // Display menu
1768 POINT pt; 1768 POINT pt;
1769 ::GetCursorPos(&pt); 1769 ::GetCursorPos(&pt);
1770 1770
1771 RECT rc; 1771 RECT rc;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 } 1975 }
1976 } 1976 }
1977 } 1977 }
1978 1978
1979 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1979 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1980 } 1980 }
1981 1981
1982 return hTabWnd; 1982 return hTabWnd;
1983 1983
1984 } 1984 }
OLDNEW
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginDebug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld