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: fix accoring to comments without entry point Created Jan. 13, 2015, 11:42 a.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"
16 #include "../shared/IE_version.h" 33 #include "../shared/IE_version.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 111 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)->Unadvise(); 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (SUCCEEDED(hr)) 261 if (SUCCEEDED(hr))
248 { 262 {
249 m_isAdvised = true; 263 m_isAdvised = true;
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 Unadvise(); 317 Unadvise();
305 } 318 }
306 } 319 }
307 else 320 else
308 { 321 {
309 Unadvise(); 322 Unadvise();
310 323
311 // Destroy window 324 // Destroy window
312 if (m_pWndProcStatus) 325 if (m_pWndProcStatus)
313 { 326 {
(...skipping 153 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(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); 510 }
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 InitObject(true); 602 {
581 UpdateStatusBar(); 603 m_isInitializedOk = true;
582 } 604 InitObject(true);
583 } 605 UpdateStatusBar();
584 } 606 }
585 notificationMessage.Hide(); 607 }
586 DEBUG_GENERAL("Tab change end"); 608 }
587 } 609 notificationMessage.Hide();
588 610 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end");
611 }
612 catch (...)
613 {
614 }
615 }
616
617 // Entry point
589 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/) 618 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/)
590 { 619 {
591 if (m_hPaneWnd == NULL) 620 try
592 { 621 {
593 CreateStatusBarPane(); 622 if (m_hPaneWnd == NULL)
594 } 623 {
595 else 624 CreateStatusBarPane();
596 { 625 }
597 if (AdblockPlus::IE::InstalledMajorVersion() > 6) 626 else
598 { 627 {
599 RECT rect; 628 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
600 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); 629 {
601 if (rectRes == TRUE) 630 RECT rect;
602 { 631 //Get the RECT for the leftmost pane (the status text pane)
603 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);
604 } 633 if (rectRes == TRUE)
605 } 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 {
606 } 654 }
607 } 655 }
608 656
609 bool CPluginClass::InitObject(bool bBHO) 657 bool CPluginClass::InitObject(bool bBHO)
610 { 658 {
611 DEBUG_GENERAL("InitObject"); 659 DEBUG_GENERAL("InitObject");
612 CPluginSettings* settings = CPluginSettings::GetInstance(); 660 CPluginSettings* settings = CPluginSettings::GetInstance();
613 661
614 if (!settings->GetPluginEnabled()) 662 if (!settings->GetPluginEnabled())
615 { 663 {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 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")
821 return true; 869 return true;
822 } 870 }
823 871
824 // Calculate pane height 872 // Calculate pane height
825 AdblockPlus::Rectangle rcStatusBar; 873 AdblockPlus::Rectangle rcStatusBar;
826 ::GetClientRect(hWndStatusBar, &rcStatusBar); 874 ::GetClientRect(hWndStatusBar, &rcStatusBar);
827 875
828 if (rcStatusBar.Height() > 0) 876 if (rcStatusBar.Height() > 0)
829 { 877 {
878 if (rcStatusBar.Height() < iconWidth)
879 {
880 iconWidth = 19;
881 iconHeight = 19;
882 }
883
830 #ifdef _DEBUG 884 #ifdef _DEBUG
831 m_nPaneWidth = 70; 885 m_nPaneWidth = 70;
832 #else 886 #else
833 m_nPaneWidth = min(rcStatusBar.Height(), 22); 887 m_nPaneWidth = min(rcStatusBar.Height(), iconWidth);
834 #endif 888 #endif
835 } 889 }
836 else 890 else
837 { 891 {
838 #ifdef _DEBUG 892 #ifdef _DEBUG
839 m_nPaneWidth = 70; 893 m_nPaneWidth = 70;
840 #else 894 #else
841 m_nPaneWidth = 22; 895 m_nPaneWidth = iconWidth;
842 #endif 896 #endif
843 } 897 }
844 // Create pane window 898 // Create pane window
845 HWND hWndNewPane = ::CreateWindowEx( 899 HWND hWndNewPane = ::CreateWindowEx(
846 NULL, 900 NULL,
847 MAKEINTATOM(GetAtomPaneClass()), 901 MAKEINTATOM(GetAtomPaneClass()),
848 L"", 902 L"",
849 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 903 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
850 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), 904 rcStatusBar.Width() - 500, 0, m_nPaneWidth, rcStatusBar.Height(),
851 hWndStatusBar, 905 hWndStatusBar,
852 (HMENU)3671, 906 (HMENU)3671,
853 _Module.m_hInst, 907 _Module.m_hInst,
854 NULL); 908 NULL);
855 909
856 if (!hWndNewPane) 910 if (!hWndNewPane)
857 { 911 {
858 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")
859 return false; 913 return false;
860 } 914 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 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)
984 { 1038 {
985 if (cCmds == 0) return E_INVALIDARG; 1039 if (cCmds == 0) return E_INVALIDARG;
986 if (prgCmds == 0) return E_POINTER; 1040 if (prgCmds == 0) return E_POINTER;
987 1041
988 prgCmds[0].cmdf = OLECMDF_ENABLED; 1042 prgCmds[0].cmdf = OLECMDF_ENABLED;
989 1043
990 return S_OK; 1044 return S_OK;
991 } 1045 }
992 1046
993 HMENU CPluginClass::CreatePluginMenu(const CString& url) 1047 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
994 { 1048 {
995 DEBUG_GENERAL("CreatePluginMenu"); 1049 DEBUG_GENERAL("CreatePluginMenu");
996 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1050 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
997 1051
998 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1052 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
999 1053
1000 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); 1054 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);
1001 1055
1002 SetMenuBar(hMenuTrackPopup, url); 1056 SetMenuBar(hMenuTrackPopup, url);
1003 1057
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 { 1145 {
1092 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")
1093 } 1147 }
1094 } 1148 }
1095 } 1149 }
1096 break; 1150 break;
1097 } 1151 }
1098 case ID_MENU_DISABLE_ON_SITE: 1152 case ID_MENU_DISABLE_ON_SITE:
1099 { 1153 {
1100 CPluginSettings* settings = CPluginSettings::GetInstance(); 1154 CPluginSettings* settings = CPluginSettings::GetInstance();
1101 CString urlString = GetTab()->GetDocumentUrl(); 1155 std::wstring urlString = GetTab()->GetDocumentUrl();
1102 if (client->IsWhitelistedUrl(to_wstring(urlString))) 1156 if (client->IsWhitelistedUrl(urlString))
1103 { 1157 {
1104 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w string(urlString)))); 1158 settings->RemoveWhiteListedDomain(ToCString(client->GetHostFromUrl(urlSt ring)));
1105 } 1159 }
1106 else 1160 else
1107 { 1161 {
1108 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr ing(urlString)))); 1162 settings->AddWhiteListedDomain(ToCString(client->GetHostFromUrl(urlStrin g)));
1109 } 1163 }
1110 GetBrowser()->Refresh(); 1164 GetBrowser()->Refresh();
1111 } 1165 }
1112 default: 1166 default:
1113 break; 1167 break;
1114 } 1168 }
1115 1169
1116 // Invalidate and redraw the control 1170 // Invalidate and redraw the control
1117 UpdateStatusBar(); 1171 UpdateStatusBar();
1118 } 1172 }
1119 1173
1120 1174
1121 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) 1175 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url)
1122 { 1176 {
1123 DEBUG_GENERAL("SetMenuBar"); 1177 DEBUG_GENERAL("SetMenuBar");
1124 1178
1125 std::wstring ctext; 1179 std::wstring ctext;
1126 Dictionary* dictionary = Dictionary::GetInstance(); 1180 Dictionary* dictionary = Dictionary::GetInstance();
1127 1181
1128 MENUITEMINFOW fmii = {}; 1182 MENUITEMINFOW fmii = {};
1129 fmii.cbSize = sizeof(fmii); 1183 fmii.cbSize = sizeof(fmii);
1130 1184
1131 MENUITEMINFOW miiSep = {}; 1185 MENUITEMINFOW miiSep = {};
1132 miiSep.cbSize = sizeof(miiSep); 1186 miiSep.cbSize = sizeof(miiSep);
1133 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1187 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1134 miiSep.fType = MFT_SEPARATOR; 1188 miiSep.fType = MFT_SEPARATOR;
1135 1189
1136 CPluginClient* client = CPluginClient::GetInstance(); 1190 CPluginClient* client = CPluginClient::GetInstance();
1137 CPluginSettings* settings = CPluginSettings::GetInstance(); 1191 CPluginSettings* settings = CPluginSettings::GetInstance();
1138 { 1192 {
1139 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1193 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1140 // Is domain in white list? 1194 // Is domain in white list?
1141 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); 1195 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url));
1142 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) 1196 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl()))
1143 { 1197 {
1144 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1198 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1145 } 1199 }
1146 else 1200 else
1147 { 1201 {
1148 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1202 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1149 } 1203 }
1150 fmii.fMask = MIIM_STRING | MIIM_STATE; 1204 fmii.fMask = MIIM_STRING | MIIM_STATE;
1151 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1205 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1152 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
1346 } 1400 }
1347 1401
1348 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); 1402 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1349 1403
1350 1404
1351 return result; 1405 return result;
1352 1406
1353 } 1407 }
1354 1408
1355 1409
1356 HICON CPluginClass::GetStatusBarIcon(const CString& url) 1410 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1357 { 1411 {
1358 // 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
1359 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1413 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1360 1414
1361 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1415 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1362 if (tab) 1416 if (tab)
1363 { 1417 {
1364 CPluginClient* client = CPluginClient::GetInstance(); 1418 CPluginClient* client = CPluginClient::GetInstance();
1365 if (CPluginSettings::GetInstance()->IsPluginEnabled()) 1419 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1366 { 1420 {
1367 if (client->IsWhitelistedUrl(ToWstring(url))) 1421 if (client->IsWhitelistedUrl(url))
1368 { 1422 {
1369 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1423 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1370 } 1424 }
1371 else 1425 else
1372 { 1426 {
1373 CPluginSettings* settings = CPluginSettings::GetInstance(); 1427 CPluginSettings* settings = CPluginSettings::GetInstance();
1374 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1428 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1375 } 1429 }
1376 } 1430 }
1377 } 1431 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 } 1500 }
1447 } 1501 }
1448 } 1502 }
1449 } 1503 }
1450 1504
1451 // Draw icon 1505 // Draw icon
1452 if (CPluginClient::GetInstance()) 1506 if (CPluginClient::GetInstance())
1453 { 1507 {
1454 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); 1508 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1455 1509
1456 int offx = (rcClient.Height() - 16)/2 + nDrawEdge; 1510 int offx = nDrawEdge;
1457 if (hIcon) 1511 if (hIcon)
1458 { 1512 {
1459 ::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)
1460 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;
1461 } 1518 }
1462 #ifdef _DEBUG 1519 #ifdef _DEBUG
1463 // Display version 1520 // Display version
1464 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1521 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0);
1465 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); 1522 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont);
1466 1523
1467 AdblockPlus::Rectangle rcText = rcClient; 1524 AdblockPlus::Rectangle rcText = rcClient;
1468 rcText.left += offx; 1525 rcText.left += offx;
1469 ::SetBkMode(hDC, TRANSPARENT); 1526 ::SetBkMode(hDC, TRANSPARENT);
1470 ::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);
1471 1528
1472 ::SelectObject(hDC, hOldFont); 1529 ::SelectObject(hDC, hOldFont);
1473 #endif // _DEBUG 1530 #endif // _DEBUG
1474 } 1531 }
1475 1532
1476 // Done! 1533 // Done!
1477 EndPaint(hWnd, &ps); 1534 EndPaint(hWnd, &ps);
1478 1535
1479 return 0; 1536 return 0;
1480 } 1537 }
1481 1538
1482 case WM_LBUTTONUP: 1539 case WM_LBUTTONUP:
1483 case WM_RBUTTONUP: 1540 case WM_RBUTTONUP:
1484 { 1541 {
1485 CString strURL = pClass->GetBrowserUrl(); 1542 std::wstring url = pClass->GetBrowserUrl();
1486 if (strURL != pClass->GetTab()->GetDocumentUrl()) 1543 if (url != pClass->GetTab()->GetDocumentUrl())
1487 { 1544 {
1488 pClass->GetTab()->SetDocumentUrl(strURL); 1545 pClass->GetTab()->SetDocumentUrl(url);
1489 } 1546 }
1490 1547
1491 // Create menu 1548 // Create menu
1492 HMENU hMenu = pClass->CreatePluginMenu(strURL); 1549 HMENU hMenu = pClass->CreatePluginMenu(url);
1493 if (!hMenu) 1550 if (!hMenu)
1494 { 1551 {
1495 return 0; 1552 return 0;
1496 } 1553 }
1497 1554
1498 // Display menu 1555 // Display menu
1499 POINT pt; 1556 POINT pt;
1500 ::GetCursorPos(&pt); 1557 ::GetCursorPos(&pt);
1501 1558
1502 RECT rc; 1559 RECT rc;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 if (m_hPaneWnd == NULL) 1644 if (m_hPaneWnd == NULL)
1588 { 1645 {
1589 CreateStatusBarPane(); 1646 CreateStatusBarPane();
1590 } 1647 }
1591 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1648 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1592 { 1649 {
1593 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");
1594 } 1651 }
1595 } 1652 }
1596 1653
1597 void STDMETHODCALLTYPE CPluginClass::OnOnQuit()
1598 {
1599 Unadvise();
1600 }
1601 1654
1602 void CPluginClass::Unadvise() 1655 void CPluginClass::Unadvise()
1603 { 1656 {
1604 s_criticalSectionLocal.Lock(); 1657 s_criticalSectionLocal.Lock();
1605 { 1658 {
1606 if (m_isAdvised) 1659 if (m_isAdvised)
1607 { 1660 {
1608 HRESULT hr = DispEventUnadvise(GetBrowser()); 1661 HRESULT hr = DispEventUnadvise(GetBrowser());
1609 if (FAILED(hr)) 1662 if (FAILED(hr))
1610 { 1663 {
1611 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise"); 1664 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1612 } 1665 }
1613 m_isAdvised = false; 1666 m_isAdvised = false;
Eric 2015/01/13 18:44:30 If the call to DispEventUnadvise() fails, we shoul
sergei 2015/02/27 18:27:37 If it's already unadvised the value of `FAILED(hr)
1614 } 1667 }
1615 } 1668 }
1616 s_criticalSectionLocal.Unlock(); 1669 s_criticalSectionLocal.Unlock();
1617 } 1670 }
1618 1671
1619 HICON CPluginClass::GetIcon(int type) 1672 HICON CPluginClass::GetIcon(int type)
1620 { 1673 {
1621 HICON icon = NULL; 1674 HICON icon = NULL;
1622 1675
1623 s_criticalSectionLocal.Lock(); 1676 s_criticalSectionLocal.Lock();
1624 { 1677 {
1625 if (!s_hIcons[type]) 1678 if (!s_hIcons[type])
1626 { 1679 {
1627 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);
1628 if (!s_hIcons[type]) 1683 if (!s_hIcons[type])
1629 { 1684 {
1630 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");
1631 } 1686 }
1632 } 1687 }
1633 1688
1634 icon = s_hIcons[type]; 1689 icon = s_hIcons[type];
1635 } 1690 }
1636 s_criticalSectionLocal.Unlock(); 1691 s_criticalSectionLocal.Unlock();
1637 1692
1638 return icon; 1693 return icon;
1639 } 1694 }
1640 1695
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 break; 1756 break;
1702 } 1757 }
1703 s_criticalSectionLocal.Unlock(); 1758 s_criticalSectionLocal.Unlock();
1704 1759
1705 } 1760 }
1706 } 1761 }
1707 } 1762 }
1708 1763
1709 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1764 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1710 } 1765 }
1711
1712 return hTabWnd; 1766 return hTabWnd;
1713 1767 }
1714 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld