LEFT | RIGHT |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
1 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
2 | 19 |
3 #include "PluginClass.h" | 20 #include "PluginClass.h" |
4 #include "PluginSettings.h" | 21 #include "PluginSettings.h" |
5 #include "PluginSystem.h" | 22 #include "PluginSystem.h" |
6 #include "PluginFilter.h" | 23 #include "PluginFilter.h" |
7 #include "PluginMimeFilterClient.h" | 24 #include "PluginMimeFilterClient.h" |
8 #include "PluginClient.h" | 25 #include "PluginClient.h" |
9 #include "PluginClientFactory.h" | 26 #include "PluginClientFactory.h" |
10 #include "PluginMutex.h" | 27 #include "PluginMutex.h" |
11 #include "sddl.h" | 28 #include "sddl.h" |
12 #include "PluginUtil.h" | 29 #include "PluginUtil.h" |
13 #include "PluginUserSettings.h" | 30 #include "PluginUserSettings.h" |
14 #include "../shared/Utils.h" | 31 #include "../shared/Utils.h" |
15 #include "../shared/Dictionary.h" | 32 #include "../shared/Dictionary.h" |
16 #include "IE_Version.h" | 33 #include "IeVersion.h" |
17 #include <thread> | 34 #include <thread> |
18 #include <array> | 35 #include <array> |
19 | 36 |
20 #ifdef DEBUG_HIDE_EL | 37 #ifdef DEBUG_HIDE_EL |
21 DWORD profileTime = 0; | 38 DWORD profileTime = 0; |
22 #endif | 39 #endif |
23 | 40 |
24 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); | 41 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); |
25 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); | 42 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); |
26 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); | 43 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); |
27 | 44 |
28 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; | 45 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; |
29 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; | 46 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; |
| 47 uint32_t iconHeight = 32; |
| 48 uint32_t iconWidth = 32; |
30 | 49 |
31 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; | 50 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; |
32 | 51 |
33 CLOSETHEMEDATA pfnClose = NULL; | 52 CLOSETHEMEDATA pfnClose = NULL; |
34 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; | 53 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; |
35 OPENTHEMEDATA pfnOpenThemeData = NULL; | 54 OPENTHEMEDATA pfnOpenThemeData = NULL; |
36 | 55 |
37 ATOM CPluginClass::s_atomPaneClass = NULL; | 56 ATOM CPluginClass::s_atomPaneClass = NULL; |
38 HINSTANCE CPluginClass::s_hUxtheme = NULL; | 57 HINSTANCE CPluginClass::s_hUxtheme = NULL; |
39 std::set<CPluginClass*> CPluginClass::s_instances; | 58 std::set<CPluginClass*> CPluginClass::s_instances; |
(...skipping 28 matching lines...) Expand all Loading... |
68 return right - left; | 87 return right - left; |
69 } | 88 } |
70 }; | 89 }; |
71 } | 90 } |
72 | 91 |
73 CPluginClass::CPluginClass() | 92 CPluginClass::CPluginClass() |
74 { | 93 { |
75 //Use this line to debug memory leaks | 94 //Use this line to debug memory leaks |
76 // _CrtDumpMemoryLeaks(); | 95 // _CrtDumpMemoryLeaks(); |
77 | 96 |
78 m_isAdviced = false; | 97 m_isAdvised = false; |
79 m_nConnectionID = 0; | |
80 m_hTabWnd = NULL; | 98 m_hTabWnd = NULL; |
81 m_hStatusBarWnd = NULL; | 99 m_hStatusBarWnd = NULL; |
82 m_hPaneWnd = NULL; | 100 m_hPaneWnd = NULL; |
83 m_nPaneWidth = 0; | 101 m_nPaneWidth = 0; |
84 m_pWndProcStatus = NULL; | 102 m_pWndProcStatus = NULL; |
85 m_hTheme = NULL; | 103 m_hTheme = NULL; |
86 m_isInitializedOk = false; | 104 m_isInitializedOk = false; |
87 | 105 |
88 | 106 |
89 m_tab = new CPluginTab(this); | 107 m_tab = new CPluginTab(this); |
(...skipping 17 matching lines...) Expand all Loading... |
107 | 125 |
108 void CPluginClass::FinalRelease() | 126 void CPluginClass::FinalRelease() |
109 { | 127 { |
110 s_criticalSectionBrowser.Lock(); | 128 s_criticalSectionBrowser.Lock(); |
111 { | 129 { |
112 m_webBrowser2.Release(); | 130 m_webBrowser2.Release(); |
113 } | 131 } |
114 s_criticalSectionBrowser.Unlock(); | 132 s_criticalSectionBrowser.Unlock(); |
115 } | 133 } |
116 | 134 |
117 | |
118 // This method tries to get a 'connection point' from the stored browser, which
can be | |
119 // used to attach or detach from the stream of browser events | |
120 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPoint() | |
121 { | |
122 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine
r(GetBrowser()); | |
123 if (!pContainer) | |
124 { | |
125 return NULL; | |
126 } | |
127 | |
128 CComPtr<IConnectionPoint> pPoint; | |
129 HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint)
; | |
130 if (FAILED(hr)) | |
131 { | |
132 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC
TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint") | |
133 return NULL; | |
134 } | |
135 | |
136 return pPoint; | |
137 } | |
138 | |
139 HWND CPluginClass::GetBrowserHWND() const | 135 HWND CPluginClass::GetBrowserHWND() const |
140 { | 136 { |
141 SHANDLE_PTR hBrowserWndHandle = NULL; | 137 SHANDLE_PTR hBrowserWndHandle = NULL; |
142 | 138 |
143 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 139 CComQIPtr<IWebBrowser2> browser = GetBrowser(); |
144 if (browser) | 140 if (browser) |
145 { | 141 { |
146 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); | 142 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); |
147 if (FAILED(hr)) | 143 if (FAILED(hr)) |
148 { | 144 { |
(...skipping 25 matching lines...) Expand all Loading... |
174 | 170 |
175 s_criticalSectionLocal.Lock(); | 171 s_criticalSectionLocal.Lock(); |
176 { | 172 { |
177 browser = s_asyncWebBrowser2; | 173 browser = s_asyncWebBrowser2; |
178 } | 174 } |
179 s_criticalSectionLocal.Unlock(); | 175 s_criticalSectionLocal.Unlock(); |
180 | 176 |
181 return browser; | 177 return browser; |
182 } | 178 } |
183 | 179 |
184 CString CPluginClass::GetBrowserUrl() const | 180 std::wstring CPluginClass::GetBrowserUrl() const |
185 { | 181 { |
186 CString url; | 182 std::wstring url; |
187 | |
188 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 183 CComQIPtr<IWebBrowser2> browser = GetBrowser(); |
189 if (browser) | 184 if (browser) |
190 { | 185 { |
191 CComBSTR bstrURL; | 186 CComBSTR bstrURL; |
192 | 187 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) |
193 if (SUCCEEDED(browser->get_LocationURL(&bstrURL))) | 188 { |
194 { | 189 url = std::wstring(bstrURL, SysStringLen(bstrURL)); |
195 url = bstrURL; | 190 UnescapeUrl(url); |
196 CPluginClient::UnescapeUrl(url); | |
197 } | 191 } |
198 } | 192 } |
199 else | 193 else |
200 { | 194 { |
201 url = m_tab->GetDocumentUrl(); | 195 url = m_tab->GetDocumentUrl(); |
202 } | 196 } |
203 | |
204 return url; | 197 return url; |
205 } | 198 } |
206 | 199 |
207 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
208 { | 201 { |
209 if (thisPtr == NULL) | 202 if (thisPtr == NULL) |
210 return 0; | 203 return 0; |
211 if (!((CPluginClass*)thisPtr)->InitObject(true)) | 204 if (!((CPluginClass*)thisPtr)->InitObject()) |
212 { | 205 { |
213 ((CPluginClass*)thisPtr)->Unadvice(); | 206 ((CPluginClass*)thisPtr)->Unadvise(); |
214 } | 207 } |
215 | 208 |
216 return 0; | 209 return 0; |
217 } | 210 } |
218 | 211 |
219 | 212 /* |
220 | 213 * IE calls this when it creates a new browser window or tab, immediately after
it also |
221 // This gets called when a new browser window is created (which also triggers th
e | 214 * creates the object. The argument 'unknownSite' in is the OLE "site" of the ob
ject, |
222 // creation of this object). The pointer passed in should be to a IWebBrowser2 | 215 * which is an IWebBrowser2 interface associated with the window/tab. |
223 // interface that represents the browser for the window. | 216 * |
224 // it is also called when a tab is closed, this unknownSite will be null | 217 * IE also ordinarily calls this again when its window/tab is closed, in which c
ase |
225 // so we should handle that it is called this way several times during a session | 218 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w
hen IE |
| 219 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru
ctor, |
| 220 * but it is not a proper substitute for one. |
| 221 */ |
226 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) | 222 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) |
227 { | 223 { |
228 CPluginSettings* settings = CPluginSettings::GetInstance(); | 224 try |
229 | 225 { |
230 MULTIPLE_VERSIONS_CHECK(); | 226 if (unknownSite) |
231 | 227 { |
232 if (unknownSite) | 228 |
233 { | 229 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
====================================") |
234 | 230 |
235 DEBUG_GENERAL(L"============================================================
====================\nNEW TAB UI\n==============================================
==================================") | 231 HRESULT hr = ::CoInitialize(NULL); |
236 | 232 if (FAILED(hr)) |
237 HRESULT hr = ::CoInitialize(NULL); | 233 { |
238 if (FAILED(hr)) | 234 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
"Class::SetSite - CoInitialize"); |
239 { | 235 } |
240 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "
Class::SetSite - CoInitialize"); | 236 |
241 } | 237 s_criticalSectionBrowser.Lock(); |
242 | 238 { |
243 s_criticalSectionBrowser.Lock(); | 239 m_webBrowser2 = unknownSite; |
244 { | 240 } |
245 m_webBrowser2 = unknownSite; | 241 s_criticalSectionBrowser.Unlock(); |
246 } | 242 |
247 s_criticalSectionBrowser.Unlock(); | 243 //register the mimefilter |
248 | 244 //and only mimefilter |
249 //register the mimefilter | 245 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread |
250 //and only mimefilter | 246 |
251 //on some few computers the mimefilter does not get properly registered when
it is done on another thread | 247 s_criticalSectionLocal.Lock(); |
252 | 248 { |
253 s_criticalSectionLocal.Lock(); | 249 // Always register on startup, then check if we need to unregister in a
separate thread |
254 { | 250 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
255 // Always register on startup, then check if we need to unregister in a se
parate thread | 251 s_asyncWebBrowser2 = unknownSite; |
256 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 252 s_instances.insert(this); |
257 s_asyncWebBrowser2 = unknownSite; | 253 } |
258 s_instances.insert(this); | 254 s_criticalSectionLocal.Unlock(); |
259 } | 255 |
260 s_criticalSectionLocal.Unlock(); | 256 try |
261 | 257 { |
262 try | 258 auto webBrowser = GetBrowser(); |
263 { | 259 if (webBrowser) |
264 // Check if loaded as BHO | 260 { |
265 if (GetBrowser()) | 261 DEBUG_GENERAL("Loaded as BHO"); |
266 { | 262 HRESULT hr = DispEventAdvise(webBrowser); |
267 DEBUG_GENERAL("Loaded as BHO"); | |
268 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); | |
269 if (pPoint) | |
270 { | |
271 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID); | |
272 if (SUCCEEDED(hr)) | 263 if (SUCCEEDED(hr)) |
273 { | 264 { |
274 m_isAdviced = true; | 265 m_isAdvised = true; |
275 | |
276 try | 266 try |
277 { | 267 { |
278 std::thread startInitObjectThread(StartInitObject, this); | 268 std::thread startInitObjectThread(StartInitObject, this); |
279 startInitObjectThread.detach(); // TODO: but actually we should wa
it for the thread in the dtr. | 269 startInitObjectThread.detach(); // TODO: but actually we should wa
it for the thread in the dtr. |
280 } | 270 } |
281 catch (const std::system_error& ex) | 271 catch (const std::system_error& ex) |
282 { | 272 { |
283 auto errDescription = std::string("Class::Thread - Failed to creat
e StartInitObject thread, ") + | 273 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_
THREAD_CREATE_PROCESS, |
284 ex.code().message() + ex.what(); | 274 "Class::Thread - Failed to create StartInitObject thread"); |
285 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERR
OR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str()); | |
286 } | 275 } |
287 } | 276 } |
288 else | 277 else |
289 { | 278 { |
290 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV
ICE, "Class::SetSite - Advice"); | 279 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV
ICE, "Class::SetSite - Advise"); |
291 } | 280 } |
292 } | 281 } |
293 } | 282 } |
294 else // Check if loaded as toolbar handler | 283 catch (const std::runtime_error& ex) |
295 { | 284 { |
296 DEBUG_GENERAL("Loaded as toolbar handler"); | 285 DEBUG_EXCEPTION(ex); |
297 CComPtr<IServiceProvider> pServiceProvider; | 286 Unadvise(); |
298 | 287 } |
299 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); | 288 } |
300 if (SUCCEEDED(hr)) | 289 else |
301 { | 290 { |
302 if (pServiceProvider) | 291 Unadvise(); |
303 { | 292 |
304 s_criticalSectionBrowser.Lock(); | 293 // Destroy window |
305 { | 294 if (m_pWndProcStatus) |
306 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, &m
_webBrowser2); | 295 { |
307 if (SUCCEEDED(hr)) | 296 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
dProcStatus); |
308 { | 297 |
309 if (m_webBrowser2) | 298 m_pWndProcStatus = NULL; |
310 { | 299 } |
311 InitObject(false); | 300 |
312 } | 301 if (m_hPaneWnd) |
313 } | 302 { |
314 else | 303 DestroyWindow(m_hPaneWnd); |
315 { | 304 m_hPaneWnd = NULL; |
316 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE
_QUERY_BROWSER, "Class::SetSite - QueryService (IID_IWebBrowserApp)"); | 305 } |
317 } | 306 |
318 } | 307 m_hTabWnd = NULL; |
319 s_criticalSectionBrowser.Unlock(); | 308 m_hStatusBarWnd = NULL; |
320 } | 309 |
321 } | 310 // Remove instance from the list, shutdown threads |
322 else | 311 HANDLE hMainThread = NULL; |
323 { | 312 HANDLE hTabThread = NULL; |
324 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY
_SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); | 313 |
325 } | 314 s_criticalSectionLocal.Lock(); |
326 } | 315 { |
327 } | 316 s_instances.erase(this); |
328 catch (std::runtime_error e) | 317 |
329 { | 318 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge
tCurrentThreadId()); |
330 DEBUG_ERROR(e.what()); | 319 if (it != s_threadInstances.end()) |
331 Unadvice(); | 320 { |
332 } | 321 s_threadInstances.erase(it); |
333 } | 322 } |
334 else | 323 if (s_instances.empty()) |
335 { | 324 { |
336 // Unadvice | 325 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr |
337 Unadvice(); | 326 CPluginClientFactory::ReleaseMimeFilterClientInstance(); |
338 | 327 } |
339 // Destroy window | 328 } |
340 if (m_pWndProcStatus) | 329 s_criticalSectionLocal.Unlock(); |
341 { | 330 |
342 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP
rocStatus); | 331 // Release browser interface |
343 | 332 s_criticalSectionBrowser.Lock(); |
344 m_pWndProcStatus = NULL; | 333 { |
345 } | 334 m_webBrowser2.Release(); |
346 | 335 } |
347 if (m_hPaneWnd) | 336 s_criticalSectionBrowser.Unlock(); |
348 { | 337 |
349 DestroyWindow(m_hPaneWnd); | 338 DEBUG_GENERAL("===========================================================
=====================\nNEW TAB UI - END\n=======================================
=========================================") |
350 m_hPaneWnd = NULL; | 339 |
351 } | 340 ::CoUninitialize(); |
352 | 341 } |
353 m_hTabWnd = NULL; | 342 |
354 m_hStatusBarWnd = NULL; | 343 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); |
355 | 344 } |
356 // Remove instance from the list, shutdown threads | 345 catch (...) |
357 HANDLE hMainThread = NULL; | 346 { |
358 HANDLE hTabThread = NULL; | 347 } |
359 | 348 return S_OK; |
360 s_criticalSectionLocal.Lock(); | |
361 { | |
362 s_instances.erase(this); | |
363 | |
364 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC
urrentThreadId()); | |
365 if (it != s_threadInstances.end()) | |
366 { | |
367 s_threadInstances.erase(it); | |
368 } | |
369 if (s_instances.empty()) | |
370 { | |
371 // TODO: Explicitly releasing a resource when a container becomes empty
looks like a job better suited for shared_ptr | |
372 CPluginClientFactory::ReleaseMimeFilterClientInstance(); | |
373 } | |
374 } | |
375 s_criticalSectionLocal.Unlock(); | |
376 | |
377 // Release browser interface | |
378 s_criticalSectionBrowser.Lock(); | |
379 { | |
380 m_webBrowser2.Release(); | |
381 } | |
382 s_criticalSectionBrowser.Unlock(); | |
383 | |
384 DEBUG_GENERAL("=============================================================
===================\nNEW TAB UI - END\n=========================================
=======================================") | |
385 | |
386 ::CoUninitialize(); | |
387 } | |
388 | |
389 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); | |
390 } | 349 } |
391 | 350 |
392 bool CPluginClass::IsStatusBarEnabled() | 351 bool CPluginClass::IsStatusBarEnabled() |
393 { | 352 { |
394 DEBUG_GENERAL("IsStatusBarEnabled start"); | 353 DEBUG_GENERAL("IsStatusBarEnabled start"); |
395 HKEY pHkey; | 354 HKEY pHkey; |
396 HKEY pHkeySub; | 355 HKEY pHkeySub; |
397 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); | 356 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); |
398 DWORD truth = 1; | 357 DWORD truth = 1; |
399 DWORD truthSize = sizeof(truth); | 358 DWORD truthSize = sizeof(truth); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 454 } |
496 } | 455 } |
497 else | 456 else |
498 { | 457 { |
499 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class
::Get statusbar state"); | 458 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class
::Get statusbar state"); |
500 } | 459 } |
501 } | 460 } |
502 DEBUG_GENERAL("ShowStatusBar end"); | 461 DEBUG_GENERAL("ShowStatusBar end"); |
503 } | 462 } |
504 | 463 |
505 /* | 464 // Entry point |
506 * #1163 This class is the implementation for method DISPID_BEFORENAVIGATE2 in C
PluginClass::Invoke. | 465 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2( |
507 * - It validates and convertes its own arguments, rather than unifying them in
the Invoke body. | 466 IDispatch* frameBrowserDisp /**< [in] */, |
508 * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu
rn S_OK. | 467 VARIANT* urlVariant /**< [in] */, |
509 */ | 468 VARIANT* /**< [in] Flags*/, |
510 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) | 469 VARIANT* /**< [in] TargetFrameName*/, |
511 { | 470 VARIANT* /**< [in] PostData*/, |
512 | 471 VARIANT* /**< [in] Headers*/, |
513 if (pDispParams->cArgs < 7) | 472 VARIANT_BOOL* /**< [in, out] Cancel*/) |
514 { | 473 { |
515 return; | 474 try |
516 } | 475 { |
517 //Register a mime filter if it's not registered yet | 476 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; |
518 if (s_mimeFilter == NULL) | 477 if (!webBrowser) |
519 { | 478 { |
520 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 479 return; |
521 } | 480 } |
522 | 481 if (!urlVariant || urlVariant->vt != VT_BSTR) |
523 // Get the IWebBrowser2 interface | 482 { |
524 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr; | 483 return; |
525 VARTYPE vt = pDispParams->rgvarg[6].vt; | 484 } |
526 if (vt == VT_DISPATCH) | 485 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); |
527 { | 486 UnescapeUrl(url); |
528 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; | 487 |
529 } | 488 //Register a mime filter if it's not registered yet |
530 else | 489 if (s_mimeFilter == nullptr) |
531 { | 490 { |
532 // Wrong type, return. | 491 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
533 return; | 492 } |
534 } | 493 // If webbrowser2 is equal to top level browser (as set in SetSite), we are |
535 | 494 // navigating new page |
536 // Get the URL | 495 CPluginClient* client = CPluginClient::GetInstance(); |
537 CString url; | 496 if (url.find(L"javascript") == 0) |
538 vt = pDispParams->rgvarg[5].vt; | 497 { |
539 if (vt == VT_BYREF + VT_VARIANT) | 498 } |
540 { | 499 else if (GetBrowser().IsEqualObject(webBrowser)) |
541 url = pDispParams->rgvarg[5].pvarVal->bstrVal; | 500 { |
542 | 501 m_tab->OnNavigate(url); |
543 CPluginClient::UnescapeUrl(url); | 502 DEBUG_GENERAL( |
544 } | 503 L"========================================================================
========\n" |
545 else | 504 L"Begin main navigation url:" + url + L"\n" |
546 { | 505 L"========================================================================
========") |
547 // Wrong type, return. | |
548 return; | |
549 } | |
550 | |
551 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na
vigating new page | |
552 CPluginClient* client = CPluginClient::GetInstance(); | |
553 | |
554 if (url.Find(L"javascript") == 0) | |
555 { | |
556 } | |
557 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) | |
558 { | |
559 m_tab->OnNavigate(url); | |
560 | |
561 DEBUG_GENERAL(L"============================================================
====================\nBegin main navigation url:" + url + "\n===================
=============================================================") | |
562 | 506 |
563 #ifdef ENABLE_DEBUG_RESULT | 507 #ifdef ENABLE_DEBUG_RESULT |
564 CPluginDebug::DebugResultDomain(url); | 508 CPluginDebug::DebugResultDomain(url); |
565 #endif | 509 #endif |
566 | 510 UpdateStatusBar(); |
567 UpdateStatusBar(); | 511 } |
568 } | 512 else |
569 else | 513 { |
570 { | 514 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) |
571 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) | 515 m_tab->CacheFrame(url); |
572 m_tab->CacheFrame(url); | 516 } |
573 } | 517 } |
574 } | 518 catch (...) |
575 | 519 { |
576 /* | 520 } |
577 * #1163 implements behavior for method DISPID_WINDOWSTATECHANGED in CPluginClas
s::Invoke | 521 } |
578 * - should validate and convert arguments in Invoke, not here | 522 |
579 * - does not validate number of arguments before indexing into 'rgvarg' | 523 // Entry point |
580 * - does not validate type of argument before using its value | 524 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() |
581 */ | |
582 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) | |
583 { | |
584 DEBUG_GENERAL("Tab changed"); | |
585 bool newtabshown = pDispParams->rgvarg[1].intVal==3; | |
586 if (newtabshown) | |
587 { | |
588 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge
tCurrentThreadId()); | |
589 if (it == s_threadInstances.end()) | |
590 { | |
591 s_threadInstances[::GetCurrentThreadId()] = this; | |
592 if (!m_isInitializedOk) | |
593 { | |
594 m_isInitializedOk = true; | |
595 InitObject(true); | |
596 UpdateStatusBar(); | |
597 } | |
598 } | |
599 } | |
600 notificationMessage.Hide(); | |
601 DEBUG_GENERAL("Tab change end"); | |
602 return S_OK; | |
603 } | |
604 | |
605 // This gets called whenever there's a browser event | |
606 // ENTRY POINT | |
607 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W
ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo,
UINT* puArgErr) | |
608 { | 525 { |
609 try | 526 try |
610 { | 527 { |
611 WCHAR tmp[256]; | 528 DEBUG_NAVI(L"Navi::Download Complete") |
612 wsprintf(tmp, L"Invoke: %d\n", dispidMember); | 529 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); |
613 DEBUG_GENERAL(tmp); | 530 if (browser) |
614 switch (dispidMember) | 531 { |
615 { | 532 m_tab->OnDownloadComplete(browser); |
616 case DISPID_WINDOWSTATECHANGED: | 533 } |
617 { | 534 } |
618 // #1163 should validate and convert arguments here | 535 catch (...) |
619 return OnTabChanged(pDispParams, wFlags); | 536 { |
620 } | 537 } |
621 | 538 } |
622 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE: | 539 |
623 break; | 540 // Entry point |
624 | 541 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD
isp, VARIANT* /*urlOrPidl*/) |
625 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK: | 542 { |
626 break; | 543 try |
627 | 544 { |
628 case DISPID_EVMETH_ONLOAD: | 545 DEBUG_NAVI(L"Navi::Document Complete"); |
629 DEBUG_NAVI("Navi::OnLoad") | 546 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; |
630 break; | 547 if (!webBrowser2) |
631 | 548 { |
632 case DISPID_EVMETH_ONCHANGE: | 549 return; |
633 break; | 550 } |
634 | 551 std::wstring frameSrc = GetLocationUrl(*webBrowser2); |
635 case DISPID_EVMETH_ONMOUSEDOWN: | 552 UnescapeUrl(frameSrc); |
636 break; | 553 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); |
637 | 554 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser); |
638 case DISPID_EVMETH_ONMOUSEENTER: | 555 } |
639 break; | 556 catch (...) |
640 | 557 { |
641 case DISPID_IHTMLIMGELEMENT_START: | 558 } |
642 break; | 559 } |
643 | 560 |
644 case STDDISPID_XOBJ_ERRORUPDATE: | 561 // Entry point |
645 break; | 562 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) |
646 | 563 { |
647 case STDDISPID_XOBJ_ONPROPERTYCHANGE: | 564 try |
648 break; | 565 { |
649 | 566 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); |
650 case DISPID_READYSTATECHANGE: | 567 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) |
651 DEBUG_NAVI("Navi::ReadyStateChange"); | 568 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA
BLED); |
652 break; | 569 if (newtabshown) |
653 | 570 { |
654 case DISPID_BEFORENAVIGATE: | 571 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(
GetCurrentThreadId()); |
655 DEBUG_NAVI("Navi::BeforeNavigate"); | 572 if (it == s_threadInstances.end()) |
656 break; | 573 { |
657 | 574 s_threadInstances[::GetCurrentThreadId()] = this; |
658 case DISPID_COMMANDSTATECHANGE: | 575 if (!m_isInitializedOk) |
659 if (m_hPaneWnd == NULL) | 576 { |
660 { | 577 m_isInitializedOk = true; |
661 CreateStatusBarPane(); | 578 InitObject(); |
662 } | 579 UpdateStatusBar(); |
663 else | 580 } |
664 { | 581 } |
| 582 } |
| 583 notificationMessage.Hide(); |
| 584 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end"); |
| 585 } |
| 586 catch (...) |
| 587 { |
| 588 } |
| 589 } |
| 590 |
| 591 // Entry point |
| 592 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI
ANT_BOOL /*enable*/) |
| 593 { |
| 594 try |
| 595 { |
| 596 if (m_hPaneWnd == NULL) |
| 597 { |
| 598 CreateStatusBarPane(); |
| 599 } |
| 600 else |
| 601 { |
665 if (AdblockPlus::IE::InstalledMajorVersion() > 6) | 602 if (AdblockPlus::IE::InstalledMajorVersion() > 6) |
666 { | 603 { |
667 RECT rect; | 604 RECT rect; |
668 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); | 605 //Get the RECT for the leftmost pane (the status text pane) |
669 if (rectRes == TRUE) | 606 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&re
ct); |
670 { | 607 if (rectRes == TRUE) |
671 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.botto
m - rect.top, TRUE); | 608 { |
672 } | 609 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, rec
t.bottom - rect.top, TRUE); |
673 } | 610 } |
674 } | 611 } |
675 break; | 612 } |
676 | 613 } |
677 case DISPID_STATUSTEXTCHANGE: | 614 catch (...) |
678 break; | 615 { |
679 | 616 } |
680 case DISPID_BEFORENAVIGATE2: | 617 } |
681 { | 618 |
682 // #1163 should validate and convert parameters here | 619 // Entry point |
683 BeforeNavigate2(pDispParams); | 620 void STDMETHODCALLTYPE CPluginClass::OnOnQuit() |
684 } | 621 { |
685 break; | 622 try |
686 | 623 { |
687 case DISPID_DOWNLOADBEGIN: | 624 Unadvise(); |
688 { | 625 } |
689 DEBUG_NAVI("Navi::Download Begin") | 626 catch (...) |
690 } | 627 { |
691 break; | 628 } |
692 | 629 } |
693 case DISPID_DOWNLOADCOMPLETE: | 630 |
694 { | 631 bool CPluginClass::InitObject() |
695 DEBUG_NAVI("Navi::Download Complete"); | |
696 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | |
697 if (browser) | |
698 { | |
699 m_tab->OnDownloadComplete(browser); | |
700 } | |
701 } | |
702 break; | |
703 | |
704 case DISPID_DOCUMENTCOMPLETE: | |
705 { | |
706 DEBUG_NAVI("Navi::Document Complete"); | |
707 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | |
708 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V
T_DISPATCH) | |
709 { | |
710 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; | |
711 if (pBrowser) | |
712 { | |
713 CString url; | |
714 CComBSTR bstrUrl; | |
715 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen
(bstrUrl) > 0) | |
716 { | |
717 url = bstrUrl; | |
718 CPluginClient::UnescapeUrl(url); | |
719 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBro
wser)); | |
720 } | |
721 } | |
722 } | |
723 } | |
724 break; | |
725 | |
726 case DISPID_ONQUIT: | |
727 case DISPID_QUIT: | |
728 { | |
729 Unadvice(); | |
730 } | |
731 break; | |
732 | |
733 default: | |
734 { | |
735 CString did; | |
736 did.Format(L"DispId:%u", dispidMember); | |
737 | |
738 DEBUG_NAVI(L"Navi::Default " + did) | |
739 } | |
740 /* | |
741 * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND. | |
742 * As a conservative initial change, we leave it behaving as before, | |
743 * which is to do nothing and return S_OK. | |
744 */ | |
745 // do nothing | |
746 break; | |
747 } | |
748 } | |
749 catch(...) | |
750 { | |
751 DEBUG_GENERAL( "Caught unknown exception in CPluginClass::Invoke" ); | |
752 return E_FAIL; | |
753 } | |
754 return S_OK; | |
755 } | |
756 | |
757 bool CPluginClass::InitObject(bool bBHO) | |
758 { | 632 { |
759 DEBUG_GENERAL("InitObject"); | 633 DEBUG_GENERAL("InitObject"); |
760 CPluginSettings* settings = CPluginSettings::GetInstance(); | 634 CPluginSettings* settings = CPluginSettings::GetInstance(); |
761 | 635 |
762 if (!settings->GetPluginEnabled()) | 636 if (!settings->GetPluginEnabled()) |
763 { | 637 { |
764 s_mimeFilter->Unregister(); | 638 s_mimeFilter->Unregister(); |
765 } | 639 } |
766 | 640 |
767 // Load theme module | 641 // Load theme module |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 698 |
825 if (!GetAtomPaneClass()) | 699 if (!GetAtomPaneClass()) |
826 { | 700 { |
827 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE
R_PANE_CLASS, "Class::InitObject - RegisterClassEx"); | 701 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE
R_PANE_CLASS, "Class::InitObject - RegisterClassEx"); |
828 return false; | 702 return false; |
829 } | 703 } |
830 } | 704 } |
831 | 705 |
832 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); | 706 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); |
833 // Create status pane | 707 // Create status pane |
834 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) | 708 if (ieVersion > 6 && !CreateStatusBarPane()) |
835 { | 709 { |
836 return false; | 710 return false; |
837 } | 711 } |
838 | 712 |
839 s_criticalSectionLocal.Lock(); | 713 s_criticalSectionLocal.Lock(); |
840 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie
nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2"); | 714 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie
nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2"); |
841 | 715 |
842 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun(); | 716 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun(); |
843 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN
_VERSION)); | 717 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN
_VERSION)); |
844 // This is the first time ABP was installed | 718 // This is the first time ABP was installed |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, "Class
::CreateStatusBarPane - No status bar") | 842 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, "Class
::CreateStatusBarPane - No status bar") |
969 return true; | 843 return true; |
970 } | 844 } |
971 | 845 |
972 // Calculate pane height | 846 // Calculate pane height |
973 AdblockPlus::Rectangle rcStatusBar; | 847 AdblockPlus::Rectangle rcStatusBar; |
974 ::GetClientRect(hWndStatusBar, &rcStatusBar); | 848 ::GetClientRect(hWndStatusBar, &rcStatusBar); |
975 | 849 |
976 if (rcStatusBar.Height() > 0) | 850 if (rcStatusBar.Height() > 0) |
977 { | 851 { |
| 852 if (rcStatusBar.Height() < iconWidth) |
| 853 { |
| 854 iconWidth = 19; |
| 855 iconHeight = 19; |
| 856 } |
| 857 |
978 #ifdef _DEBUG | 858 #ifdef _DEBUG |
979 m_nPaneWidth = 70; | 859 m_nPaneWidth = 70; |
980 #else | 860 #else |
981 m_nPaneWidth = min(rcStatusBar.Height(), 22); | 861 m_nPaneWidth = min(rcStatusBar.Height(), iconWidth); |
982 #endif | 862 #endif |
983 } | 863 } |
984 else | 864 else |
985 { | 865 { |
986 #ifdef _DEBUG | 866 #ifdef _DEBUG |
987 m_nPaneWidth = 70; | 867 m_nPaneWidth = 70; |
988 #else | 868 #else |
989 m_nPaneWidth = 22; | 869 m_nPaneWidth = iconWidth; |
990 #endif | 870 #endif |
991 } | 871 } |
992 // Create pane window | 872 // Create pane window |
993 HWND hWndNewPane = ::CreateWindowEx( | 873 HWND hWndNewPane = ::CreateWindowEx( |
994 NULL, | 874 NULL, |
995 MAKEINTATOM(GetAtomPaneClass()), | 875 MAKEINTATOM(GetAtomPaneClass()), |
996 L"", | 876 L"", |
997 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, | 877 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, |
998 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), | 878 rcStatusBar.Width() - 500, 0, m_nPaneWidth, rcStatusBar.Height(), |
999 hWndStatusBar, | 879 hWndStatusBar, |
1000 (HMENU)3671, | 880 (HMENU)3671, |
1001 _Module.m_hInst, | 881 _Module.m_hInst, |
1002 NULL); | 882 NULL); |
1003 | 883 |
1004 if (!hWndNewPane) | 884 if (!hWndNewPane) |
1005 { | 885 { |
1006 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST
ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx") | 886 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST
ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx") |
1007 return false; | 887 return false; |
1008 } | 888 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) | 1011 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) |
1132 { | 1012 { |
1133 if (cCmds == 0) return E_INVALIDARG; | 1013 if (cCmds == 0) return E_INVALIDARG; |
1134 if (prgCmds == 0) return E_POINTER; | 1014 if (prgCmds == 0) return E_POINTER; |
1135 | 1015 |
1136 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1016 prgCmds[0].cmdf = OLECMDF_ENABLED; |
1137 | 1017 |
1138 return S_OK; | 1018 return S_OK; |
1139 } | 1019 } |
1140 | 1020 |
1141 HMENU CPluginClass::CreatePluginMenu(const CString& url) | 1021 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) |
1142 { | 1022 { |
1143 DEBUG_GENERAL("CreatePluginMenu"); | 1023 DEBUG_GENERAL("CreatePluginMenu"); |
1144 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1024 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
1145 | 1025 |
1146 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1026 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
1147 | 1027 |
1148 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); | 1028 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); |
1149 | 1029 |
1150 SetMenuBar(hMenuTrackPopup, url); | 1030 SetMenuBar(hMenuTrackPopup, url); |
1151 | 1031 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 { | 1119 { |
1240 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION
_SETTINGS, "Navigation::Failed") | 1120 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION
_SETTINGS, "Navigation::Failed") |
1241 } | 1121 } |
1242 } | 1122 } |
1243 } | 1123 } |
1244 break; | 1124 break; |
1245 } | 1125 } |
1246 case ID_MENU_DISABLE_ON_SITE: | 1126 case ID_MENU_DISABLE_ON_SITE: |
1247 { | 1127 { |
1248 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1128 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1249 CString urlString = GetTab()->GetDocumentUrl(); | 1129 std::wstring urlString = GetTab()->GetDocumentUrl(); |
1250 if (client->IsWhitelistedUrl(to_wstring(urlString))) | 1130 std::string filterText = client->GetWhitelistingFilter(urlString); |
1251 { | 1131 if (!filterText.empty()) |
1252 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w
string(urlString)))); | 1132 { |
| 1133 client->RemoveFilter(filterText); |
1253 } | 1134 } |
1254 else | 1135 else |
1255 { | 1136 { |
1256 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr
ing(urlString)))); | 1137 settings->AddWhiteListedDomain(ToCString(client->GetHostFromUrl(urlStrin
g))); |
1257 } | 1138 } |
1258 GetBrowser()->Refresh(); | 1139 GetBrowser()->Refresh(); |
1259 } | 1140 } |
1260 default: | 1141 default: |
1261 break; | 1142 break; |
1262 } | 1143 } |
1263 | 1144 |
1264 // Invalidate and redraw the control | 1145 // Invalidate and redraw the control |
1265 UpdateStatusBar(); | 1146 UpdateStatusBar(); |
1266 } | 1147 } |
1267 | 1148 |
1268 | 1149 |
1269 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) | 1150 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url) |
1270 { | 1151 { |
1271 DEBUG_GENERAL("SetMenuBar"); | 1152 DEBUG_GENERAL("SetMenuBar"); |
1272 | 1153 |
1273 std::wstring ctext; | 1154 std::wstring ctext; |
1274 Dictionary* dictionary = Dictionary::GetInstance(); | 1155 Dictionary* dictionary = Dictionary::GetInstance(); |
1275 | 1156 |
1276 MENUITEMINFOW fmii = {}; | 1157 MENUITEMINFOW fmii = {}; |
1277 fmii.cbSize = sizeof(fmii); | 1158 fmii.cbSize = sizeof(fmii); |
1278 | 1159 |
1279 MENUITEMINFOW miiSep = {}; | 1160 MENUITEMINFOW miiSep = {}; |
1280 miiSep.cbSize = sizeof(miiSep); | 1161 miiSep.cbSize = sizeof(miiSep); |
1281 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 1162 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |
1282 miiSep.fType = MFT_SEPARATOR; | 1163 miiSep.fType = MFT_SEPARATOR; |
1283 | 1164 |
1284 CPluginClient* client = CPluginClient::GetInstance(); | 1165 CPluginClient* client = CPluginClient::GetInstance(); |
1285 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1166 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1286 { | 1167 { |
1287 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 1168 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |
1288 // Is domain in white list? | 1169 // Is domain in white list? |
1289 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); | 1170 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); |
1290 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) | 1171 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) |
1291 { | 1172 { |
1292 fmii.fState = MFS_CHECKED | MFS_ENABLED; | 1173 fmii.fState = MFS_CHECKED | MFS_ENABLED; |
1293 } | 1174 } |
1294 else | 1175 else |
1295 { | 1176 { |
1296 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 1177 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |
1297 } | 1178 } |
1298 fmii.fMask = MIIM_STRING | MIIM_STATE; | 1179 fmii.fMask = MIIM_STRING | MIIM_STATE; |
1299 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1180 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1300 fmii.cch = static_cast<UINT>(ctext.size()); | 1181 fmii.cch = static_cast<UINT>(ctext.size()); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 } | 1375 } |
1495 | 1376 |
1496 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
m, lParam); | 1377 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
m, lParam); |
1497 | 1378 |
1498 | 1379 |
1499 return result; | 1380 return result; |
1500 | 1381 |
1501 } | 1382 } |
1502 | 1383 |
1503 | 1384 |
1504 HICON CPluginClass::GetStatusBarIcon(const CString& url) | 1385 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1505 { | 1386 { |
1506 // use the disable icon as defualt, if the client doesn't exists | 1387 // use the disable icon as defualt, if the client doesn't exists |
1507 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1388 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1508 | 1389 |
1509 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1390 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
1510 if (tab) | 1391 if (tab) |
1511 { | 1392 { |
1512 CPluginClient* client = CPluginClient::GetInstance(); | 1393 CPluginClient* client = CPluginClient::GetInstance(); |
1513 if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 1394 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1514 { | 1395 { |
1515 if (client->IsWhitelistedUrl(ToWstring(url))) | 1396 if (client->IsWhitelistedUrl(url)) |
1516 { | 1397 { |
1517 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1398 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1518 } | 1399 } |
1519 else | 1400 else |
1520 { | 1401 { |
1521 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1402 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1522 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 1403 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1523 } | 1404 } |
1524 } | 1405 } |
1525 } | 1406 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 } | 1475 } |
1595 } | 1476 } |
1596 } | 1477 } |
1597 } | 1478 } |
1598 | 1479 |
1599 // Draw icon | 1480 // Draw icon |
1600 if (CPluginClient::GetInstance()) | 1481 if (CPluginClient::GetInstance()) |
1601 { | 1482 { |
1602 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); | 1483 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); |
1603 | 1484 |
1604 int offx = (rcClient.Height() - 16)/2 + nDrawEdge; | 1485 int offx = nDrawEdge; |
1605 if (hIcon) | 1486 if (hIcon) |
1606 { | 1487 { |
1607 ::DrawIconEx(hDC, offx, (rcClient.Height() - 16)/2 + 2, hIcon, 16, 16,
NULL, NULL, DI_NORMAL); | 1488 //Get the RECT for the leftmost pane (the status text pane) |
1608 offx += 22; | 1489 RECT rect; |
| 1490 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (
LPARAM)&rect); |
| 1491 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW
idth, iconHeight, NULL, NULL, DI_NORMAL); |
| 1492 offx += iconWidth; |
1609 } | 1493 } |
1610 #ifdef _DEBUG | 1494 #ifdef _DEBUG |
1611 // Display version | 1495 // Display version |
1612 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT,
0, 0); | 1496 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT,
0, 0); |
1613 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); | 1497 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); |
1614 | 1498 |
1615 AdblockPlus::Rectangle rcText = rcClient; | 1499 AdblockPlus::Rectangle rcText = rcClient; |
1616 rcText.left += offx; | 1500 rcText.left += offx; |
1617 ::SetBkMode(hDC, TRANSPARENT); | 1501 ::SetBkMode(hDC, TRANSPARENT); |
1618 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT
|DT_SINGLELINE|DT_VCENTER); | 1502 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT
|DT_SINGLELINE|DT_VCENTER); |
1619 | 1503 |
1620 ::SelectObject(hDC, hOldFont); | 1504 ::SelectObject(hDC, hOldFont); |
1621 #endif // _DEBUG | 1505 #endif // _DEBUG |
1622 } | 1506 } |
1623 | 1507 |
1624 // Done! | 1508 // Done! |
1625 EndPaint(hWnd, &ps); | 1509 EndPaint(hWnd, &ps); |
1626 | 1510 |
1627 return 0; | 1511 return 0; |
1628 } | 1512 } |
1629 | 1513 |
1630 case WM_LBUTTONUP: | 1514 case WM_LBUTTONUP: |
1631 case WM_RBUTTONUP: | 1515 case WM_RBUTTONUP: |
1632 { | 1516 { |
1633 CString strURL = pClass->GetBrowserUrl(); | 1517 std::wstring url = pClass->GetBrowserUrl(); |
1634 if (strURL != pClass->GetTab()->GetDocumentUrl()) | 1518 if (url != pClass->GetTab()->GetDocumentUrl()) |
1635 { | 1519 { |
1636 pClass->GetTab()->SetDocumentUrl(strURL); | 1520 pClass->GetTab()->SetDocumentUrl(url); |
1637 } | 1521 } |
1638 | 1522 |
1639 // Create menu | 1523 // Create menu |
1640 HMENU hMenu = pClass->CreatePluginMenu(strURL); | 1524 HMENU hMenu = pClass->CreatePluginMenu(url); |
1641 if (!hMenu) | 1525 if (!hMenu) |
1642 { | 1526 { |
1643 return 0; | 1527 return 0; |
1644 } | 1528 } |
1645 | 1529 |
1646 // Display menu | 1530 // Display menu |
1647 POINT pt; | 1531 POINT pt; |
1648 ::GetCursorPos(&pt); | 1532 ::GetCursorPos(&pt); |
1649 | 1533 |
1650 RECT rc; | 1534 RECT rc; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 { | 1620 { |
1737 CreateStatusBarPane(); | 1621 CreateStatusBarPane(); |
1738 } | 1622 } |
1739 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) | 1623 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) |
1740 { | 1624 { |
1741 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
ATE_STATUSBAR, "Class::Invalidate statusbar"); | 1625 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
ATE_STATUSBAR, "Class::Invalidate statusbar"); |
1742 } | 1626 } |
1743 } | 1627 } |
1744 | 1628 |
1745 | 1629 |
1746 void CPluginClass::Unadvice() | 1630 void CPluginClass::Unadvise() |
1747 { | 1631 { |
1748 s_criticalSectionLocal.Lock(); | 1632 s_criticalSectionLocal.Lock(); |
1749 { | 1633 { |
1750 if (m_isAdviced) | 1634 if (m_isAdvised) |
1751 { | 1635 { |
1752 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); | 1636 HRESULT hr = DispEventUnadvise(GetBrowser()); |
1753 if (pPoint) | 1637 if (FAILED(hr)) |
1754 { | 1638 { |
1755 HRESULT hr = pPoint->Unadvise(m_nConnectionID); | 1639 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS
E, "Class::Unadvise - Unadvise"); |
1756 if (FAILED(hr)) | 1640 } |
1757 { | 1641 m_isAdvised = false; |
1758 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV
ICE, "Class::Unadvice - Unadvise"); | |
1759 } | |
1760 } | |
1761 | |
1762 m_isAdviced = false; | |
1763 } | 1642 } |
1764 } | 1643 } |
1765 s_criticalSectionLocal.Unlock(); | 1644 s_criticalSectionLocal.Unlock(); |
1766 } | 1645 } |
1767 | 1646 |
1768 HICON CPluginClass::GetIcon(int type) | 1647 HICON CPluginClass::GetIcon(int type) |
1769 { | 1648 { |
1770 HICON icon = NULL; | 1649 HICON icon = NULL; |
1771 | 1650 |
1772 s_criticalSectionLocal.Lock(); | 1651 s_criticalSectionLocal.Lock(); |
1773 { | 1652 { |
1774 if (!s_hIcons[type]) | 1653 if (!s_hIcons[type]) |
1775 { | 1654 { |
1776 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[
type])); | 1655 std::wstring imageToLoad = L"#"; |
| 1656 imageToLoad += std::to_wstring(s_hIconTypes[type]); |
| 1657 s_hIcons[type] = (HICON)::LoadImage(_Module.m_hInst, imageToLoad.c_str(),
IMAGE_ICON, iconWidth, iconHeight, LR_SHARED); |
1777 if (!s_hIcons[type]) | 1658 if (!s_hIcons[type]) |
1778 { | 1659 { |
1779 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_
ICON, "Class::GetIcon - LoadIcon") | 1660 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_
ICON, "Class::GetIcon - LoadIcon"); |
1780 } | 1661 } |
1781 } | 1662 } |
1782 | 1663 |
1783 icon = s_hIcons[type]; | 1664 icon = s_hIcons[type]; |
1784 } | 1665 } |
1785 s_criticalSectionLocal.Unlock(); | 1666 s_criticalSectionLocal.Unlock(); |
1786 | 1667 |
1787 return icon; | 1668 return icon; |
1788 } | 1669 } |
1789 | 1670 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 break; | 1731 break; |
1851 } | 1732 } |
1852 s_criticalSectionLocal.Unlock(); | 1733 s_criticalSectionLocal.Unlock(); |
1853 | 1734 |
1854 } | 1735 } |
1855 } | 1736 } |
1856 } | 1737 } |
1857 | 1738 |
1858 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 1739 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |
1859 } | 1740 } |
1860 | |
1861 return hTabWnd; | 1741 return hTabWnd; |
1862 | 1742 } |
1863 } | |
LEFT | RIGHT |