Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/plugin/PluginClass.cpp

Issue 4937147073167360: Issue 1672 - Subscribe and listen COM events using ATL::IDispEventImpl and BEGIN_SINK_MAP (Closed)
Left Patch Set: Created Dec. 8, 2014, 12:19 p.m.
Right Patch Set: rebase, parent = 5d5eb4df1bf2 Created March 13, 2015, 3:20 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginClass.h ('k') | src/plugin/PluginErrorCodes.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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"
33 #include "../shared/IE_version.h"
16 #include <thread> 34 #include <thread>
17 #include <array> 35 #include <array>
18 36
19 #ifdef DEBUG_HIDE_EL 37 #ifdef DEBUG_HIDE_EL
20 DWORD profileTime = 0; 38 DWORD profileTime = 0;
21 #endif 39 #endif
22 40
23 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); 41 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR);
24 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT); 42 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT);
25 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); 43 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE);
26 44
27 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; 45 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL };
28 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;
29 49
30 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; 50 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL;
31 51
32 CLOSETHEMEDATA pfnClose = NULL; 52 CLOSETHEMEDATA pfnClose = NULL;
33 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; 53 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL;
34 OPENTHEMEDATA pfnOpenThemeData = NULL; 54 OPENTHEMEDATA pfnOpenThemeData = NULL;
35 55
36 ATOM CPluginClass::s_atomPaneClass = NULL; 56 ATOM CPluginClass::s_atomPaneClass = NULL;
37 HINSTANCE CPluginClass::s_hUxtheme = NULL; 57 HINSTANCE CPluginClass::s_hUxtheme = NULL;
38 std::set<CPluginClass*> CPluginClass::s_instances; 58 std::set<CPluginClass*> CPluginClass::s_instances;
39 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; 59 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances;
40 60
41 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; 61 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal;
42 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser; 62 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser;
43 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; 63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow;
44 64
45 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; 65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2;
46 std::map<UINT,CString> CPluginClass::s_menuDomains;
47 66
48 /* 67 /*
49 * Without namespace declaration, the identifier "Rectangle" is ambiguous 68 * Without namespace declaration, the identifier "Rectangle" is ambiguous
50 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx 69 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx
51 */ 70 */
52 namespace AdblockPlus 71 namespace AdblockPlus
53 { 72 {
54 /** 73 /**
55 * Replacement for ATL type CRect. 74 * Replacement for ATL type CRect.
56 */ 75 */
(...skipping 11 matching lines...) Expand all
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_hTabWnd = NULL; 98 m_hTabWnd = NULL;
80 m_hStatusBarWnd = NULL; 99 m_hStatusBarWnd = NULL;
81 m_hPaneWnd = NULL; 100 m_hPaneWnd = NULL;
82 m_nPaneWidth = 0; 101 m_nPaneWidth = 0;
83 m_pWndProcStatus = NULL; 102 m_pWndProcStatus = NULL;
84 m_hTheme = NULL; 103 m_hTheme = NULL;
85 m_isInitializedOk = false; 104 m_isInitializedOk = false;
86 105
87 106
88 m_tab = new CPluginTab(this); 107 m_tab = new CPluginTab(this);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 170
152 s_criticalSectionLocal.Lock(); 171 s_criticalSectionLocal.Lock();
153 { 172 {
154 browser = s_asyncWebBrowser2; 173 browser = s_asyncWebBrowser2;
155 } 174 }
156 s_criticalSectionLocal.Unlock(); 175 s_criticalSectionLocal.Unlock();
157 176
158 return browser; 177 return browser;
159 } 178 }
160 179
161 CString CPluginClass::GetBrowserUrl() const 180 std::wstring CPluginClass::GetBrowserUrl() const
162 { 181 {
163 CString url; 182 std::wstring url;
164
165 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 183 CComQIPtr<IWebBrowser2> browser = GetBrowser();
166 if (browser) 184 if (browser)
167 { 185 {
168 CComBSTR bstrURL; 186 CComBSTR bstrURL;
169 187 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL)
170 if (SUCCEEDED(browser->get_LocationURL(&bstrURL))) 188 {
171 { 189 url = std::wstring(bstrURL, SysStringLen(bstrURL));
172 url = bstrURL; 190 UnescapeUrl(url);
173 CPluginClient::UnescapeUrl(url);
174 } 191 }
175 } 192 }
176 else 193 else
177 { 194 {
178 url = m_tab->GetDocumentUrl(); 195 url = m_tab->GetDocumentUrl();
179 } 196 }
180
181 return url; 197 return url;
182 } 198 }
183 199
184 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
185 { 201 {
186 if (thisPtr == NULL) 202 if (thisPtr == NULL)
187 return 0; 203 return 0;
188 if (!((CPluginClass*)thisPtr)->InitObject(true)) 204 if (!((CPluginClass*)thisPtr)->InitObject(true))
189 { 205 {
190 ((CPluginClass*)thisPtr)->Unadvice(); 206 ((CPluginClass*)thisPtr)->Unadvise();
191 } 207 }
192 208
193 return 0; 209 return 0;
194 } 210 }
195
196
197 211
198 // This gets called when a new browser window is created (which also triggers th e 212 // This gets called when a new browser window is created (which also triggers th e
199 // creation of this object). The pointer passed in should be to a IWebBrowser2 213 // creation of this object). The pointer passed in should be to a IWebBrowser2
200 // interface that represents the browser for the window. 214 // interface that represents the browser for the window.
201 // it is also called when a tab is closed, this unknownSite will be null 215 // it is also called when a tab is closed, this unknownSite will be null
202 // so we should handle that it is called this way several times during a session 216 // so we should handle that it is called this way several times during a session
203 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 217 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
204 { 218 {
205 CPluginSettings* settings = CPluginSettings::GetInstance(); 219 CPluginSettings* settings = CPluginSettings::GetInstance();
206 220
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 try 253 try
240 { 254 {
241 // Check if loaded as BHO 255 // Check if loaded as BHO
242 auto webBrowser = GetBrowser(); 256 auto webBrowser = GetBrowser();
243 if (webBrowser) 257 if (webBrowser)
244 { 258 {
245 DEBUG_GENERAL("Loaded as BHO"); 259 DEBUG_GENERAL("Loaded as BHO");
246 HRESULT hr = DispEventAdvise(webBrowser); 260 HRESULT hr = DispEventAdvise(webBrowser);
247 if (SUCCEEDED(hr)) 261 if (SUCCEEDED(hr))
248 { 262 {
249 m_isAdviced = true; 263 m_isAdvised = true;
Oleksandr 2015/01/09 00:02:17 NIT: m_isAdvised. I know it was my spelling mistak
250 try 264 try
251 { 265 {
252 std::thread startInitObjectThread(StartInitObject, this); 266 std::thread startInitObjectThread(StartInitObject, this);
253 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr. 267 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
254 } 268 }
255 catch (const std::system_error& ex) 269 catch (const std::system_error& ex)
256 { 270 {
257 auto errDescription = std::string("Class::Thread - Failed to create StartInitObject thread, ") + 271 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS,
258 ex.code().message() + ex.what(); 272 "Class::Thread - Failed to create StartInitObject thread");
259 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR _MAIN_THREAD_CREATE_PROCESS, errDescription.c_str());
260 } 273 }
261 } 274 }
262 else 275 else
263 { 276 {
264 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advice"); 277 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
265 } 278 }
266 } 279 }
267 else // Check if loaded as toolbar handler 280 else // Check if loaded as toolbar handler
268 { 281 {
269 DEBUG_GENERAL("Loaded as toolbar handler"); 282 DEBUG_GENERAL("Loaded as toolbar handler");
270 CComPtr<IServiceProvider> pServiceProvider; 283 CComPtr<IServiceProvider> pServiceProvider;
271 284
272 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); 285 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider);
273 if (SUCCEEDED(hr)) 286 if (SUCCEEDED(hr))
274 { 287 {
(...skipping 16 matching lines...) Expand all
291 } 304 }
292 s_criticalSectionBrowser.Unlock(); 305 s_criticalSectionBrowser.Unlock();
293 } 306 }
294 } 307 }
295 else 308 else
296 { 309 {
297 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); 310 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)");
298 } 311 }
299 } 312 }
300 } 313 }
301 catch (std::runtime_error e) 314 catch (const std::runtime_error& ex)
302 { 315 {
303 DEBUG_ERROR(e.what()); 316 DEBUG_EXCEPTION(ex);
304 Unadvice(); 317 Unadvise();
305 } 318 }
306 } 319 }
307 else 320 else
308 { 321 {
309 // Unadvice 322 Unadvise();
310 Unadvice();
311 323
312 // Destroy window 324 // Destroy window
313 if (m_pWndProcStatus) 325 if (m_pWndProcStatus)
314 { 326 {
315 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP rocStatus); 327 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP rocStatus);
316 328
317 m_pWndProcStatus = NULL; 329 m_pWndProcStatus = NULL;
318 } 330 }
319 331
320 if (m_hPaneWnd) 332 if (m_hPaneWnd)
(...skipping 13 matching lines...) Expand all
334 { 346 {
335 s_instances.erase(this); 347 s_instances.erase(this);
336 348
337 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId()); 349 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId());
338 if (it != s_threadInstances.end()) 350 if (it != s_threadInstances.end())
339 { 351 {
340 s_threadInstances.erase(it); 352 s_threadInstances.erase(it);
341 } 353 }
342 if (s_instances.empty()) 354 if (s_instances.empty())
343 { 355 {
356 // TODO: Explicitly releasing a resource when a container becomes empty looks like a job better suited for shared_ptr
344 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 357 CPluginClientFactory::ReleaseMimeFilterClientInstance();
345 } 358 }
346 } 359 }
347 s_criticalSectionLocal.Unlock(); 360 s_criticalSectionLocal.Unlock();
348 361
349 // Release browser interface 362 // Release browser interface
350 s_criticalSectionBrowser.Lock(); 363 s_criticalSectionBrowser.Lock();
351 { 364 {
352 m_webBrowser2.Release(); 365 m_webBrowser2.Release();
353 } 366 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 480 }
468 } 481 }
469 else 482 else
470 { 483 {
471 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state"); 484 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
472 } 485 }
473 } 486 }
474 DEBUG_GENERAL("ShowStatusBar end"); 487 DEBUG_GENERAL("ShowStatusBar end");
475 } 488 }
476 489
490 // Entry point
477 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2( 491 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2(
478 /* [in] */ IDispatch* frameBrowserDisp, 492 /* [in] */ IDispatch* frameBrowserDisp,
479 /* [in] */ VARIANT* urlVariant, 493 /* [in] */ VARIANT* urlVariant,
480 /* [in] */ VARIANT* /*Flags*/, 494 /* [in] */ VARIANT* /*Flags*/,
481 /* [in] */ VARIANT* /*TargetFrameName*/, 495 /* [in] */ VARIANT* /*TargetFrameName*/,
482 /* [in] */ VARIANT* /*PostData*/, 496 /* [in] */ VARIANT* /*PostData*/,
483 /* [in] */ VARIANT* /*Headers*/, 497 /* [in] */ VARIANT* /*Headers*/,
484 /* [in, out] */ VARIANT_BOOL* /*Cancel*/) 498 /* [in, out] */ VARIANT_BOOL* /*Cancel*/)
485 { 499 {
486 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; 500 try
487 if (!webBrowser) 501 {
488 { 502 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
489 return; 503 if (!webBrowser)
490 } 504 {
491 505 return;
492 if (!urlVariant || urlVariant->vt != VT_BSTR) 506 }
493 { 507 if (!urlVariant || urlVariant->vt != VT_BSTR)
494 return; 508 {
495 } 509 return;
496 std::wstring url(V_BSTR(urlVariant), SysStringLen(V_BSTR(urlVariant))); 510 }
Oleksandr 2015/01/09 00:02:17 I would prefer minimizing the amount of macros we
sergei 2015/01/09 16:10:30 Sure, fine for me, fixed.
497 UnescapeUrl(url); 511 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
498 512 UnescapeUrl(url);
499 //Register a mime filter if it's not registered yet 513
500 if (s_mimeFilter == NULL) 514 //Register a mime filter if it's not registered yet
501 { 515 if (s_mimeFilter == nullptr)
502 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 516 {
503 } 517 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
504 518 }
505 CString urlCString = ToCString(url); 519 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
506 520 // navigating new page
507 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page 521 CPluginClient* client = CPluginClient::GetInstance();
508 CPluginClient* client = CPluginClient::GetInstance(); 522 if (url.find(L"javascript") == 0)
509 523 {
510 if (urlCString.Find(L"javascript") == 0) 524 }
511 { 525 else if (GetBrowser().IsEqualObject(webBrowser))
512 } 526 {
513 else if (GetBrowser().IsEqualObject(webBrowser)) 527 m_tab->OnNavigate(url);
514 { 528 DEBUG_GENERAL(
515 m_tab->OnNavigate(urlCString); 529 L"======================================================================== ========\n"
516 530 L"Begin main navigation url:" + url + L"\n"
517 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + urlCString + "\n============ ====================================================================") 531 L"======================================================================== ========")
518 532
519 #ifdef ENABLE_DEBUG_RESULT 533 #ifdef ENABLE_DEBUG_RESULT
520 CPluginDebug::DebugResultDomain(urlCString); 534 CPluginDebug::DebugResultDomain(url);
521 #endif 535 #endif
522 536 UpdateStatusBar();
523 UpdateStatusBar(); 537 }
524 } 538 else
525 else 539 {
526 { 540 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
527 DEBUG_NAVI(L"Navi::Begin navigation url:" + urlCString) 541 m_tab->CacheFrame(url);
528 m_tab->CacheFrame(urlCString); 542 }
529 } 543 }
530 } 544 catch (...)
531 545 {
532 void STDMETHODCALLTYPE CPluginClass::OnDownloadBegin() 546 }
533 { 547 }
534 DEBUG_NAVI("Navi::Download Begin") 548
535 } 549 // Entry point
536
537 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() 550 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
538 { 551 {
539 DEBUG_NAVI("Navi::Download Complete") 552 try
540 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); 553 {
541 if (browser) 554 DEBUG_NAVI(L"Navi::Download Complete")
542 { 555 ATL::CComPtr<IWebBrowser2> browser = GetBrowser();
543 m_tab->OnDownloadComplete(browser); 556 if (browser)
544 } 557 {
545 } 558 m_tab->OnDownloadComplete(browser);
546 559 }
560 }
561 catch (...)
562 {
563 }
564 }
565
566 // Entry point
547 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/) 567 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
548 { 568 {
549 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; 569 try
550 if (!webBrowser2) 570 {
551 { 571 DEBUG_NAVI(L"Navi::Document Complete");
552 return; 572 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
553 } 573 if (!webBrowser2)
554 ATL::CString frameSrc; 574 {
555 ATL::CComBSTR locationUrl; 575 return;
556 if (FAILED(webBrowser2->get_LocationURL(&locationUrl)) && !!locationUrl) 576 }
557 { 577 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
558 return; 578 UnescapeUrl(frameSrc);
559 } 579 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2);
560 frameSrc = locationUrl; 580 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
561 CPluginClient::UnescapeUrl(frameSrc); 581 }
562 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); 582 catch (...)
563 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser); 583 {
564 } 584 }
565 585 }
586
587 // Entry point
566 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 588 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
567 { 589 {
568 DEBUG_GENERAL("Tab changed"); 590 try
569 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLEC MDIDF_WINDOWSTATE_ENABLED) 591 {
570 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WIN DOWSTATE_ENABLED); 592 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)");
571 if (newtabshown) 593 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED)
572 { 594 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA BLED);
573 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); 595 if (newtabshown)
574 if (it == s_threadInstances.end()) 596 {
575 { 597 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find( GetCurrentThreadId());
576 s_threadInstances[::GetCurrentThreadId()] = this; 598 if (it == s_threadInstances.end())
577 if (!m_isInitializedOk) 599 {
578 { 600 s_threadInstances[::GetCurrentThreadId()] = this;
579 m_isInitializedOk = true; 601 if (!m_isInitializedOk)
580 if (!InitObject(true)) 602 {
581 { 603 m_isInitializedOk = true;
582 //» » » » » Unadvice(); 604 InitObject(true);
583 } 605 UpdateStatusBar();
584 UpdateStatusBar(); 606 }
585 } 607 }
586 } 608 }
587 } 609 notificationMessage.Hide();
588 notificationMessage.Hide(); 610 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end");
589 DEBUG_GENERAL("Tab change end"); 611 }
590 } 612 catch (...)
591 613 {
614 }
615 }
616
617 // Entry point
592 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/) 618 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/)
Oleksandr 2015/01/09 00:02:17 Is there any reason why parameter names are commen
593 { 619 {
594 if (m_hPaneWnd == NULL) 620 try
595 { 621 {
596 CreateStatusBarPane(); 622 if (m_hPaneWnd == NULL)
597 } 623 {
598 else 624 CreateStatusBarPane();
599 { 625 }
600 if (CPluginClient::GetInstance()->GetIEVersion() > 6) 626 else
601 { 627 {
602 RECT rect; 628 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
603 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); 629 {
604 if (rectRes == TRUE) 630 RECT rect;
605 { 631 //Get the RECT for the leftmost pane (the status text pane)
606 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom - rect.top, TRUE); 632 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&re ct);
607 } 633 if (rectRes == TRUE)
608 } 634 {
635 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, rec t.bottom - rect.top, TRUE);
636 }
637 }
638 }
639 }
640 catch (...)
641 {
642 }
643 }
644
645 // Entry point
646 void STDMETHODCALLTYPE CPluginClass::OnOnQuit()
647 {
648 try
649 {
650 Unadvise();
651 }
652 catch (...)
653 {
609 } 654 }
610 } 655 }
611 656
612 bool CPluginClass::InitObject(bool bBHO) 657 bool CPluginClass::InitObject(bool bBHO)
613 { 658 {
614 DEBUG_GENERAL("InitObject"); 659 DEBUG_GENERAL("InitObject");
615 CPluginSettings* settings = CPluginSettings::GetInstance(); 660 CPluginSettings* settings = CPluginSettings::GetInstance();
616 661
617 if (!settings->GetPluginEnabled()) 662 if (!settings->GetPluginEnabled())
618 { 663 {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 722 }
678 s_criticalSectionLocal.Unlock(); 723 s_criticalSectionLocal.Unlock();
679 724
680 if (!GetAtomPaneClass()) 725 if (!GetAtomPaneClass())
681 { 726 {
682 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx"); 727 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx");
683 return false; 728 return false;
684 } 729 }
685 } 730 }
686 731
687 732 int ieVersion = AdblockPlus::IE::InstalledMajorVersion();
688 int ieVersion = CPluginClient::GetInstance()->GetIEVersion();
689 // Create status pane 733 // Create status pane
690 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) 734 if (bBHO && ieVersion > 6 && !CreateStatusBarPane())
691 { 735 {
692 return false; 736 return false;
693 } 737 }
694 738
695 s_criticalSectionLocal.Lock(); 739 s_criticalSectionLocal.Lock();
696 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2"); 740 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2");
697 741
698 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun(); 742 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, "Class ::CreateStatusBarPane - No status bar") 868 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, "Class ::CreateStatusBarPane - No status bar")
825 return true; 869 return true;
826 } 870 }
827 871
828 // Calculate pane height 872 // Calculate pane height
829 AdblockPlus::Rectangle rcStatusBar; 873 AdblockPlus::Rectangle rcStatusBar;
830 ::GetClientRect(hWndStatusBar, &rcStatusBar); 874 ::GetClientRect(hWndStatusBar, &rcStatusBar);
831 875
832 if (rcStatusBar.Height() > 0) 876 if (rcStatusBar.Height() > 0)
833 { 877 {
878 if (rcStatusBar.Height() < iconWidth)
879 {
880 iconWidth = 19;
881 iconHeight = 19;
882 }
883
834 #ifdef _DEBUG 884 #ifdef _DEBUG
835 m_nPaneWidth = 70; 885 m_nPaneWidth = 70;
836 #else 886 #else
837 m_nPaneWidth = min(rcStatusBar.Height(), 22); 887 m_nPaneWidth = min(rcStatusBar.Height(), iconWidth);
838 #endif 888 #endif
839 } 889 }
840 else 890 else
841 { 891 {
842 #ifdef _DEBUG 892 #ifdef _DEBUG
843 m_nPaneWidth = 70; 893 m_nPaneWidth = 70;
844 #else 894 #else
845 m_nPaneWidth = 22; 895 m_nPaneWidth = iconWidth;
846 #endif 896 #endif
847 } 897 }
848 // Create pane window 898 // Create pane window
849 HWND hWndNewPane = ::CreateWindowEx( 899 HWND hWndNewPane = ::CreateWindowEx(
850 NULL, 900 NULL,
851 MAKEINTATOM(GetAtomPaneClass()), 901 MAKEINTATOM(GetAtomPaneClass()),
852 L"", 902 L"",
853 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 903 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
854 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), 904 rcStatusBar.Width() - 500, 0, m_nPaneWidth, rcStatusBar.Height(),
855 hWndStatusBar, 905 hWndStatusBar,
856 (HMENU)3671, 906 (HMENU)3671,
857 _Module.m_hInst, 907 _Module.m_hInst,
858 NULL); 908 NULL);
859 909
860 if (!hWndNewPane) 910 if (!hWndNewPane)
861 { 911 {
862 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx") 912 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx")
863 return false; 913 return false;
864 } 914 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1037 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
988 { 1038 {
989 if (cCmds == 0) return E_INVALIDARG; 1039 if (cCmds == 0) return E_INVALIDARG;
990 if (prgCmds == 0) return E_POINTER; 1040 if (prgCmds == 0) return E_POINTER;
991 1041
992 prgCmds[0].cmdf = OLECMDF_ENABLED; 1042 prgCmds[0].cmdf = OLECMDF_ENABLED;
993 1043
994 return S_OK; 1044 return S_OK;
995 } 1045 }
996 1046
997 HMENU CPluginClass::CreatePluginMenu(const CString& url) 1047 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
998 { 1048 {
999 DEBUG_GENERAL("CreatePluginMenu"); 1049 DEBUG_GENERAL("CreatePluginMenu");
1000 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1050 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1001 1051
1002 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1052 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1003 1053
1004 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); 1054 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);
1005 1055
1006 SetMenuBar(hMenuTrackPopup, url); 1056 SetMenuBar(hMenuTrackPopup, url);
1007 1057
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 break; 1126 break;
1077 case ID_MENU_SETTINGS: 1127 case ID_MENU_SETTINGS:
1078 { 1128 {
1079 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 1129 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1080 if (browser) 1130 if (browser)
1081 { 1131 {
1082 VARIANT vFlags; 1132 VARIANT vFlags;
1083 vFlags.vt = VT_I4; 1133 vFlags.vt = VT_I4;
1084 vFlags.intVal = navOpenInNewTab; 1134 vFlags.intVal = navOpenInNewTab;
1085 1135
1086 BSTR urlToNavigate = BString(UserSettingsFileUrl()); 1136 auto userSettingsFileUrl = UserSettingsFileUrl();
1137 ATL::CComBSTR urlToNavigate(static_cast<int>(userSettingsFileUrl.length( )), userSettingsFileUrl.c_str());
1087 HRESULT hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL) ; 1138 HRESULT hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL) ;
1088 if (FAILED(hr)) 1139 if (FAILED(hr))
1089 { 1140 {
1090 vFlags.intVal = navOpenInNewWindow; 1141 vFlags.intVal = navOpenInNewWindow;
1091 1142
1092 hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL); 1143 hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL);
1093 if (FAILED(hr)) 1144 if (FAILED(hr))
1094 { 1145 {
1095 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1146 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1096 } 1147 }
1097 } 1148 }
1098 } 1149 }
1099 break; 1150 break;
1100 } 1151 }
1101 case ID_MENU_DISABLE_ON_SITE: 1152 case ID_MENU_DISABLE_ON_SITE:
1102 { 1153 {
1103 CPluginSettings* settings = CPluginSettings::GetInstance(); 1154 CPluginSettings* settings = CPluginSettings::GetInstance();
1104 CString urlString = GetTab()->GetDocumentUrl(); 1155 std::wstring urlString = GetTab()->GetDocumentUrl();
1105 if (client->IsWhitelistedUrl(to_wstring(urlString))) 1156 if (client->IsWhitelistedUrl(urlString))
1106 { 1157 {
1107 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w string(urlString)))); 1158 settings->RemoveWhiteListedDomain(ToCString(client->GetHostFromUrl(urlSt ring)));
1108 } 1159 }
1109 else 1160 else
1110 { 1161 {
1111 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr ing(urlString)))); 1162 settings->AddWhiteListedDomain(ToCString(client->GetHostFromUrl(urlStrin g)));
1112 } 1163 }
1113 GetBrowser()->Refresh(); 1164 GetBrowser()->Refresh();
1114 } 1165 }
1115 default: 1166 default:
1116 break; 1167 break;
1117 } 1168 }
1118 1169
1119 // Invalidate and redraw the control 1170 // Invalidate and redraw the control
1120 UpdateStatusBar(); 1171 UpdateStatusBar();
1121 } 1172 }
1122 1173
1123 1174
1124 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) 1175 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url)
1125 { 1176 {
1126 DEBUG_GENERAL("SetMenuBar"); 1177 DEBUG_GENERAL("SetMenuBar");
1127 1178
1128 std::wstring ctext; 1179 std::wstring ctext;
1129
1130 s_criticalSectionLocal.Lock();
1131 {
1132 s_menuDomains.clear();
1133 }
1134 s_criticalSectionLocal.Unlock();
1135
1136 Dictionary* dictionary = Dictionary::GetInstance(); 1180 Dictionary* dictionary = Dictionary::GetInstance();
1137 1181
1138 MENUITEMINFOW fmii = {}; 1182 MENUITEMINFOW fmii = {};
1139 fmii.cbSize = sizeof(fmii); 1183 fmii.cbSize = sizeof(fmii);
1140 1184
1141 MENUITEMINFOW miiSep = {}; 1185 MENUITEMINFOW miiSep = {};
1142 miiSep.cbSize = sizeof(miiSep); 1186 miiSep.cbSize = sizeof(miiSep);
1143 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1187 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1144 miiSep.fType = MFT_SEPARATOR; 1188 miiSep.fType = MFT_SEPARATOR;
1145 1189
1146 CPluginClient* client = CPluginClient::GetInstance(); 1190 CPluginClient* client = CPluginClient::GetInstance();
1147 CPluginSettings* settings = CPluginSettings::GetInstance(); 1191 CPluginSettings* settings = CPluginSettings::GetInstance();
1148 { 1192 {
1149 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1193 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1150 // Is domain in white list? 1194 // Is domain in white list?
1151 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); 1195 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url));
1152 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) 1196 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl()))
1153 { 1197 {
1154 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1198 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1155 } 1199 }
1156 else 1200 else
1157 { 1201 {
1158 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1202 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1159 } 1203 }
1160 fmii.fMask = MIIM_STRING | MIIM_STATE; 1204 fmii.fMask = MIIM_STRING | MIIM_STATE;
1161 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1205 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1162 fmii.cch = static_cast<UINT>(ctext.size()); 1206 fmii.cch = static_cast<UINT>(ctext.size());
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 } 1400 }
1357 1401
1358 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); 1402 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1359 1403
1360 1404
1361 return result; 1405 return result;
1362 1406
1363 } 1407 }
1364 1408
1365 1409
1366 HICON CPluginClass::GetStatusBarIcon(const CString& url) 1410 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1367 { 1411 {
1368 // use the disable icon as defualt, if the client doesn't exists 1412 // use the disable icon as defualt, if the client doesn't exists
1369 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1413 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1370 1414
1371 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1415 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1372 if (tab) 1416 if (tab)
1373 { 1417 {
1374 CPluginClient* client = CPluginClient::GetInstance(); 1418 CPluginClient* client = CPluginClient::GetInstance();
1375 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) 1419 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1376 { 1420 {
1377 } 1421 if (client->IsWhitelistedUrl(url))
1378 else if (client->IsWhitelistedUrl(to_wstring(url))) 1422 {
1379 { 1423 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1380 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1424 }
1381 } 1425 else
1382 else 1426 {
1383 { 1427 CPluginSettings* settings = CPluginSettings::GetInstance();
1384 CPluginSettings* settings = CPluginSettings::GetInstance(); 1428 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1385 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1429 }
1386 } 1430 }
1387 } 1431 }
1388 return hIcon; 1432 return hIcon;
1389 } 1433 }
1390 1434
1391 1435
1392 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) 1436 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam)
1393 { 1437 {
1394 // Find tab 1438 // Find tab
1395 CPluginClass *pClass = FindInstance(GetParent(hWnd)); 1439 CPluginClass *pClass = FindInstance(GetParent(hWnd));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 } 1500 }
1457 } 1501 }
1458 } 1502 }
1459 } 1503 }
1460 1504
1461 // Draw icon 1505 // Draw icon
1462 if (CPluginClient::GetInstance()) 1506 if (CPluginClient::GetInstance())
1463 { 1507 {
1464 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); 1508 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1465 1509
1466 int offx = (rcClient.Height() - 16)/2 + nDrawEdge; 1510 int offx = nDrawEdge;
1467 if (hIcon) 1511 if (hIcon)
1468 { 1512 {
1469 ::DrawIconEx(hDC, offx, (rcClient.Height() - 16)/2 + 2, hIcon, 16, 16, NULL, NULL, DI_NORMAL); 1513 //Get the RECT for the leftmost pane (the status text pane)
1470 offx += 22; 1514 RECT rect;
1515 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, ( LPARAM)&rect);
1516 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW idth, iconHeight, NULL, NULL, DI_NORMAL);
1517 offx += iconWidth;
1471 } 1518 }
1472 #ifdef _DEBUG 1519 #ifdef _DEBUG
1473 // Display version 1520 // Display version
1474 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1521 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0);
1475 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); 1522 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont);
1476 1523
1477 AdblockPlus::Rectangle rcText = rcClient; 1524 AdblockPlus::Rectangle rcText = rcClient;
1478 rcText.left += offx; 1525 rcText.left += offx;
1479 ::SetBkMode(hDC, TRANSPARENT); 1526 ::SetBkMode(hDC, TRANSPARENT);
1480 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER); 1527 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER);
1481 1528
1482 ::SelectObject(hDC, hOldFont); 1529 ::SelectObject(hDC, hOldFont);
1483 #endif // _DEBUG 1530 #endif // _DEBUG
1484 } 1531 }
1485 1532
1486 // Done! 1533 // Done!
1487 EndPaint(hWnd, &ps); 1534 EndPaint(hWnd, &ps);
1488 1535
1489 return 0; 1536 return 0;
1490 } 1537 }
1491 1538
1492 case WM_LBUTTONUP: 1539 case WM_LBUTTONUP:
1493 case WM_RBUTTONUP: 1540 case WM_RBUTTONUP:
1494 { 1541 {
1495 CString strURL = pClass->GetBrowserUrl(); 1542 std::wstring url = pClass->GetBrowserUrl();
1496 if (strURL != pClass->GetTab()->GetDocumentUrl()) 1543 if (url != pClass->GetTab()->GetDocumentUrl())
1497 { 1544 {
1498 pClass->GetTab()->SetDocumentUrl(strURL); 1545 pClass->GetTab()->SetDocumentUrl(url);
1499 } 1546 }
1500 1547
1501 // Create menu 1548 // Create menu
1502 HMENU hMenu = pClass->CreatePluginMenu(strURL); 1549 HMENU hMenu = pClass->CreatePluginMenu(url);
1503 if (!hMenu) 1550 if (!hMenu)
1504 { 1551 {
1505 return 0; 1552 return 0;
1506 } 1553 }
1507 1554
1508 // Display menu 1555 // Display menu
1509 POINT pt; 1556 POINT pt;
1510 ::GetCursorPos(&pt); 1557 ::GetCursorPos(&pt);
1511 1558
1512 RECT rc; 1559 RECT rc;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 { 1645 {
1599 CreateStatusBarPane(); 1646 CreateStatusBarPane();
1600 } 1647 }
1601 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1648 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1602 { 1649 {
1603 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1650 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1604 } 1651 }
1605 } 1652 }
1606 1653
1607 1654
1608 void STDMETHODCALLTYPE CPluginClass::Unadvice() 1655 void CPluginClass::Unadvise()
1609 { 1656 {
1610 s_criticalSectionLocal.Lock(); 1657 s_criticalSectionLocal.Lock();
1611 { 1658 {
1612 if (m_isAdviced) 1659 if (m_isAdvised)
1613 { 1660 {
1614 HRESULT hr = DispEventUnadvise(GetBrowser()); 1661 HRESULT hr = DispEventUnadvise(GetBrowser());
1615 if (FAILED(hr)) 1662 if (FAILED(hr))
1616 { 1663 {
1617 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIC E, "Class::Unadvice - Unadvise"); 1664 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1618 } 1665 }
1619 m_isAdviced = false; 1666 m_isAdvised = false;
1620 } 1667 }
1621 } 1668 }
1622 s_criticalSectionLocal.Unlock(); 1669 s_criticalSectionLocal.Unlock();
1623 } 1670 }
1624 1671
1625 HICON CPluginClass::GetIcon(int type) 1672 HICON CPluginClass::GetIcon(int type)
1626 { 1673 {
1627 HICON icon = NULL; 1674 HICON icon = NULL;
1628 1675
1629 s_criticalSectionLocal.Lock(); 1676 s_criticalSectionLocal.Lock();
1630 { 1677 {
1631 if (!s_hIcons[type]) 1678 if (!s_hIcons[type])
1632 { 1679 {
1633 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[ type])); 1680 std::wstring imageToLoad = L"#";
1681 imageToLoad += std::to_wstring(s_hIconTypes[type]);
1682 s_hIcons[type] = (HICON)::LoadImage(_Module.m_hInst, imageToLoad.c_str(), IMAGE_ICON, iconWidth, iconHeight, LR_SHARED);
1634 if (!s_hIcons[type]) 1683 if (!s_hIcons[type])
1635 { 1684 {
1636 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon") 1685 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon");
1637 } 1686 }
1638 } 1687 }
1639 1688
1640 icon = s_hIcons[type]; 1689 icon = s_hIcons[type];
1641 } 1690 }
1642 s_criticalSectionLocal.Unlock(); 1691 s_criticalSectionLocal.Unlock();
1643 1692
1644 return icon; 1693 return icon;
1645 } 1694 }
1646 1695
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 break; 1756 break;
1708 } 1757 }
1709 s_criticalSectionLocal.Unlock(); 1758 s_criticalSectionLocal.Unlock();
1710 1759
1711 } 1760 }
1712 } 1761 }
1713 } 1762 }
1714 1763
1715 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1764 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1716 } 1765 }
1717
1718 return hTabWnd; 1766 return hTabWnd;
1719 1767 }
1720 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld