LEFT | RIGHT |
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-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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 CLOSETHEMEDATA pfnClose = NULL; | 54 CLOSETHEMEDATA pfnClose = NULL; |
55 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; | 55 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; |
56 OPENTHEMEDATA pfnOpenThemeData = NULL; | 56 OPENTHEMEDATA pfnOpenThemeData = NULL; |
57 | 57 |
58 ATOM CPluginClass::s_atomPaneClass = NULL; | 58 ATOM CPluginClass::s_atomPaneClass = NULL; |
59 HINSTANCE CPluginClass::s_hUxtheme = NULL; | 59 HINSTANCE CPluginClass::s_hUxtheme = NULL; |
60 std::set<CPluginClass*> CPluginClass::s_instances; | 60 std::set<CPluginClass*> CPluginClass::s_instances; |
61 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; | 61 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; |
62 | 62 |
63 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; | 63 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; |
64 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser; | |
65 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; | 64 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; |
66 | 65 |
67 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; | 66 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; |
68 | 67 |
69 /* | 68 /* |
70 * Without namespace declaration, the identifier "Rectangle" is ambiguous | 69 * Without namespace declaration, the identifier "Rectangle" is ambiguous |
71 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85)
.aspx | 70 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85)
.aspx |
72 */ | 71 */ |
73 namespace AdblockPlus | 72 namespace AdblockPlus |
74 { | 73 { |
75 /** | 74 /** |
76 * Replacement for ATL type CRect. | 75 * Replacement for ATL type CRect. |
77 */ | 76 */ |
78 class Rectangle | 77 class Rectangle |
79 : public RECT | 78 : public RECT |
80 { | 79 { |
81 public: | 80 public: |
82 int Height() const | 81 unsigned long Height() const |
83 { | 82 { |
84 return bottom - top; | 83 if (bottom < top) |
85 } | 84 { |
86 | 85 throw std::runtime_error("invariant violation: rectangle bottom < top"); |
87 int Width() const | 86 } |
88 { | 87 return static_cast<unsigned long>(bottom - top); |
89 return right - left; | 88 } |
| 89 |
| 90 unsigned long Width() const |
| 91 { |
| 92 if (right < left) |
| 93 { |
| 94 throw std::runtime_error("invariant violation: rectangle right < left"); |
| 95 } |
| 96 return static_cast<unsigned long>(right - left); |
90 } | 97 } |
91 }; | 98 }; |
92 } | 99 } |
93 | 100 |
94 CPluginClass::CPluginClass() | 101 CPluginClass::CPluginClass() |
95 : m_data(std::make_shared<Data>()) | 102 : m_data(std::make_shared<Data>()) |
96 { | 103 { |
| 104 DEBUG_GENERAL([this]() -> std::wstring |
| 105 { |
| 106 std::wstring s = L"CPluginClass::<constructor>, this = "; |
| 107 s += ToHexLiteral(this); |
| 108 return s; |
| 109 }()); |
| 110 |
97 //Use this line to debug memory leaks | 111 //Use this line to debug memory leaks |
98 // _CrtDumpMemoryLeaks(); | 112 // _CrtDumpMemoryLeaks(); |
99 | 113 |
100 m_isAdvised = false; | 114 m_isAdvised = false; |
101 m_hTabWnd = NULL; | 115 m_hTabWnd = NULL; |
102 m_hStatusBarWnd = NULL; | 116 m_hStatusBarWnd = NULL; |
103 m_hPaneWnd = NULL; | 117 m_hPaneWnd = NULL; |
104 m_nPaneWidth = 0; | 118 m_nPaneWidth = 0; |
105 m_pWndProcStatus = NULL; | 119 m_pWndProcStatus = NULL; |
106 m_hTheme = NULL; | 120 m_hTheme = NULL; |
107 m_isInitializedOk = false; | 121 m_isInitializedOk = false; |
108 | 122 |
109 | 123 |
110 m_data->tab.reset(new CPluginTab(this)); | 124 m_data->tab.reset(new CPluginTab()); |
| 125 |
111 Dictionary::Create(GetBrowserLanguage()); | 126 Dictionary::Create(GetBrowserLanguage()); |
112 } | 127 } |
113 | 128 |
114 CPluginClass::~CPluginClass() | 129 CPluginClass::~CPluginClass() |
115 { | 130 { |
116 } | 131 DEBUG_GENERAL([this]() -> std::wstring |
117 | 132 { |
118 ///////////////////////////////////////////////////////////////////////////// | 133 std::wstring s = L"CPluginClass::<destructor>, this = "; |
119 // Initialization | 134 s += ToHexLiteral(this); |
120 | 135 return s; |
121 HRESULT CPluginClass::FinalConstruct() | 136 }()); |
122 { | 137 |
123 return S_OK; | 138 m_data.reset(); |
124 } | |
125 | |
126 void CPluginClass::FinalRelease() | |
127 { | |
128 s_criticalSectionBrowser.Lock(); | |
129 { | |
130 m_data.reset(); | |
131 } | |
132 s_criticalSectionBrowser.Unlock(); | |
133 } | 139 } |
134 | 140 |
135 HWND CPluginClass::GetBrowserHWND() const | 141 HWND CPluginClass::GetBrowserHWND() const |
136 { | 142 { |
137 SHANDLE_PTR hBrowserWndHandle = NULL; | 143 if (!m_data->webBrowser2) |
138 | 144 { |
139 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 145 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with webBro
wser2 == nullptr"); |
140 if (browser) | 146 return nullptr; |
141 { | 147 } |
142 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); | 148 SHANDLE_PTR hBrowserWndHandle = 0; |
143 if (FAILED(hr)) | 149 HRESULT hr = m_data->webBrowser2->get_HWND(&hBrowserWndHandle); |
144 { | 150 if (FAILED(hr)) |
145 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "
Class::GetBrowserHWND - failed") | 151 { |
146 } | 152 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl
ass::GetBrowserHWND - failed"); |
147 } | 153 return nullptr; |
148 | 154 } |
149 return (HWND)hBrowserWndHandle; | 155 return (HWND)hBrowserWndHandle; |
150 } | 156 } |
151 | 157 |
152 | 158 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser) |
153 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const | 159 { |
| 160 return m_data->webBrowser2.IsEqualObject(otherBrowser); |
| 161 } |
| 162 |
| 163 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() |
154 { | 164 { |
155 CComQIPtr<IWebBrowser2> browser; | 165 CComQIPtr<IWebBrowser2> browser; |
156 | 166 |
157 s_criticalSectionBrowser.Lock(); | 167 s_criticalSectionLocal.Lock(); |
158 { | 168 { |
159 browser = m_data->webBrowser2; | 169 browser = s_asyncWebBrowser2; |
160 } | 170 } |
161 s_criticalSectionBrowser.Unlock(); | 171 s_criticalSectionLocal.Unlock(); |
162 | 172 |
163 return browser; | 173 return browser; |
164 } | 174 } |
165 | 175 |
166 | |
167 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() | |
168 { | |
169 CComQIPtr<IWebBrowser2> browser; | |
170 | |
171 s_criticalSectionLocal.Lock(); | |
172 { | |
173 browser = s_asyncWebBrowser2; | |
174 } | |
175 s_criticalSectionLocal.Unlock(); | |
176 | |
177 return browser; | |
178 } | |
179 | |
180 std::wstring CPluginClass::GetBrowserUrl() const | 176 std::wstring CPluginClass::GetBrowserUrl() const |
181 { | 177 { |
182 std::wstring url; | 178 std::wstring url; |
183 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 179 if (m_data->webBrowser2) |
184 if (browser) | |
185 { | 180 { |
186 CComBSTR bstrURL; | 181 CComBSTR bstrURL; |
187 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) | 182 if (SUCCEEDED(m_data->webBrowser2->get_LocationURL(&bstrURL))) |
188 { | 183 { |
189 url = std::wstring(bstrURL, SysStringLen(bstrURL)); | 184 url = ToWstring(bstrURL); |
190 } | 185 } |
191 } | 186 } |
192 else | 187 else |
| 188 { |
| 189 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with webBrowser2 == nu
llptr (probable invariant violation)"); |
| 190 } |
| 191 if (url.empty()) |
193 { | 192 { |
194 url = m_data->tab->GetDocumentUrl(); | 193 url = m_data->tab->GetDocumentUrl(); |
195 } | 194 } |
196 return url; | 195 return url; |
197 } | 196 } |
198 | 197 |
199 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 198 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
200 { | 199 { |
201 if (thisPtr == NULL) | 200 if (thisPtr == NULL) |
202 return 0; | 201 return 0; |
(...skipping 14 matching lines...) Expand all Loading... |
217 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w
hen IE | 216 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w
hen IE |
218 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru
ctor, | 217 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru
ctor, |
219 * but it is not a proper substitute for one. | 218 * but it is not a proper substitute for one. |
220 */ | 219 */ |
221 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) | 220 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) |
222 { | 221 { |
223 try | 222 try |
224 { | 223 { |
225 if (unknownSite) | 224 if (unknownSite) |
226 { | 225 { |
227 | 226 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
===================================="); |
228 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
====================================") | |
229 | 227 |
230 HRESULT hr = ::CoInitialize(NULL); | 228 HRESULT hr = ::CoInitialize(NULL); |
231 if (FAILED(hr)) | 229 if (FAILED(hr)) |
232 { | 230 { |
233 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"); |
234 } | 232 } |
235 | 233 |
236 s_criticalSectionBrowser.Lock(); | 234 /* |
237 { | 235 * We were instantiated as a BHO, so our site is always of type IWebBrowse
r2. |
238 m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); | 236 */ |
239 } | 237 m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); |
240 s_criticalSectionBrowser.Unlock(); | 238 if (!m_data->webBrowser2) |
| 239 { |
| 240 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p
ointer to IWebBrowser2*"); |
| 241 } |
| 242 DEBUG_GENERAL([this]() -> std::wstring |
| 243 { |
| 244 std::wstringstream ss; |
| 245 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); |
| 246 ss << L", browser = " << ToHexLiteral(m_data->webBrowser2); |
| 247 return ss.str(); |
| 248 }()); |
241 | 249 |
242 //register the mimefilter | 250 //register the mimefilter |
243 //and only mimefilter | 251 //and only mimefilter |
244 //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 |
245 | |
246 s_criticalSectionLocal.Lock(); | 253 s_criticalSectionLocal.Lock(); |
247 { | 254 { |
248 // 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 |
249 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 256 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
250 s_asyncWebBrowser2 = unknownSite; | 257 s_asyncWebBrowser2 = unknownSite; |
251 s_instances.insert(this); | 258 s_instances.insert(this); |
252 } | 259 } |
253 s_criticalSectionLocal.Unlock(); | 260 s_criticalSectionLocal.Unlock(); |
254 | 261 |
255 try | 262 try |
256 { | 263 { |
257 auto webBrowser = GetBrowser(); | 264 HRESULT hr = DispEventAdvise(m_data->webBrowser2); |
258 if (webBrowser) | 265 if (SUCCEEDED(hr)) |
259 { | 266 { |
260 DEBUG_GENERAL("Loaded as BHO"); | 267 m_isAdvised = true; |
261 HRESULT hr = DispEventAdvise(webBrowser); | 268 try |
262 if (SUCCEEDED(hr)) | |
263 { | 269 { |
264 m_isAdvised = true; | 270 std::thread startInitObjectThread(StartInitObject, this); |
265 try | 271 startInitObjectThread.detach(); // TODO: but actually we should wait
for the thread in the dtr. |
266 { | |
267 std::thread startInitObjectThread(StartInitObject, this); | |
268 startInitObjectThread.detach(); // TODO: but actually we should wa
it for the thread in the dtr. | |
269 } | |
270 catch (const std::system_error& ex) | |
271 { | |
272 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_
THREAD_CREATE_PROCESS, | |
273 "Class::Thread - Failed to create StartInitObject thread"); | |
274 } | |
275 } | 272 } |
276 else | 273 catch (const std::system_error& ex) |
277 { | 274 { |
278 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV
ICE, "Class::SetSite - Advise"); | 275 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH
READ_CREATE_PROCESS, |
| 276 "Class::Thread - Failed to create StartInitObject thread"); |
279 } | 277 } |
| 278 } |
| 279 else |
| 280 { |
| 281 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC
E, "Class::SetSite - Advise"); |
280 } | 282 } |
281 } | 283 } |
282 catch (const std::runtime_error& ex) | 284 catch (const std::runtime_error& ex) |
283 { | 285 { |
284 DEBUG_EXCEPTION(ex); | 286 DEBUG_EXCEPTION(ex); |
285 Unadvise(); | 287 Unadvise(); |
286 } | 288 } |
287 } | 289 } |
288 else | 290 else |
289 { | 291 { |
| 292 DEBUG_GENERAL([this]() -> std::wstring |
| 293 { |
| 294 std::wstringstream ss; |
| 295 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); |
| 296 ss << L", browser = nullptr"; |
| 297 return ss.str(); |
| 298 }()); |
| 299 |
290 Unadvise(); | 300 Unadvise(); |
| 301 assert(m_data->connectedWebBrowsersCache.empty() && "Connected web browser
cache should be already empty"); |
291 | 302 |
292 // Destroy window | 303 // Destroy window |
293 if (m_pWndProcStatus) | 304 if (m_pWndProcStatus) |
294 { | 305 { |
295 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
dProcStatus); | 306 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
dProcStatus); |
296 | 307 |
297 m_pWndProcStatus = NULL; | 308 m_pWndProcStatus = NULL; |
298 } | 309 } |
299 | 310 |
300 if (m_hPaneWnd) | 311 if (m_hPaneWnd) |
(...skipping 19 matching lines...) Expand all Loading... |
320 s_threadInstances.erase(it); | 331 s_threadInstances.erase(it); |
321 } | 332 } |
322 if (s_instances.empty()) | 333 if (s_instances.empty()) |
323 { | 334 { |
324 // 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 |
325 CPluginClientFactory::ReleaseMimeFilterClientInstance(); | 336 CPluginClientFactory::ReleaseMimeFilterClientInstance(); |
326 } | 337 } |
327 } | 338 } |
328 s_criticalSectionLocal.Unlock(); | 339 s_criticalSectionLocal.Unlock(); |
329 | 340 |
330 // Release browser interface | 341 m_data->webBrowser2 = nullptr; |
331 s_criticalSectionBrowser.Lock(); | |
332 { | |
333 m_data->webBrowser2.Release(); | |
334 } | |
335 s_criticalSectionBrowser.Unlock(); | |
336 | 342 |
337 DEBUG_GENERAL("===========================================================
=====================\nNEW TAB UI - END\n=======================================
=========================================") | 343 DEBUG_GENERAL("===========================================================
=====================\nNEW TAB UI - END\n=======================================
=========================================") |
338 | 344 |
339 ::CoUninitialize(); | 345 ::CoUninitialize(); |
340 } | 346 } |
341 | 347 |
342 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); | |
343 } | 348 } |
344 catch (...) | 349 catch (...) |
345 { | 350 { |
346 } | 351 } |
| 352 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); |
347 return S_OK; | 353 return S_OK; |
348 } | 354 } |
349 | 355 |
350 bool CPluginClass::IsStatusBarEnabled() | 356 bool CPluginClass::IsStatusBarEnabled() |
351 { | 357 { |
352 DEBUG_GENERAL("IsStatusBarEnabled start"); | 358 DEBUG_GENERAL("IsStatusBarEnabled start"); |
353 HKEY pHkey; | 359 HKEY pHkey; |
354 HKEY pHkeySub; | 360 HKEY pHkeySub; |
355 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); | 361 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); |
356 DWORD truth = 1; | 362 DWORD truth = 1; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 { | 480 { |
475 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; | 481 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; |
476 if (!webBrowser) | 482 if (!webBrowser) |
477 { | 483 { |
478 return; | 484 return; |
479 } | 485 } |
480 if (!urlVariant || urlVariant->vt != VT_BSTR) | 486 if (!urlVariant || urlVariant->vt != VT_BSTR) |
481 { | 487 { |
482 return; | 488 return; |
483 } | 489 } |
484 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); | 490 std::wstring url = ToWstring(urlVariant->bstrVal); |
485 EnsureWebBrowserConnected(webBrowser); | 491 EnsureWebBrowserConnected(webBrowser); |
486 | 492 |
487 // 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 |
488 // navigating new page | 494 // navigating new page |
489 CPluginClient* client = CPluginClient::GetInstance(); | 495 CPluginClient* client = CPluginClient::GetInstance(); |
490 if (url.find(L"javascript") == 0) | 496 if (url.find(L"javascript") == 0) |
491 { | 497 { |
492 } | 498 } |
493 else if (GetBrowser().IsEqualObject(webBrowser)) | 499 else if (IsRootBrowser(webBrowser)) |
494 { | 500 { |
495 m_data->tab->OnNavigate(url); | 501 m_data->tab->OnNavigate(url); |
496 DEBUG_GENERAL( | 502 DEBUG_GENERAL( |
497 L"========================================================================
========\n" | 503 L"========================================================================
========\n" |
498 L"Begin main navigation url:" + url + L"\n" | 504 L"Begin main navigation url:" + url + L"\n" |
499 L"========================================================================
========") | 505 L"========================================================================
========") |
500 | 506 |
501 #ifdef ENABLE_DEBUG_RESULT | 507 #ifdef ENABLE_DEBUG_RESULT |
502 CPluginDebug::DebugResultDomain(url); | 508 CPluginDebug::DebugResultDomain(url); |
503 #endif | 509 #endif |
504 UpdateStatusBar(); | 510 UpdateStatusBar(); |
505 } | 511 } |
506 else | 512 else |
507 { | 513 { |
508 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) | 514 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) |
509 m_data->tab->CacheFrame(url); | 515 m_data->tab->CacheFrame(url); |
510 } | 516 } |
511 } | 517 } |
512 catch (...) | 518 catch (...) |
513 { | 519 { |
514 } | 520 } |
515 } | 521 } |
516 | 522 |
517 // Entry point | 523 // Entry point |
518 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() | 524 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() |
519 { | 525 { |
520 try | 526 try |
521 { | 527 { |
| 528 if (!m_data->webBrowser2) |
| 529 { |
| 530 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with
webBrowser2 == nullptr"); |
| 531 return; |
| 532 } |
522 DEBUG_NAVI(L"Navi::Download Complete") | 533 DEBUG_NAVI(L"Navi::Download Complete") |
523 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); | 534 m_data->tab->OnDownloadComplete(m_data->webBrowser2); |
524 if (browser) | |
525 { | |
526 m_data->tab->OnDownloadComplete(browser); | |
527 } | |
528 } | 535 } |
529 catch (...) | 536 catch (...) |
530 { | 537 { |
531 } | 538 } |
532 } | 539 } |
533 | 540 |
534 // Entry point | 541 // Entry point |
535 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) | 542 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) |
536 { | 543 { |
537 try | 544 try |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 { | 603 { |
597 Unadvise(); | 604 Unadvise(); |
598 } | 605 } |
599 catch (...) | 606 catch (...) |
600 { | 607 { |
601 } | 608 } |
602 } | 609 } |
603 | 610 |
604 bool CPluginClass::InitObject() | 611 bool CPluginClass::InitObject() |
605 { | 612 { |
606 DEBUG_GENERAL("InitObject"); | 613 DEBUG_GENERAL("InitObject - begin"); |
607 CPluginSettings* settings = CPluginSettings::GetInstance(); | 614 CPluginSettings* settings = CPluginSettings::GetInstance(); |
608 | 615 |
609 if (!settings->GetPluginEnabled()) | 616 if (!settings->GetPluginEnabled()) |
610 { | 617 { |
611 s_mimeFilter->Unregister(); | 618 s_mimeFilter->Unregister(); |
612 } | 619 } |
613 | 620 |
614 // Load theme module | 621 // Load theme module |
615 s_criticalSectionLocal.Lock(); | 622 s_criticalSectionLocal.Lock(); |
616 { | 623 { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun) | 716 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun) |
710 { | 717 { |
711 ShowStatusBar(); | 718 ShowStatusBar(); |
712 } | 719 } |
713 | 720 |
714 // Enable acceptable ads by default | 721 // Enable acceptable ads by default |
715 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e
xceptionsurl", L""); | 722 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e
xceptionsurl", L""); |
716 CPluginClient::GetInstance()->AddSubscription(aaUrl); | 723 CPluginClient::GetInstance()->AddSubscription(aaUrl); |
717 } | 724 } |
718 s_criticalSectionLocal.Unlock(); | 725 s_criticalSectionLocal.Unlock(); |
| 726 |
| 727 DEBUG_GENERAL("InitObject - end"); |
719 return true; | 728 return true; |
720 } | 729 } |
721 | 730 |
722 bool CPluginClass::CreateStatusBarPane() | 731 bool CPluginClass::CreateStatusBarPane() |
723 { | 732 { |
724 CriticalSection::Lock lock(m_csStatusBar); | 733 CriticalSection::Lock lock(m_csStatusBar); |
725 | 734 |
726 CPluginClient* client = CPluginClient::GetInstance(); | 735 CPluginClient* client = CPluginClient::GetInstance(); |
727 | 736 |
728 std::array<wchar_t, MAX_PATH> className; | 737 std::array<wchar_t, MAX_PATH> className; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 if (it != s_threadInstances.end()) | 986 if (it != s_threadInstances.end()) |
978 { | 987 { |
979 tab = it->second->m_data->tab.get(); | 988 tab = it->second->m_data->tab.get(); |
980 } | 989 } |
981 } | 990 } |
982 s_criticalSectionLocal.Unlock(); | 991 s_criticalSectionLocal.Unlock(); |
983 | 992 |
984 return tab; | 993 return tab; |
985 } | 994 } |
986 | 995 |
987 | 996 // Entry point |
988 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) |
989 { | 998 { |
990 if (cCmds == 0) return E_INVALIDARG; | 999 try |
991 if (prgCmds == 0) return E_POINTER; | 1000 { |
992 | 1001 if (cCmds == 0) return E_INVALIDARG; |
993 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1002 if (prgCmds == 0) return E_POINTER; |
994 | 1003 |
| 1004 prgCmds[0].cmdf = OLECMDF_ENABLED; |
| 1005 } |
| 1006 catch (...) |
| 1007 { |
| 1008 DEBUG_GENERAL(L"CPluginClass::QueryStatus - exception"); |
| 1009 return E_FAIL; |
| 1010 } |
995 return S_OK; | 1011 return S_OK; |
996 } | 1012 } |
997 | 1013 |
998 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) | 1014 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) |
999 { | 1015 { |
1000 DEBUG_GENERAL("CreatePluginMenu"); | 1016 DEBUG_GENERAL("CreatePluginMenu"); |
1001 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1017 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
1002 | 1018 |
1003 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1019 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
1004 | 1020 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 if (FAILED(hr)) | 1111 if (FAILED(hr)) |
1096 { | 1112 { |
1097 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION
_SETTINGS, "Navigation::Failed") | 1113 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION
_SETTINGS, "Navigation::Failed") |
1098 } | 1114 } |
1099 } | 1115 } |
1100 } | 1116 } |
1101 break; | 1117 break; |
1102 } | 1118 } |
1103 case ID_MENU_DISABLE_ON_SITE: | 1119 case ID_MENU_DISABLE_ON_SITE: |
1104 { | 1120 { |
1105 CPluginSettings* settings = CPluginSettings::GetInstance(); | |
1106 std::wstring urlString = GetTab()->GetDocumentUrl(); | 1121 std::wstring urlString = GetTab()->GetDocumentUrl(); |
1107 std::string filterText = client->GetWhitelistingFilter(urlString); | 1122 std::string filterText = client->GetWhitelistingFilter(urlString); |
1108 if (!filterText.empty()) | 1123 if (!filterText.empty()) |
1109 { | 1124 { |
1110 client->RemoveFilter(filterText); | 1125 client->RemoveFilter(filterText); |
1111 } | 1126 } |
1112 else | 1127 else |
1113 { | 1128 { |
1114 settings->AddWhiteListedDomain(client->GetHostFromUrl(urlString)); | 1129 CPluginSettings::GetInstance()->AddWhiteListedDomain(client->GetHostFrom
Url(urlString)); |
1115 } | 1130 } |
1116 } | 1131 } |
1117 default: | 1132 default: |
1118 break; | 1133 break; |
1119 } | 1134 } |
1120 | 1135 |
1121 // Invalidate and redraw the control | 1136 // Invalidate and redraw the control |
1122 UpdateStatusBar(); | 1137 UpdateStatusBar(); |
1123 } | 1138 } |
1124 | 1139 |
(...skipping 10 matching lines...) Expand all Loading... |
1135 | 1150 |
1136 MENUITEMINFOW miiSep = {}; | 1151 MENUITEMINFOW miiSep = {}; |
1137 miiSep.cbSize = sizeof(miiSep); | 1152 miiSep.cbSize = sizeof(miiSep); |
1138 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 1153 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |
1139 miiSep.fType = MFT_SEPARATOR; | 1154 miiSep.fType = MFT_SEPARATOR; |
1140 | 1155 |
1141 CPluginClient* client = CPluginClient::GetInstance(); | 1156 CPluginClient* client = CPluginClient::GetInstance(); |
1142 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1157 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1143 { | 1158 { |
1144 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 1159 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |
1145 // Is domain in white list? | |
1146 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); | 1160 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); |
1147 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) | 1161 /* |
1148 { | 1162 * The display state of the "disable on this site" menu item depends upon ta
b content |
| 1163 */ |
| 1164 if (!GetTab()->IsPossibleToDisableOnSite()) |
| 1165 { |
| 1166 // Since we can't disable the present content, |
| 1167 // it makes no sense to offer the user an option to block it. |
| 1168 fmii.fState = MFS_UNCHECKED | MFS_DISABLED; |
| 1169 } |
| 1170 else if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) |
| 1171 { |
| 1172 // Domain is in white list, indicated by a check mark |
1149 fmii.fState = MFS_CHECKED | MFS_ENABLED; | 1173 fmii.fState = MFS_CHECKED | MFS_ENABLED; |
1150 } | 1174 } |
1151 else | 1175 else |
1152 { | 1176 { |
1153 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 1177 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |
1154 } | 1178 } |
1155 fmii.fMask = MIIM_STRING | MIIM_STATE; | 1179 fmii.fMask = MIIM_STRING | MIIM_STATE; |
1156 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1180 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1157 fmii.cch = static_cast<UINT>(ctext.size()); | 1181 fmii.cch = static_cast<UINT>(ctext.size()); |
1158 | 1182 |
(...skipping 28 matching lines...) Expand all Loading... |
1187 ctext = dictionary->Lookup("menu", "menu-settings"); | 1211 ctext = dictionary->Lookup("menu", "menu-settings"); |
1188 fmii.fMask = MIIM_STATE | MIIM_STRING; | 1212 fmii.fMask = MIIM_STATE | MIIM_STRING; |
1189 fmii.fState = MFS_ENABLED; | 1213 fmii.fState = MFS_ENABLED; |
1190 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1214 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1191 fmii.cch = static_cast<UINT>(ctext.size()); | 1215 fmii.cch = static_cast<UINT>(ctext.size()); |
1192 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); | 1216 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); |
1193 | 1217 |
1194 return true; | 1218 return true; |
1195 } | 1219 } |
1196 | 1220 |
1197 | 1221 // Entry point |
1198 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) | 1222 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) |
1199 { | 1223 { |
1200 HWND hBrowserWnd = GetBrowserHWND(); | 1224 try |
1201 if (!hBrowserWnd) | 1225 { |
1202 { | 1226 HWND hBrowserWnd = GetBrowserHWND(); |
1203 return E_FAIL; | 1227 if (!hBrowserWnd) |
1204 } | 1228 { |
1205 | 1229 return E_FAIL; |
1206 // Create menu | 1230 } |
1207 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl()); | 1231 |
1208 if (!hMenu) | 1232 // Create menu |
1209 { | 1233 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl()); |
1210 return E_FAIL; | 1234 if (!hMenu) |
1211 } | 1235 { |
1212 | 1236 return E_FAIL; |
1213 // Check if button in toolbar was pressed | 1237 } |
1214 int nIDCommand = -1; | 1238 |
1215 BOOL bRightAlign = FALSE; | 1239 // Check if button in toolbar was pressed |
1216 | 1240 int nIDCommand = -1; |
1217 POINT pt; | 1241 BOOL bRightAlign = FALSE; |
1218 GetCursorPos(&pt); | 1242 |
1219 | 1243 POINT pt; |
1220 HWND hWndToolBar = ::WindowFromPoint(pt); | 1244 GetCursorPos(&pt); |
1221 | 1245 |
1222 DWORD nProcessId; | 1246 HWND hWndToolBar = ::WindowFromPoint(pt); |
1223 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | 1247 |
1224 | 1248 DWORD nProcessId; |
1225 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | 1249 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |
1226 { | 1250 |
1227 ::ScreenToClient(hWndToolBar, &pt); | 1251 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |
1228 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | 1252 { |
1229 | 1253 ::ScreenToClient(hWndToolBar, &pt); |
1230 if (nButton > 0) | 1254 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |
1231 { | 1255 |
1232 TBBUTTON pTBBtn = {}; | 1256 if (nButton > 0) |
1233 | 1257 { |
1234 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 1258 TBBUTTON pTBBtn = {}; |
1235 { | 1259 |
1236 RECT rcButton; | 1260 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |
1237 nIDCommand = pTBBtn.idCommand; | 1261 { |
1238 | 1262 RECT rcButton; |
1239 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) | 1263 nIDCommand = pTBBtn.idCommand; |
1240 { | 1264 |
1241 pt.x = rcButton.left; | 1265 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton
)) |
1242 pt.y = rcButton.bottom; | |
1243 ClientToScreen(hWndToolBar, &pt); | |
1244 | |
1245 RECT rcWorkArea; | |
1246 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
1247 if (rcWorkArea.right - pt.x < 150) | |
1248 { | 1266 { |
1249 bRightAlign = TRUE; | 1267 pt.x = rcButton.left; |
1250 pt.x = rcButton.right; | |
1251 pt.y = rcButton.bottom; | 1268 pt.y = rcButton.bottom; |
1252 ClientToScreen(hWndToolBar, &pt); | 1269 ClientToScreen(hWndToolBar, &pt); |
| 1270 |
| 1271 RECT rcWorkArea; |
| 1272 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); |
| 1273 if (rcWorkArea.right - pt.x < 150) |
| 1274 { |
| 1275 bRightAlign = TRUE; |
| 1276 pt.x = rcButton.right; |
| 1277 pt.y = rcButton.bottom; |
| 1278 ClientToScreen(hWndToolBar, &pt); |
| 1279 } |
1253 } | 1280 } |
1254 } | 1281 } |
1255 } | 1282 } |
| 1283 else |
| 1284 { |
| 1285 GetCursorPos(&pt); |
| 1286 } |
| 1287 } |
| 1288 |
| 1289 // Display menu |
| 1290 UINT nFlags = 0; |
| 1291 if (bRightAlign) |
| 1292 { |
| 1293 nFlags |= TPM_RIGHTALIGN; |
1256 } | 1294 } |
1257 else | 1295 else |
1258 { | 1296 { |
1259 GetCursorPos(&pt); | 1297 nFlags |= TPM_LEFTALIGN; |
1260 } | 1298 } |
1261 } | 1299 |
1262 | 1300 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); |
1263 // Display menu | 1301 } |
1264 UINT nFlags = 0; | 1302 catch (...) |
1265 if (bRightAlign) | 1303 { |
1266 { | 1304 // Suppress exception, log only |
1267 nFlags |= TPM_RIGHTALIGN; | 1305 DEBUG_GENERAL(L"CPluginClass::Exec - exception"); |
1268 } | 1306 return E_FAIL; |
1269 else | 1307 } |
1270 { | |
1271 nFlags |= TPM_LEFTALIGN; | |
1272 } | |
1273 | |
1274 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | |
1275 | 1308 |
1276 return S_OK; | 1309 return S_OK; |
1277 } | 1310 } |
1278 | 1311 |
1279 ///////////////////////////////////////////////////////////////////////////// | 1312 // Entry point |
1280 // Window procedures | |
1281 | |
1282 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) | 1313 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) |
1283 { | 1314 { |
1284 // Find tab | 1315 CPluginClass *pClass; |
1285 CPluginClass *pClass = FindInstance(hWnd); | 1316 try |
1286 if (!pClass) | 1317 { |
1287 { | 1318 // Find tab |
1288 return DefWindowProc(hWnd, message, wParam, lParam); | 1319 pClass = FindInstance(hWnd); |
1289 } | 1320 if (!pClass) |
1290 | 1321 { |
1291 // Process message | 1322 /* |
1292 switch (message) | 1323 * Race condition if reached. |
1293 { | 1324 * We did not unhook the window procedure for the status bar when the last
BHO instance using it terminated. |
1294 case SB_SIMPLE: | 1325 * The next best thing is to call the system default window function. |
1295 { | 1326 */ |
1296 ShowWindow(pClass->m_hPaneWnd, !wParam); | 1327 return DefWindowProc(hWnd, message, wParam, lParam); |
| 1328 } |
| 1329 |
| 1330 // Process message |
| 1331 switch (message) |
| 1332 { |
| 1333 case SB_SIMPLE: |
| 1334 { |
| 1335 ShowWindow(pClass->m_hPaneWnd, !wParam); |
| 1336 break; |
| 1337 } |
| 1338 |
| 1339 case WM_SYSCOLORCHANGE: |
| 1340 { |
| 1341 pClass->UpdateTheme(); |
| 1342 break; |
| 1343 } |
| 1344 |
| 1345 case SB_SETPARTS: |
| 1346 { |
| 1347 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) |
| 1348 { |
| 1349 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam,
lParam); |
| 1350 } |
| 1351 |
| 1352 WPARAM nParts = wParam; |
| 1353 if (STATUSBAR_PANE_NUMBER >= nParts) |
| 1354 { |
| 1355 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam,
lParam); |
| 1356 } |
| 1357 |
| 1358 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1)); |
| 1359 LPINT lpParts = (LPINT)LocalLock(hLocal); |
| 1360 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); |
| 1361 |
| 1362 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) |
| 1363 { |
| 1364 lpParts[i] -= pClass->m_nPaneWidth; |
| 1365 } |
| 1366 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w
Param, (LPARAM)lpParts); |
| 1367 |
| 1368 AdblockPlus::Rectangle rcPane; |
| 1369 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); |
| 1370 |
| 1371 AdblockPlus::Rectangle rcClient; |
| 1372 ::GetClientRect(hWnd, &rcClient); |
| 1373 |
| 1374 ::MoveWindow( |
| 1375 pClass->m_hPaneWnd, |
| 1376 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, |
| 1377 0, |
| 1378 pClass->m_nPaneWidth, |
| 1379 rcClient.Height(), |
| 1380 TRUE); |
| 1381 |
| 1382 ::LocalFree(hLocal); |
| 1383 return hRet; |
| 1384 } |
| 1385 |
| 1386 default: |
1297 break; | 1387 break; |
1298 } | 1388 } |
1299 | 1389 } |
1300 case WM_SYSCOLORCHANGE: | 1390 catch (...) |
1301 { | 1391 { |
1302 pClass->UpdateTheme(); | 1392 // Suppress exception. Fall through to default handler. |
1303 break; | 1393 DEBUG_GENERAL(L"CPluginClass::NewStatusProc - exception"); |
1304 } | 1394 } |
1305 | 1395 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara
m); |
1306 case SB_SETPARTS: | |
1307 { | |
1308 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) | |
1309 { | |
1310 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l
Param); | |
1311 } | |
1312 | |
1313 WPARAM nParts = wParam; | |
1314 if (STATUSBAR_PANE_NUMBER >= nParts) | |
1315 { | |
1316 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l
Param); | |
1317 } | |
1318 | |
1319 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); | |
1320 LPINT lpParts = (LPINT)LocalLock(hLocal); | |
1321 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | |
1322 | |
1323 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | |
1324 { | |
1325 lpParts[i] -= pClass->m_nPaneWidth; | |
1326 } | |
1327 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa
ram, (LPARAM)lpParts); | |
1328 | |
1329 AdblockPlus::Rectangle rcPane; | |
1330 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | |
1331 | |
1332 AdblockPlus::Rectangle rcClient; | |
1333 ::GetClientRect(hWnd, &rcClient); | |
1334 | |
1335 ::MoveWindow( | |
1336 pClass->m_hPaneWnd, | |
1337 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | |
1338 0, | |
1339 pClass->m_nPaneWidth, | |
1340 rcClient.Height(), | |
1341 TRUE); | |
1342 | |
1343 ::LocalFree(hLocal); | |
1344 | |
1345 | |
1346 return hRet; | |
1347 } | |
1348 | |
1349 default: | |
1350 break; | |
1351 } | |
1352 | |
1353 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
m, lParam); | |
1354 | |
1355 | |
1356 return result; | |
1357 | |
1358 } | 1396 } |
1359 | 1397 |
1360 | 1398 |
1361 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) | 1399 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1362 { | 1400 { |
1363 // use the disable icon as defualt, if the client doesn't exists | 1401 // use the disable icon as defualt, if the client doesn't exists |
1364 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1402 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1365 | 1403 |
1366 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1404 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
1367 if (tab) | 1405 if (tab) |
1368 { | 1406 { |
1369 CPluginClient* client = CPluginClient::GetInstance(); | 1407 CPluginClient* client = CPluginClient::GetInstance(); |
1370 if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 1408 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1371 { | 1409 { |
1372 if (client->IsWhitelistedUrl(url)) | 1410 if (client->IsWhitelistedUrl(url)) |
1373 { | 1411 { |
1374 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1412 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1375 } | 1413 } |
1376 else | 1414 else |
1377 { | 1415 { |
1378 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1416 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1379 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 1417 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1380 } | 1418 } |
1381 } | 1419 } |
1382 } | 1420 } |
1383 return hIcon; | 1421 return hIcon; |
1384 } | 1422 } |
1385 | 1423 |
1386 | 1424 // Entry point |
1387 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP
aram, LPARAM lParam) | 1425 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP
aram, LPARAM lParam) |
1388 { | 1426 { |
1389 // Find tab | 1427 try |
1390 CPluginClass *pClass = FindInstance(GetParent(hWnd)); | 1428 { |
1391 if (!pClass) | 1429 // Find tab |
1392 { | 1430 CPluginClass *pClass = FindInstance(GetParent(hWnd)); |
1393 return ::DefWindowProc(hWnd, message, wParam, lParam); | 1431 if (!pClass) |
1394 } | 1432 { |
1395 | 1433 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1396 // Process message | 1434 } |
1397 switch (message) | 1435 |
1398 { | 1436 // Process message |
1399 | 1437 switch (message) |
1400 case WM_SETCURSOR: | 1438 { |
1401 { | 1439 case WM_SETCURSOR: |
1402 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); | 1440 { |
1403 return TRUE; | 1441 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); |
1404 } | 1442 return TRUE; |
1405 case WM_PAINT: | 1443 } |
1406 { | 1444 case WM_PAINT: |
1407 PAINTSTRUCT ps; | 1445 { |
1408 HDC hDC = ::BeginPaint(hWnd, &ps); | 1446 PAINTSTRUCT ps; |
1409 | 1447 HDC hDC = ::BeginPaint(hWnd, &ps); |
1410 AdblockPlus::Rectangle rcClient; | 1448 |
1411 ::GetClientRect(hWnd, &rcClient); | 1449 AdblockPlus::Rectangle rcClient; |
1412 | 1450 ::GetClientRect(hWnd, &rcClient); |
1413 int nDrawEdge = 0; | 1451 |
1414 | 1452 int nDrawEdge = 0; |
1415 // Old Windows background drawing | 1453 |
1416 if (pClass->m_hTheme == NULL) | 1454 // Old Windows background drawing |
1417 { | 1455 if (pClass->m_hTheme == NULL) |
1418 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); | 1456 { |
1419 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); | 1457 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); |
1420 | 1458 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); |
1421 nDrawEdge = 3; | 1459 |
1422 rcClient.left += 3; | 1460 nDrawEdge = 3; |
1423 | 1461 rcClient.left += 3; |
1424 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); | 1462 |
1425 } | 1463 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); |
1426 // Themed background drawing | 1464 } |
1427 else | 1465 // Themed background drawing |
1428 { | 1466 else |
1429 // Draw background | 1467 { |
1430 if (pfnDrawThemeBackground) | 1468 // Draw background |
1431 { | 1469 if (pfnDrawThemeBackground) |
1432 AdblockPlus::Rectangle rc = rcClient; | |
1433 rc.right -= 2; | |
1434 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); | |
1435 } | |
1436 | |
1437 // Copy separator picture to left side | |
1438 int nHeight = rcClient.Height(); | |
1439 int nWidth = rcClient.Width() - 2; | |
1440 | |
1441 for (int i = 0; i < 2; i++) | |
1442 { | |
1443 for (int j = 0; j < nHeight; j++) | |
1444 { | 1470 { |
1445 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); | 1471 AdblockPlus::Rectangle rc = rcClient; |
1446 | 1472 rc.right -= 2; |
1447 // Ignore black boxes (if source is obscured by other windows) | 1473 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); |
1448 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa
lue(clr) > 8)) | 1474 } |
| 1475 |
| 1476 // Copy separator picture to left side |
| 1477 int nHeight = rcClient.Height(); |
| 1478 int nWidth = rcClient.Width() - 2; |
| 1479 |
| 1480 for (int i = 0; i < 2; i++) |
| 1481 { |
| 1482 for (int j = 0; j < nHeight; j++) |
1449 { | 1483 { |
1450 ::SetPixel(hDC, i, j, clr); | 1484 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); |
| 1485 |
| 1486 // Ignore black boxes (if source is obscured by other windows) |
| 1487 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB
Value(clr) > 8)) |
| 1488 { |
| 1489 ::SetPixel(hDC, i, j, clr); |
| 1490 } |
1451 } | 1491 } |
1452 } | 1492 } |
1453 } | 1493 } |
1454 } | 1494 |
1455 | 1495 // Draw icon |
1456 // Draw icon | 1496 if (CPluginClient::GetInstance()) |
1457 if (CPluginClient::GetInstance()) | 1497 { |
1458 { | 1498 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); |
1459 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); | 1499 |
1460 | 1500 int offx = nDrawEdge; |
1461 int offx = nDrawEdge; | 1501 if (hIcon) |
1462 if (hIcon) | 1502 { |
1463 { | 1503 //Get the RECT for the leftmost pane (the status text pane) |
1464 //Get the RECT for the leftmost pane (the status text pane) | 1504 RECT rect; |
| 1505 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0,
(LPARAM)&rect); |
| 1506 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico
nWidth, iconHeight, NULL, NULL, DI_NORMAL); |
| 1507 offx += iconWidth; |
| 1508 } |
| 1509 #ifdef _DEBUG |
| 1510 // Display version |
| 1511 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT
, 0, 0); |
| 1512 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont); |
| 1513 |
| 1514 AdblockPlus::Rectangle rcText = rcClient; |
| 1515 rcText.left += offx; |
| 1516 ::SetBkMode(hDC, TRANSPARENT); |
| 1517 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_
LEFT | DT_SINGLELINE | DT_VCENTER); |
| 1518 |
| 1519 ::SelectObject(hDC, hOldFont); |
| 1520 #endif // _DEBUG |
| 1521 } |
| 1522 |
| 1523 // Done! |
| 1524 EndPaint(hWnd, &ps); |
| 1525 |
| 1526 return 0; |
| 1527 } |
| 1528 |
| 1529 case WM_LBUTTONUP: |
| 1530 case WM_RBUTTONUP: |
| 1531 { |
| 1532 std::wstring url = pClass->GetBrowserUrl(); |
| 1533 if (url != pClass->GetTab()->GetDocumentUrl()) |
| 1534 { |
| 1535 pClass->GetTab()->SetDocumentUrl(url); |
| 1536 } |
| 1537 |
| 1538 // Create menu |
| 1539 HMENU hMenu = pClass->CreatePluginMenu(url); |
| 1540 if (!hMenu) |
| 1541 { |
| 1542 return 0; |
| 1543 } |
| 1544 |
| 1545 // Display menu |
| 1546 POINT pt; |
| 1547 ::GetCursorPos(&pt); |
| 1548 |
| 1549 RECT rc; |
| 1550 ::GetWindowRect(hWnd, &rc); |
| 1551 |
| 1552 if (rc.left >= 0 && rc.top >= 0) |
| 1553 { |
| 1554 pt.x = rc.left; |
| 1555 pt.y = rc.top; |
| 1556 } |
| 1557 |
| 1558 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN
); |
| 1559 break; |
| 1560 } |
| 1561 case WM_DESTROY: |
| 1562 break; |
| 1563 case SC_CLOSE: |
| 1564 break; |
| 1565 |
| 1566 case WM_UPDATEUISTATE: |
| 1567 { |
| 1568 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
| 1569 if (tab) |
| 1570 { |
| 1571 tab->OnActivate(); |
1465 RECT rect; | 1572 RECT rect; |
1466 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (
LPARAM)&rect); | 1573 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1467 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW
idth, iconHeight, NULL, NULL, DI_NORMAL); | 1574 pClass->notificationMessage.MoveToCenter(rect); |
1468 offx += iconWidth; | 1575 } |
1469 } | 1576 if (LOWORD(wParam) == UIS_CLEAR) |
1470 #ifdef _DEBUG | 1577 { |
1471 // Display version | 1578 pClass->notificationMessage.Hide(); |
1472 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT,
0, 0); | 1579 } |
1473 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); | 1580 break; |
1474 | 1581 } |
1475 AdblockPlus::Rectangle rcText = rcClient; | 1582 case WM_WINDOWPOSCHANGING: |
1476 rcText.left += offx; | 1583 { |
1477 ::SetBkMode(hDC, TRANSPARENT); | |
1478 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT
|DT_SINGLELINE|DT_VCENTER); | |
1479 | |
1480 ::SelectObject(hDC, hOldFont); | |
1481 #endif // _DEBUG | |
1482 } | |
1483 | |
1484 // Done! | |
1485 EndPaint(hWnd, &ps); | |
1486 | |
1487 return 0; | |
1488 } | |
1489 | |
1490 case WM_LBUTTONUP: | |
1491 case WM_RBUTTONUP: | |
1492 { | |
1493 std::wstring url = pClass->GetBrowserUrl(); | |
1494 if (url != pClass->GetTab()->GetDocumentUrl()) | |
1495 { | |
1496 pClass->GetTab()->SetDocumentUrl(url); | |
1497 } | |
1498 | |
1499 // Create menu | |
1500 HMENU hMenu = pClass->CreatePluginMenu(url); | |
1501 if (!hMenu) | |
1502 { | |
1503 return 0; | |
1504 } | |
1505 | |
1506 // Display menu | |
1507 POINT pt; | |
1508 ::GetCursorPos(&pt); | |
1509 | |
1510 RECT rc; | |
1511 ::GetWindowRect(hWnd, &rc); | |
1512 | |
1513 if (rc.left >= 0 && rc.top >= 0) | |
1514 { | |
1515 pt.x = rc.left; | |
1516 pt.y = rc.top; | |
1517 } | |
1518 | |
1519 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN); | |
1520 } | |
1521 break; | |
1522 case WM_DESTROY: | |
1523 break; | |
1524 case SC_CLOSE: | |
1525 break; | |
1526 | |
1527 case WM_UPDATEUISTATE: | |
1528 { | |
1529 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | |
1530 if (tab) | |
1531 { | |
1532 tab->OnActivate(); | |
1533 RECT rect; | 1584 RECT rect; |
1534 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1585 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1535 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) /
2, rect.top + (rect.bottom - rect.top) / 2); | 1586 if (pClass->notificationMessage.IsVisible()) |
1536 } | 1587 { |
1537 if (LOWORD(wParam) == UIS_CLEAR) | 1588 pClass->notificationMessage.MoveToCenter(rect); |
1538 { | 1589 } |
1539 pClass->notificationMessage.Hide(); | 1590 break; |
1540 } | 1591 } |
1541 } | 1592 case WM_WINDOWPOSCHANGED: |
1542 break; | 1593 { |
1543 case WM_WINDOWPOSCHANGING: | 1594 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); |
1544 { | 1595 if (wndPos->flags & SWP_HIDEWINDOW) |
1545 RECT rect; | 1596 { |
1546 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1597 pClass->notificationMessage.Hide(); |
1547 if (pClass->notificationMessage.IsVisible()) | 1598 } |
1548 { | 1599 break; |
1549 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) /
2, rect.top + (rect.bottom - rect.top) / 2); | 1600 } |
1550 } | 1601 case WM_ALREADY_UP_TO_DATE: |
1551 } | 1602 { |
1552 break; | 1603 Dictionary* dictionary = Dictionary::GetInstance(); |
1553 case WM_WINDOWPOSCHANGED: | 1604 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread
y-up-to-date-text"); |
1554 { | 1605 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea
dy-up-to-date-title"); |
1555 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); | 1606 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle,
TTI_INFO); |
1556 if (wndPos->flags & SWP_HIDEWINDOW) | 1607 break; |
1557 { | 1608 } |
1558 pClass->notificationMessage.Hide(); | 1609 case WM_UPDATE_CHECK_ERROR: |
1559 } | 1610 { |
1560 } | 1611 Dictionary* dictionary = Dictionary::GetInstance(); |
1561 break; | 1612 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex
t"); |
1562 case WM_ALREADY_UP_TO_DATE: | 1613 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti
tle"); |
1563 { | 1614 pClass->notificationMessage.SetTextAndIcon(errorText, errorTitle, TTI_ER
ROR); |
1564 Dictionary* dictionary = Dictionary::GetInstance(); | 1615 break; |
1565 std::wstring upToDateText = dictionary->Lookup("updater", "update-already-
up-to-date-text"); | 1616 } |
1566 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already
-up-to-date-title"); | 1617 case WM_DOWNLOADING_UPDATE: |
1567 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT
I_INFO); | 1618 { |
1568 } | 1619 Dictionary* dictionary = Dictionary::GetInstance(); |
1569 break; | 1620 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin
g-update-text"); |
1570 case WM_UPDATE_CHECK_ERROR: | 1621 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi
ng-update-title"); |
1571 { | 1622 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT
itle, TTI_INFO); |
1572 Dictionary* dictionary = Dictionary::GetInstance(); | 1623 break; |
1573 std::wstring errorText = dictionary->Lookup("updater", "update-error-text"
); | 1624 } |
1574 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl
e"); | 1625 } |
1575 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR
); | 1626 } |
1576 } | 1627 catch (...) |
1577 break; | 1628 { |
1578 case WM_DOWNLOADING_UPDATE: | 1629 // Suppress exception. Fall through to default handler. |
1579 { | 1630 DEBUG_GENERAL(L"CPluginClass::PaneWindowProc - exception"); |
1580 Dictionary* dictionary = Dictionary::GetInstance(); | 1631 } |
1581 std::wstring downloadingText = dictionary->Lookup("updater", "downloading-
update-text"); | 1632 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1582 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading
-update-title"); | |
1583 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit
le, TTI_INFO); | |
1584 } | |
1585 break; | |
1586 } | |
1587 | |
1588 return DefWindowProc(hWnd, message, wParam, lParam); | |
1589 } | 1633 } |
1590 | 1634 |
1591 | 1635 |
1592 void CPluginClass::UpdateStatusBar() | 1636 void CPluginClass::UpdateStatusBar() |
1593 { | 1637 { |
1594 DEBUG_GENERAL("*** Updating statusbar") | 1638 DEBUG_GENERAL("*** Updating statusbar") |
1595 if (m_hPaneWnd == NULL) | 1639 if (m_hPaneWnd == NULL) |
1596 { | 1640 { |
1597 CreateStatusBarPane(); | 1641 CreateStatusBarPane(); |
1598 } | 1642 } |
1599 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) | 1643 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) |
1600 { | 1644 { |
1601 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"); |
1602 } | 1646 } |
1603 } | 1647 } |
1604 | 1648 |
1605 void CPluginClass::Unadvise() | 1649 void CPluginClass::Unadvise() |
1606 { | 1650 { |
| 1651 if (!m_data->webBrowser2) |
| 1652 { |
| 1653 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with webBrowser2
== nullptr"); |
| 1654 return; |
| 1655 } |
1607 s_criticalSectionLocal.Lock(); | 1656 s_criticalSectionLocal.Lock(); |
1608 { | 1657 { |
1609 if (m_isAdvised) | 1658 if (m_isAdvised) |
1610 { | 1659 { |
1611 HRESULT hr = DispEventUnadvise(GetBrowser()); | 1660 HRESULT hr = DispEventUnadvise(m_data->webBrowser2); |
1612 if (FAILED(hr)) | 1661 if (FAILED(hr)) |
1613 { | 1662 { |
1614 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"); |
1615 } | 1664 } |
1616 m_isAdvised = false; | 1665 m_isAdvised = false; |
1617 } | 1666 } |
1618 } | 1667 } |
1619 s_criticalSectionLocal.Unlock(); | 1668 s_criticalSectionLocal.Unlock(); |
1620 } | 1669 } |
1621 | 1670 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 s_criticalSectionLocal.Unlock(); | 1726 s_criticalSectionLocal.Unlock(); |
1678 | 1727 |
1679 return icon; | 1728 return icon; |
1680 } | 1729 } |
1681 | 1730 |
1682 ATOM CPluginClass::GetAtomPaneClass() | 1731 ATOM CPluginClass::GetAtomPaneClass() |
1683 { | 1732 { |
1684 return s_atomPaneClass; | 1733 return s_atomPaneClass; |
1685 } | 1734 } |
1686 | 1735 |
1687 HWND CPluginClass::GetTabHWND() const | |
1688 { | |
1689 std::array<wchar_t, MAX_PATH> className; | |
1690 // Get browser window and url | |
1691 HWND hBrowserWnd = GetBrowserHWND(); | |
1692 if (!hBrowserWnd) | |
1693 { | |
1694 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C
lass::GetTabWindow - No tab window") | |
1695 s_criticalSectionWindow.Unlock(); | |
1696 | |
1697 return false; | |
1698 } | |
1699 | |
1700 // Looking for a TabWindowClass window in IE7 | |
1701 | |
1702 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); | |
1703 while (hTabWnd) | |
1704 { | |
1705 className[0] = L'\0'; | |
1706 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz
e()); | |
1707 | |
1708 if (classNameLength && (wcscmp(className.data(), L"TabWindowClass") == 0 ||
wcscmp(className.data(), L"Frame Tab") == 0)) | |
1709 { | |
1710 // IE8 support | |
1711 HWND hTabWnd2 = hTabWnd; | |
1712 if (wcscmp(className.data(), L"Frame Tab") == 0) | |
1713 { | |
1714 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL); | |
1715 } | |
1716 | |
1717 if (hTabWnd2) | |
1718 { | |
1719 DWORD nProcessId; | |
1720 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); | |
1721 if (::GetCurrentProcessId() == nProcessId) | |
1722 { | |
1723 bool bExistingTab = false; | |
1724 s_criticalSectionLocal.Lock(); | |
1725 | |
1726 { | |
1727 for (auto instance : s_instances) | |
1728 { | |
1729 if (instance->m_hTabWnd == hTabWnd2) | |
1730 { | |
1731 bExistingTab = true; | |
1732 break; | |
1733 } | |
1734 } | |
1735 } | |
1736 | |
1737 if (!bExistingTab) | |
1738 { | |
1739 hBrowserWnd = hTabWnd2; | |
1740 hTabWnd = hTabWnd2; | |
1741 s_criticalSectionLocal.Unlock(); | |
1742 break; | |
1743 } | |
1744 s_criticalSectionLocal.Unlock(); | |
1745 | |
1746 } | |
1747 } | |
1748 } | |
1749 | |
1750 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | |
1751 } | |
1752 return hTabWnd; | |
1753 } | |
LEFT | RIGHT |