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: rename OnQuit Created Sept. 30, 2016, 3:25 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/PluginDomTraverserBase.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 16 matching lines...) Expand all
290 { 291 {
291 DEBUG_GENERAL([this]() -> std::wstring 292 DEBUG_GENERAL([this]() -> std::wstring
292 { 293 {
293 std::wstringstream ss; 294 std::wstringstream ss;
294 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); 295 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
295 ss << L", browser = nullptr"; 296 ss << L", browser = nullptr";
296 return ss.str(); 297 return ss.str();
297 }()); 298 }());
298 299
299 Unadvise(); 300 Unadvise();
301 assert(m_data->connectedWebBrowsersCache.empty() && "Connected web browser cache should be already empty");
300 302
301 // Destroy window 303 // Destroy window
302 if (m_pWndProcStatus) 304 if (m_pWndProcStatus)
303 { 305 {
304 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus); 306 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus);
305 307
306 m_pWndProcStatus = NULL; 308 m_pWndProcStatus = NULL;
307 } 309 }
308 310
309 if (m_hPaneWnd) 311 if (m_hPaneWnd)
(...skipping 19 matching lines...) Expand all
329 s_threadInstances.erase(it); 331 s_threadInstances.erase(it);
330 } 332 }
331 if (s_instances.empty()) 333 if (s_instances.empty())
332 { 334 {
333 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 335 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
334 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 336 CPluginClientFactory::ReleaseMimeFilterClientInstance();
335 } 337 }
336 } 338 }
337 s_criticalSectionLocal.Unlock(); 339 s_criticalSectionLocal.Unlock();
338 340
339 m_webBrowser2 = nullptr; 341 m_data->webBrowser2 = nullptr;
340 342
341 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 343 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
342 344
343 ::CoUninitialize(); 345 ::CoUninitialize();
344 } 346 }
345 347
346 } 348 }
347 catch (...) 349 catch (...)
348 { 350 {
349 } 351 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; 481 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
480 if (!webBrowser) 482 if (!webBrowser)
481 { 483 {
482 return; 484 return;
483 } 485 }
484 if (!urlVariant || urlVariant->vt != VT_BSTR) 486 if (!urlVariant || urlVariant->vt != VT_BSTR)
485 { 487 {
486 return; 488 return;
487 } 489 }
488 std::wstring url = ToWstring(urlVariant->bstrVal); 490 std::wstring url = ToWstring(urlVariant->bstrVal);
491 EnsureWebBrowserConnected(webBrowser);
489 492
490 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 493 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
491 // navigating new page 494 // navigating new page
492 CPluginClient* client = CPluginClient::GetInstance(); 495 CPluginClient* client = CPluginClient::GetInstance();
493 if (url.find(L"javascript") == 0) 496 if (url.find(L"javascript") == 0)
494 { 497 {
495 } 498 }
496 else if (IsRootBrowser(webBrowser)) 499 else if (IsRootBrowser(webBrowser))
497 { 500 {
498 m_tab->OnNavigate(url); 501 m_data->tab->OnNavigate(url);
499 DEBUG_GENERAL( 502 DEBUG_GENERAL(
500 L"======================================================================== ========\n" 503 L"======================================================================== ========\n"
501 L"Begin main navigation url:" + url + L"\n" 504 L"Begin main navigation url:" + url + L"\n"
502 L"======================================================================== ========") 505 L"======================================================================== ========")
503 506
504 #ifdef ENABLE_DEBUG_RESULT 507 #ifdef ENABLE_DEBUG_RESULT
505 CPluginDebug::DebugResultDomain(url); 508 CPluginDebug::DebugResultDomain(url);
506 #endif 509 #endif
507 UpdateStatusBar(); 510 UpdateStatusBar();
508 } 511 }
509 else 512 else
510 { 513 {
511 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 514 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
512 m_tab->CacheFrame(url); 515 m_data->tab->CacheFrame(url);
513 } 516 }
514 } 517 }
515 catch (...) 518 catch (...)
516 { 519 {
517 } 520 }
518 } 521 }
519 522
520 // Entry point 523 // Entry point
521 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() 524 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
522 { 525 {
523 try 526 try
524 { 527 {
525 if (!m_webBrowser2) 528 if (!m_data->webBrowser2)
526 { 529 {
527 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with m_webBrowser2 == nullptr"); 530 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with webBrowser2 == nullptr");
528 return; 531 return;
529 } 532 }
530 DEBUG_NAVI(L"Navi::Download Complete") 533 DEBUG_NAVI(L"Navi::Download Complete")
531 m_tab->OnDownloadComplete(m_webBrowser2); 534 m_data->tab->OnDownloadComplete(m_data->webBrowser2);
532 } 535 }
533 catch (...) 536 catch (...)
534 { 537 {
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 } 538 }
555 } 539 }
556 540
557 // Entry point 541 // Entry point
558 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 542 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
559 { 543 {
560 try 544 try
561 { 545 {
562 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); 546 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)");
563 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED) 547 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED)
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 } 966 }
983 } 967 }
984 } 968 }
985 s_criticalSectionLocal.Unlock(); 969 s_criticalSectionLocal.Unlock();
986 970
987 return result; 971 return result;
988 } 972 }
989 973
990 CPluginTab* CPluginClass::GetTab() 974 CPluginTab* CPluginClass::GetTab()
991 { 975 {
992 return m_tab; 976 return m_data->tab.get();
993 } 977 }
994 978
995 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) 979 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId)
996 { 980 {
997 CPluginTab* tab = NULL; 981 CPluginTab* tab = NULL;
998 982
999 s_criticalSectionLocal.Lock(); 983 s_criticalSectionLocal.Lock();
1000 { 984 {
1001 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw ThreadId); 985 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw ThreadId);
1002 if (it != s_threadInstances.end()) 986 if (it != s_threadInstances.end())
1003 { 987 {
1004 tab = it->second->m_tab; 988 tab = it->second->m_data->tab.get();
1005 } 989 }
1006 } 990 }
1007 s_criticalSectionLocal.Unlock(); 991 s_criticalSectionLocal.Unlock();
1008 992
1009 return tab; 993 return tab;
1010 } 994 }
1011 995
1012 // Entry point 996 // Entry point
1013 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 997 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1014 { 998 {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 { 1223 {
1240 try 1224 try
1241 { 1225 {
1242 HWND hBrowserWnd = GetBrowserHWND(); 1226 HWND hBrowserWnd = GetBrowserHWND();
1243 if (!hBrowserWnd) 1227 if (!hBrowserWnd)
1244 { 1228 {
1245 return E_FAIL; 1229 return E_FAIL;
1246 } 1230 }
1247 1231
1248 // Create menu 1232 // Create menu
1249 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); 1233 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl());
1250 if (!hMenu) 1234 if (!hMenu)
1251 { 1235 {
1252 return E_FAIL; 1236 return E_FAIL;
1253 } 1237 }
1254 1238
1255 // Check if button in toolbar was pressed 1239 // Check if button in toolbar was pressed
1256 int nIDCommand = -1; 1240 int nIDCommand = -1;
1257 BOOL bRightAlign = FALSE; 1241 BOOL bRightAlign = FALSE;
1258 1242
1259 POINT pt; 1243 POINT pt;
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 if (m_hPaneWnd == NULL) 1639 if (m_hPaneWnd == NULL)
1656 { 1640 {
1657 CreateStatusBarPane(); 1641 CreateStatusBarPane();
1658 } 1642 }
1659 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1643 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1660 { 1644 {
1661 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1645 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1662 } 1646 }
1663 } 1647 }
1664 1648
1665
1666 void CPluginClass::Unadvise() 1649 void CPluginClass::Unadvise()
1667 { 1650 {
1668 if (!m_webBrowser2) 1651 if (!m_data->webBrowser2)
1669 { 1652 {
1670 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with m_webBrowser 2 == nullptr"); 1653 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with webBrowser2 == nullptr");
1671 return; 1654 return;
1672 } 1655 }
1673 s_criticalSectionLocal.Lock(); 1656 s_criticalSectionLocal.Lock();
1674 { 1657 {
1675 if (m_isAdvised) 1658 if (m_isAdvised)
1676 { 1659 {
1677 HRESULT hr = DispEventUnadvise(m_webBrowser2); 1660 HRESULT hr = DispEventUnadvise(m_data->webBrowser2);
1678 if (FAILED(hr)) 1661 if (FAILED(hr))
1679 { 1662 {
1680 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise"); 1663 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1681 } 1664 }
1682 m_isAdvised = false; 1665 m_isAdvised = false;
1683 } 1666 }
1684 } 1667 }
1685 s_criticalSectionLocal.Unlock(); 1668 s_criticalSectionLocal.Unlock();
1686 } 1669 }
1687 1670
1671 void CPluginClass::EnsureWebBrowserConnected(const ATL::CComPtr<IWebBrowser2>& w ebBrowser)
1672 {
1673 auto it = m_data->connectedWebBrowsersCache.find(webBrowser);
1674 if (it != m_data->connectedWebBrowsersCache.end())
1675 {
1676 return;
1677 }
1678 ATL::CComObject<WebBrowserEventsListener>* listenerImpl = nullptr;
1679 if (FAILED(ATL::CComObject<WebBrowserEventsListener>::CreateInstance(&listener Impl)))
1680 {
1681 return;
1682 }
1683 ATL::CComPtr<IUnknown> listenerRefCounterGuard(listenerImpl->GetUnknown());
1684 std::weak_ptr<Data> dataForCapturing = m_data;
1685 auto onListenerDestroy = [webBrowser, dataForCapturing]
1686 {
1687 if (auto data = dataForCapturing.lock())
1688 {
1689 data->connectedWebBrowsersCache.erase(webBrowser);
1690 }
1691 };
1692 auto onReloaded = [webBrowser, dataForCapturing]
1693 {
1694 if (auto data = dataForCapturing.lock())
1695 {
1696 auto frameSrc = GetLocationUrl(*webBrowser);
1697 data->tab->OnDocumentComplete(webBrowser, frameSrc, data->webBrowser2.IsEq ualObject(webBrowser));
1698 }
1699 };
1700 if (FAILED(listenerImpl->Init(webBrowser, onListenerDestroy, onReloaded)))
1701 {
1702 return;
1703 }
1704 m_data->connectedWebBrowsersCache.emplace(webBrowser, listenerImpl);
1705 }
1706
1688 HICON CPluginClass::GetIcon(int type) 1707 HICON CPluginClass::GetIcon(int type)
1689 { 1708 {
1690 HICON icon = NULL; 1709 HICON icon = NULL;
1691 1710
1692 s_criticalSectionLocal.Lock(); 1711 s_criticalSectionLocal.Lock();
1693 { 1712 {
1694 if (!s_hIcons[type]) 1713 if (!s_hIcons[type])
1695 { 1714 {
1696 std::wstring imageToLoad = L"#"; 1715 std::wstring imageToLoad = L"#";
1697 imageToLoad += std::to_wstring(s_hIconTypes[type]); 1716 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); 1717 s_hIcons[type] = (HICON)::LoadImage(_Module.m_hInst, imageToLoad.c_str(), IMAGE_ICON, iconWidth, iconHeight, LR_SHARED);
1699 if (!s_hIcons[type]) 1718 if (!s_hIcons[type])
1700 { 1719 {
1701 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon"); 1720 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon");
1702 } 1721 }
1703 } 1722 }
1704 1723
1705 icon = s_hIcons[type]; 1724 icon = s_hIcons[type];
1706 } 1725 }
1707 s_criticalSectionLocal.Unlock(); 1726 s_criticalSectionLocal.Unlock();
1708 1727
1709 return icon; 1728 return icon;
1710 } 1729 }
1711 1730
1712 ATOM CPluginClass::GetAtomPaneClass() 1731 ATOM CPluginClass::GetAtomPaneClass()
1713 { 1732 {
1714 return s_atomPaneClass; 1733 return s_atomPaneClass;
1715 } 1734 }
1716 1735
OLDNEW
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginDomTraverserBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld