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 Feb. 25, 2016, 5:38 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/PluginFilter.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 /* 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (right < left) 92 if (right < left)
92 { 93 {
93 throw std::runtime_error("invariant violation: rectangle right < left"); 94 throw std::runtime_error("invariant violation: rectangle right < left");
94 } 95 }
95 return static_cast<unsigned long>(right - left); 96 return static_cast<unsigned long>(right - left);
96 } 97 }
97 }; 98 };
98 } 99 }
99 100
100 CPluginClass::CPluginClass() 101 CPluginClass::CPluginClass()
101 : m_webBrowser2(nullptr) 102 : m_data(std::make_shared<Data>())
102 { 103 {
103 DEBUG_GENERAL([this]() -> std::wstring 104 DEBUG_GENERAL([this]() -> std::wstring
104 { 105 {
105 std::wstring s = L"CPluginClass::<constructor>, this = "; 106 std::wstring s = L"CPluginClass::<constructor>, this = ";
106 s += ToHexLiteral(this); 107 s += ToHexLiteral(this);
107 return s; 108 return s;
108 }()); 109 }());
109 110
110 //Use this line to debug memory leaks 111 //Use this line to debug memory leaks
111 // _CrtDumpMemoryLeaks(); 112 // _CrtDumpMemoryLeaks();
112 113
113 m_isAdvised = false; 114 m_isAdvised = false;
114 m_hTabWnd = NULL; 115 m_hTabWnd = NULL;
115 m_hStatusBarWnd = NULL; 116 m_hStatusBarWnd = NULL;
116 m_hPaneWnd = NULL; 117 m_hPaneWnd = NULL;
117 m_nPaneWidth = 0; 118 m_nPaneWidth = 0;
118 m_pWndProcStatus = NULL; 119 m_pWndProcStatus = NULL;
119 m_hTheme = NULL; 120 m_hTheme = NULL;
120 m_isInitializedOk = false; 121 m_isInitializedOk = false;
121 122
122 123
123 m_tab = new CPluginTab(); 124 m_data->tab.reset(new CPluginTab());
124 125
125 Dictionary::Create(GetBrowserLanguage()); 126 Dictionary::Create(GetBrowserLanguage());
126 } 127 }
127 128
128 CPluginClass::~CPluginClass() 129 CPluginClass::~CPluginClass()
129 { 130 {
130 DEBUG_GENERAL([this]() -> std::wstring 131 DEBUG_GENERAL([this]() -> std::wstring
131 { 132 {
132 std::wstring s = L"CPluginClass::<destructor>, this = "; 133 std::wstring s = L"CPluginClass::<destructor>, this = ";
133 s += ToHexLiteral(this); 134 s += ToHexLiteral(this);
134 return s; 135 return s;
135 }()); 136 }());
136 137
137 delete m_tab; 138 m_data.reset();
138 } 139 }
139 140
140 HWND CPluginClass::GetBrowserHWND() const 141 HWND CPluginClass::GetBrowserHWND() const
141 { 142 {
142 if (!m_webBrowser2) 143 if (!m_data->webBrowser2)
143 { 144 {
144 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr"); 145 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with webBro wser2 == nullptr");
145 return nullptr; 146 return nullptr;
146 } 147 }
147 SHANDLE_PTR hBrowserWndHandle = 0; 148 SHANDLE_PTR hBrowserWndHandle = 0;
148 HRESULT hr = m_webBrowser2->get_HWND(&hBrowserWndHandle); 149 HRESULT hr = m_data->webBrowser2->get_HWND(&hBrowserWndHandle);
149 if (FAILED(hr)) 150 if (FAILED(hr))
150 { 151 {
151 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed"); 152 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed");
152 return nullptr; 153 return nullptr;
153 } 154 }
154 return (HWND)hBrowserWndHandle; 155 return (HWND)hBrowserWndHandle;
155 } 156 }
156 157
157 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser) 158 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser)
158 { 159 {
159 return m_webBrowser2.IsEqualObject(otherBrowser); 160 return m_data->webBrowser2.IsEqualObject(otherBrowser);
160 } 161 }
161 162
162 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() 163 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
163 { 164 {
164 CComQIPtr<IWebBrowser2> browser; 165 CComQIPtr<IWebBrowser2> browser;
165 166
166 s_criticalSectionLocal.Lock(); 167 s_criticalSectionLocal.Lock();
167 { 168 {
168 browser = s_asyncWebBrowser2; 169 browser = s_asyncWebBrowser2;
169 } 170 }
170 s_criticalSectionLocal.Unlock(); 171 s_criticalSectionLocal.Unlock();
171 172
172 return browser; 173 return browser;
173 } 174 }
174 175
175 std::wstring CPluginClass::GetBrowserUrl() const 176 std::wstring CPluginClass::GetBrowserUrl() const
176 { 177 {
177 std::wstring url; 178 std::wstring url;
178 if (m_webBrowser2) 179 if (m_data->webBrowser2)
179 { 180 {
180 CComBSTR bstrURL; 181 CComBSTR bstrURL;
181 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL))) 182 if (SUCCEEDED(m_data->webBrowser2->get_LocationURL(&bstrURL)))
182 { 183 {
183 url = ToWstring(bstrURL); 184 url = ToWstring(bstrURL);
184 } 185 }
185 } 186 }
186 else 187 else
187 { 188 {
188 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with m_webBrowser2 == nullptr (probable invariant violation)"); 189 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with webBrowser2 == nu llptr (probable invariant violation)");
189 } 190 }
190 if (url.empty()) 191 if (url.empty())
191 { 192 {
192 url = m_tab->GetDocumentUrl(); 193 url = m_data->tab->GetDocumentUrl();
193 } 194 }
194 return url; 195 return url;
195 } 196 }
196 197
197 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 198 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
198 { 199 {
199 if (thisPtr == NULL) 200 if (thisPtr == NULL)
200 return 0; 201 return 0;
201 if (!((CPluginClass*)thisPtr)->InitObject()) 202 if (!((CPluginClass*)thisPtr)->InitObject())
202 { 203 {
(...skipping 23 matching lines...) Expand all
226 227
227 HRESULT hr = ::CoInitialize(NULL); 228 HRESULT hr = ::CoInitialize(NULL);
228 if (FAILED(hr)) 229 if (FAILED(hr))
229 { 230 {
230 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 231 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
231 } 232 }
232 233
233 /* 234 /*
234 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2. 235 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2.
235 */ 236 */
236 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); 237 m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite);
237 if (!m_webBrowser2) 238 if (!m_data->webBrowser2)
238 { 239 {
239 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*"); 240 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*");
240 } 241 }
241 DEBUG_GENERAL([this]() -> std::wstring 242 DEBUG_GENERAL([this]() -> std::wstring
242 { 243 {
243 std::wstringstream ss; 244 std::wstringstream ss;
244 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); 245 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
245 ss << L", browser = " << ToHexLiteral(m_webBrowser2); 246 ss << L", browser = " << ToHexLiteral(m_data->webBrowser2);
246 return ss.str(); 247 return ss.str();
247 }()); 248 }());
248 249
249 //register the mimefilter 250 //register the mimefilter
250 //and only mimefilter 251 //and only mimefilter
251 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 252 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
252 s_criticalSectionLocal.Lock(); 253 s_criticalSectionLocal.Lock();
253 { 254 {
254 // Always register on startup, then check if we need to unregister in a separate thread 255 // Always register on startup, then check if we need to unregister in a separate thread
255 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 256 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
256 s_asyncWebBrowser2 = unknownSite; 257 s_asyncWebBrowser2 = unknownSite;
257 s_instances.insert(this); 258 s_instances.insert(this);
258 } 259 }
259 s_criticalSectionLocal.Unlock(); 260 s_criticalSectionLocal.Unlock();
260 261
261 try 262 try
262 { 263 {
263 HRESULT hr = DispEventAdvise(m_webBrowser2); 264 HRESULT hr = DispEventAdvise(m_data->webBrowser2);
264 if (SUCCEEDED(hr)) 265 if (SUCCEEDED(hr))
265 { 266 {
266 m_isAdvised = true; 267 m_isAdvised = true;
267 try 268 try
268 { 269 {
269 std::thread startInitObjectThread(StartInitObject, this); 270 std::thread startInitObjectThread(StartInitObject, this);
270 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr. 271 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
271 } 272 }
272 catch (const std::system_error& ex) 273 catch (const std::system_error& ex)
273 { 274 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 s_threadInstances.erase(it); 330 s_threadInstances.erase(it);
330 } 331 }
331 if (s_instances.empty()) 332 if (s_instances.empty())
332 { 333 {
333 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 334 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
334 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 335 CPluginClientFactory::ReleaseMimeFilterClientInstance();
335 } 336 }
336 } 337 }
337 s_criticalSectionLocal.Unlock(); 338 s_criticalSectionLocal.Unlock();
338 339
339 m_webBrowser2 = nullptr; 340 m_data->webBrowser2 = nullptr;
340 341
341 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 342 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
342 343
343 ::CoUninitialize(); 344 ::CoUninitialize();
344 } 345 }
345 346
346 } 347 }
347 catch (...) 348 catch (...)
348 { 349 {
349 } 350 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; 480 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
480 if (!webBrowser) 481 if (!webBrowser)
481 { 482 {
482 return; 483 return;
483 } 484 }
484 if (!urlVariant || urlVariant->vt != VT_BSTR) 485 if (!urlVariant || urlVariant->vt != VT_BSTR)
485 { 486 {
486 return; 487 return;
487 } 488 }
488 std::wstring url = ToWstring(urlVariant->bstrVal); 489 std::wstring url = ToWstring(urlVariant->bstrVal);
490 EnsureWebBrowserConnected(webBrowser);
489 491
490 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 492 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
491 // navigating new page 493 // navigating new page
492 CPluginClient* client = CPluginClient::GetInstance(); 494 CPluginClient* client = CPluginClient::GetInstance();
493 if (url.find(L"javascript") == 0) 495 if (url.find(L"javascript") == 0)
494 { 496 {
495 } 497 }
496 else if (IsRootBrowser(webBrowser)) 498 else if (IsRootBrowser(webBrowser))
497 { 499 {
498 m_tab->OnNavigate(url); 500 m_data->tab->OnNavigate(url);
499 DEBUG_GENERAL( 501 DEBUG_GENERAL(
500 L"======================================================================== ========\n" 502 L"======================================================================== ========\n"
501 L"Begin main navigation url:" + url + L"\n" 503 L"Begin main navigation url:" + url + L"\n"
502 L"======================================================================== ========") 504 L"======================================================================== ========")
503 505
504 #ifdef ENABLE_DEBUG_RESULT 506 #ifdef ENABLE_DEBUG_RESULT
505 CPluginDebug::DebugResultDomain(url); 507 CPluginDebug::DebugResultDomain(url);
506 #endif 508 #endif
507 UpdateStatusBar(); 509 UpdateStatusBar();
508 } 510 }
509 else 511 else
510 { 512 {
511 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 513 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
512 m_tab->CacheFrame(url); 514 m_data->tab->CacheFrame(url);
513 } 515 }
514 } 516 }
515 catch (...) 517 catch (...)
516 { 518 {
517 } 519 }
518 } 520 }
519 521
520 // Entry point 522 // Entry point
521 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() 523 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
522 { 524 {
523 try 525 try
524 { 526 {
525 if (!m_webBrowser2) 527 if (!m_data->webBrowser2)
526 { 528 {
527 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with m_webBrowser2 == nullptr"); 529 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with webBrowser2 == nullptr");
528 return; 530 return;
529 } 531 }
530 DEBUG_NAVI(L"Navi::Download Complete") 532 DEBUG_NAVI(L"Navi::Download Complete")
531 m_tab->OnDownloadComplete(m_webBrowser2); 533 m_data->tab->OnDownloadComplete(m_data->webBrowser2);
532 } 534 }
533 catch (...) 535 catch (...)
534 { 536 {
535 }
536 }
537
538 // Entry point
539 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
540 {
541 try
542 {
543 DEBUG_NAVI(L"Navi::Document Complete");
544 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
545 if (!webBrowser2)
546 {
547 return;
548 }
549 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
550 m_tab->OnDocumentComplete(webBrowser2, frameSrc, IsRootBrowser(webBrowser2)) ;
551 }
552 catch (...)
553 {
554 } 537 }
555 } 538 }
556 539
557 // Entry point 540 // Entry point
558 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 541 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
559 { 542 {
560 try 543 try
561 { 544 {
562 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); 545 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)");
563 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED) 546 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED)
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 } 965 }
983 } 966 }
984 } 967 }
985 s_criticalSectionLocal.Unlock(); 968 s_criticalSectionLocal.Unlock();
986 969
987 return result; 970 return result;
988 } 971 }
989 972
990 CPluginTab* CPluginClass::GetTab() 973 CPluginTab* CPluginClass::GetTab()
991 { 974 {
992 return m_tab; 975 return m_data->tab.get();
993 } 976 }
994 977
995 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) 978 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId)
996 { 979 {
997 CPluginTab* tab = NULL; 980 CPluginTab* tab = NULL;
998 981
999 s_criticalSectionLocal.Lock(); 982 s_criticalSectionLocal.Lock();
1000 { 983 {
1001 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw ThreadId); 984 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw ThreadId);
1002 if (it != s_threadInstances.end()) 985 if (it != s_threadInstances.end())
1003 { 986 {
1004 tab = it->second->m_tab; 987 tab = it->second->m_data->tab.get();
1005 } 988 }
1006 } 989 }
1007 s_criticalSectionLocal.Unlock(); 990 s_criticalSectionLocal.Unlock();
1008 991
1009 return tab; 992 return tab;
1010 } 993 }
1011 994
1012 // Entry point 995 // Entry point
1013 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 996 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1014 { 997 {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 { 1222 {
1240 try 1223 try
1241 { 1224 {
1242 HWND hBrowserWnd = GetBrowserHWND(); 1225 HWND hBrowserWnd = GetBrowserHWND();
1243 if (!hBrowserWnd) 1226 if (!hBrowserWnd)
1244 { 1227 {
1245 return E_FAIL; 1228 return E_FAIL;
1246 } 1229 }
1247 1230
1248 // Create menu 1231 // Create menu
1249 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); 1232 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl());
1250 if (!hMenu) 1233 if (!hMenu)
1251 { 1234 {
1252 return E_FAIL; 1235 return E_FAIL;
1253 } 1236 }
1254 1237
1255 // Check if button in toolbar was pressed 1238 // Check if button in toolbar was pressed
1256 int nIDCommand = -1; 1239 int nIDCommand = -1;
1257 BOOL bRightAlign = FALSE; 1240 BOOL bRightAlign = FALSE;
1258 1241
1259 POINT pt; 1242 POINT pt;
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 if (m_hPaneWnd == NULL) 1638 if (m_hPaneWnd == NULL)
1656 { 1639 {
1657 CreateStatusBarPane(); 1640 CreateStatusBarPane();
1658 } 1641 }
1659 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1642 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1660 { 1643 {
1661 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1644 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1662 } 1645 }
1663 } 1646 }
1664 1647
1665
1666 void CPluginClass::Unadvise() 1648 void CPluginClass::Unadvise()
1667 { 1649 {
1668 if (!m_webBrowser2) 1650 if (!m_data->webBrowser2)
1669 { 1651 {
1670 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with m_webBrowser 2 == nullptr"); 1652 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with webBrowser2 == nullptr");
1671 return; 1653 return;
1672 } 1654 }
1673 s_criticalSectionLocal.Lock(); 1655 s_criticalSectionLocal.Lock();
1674 { 1656 {
1675 if (m_isAdvised) 1657 if (m_isAdvised)
1676 { 1658 {
1677 HRESULT hr = DispEventUnadvise(m_webBrowser2); 1659 HRESULT hr = DispEventUnadvise(m_data->webBrowser2);
1678 if (FAILED(hr)) 1660 if (FAILED(hr))
1679 { 1661 {
1680 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise"); 1662 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1681 } 1663 }
1682 m_isAdvised = false; 1664 m_isAdvised = false;
1683 } 1665 }
1684 } 1666 }
1685 s_criticalSectionLocal.Unlock(); 1667 s_criticalSectionLocal.Unlock();
1686 } 1668 }
1687 1669
1670 void CPluginClass::EnsureWebBrowserConnected(const ATL::CComPtr<IWebBrowser2>& w ebBrowser)
1671 {
1672 auto it = m_data->connectedWebBrowsersCache.find(webBrowser);
1673 if (it != m_data->connectedWebBrowsersCache.end())
1674 {
1675 return;
1676 }
1677 ATL::CComObject<WebBrowserEventsListener>* listenerImpl = nullptr;
1678 if (FAILED(ATL::CComObject<WebBrowserEventsListener>::CreateInstance(&listener Impl)))
1679 {
1680 return;
1681 }
1682 ATL::CComPtr<IUnknown> listenerRefCounterGuard(listenerImpl->GetUnknown());
1683 std::weak_ptr<Data> dataForCapturing = m_data;
1684 auto onListenerDestroy = [webBrowser, dataForCapturing]
1685 {
1686 if (auto data = dataForCapturing.lock())
1687 {
1688 data->connectedWebBrowsersCache.erase(webBrowser);
1689 }
1690 };
1691 auto onReloaded = [webBrowser, dataForCapturing]
1692 {
1693 if (auto data = dataForCapturing.lock())
1694 {
1695 auto frameSrc = GetLocationUrl(*webBrowser);
1696 data->tab->OnDocumentComplete(webBrowser, frameSrc, data->webBrowser2.IsEq ualObject(webBrowser));
1697 }
1698 };
1699 if (FAILED(listenerImpl->Init(webBrowser, onListenerDestroy, onReloaded)))
1700 {
1701 return;
1702 }
1703 m_data->connectedWebBrowsersCache.emplace(webBrowser, listenerImpl);
1704 }
1705
1688 HICON CPluginClass::GetIcon(int type) 1706 HICON CPluginClass::GetIcon(int type)
1689 { 1707 {
1690 HICON icon = NULL; 1708 HICON icon = NULL;
1691 1709
1692 s_criticalSectionLocal.Lock(); 1710 s_criticalSectionLocal.Lock();
1693 { 1711 {
1694 if (!s_hIcons[type]) 1712 if (!s_hIcons[type])
1695 { 1713 {
1696 std::wstring imageToLoad = L"#"; 1714 std::wstring imageToLoad = L"#";
1697 imageToLoad += std::to_wstring(s_hIconTypes[type]); 1715 imageToLoad += std::to_wstring(s_hIconTypes[type]);
1698 s_hIcons[type] = (HICON)::LoadImage(_Module.m_hInst, imageToLoad.c_str(), IMAGE_ICON, iconWidth, iconHeight, LR_SHARED); 1716 s_hIcons[type] = (HICON)::LoadImage(_Module.m_hInst, imageToLoad.c_str(), IMAGE_ICON, iconWidth, iconHeight, LR_SHARED);
1699 if (!s_hIcons[type]) 1717 if (!s_hIcons[type])
1700 { 1718 {
1701 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon"); 1719 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon");
1702 } 1720 }
1703 } 1721 }
1704 1722
1705 icon = s_hIcons[type]; 1723 icon = s_hIcons[type];
1706 } 1724 }
1707 s_criticalSectionLocal.Unlock(); 1725 s_criticalSectionLocal.Unlock();
1708 1726
1709 return icon; 1727 return icon;
1710 } 1728 }
1711 1729
1712 ATOM CPluginClass::GetAtomPaneClass() 1730 ATOM CPluginClass::GetAtomPaneClass()
1713 { 1731 {
1714 return s_atomPaneClass; 1732 return s_atomPaneClass;
1715 } 1733 }
1716 1734
OLDNEW
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld