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

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

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

Powered by Google App Engine
This is Rietveld