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

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

Issue 6215938672164864: [IE] Replace ATL::CRect (Closed)
Left Patch Set: Created June 25, 2014, 7:02 p.m.
Right Patch Set: hopefully final Created July 23, 2014, 4:28 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 | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginClass.h" 3 #include "PluginClass.h"
4 #include "PluginSettings.h" 4 #include "PluginSettings.h"
5 #include "PluginSystem.h" 5 #include "PluginSystem.h"
6 #ifdef SUPPORT_FILTER 6 #ifdef SUPPORT_FILTER
7 #include "PluginFilter.h" 7 #include "PluginFilter.h"
8 #endif 8 #endif
9 #include "PluginMimeFilterClient.h" 9 #include "PluginMimeFilterClient.h"
10 #include "PluginClient.h" 10 #include "PluginClient.h"
11 #include "PluginClientFactory.h" 11 #include "PluginClientFactory.h"
12 #include "PluginMutex.h" 12 #include "PluginMutex.h"
13 #include "sddl.h" 13 #include "sddl.h"
14 #include "PluginUtil.h" 14 #include "PluginUtil.h"
15 #include "PluginUserSettings.h" 15 #include "PluginUserSettings.h"
16 #include "../shared/Utils.h" 16 #include "../shared/Utils.h"
17 #include "../shared/Dictionary.h" 17 #include "../shared/Dictionary.h"
18 #include <thread> 18 #include <thread>
19 19
20 #include "COM_Client.h"
21 #include "Wrapper.h"
22
23 #ifdef DEBUG_HIDE_EL 20 #ifdef DEBUG_HIDE_EL
24 DWORD profileTime = 0; 21 DWORD profileTime = 0;
25 #endif 22 #endif
26 23
27 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); 24 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR);
28 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT); 25 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT);
29 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); 26 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE);
30 27
31 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; 28 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL };
32 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED }; 29 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED };
33 30
34 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; 31 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL;
35 32
36 CLOSETHEMEDATA pfnClose = NULL; 33 CLOSETHEMEDATA pfnClose = NULL;
37 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; 34 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL;
38 OPENTHEMEDATA pfnOpenThemeData = NULL; 35 OPENTHEMEDATA pfnOpenThemeData = NULL;
39 36
40 ATOM CPluginClass::s_atomPaneClass = NULL; 37 ATOM CPluginClass::s_atomPaneClass = NULL;
41 HINSTANCE CPluginClass::s_hUxtheme = NULL; 38 HINSTANCE CPluginClass::s_hUxtheme = NULL;
42 CSimpleArray<CPluginClass*> CPluginClass::s_instances; 39 std::set<CPluginClass*> CPluginClass::s_instances;
43 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; 40 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances;
44 41
45 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; 42 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal;
46 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser; 43 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser;
47 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; 44 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow;
48 45
49 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; 46 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2;
50 47
51 #ifdef SUPPORT_WHITELIST 48 #ifdef SUPPORT_WHITELIST
52 std::map<UINT,std::wstring> CPluginClass::s_menuDomains; 49 std::map<UINT,CString> CPluginClass::s_menuDomains;
53 #endif 50 #endif
54 51
55 //------------------------------------------------------- 52 /*
56 // Rectangle 53 * Without namespace declaration, the identifier "Rectangle" is ambiguous
57 //------------------------------------------------------- 54 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx
58 55 */
59 namespace { 56 namespace AdblockPlus
Oleksandr 2014/07/09 19:29:08 Nit: New line before {
Felix Dahlke 2014/07/24 07:24:17 This would normally be an anonymous namespace, so
60 // Without an extra namespace within the anonymous one, the identifier "Rectan gle" is ambiguous 57 {
Felix Dahlke 2014/07/10 04:49:03 Hm, guess it conflicts with this one? http://msdn
Eric 2014/07/23 11:25:05 FYI. This URL is exhibited a defect in the code re
Eric 2014/07/23 12:03:18 Well, the base class is "RECT", and it doesn't see
61 namespace Local { 58 /**
Oleksandr 2014/07/09 19:29:08 Nit: New line before {
62 /** 59 * Replacement for ATL type CRect.
63 * Replacement for ATL type CRect. 60 */
64 */ 61 class Rectangle
65 class Rectangle 62 : public RECT
66 : public RECT 63 {
67 { 64 public:
68 public: 65 int Height() const
69 // C++11 noexcept 66 {
Felix Dahlke 2014/07/10 04:49:03 I guess you're marking this so we can make it noex
Eric 2014/07/23 11:25:05 Yes.
70 inline int Height() const 67 return bottom - top;
Felix Dahlke 2014/07/10 04:49:03 inline is redundant here, since this will only be
71 { 68 }
72 return bottom - top; 69
73 } 70 int Width() const
74 71 {
75 // C++11 noexcept 72 return right - left;
76 inline int Width() const 73 }
77 { 74 };
78 return right - left; 75 }
79 } 76
80 };
81 }
82 }
83
84 //-------------------------------------------------------
85 // CPluginClass
Felix Dahlke 2014/07/10 04:49:03 We don't do class headers like this usually, I per
Oleksandr 2014/07/14 07:56:21 Visually I think it makes sense, and sometimes it'
86 //-------------------------------------------------------
87 CPluginClass::CPluginClass() 77 CPluginClass::CPluginClass()
88 { 78 {
89 //Use this line to debug memory leaks 79 //Use this line to debug memory leaks
90 // _CrtDumpMemoryLeaks(); 80 // _CrtDumpMemoryLeaks();
91 81
92 m_isAdviced = false; 82 m_isAdviced = false;
93 m_nConnectionID = 0; 83 m_nConnectionID = 0;
94 m_hTabWnd = NULL; 84 m_hTabWnd = NULL;
95 m_hStatusBarWnd = NULL; 85 m_hStatusBarWnd = NULL;
96 m_hPaneWnd = NULL; 86 m_hPaneWnd = NULL;
97 m_nPaneWidth = 0; 87 m_nPaneWidth = 0;
98 m_pWndProcStatus = NULL; 88 m_pWndProcStatus = NULL;
99 m_hTheme = NULL; 89 m_hTheme = NULL;
100 m_isInitializedOk = false; 90 m_isInitializedOk = false;
101 91
102 92
103 m_tab = new CPluginTab(this); 93 m_tab = new CPluginTab(this);
104 94
105 CPluginSystem* system = CPluginSystem::GetInstance(); 95 CPluginSystem* system = CPluginSystem::GetInstance();
106 96
107 Dictionary::Create( system->GetBrowserLanguage() ); 97 std::wstring locale((LPCWSTR)system->GetBrowserLanguage());
98 Dictionary::Create(locale);
108 } 99 }
109 100
110 CPluginClass::~CPluginClass() 101 CPluginClass::~CPluginClass()
111 { 102 {
112 delete m_tab; 103 delete m_tab;
113 } 104 }
114 105
115 106
116 ///////////////////////////////////////////////////////////////////////////// 107 /////////////////////////////////////////////////////////////////////////////
117 // Initialization 108 // Initialization
(...skipping 20 matching lines...) Expand all
138 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser()); 129 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser());
139 if (!pContainer) 130 if (!pContainer)
140 { 131 {
141 return NULL; 132 return NULL;
142 } 133 }
143 134
144 CComPtr<IConnectionPoint> pPoint; 135 CComPtr<IConnectionPoint> pPoint;
145 HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint) ; 136 HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint) ;
146 if (FAILED(hr)) 137 if (FAILED(hr))
147 { 138 {
148 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, L"Class::GetConnectionPoint - FindConnectionPoint") 139 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint")
149 return NULL; 140 return NULL;
150 } 141 }
151 142
152 return pPoint; 143 return pPoint;
153 } 144 }
154 145
155 // This method tries to get a 'connection point' from the stored browser, which can be 146 // This method tries to get a 'connection point' from the stored browser, which can be
156 // used to attach or detach from the stream of browser events 147 // used to attach or detach from the stream of browser events
157 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPointPropSink() 148 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPointPropSink()
158 { 149 {
159 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser()); 150 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser());
160 if (!pContainer) 151 if (!pContainer)
161 { 152 {
162 return NULL; 153 return NULL;
163 } 154 }
164 155
165 CComPtr<IConnectionPoint> pPoint; 156 CComPtr<IConnectionPoint> pPoint;
166 HRESULT hr = pContainer->FindConnectionPoint(IID_IPropertyNotifySink, &pPoint) ; 157 HRESULT hr = pContainer->FindConnectionPoint(IID_IPropertyNotifySink, &pPoint) ;
167 if (FAILED(hr)) 158 if (FAILED(hr))
168 { 159 {
169 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, L"Class::GetConnectionPoint - FindConnectionPoint") 160 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint")
170 return NULL; 161 return NULL;
171 } 162 }
172 163
173 return pPoint; 164 return pPoint;
174 } 165 }
175 166
176 167
177 HWND CPluginClass::GetBrowserHWND() const 168 HWND CPluginClass::GetBrowserHWND() const
178 { 169 {
179 SHANDLE_PTR hBrowserWndHandle = NULL; 170 SHANDLE_PTR hBrowserWndHandle = NULL;
180 171
181 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 172 CComQIPtr<IWebBrowser2> browser = GetBrowser();
182 if (browser) 173 if (browser)
183 { 174 {
184 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); 175 HRESULT hr = browser->get_HWND(&hBrowserWndHandle);
185 if (FAILED(hr)) 176 if (FAILED(hr))
186 { 177 {
187 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, L "Class::GetBrowserHWND - failed") 178 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, " Class::GetBrowserHWND - failed")
188 } 179 }
189 } 180 }
190 181
191 return (HWND)hBrowserWndHandle; 182 return (HWND)hBrowserWndHandle;
192 } 183 }
193 184
194 185
195 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const 186 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const
196 { 187 {
197 CComQIPtr<IWebBrowser2> browser; 188 CComQIPtr<IWebBrowser2> browser;
(...skipping 14 matching lines...) Expand all
212 203
213 s_criticalSectionLocal.Lock(); 204 s_criticalSectionLocal.Lock();
214 { 205 {
215 browser = s_asyncWebBrowser2; 206 browser = s_asyncWebBrowser2;
216 } 207 }
217 s_criticalSectionLocal.Unlock(); 208 s_criticalSectionLocal.Unlock();
218 209
219 return browser; 210 return browser;
220 } 211 }
221 212
222 std::wstring CPluginClass::GetBrowserUrl() const 213 CString CPluginClass::GetBrowserUrl() const
223 { 214 {
224 std::wstring url; 215 CString url;
225 216
226 CComQIPtr<IWebBrowser2> ccom_browser = GetBrowser(); 217 CComQIPtr<IWebBrowser2> browser = GetBrowser();
227 if (ccom_browser) 218 if (browser)
228 { 219 {
229 Wrapper::Browser browser( ccom_browser ); 220 CComBSTR bstrURL;
230 if ( browser.Location_URL( url ) ) 221
231 { 222 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)))
232 Wrapper::Unescape_URL( url ); 223 {
224 url = bstrURL;
225 CPluginClient::UnescapeUrl(url);
233 } 226 }
234 } 227 }
235 else 228 else
236 { 229 {
237 url = m_tab->GetDocumentUrl(); 230 url = m_tab->GetDocumentUrl();
238 } 231 }
232
239 return url; 233 return url;
240 } 234 }
241 235
242 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 236 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
243 { 237 {
244 if (thisPtr == NULL) 238 if (thisPtr == NULL)
245 return 0; 239 return 0;
246 if (!((CPluginClass*)thisPtr)->InitObject(true)) 240 if (!((CPluginClass*)thisPtr)->InitObject(true))
247 { 241 {
248 ((CPluginClass*)thisPtr)->Unadvice(); 242 ((CPluginClass*)thisPtr)->Unadvice();
(...skipping 11 matching lines...) Expand all
260 // so we should handle that it is called this way several times during a session 254 // so we should handle that it is called this way several times during a session
261 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 255 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
262 { 256 {
263 CPluginSettings* settings = CPluginSettings::GetInstance(); 257 CPluginSettings* settings = CPluginSettings::GetInstance();
264 CPluginSystem* system = CPluginSystem::GetInstance(); 258 CPluginSystem* system = CPluginSystem::GetInstance();
265 259
266 MULTIPLE_VERSIONS_CHECK(); 260 MULTIPLE_VERSIONS_CHECK();
267 261
268 if (unknownSite) 262 if (unknownSite)
269 { 263 {
270 std::wstring t[] = { 264
271 L"======================================================================== ========", 265 DEBUG_GENERAL(L"============================================================ ====================\nNEW TAB UI\n============================================== ==================================")
272 L"NEW TAB UI",
273 L"======================================================================== ========"
274 };
275 DEBUG_GENERAL(t);
276 266
277 HRESULT hr = ::CoInitialize(NULL); 267 HRESULT hr = ::CoInitialize(NULL);
278 if (FAILED(hr)) 268 if (FAILED(hr))
279 { 269 {
280 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, L "Class::SetSite - CoInitialize"); 270 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, " Class::SetSite - CoInitialize");
281 } 271 }
282 272
283 s_criticalSectionBrowser.Lock(); 273 s_criticalSectionBrowser.Lock();
284 { 274 {
285 m_webBrowser2 = unknownSite; 275 m_webBrowser2 = unknownSite;
286 } 276 }
287 s_criticalSectionBrowser.Unlock(); 277 s_criticalSectionBrowser.Unlock();
288 278
289 //register the mimefilter 279 //register the mimefilter
290 //and only mimefilter 280 //and only mimefilter
291 //on some few computers the mimefilter does not get properly registered when it is done on another thread 281 //on some few computers the mimefilter does not get properly registered when it is done on another thread
292 282
293 s_criticalSectionLocal.Lock(); 283 s_criticalSectionLocal.Lock();
294 { 284 {
295 // Always register on startup, then check if we need to unregister in a se parate thread 285 // Always register on startup, then check if we need to unregister in a se parate thread
296 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 286 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
297 s_asyncWebBrowser2 = unknownSite; 287 s_asyncWebBrowser2 = unknownSite;
298 s_instances.Add(this); 288 s_instances.insert(this);
299 } 289 }
300 s_criticalSectionLocal.Unlock(); 290 s_criticalSectionLocal.Unlock();
301 291
302 try 292 try
303 { 293 {
304 // Check if loaded as BHO 294 // Check if loaded as BHO
305 if (GetBrowser()) 295 if (GetBrowser())
306 { 296 {
307 DEBUG_GENERAL(L"Loaded as BHO"); 297 DEBUG_GENERAL("Loaded as BHO");
308 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 298 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint();
309 if (pPoint) 299 if (pPoint)
310 { 300 {
311 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID); 301 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID);
312 if (SUCCEEDED(hr)) 302 if (SUCCEEDED(hr))
313 { 303 {
314 m_isAdviced = true; 304 m_isAdviced = true;
315 305
316 try 306 try
317 { 307 {
318 std::thread startInitObjectThread(StartInitObject, this); 308 std::thread startInitObjectThread(StartInitObject, this);
319 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr. 309 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr.
320 } 310 }
321 catch (const std::system_error& ex) 311 catch (const std::system_error& ex)
322 { 312 {
323 std::wstring errDescription( L"Class::Thread - Failed to create St artInitObject thread, " ); 313 auto errDescription = std::string("Class::Thread - Failed to creat e StartInitObject thread, ") +
324 errDescription += ABP::debug::widen( ex.code().message() + ex.what () ); 314 ex.code().message() + ex.what();
325 DEBUG_ERROR_LOG( ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ER ROR_MAIN_THREAD_CREATE_PROCESS, errDescription ); 315 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERR OR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str());
326 } 316 }
327 } 317 }
328 else 318 else
329 { 319 {
330 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, L"Class::SetSite - Advice"); 320 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advice");
331 } 321 }
332 } 322 }
333 } 323 }
334 else // Check if loaded as toolbar handler 324 else // Check if loaded as toolbar handler
335 { 325 {
336 DEBUG_GENERAL(L"Loaded as toolbar handler"); 326 DEBUG_GENERAL("Loaded as toolbar handler");
337 CComPtr<IServiceProvider> pServiceProvider; 327 CComPtr<IServiceProvider> pServiceProvider;
338 328
339 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); 329 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider);
340 if (SUCCEEDED(hr)) 330 if (SUCCEEDED(hr))
341 { 331 {
342 if (pServiceProvider) 332 if (pServiceProvider)
343 { 333 {
344 s_criticalSectionBrowser.Lock(); 334 s_criticalSectionBrowser.Lock();
345 { 335 {
346 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, &m _webBrowser2); 336 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, &m _webBrowser2);
347 if (SUCCEEDED(hr)) 337 if (SUCCEEDED(hr))
348 { 338 {
349 if (m_webBrowser2) 339 if (m_webBrowser2)
350 { 340 {
351 InitObject(false); 341 InitObject(false);
352 } 342 }
353 } 343 }
354 else 344 else
355 { 345 {
356 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE _QUERY_BROWSER, L"Class::SetSite - QueryService (IID_IWebBrowserApp)"); 346 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE _QUERY_BROWSER, "Class::SetSite - QueryService (IID_IWebBrowserApp)");
357 } 347 }
358 } 348 }
359 s_criticalSectionBrowser.Unlock(); 349 s_criticalSectionBrowser.Unlock();
360 } 350 }
361 } 351 }
362 else 352 else
363 { 353 {
364 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, L"Class::SetSite - QueryInterface (service provider)"); 354 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)");
365 } 355 }
366 } 356 }
367 } 357 }
368 catch (std::runtime_error e) 358 catch (std::runtime_error e)
369 { 359 {
370 DEBUG_ERROR(e.what()); 360 DEBUG_ERROR(e.what());
371 Unadvice(); 361 Unadvice();
372 } 362 }
373 } 363 }
374 else 364 else
(...skipping 17 matching lines...) Expand all
392 382
393 m_hTabWnd = NULL; 383 m_hTabWnd = NULL;
394 m_hStatusBarWnd = NULL; 384 m_hStatusBarWnd = NULL;
395 385
396 // Remove instance from the list, shutdown threads 386 // Remove instance from the list, shutdown threads
397 HANDLE hMainThread = NULL; 387 HANDLE hMainThread = NULL;
398 HANDLE hTabThread = NULL; 388 HANDLE hTabThread = NULL;
399 389
400 s_criticalSectionLocal.Lock(); 390 s_criticalSectionLocal.Lock();
401 { 391 {
402 s_instances.Remove(this); 392 s_instances.erase(this);
403 393
404 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId()); 394 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId());
405 if (it != s_threadInstances.end()) 395 if (it != s_threadInstances.end())
406 { 396 {
407 s_threadInstances.erase(it); 397 s_threadInstances.erase(it);
408 } 398 }
409 if (s_instances.GetSize() == 0) 399 if (s_instances.empty())
410 { 400 {
411 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 401 CPluginClientFactory::ReleaseMimeFilterClientInstance();
412 } 402 }
413 } 403 }
414 s_criticalSectionLocal.Unlock(); 404 s_criticalSectionLocal.Unlock();
415 405
416 // Release browser interface 406 // Release browser interface
417 s_criticalSectionBrowser.Lock(); 407 s_criticalSectionBrowser.Lock();
418 { 408 {
419 m_webBrowser2.Release(); 409 m_webBrowser2.Release();
420 } 410 }
421 s_criticalSectionBrowser.Unlock(); 411 s_criticalSectionBrowser.Unlock();
422 412
423 std::wstring t[] = { 413 DEBUG_GENERAL("============================================================= ===================\nNEW TAB UI - END\n========================================= =======================================")
424 L"======================================================================== ========",
425 L"NEW TAB UI - END",
426 L"======================================================================== ========"
427 };
428 DEBUG_GENERAL( t );
429 414
430 ::CoUninitialize(); 415 ::CoUninitialize();
431 } 416 }
432 417
433 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); 418 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
434 } 419 }
435 420
436 bool CPluginClass::IsStatusBarEnabled() 421 bool CPluginClass::IsStatusBarEnabled()
437 { 422 {
438 DEBUG_GENERAL(L"IsStatusBarEnabled start"); 423 DEBUG_GENERAL("IsStatusBarEnabled start");
439 HKEY pHkey; 424 HKEY pHkey;
440 HKEY pHkeySub; 425 HKEY pHkeySub;
441 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); 426 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey);
442 DWORD trueth = 1; 427 DWORD trueth = 1;
443 DWORD truethSize = sizeof(DWORD); 428 DWORD truethSize = sizeof(DWORD);
444 RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\Main", &pHkeySub); 429 RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\Main", &pHkeySub);
445 LONG res = RegQueryValueEx(pHkeySub, L"StatusBarWeb", NULL, NULL, (BYTE*)&true th, &truethSize); 430 LONG res = RegQueryValueEx(pHkeySub, L"StatusBarWeb", NULL, NULL, (BYTE*)&true th, &truethSize);
446 RegCloseKey(pHkey); 431 RegCloseKey(pHkey);
447 if (res != ERROR_SUCCESS) 432 if (res != ERROR_SUCCESS)
448 { 433 {
449 res = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\MINIE", &p HkeySub); 434 res = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\MINIE", &p HkeySub);
450 if (res == ERROR_SUCCESS) 435 if (res == ERROR_SUCCESS)
451 { 436 {
452 LONG res = RegQueryValueEx(pHkeySub, L"ShowStatusBar", NULL, NULL, (BYTE*) &trueth, &truethSize); 437 LONG res = RegQueryValueEx(pHkeySub, L"ShowStatusBar", NULL, NULL, (BYTE*) &trueth, &truethSize);
453 if (res == ERROR_SUCCESS) 438 if (res == ERROR_SUCCESS)
454 { 439 {
455 RegCloseKey(pHkey); 440 RegCloseKey(pHkey);
456 } 441 }
457 } 442 }
458 } 443 }
459 DEBUG_GENERAL(L"IsStatusBarEnabled end"); 444 DEBUG_GENERAL("IsStatusBarEnabled end");
460 return trueth == 1; 445 return trueth == 1;
461 } 446 }
462 447
463 void CPluginClass::ShowStatusBar() 448 void CPluginClass::ShowStatusBar()
464 { 449 {
465 DEBUG_GENERAL(L"ShowStatusBar start"); 450 DEBUG_GENERAL("ShowStatusBar start");
466 451
467 VARIANT_BOOL isVisible; 452 VARIANT_BOOL isVisible;
468 453
469 454
470 CComQIPtr<IWebBrowser2> ccom_browser = GetAsyncBrowser(); 455 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
471 if (ccom_browser) 456 if (browser)
472 { 457 {
473 Wrapper::Browser browser( ccom_browser );
474 HRESULT hr = S_OK; 458 HRESULT hr = S_OK;
475 hr = ccom_browser->get_StatusBar(&isVisible); 459 hr = browser->get_StatusBar(&isVisible);
476 if (SUCCEEDED(hr)) 460 if (SUCCEEDED(hr))
477 { 461 {
478 if (!isVisible) 462 if (!isVisible)
479 { 463 {
480 SHANDLE_PTR pBrowserHWnd; 464 SHANDLE_PTR pBrowserHWnd;
481 ccom_browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd); 465 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd);
482 Dictionary* dictionary = Dictionary::GetInstance(); 466 Dictionary* dictionary = Dictionary::GetInstance();
483 467
484 HKEY pHkey; 468 HKEY pHkey;
485 HKEY pHkeySub; 469 HKEY pHkeySub;
486 LSTATUS regRes = 0; 470 LSTATUS regRes = 0;
487 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey); 471 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey);
488 472
489 // Do we have enough rights to enable a status bar? 473 // Do we have enough rights to enable a status bar?
490 if (regRes != 0) 474 if (regRes != 0)
491 { 475 {
(...skipping 11 matching lines...) Expand all
503 MB_YESNO); 487 MB_YESNO);
504 if (res == IDYES) 488 if (res == IDYES)
505 { 489 {
506 DWORD trueth = 1; 490 DWORD trueth = 1;
507 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M INIE", &pHkeySub); 491 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M INIE", &pHkeySub);
508 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE *)&trueth, sizeof(DWORD)); 492 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE *)&trueth, sizeof(DWORD));
509 regRes = RegCloseKey(pHkeySub); 493 regRes = RegCloseKey(pHkeySub);
510 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M ain", &pHkeySub); 494 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M ain", &pHkeySub);
511 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE* )&trueth, sizeof(DWORD)); 495 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE* )&trueth, sizeof(DWORD));
512 regRes = RegCloseKey(pHkeySub); 496 regRes = RegCloseKey(pHkeySub);
513 hr = ccom_browser->put_StatusBar(TRUE); 497 hr = browser->put_StatusBar(TRUE);
514 if (FAILED(hr)) 498 if (FAILED(hr))
515 { 499 {
516 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, L"Class::Enable statusbar"); 500 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, "Class::Enable statusbar");
517 } 501 }
518 CreateStatusBarPane(); 502 CreateStatusBarPane();
519 503
520 /* 504 // We need to restart the tab now, to enable the status bar properly
521 * We need to restart the tab now, to enable the status bar properly 505 VARIANT vFlags;
522 */ 506 vFlags.vt = VT_I4;
523 std::wstring location; 507 vFlags.intVal = navOpenInNewTab;
524 browser.Location_URL( location ); 508
525 HRESULT hr = browser.navigate( location ); 509 CComBSTR curLoc;
526 if ( FAILED(hr) ) 510 browser->get_LocationURL(&curLoc);
511 HRESULT hr = browser->Navigate(curLoc, &vFlags, NULL, NULL, NULL);
512 if (FAILED(hr))
527 { 513 {
528 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION , L"Navigation::Failed") 514 vFlags.intVal = navOpenInNewWindow;
515
516 hr = browser->Navigate(CComBSTR(curLoc), &vFlags, NULL, NULL, NULL);
517 if (FAILED(hr))
518 {
519 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATI ON, "Navigation::Failed")
520 }
529 } 521 }
530 ccom_browser->Quit(); 522 browser->Quit();
531 } 523 }
532 } 524 }
533 } 525 }
534 else 526 else
535 { 527 {
536 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, L"Clas s::Get statusbar state"); 528 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
537 } 529 }
538 } 530 }
539 DEBUG_GENERAL(L"ShowStatusBar end"); 531 DEBUG_GENERAL("ShowStatusBar end");
540 } 532 }
541 533
542 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) 534 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams)
543 { 535 {
544 536
545 if (pDispParams->cArgs < 7) 537 if (pDispParams->cArgs < 7)
546 { 538 {
547 return; 539 return;
548 } 540 }
549 //Register a mime filter if it's not registered yet 541 //Register a mime filter if it's not registered yet
550 if (s_mimeFilter == NULL) 542 if (s_mimeFilter == NULL)
551 { 543 {
552 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 544 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
553 } 545 }
554 546
555 // Get the IWebBrowser2 interface 547 // Get the IWebBrowser2 interface
556 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr; 548 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr;
557 VARTYPE vt = pDispParams->rgvarg[6].vt; 549 VARTYPE vt = pDispParams->rgvarg[6].vt;
558 if (vt == VT_DISPATCH) 550 if (vt == VT_DISPATCH)
559 { 551 {
560 // The implementation of this assignment operator contains the QueryInterfac e call.
561 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; 552 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal;
562 } 553 }
563 else 554 else
564 { 555 {
565 // Wrong type, return. 556 // Wrong type, return.
566 return; 557 return;
567 } 558 }
568 559
569 // Get the URL 560 // Get the URL
570 std::wstring url; 561 CString url;
571 vt = pDispParams->rgvarg[5].vt; 562 vt = pDispParams->rgvarg[5].vt;
572 if (vt == VT_BYREF + VT_VARIANT) 563 if (vt == VT_BYREF + VT_VARIANT)
573 { 564 {
574 url = pDispParams->rgvarg[5].pvarVal->bstrVal; 565 url = pDispParams->rgvarg[5].pvarVal->bstrVal;
575 Wrapper::Unescape_URL( url ); 566
567 CPluginClient::UnescapeUrl(url);
576 } 568 }
577 else 569 else
578 { 570 {
579 // Wrong type, return. 571 // Wrong type, return.
580 return; 572 return;
581 } 573 }
582 574
583 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page 575 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page
584 CPluginClient* client = CPluginClient::GetInstance(); 576 CPluginClient* client = CPluginClient::GetInstance();
585 577
586 // This comparison means "begins with" 578 if (url.Find(L"javascript") == 0)
587 if ( url.compare( 0, 10, L"javascript" ) == 0 )
588 { 579 {
589 } 580 }
590 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) 581 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr))
591 { 582 {
592 m_tab->OnNavigate( url ); 583 m_tab->OnNavigate(url);
593 584
594 std::wstring t[] = { 585 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + url + "\n=================== =============================================================")
595 L"======================================================================== ========",
596 L"Begin main navigation url:" + url,
597 L"======================================================================== ========"
598 };
599 DEBUG_GENERAL( t );
600 586
601 #ifdef ENABLE_DEBUG_RESULT 587 #ifdef ENABLE_DEBUG_RESULT
602 CPluginDebug::DebugResultDomain( url ); 588 CPluginDebug::DebugResultDomain(url);
603 #endif 589 #endif
604 590
605 UpdateStatusBar(); 591 UpdateStatusBar();
606 } 592 }
607 else 593 else
608 { 594 {
609 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 595 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
610 596
611 #ifdef SUPPORT_FRAME_CACHING 597 #ifdef SUPPORT_FRAME_CACHING
612 m_tab->CacheFrame( url ); 598 m_tab->CacheFrame(url);
613 #endif 599 #endif
614 } 600 }
615 } 601 }
616 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) 602 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags)
617 { 603 {
618 DEBUG_GENERAL(L"Tab changed"); 604 DEBUG_GENERAL("Tab changed");
619 bool newtabshown = pDispParams->rgvarg[1].intVal==3; 605 bool newtabshown = pDispParams->rgvarg[1].intVal==3;
620 if (newtabshown) 606 if (newtabshown)
621 { 607 {
622 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); 608 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId());
623 if (it == s_threadInstances.end()) 609 if (it == s_threadInstances.end())
624 { 610 {
625 s_threadInstances[::GetCurrentThreadId()] = this; 611 s_threadInstances[::GetCurrentThreadId()] = this;
626 612
627 613
628 if (!m_isInitializedOk) 614 if (!m_isInitializedOk)
629 { 615 {
630 m_isInitializedOk = true; 616 m_isInitializedOk = true;
631 if (!InitObject(true)) 617 if (!InitObject(true))
632 { 618 {
633 // Unadvice(); 619 // Unadvice();
634 } 620 }
635 UpdateStatusBar(); 621 UpdateStatusBar();
636 } 622 }
637 } 623 }
638 } 624 }
639 notificationMessage.Hide(); 625 notificationMessage.Hide();
640 DEBUG_GENERAL(L"Tab change end"); 626 DEBUG_GENERAL("Tab change end");
641 return VARIANT_TRUE; 627 return VARIANT_TRUE;
642 } 628 }
643 629
644 // This gets called whenever there's a browser event 630 // This gets called whenever there's a browser event
645 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) 631 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
646 { 632 {
647 WCHAR tmp[256]; 633 WCHAR tmp[256];
648 wsprintf(tmp, L"Invoke: %d\n", dispidMember); 634 wsprintf(tmp, L"Invoke: %d\n", dispidMember);
649 DEBUG_GENERAL(tmp); 635 DEBUG_GENERAL(tmp);
650 switch (dispidMember) 636 switch (dispidMember)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 case DISPID_BEFORENAVIGATE: 677 case DISPID_BEFORENAVIGATE:
692 DEBUG_NAVI("Navi::BeforeNavigate") 678 DEBUG_NAVI("Navi::BeforeNavigate")
693 return VARIANT_TRUE; 679 return VARIANT_TRUE;
694 case DISPID_COMMANDSTATECHANGE: 680 case DISPID_COMMANDSTATECHANGE:
695 if (m_hPaneWnd == NULL) 681 if (m_hPaneWnd == NULL)
696 { 682 {
697 CreateStatusBarPane(); 683 CreateStatusBarPane();
698 } 684 }
699 else 685 else
700 { 686 {
701 if ( ABP::IE::installed_major_version() > 6 ) 687 if (CPluginClient::GetInstance()->GetIEVersion() > 6)
702 { 688 {
703 RECT rect; 689 RECT rect;
704 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); 690 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect);
705 if (rectRes == TRUE) 691 if (rectRes == TRUE)
706 { 692 {
707 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom - rect.top, TRUE); 693 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom - rect.top, TRUE);
708 } 694 }
709 } 695 }
710 } 696 }
711 break; 697 break;
(...skipping 19 matching lines...) Expand all
731 { 717 {
732 m_tab->OnDownloadComplete(browser); 718 m_tab->OnDownloadComplete(browser);
733 } 719 }
734 } 720 }
735 break; 721 break;
736 722
737 case DISPID_DOCUMENTCOMPLETE: 723 case DISPID_DOCUMENTCOMPLETE:
738 { 724 {
739 DEBUG_NAVI("Navi::Document Complete") 725 DEBUG_NAVI("Navi::Document Complete")
740 726
741 CComQIPtr<IWebBrowser2> ccom_browser = GetBrowser(); 727 CComQIPtr<IWebBrowser2> browser = GetBrowser();
742 728
743 if (ccom_browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt = = VT_DISPATCH) 729 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_ DISPATCH)
744 { 730 {
745 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; 731 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
746 if (pBrowser) 732 if (pBrowser)
747 { 733 {
748 Wrapper::Browser browser( pBrowser ); 734 CString url;
749 std::wstring url; 735 CComBSTR bstrUrl;
750 if ( browser.Location_URL( url ) && !url.empty() ) 736 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen(b strUrl) > 0)
751 { 737 {
752 Wrapper::Unescape_URL(url); 738 url = bstrUrl;
753 m_tab->OnDocumentComplete(ccom_browser, url, ccom_browser.IsEqualObj ect(pBrowser)); 739
740 CPluginClient::UnescapeUrl(url);
741
742 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBrows er));
754 } 743 }
755 } 744 }
756 } 745 }
757 } 746 }
758 break; 747 break;
759 748
760 case DISPID_ONQUIT: 749 case DISPID_ONQUIT:
761 case DISPID_QUIT: 750 case DISPID_QUIT:
762 { 751 {
763 Unadvice(); 752 Unadvice();
764 } 753 }
765 break; 754 break;
766 755
767 default: 756 default:
768 { 757 {
769 std::wostringstream msg; 758 CString did;
770 msg << L"Navi::Default DispId:"; 759 did.Format(L"DispId:%u", dispidMember);
771 msg << static_cast< unsigned long >( dispidMember ); 760
772 DEBUG_NAVI( msg.str() ) 761 DEBUG_NAVI(L"Navi::Default " + did)
773 } 762 }
774 763
775 // do nothing 764 // do nothing
776 break; 765 break;
777 } 766 }
778 767
779 return VARIANT_TRUE; 768 return VARIANT_TRUE;
780 } 769 }
781 770
782 bool CPluginClass::InitObject(bool bBHO) 771 bool CPluginClass::InitObject(bool bBHO)
783 { 772 {
784 DEBUG_GENERAL(L"InitObject"); 773 DEBUG_GENERAL("InitObject");
785 CPluginSettings* settings = CPluginSettings::GetInstance(); 774 CPluginSettings* settings = CPluginSettings::GetInstance();
786 775
787 if (!settings->GetPluginEnabled()) 776 if (!settings->GetPluginEnabled())
788 { 777 {
789 s_mimeFilter->Unregister(); 778 s_mimeFilter->Unregister();
790 } 779 }
791 780
792 // Load theme module 781 // Load theme module
793 s_criticalSectionLocal.Lock(); 782 s_criticalSectionLocal.Lock();
794 { 783 {
795 if (!s_hUxtheme) 784 if (!s_hUxtheme)
796 { 785 {
797 s_hUxtheme = ::GetModuleHandleW(L"uxtheme.dll"); 786 s_hUxtheme = ::GetModuleHandle(_T("uxtheme.dll"));
798 if (s_hUxtheme) 787 if (s_hUxtheme)
799 { 788 {
800 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData" ); 789 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData" );
801 if (!pfnClose) 790 if (!pfnClose)
802 { 791 {
803 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_CLOSE, L"Class::InitObject - GetProcAddress(CloseThemeData)"); 792 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_CLOSE, "Class::InitObject - GetProcAddress(CloseThemeData)");
804 } 793 }
805 794
806 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem e, "DrawThemeBackground"); 795 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem e, "DrawThemeBackground");
807 if (!pfnDrawThemeBackground) 796 if (!pfnDrawThemeBackground)
808 { 797 {
809 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_DRAW_BACKGROUND, L"Class::InitObject - GetProcAddress(DrawThemeBackgrou nd)"); 798 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_DRAW_BACKGROUND, "Class::InitObject - GetProcAddress(DrawThemeBackgroun d)");
810 } 799 }
811 800
812 pfnOpenThemeData = (OPENTHEMEDATA)::GetProcAddress(s_hUxtheme, "OpenThem eData"); 801 pfnOpenThemeData = (OPENTHEMEDATA)::GetProcAddress(s_hUxtheme, "OpenThem eData");
813 if (!pfnOpenThemeData) 802 if (!pfnOpenThemeData)
814 { 803 {
815 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_OPEN, L"Class::InitObject - GetProcAddress(pfnOpenThemeData)"); 804 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_OPEN, "Class::InitObject - GetProcAddress(pfnOpenThemeData)");
816 } 805 }
817 } 806 }
818 else 807 else
819 { 808 {
820 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_U XTHEME, L"Class::InitObject - GetModuleHandle(uxtheme.dll)"); 809 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_U XTHEME, "Class::InitObject - GetModuleHandle(uxtheme.dll)");
821 } 810 }
822 } 811 }
823 } 812 }
824 s_criticalSectionLocal.Unlock(); 813 s_criticalSectionLocal.Unlock();
825 814
826 // Register pane class 815 // Register pane class
827 if (!GetAtomPaneClass()) 816 if (!GetAtomPaneClass())
828 { 817 {
829 WNDCLASSEX wcex; 818 WNDCLASSEX wcex;
830 819
(...skipping 11 matching lines...) Expand all
842 wcex.hIconSm = NULL; 831 wcex.hIconSm = NULL;
843 832
844 s_criticalSectionLocal.Lock(); 833 s_criticalSectionLocal.Lock();
845 { 834 {
846 s_atomPaneClass = ::RegisterClassEx(&wcex); 835 s_atomPaneClass = ::RegisterClassEx(&wcex);
847 } 836 }
848 s_criticalSectionLocal.Unlock(); 837 s_criticalSectionLocal.Unlock();
849 838
850 if (!GetAtomPaneClass()) 839 if (!GetAtomPaneClass())
851 { 840 {
852 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, L"Class::InitObject - RegisterClassEx"); 841 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx");
853 return false; 842 return false;
854 } 843 }
855 } 844 }
856 845
857 846
858 int ieVersion = ABP::IE::installed_major_version(); 847 int ieVersion = CPluginClient::GetInstance()->GetIEVersion();
859 // Create status pane 848 // Create status pane
860 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) 849 if (bBHO && ieVersion > 6 && !CreateStatusBarPane())
861 { 850 {
862 return false; 851 return false;
863 } 852 }
864 853
865 if (CPluginClient::GetInstance()->IsFirstRun()) 854 if (CPluginClient::GetInstance()->IsFirstRun())
866 { 855 {
867 // IE6 can't be accessed from another thread, execute in current thread 856 // IE6 can't be accessed from another thread, execute in current thread
868 if (ieVersion < 7) 857 if (ieVersion < 7)
(...skipping 17 matching lines...) Expand all
886 { 875 {
887 CriticalSection::Lock lock(m_csStatusBar); 876 CriticalSection::Lock lock(m_csStatusBar);
888 877
889 CPluginClient* client = CPluginClient::GetInstance(); 878 CPluginClient* client = CPluginClient::GetInstance();
890 879
891 TCHAR szClassName[MAX_PATH]; 880 TCHAR szClassName[MAX_PATH];
892 // Get browser window and url 881 // Get browser window and url
893 HWND hBrowserWnd = GetBrowserHWND(); 882 HWND hBrowserWnd = GetBrowserHWND();
894 if (!hBrowserWnd) 883 if (!hBrowserWnd)
895 { 884 {
896 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, L" Class::CreateStatusBarPane - No status bar") 885 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::CreateStatusBarPane - No status bar")
897 return false; 886 return false;
898 } 887 }
899 888
900 // Looking for a TabWindowClass window in IE7 889 // Looking for a TabWindowClass window in IE7
901 // the last one should be parent for statusbar 890 // the last one should be parent for statusbar
902 HWND hWndStatusBar = NULL; 891 HWND hWndStatusBar = NULL;
903 892
904 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 893 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
905 UINT amoundOfNewTabs = 0; 894 UINT amoundOfNewTabs = 0;
906 HWND uniqueNewTab = NULL; 895 HWND uniqueNewTab = NULL;
(...skipping 14 matching lines...) Expand all
921 if (hTabWnd2) 910 if (hTabWnd2)
922 { 911 {
923 DWORD nProcessId; 912 DWORD nProcessId;
924 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); 913 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
925 if (::GetCurrentProcessId() == nProcessId) 914 if (::GetCurrentProcessId() == nProcessId)
926 { 915 {
927 bool bExistingTab = false; 916 bool bExistingTab = false;
928 917
929 s_criticalSectionLocal.Lock(); 918 s_criticalSectionLocal.Lock();
930 { 919 {
931 for (int i = 0; i < s_instances.GetSize(); i++) 920 for (auto instance : s_instances)
932 { 921 {
933 if (s_instances[i]->m_hTabWnd == hTabWnd2) 922 if (instance->m_hTabWnd == hTabWnd2)
934 { 923 {
935
936 bExistingTab = true; 924 bExistingTab = true;
937 break; 925 break;
938 } 926 }
939 } 927 }
940 } 928 }
941 s_criticalSectionLocal.Unlock(); 929 s_criticalSectionLocal.Unlock();
942 930
943 if (!bExistingTab) 931 if (!bExistingTab)
944 { 932 {
945 amoundOfNewTabs ++; 933 amoundOfNewTabs ++;
(...skipping 22 matching lines...) Expand all
968 { 956 {
969 hWndStatusBar = hWnd; 957 hWndStatusBar = hWnd;
970 break; 958 break;
971 } 959 }
972 960
973 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); 961 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT);
974 } 962 }
975 963
976 if (!hWndStatusBar) 964 if (!hWndStatusBar)
977 { 965 {
978 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, L"Clas s::CreateStatusBarPane - No status bar") 966 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, "Class ::CreateStatusBarPane - No status bar")
979 return true; 967 return true;
980 } 968 }
981 969
982 // Calculate pane height 970 // Calculate pane height
983 Local::Rectangle rcStatusBar; 971 AdblockPlus::Rectangle rcStatusBar;
984 ::GetClientRect(hWndStatusBar, &rcStatusBar); 972 ::GetClientRect(hWndStatusBar, &rcStatusBar);
985 973
986 if (rcStatusBar.Height() > 0) 974 if (rcStatusBar.Height() > 0)
987 { 975 {
988 #ifdef _DEBUG 976 #ifdef _DEBUG
989 m_nPaneWidth = 70; 977 m_nPaneWidth = 70;
990 #else 978 #else
991 m_nPaneWidth = min(rcStatusBar.Height(), 22); 979 m_nPaneWidth = min(rcStatusBar.Height(), 22);
992 #endif 980 #endif
993 } 981 }
(...skipping 12 matching lines...) Expand all
1006 _T(""), 994 _T(""),
1007 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 995 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
1008 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), 996 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(),
1009 hWndStatusBar, 997 hWndStatusBar,
1010 (HMENU)3671, 998 (HMENU)3671,
1011 _Module.m_hInst, 999 _Module.m_hInst,
1012 NULL); 1000 NULL);
1013 1001
1014 if (!hWndNewPane) 1002 if (!hWndNewPane)
1015 { 1003 {
1016 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, L"Class::CreateStatusBarPane - CreateWindowEx") 1004 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx")
1017 return false; 1005 return false;
1018 } 1006 }
1019 1007
1020 DEBUG_GENERAL(L"ABP window created"); 1008 DEBUG_GENERAL("ABP window created");
1021 m_hTabWnd = hTabWnd; 1009 m_hTabWnd = hTabWnd;
1022 m_hStatusBarWnd = hWndStatusBar; 1010 m_hStatusBarWnd = hWndStatusBar;
1023 m_hPaneWnd = hWndNewPane; 1011 m_hPaneWnd = hWndNewPane;
1024 1012
1025 UpdateTheme(); 1013 UpdateTheme();
1026 1014
1027 // Subclass status bar 1015 // Subclass status bar
1028 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA RAM)(WNDPROC)NewStatusProc); 1016 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA RAM)(WNDPROC)NewStatusProc);
1029 1017
1030 // Adjust pane 1018 // Adjust pane
(...skipping 12 matching lines...) Expand all
1043 HDC hdc = GetWindowDC(m_hStatusBarWnd); 1031 HDC hdc = GetWindowDC(m_hStatusBarWnd);
1044 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); 1032 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0);
1045 ReleaseDC(m_hStatusBarWnd, hdc); 1033 ReleaseDC(m_hStatusBarWnd, hdc);
1046 1034
1047 return true; 1035 return true;
1048 } 1036 }
1049 1037
1050 void CPluginClass::FirstRunThread() 1038 void CPluginClass::FirstRunThread()
1051 { 1039 {
1052 CoInitialize(NULL); 1040 CoInitialize(NULL);
1053 1041 VARIANT vFlags;
1054 Wrapper::Browser browser( GetAsyncBrowser() ); 1042 vFlags.vt = VT_I4;
1055 HRESULT hr = browser.navigate( FirstRunPageFileUrl() ); 1043 vFlags.intVal = navOpenInNewTab;
1056 if ( FAILED( hr ) ) 1044
1057 { 1045 CComBSTR navigatePath = CComBSTR(FirstRunPageFileUrl().c_str());
1058 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_WELCOME , L"Navigation::Welcome page failed") 1046
1059 } 1047 HRESULT hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NU LL);
1060 } 1048 if (FAILED(hr))
1061 1049 {
1050 vFlags.intVal = navOpenInNewWindow;
1051 hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NULL);
1052 }
1053
1054 if (FAILED(hr))
1055 {
1056 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_WELCOME , "Navigation::Welcome page failed")
1057 }
1058 }
1062 void CPluginClass::CloseTheme() 1059 void CPluginClass::CloseTheme()
1063 { 1060 {
1064 if (m_hTheme) 1061 if (m_hTheme)
1065 { 1062 {
1066 if (pfnClose) 1063 if (pfnClose)
1067 { 1064 {
1068 pfnClose(m_hTheme); 1065 pfnClose(m_hTheme);
1069 } 1066 }
1070 1067
1071 m_hTheme = NULL; 1068 m_hTheme = NULL;
1072 } 1069 }
1073 } 1070 }
1074 1071
1075 void CPluginClass::UpdateTheme() 1072 void CPluginClass::UpdateTheme()
1076 { 1073 {
1077 CloseTheme(); 1074 CloseTheme();
1078 1075
1079 if (pfnOpenThemeData) 1076 if (pfnOpenThemeData)
1080 { 1077 {
1081 m_hTheme = pfnOpenThemeData(m_hPaneWnd, L"STATUS"); 1078 m_hTheme = pfnOpenThemeData(m_hPaneWnd, L"STATUS");
1082 if (!m_hTheme) 1079 if (!m_hTheme)
1083 { 1080 {
1084 } 1081 }
1085 } 1082 }
1086 } 1083 }
1087 1084
1088 1085
1089 CPluginClass* CPluginClass::FindInstance(HWND hStatusBarWnd) 1086 CPluginClass* CPluginClass::FindInstance(HWND hStatusBarWnd)
1090 { 1087 {
1091 CPluginClass* instance = NULL; 1088 CPluginClass* return_instance = nullptr;
1092 1089
1093 s_criticalSectionLocal.Lock(); 1090 s_criticalSectionLocal.Lock();
1094 { 1091 {
1095 for (int i = 0; i < s_instances.GetSize(); i++) 1092 for (auto instance : s_instances)
1096 { 1093 {
1097 if (s_instances[i]->m_hStatusBarWnd == hStatusBarWnd) 1094 if (instance->m_hStatusBarWnd == hStatusBarWnd)
1098 { 1095 {
1099 instance = s_instances[i]; 1096 return_instance = instance;
1100 break; 1097 break;
1101 } 1098 }
1102 } 1099 }
1103 } 1100 }
1104 s_criticalSectionLocal.Unlock(); 1101 s_criticalSectionLocal.Unlock();
1105 1102
1106 return instance; 1103 return return_instance;
1107 } 1104 }
1108 1105
1109 CPluginTab* CPluginClass::GetTab() 1106 CPluginTab* CPluginClass::GetTab()
1110 { 1107 {
1111 return m_tab; 1108 return m_tab;
1112 } 1109 }
1113 1110
1114 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) 1111 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId)
1115 { 1112 {
1116 CPluginTab* tab = NULL; 1113 CPluginTab* tab = NULL;
(...skipping 15 matching lines...) Expand all
1132 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1129 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1133 { 1130 {
1134 if (cCmds == 0) return E_INVALIDARG; 1131 if (cCmds == 0) return E_INVALIDARG;
1135 if (prgCmds == 0) return E_POINTER; 1132 if (prgCmds == 0) return E_POINTER;
1136 1133
1137 prgCmds[0].cmdf = OLECMDF_ENABLED; 1134 prgCmds[0].cmdf = OLECMDF_ENABLED;
1138 1135
1139 return S_OK; 1136 return S_OK;
1140 } 1137 }
1141 1138
1142 HMENU CPluginClass::CreatePluginMenu(const std::wstring & url) 1139 HMENU CPluginClass::CreatePluginMenu(const CString& url)
1143 { 1140 {
1144 DEBUG_GENERAL(L"CreatePluginMenu"); 1141 DEBUG_GENERAL("CreatePluginMenu");
1145 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1142 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1146 1143
1147 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1144 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1148 1145
1149 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); 1146 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);
1150 1147
1151 SetMenuBar(hMenuTrackPopup, url); 1148 SetMenuBar(hMenuTrackPopup, url);
1152 1149
1153 return hMenuTrackPopup; 1150 return hMenuTrackPopup;
1154 } 1151 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 } 1326 }
1330 } 1327 }
1331 s_criticalSectionLocal.Unlock(); 1328 s_criticalSectionLocal.Unlock();
1332 } 1329 }
1333 break; 1330 break;
1334 case ID_MENU_SETTINGS: 1331 case ID_MENU_SETTINGS:
1335 { 1332 {
1336 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 1333 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1337 if (browser) 1334 if (browser)
1338 { 1335 {
1339 Wrapper::Browser b( browser ); 1336 VARIANT vFlags;
1340 HRESULT hr = b.navigate( UserSettingsFileUrl() ); 1337 vFlags.vt = VT_I4;
1341 if ( FAILED(hr) ) 1338 vFlags.intVal = navOpenInNewTab;
1339
1340 BSTR urlToNavigate = BString(UserSettingsFileUrl());
1341 HRESULT hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL) ;
1342 if (FAILED(hr))
1342 { 1343 {
1343 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_S ETTINGS, L"Navigation::Failed") 1344 vFlags.intVal = navOpenInNewWindow;
1345
1346 hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL);
1347 if (FAILED(hr))
1348 {
1349 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1350 }
1344 } 1351 }
1345 } 1352 }
1346 break; 1353 break;
1347 } 1354 }
1348 case ID_MENU_DISABLE_ON_SITE: 1355 case ID_MENU_DISABLE_ON_SITE:
1349 { 1356 {
1350 CPluginSettings* settings = CPluginSettings::GetInstance(); 1357 CPluginSettings* settings = CPluginSettings::GetInstance();
1351 std::wstring urlString = GetTab()->GetDocumentUrl(); 1358 CString urlString = GetTab()->GetDocumentUrl();
1352 if (client->IsWhitelistedUrl(urlString)) 1359 if (client->IsWhitelistedUrl(std::wstring(urlString)))
1353 { 1360 {
1354 settings->RemoveWhiteListedDomain( client->GetHostFromUrl( urlString ).c _str() ); 1361 settings->RemoveWhiteListedDomain(client->GetHostFromUrl(urlString.GetSt ring()).c_str());
1355 } 1362 }
1356 else 1363 else
1357 { 1364 {
1358 settings->AddWhiteListedDomain( client->GetHostFromUrl( urlString).c_str ()); 1365 settings->AddWhiteListedDomain(client->GetHostFromUrl(urlString.GetStrin g()).c_str());
1359 } 1366 }
1360 GetBrowser()->Refresh(); 1367 GetBrowser()->Refresh();
1361 } 1368 }
1362 default: 1369 default:
1363 break; 1370 break;
1364 } 1371 }
1365 1372
1366 // Invalidate and redraw the control 1373 // Invalidate and redraw the control
1367 UpdateStatusBar(); 1374 UpdateStatusBar();
1368 } 1375 }
1369 1376
1370 1377
1371 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring & url) 1378 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url)
1372 { 1379 {
1373 DEBUG_GENERAL(L"SetMenuBar"); 1380 DEBUG_GENERAL("SetMenuBar");
1374 1381
1375 std::wstring ctext; 1382 std::wstring ctext;
1376 1383
1377 s_criticalSectionLocal.Lock(); 1384 s_criticalSectionLocal.Lock();
1378 { 1385 {
1379 #ifdef SUPPORT_WHITELIST 1386 #ifdef SUPPORT_WHITELIST
1380 s_menuDomains.clear(); 1387 s_menuDomains.clear();
1381 #endif 1388 #endif
1382 } 1389 }
1383 s_criticalSectionLocal.Unlock(); 1390 s_criticalSectionLocal.Unlock();
(...skipping 12 matching lines...) Expand all
1396 miiSep.fType = MFT_SEPARATOR; 1403 miiSep.fType = MFT_SEPARATOR;
1397 1404
1398 CPluginClient* client = CPluginClient::GetInstance(); 1405 CPluginClient* client = CPluginClient::GetInstance();
1399 1406
1400 CPluginSettings* settings = CPluginSettings::GetInstance(); 1407 CPluginSettings* settings = CPluginSettings::GetInstance();
1401 1408
1402 #ifdef SUPPORT_WHITELIST 1409 #ifdef SUPPORT_WHITELIST
1403 { 1410 {
1404 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1411 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1405 // Is domain in white list? 1412 // Is domain in white list?
1406 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); 1413 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url.GetString()));
1407 if (client->IsWhitelistedUrl(std::wstring(GetTab()->GetDocumentUrl()))) 1414 if (client->IsWhitelistedUrl(std::wstring(GetTab()->GetDocumentUrl())))
1408 { 1415 {
1409 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1416 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1410 } 1417 }
1411 else 1418 else
1412 { 1419 {
1413 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1420 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1414 } 1421 }
1415 fmii.fMask = MIIM_STRING | MIIM_STATE; 1422 fmii.fMask = MIIM_STRING | MIIM_STATE;
1416 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1423 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); 1592 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1));
1586 LPINT lpParts = (LPINT)LocalLock(hLocal); 1593 LPINT lpParts = (LPINT)LocalLock(hLocal);
1587 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); 1594 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1588 1595
1589 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) 1596 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1590 { 1597 {
1591 lpParts[i] -= pClass->m_nPaneWidth; 1598 lpParts[i] -= pClass->m_nPaneWidth;
1592 } 1599 }
1593 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts); 1600 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts);
1594 1601
1595 Local::Rectangle rcPane; 1602 AdblockPlus::Rectangle rcPane;
1596 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); 1603 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1597 1604
1598 Local::Rectangle rcClient; 1605 AdblockPlus::Rectangle rcClient;
1599 ::GetClientRect(hWnd, &rcClient); 1606 ::GetClientRect(hWnd, &rcClient);
1600 1607
1601 ::MoveWindow( 1608 ::MoveWindow(
1602 pClass->m_hPaneWnd, 1609 pClass->m_hPaneWnd,
1603 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, 1610 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1604 0, 1611 0,
1605 pClass->m_nPaneWidth, 1612 pClass->m_nPaneWidth,
1606 rcClient.Height(), 1613 rcClient.Height(),
1607 TRUE); 1614 TRUE);
1608 1615
1609 ::LocalFree(hLocal); 1616 ::LocalFree(hLocal);
1610 1617
1611 1618
1612 return hRet; 1619 return hRet;
1613 } 1620 }
1614 1621
1615 default: 1622 default:
1616 break; 1623 break;
1617 } 1624 }
1618 1625
1619 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); 1626 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1620 1627
1621 1628
1622 return result; 1629 return result;
1623 1630
1624 } 1631 }
1625 1632
1626 1633
1627 HICON CPluginClass::GetStatusBarIcon(const std::wstring & url) 1634 HICON CPluginClass::GetStatusBarIcon(const CString& url)
1628 { 1635 {
1629 // use the disable icon as defualt, if the client doesn't exists 1636 // use the disable icon as defualt, if the client doesn't exists
1630 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1637 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1631 1638
1632 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1639 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1633 if (tab) 1640 if (tab)
1634 { 1641 {
1635 CPluginClient* client = CPluginClient::GetInstance(); 1642 CPluginClient* client = CPluginClient::GetInstance();
1636 1643
1637 #ifdef PRODUCT_ADBLOCKPLUS 1644 #ifdef PRODUCT_ADBLOCKPLUS
1638 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) 1645 if (!CPluginSettings::GetInstance()->IsPluginEnabled())
1639 { 1646 {
1640 } 1647 }
1641 #ifdef SUPPORT_WHITELIST 1648 #ifdef SUPPORT_WHITELIST
1642 else if (client->IsWhitelistedUrl( url )) 1649 else if (client->IsWhitelistedUrl(std::wstring(url)))
1643 { 1650 {
1644 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1651 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1645 } 1652 }
1646 #endif // SUPPORT_WHITELIST 1653 #endif // SUPPORT_WHITELIST
1647 else 1654 else
1648 { 1655 {
1649 CPluginSettings* settings = CPluginSettings::GetInstance(); 1656 CPluginSettings* settings = CPluginSettings::GetInstance();
1650 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1657 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1651 } 1658 }
1652 1659
(...skipping 22 matching lines...) Expand all
1675 case WM_SETCURSOR: 1682 case WM_SETCURSOR:
1676 { 1683 {
1677 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); 1684 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
1678 return TRUE; 1685 return TRUE;
1679 } 1686 }
1680 case WM_PAINT: 1687 case WM_PAINT:
1681 { 1688 {
1682 PAINTSTRUCT ps; 1689 PAINTSTRUCT ps;
1683 HDC hDC = ::BeginPaint(hWnd, &ps); 1690 HDC hDC = ::BeginPaint(hWnd, &ps);
1684 1691
1685 Local::Rectangle rcClient; 1692 AdblockPlus::Rectangle rcClient;
1686 ::GetClientRect(hWnd, &rcClient); 1693 ::GetClientRect(hWnd, &rcClient);
1687 1694
1688 int nDrawEdge = 0; 1695 int nDrawEdge = 0;
1689 1696
1690 // Old Windows background drawing 1697 // Old Windows background drawing
1691 if (pClass->m_hTheme == NULL) 1698 if (pClass->m_hTheme == NULL)
1692 { 1699 {
1693 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); 1700 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1));
1694 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); 1701 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT);
1695 1702
1696 nDrawEdge = 3; 1703 nDrawEdge = 3;
1697 rcClient.left += 3; 1704 rcClient.left += 3;
1698 1705
1699 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); 1706 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT);
1700 } 1707 }
1701 // Themed background drawing 1708 // Themed background drawing
1702 else 1709 else
1703 { 1710 {
1704 // Draw background 1711 // Draw background
1705 if (pfnDrawThemeBackground) 1712 if (pfnDrawThemeBackground)
1706 { 1713 {
1707 Local::Rectangle rc = rcClient; 1714 AdblockPlus::Rectangle rc = rcClient;
1708 rc.right -= 2; 1715 rc.right -= 2;
1709 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); 1716 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1710 } 1717 }
1711 1718
1712 // Copy separator picture to left side 1719 // Copy separator picture to left side
1713 int nHeight = rcClient.Height(); 1720 int nHeight = rcClient.Height();
1714 int nWidth = rcClient.Width() - 2; 1721 int nWidth = rcClient.Width() - 2;
1715 1722
1716 for (int i = 0; i < 2; i++) 1723 for (int i = 0; i < 2; i++)
1717 { 1724 {
1718 for (int j = 0; j < nHeight; j++) 1725 for (int j = 0; j < nHeight; j++)
1719 { 1726 {
1720 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); 1727 COLORREF clr = ::GetPixel(hDC, i + nWidth, j);
1721 1728
1722 // Ignore black boxes (if source is obscured by other windows) 1729 // Ignore black boxes (if source is obscured by other windows)
1723 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) 1730 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8))
1724 { 1731 {
1725 ::SetPixel(hDC, i, j, clr); 1732 ::SetPixel(hDC, i, j, clr);
1726 } 1733 }
1727 } 1734 }
1728 } 1735 }
1729 } 1736 }
1730 1737
1731 // Draw icon 1738 // Draw icon
1732 if (CPluginClient::GetInstance()) 1739 if (CPluginClient::GetInstance())
1733 { 1740 {
1734 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl().c_str( )); 1741 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1735 1742
1736 int offx = (rcClient.Height() - 16)/2 + nDrawEdge; 1743 int offx = (rcClient.Height() - 16)/2 + nDrawEdge;
1737 if (hIcon) 1744 if (hIcon)
1738 { 1745 {
1739 ::DrawIconEx(hDC, offx, (rcClient.Height() - 16)/2 + 2, hIcon, 16, 16, NULL, NULL, DI_NORMAL); 1746 ::DrawIconEx(hDC, offx, (rcClient.Height() - 16)/2 + 2, hIcon, 16, 16, NULL, NULL, DI_NORMAL);
1740 offx += 22; 1747 offx += 22;
1741 } 1748 }
1742 #ifdef _DEBUG 1749 #ifdef _DEBUG
1743 // Display version 1750 // Display version
1744 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1751 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0);
1745 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); 1752 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont);
1746 1753
1747 Local::Rectangle rcText = rcClient; 1754 AdblockPlus::Rectangle rcText = rcClient;
1748 rcText.left += offx; 1755 rcText.left += offx;
1749 ::SetBkMode(hDC, TRANSPARENT); 1756 ::SetBkMode(hDC, TRANSPARENT);
1750 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER); 1757 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER);
1751 1758
1752 ::SelectObject(hDC, hOldFont); 1759 ::SelectObject(hDC, hOldFont);
1753 #endif // _DEBUG 1760 #endif // _DEBUG
1754 } 1761 }
1755 1762
1756 // Done! 1763 // Done!
1757 EndPaint(hWnd, &ps); 1764 EndPaint(hWnd, &ps);
1758 1765
1759 return 0; 1766 return 0;
1760 } 1767 }
1761 1768
1762 case WM_LBUTTONUP: 1769 case WM_LBUTTONUP:
1763 case WM_RBUTTONUP: 1770 case WM_RBUTTONUP:
1764 { 1771 {
1765 std::wstring url = pClass->GetBrowserUrl(); 1772 CString strURL = pClass->GetBrowserUrl();
1766 if (url != pClass->GetTab()->GetDocumentUrl()) 1773 if (strURL != pClass->GetTab()->GetDocumentUrl())
1767 { 1774 {
1768 pClass->GetTab()->SetDocumentUrl( url ); 1775 pClass->GetTab()->SetDocumentUrl(strURL);
1769 } 1776 }
1770 1777
1771 // Create menu 1778 // Create menu
1772 HMENU hMenu = pClass->CreatePluginMenu( url ); 1779 HMENU hMenu = pClass->CreatePluginMenu(strURL);
1773 if (!hMenu) 1780 if (!hMenu)
1774 { 1781 {
1775 return 0; 1782 return 0;
1776 } 1783 }
1777 1784
1778 // Display menu 1785 // Display menu
1779 POINT pt; 1786 POINT pt;
1780 ::GetCursorPos(&pt); 1787 ::GetCursorPos(&pt);
1781 1788
1782 RECT rc; 1789 RECT rc;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 } 1863 }
1857 break; 1864 break;
1858 } 1865 }
1859 1866
1860 return DefWindowProc(hWnd, message, wParam, lParam); 1867 return DefWindowProc(hWnd, message, wParam, lParam);
1861 } 1868 }
1862 1869
1863 1870
1864 void CPluginClass::UpdateStatusBar() 1871 void CPluginClass::UpdateStatusBar()
1865 { 1872 {
1866 DEBUG_GENERAL(L"*** Updating statusbar") 1873 DEBUG_GENERAL("*** Updating statusbar")
1867 if (m_hPaneWnd == NULL) 1874 if (m_hPaneWnd == NULL)
1868 { 1875 {
1869 CreateStatusBarPane(); 1876 CreateStatusBarPane();
1870 } 1877 }
1871 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1878 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1872 { 1879 {
1873 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, L"Class::Invalidate statusbar"); 1880 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1874 } 1881 }
1875 } 1882 }
1876 1883
1877 1884
1878 void CPluginClass::Unadvice() 1885 void CPluginClass::Unadvice()
1879 { 1886 {
1880 s_criticalSectionLocal.Lock(); 1887 s_criticalSectionLocal.Lock();
1881 { 1888 {
1882 if (m_isAdviced) 1889 if (m_isAdviced)
1883 { 1890 {
1884 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 1891 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint();
1885 if (pPoint) 1892 if (pPoint)
1886 { 1893 {
1887 HRESULT hr = pPoint->Unadvise(m_nConnectionID); 1894 HRESULT hr = pPoint->Unadvise(m_nConnectionID);
1888 if (FAILED(hr)) 1895 if (FAILED(hr))
1889 { 1896 {
1890 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV ICE, L"Class::Unadvice - Unadvise"); 1897 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV ICE, "Class::Unadvice - Unadvise");
1891 } 1898 }
1892 } 1899 }
1893 1900
1894 m_isAdviced = false; 1901 m_isAdviced = false;
1895 } 1902 }
1896 } 1903 }
1897 s_criticalSectionLocal.Unlock(); 1904 s_criticalSectionLocal.Unlock();
1898 } 1905 }
1899 1906
1900 HICON CPluginClass::GetIcon(int type) 1907 HICON CPluginClass::GetIcon(int type)
1901 { 1908 {
1902 HICON icon = NULL; 1909 HICON icon = NULL;
1903 1910
1904 s_criticalSectionLocal.Lock(); 1911 s_criticalSectionLocal.Lock();
1905 { 1912 {
1906 if (!s_hIcons[type]) 1913 if (!s_hIcons[type])
1907 { 1914 {
1908 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[ type])); 1915 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[ type]));
1909 if (!s_hIcons[type]) 1916 if (!s_hIcons[type])
1910 { 1917 {
1911 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, L"Class::GetIcon - LoadIcon") 1918 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon")
1912 } 1919 }
1913 } 1920 }
1914 1921
1915 icon = s_hIcons[type]; 1922 icon = s_hIcons[type];
1916 } 1923 }
1917 s_criticalSectionLocal.Unlock(); 1924 s_criticalSectionLocal.Unlock();
1918 1925
1919 return icon; 1926 return icon;
1920 } 1927 }
1921 1928
1922 ATOM CPluginClass::GetAtomPaneClass() 1929 ATOM CPluginClass::GetAtomPaneClass()
1923 { 1930 {
1924 return s_atomPaneClass; 1931 return s_atomPaneClass;
1925 } 1932 }
1926 1933
1927 HWND CPluginClass::GetTabHWND() const 1934 HWND CPluginClass::GetTabHWND() const
1928 { 1935 {
1929 1936
1930 TCHAR szClassName[MAX_PATH]; 1937 TCHAR szClassName[MAX_PATH];
1931 // Get browser window and url 1938 // Get browser window and url
1932 HWND hBrowserWnd = GetBrowserHWND(); 1939 HWND hBrowserWnd = GetBrowserHWND();
1933 if (!hBrowserWnd) 1940 if (!hBrowserWnd)
1934 { 1941 {
1935 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, L" Class::GetTabWindow - No tab window") 1942 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::GetTabWindow - No tab window")
1936 s_criticalSectionWindow.Unlock(); 1943 s_criticalSectionWindow.Unlock();
1937 1944
1938 return false; 1945 return false;
1939 } 1946 }
1940 1947
1941 // Looking for a TabWindowClass window in IE7 1948 // Looking for a TabWindowClass window in IE7
1942 1949
1943 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 1950 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
1944 while (hTabWnd) 1951 while (hTabWnd)
1945 { 1952 {
(...skipping 12 matching lines...) Expand all
1958 if (hTabWnd2) 1965 if (hTabWnd2)
1959 { 1966 {
1960 DWORD nProcessId; 1967 DWORD nProcessId;
1961 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); 1968 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
1962 if (::GetCurrentProcessId() == nProcessId) 1969 if (::GetCurrentProcessId() == nProcessId)
1963 { 1970 {
1964 bool bExistingTab = false; 1971 bool bExistingTab = false;
1965 s_criticalSectionLocal.Lock(); 1972 s_criticalSectionLocal.Lock();
1966 1973
1967 { 1974 {
1968 for (int i = 0; i < s_instances.GetSize(); i++) 1975 for (auto instance : s_instances)
1969 { 1976 {
1970 if (s_instances[i]->m_hTabWnd == hTabWnd2) 1977 if (instance->m_hTabWnd == hTabWnd2)
1971 { 1978 {
1972 bExistingTab = true; 1979 bExistingTab = true;
1973 break; 1980 break;
1974 } 1981 }
1975 } 1982 }
1976 } 1983 }
1977 1984
1978 if (!bExistingTab) 1985 if (!bExistingTab)
1979 { 1986 {
1980 hBrowserWnd = hTabWnd2; 1987 hBrowserWnd = hTabWnd2;
1981 hTabWnd = hTabWnd2; 1988 hTabWnd = hTabWnd2;
1982 s_criticalSectionLocal.Unlock(); 1989 s_criticalSectionLocal.Unlock();
1983 break; 1990 break;
1984 } 1991 }
1985 s_criticalSectionLocal.Unlock(); 1992 s_criticalSectionLocal.Unlock();
1986 1993
1987 } 1994 }
1988 } 1995 }
1989 } 1996 }
1990 1997
1991 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1998 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1992 } 1999 }
1993 2000
1994 return hTabWnd; 2001 return hTabWnd;
1995 2002
1996 } 2003 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld