| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 int Width() const | 85 int Width() const |
| 86 { | 86 { |
| 87 return right - left; | 87 return right - left; |
| 88 } | 88 } |
| 89 }; | 89 }; |
| 90 } | 90 } |
| 91 | 91 |
| 92 CPluginClass::CPluginClass() | 92 CPluginClass::CPluginClass() |
| 93 : m_webBrowser2(nullptr) | 93 : m_webBrowser2(nullptr) |
| 94 { | 94 { |
| 95 DEBUG_GENERAL([this]() -> std::wstring |
| 96 { |
| 97 std::wstring s = L"CPluginClass::<constructor>, this = "; |
| 98 s += ToHexLiteral(this); |
| 99 return s; |
| 100 }()); |
| 101 |
| 95 //Use this line to debug memory leaks | 102 //Use this line to debug memory leaks |
| 96 // _CrtDumpMemoryLeaks(); | 103 // _CrtDumpMemoryLeaks(); |
| 97 | 104 |
| 98 m_isAdvised = false; | 105 m_isAdvised = false; |
| 99 m_hTabWnd = NULL; | 106 m_hTabWnd = NULL; |
| 100 m_hStatusBarWnd = NULL; | 107 m_hStatusBarWnd = NULL; |
| 101 m_hPaneWnd = NULL; | 108 m_hPaneWnd = NULL; |
| 102 m_nPaneWidth = 0; | 109 m_nPaneWidth = 0; |
| 103 m_pWndProcStatus = NULL; | 110 m_pWndProcStatus = NULL; |
| 104 m_hTheme = NULL; | 111 m_hTheme = NULL; |
| 105 m_isInitializedOk = false; | 112 m_isInitializedOk = false; |
| 106 | 113 |
| 107 | 114 |
| 108 m_tab = new CPluginTab(this); | 115 m_tab = new CPluginTab(this); |
| 109 | 116 |
| 110 Dictionary::Create(GetBrowserLanguage()); | 117 Dictionary::Create(GetBrowserLanguage()); |
| 111 } | 118 } |
| 112 | 119 |
| 113 CPluginClass::~CPluginClass() | 120 CPluginClass::~CPluginClass() |
| 114 { | 121 { |
| 122 DEBUG_GENERAL([this]() -> std::wstring |
| 123 { |
| 124 std::wstring s = L"CPluginClass::<destructor>, this = "; |
| 125 s += ToHexLiteral(this); |
| 126 return s; |
| 127 }()); |
| 128 |
| 115 delete m_tab; | 129 delete m_tab; |
| 116 } | 130 } |
| 117 | 131 |
| 118 HWND CPluginClass::GetBrowserHWND() const | 132 HWND CPluginClass::GetBrowserHWND() const |
| 119 { | 133 { |
| 120 if (!m_webBrowser2) | 134 if (!m_webBrowser2) |
| 121 { | 135 { |
| 122 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB
rowser2 == nullptr"); | 136 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB
rowser2 == nullptr"); |
| 123 return nullptr; | 137 return nullptr; |
| 124 } | 138 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w
hen IE | 204 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w
hen IE |
| 191 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru
ctor, | 205 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru
ctor, |
| 192 * but it is not a proper substitute for one. | 206 * but it is not a proper substitute for one. |
| 193 */ | 207 */ |
| 194 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) | 208 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) |
| 195 { | 209 { |
| 196 try | 210 try |
| 197 { | 211 { |
| 198 if (unknownSite) | 212 if (unknownSite) |
| 199 { | 213 { |
| 200 | 214 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
===================================="); |
| 201 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
====================================") | |
| 202 | 215 |
| 203 HRESULT hr = ::CoInitialize(NULL); | 216 HRESULT hr = ::CoInitialize(NULL); |
| 204 if (FAILED(hr)) | 217 if (FAILED(hr)) |
| 205 { | 218 { |
| 206 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
"Class::SetSite - CoInitialize"); | 219 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
"Class::SetSite - CoInitialize"); |
| 207 } | 220 } |
| 208 | 221 |
| 209 /* | 222 /* |
| 210 * We were instantiated as a BHO, so our site is always of type IWebBrowse
r2. | 223 * We were instantiated as a BHO, so our site is always of type IWebBrowse
r2. |
| 211 */ | 224 */ |
| 212 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); | 225 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); |
| 213 if (!m_webBrowser2) | 226 if (!m_webBrowser2) |
| 214 { | 227 { |
| 215 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p
ointer to IWebBrowser2*"); | 228 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p
ointer to IWebBrowser2*"); |
| 216 } | 229 } |
| 230 DEBUG_GENERAL([this]() -> std::wstring |
| 231 { |
| 232 std::wstringstream ss; |
| 233 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); |
| 234 ss << L", browser = " << ToHexLiteral(m_webBrowser2); |
| 235 return ss.str(); |
| 236 }()); |
| 217 | 237 |
| 218 //register the mimefilter | 238 //register the mimefilter |
| 219 //and only mimefilter | 239 //and only mimefilter |
| 220 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread | 240 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread |
| 221 s_criticalSectionLocal.Lock(); | 241 s_criticalSectionLocal.Lock(); |
| 222 { | 242 { |
| 223 // Always register on startup, then check if we need to unregister in a
separate thread | 243 // Always register on startup, then check if we need to unregister in a
separate thread |
| 224 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 244 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
| 225 s_asyncWebBrowser2 = unknownSite; | 245 s_asyncWebBrowser2 = unknownSite; |
| 226 s_instances.insert(this); | 246 s_instances.insert(this); |
| 227 } | 247 } |
| 228 s_criticalSectionLocal.Unlock(); | 248 s_criticalSectionLocal.Unlock(); |
| 229 | 249 |
| 230 try | 250 try |
| 231 { | 251 { |
| 232 DEBUG_GENERAL("Loaded as BHO"); | |
| 233 HRESULT hr = DispEventAdvise(m_webBrowser2); | 252 HRESULT hr = DispEventAdvise(m_webBrowser2); |
| 234 if (SUCCEEDED(hr)) | 253 if (SUCCEEDED(hr)) |
| 235 { | 254 { |
| 236 m_isAdvised = true; | 255 m_isAdvised = true; |
| 237 try | 256 try |
| 238 { | 257 { |
| 239 std::thread startInitObjectThread(StartInitObject, this); | 258 std::thread startInitObjectThread(StartInitObject, this); |
| 240 startInitObjectThread.detach(); // TODO: but actually we should wait
for the thread in the dtr. | 259 startInitObjectThread.detach(); // TODO: but actually we should wait
for the thread in the dtr. |
| 241 } | 260 } |
| 242 catch (const std::system_error& ex) | 261 catch (const std::system_error& ex) |
| 243 { | 262 { |
| 244 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH
READ_CREATE_PROCESS, | 263 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH
READ_CREATE_PROCESS, |
| 245 "Class::Thread - Failed to create StartInitObject thread"); | 264 "Class::Thread - Failed to create StartInitObject thread"); |
| 246 } | 265 } |
| 247 } | 266 } |
| 248 else | 267 else |
| 249 { | 268 { |
| 250 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC
E, "Class::SetSite - Advise"); | 269 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC
E, "Class::SetSite - Advise"); |
| 251 } | 270 } |
| 252 } | 271 } |
| 253 catch (const std::runtime_error& ex) | 272 catch (const std::runtime_error& ex) |
| 254 { | 273 { |
| 255 DEBUG_EXCEPTION(ex); | 274 DEBUG_EXCEPTION(ex); |
| 256 Unadvise(); | 275 Unadvise(); |
| 257 } | 276 } |
| 258 } | 277 } |
| 259 else | 278 else |
| 260 { | 279 { |
| 280 DEBUG_GENERAL([this]() -> std::wstring |
| 281 { |
| 282 std::wstringstream ss; |
| 283 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); |
| 284 ss << L", browser = nullptr"; |
| 285 return ss.str(); |
| 286 }()); |
| 287 |
| 261 Unadvise(); | 288 Unadvise(); |
| 262 | 289 |
| 263 // Destroy window | 290 // Destroy window |
| 264 if (m_pWndProcStatus) | 291 if (m_pWndProcStatus) |
| 265 { | 292 { |
| 266 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
dProcStatus); | 293 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
dProcStatus); |
| 267 | 294 |
| 268 m_pWndProcStatus = NULL; | 295 m_pWndProcStatus = NULL; |
| 269 } | 296 } |
| 270 | 297 |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 s_criticalSectionLocal.Unlock(); | 1660 s_criticalSectionLocal.Unlock(); |
| 1634 | 1661 |
| 1635 return icon; | 1662 return icon; |
| 1636 } | 1663 } |
| 1637 | 1664 |
| 1638 ATOM CPluginClass::GetAtomPaneClass() | 1665 ATOM CPluginClass::GetAtomPaneClass() |
| 1639 { | 1666 { |
| 1640 return s_atomPaneClass; | 1667 return s_atomPaneClass; |
| 1641 } | 1668 } |
| 1642 | 1669 |
| OLD | NEW |