OLD | NEW |
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 Loading... |
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 Loading... |
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(); |
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 15 matching lines...) Expand all Loading... |
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 UnescapeUrl(url); | 190 UnescapeUrl(url); |
192 } | 191 } |
193 } | 192 } |
194 else | 193 else |
195 { | 194 { |
196 url = m_tab->GetDocumentUrl(); | 195 url = m_data->tab->GetDocumentUrl(); |
197 } | 196 } |
198 return url; | 197 return url; |
199 } | 198 } |
200 | 199 |
201 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
202 { | 201 { |
203 if (thisPtr == NULL) | 202 if (thisPtr == NULL) |
204 return 0; | 203 return 0; |
205 if (!((CPluginClass*)thisPtr)->InitObject()) | 204 if (!((CPluginClass*)thisPtr)->InitObject()) |
206 { | 205 { |
(...skipping 23 matching lines...) Expand all Loading... |
230 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
====================================") | 229 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
====================================") |
231 | 230 |
232 HRESULT hr = ::CoInitialize(NULL); | 231 HRESULT hr = ::CoInitialize(NULL); |
233 if (FAILED(hr)) | 232 if (FAILED(hr)) |
234 { | 233 { |
235 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
"Class::SetSite - CoInitialize"); | 234 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
"Class::SetSite - CoInitialize"); |
236 } | 235 } |
237 | 236 |
238 s_criticalSectionBrowser.Lock(); | 237 s_criticalSectionBrowser.Lock(); |
239 { | 238 { |
240 m_webBrowser2 = unknownSite; | 239 m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); |
241 } | 240 } |
242 s_criticalSectionBrowser.Unlock(); | 241 s_criticalSectionBrowser.Unlock(); |
243 | 242 |
244 //register the mimefilter | 243 //register the mimefilter |
245 //and only mimefilter | 244 //and only mimefilter |
246 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread | 245 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread |
247 | 246 |
248 s_criticalSectionLocal.Lock(); | 247 s_criticalSectionLocal.Lock(); |
249 { | 248 { |
250 // Always register on startup, then check if we need to unregister in a
separate thread | 249 // 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 Loading... |
325 { | 324 { |
326 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr | 325 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr |
327 CPluginClientFactory::ReleaseMimeFilterClientInstance(); | 326 CPluginClientFactory::ReleaseMimeFilterClientInstance(); |
328 } | 327 } |
329 } | 328 } |
330 s_criticalSectionLocal.Unlock(); | 329 s_criticalSectionLocal.Unlock(); |
331 | 330 |
332 // Release browser interface | 331 // Release browser interface |
333 s_criticalSectionBrowser.Lock(); | 332 s_criticalSectionBrowser.Lock(); |
334 { | 333 { |
335 m_webBrowser2.Release(); | 334 m_data->webBrowser2.Release(); |
336 } | 335 } |
337 s_criticalSectionBrowser.Unlock(); | 336 s_criticalSectionBrowser.Unlock(); |
338 | 337 |
339 DEBUG_GENERAL("===========================================================
=====================\nNEW TAB UI - END\n=======================================
=========================================") | 338 DEBUG_GENERAL("===========================================================
=====================\nNEW TAB UI - END\n=======================================
=========================================") |
340 | 339 |
341 ::CoUninitialize(); | 340 ::CoUninitialize(); |
342 } | 341 } |
343 | 342 |
344 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); | 343 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); |
345 } | 344 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (!webBrowser) | 477 if (!webBrowser) |
479 { | 478 { |
480 return; | 479 return; |
481 } | 480 } |
482 if (!urlVariant || urlVariant->vt != VT_BSTR) | 481 if (!urlVariant || urlVariant->vt != VT_BSTR) |
483 { | 482 { |
484 return; | 483 return; |
485 } | 484 } |
486 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); | 485 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); |
487 UnescapeUrl(url); | 486 UnescapeUrl(url); |
| 487 EnsureWebBrowserConnected(webBrowser); |
488 | 488 |
489 // If webbrowser2 is equal to top level browser (as set in SetSite), we are | 489 // If webbrowser2 is equal to top level browser (as set in SetSite), we are |
490 // navigating new page | 490 // navigating new page |
491 CPluginClient* client = CPluginClient::GetInstance(); | 491 CPluginClient* client = CPluginClient::GetInstance(); |
492 if (url.find(L"javascript") == 0) | 492 if (url.find(L"javascript") == 0) |
493 { | 493 { |
494 } | 494 } |
495 else if (GetBrowser().IsEqualObject(webBrowser)) | 495 else if (GetBrowser().IsEqualObject(webBrowser)) |
496 { | 496 { |
497 m_tab->OnNavigate(url); | 497 m_data->tab->OnNavigate(url); |
498 DEBUG_GENERAL( | 498 DEBUG_GENERAL( |
499 L"========================================================================
========\n" | 499 L"========================================================================
========\n" |
500 L"Begin main navigation url:" + url + L"\n" | 500 L"Begin main navigation url:" + url + L"\n" |
501 L"========================================================================
========") | 501 L"========================================================================
========") |
502 | 502 |
503 #ifdef ENABLE_DEBUG_RESULT | 503 #ifdef ENABLE_DEBUG_RESULT |
504 CPluginDebug::DebugResultDomain(url); | 504 CPluginDebug::DebugResultDomain(url); |
505 #endif | 505 #endif |
506 UpdateStatusBar(); | 506 UpdateStatusBar(); |
507 } | 507 } |
508 else | 508 else |
509 { | 509 { |
510 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) | 510 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) |
511 m_tab->CacheFrame(url); | 511 m_data->tab->CacheFrame(url); |
512 } | 512 } |
513 } | 513 } |
514 catch (...) | 514 catch (...) |
515 { | 515 { |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 // Entry point | 519 // Entry point |
520 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() | 520 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() |
521 { | 521 { |
522 try | 522 try |
523 { | 523 { |
524 DEBUG_NAVI(L"Navi::Download Complete") | 524 DEBUG_NAVI(L"Navi::Download Complete") |
525 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); | 525 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); |
526 if (browser) | 526 if (browser) |
527 { | 527 { |
528 m_tab->OnDownloadComplete(browser); | 528 m_data->tab->OnDownloadComplete(browser); |
529 } | 529 } |
530 } | 530 } |
531 catch (...) | 531 catch (...) |
532 { | 532 { |
533 } | |
534 } | |
535 | |
536 // Entry point | |
537 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD
isp, VARIANT* /*urlOrPidl*/) | |
538 { | |
539 try | |
540 { | |
541 DEBUG_NAVI(L"Navi::Document Complete"); | |
542 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; | |
543 if (!webBrowser2) | |
544 { | |
545 return; | |
546 } | |
547 std::wstring frameSrc = GetLocationUrl(*webBrowser2); | |
548 UnescapeUrl(frameSrc); | |
549 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); | |
550 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser); | |
551 } | |
552 catch (...) | |
553 { | |
554 } | 533 } |
555 } | 534 } |
556 | 535 |
557 // Entry point | 536 // Entry point |
558 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) | 537 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) |
559 { | 538 { |
560 try | 539 try |
561 { | 540 { |
562 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); | 541 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); |
563 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) | 542 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 } | 959 } |
981 } | 960 } |
982 } | 961 } |
983 s_criticalSectionLocal.Unlock(); | 962 s_criticalSectionLocal.Unlock(); |
984 | 963 |
985 return result; | 964 return result; |
986 } | 965 } |
987 | 966 |
988 CPluginTab* CPluginClass::GetTab() | 967 CPluginTab* CPluginClass::GetTab() |
989 { | 968 { |
990 return m_tab; | 969 return m_data->tab.get(); |
991 } | 970 } |
992 | 971 |
993 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) | 972 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) |
994 { | 973 { |
995 CPluginTab* tab = NULL; | 974 CPluginTab* tab = NULL; |
996 | 975 |
997 s_criticalSectionLocal.Lock(); | 976 s_criticalSectionLocal.Lock(); |
998 { | 977 { |
999 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw
ThreadId); | 978 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw
ThreadId); |
1000 if (it != s_threadInstances.end()) | 979 if (it != s_threadInstances.end()) |
1001 { | 980 { |
1002 tab = it->second->m_tab; | 981 tab = it->second->m_data->tab.get(); |
1003 } | 982 } |
1004 } | 983 } |
1005 s_criticalSectionLocal.Unlock(); | 984 s_criticalSectionLocal.Unlock(); |
1006 | 985 |
1007 return tab; | 986 return tab; |
1008 } | 987 } |
1009 | 988 |
1010 | 989 |
1011 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) | 990 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) |
1012 { | 991 { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 | 1199 |
1221 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) | 1200 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) |
1222 { | 1201 { |
1223 HWND hBrowserWnd = GetBrowserHWND(); | 1202 HWND hBrowserWnd = GetBrowserHWND(); |
1224 if (!hBrowserWnd) | 1203 if (!hBrowserWnd) |
1225 { | 1204 { |
1226 return E_FAIL; | 1205 return E_FAIL; |
1227 } | 1206 } |
1228 | 1207 |
1229 // Create menu | 1208 // Create menu |
1230 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); | 1209 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl()); |
1231 if (!hMenu) | 1210 if (!hMenu) |
1232 { | 1211 { |
1233 return E_FAIL; | 1212 return E_FAIL; |
1234 } | 1213 } |
1235 | 1214 |
1236 // Check if button in toolbar was pressed | 1215 // Check if button in toolbar was pressed |
1237 int nIDCommand = -1; | 1216 int nIDCommand = -1; |
1238 BOOL bRightAlign = FALSE; | 1217 BOOL bRightAlign = FALSE; |
1239 | 1218 |
1240 POINT pt; | 1219 POINT pt; |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 if (m_hPaneWnd == NULL) | 1597 if (m_hPaneWnd == NULL) |
1619 { | 1598 { |
1620 CreateStatusBarPane(); | 1599 CreateStatusBarPane(); |
1621 } | 1600 } |
1622 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) | 1601 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) |
1623 { | 1602 { |
1624 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
ATE_STATUSBAR, "Class::Invalidate statusbar"); | 1603 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
ATE_STATUSBAR, "Class::Invalidate statusbar"); |
1625 } | 1604 } |
1626 } | 1605 } |
1627 | 1606 |
1628 | |
1629 void CPluginClass::Unadvise() | 1607 void CPluginClass::Unadvise() |
1630 { | 1608 { |
1631 s_criticalSectionLocal.Lock(); | 1609 s_criticalSectionLocal.Lock(); |
1632 { | 1610 { |
1633 if (m_isAdvised) | 1611 if (m_isAdvised) |
1634 { | 1612 { |
1635 HRESULT hr = DispEventUnadvise(GetBrowser()); | 1613 HRESULT hr = DispEventUnadvise(GetBrowser()); |
1636 if (FAILED(hr)) | 1614 if (FAILED(hr)) |
1637 { | 1615 { |
1638 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS
E, "Class::Unadvise - Unadvise"); | 1616 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS
E, "Class::Unadvise - Unadvise"); |
1639 } | 1617 } |
1640 m_isAdvised = false; | 1618 m_isAdvised = false; |
1641 } | 1619 } |
1642 } | 1620 } |
1643 s_criticalSectionLocal.Unlock(); | 1621 s_criticalSectionLocal.Unlock(); |
1644 } | 1622 } |
1645 | 1623 |
| 1624 void CPluginClass::EnsureWebBrowserConnected(const ATL::CComPtr<IWebBrowser2>& w
ebBrowser) |
| 1625 { |
| 1626 auto it = m_data->connectedWebBrowsersCache.find(webBrowser); |
| 1627 if (it != m_data->connectedWebBrowsersCache.end()) |
| 1628 { |
| 1629 return; |
| 1630 } |
| 1631 ATL::CComObject<WebBrowserEventsListener>* listenerImpl = nullptr; |
| 1632 if (FAILED(ATL::CComObject<WebBrowserEventsListener>::CreateInstance(&listener
Impl))) |
| 1633 { |
| 1634 return; |
| 1635 } |
| 1636 ATL::CComPtr<IUnknown> listenerRefCounterGuard(listenerImpl->GetUnknown()); |
| 1637 std::weak_ptr<Data> dataForCapturing = m_data; |
| 1638 auto onListenerDestroy = [webBrowser, dataForCapturing] |
| 1639 { |
| 1640 if (auto data = dataForCapturing.lock()) |
| 1641 { |
| 1642 data->connectedWebBrowsersCache.erase(webBrowser); |
| 1643 } |
| 1644 }; |
| 1645 auto onReloaded = [webBrowser, dataForCapturing] |
| 1646 { |
| 1647 if (auto data = dataForCapturing.lock()) |
| 1648 { |
| 1649 auto frameSrc = GetLocationUrl(*webBrowser); |
| 1650 UnescapeUrl(frameSrc); |
| 1651 data->tab->OnDocumentComplete(webBrowser, frameSrc, data->webBrowser2.IsEq
ualObject(webBrowser)); |
| 1652 } |
| 1653 }; |
| 1654 if (FAILED(listenerImpl->Init(webBrowser, onListenerDestroy, onReloaded))) |
| 1655 { |
| 1656 return; |
| 1657 } |
| 1658 m_data->connectedWebBrowsersCache.emplace(webBrowser, listenerImpl); |
| 1659 } |
| 1660 |
1646 HICON CPluginClass::GetIcon(int type) | 1661 HICON CPluginClass::GetIcon(int type) |
1647 { | 1662 { |
1648 HICON icon = NULL; | 1663 HICON icon = NULL; |
1649 | 1664 |
1650 s_criticalSectionLocal.Lock(); | 1665 s_criticalSectionLocal.Lock(); |
1651 { | 1666 { |
1652 if (!s_hIcons[type]) | 1667 if (!s_hIcons[type]) |
1653 { | 1668 { |
1654 std::wstring imageToLoad = L"#"; | 1669 std::wstring imageToLoad = L"#"; |
1655 imageToLoad += std::to_wstring(s_hIconTypes[type]); | 1670 imageToLoad += std::to_wstring(s_hIconTypes[type]); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 s_criticalSectionLocal.Unlock(); | 1747 s_criticalSectionLocal.Unlock(); |
1733 | 1748 |
1734 } | 1749 } |
1735 } | 1750 } |
1736 } | 1751 } |
1737 | 1752 |
1738 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 1753 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |
1739 } | 1754 } |
1740 return hTabWnd; | 1755 return hTabWnd; |
1741 } | 1756 } |
OLD | NEW |