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

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

Issue 6567422169448448: Issue 119 - Switch to injecting CSS for element hiding (Closed)
Patch Set: rebase Created Dec. 1, 2015, 3:45 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 /* 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 14 matching lines...) Expand all
25 #include "AdblockPlusClient.h" 25 #include "AdblockPlusClient.h"
26 #include "PluginClientBase.h" 26 #include "PluginClientBase.h"
27 #include "PluginClientFactory.h" 27 #include "PluginClientFactory.h"
28 #include "PluginUtil.h" 28 #include "PluginUtil.h"
29 #include "../shared/Utils.h" 29 #include "../shared/Utils.h"
30 #include "../shared/Dictionary.h" 30 #include "../shared/Dictionary.h"
31 #include "IeVersion.h" 31 #include "IeVersion.h"
32 #include "../shared/Version.h" 32 #include "../shared/Version.h"
33 #include <thread> 33 #include <thread>
34 #include <array> 34 #include <array>
35 #include "WebBrowserEventsListener.h"
35 36
36 #ifdef DEBUG_HIDE_EL 37 #ifdef DEBUG_HIDE_EL
37 DWORD profileTime = 0; 38 DWORD profileTime = 0;
38 #endif 39 #endif
39 40
40 extern CComModule _Module; 41 extern CComModule _Module;
41 42
42 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); 43 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR);
43 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT); 44 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT);
44 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); 45 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 85 }
85 86
86 int Width() const 87 int Width() const
87 { 88 {
88 return right - left; 89 return right - left;
89 } 90 }
90 }; 91 };
91 } 92 }
92 93
93 CPluginClass::CPluginClass() 94 CPluginClass::CPluginClass()
95 : m_data(std::make_shared<Data>())
94 { 96 {
95 //Use this line to debug memory leaks 97 //Use this line to debug memory leaks
96 // _CrtDumpMemoryLeaks(); 98 // _CrtDumpMemoryLeaks();
97 99
98 m_isAdvised = false; 100 m_isAdvised = false;
99 m_hTabWnd = NULL; 101 m_hTabWnd = NULL;
100 m_hStatusBarWnd = NULL; 102 m_hStatusBarWnd = NULL;
101 m_hPaneWnd = NULL; 103 m_hPaneWnd = NULL;
102 m_nPaneWidth = 0; 104 m_nPaneWidth = 0;
103 m_pWndProcStatus = NULL; 105 m_pWndProcStatus = NULL;
104 m_hTheme = NULL; 106 m_hTheme = NULL;
105 m_isInitializedOk = false; 107 m_isInitializedOk = false;
106 108
107 109
108 m_tab = new CPluginTab(this); 110 m_data->tab.reset(new CPluginTab(this));
109
110 Dictionary::Create(GetBrowserLanguage()); 111 Dictionary::Create(GetBrowserLanguage());
111 } 112 }
112 113
113 CPluginClass::~CPluginClass() 114 CPluginClass::~CPluginClass()
114 { 115 {
115 delete m_tab;
116 } 116 }
117 117
118
119 ///////////////////////////////////////////////////////////////////////////// 118 /////////////////////////////////////////////////////////////////////////////
120 // Initialization 119 // Initialization
121 120
122 HRESULT CPluginClass::FinalConstruct() 121 HRESULT CPluginClass::FinalConstruct()
123 { 122 {
124 return S_OK; 123 return S_OK;
125 } 124 }
126 125
127 void CPluginClass::FinalRelease() 126 void CPluginClass::FinalRelease()
128 { 127 {
129 s_criticalSectionBrowser.Lock(); 128 s_criticalSectionBrowser.Lock();
130 { 129 {
131 m_webBrowser2.Release(); 130 m_data.reset();
Eric 2015/12/02 17:00:13 'FinalRelease' is slated to disappear as part of t
132 } 131 }
133 s_criticalSectionBrowser.Unlock(); 132 s_criticalSectionBrowser.Unlock();
134 } 133 }
135 134
136 HWND CPluginClass::GetBrowserHWND() const 135 HWND CPluginClass::GetBrowserHWND() const
137 { 136 {
138 SHANDLE_PTR hBrowserWndHandle = NULL; 137 SHANDLE_PTR hBrowserWndHandle = NULL;
139 138
140 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 139 CComQIPtr<IWebBrowser2> browser = GetBrowser();
141 if (browser) 140 if (browser)
142 { 141 {
143 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); 142 HRESULT hr = browser->get_HWND(&hBrowserWndHandle);
144 if (FAILED(hr)) 143 if (FAILED(hr))
145 { 144 {
146 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, " Class::GetBrowserHWND - failed") 145 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, " Class::GetBrowserHWND - failed")
147 } 146 }
148 } 147 }
149 148
150 return (HWND)hBrowserWndHandle; 149 return (HWND)hBrowserWndHandle;
151 } 150 }
152 151
153 152
154 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const 153 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const
155 { 154 {
156 CComQIPtr<IWebBrowser2> browser; 155 CComQIPtr<IWebBrowser2> browser;
157 156
158 s_criticalSectionBrowser.Lock(); 157 s_criticalSectionBrowser.Lock();
159 { 158 {
160 browser = m_webBrowser2; 159 browser = m_data->webBrowser2;
161 } 160 }
162 s_criticalSectionBrowser.Unlock(); 161 s_criticalSectionBrowser.Unlock();
163 162
164 return browser; 163 return browser;
165 } 164 }
166 165
167 166
168 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() 167 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
169 { 168 {
170 CComQIPtr<IWebBrowser2> browser; 169 CComQIPtr<IWebBrowser2> browser;
(...skipping 14 matching lines...) Expand all
185 if (browser) 184 if (browser)
186 { 185 {
187 CComBSTR bstrURL; 186 CComBSTR bstrURL;
188 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) 187 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL)
189 { 188 {
190 url = std::wstring(bstrURL, SysStringLen(bstrURL)); 189 url = std::wstring(bstrURL, SysStringLen(bstrURL));
191 } 190 }
192 } 191 }
193 else 192 else
194 { 193 {
195 url = m_tab->GetDocumentUrl(); 194 url = m_data->tab->GetDocumentUrl();
196 } 195 }
197 return url; 196 return url;
198 } 197 }
199 198
200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 199 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
201 { 200 {
202 if (thisPtr == NULL) 201 if (thisPtr == NULL)
203 return 0; 202 return 0;
204 if (!((CPluginClass*)thisPtr)->InitObject()) 203 if (!((CPluginClass*)thisPtr)->InitObject())
205 { 204 {
(...skipping 23 matching lines...) Expand all
229 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================") 228 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
230 229
231 HRESULT hr = ::CoInitialize(NULL); 230 HRESULT hr = ::CoInitialize(NULL);
232 if (FAILED(hr)) 231 if (FAILED(hr))
233 { 232 {
234 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 233 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
235 } 234 }
236 235
237 s_criticalSectionBrowser.Lock(); 236 s_criticalSectionBrowser.Lock();
238 { 237 {
239 m_webBrowser2 = unknownSite; 238 m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite);
240 } 239 }
241 s_criticalSectionBrowser.Unlock(); 240 s_criticalSectionBrowser.Unlock();
242 241
243 //register the mimefilter 242 //register the mimefilter
244 //and only mimefilter 243 //and only mimefilter
245 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 244 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
246 245
247 s_criticalSectionLocal.Lock(); 246 s_criticalSectionLocal.Lock();
248 { 247 {
249 // Always register on startup, then check if we need to unregister in a separate thread 248 // Always register on startup, then check if we need to unregister in a separate thread
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 { 323 {
325 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 324 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
326 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 325 CPluginClientFactory::ReleaseMimeFilterClientInstance();
327 } 326 }
328 } 327 }
329 s_criticalSectionLocal.Unlock(); 328 s_criticalSectionLocal.Unlock();
330 329
331 // Release browser interface 330 // Release browser interface
332 s_criticalSectionBrowser.Lock(); 331 s_criticalSectionBrowser.Lock();
333 { 332 {
334 m_webBrowser2.Release(); 333 m_data->webBrowser2.Release();
335 } 334 }
336 s_criticalSectionBrowser.Unlock(); 335 s_criticalSectionBrowser.Unlock();
337 336
338 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 337 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
339 338
340 ::CoUninitialize(); 339 ::CoUninitialize();
341 } 340 }
342 341
343 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); 342 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
344 } 343 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; 475 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
477 if (!webBrowser) 476 if (!webBrowser)
478 { 477 {
479 return; 478 return;
480 } 479 }
481 if (!urlVariant || urlVariant->vt != VT_BSTR) 480 if (!urlVariant || urlVariant->vt != VT_BSTR)
482 { 481 {
483 return; 482 return;
484 } 483 }
485 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); 484 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
485 EnsureWebBrowserConnected(webBrowser);
486 486
487 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 487 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
488 // navigating new page 488 // navigating new page
489 CPluginClient* client = CPluginClient::GetInstance(); 489 CPluginClient* client = CPluginClient::GetInstance();
490 if (url.find(L"javascript") == 0) 490 if (url.find(L"javascript") == 0)
491 { 491 {
492 } 492 }
493 else if (GetBrowser().IsEqualObject(webBrowser)) 493 else if (GetBrowser().IsEqualObject(webBrowser))
494 { 494 {
495 m_tab->OnNavigate(url); 495 m_data->tab->OnNavigate(url);
496 DEBUG_GENERAL( 496 DEBUG_GENERAL(
497 L"======================================================================== ========\n" 497 L"======================================================================== ========\n"
498 L"Begin main navigation url:" + url + L"\n" 498 L"Begin main navigation url:" + url + L"\n"
499 L"======================================================================== ========") 499 L"======================================================================== ========")
500 500
501 #ifdef ENABLE_DEBUG_RESULT 501 #ifdef ENABLE_DEBUG_RESULT
502 CPluginDebug::DebugResultDomain(url); 502 CPluginDebug::DebugResultDomain(url);
503 #endif 503 #endif
504 UpdateStatusBar(); 504 UpdateStatusBar();
505 } 505 }
506 else 506 else
507 { 507 {
508 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 508 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
509 m_tab->CacheFrame(url); 509 m_data->tab->CacheFrame(url);
510 } 510 }
511 } 511 }
512 catch (...) 512 catch (...)
513 { 513 {
514 } 514 }
515 } 515 }
516 516
517 // Entry point 517 // Entry point
518 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() 518 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
519 { 519 {
520 try 520 try
521 { 521 {
522 DEBUG_NAVI(L"Navi::Download Complete") 522 DEBUG_NAVI(L"Navi::Download Complete")
523 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); 523 ATL::CComPtr<IWebBrowser2> browser = GetBrowser();
524 if (browser) 524 if (browser)
525 { 525 {
526 m_tab->OnDownloadComplete(browser); 526 m_data->tab->OnDownloadComplete(browser);
527 } 527 }
528 } 528 }
529 catch (...) 529 catch (...)
530 { 530 {
531 } 531 }
532 } 532 }
533 533
534 // Entry point 534 // Entry point
535 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
536 {
537 try
538 {
539 DEBUG_NAVI(L"Navi::Document Complete");
540 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
541 if (!webBrowser2)
542 {
543 return;
544 }
545 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
546 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2);
547 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
548 }
549 catch (...)
550 {
551 }
552 }
553
554 // Entry point
555 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 535 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
556 { 536 {
557 try 537 try
558 { 538 {
559 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); 539 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)");
560 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED) 540 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED)
561 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA BLED); 541 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA BLED);
562 if (newtabshown) 542 if (newtabshown)
563 { 543 {
564 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find( GetCurrentThreadId()); 544 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find( GetCurrentThreadId());
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 } 957 }
978 } 958 }
979 } 959 }
980 s_criticalSectionLocal.Unlock(); 960 s_criticalSectionLocal.Unlock();
981 961
982 return result; 962 return result;
983 } 963 }
984 964
985 CPluginTab* CPluginClass::GetTab() 965 CPluginTab* CPluginClass::GetTab()
986 { 966 {
987 return m_tab; 967 return m_data->tab.get();
988 } 968 }
989 969
990 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) 970 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId)
991 { 971 {
992 CPluginTab* tab = NULL; 972 CPluginTab* tab = NULL;
993 973
994 s_criticalSectionLocal.Lock(); 974 s_criticalSectionLocal.Lock();
995 { 975 {
996 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw ThreadId); 976 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw ThreadId);
997 if (it != s_threadInstances.end()) 977 if (it != s_threadInstances.end())
998 { 978 {
999 tab = it->second->m_tab; 979 tab = it->second->m_data->tab.get();
1000 } 980 }
1001 } 981 }
1002 s_criticalSectionLocal.Unlock(); 982 s_criticalSectionLocal.Unlock();
1003 983
1004 return tab; 984 return tab;
1005 } 985 }
1006 986
1007 987
1008 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 988 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1009 { 989 {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 if (FAILED(hr)) 1095 if (FAILED(hr))
1116 { 1096 {
1117 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1097 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1118 } 1098 }
1119 } 1099 }
1120 } 1100 }
1121 break; 1101 break;
1122 } 1102 }
1123 case ID_MENU_DISABLE_ON_SITE: 1103 case ID_MENU_DISABLE_ON_SITE:
1124 { 1104 {
1105 CPluginSettings* settings = CPluginSettings::GetInstance();
1125 std::wstring urlString = GetTab()->GetDocumentUrl(); 1106 std::wstring urlString = GetTab()->GetDocumentUrl();
1126 std::string filterText = client->GetWhitelistingFilter(urlString); 1107 std::string filterText = client->GetWhitelistingFilter(urlString);
1127 if (!filterText.empty()) 1108 if (!filterText.empty())
1128 { 1109 {
1129 client->RemoveFilter(filterText); 1110 client->RemoveFilter(filterText);
1130 } 1111 }
1131 else 1112 else
1132 { 1113 {
1133 CPluginSettings::GetInstance()->AddWhiteListedDomain(client->GetHostFrom Url(urlString)); 1114 settings->AddWhiteListedDomain(client->GetHostFromUrl(urlString));
Eric 2015/12/02 17:00:14 This change and the one immediately above are a re
sergei 2016/02/25 17:48:26 Done.
1134 } 1115 }
1135 } 1116 }
1136 default: 1117 default:
1137 break; 1118 break;
1138 } 1119 }
1139 1120
1140 // Invalidate and redraw the control 1121 // Invalidate and redraw the control
1141 UpdateStatusBar(); 1122 UpdateStatusBar();
1142 } 1123 }
1143 1124
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 1197
1217 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) 1198 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*)
1218 { 1199 {
1219 HWND hBrowserWnd = GetBrowserHWND(); 1200 HWND hBrowserWnd = GetBrowserHWND();
1220 if (!hBrowserWnd) 1201 if (!hBrowserWnd)
1221 { 1202 {
1222 return E_FAIL; 1203 return E_FAIL;
1223 } 1204 }
1224 1205
1225 // Create menu 1206 // Create menu
1226 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); 1207 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl());
1227 if (!hMenu) 1208 if (!hMenu)
1228 { 1209 {
1229 return E_FAIL; 1210 return E_FAIL;
1230 } 1211 }
1231 1212
1232 // Check if button in toolbar was pressed 1213 // Check if button in toolbar was pressed
1233 int nIDCommand = -1; 1214 int nIDCommand = -1;
1234 BOOL bRightAlign = FALSE; 1215 BOOL bRightAlign = FALSE;
1235 1216
1236 POINT pt; 1217 POINT pt;
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 if (m_hPaneWnd == NULL) 1595 if (m_hPaneWnd == NULL)
1615 { 1596 {
1616 CreateStatusBarPane(); 1597 CreateStatusBarPane();
1617 } 1598 }
1618 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1599 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1619 { 1600 {
1620 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1601 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1621 } 1602 }
1622 } 1603 }
1623 1604
1624
1625 void CPluginClass::Unadvise() 1605 void CPluginClass::Unadvise()
1626 { 1606 {
1627 s_criticalSectionLocal.Lock(); 1607 s_criticalSectionLocal.Lock();
1628 { 1608 {
1629 if (m_isAdvised) 1609 if (m_isAdvised)
1630 { 1610 {
1631 HRESULT hr = DispEventUnadvise(GetBrowser()); 1611 HRESULT hr = DispEventUnadvise(GetBrowser());
1632 if (FAILED(hr)) 1612 if (FAILED(hr))
1633 { 1613 {
1634 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise"); 1614 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1635 } 1615 }
1636 m_isAdvised = false; 1616 m_isAdvised = false;
1637 } 1617 }
1638 } 1618 }
1639 s_criticalSectionLocal.Unlock(); 1619 s_criticalSectionLocal.Unlock();
1640 } 1620 }
1641 1621
1622 void CPluginClass::EnsureWebBrowserConnected(const ATL::CComPtr<IWebBrowser2>& w ebBrowser)
1623 {
1624 auto it = m_data->connectedWebBrowsersCache.find(webBrowser);
1625 if (it != m_data->connectedWebBrowsersCache.end())
1626 {
1627 return;
1628 }
1629 ATL::CComObject<WebBrowserEventsListener>* listenerImpl = nullptr;
1630 if (FAILED(ATL::CComObject<WebBrowserEventsListener>::CreateInstance(&listener Impl)))
1631 {
1632 return;
1633 }
1634 ATL::CComPtr<IUnknown> listenerRefCounterGuard(listenerImpl->GetUnknown());
1635 std::weak_ptr<Data> dataForCapturing = m_data;
1636 auto onListenerDestroy = [webBrowser, dataForCapturing]
1637 {
1638 if (auto data = dataForCapturing.lock())
1639 {
1640 data->connectedWebBrowsersCache.erase(webBrowser);
1641 }
1642 };
1643 auto onReloaded = [webBrowser, dataForCapturing]
1644 {
1645 if (auto data = dataForCapturing.lock())
1646 {
1647 auto frameSrc = GetLocationUrl(*webBrowser);
1648 data->tab->OnDocumentComplete(webBrowser, frameSrc, data->webBrowser2.IsEq ualObject(webBrowser));
1649 }
1650 };
1651 if (FAILED(listenerImpl->Init(webBrowser, onListenerDestroy, onReloaded)))
1652 {
1653 return;
1654 }
1655 m_data->connectedWebBrowsersCache.emplace(webBrowser, listenerImpl);
1656 }
1657
1642 HICON CPluginClass::GetIcon(int type) 1658 HICON CPluginClass::GetIcon(int type)
1643 { 1659 {
1644 HICON icon = NULL; 1660 HICON icon = NULL;
1645 1661
1646 s_criticalSectionLocal.Lock(); 1662 s_criticalSectionLocal.Lock();
1647 { 1663 {
1648 if (!s_hIcons[type]) 1664 if (!s_hIcons[type])
1649 { 1665 {
1650 std::wstring imageToLoad = L"#"; 1666 std::wstring imageToLoad = L"#";
1651 imageToLoad += std::to_wstring(s_hIconTypes[type]); 1667 imageToLoad += std::to_wstring(s_hIconTypes[type]);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 s_criticalSectionLocal.Unlock(); 1744 s_criticalSectionLocal.Unlock();
1729 1745
1730 } 1746 }
1731 } 1747 }
1732 } 1748 }
1733 1749
1734 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1750 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1735 } 1751 }
1736 return hTabWnd; 1752 return hTabWnd;
1737 } 1753 }
OLDNEW

Powered by Google App Engine
This is Rietveld