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

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

Issue 29330403: Issue #1467, #3397 - Rewrite the map from threads to tabs (Closed)
Left Patch Set: Created Nov. 22, 2015, 8:17 p.m.
Right Patch Set: add comment; new function body Created July 17, 2016, 4:01 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
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 61
62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; 62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal;
63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; 63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow;
64 64
65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; 65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2;
66 66
67 67 namespace
68 /** 68 {
69 * A synchronized map whose key is always the current thread ID. 69 /**
70 */ 70 * A synchronized map whose key is always the current thread ID.
71 class CurrentThreadMap 71 */
72 : public SyncMap<DWORD, CPluginClass*, nullptr> 72 class CurrentThreadMap
73 { 73 : public SyncMap<DWORD, CPluginClass*, nullptr>
74 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base; 74 {
75 75 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base;
76 public: 76
77 bool AddIfAbsent(CPluginClass* p) 77 public:
78 { 78 bool AddIfAbsent(CPluginClass* p)
79 return Base::AddIfAbsent(::GetCurrentThreadId(), p); 79 {
80 } 80 return Base::AddIfAbsent(::GetCurrentThreadId(), p);
81 81 }
82 bool RemoveAndCheck() 82
83 { 83 bool RemoveAndCheck()
84 return Base::RemoveAndCheck(::GetCurrentThreadId()); 84 {
85 } 85 return Base::RemoveIfPresent(::GetCurrentThreadId());
86 86 }
87 CPluginClass* Locate() 87
88 { 88 CPluginClass* Locate()
89 return Base::Locate(::GetCurrentThreadId()); 89 {
90 } 90 return Base::Locate(::GetCurrentThreadId());
91 }; 91 }
92 92 };
93 /** 93
94 * Map from thread ID's to CPluginClass instances 94 /**
95 */ 95 * Map from thread ID's to CPluginClass instances
96 CurrentThreadMap threadMap; 96 */
97 CurrentThreadMap threadMap;
98 }
97 99
98 /* 100 /*
99 * Without namespace declaration, the identifier "Rectangle" is ambiguous 101 * Without namespace declaration, the identifier "Rectangle" is ambiguous
100 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx 102 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx
101 */ 103 */
102 namespace AdblockPlus 104 namespace AdblockPlus
103 { 105 {
104 /** 106 /**
105 * Replacement for ATL type CRect. 107 * Replacement for ATL type CRect.
106 */ 108 */
107 class Rectangle 109 class Rectangle
108 : public RECT 110 : public RECT
109 { 111 {
110 public: 112 public:
111 int Height() const 113 unsigned long Height() const
112 { 114 {
113 return bottom - top; 115 if (bottom < top)
114 } 116 {
115 117 throw std::runtime_error("invariant violation: rectangle bottom < top");
116 int Width() const 118 }
117 { 119 return static_cast<unsigned long>(bottom - top);
118 return right - left; 120 }
121
122 unsigned long Width() const
123 {
124 if (right < left)
125 {
126 throw std::runtime_error("invariant violation: rectangle right < left");
127 }
128 return static_cast<unsigned long>(right - left);
119 } 129 }
120 }; 130 };
121 } 131 }
122 132
123 CPluginClass::CPluginClass() 133 CPluginClass::CPluginClass()
124 : m_webBrowser2(nullptr) 134 : m_webBrowser2(nullptr)
125 { 135 {
136 DEBUG_GENERAL([this]() -> std::wstring
137 {
138 std::wstring s = L"CPluginClass::<constructor>, this = ";
139 s += ToHexLiteral(this);
140 return s;
141 }());
142
126 //Use this line to debug memory leaks 143 //Use this line to debug memory leaks
127 // _CrtDumpMemoryLeaks(); 144 // _CrtDumpMemoryLeaks();
128 145
129 m_isAdvised = false; 146 m_isAdvised = false;
130 m_hTabWnd = NULL; 147 m_hTabWnd = NULL;
131 m_hStatusBarWnd = NULL; 148 m_hStatusBarWnd = NULL;
132 m_hPaneWnd = NULL; 149 m_hPaneWnd = NULL;
133 m_nPaneWidth = 0; 150 m_nPaneWidth = 0;
134 m_pWndProcStatus = NULL; 151 m_pWndProcStatus = NULL;
135 m_hTheme = NULL; 152 m_hTheme = NULL;
136 m_isInitializedOk = false; 153 m_isInitializedOk = false;
137 m_tab = new CPluginTab(this); 154 m_tab = new CPluginTab();
138 Dictionary::Create(GetBrowserLanguage()); 155 Dictionary::Create(GetBrowserLanguage());
139 } 156 }
140 157
141 CPluginClass::~CPluginClass() 158 CPluginClass::~CPluginClass()
142 { 159 {
160 DEBUG_GENERAL([this]() -> std::wstring
161 {
162 std::wstring s = L"CPluginClass::<destructor>, this = ";
163 s += ToHexLiteral(this);
164 return s;
165 }());
166
143 delete m_tab; 167 delete m_tab;
144 } 168 }
145 169
146 HWND CPluginClass::GetBrowserHWND() const 170 HWND CPluginClass::GetBrowserHWND() const
147 { 171 {
148 if (!m_webBrowser2) 172 if (!m_webBrowser2)
149 { 173 {
150 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr"); 174 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr");
151 return nullptr; 175 return nullptr;
152 } 176 }
153 SHANDLE_PTR hBrowserWndHandle; 177 SHANDLE_PTR hBrowserWndHandle = 0;
154 HRESULT hr = m_webBrowser2->get_HWND(&hBrowserWndHandle); 178 HRESULT hr = m_webBrowser2->get_HWND(&hBrowserWndHandle);
155 if (FAILED(hr)) 179 if (FAILED(hr))
156 { 180 {
157 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed") 181 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed");
182 return nullptr;
158 } 183 }
159 return (HWND)hBrowserWndHandle; 184 return (HWND)hBrowserWndHandle;
160 } 185 }
161 186
162 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser) 187 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser)
163 { 188 {
164 return m_webBrowser2.IsEqualObject(otherBrowser); 189 return m_webBrowser2.IsEqualObject(otherBrowser);
165 } 190 }
166 191
167 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() 192 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
168 { 193 {
169 CComQIPtr<IWebBrowser2> browser; 194 CComQIPtr<IWebBrowser2> browser;
170 195
171 s_criticalSectionLocal.Lock(); 196 s_criticalSectionLocal.Lock();
172 { 197 {
173 browser = s_asyncWebBrowser2; 198 browser = s_asyncWebBrowser2;
174 } 199 }
175 s_criticalSectionLocal.Unlock(); 200 s_criticalSectionLocal.Unlock();
176 201
177 return browser; 202 return browser;
178 } 203 }
179 204
180 std::wstring CPluginClass::GetBrowserUrl() const 205 std::wstring CPluginClass::GetBrowserUrl() const
181 { 206 {
182 std::wstring url; 207 std::wstring url;
183 if (m_webBrowser2) 208 if (m_webBrowser2)
184 { 209 {
185 CComBSTR bstrURL; 210 CComBSTR bstrURL;
186 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL) 211 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)))
187 { 212 {
188 url = std::wstring(bstrURL, SysStringLen(bstrURL)); 213 url = ToWstring(bstrURL);
189 UnescapeUrl(url);
190 } 214 }
191 } 215 }
192 else 216 else
193 { 217 {
194 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr owser2 == nullptr"); 218 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with m_webBrowser2 == nullptr (probable invariant violation)");
219 }
220 if (url.empty())
221 {
195 url = m_tab->GetDocumentUrl(); 222 url = m_tab->GetDocumentUrl();
196 } 223 }
197 return url; 224 return url;
198 } 225 }
199 226
200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 227 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
201 { 228 {
202 if (thisPtr == NULL) 229 if (thisPtr == NULL)
203 return 0; 230 return 0;
204 if (!((CPluginClass*)thisPtr)->InitObject()) 231 if (!((CPluginClass*)thisPtr)->InitObject())
(...skipping 13 matching lines...) Expand all
218 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE 245 * '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, 246 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor,
220 * but it is not a proper substitute for one. 247 * but it is not a proper substitute for one.
221 */ 248 */
222 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 249 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
223 { 250 {
224 try 251 try
225 { 252 {
226 if (unknownSite) 253 if (unknownSite)
227 { 254 {
228 255 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================");
229 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
230 256
231 HRESULT hr = ::CoInitialize(NULL); 257 HRESULT hr = ::CoInitialize(NULL);
232 if (FAILED(hr)) 258 if (FAILED(hr))
233 { 259 {
234 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 260 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
235 } 261 }
236 262
237 /* 263 /*
238 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2. 264 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2.
239 */ 265 */
240 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); 266 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite);
241 if (!m_webBrowser2) 267 if (!m_webBrowser2)
242 { 268 {
243 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*"); 269 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*");
244 } 270 }
271 DEBUG_GENERAL([this]() -> std::wstring
272 {
273 std::wstringstream ss;
274 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
275 ss << L", browser = " << ToHexLiteral(m_webBrowser2);
276 return ss.str();
277 }());
245 278
246 /* 279 /*
247 * Add ourselves to the thread map. 280 * Add ourselves to the thread map.
248 */ 281 */
249 if (!threadMap.AddIfAbsent(this)) 282 if (!threadMap.AddIfAbsent(this))
250 { 283 {
251 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi ng entry in thread map"); 284 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi ng entry in thread map");
252 } 285 }
253 286
254 //register the mimefilter 287 //register the mimefilter
255 //and only mimefilter 288 //and only mimefilter
256 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 289 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
257 s_criticalSectionLocal.Lock(); 290 s_criticalSectionLocal.Lock();
258 { 291 {
259 // Always register on startup, then check if we need to unregister in a separate thread 292 // Always register on startup, then check if we need to unregister in a separate thread
260 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 293 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
261 s_asyncWebBrowser2 = unknownSite; 294 s_asyncWebBrowser2 = unknownSite;
262 s_instances.insert(this); 295 s_instances.insert(this);
263 } 296 }
264 s_criticalSectionLocal.Unlock(); 297 s_criticalSectionLocal.Unlock();
265 298
266 try 299 try
267 { 300 {
268 DEBUG_GENERAL("Loaded as BHO");
269 HRESULT hr = DispEventAdvise(m_webBrowser2); 301 HRESULT hr = DispEventAdvise(m_webBrowser2);
270 if (SUCCEEDED(hr)) 302 if (SUCCEEDED(hr))
271 { 303 {
272 m_isAdvised = true; 304 m_isAdvised = true;
273 try 305 try
274 { 306 {
275 std::thread startInitObjectThread(StartInitObject, this); 307 std::thread startInitObjectThread(StartInitObject, this);
276 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr. 308 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
277 } 309 }
278 catch (const std::system_error& ex) 310 catch (const std::system_error& ex)
279 { 311 {
280 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, 312 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS,
281 "Class::Thread - Failed to create StartInitObject thread"); 313 "Class::Thread - Failed to create StartInitObject thread");
282 } 314 }
283 } 315 }
284 else 316 else
285 { 317 {
286 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise"); 318 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
287 } 319 }
288 } 320 }
289 catch (const std::runtime_error& ex) 321 catch (const std::runtime_error& ex)
290 { 322 {
291 DEBUG_EXCEPTION(ex); 323 DEBUG_EXCEPTION(ex);
292 Unadvise(); 324 Unadvise();
293 } 325 }
294 } 326 }
295 else 327 else
296 { 328 {
329 DEBUG_GENERAL([this]() -> std::wstring
330 {
331 std::wstringstream ss;
332 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
333 ss << L", browser = nullptr";
334 return ss.str();
335 }());
336
297 Unadvise(); 337 Unadvise();
298 338
299 // Destroy window 339 // Destroy window
300 if (m_pWndProcStatus) 340 if (m_pWndProcStatus)
301 { 341 {
302 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus); 342 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus);
303 343
304 m_pWndProcStatus = NULL; 344 m_pWndProcStatus = NULL;
305 } 345 }
306 346
(...skipping 18 matching lines...) Expand all
325 s_criticalSectionLocal.Lock(); 365 s_criticalSectionLocal.Lock();
326 { 366 {
327 s_instances.erase(this); 367 s_instances.erase(this);
328 if (s_instances.empty()) 368 if (s_instances.empty())
329 { 369 {
330 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 370 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
331 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 371 CPluginClientFactory::ReleaseMimeFilterClientInstance();
332 } 372 }
333 } 373 }
334 s_criticalSectionLocal.Unlock(); 374 s_criticalSectionLocal.Unlock();
375
376 m_webBrowser2 = nullptr;
335 377
336 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 378 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
337 379
338 ::CoUninitialize(); 380 ::CoUninitialize();
339 } 381 }
340 382
341 } 383 }
342 catch (...) 384 catch (...)
343 { 385 {
344 } 386 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 { 515 {
474 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; 516 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
475 if (!webBrowser) 517 if (!webBrowser)
476 { 518 {
477 return; 519 return;
478 } 520 }
479 if (!urlVariant || urlVariant->vt != VT_BSTR) 521 if (!urlVariant || urlVariant->vt != VT_BSTR)
480 { 522 {
481 return; 523 return;
482 } 524 }
483 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); 525 std::wstring url = ToWstring(urlVariant->bstrVal);
484 UnescapeUrl(url);
485 526
486 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 527 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
487 // navigating new page 528 // navigating new page
488 CPluginClient* client = CPluginClient::GetInstance(); 529 CPluginClient* client = CPluginClient::GetInstance();
489 if (url.find(L"javascript") == 0) 530 if (url.find(L"javascript") == 0)
490 { 531 {
491 } 532 }
492 else if (IsRootBrowser(webBrowser)) 533 else if (IsRootBrowser(webBrowser))
493 { 534 {
494 m_tab->OnNavigate(url); 535 m_tab->OnNavigate(url);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 { 577 {
537 try 578 try
538 { 579 {
539 DEBUG_NAVI(L"Navi::Document Complete"); 580 DEBUG_NAVI(L"Navi::Document Complete");
540 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; 581 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
541 if (!webBrowser2) 582 if (!webBrowser2)
542 { 583 {
543 return; 584 return;
544 } 585 }
545 std::wstring frameSrc = GetLocationUrl(*webBrowser2); 586 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
546 UnescapeUrl(frameSrc);
547 m_tab->OnDocumentComplete(webBrowser2, frameSrc, IsRootBrowser(webBrowser2)) ; 587 m_tab->OnDocumentComplete(webBrowser2, frameSrc, IsRootBrowser(webBrowser2)) ;
548 } 588 }
549 catch (...) 589 catch (...)
550 { 590 {
551 } 591 }
552 } 592 }
553 593
554 // Entry point 594 // Entry point
555 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 595 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
556 { 596 {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 s_criticalSectionLocal.Unlock(); 1017 s_criticalSectionLocal.Unlock();
978 1018
979 return result; 1019 return result;
980 } 1020 }
981 1021
982 CPluginTab* CPluginClass::GetTab() 1022 CPluginTab* CPluginClass::GetTab()
983 { 1023 {
984 return m_tab; 1024 return m_tab;
985 } 1025 }
986 1026
987 CPluginTab* CPluginClass::GetTabCurrentThread() 1027 CPluginTab* CPluginClass::GetTabForCurrentThread()
988 { 1028 {
989 auto p = threadMap.Locate(); 1029 auto p = threadMap.Locate();
990 return p ? p->m_tab : nullptr; 1030 return p ? p->m_tab : nullptr;
991 } 1031 }
992 1032
993 1033 // Entry point
994 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1034 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
995 { 1035 {
996 if (cCmds == 0) return E_INVALIDARG; 1036 try
997 if (prgCmds == 0) return E_POINTER; 1037 {
998 1038 if (cCmds == 0) return E_INVALIDARG;
999 prgCmds[0].cmdf = OLECMDF_ENABLED; 1039 if (prgCmds == 0) return E_POINTER;
1000 1040
1041 prgCmds[0].cmdf = OLECMDF_ENABLED;
1042 }
1043 catch (...)
1044 {
1045 DEBUG_GENERAL(L"CPluginClass::QueryStatus - exception");
1046 return E_FAIL;
1047 }
1001 return S_OK; 1048 return S_OK;
1002 } 1049 }
1003 1050
1004 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) 1051 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
1005 { 1052 {
1006 DEBUG_GENERAL("CreatePluginMenu"); 1053 DEBUG_GENERAL("CreatePluginMenu");
1007 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1054 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1008 1055
1009 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1056 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1010 1057
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 if (FAILED(hr)) 1148 if (FAILED(hr))
1102 { 1149 {
1103 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1150 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1104 } 1151 }
1105 } 1152 }
1106 } 1153 }
1107 break; 1154 break;
1108 } 1155 }
1109 case ID_MENU_DISABLE_ON_SITE: 1156 case ID_MENU_DISABLE_ON_SITE:
1110 { 1157 {
1111 CPluginSettings* settings = CPluginSettings::GetInstance();
1112 std::wstring urlString = GetTab()->GetDocumentUrl(); 1158 std::wstring urlString = GetTab()->GetDocumentUrl();
1113 std::string filterText = client->GetWhitelistingFilter(urlString); 1159 std::string filterText = client->GetWhitelistingFilter(urlString);
1114 if (!filterText.empty()) 1160 if (!filterText.empty())
1115 { 1161 {
1116 client->RemoveFilter(filterText); 1162 client->RemoveFilter(filterText);
1117 } 1163 }
1118 else 1164 else
1119 { 1165 {
1120 settings->AddWhiteListedDomain(ToCString(client->GetHostFromUrl(urlStrin g))); 1166 CPluginSettings::GetInstance()->AddWhiteListedDomain(client->GetHostFrom Url(urlString));
1121 } 1167 }
1122 } 1168 }
1123 default: 1169 default:
1124 break; 1170 break;
1125 } 1171 }
1126 1172
1127 // Invalidate and redraw the control 1173 // Invalidate and redraw the control
1128 UpdateStatusBar(); 1174 UpdateStatusBar();
1129 } 1175 }
1130 1176
(...skipping 10 matching lines...) Expand all
1141 1187
1142 MENUITEMINFOW miiSep = {}; 1188 MENUITEMINFOW miiSep = {};
1143 miiSep.cbSize = sizeof(miiSep); 1189 miiSep.cbSize = sizeof(miiSep);
1144 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1190 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1145 miiSep.fType = MFT_SEPARATOR; 1191 miiSep.fType = MFT_SEPARATOR;
1146 1192
1147 CPluginClient* client = CPluginClient::GetInstance(); 1193 CPluginClient* client = CPluginClient::GetInstance();
1148 CPluginSettings* settings = CPluginSettings::GetInstance(); 1194 CPluginSettings* settings = CPluginSettings::GetInstance();
1149 { 1195 {
1150 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1196 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1151 // Is domain in white list?
1152 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); 1197 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url));
1153 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) 1198 /*
1154 { 1199 * The display state of the "disable on this site" menu item depends upon ta b content
1200 */
1201 if (!GetTab()->IsPossibleToDisableOnSite())
1202 {
1203 // Since we can't disable the present content,
1204 // it makes no sense to offer the user an option to block it.
1205 fmii.fState = MFS_UNCHECKED | MFS_DISABLED;
1206 }
1207 else if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl()))
1208 {
1209 // Domain is in white list, indicated by a check mark
1155 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1210 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1156 } 1211 }
1157 else 1212 else
1158 { 1213 {
1159 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1214 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1160 } 1215 }
1161 fmii.fMask = MIIM_STRING | MIIM_STATE; 1216 fmii.fMask = MIIM_STRING | MIIM_STATE;
1162 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1217 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1163 fmii.cch = static_cast<UINT>(ctext.size()); 1218 fmii.cch = static_cast<UINT>(ctext.size());
1164 1219
(...skipping 28 matching lines...) Expand all
1193 ctext = dictionary->Lookup("menu", "menu-settings"); 1248 ctext = dictionary->Lookup("menu", "menu-settings");
1194 fmii.fMask = MIIM_STATE | MIIM_STRING; 1249 fmii.fMask = MIIM_STATE | MIIM_STRING;
1195 fmii.fState = MFS_ENABLED; 1250 fmii.fState = MFS_ENABLED;
1196 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1251 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1197 fmii.cch = static_cast<UINT>(ctext.size()); 1252 fmii.cch = static_cast<UINT>(ctext.size());
1198 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); 1253 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii);
1199 1254
1200 return true; 1255 return true;
1201 } 1256 }
1202 1257
1203 1258 // Entry point
1204 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) 1259 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*)
1205 { 1260 {
1206 HWND hBrowserWnd = GetBrowserHWND(); 1261 try
1207 if (!hBrowserWnd) 1262 {
1208 { 1263 HWND hBrowserWnd = GetBrowserHWND();
1209 return E_FAIL; 1264 if (!hBrowserWnd)
1210 } 1265 {
1211 1266 return E_FAIL;
1212 // Create menu 1267 }
1213 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); 1268
1214 if (!hMenu) 1269 // Create menu
1215 { 1270 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl());
1216 return E_FAIL; 1271 if (!hMenu)
1217 } 1272 {
1218 1273 return E_FAIL;
1219 // Check if button in toolbar was pressed 1274 }
1220 int nIDCommand = -1; 1275
1221 BOOL bRightAlign = FALSE; 1276 // Check if button in toolbar was pressed
1222 1277 int nIDCommand = -1;
1223 POINT pt; 1278 BOOL bRightAlign = FALSE;
1224 GetCursorPos(&pt); 1279
1225 1280 POINT pt;
1226 HWND hWndToolBar = ::WindowFromPoint(pt); 1281 GetCursorPos(&pt);
1227 1282
1228 DWORD nProcessId; 1283 HWND hWndToolBar = ::WindowFromPoint(pt);
1229 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); 1284
1230 1285 DWORD nProcessId;
1231 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) 1286 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId);
1232 { 1287
1233 ::ScreenToClient(hWndToolBar, &pt); 1288 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId)
1234 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); 1289 {
1235 1290 ::ScreenToClient(hWndToolBar, &pt);
1236 if (nButton > 0) 1291 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt);
1237 { 1292
1238 TBBUTTON pTBBtn = {}; 1293 if (nButton > 0)
1239 1294 {
1240 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) 1295 TBBUTTON pTBBtn = {};
1241 { 1296
1242 RECT rcButton; 1297 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn))
1243 nIDCommand = pTBBtn.idCommand; 1298 {
1244 1299 RECT rcButton;
1245 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) 1300 nIDCommand = pTBBtn.idCommand;
1246 { 1301
1247 pt.x = rcButton.left; 1302 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton ))
1248 pt.y = rcButton.bottom;
1249 ClientToScreen(hWndToolBar, &pt);
1250
1251 RECT rcWorkArea;
1252 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0);
1253 if (rcWorkArea.right - pt.x < 150)
1254 { 1303 {
1255 bRightAlign = TRUE; 1304 pt.x = rcButton.left;
1256 pt.x = rcButton.right;
1257 pt.y = rcButton.bottom; 1305 pt.y = rcButton.bottom;
1258 ClientToScreen(hWndToolBar, &pt); 1306 ClientToScreen(hWndToolBar, &pt);
1307
1308 RECT rcWorkArea;
1309 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0);
1310 if (rcWorkArea.right - pt.x < 150)
1311 {
1312 bRightAlign = TRUE;
1313 pt.x = rcButton.right;
1314 pt.y = rcButton.bottom;
1315 ClientToScreen(hWndToolBar, &pt);
1316 }
1259 } 1317 }
1260 } 1318 }
1261 } 1319 }
1320 else
1321 {
1322 GetCursorPos(&pt);
1323 }
1324 }
1325
1326 // Display menu
1327 UINT nFlags = 0;
1328 if (bRightAlign)
1329 {
1330 nFlags |= TPM_RIGHTALIGN;
1262 } 1331 }
1263 else 1332 else
1264 { 1333 {
1265 GetCursorPos(&pt); 1334 nFlags |= TPM_LEFTALIGN;
1266 } 1335 }
1267 } 1336
1268 1337 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags);
1269 // Display menu 1338 }
1270 UINT nFlags = 0; 1339 catch (...)
1271 if (bRightAlign) 1340 {
1272 { 1341 // Suppress exception, log only
1273 nFlags |= TPM_RIGHTALIGN; 1342 DEBUG_GENERAL(L"CPluginClass::Exec - exception");
1274 } 1343 return E_FAIL;
1275 else 1344 }
1276 {
1277 nFlags |= TPM_LEFTALIGN;
1278 }
1279
1280 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags);
1281 1345
1282 return S_OK; 1346 return S_OK;
1283 } 1347 }
1284 1348
1285 ///////////////////////////////////////////////////////////////////////////// 1349 // Entry point
1286 // Window procedures
1287
1288 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) 1350 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam)
1289 { 1351 {
1290 // Find tab 1352 CPluginClass *pClass;
1291 CPluginClass *pClass = FindInstance(hWnd); 1353 try
1292 if (!pClass) 1354 {
1293 { 1355 // Find tab
1294 return DefWindowProc(hWnd, message, wParam, lParam); 1356 pClass = FindInstance(hWnd);
1295 } 1357 if (!pClass)
1296 1358 {
1297 // Process message 1359 /*
1298 switch (message) 1360 * Race condition if reached.
1299 { 1361 * We did not unhook the window procedure for the status bar when the last BHO instance using it terminated.
1300 case SB_SIMPLE: 1362 * The next best thing is to call the system default window function.
1301 { 1363 */
1302 ShowWindow(pClass->m_hPaneWnd, !wParam); 1364 return DefWindowProc(hWnd, message, wParam, lParam);
1365 }
1366
1367 // Process message
1368 switch (message)
1369 {
1370 case SB_SIMPLE:
1371 {
1372 ShowWindow(pClass->m_hPaneWnd, !wParam);
1373 break;
1374 }
1375
1376 case WM_SYSCOLORCHANGE:
1377 {
1378 pClass->UpdateTheme();
1379 break;
1380 }
1381
1382 case SB_SETPARTS:
1383 {
1384 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd))
1385 {
1386 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1387 }
1388
1389 WPARAM nParts = wParam;
1390 if (STATUSBAR_PANE_NUMBER >= nParts)
1391 {
1392 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1393 }
1394
1395 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1));
1396 LPINT lpParts = (LPINT)LocalLock(hLocal);
1397 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1398
1399 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1400 {
1401 lpParts[i] -= pClass->m_nPaneWidth;
1402 }
1403 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w Param, (LPARAM)lpParts);
1404
1405 AdblockPlus::Rectangle rcPane;
1406 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1407
1408 AdblockPlus::Rectangle rcClient;
1409 ::GetClientRect(hWnd, &rcClient);
1410
1411 ::MoveWindow(
1412 pClass->m_hPaneWnd,
1413 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1414 0,
1415 pClass->m_nPaneWidth,
1416 rcClient.Height(),
1417 TRUE);
1418
1419 ::LocalFree(hLocal);
1420 return hRet;
1421 }
1422
1423 default:
1303 break; 1424 break;
1304 } 1425 }
1305 1426 }
1306 case WM_SYSCOLORCHANGE: 1427 catch (...)
1307 { 1428 {
1308 pClass->UpdateTheme(); 1429 // Suppress exception. Fall through to default handler.
1309 break; 1430 DEBUG_GENERAL(L"CPluginClass::NewStatusProc - exception");
1310 } 1431 }
1311 1432 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m);
1312 case SB_SETPARTS:
1313 {
1314 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd))
1315 {
1316 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param);
1317 }
1318
1319 WPARAM nParts = wParam;
1320 if (STATUSBAR_PANE_NUMBER >= nParts)
1321 {
1322 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param);
1323 }
1324
1325 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1));
1326 LPINT lpParts = (LPINT)LocalLock(hLocal);
1327 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1328
1329 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1330 {
1331 lpParts[i] -= pClass->m_nPaneWidth;
1332 }
1333 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts);
1334
1335 AdblockPlus::Rectangle rcPane;
1336 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1337
1338 AdblockPlus::Rectangle rcClient;
1339 ::GetClientRect(hWnd, &rcClient);
1340
1341 ::MoveWindow(
1342 pClass->m_hPaneWnd,
1343 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1344 0,
1345 pClass->m_nPaneWidth,
1346 rcClient.Height(),
1347 TRUE);
1348
1349 ::LocalFree(hLocal);
1350
1351
1352 return hRet;
1353 }
1354
1355 default:
1356 break;
1357 }
1358
1359 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1360
1361
1362 return result;
1363
1364 } 1433 }
1365 1434
1366 1435
1367 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) 1436 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1368 { 1437 {
1369 // use the disable icon as defualt, if the client doesn't exists 1438 // use the disable icon as defualt, if the client doesn't exists
1370 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1439 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1371 1440
1372 CPluginTab* tab = GetTabCurrentThread(); 1441 CPluginTab* tab = GetTabForCurrentThread();
1373 if (tab) 1442 if (tab)
1374 { 1443 {
1375 CPluginClient* client = CPluginClient::GetInstance(); 1444 CPluginClient* client = CPluginClient::GetInstance();
1376 if (CPluginSettings::GetInstance()->IsPluginEnabled()) 1445 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1377 { 1446 {
1378 if (client->IsWhitelistedUrl(url)) 1447 if (client->IsWhitelistedUrl(url))
1379 { 1448 {
1380 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1449 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1381 } 1450 }
1382 else 1451 else
1383 { 1452 {
1384 CPluginSettings* settings = CPluginSettings::GetInstance(); 1453 CPluginSettings* settings = CPluginSettings::GetInstance();
1385 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1454 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1386 } 1455 }
1387 } 1456 }
1388 } 1457 }
1389 return hIcon; 1458 return hIcon;
1390 } 1459 }
1391 1460
1392 1461 // Entry point
1393 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) 1462 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam)
1394 { 1463 {
1395 // Find tab 1464 try
1396 CPluginClass *pClass = FindInstance(GetParent(hWnd)); 1465 {
1397 if (!pClass) 1466 // Find tab
1398 { 1467 CPluginClass *pClass = FindInstance(GetParent(hWnd));
1399 return ::DefWindowProc(hWnd, message, wParam, lParam); 1468 if (!pClass)
1400 } 1469 {
1401 1470 return ::DefWindowProc(hWnd, message, wParam, lParam);
1402 // Process message 1471 }
1403 switch (message) 1472
1404 { 1473 // Process message
1405 1474 switch (message)
1406 case WM_SETCURSOR: 1475 {
1407 { 1476 case WM_SETCURSOR:
1408 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); 1477 {
1409 return TRUE; 1478 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
1410 } 1479 return TRUE;
1411 case WM_PAINT: 1480 }
1412 { 1481 case WM_PAINT:
1413 PAINTSTRUCT ps; 1482 {
1414 HDC hDC = ::BeginPaint(hWnd, &ps); 1483 PAINTSTRUCT ps;
1415 1484 HDC hDC = ::BeginPaint(hWnd, &ps);
1416 AdblockPlus::Rectangle rcClient; 1485
1417 ::GetClientRect(hWnd, &rcClient); 1486 AdblockPlus::Rectangle rcClient;
1418 1487 ::GetClientRect(hWnd, &rcClient);
1419 int nDrawEdge = 0; 1488
1420 1489 int nDrawEdge = 0;
1421 // Old Windows background drawing 1490
1422 if (pClass->m_hTheme == NULL) 1491 // Old Windows background drawing
1423 { 1492 if (pClass->m_hTheme == NULL)
1424 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); 1493 {
1425 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); 1494 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1));
1426 1495 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT);
1427 nDrawEdge = 3; 1496
1428 rcClient.left += 3; 1497 nDrawEdge = 3;
1429 1498 rcClient.left += 3;
1430 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); 1499
1431 } 1500 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT);
1432 // Themed background drawing 1501 }
1433 else 1502 // Themed background drawing
1434 { 1503 else
1435 // Draw background 1504 {
1436 if (pfnDrawThemeBackground) 1505 // Draw background
1437 { 1506 if (pfnDrawThemeBackground)
1438 AdblockPlus::Rectangle rc = rcClient;
1439 rc.right -= 2;
1440 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1441 }
1442
1443 // Copy separator picture to left side
1444 int nHeight = rcClient.Height();
1445 int nWidth = rcClient.Width() - 2;
1446
1447 for (int i = 0; i < 2; i++)
1448 {
1449 for (int j = 0; j < nHeight; j++)
1450 { 1507 {
1451 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); 1508 AdblockPlus::Rectangle rc = rcClient;
1452 1509 rc.right -= 2;
1453 // Ignore black boxes (if source is obscured by other windows) 1510 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1454 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) 1511 }
1512
1513 // Copy separator picture to left side
1514 int nHeight = rcClient.Height();
1515 int nWidth = rcClient.Width() - 2;
1516
1517 for (int i = 0; i < 2; i++)
1518 {
1519 for (int j = 0; j < nHeight; j++)
1455 { 1520 {
1456 ::SetPixel(hDC, i, j, clr); 1521 COLORREF clr = ::GetPixel(hDC, i + nWidth, j);
1522
1523 // Ignore black boxes (if source is obscured by other windows)
1524 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB Value(clr) > 8))
1525 {
1526 ::SetPixel(hDC, i, j, clr);
1527 }
1457 } 1528 }
1458 } 1529 }
1459 } 1530 }
1460 } 1531
1461 1532 // Draw icon
1462 // Draw icon 1533 if (CPluginClient::GetInstance())
1463 if (CPluginClient::GetInstance()) 1534 {
1464 { 1535 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1465 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); 1536
1466 1537 int offx = nDrawEdge;
1467 int offx = nDrawEdge; 1538 if (hIcon)
1468 if (hIcon) 1539 {
1469 { 1540 //Get the RECT for the leftmost pane (the status text pane)
1470 //Get the RECT for the leftmost pane (the status text pane) 1541 RECT rect;
1542 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&rect);
1543 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico nWidth, iconHeight, NULL, NULL, DI_NORMAL);
1544 offx += iconWidth;
1545 }
1546 #ifdef _DEBUG
1547 // Display version
1548 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT , 0, 0);
1549 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont);
1550
1551 AdblockPlus::Rectangle rcText = rcClient;
1552 rcText.left += offx;
1553 ::SetBkMode(hDC, TRANSPARENT);
1554 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_ LEFT | DT_SINGLELINE | DT_VCENTER);
1555
1556 ::SelectObject(hDC, hOldFont);
1557 #endif // _DEBUG
1558 }
1559
1560 // Done!
1561 EndPaint(hWnd, &ps);
1562
1563 return 0;
1564 }
1565
1566 case WM_LBUTTONUP:
1567 case WM_RBUTTONUP:
1568 {
1569 std::wstring url = pClass->GetBrowserUrl();
1570 if (url != pClass->GetTab()->GetDocumentUrl())
1571 {
1572 pClass->GetTab()->SetDocumentUrl(url);
1573 }
1574
1575 // Create menu
1576 HMENU hMenu = pClass->CreatePluginMenu(url);
1577 if (!hMenu)
1578 {
1579 return 0;
1580 }
1581
1582 // Display menu
1583 POINT pt;
1584 ::GetCursorPos(&pt);
1585
1586 RECT rc;
1587 ::GetWindowRect(hWnd, &rc);
1588
1589 if (rc.left >= 0 && rc.top >= 0)
1590 {
1591 pt.x = rc.left;
1592 pt.y = rc.top;
1593 }
1594
1595 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN );
1596 break;
1597 }
1598 case WM_DESTROY:
1599 break;
1600 case SC_CLOSE:
1601 break;
1602
1603 case WM_UPDATEUISTATE:
1604 {
1605 CPluginTab* tab = GetTabForCurrentThread();
1606 if (tab)
1607 {
1608 tab->OnActivate();
1471 RECT rect; 1609 RECT rect;
1472 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, ( LPARAM)&rect); 1610 GetWindowRect(pClass->m_hPaneWnd, &rect);
1473 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW idth, iconHeight, NULL, NULL, DI_NORMAL); 1611 pClass->notificationMessage.MoveToCenter(rect);
1474 offx += iconWidth; 1612 }
1475 } 1613 if (LOWORD(wParam) == UIS_CLEAR)
1476 #ifdef _DEBUG 1614 {
1477 // Display version 1615 pClass->notificationMessage.Hide();
1478 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1616 }
1479 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); 1617 break;
1480 1618 }
1481 AdblockPlus::Rectangle rcText = rcClient; 1619 case WM_WINDOWPOSCHANGING:
1482 rcText.left += offx; 1620 {
1483 ::SetBkMode(hDC, TRANSPARENT);
1484 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER);
1485
1486 ::SelectObject(hDC, hOldFont);
1487 #endif // _DEBUG
1488 }
1489
1490 // Done!
1491 EndPaint(hWnd, &ps);
1492
1493 return 0;
1494 }
1495
1496 case WM_LBUTTONUP:
1497 case WM_RBUTTONUP:
1498 {
1499 std::wstring url = pClass->GetBrowserUrl();
1500 if (url != pClass->GetTab()->GetDocumentUrl())
1501 {
1502 pClass->GetTab()->SetDocumentUrl(url);
1503 }
1504
1505 // Create menu
1506 HMENU hMenu = pClass->CreatePluginMenu(url);
1507 if (!hMenu)
1508 {
1509 return 0;
1510 }
1511
1512 // Display menu
1513 POINT pt;
1514 ::GetCursorPos(&pt);
1515
1516 RECT rc;
1517 ::GetWindowRect(hWnd, &rc);
1518
1519 if (rc.left >= 0 && rc.top >= 0)
1520 {
1521 pt.x = rc.left;
1522 pt.y = rc.top;
1523 }
1524
1525 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN);
1526 }
1527 break;
1528 case WM_DESTROY:
1529 break;
1530 case SC_CLOSE:
1531 break;
1532
1533 case WM_UPDATEUISTATE:
1534 {
1535 CPluginTab* tab = GetTabCurrentThread();
1536 if (tab)
1537 {
1538 tab->OnActivate();
1539 RECT rect; 1621 RECT rect;
1540 GetWindowRect(pClass->m_hPaneWnd, &rect); 1622 GetWindowRect(pClass->m_hPaneWnd, &rect);
1541 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); 1623 if (pClass->notificationMessage.IsVisible())
1542 } 1624 {
1543 if (LOWORD(wParam) == UIS_CLEAR) 1625 pClass->notificationMessage.MoveToCenter(rect);
1544 { 1626 }
1545 pClass->notificationMessage.Hide(); 1627 break;
1546 } 1628 }
1547 } 1629 case WM_WINDOWPOSCHANGED:
1548 break; 1630 {
1549 case WM_WINDOWPOSCHANGING: 1631 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam);
1550 { 1632 if (wndPos->flags & SWP_HIDEWINDOW)
1551 RECT rect; 1633 {
1552 GetWindowRect(pClass->m_hPaneWnd, &rect); 1634 pClass->notificationMessage.Hide();
1553 if (pClass->notificationMessage.IsVisible()) 1635 }
1554 { 1636 break;
1555 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); 1637 }
1556 } 1638 case WM_ALREADY_UP_TO_DATE:
1557 } 1639 {
1558 break; 1640 Dictionary* dictionary = Dictionary::GetInstance();
1559 case WM_WINDOWPOSCHANGED: 1641 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread y-up-to-date-text");
1560 { 1642 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea dy-up-to-date-title");
1561 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); 1643 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TTI_INFO);
1562 if (wndPos->flags & SWP_HIDEWINDOW) 1644 break;
1563 { 1645 }
1564 pClass->notificationMessage.Hide(); 1646 case WM_UPDATE_CHECK_ERROR:
1565 } 1647 {
1566 } 1648 Dictionary* dictionary = Dictionary::GetInstance();
1567 break; 1649 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex t");
1568 case WM_ALREADY_UP_TO_DATE: 1650 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti tle");
1569 { 1651 pClass->notificationMessage.SetTextAndIcon(errorText, errorTitle, TTI_ER ROR);
1570 Dictionary* dictionary = Dictionary::GetInstance(); 1652 break;
1571 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); 1653 }
1572 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title"); 1654 case WM_DOWNLOADING_UPDATE:
1573 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT I_INFO); 1655 {
1574 } 1656 Dictionary* dictionary = Dictionary::GetInstance();
1575 break; 1657 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin g-update-text");
1576 case WM_UPDATE_CHECK_ERROR: 1658 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi ng-update-title");
1577 { 1659 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT itle, TTI_INFO);
1578 Dictionary* dictionary = Dictionary::GetInstance(); 1660 break;
1579 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); 1661 }
1580 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); 1662 }
1581 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR ); 1663 }
1582 } 1664 catch (...)
1583 break; 1665 {
1584 case WM_DOWNLOADING_UPDATE: 1666 // Suppress exception. Fall through to default handler.
1585 { 1667 DEBUG_GENERAL(L"CPluginClass::PaneWindowProc - exception");
1586 Dictionary* dictionary = Dictionary::GetInstance(); 1668 }
1587 std::wstring downloadingText = dictionary->Lookup("updater", "downloading- update-text"); 1669 return ::DefWindowProc(hWnd, message, wParam, lParam);
1588 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading -update-title");
1589 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit le, TTI_INFO);
1590 }
1591 break;
1592 }
1593
1594 return DefWindowProc(hWnd, message, wParam, lParam);
1595 } 1670 }
1596 1671
1597 1672
1598 void CPluginClass::UpdateStatusBar() 1673 void CPluginClass::UpdateStatusBar()
1599 { 1674 {
1600 DEBUG_GENERAL("*** Updating statusbar") 1675 DEBUG_GENERAL("*** Updating statusbar")
1601 if (m_hPaneWnd == NULL) 1676 if (m_hPaneWnd == NULL)
1602 { 1677 {
1603 CreateStatusBarPane(); 1678 CreateStatusBarPane();
1604 } 1679 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 s_criticalSectionLocal.Unlock(); 1728 s_criticalSectionLocal.Unlock();
1654 1729
1655 return icon; 1730 return icon;
1656 } 1731 }
1657 1732
1658 ATOM CPluginClass::GetAtomPaneClass() 1733 ATOM CPluginClass::GetAtomPaneClass()
1659 { 1734 {
1660 return s_atomPaneClass; 1735 return s_atomPaneClass;
1661 } 1736 }
1662 1737
LEFTRIGHT

Powered by Google App Engine
This is Rietveld