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: Rebased Created Oct. 21, 2014, 6:26 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 #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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 s_criticalSectionLocal.Lock(); 197 s_criticalSectionLocal.Lock();
198 { 198 {
199 browser = s_asyncWebBrowser2; 199 browser = s_asyncWebBrowser2;
200 } 200 }
201 s_criticalSectionLocal.Unlock(); 201 s_criticalSectionLocal.Unlock();
202 202
203 return browser; 203 return browser;
204 } 204 }
205 205
206 CString CPluginClass::GetBrowserUrl() const 206 std::wstring CPluginClass::GetBrowserUrl() const
207 { 207 {
208 CString url; 208 std::wstring url;
209
210 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 209 CComQIPtr<IWebBrowser2> browser = GetBrowser();
211 if (browser) 210 if (browser)
212 { 211 {
213 CComBSTR bstrURL; 212 BSTR bstrURL;
214 213 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL)
215 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)))
216 { 214 {
217 url = bstrURL; 215 url = std::wstring(bstrURL, SysStringLen(bstrURL));
218 CPluginClient::UnescapeUrl(url); 216 SysFreeString(bstrURL);
217 UnescapeUrl(url);
219 } 218 }
220 } 219 }
221 else 220 else
222 { 221 {
223 url = m_tab->GetDocumentUrl(); 222 url = m_tab->GetDocumentUrl();
224 } 223 }
225
226 return url; 224 return url;
227 } 225 }
228 226
229 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 227 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
230 { 228 {
231 if (thisPtr == NULL) 229 if (thisPtr == NULL)
232 return 0; 230 return 0;
233 if (!((CPluginClass*)thisPtr)->InitObject(true)) 231 if (!((CPluginClass*)thisPtr)->InitObject(true))
234 { 232 {
235 ((CPluginClass*)thisPtr)->Unadvice(); 233 ((CPluginClass*)thisPtr)->Unadvice();
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 { 541 {
544 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; 542 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal;
545 } 543 }
546 else 544 else
547 { 545 {
548 // Wrong type, return. 546 // Wrong type, return.
549 return; 547 return;
550 } 548 }
551 549
552 // Get the URL 550 // Get the URL
553 CString url; 551 std::wstring url;
554 vt = pDispParams->rgvarg[5].vt; 552 const auto& arg = pDispParams->rgvarg[5];
555 if (vt == VT_BYREF + VT_VARIANT) 553 vt = arg.vt;
554 if (vt == (VT_BYREF | VT_VARIANT) && arg.pvarVal->vt == VT_BSTR)
556 { 555 {
557 url = pDispParams->rgvarg[5].pvarVal->bstrVal; 556 BSTR b = arg.pvarVal->bstrVal;
558 557 if (b) {
559 CPluginClient::UnescapeUrl(url); 558 url = std::wstring(b, SysStringLen(b));
559 UnescapeUrl(url);
560 }
560 } 561 }
561 else 562 else
562 { 563 {
563 // Wrong type, return. 564 // Wrong type, return.
564 return; 565 return;
565 } 566 }
566 567
567 // 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
568 CPluginClient* client = CPluginClient::GetInstance(); 569 CPluginClient* client = CPluginClient::GetInstance();
569 570 CString urlLegacy = ToCString(url);
570 if (url.Find(L"javascript") == 0) 571 if (urlLegacy.Find(L"javascript") == 0)
571 { 572 {
572 } 573 }
573 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) 574 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr))
574 { 575 {
575 m_tab->OnNavigate(url); 576 m_tab->OnNavigate(url);
576 577
577 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + url + "\n=================== =============================================================") 578 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + urlLegacy + "\n============= ===================================================================")
578 579
579 #ifdef ENABLE_DEBUG_RESULT 580 #ifdef ENABLE_DEBUG_RESULT
580 CPluginDebug::DebugResultDomain(url); 581 CPluginDebug::DebugResultDomain(urlLegacy);
581 #endif 582 #endif
582 583
583 UpdateStatusBar(); 584 UpdateStatusBar();
584 } 585 }
585 else 586 else
586 { 587 {
587 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 588 DEBUG_NAVI(L"Navi::Begin navigation url:" + urlLegacy)
588 m_tab->CacheFrame(url); 589 m_tab->CacheFrame(url);
589 } 590 }
590 } 591 }
592
591 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) 593 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags)
592 { 594 {
593 DEBUG_GENERAL("Tab changed"); 595 DEBUG_GENERAL("Tab changed");
594 bool newtabshown = pDispParams->rgvarg[1].intVal==3; 596 bool newtabshown = pDispParams->rgvarg[1].intVal==3;
595 if (newtabshown) 597 if (newtabshown)
596 { 598 {
597 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());
598 if (it == s_threadInstances.end()) 600 if (it == s_threadInstances.end())
599 { 601 {
600 s_threadInstances[::GetCurrentThreadId()] = this; 602 s_threadInstances[::GetCurrentThreadId()] = this;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 { 715 {
714 DEBUG_NAVI("Navi::Document Complete") 716 DEBUG_NAVI("Navi::Document Complete")
715 717
716 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 718 CComQIPtr<IWebBrowser2> browser = GetBrowser();
717 719
718 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH) 720 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH)
719 { 721 {
720 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; 722 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
721 if (pBrowser) 723 if (pBrowser)
722 { 724 {
723 CString url; 725 BSTR bstrUrl;
724 CComBSTR bstrUrl;
725 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0) 726 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0)
726 { 727 {
727 url = bstrUrl; 728 std::wstring url(bstrUrl, SysStringLen(bstrUrl));
728 729 SysFreeString(bstrUrl);
729 CPluginClient::UnescapeUrl(url); 730 UnescapeUrl(url);
730
731 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er)); 731 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er));
732 } 732 }
733 } 733 }
734 } 734 }
735 } 735 }
736 break; 736 break;
737 737
738 case DISPID_ONQUIT: 738 case DISPID_ONQUIT:
739 case DISPID_QUIT: 739 case DISPID_QUIT:
740 { 740 {
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1135 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1136 { 1136 {
1137 if (cCmds == 0) return E_INVALIDARG; 1137 if (cCmds == 0) return E_INVALIDARG;
1138 if (prgCmds == 0) return E_POINTER; 1138 if (prgCmds == 0) return E_POINTER;
1139 1139
1140 prgCmds[0].cmdf = OLECMDF_ENABLED; 1140 prgCmds[0].cmdf = OLECMDF_ENABLED;
1141 1141
1142 return S_OK; 1142 return S_OK;
1143 } 1143 }
1144 1144
1145 HMENU CPluginClass::CreatePluginMenu(const CString& url) 1145 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
1146 { 1146 {
1147 DEBUG_GENERAL("CreatePluginMenu"); 1147 DEBUG_GENERAL("CreatePluginMenu");
1148 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1148 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1149 1149
1150 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1150 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1151 1151
1152 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); 1152 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);
1153 1153
1154 SetMenuBar(hMenuTrackPopup, url); 1154 SetMenuBar(hMenuTrackPopup, url);
1155 1155
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 { 1242 {
1243 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1243 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1244 } 1244 }
1245 } 1245 }
1246 } 1246 }
1247 break; 1247 break;
1248 } 1248 }
1249 case ID_MENU_DISABLE_ON_SITE: 1249 case ID_MENU_DISABLE_ON_SITE:
1250 { 1250 {
1251 CPluginSettings* settings = CPluginSettings::GetInstance(); 1251 CPluginSettings* settings = CPluginSettings::GetInstance();
1252 CString urlString = GetTab()->GetDocumentUrl(); 1252 std::wstring urlString = GetTab()->GetDocumentUrl();
1253 if (client->IsWhitelistedUrl(to_wstring(urlString))) 1253 if (client->IsWhitelistedUrl(urlString))
1254 { 1254 {
1255 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w string(urlString)))); 1255 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(urlS tring)));
1256 } 1256 }
1257 else 1257 else
1258 { 1258 {
1259 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr ing(urlString)))); 1259 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(urlStri ng)));
1260 } 1260 }
1261 GetBrowser()->Refresh(); 1261 GetBrowser()->Refresh();
1262 } 1262 }
1263 default: 1263 default:
1264 break; 1264 break;
1265 } 1265 }
1266 1266
1267 // Invalidate and redraw the control 1267 // Invalidate and redraw the control
1268 UpdateStatusBar(); 1268 UpdateStatusBar();
1269 } 1269 }
1270 1270
1271 1271
1272 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) 1272 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url)
1273 { 1273 {
1274 DEBUG_GENERAL("SetMenuBar"); 1274 DEBUG_GENERAL("SetMenuBar");
1275 1275
1276 std::wstring ctext; 1276 std::wstring ctext;
1277 1277
1278 s_criticalSectionLocal.Lock(); 1278 s_criticalSectionLocal.Lock();
1279 { 1279 {
1280 s_menuDomains.clear(); 1280 s_menuDomains.clear();
1281 } 1281 }
1282 s_criticalSectionLocal.Unlock(); 1282 s_criticalSectionLocal.Unlock();
1283 1283
1284 Dictionary* dictionary = Dictionary::GetInstance(); 1284 Dictionary* dictionary = Dictionary::GetInstance();
1285 1285
1286 MENUITEMINFOW fmii = {}; 1286 MENUITEMINFOW fmii = {};
1287 fmii.cbSize = sizeof(fmii); 1287 fmii.cbSize = sizeof(fmii);
1288 1288
1289 MENUITEMINFOW miiSep = {}; 1289 MENUITEMINFOW miiSep = {};
1290 miiSep.cbSize = sizeof(miiSep); 1290 miiSep.cbSize = sizeof(miiSep);
1291 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1291 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1292 miiSep.fType = MFT_SEPARATOR; 1292 miiSep.fType = MFT_SEPARATOR;
1293 1293
1294 CPluginClient* client = CPluginClient::GetInstance(); 1294 CPluginClient* client = CPluginClient::GetInstance();
1295 CPluginSettings* settings = CPluginSettings::GetInstance(); 1295 CPluginSettings* settings = CPluginSettings::GetInstance();
1296 { 1296 {
1297 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1297 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1298 // Is domain in white list? 1298 // Is domain in white list?
1299 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); 1299 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url));
1300 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) 1300 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl()))
1301 { 1301 {
1302 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1302 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1303 } 1303 }
1304 else 1304 else
1305 { 1305 {
1306 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1306 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1307 } 1307 }
1308 fmii.fMask = MIIM_STRING | MIIM_STATE; 1308 fmii.fMask = MIIM_STRING | MIIM_STATE;
1309 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1309 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1310 fmii.cch = static_cast<UINT>(ctext.size()); 1310 fmii.cch = static_cast<UINT>(ctext.size());
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 } 1504 }
1505 1505
1506 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); 1506 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1507 1507
1508 1508
1509 return result; 1509 return result;
1510 1510
1511 } 1511 }
1512 1512
1513 1513
1514 HICON CPluginClass::GetStatusBarIcon(const CString& url) 1514 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1515 { 1515 {
1516 // use the disable icon as defualt, if the client doesn't exists 1516 // use the disable icon as defualt, if the client doesn't exists
1517 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1517 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1518 1518
1519 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1519 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1520 if (tab) 1520 if (tab)
1521 { 1521 {
1522 CPluginClient* client = CPluginClient::GetInstance(); 1522 CPluginClient* client = CPluginClient::GetInstance();
1523 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) 1523 if (!CPluginSettings::GetInstance()->IsPluginEnabled())
1524 { 1524 {
1525 } 1525 }
1526 else if (client->IsWhitelistedUrl(to_wstring(url))) 1526 else if (client->IsWhitelistedUrl(url))
1527 { 1527 {
1528 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1528 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1529 } 1529 }
1530 else 1530 else
1531 { 1531 {
1532 CPluginSettings* settings = CPluginSettings::GetInstance(); 1532 CPluginSettings* settings = CPluginSettings::GetInstance();
1533 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1533 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1534 } 1534 }
1535 } 1535 }
1536 return hIcon; 1536 return hIcon;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 1633
1634 // Done! 1634 // Done!
1635 EndPaint(hWnd, &ps); 1635 EndPaint(hWnd, &ps);
1636 1636
1637 return 0; 1637 return 0;
1638 } 1638 }
1639 1639
1640 case WM_LBUTTONUP: 1640 case WM_LBUTTONUP:
1641 case WM_RBUTTONUP: 1641 case WM_RBUTTONUP:
1642 { 1642 {
1643 CString strURL = pClass->GetBrowserUrl(); 1643 std::wstring url = pClass->GetBrowserUrl();
1644 if (strURL != pClass->GetTab()->GetDocumentUrl()) 1644 if (url != pClass->GetTab()->GetDocumentUrl())
1645 { 1645 {
1646 pClass->GetTab()->SetDocumentUrl(strURL); 1646 pClass->GetTab()->SetDocumentUrl(url);
1647 } 1647 }
1648 1648
1649 // Create menu 1649 // Create menu
1650 HMENU hMenu = pClass->CreatePluginMenu(strURL); 1650 HMENU hMenu = pClass->CreatePluginMenu(url);
1651 if (!hMenu) 1651 if (!hMenu)
1652 { 1652 {
1653 return 0; 1653 return 0;
1654 } 1654 }
1655 1655
1656 // Display menu 1656 // Display menu
1657 POINT pt; 1657 POINT pt;
1658 ::GetCursorPos(&pt); 1658 ::GetCursorPos(&pt);
1659 1659
1660 RECT rc; 1660 RECT rc;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 } 1864 }
1865 } 1865 }
1866 } 1866 }
1867 1867
1868 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1868 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1869 } 1869 }
1870 1870
1871 return hTabWnd; 1871 return hTabWnd;
1872 1872
1873 } 1873 }
OLDNEW
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginDebug.h » ('j') | src/plugin/PluginFilter.cpp » ('J')

Powered by Google App Engine
This is Rietveld