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

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

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Left Patch Set: Second version Created June 25, 2014, 6:53 p.m.
Right Patch Set: Final (?) 2 Created Jan. 5, 2015, 1:02 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 #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
7 #include "PluginFilter.h" 6 #include "PluginFilter.h"
8 #endif
9 #include "PluginMimeFilterClient.h" 7 #include "PluginMimeFilterClient.h"
10 #include "PluginClient.h" 8 #include "PluginClient.h"
11 #include "PluginClientFactory.h" 9 #include "PluginClientFactory.h"
12 #include "PluginMutex.h" 10 #include "PluginMutex.h"
13 #include "sddl.h" 11 #include "sddl.h"
14 #include "PluginUtil.h" 12 #include "PluginUtil.h"
15 #include "PluginUserSettings.h" 13 #include "PluginUserSettings.h"
16 #include "../shared/Utils.h" 14 #include "../shared/Utils.h"
17 #include "../shared/Dictionary.h" 15 #include "../shared/Dictionary.h"
16 #include "../shared/IE_version.h"
18 #include <thread> 17 #include <thread>
19 18 #include <array>
20 #include "COM_Client.h"
21 #include "Wrapper.h"
22 19
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 /*
52 std::map<UINT,std::wstring> CPluginClass::s_menuDomains; 49 * Without namespace declaration, the identifier "Rectangle" is ambiguous
53 #endif 50 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx
54 51 */
52 namespace AdblockPlus
53 {
54 /**
55 * Replacement for ATL type CRect.
56 */
57 class Rectangle
58 : public RECT
59 {
60 public:
61 int Height() const
62 {
63 return bottom - top;
64 }
65
66 int Width() const
67 {
68 return right - left;
69 }
70 };
71 }
55 72
56 CPluginClass::CPluginClass() 73 CPluginClass::CPluginClass()
57 { 74 {
58 //Use this line to debug memory leaks 75 //Use this line to debug memory leaks
59 // _CrtDumpMemoryLeaks(); 76 // _CrtDumpMemoryLeaks();
60 77
61 m_isAdviced = false; 78 m_isAdviced = false;
62 m_nConnectionID = 0; 79 m_nConnectionID = 0;
63 m_hTabWnd = NULL; 80 m_hTabWnd = NULL;
64 m_hStatusBarWnd = NULL; 81 m_hStatusBarWnd = NULL;
65 m_hPaneWnd = NULL; 82 m_hPaneWnd = NULL;
66 m_nPaneWidth = 0; 83 m_nPaneWidth = 0;
67 m_pWndProcStatus = NULL; 84 m_pWndProcStatus = NULL;
68 m_hTheme = NULL; 85 m_hTheme = NULL;
69 m_isInitializedOk = false; 86 m_isInitializedOk = false;
70 87
71 88
72 m_tab = new CPluginTab(this); 89 m_tab = new CPluginTab(this);
73 90
74 CPluginSystem* system = CPluginSystem::GetInstance(); 91 Dictionary::Create(GetBrowserLanguage());
75
76 Dictionary::Create( system->GetBrowserLanguage() );
77 } 92 }
78 93
79 CPluginClass::~CPluginClass() 94 CPluginClass::~CPluginClass()
80 { 95 {
81 delete m_tab; 96 delete m_tab;
82 } 97 }
83 98
84 99
85 ///////////////////////////////////////////////////////////////////////////// 100 /////////////////////////////////////////////////////////////////////////////
86 // Initialization 101 // Initialization
(...skipping 20 matching lines...) Expand all
107 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser()); 122 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser());
108 if (!pContainer) 123 if (!pContainer)
109 { 124 {
110 return NULL; 125 return NULL;
111 } 126 }
112 127
113 CComPtr<IConnectionPoint> pPoint; 128 CComPtr<IConnectionPoint> pPoint;
114 HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint) ; 129 HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint) ;
115 if (FAILED(hr)) 130 if (FAILED(hr))
116 { 131 {
117 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, L"Class::GetConnectionPoint - FindConnectionPoint") 132 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint")
118 return NULL; 133 return NULL;
119 } 134 }
120 135
121 return pPoint; 136 return pPoint;
122 } 137 }
123 138
124 // This method tries to get a 'connection point' from the stored browser, which can be 139 // This method tries to get a 'connection point' from the stored browser, which can be
125 // used to attach or detach from the stream of browser events 140 // used to attach or detach from the stream of browser events
126 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPointPropSink() 141 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPointPropSink()
127 { 142 {
128 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser()); 143 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser());
129 if (!pContainer) 144 if (!pContainer)
130 { 145 {
131 return NULL; 146 return NULL;
132 } 147 }
133 148
134 CComPtr<IConnectionPoint> pPoint; 149 CComPtr<IConnectionPoint> pPoint;
135 HRESULT hr = pContainer->FindConnectionPoint(IID_IPropertyNotifySink, &pPoint) ; 150 HRESULT hr = pContainer->FindConnectionPoint(IID_IPropertyNotifySink, &pPoint) ;
136 if (FAILED(hr)) 151 if (FAILED(hr))
137 { 152 {
138 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, L"Class::GetConnectionPoint - FindConnectionPoint") 153 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint")
139 return NULL; 154 return NULL;
140 } 155 }
141 156
142 return pPoint; 157 return pPoint;
143 } 158 }
144 159
145 160
146 HWND CPluginClass::GetBrowserHWND() const 161 HWND CPluginClass::GetBrowserHWND() const
147 { 162 {
148 SHANDLE_PTR hBrowserWndHandle = NULL; 163 SHANDLE_PTR hBrowserWndHandle = NULL;
149 164
150 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 165 CComQIPtr<IWebBrowser2> browser = GetBrowser();
151 if (browser) 166 if (browser)
152 { 167 {
153 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); 168 HRESULT hr = browser->get_HWND(&hBrowserWndHandle);
154 if (FAILED(hr)) 169 if (FAILED(hr))
155 { 170 {
156 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, L "Class::GetBrowserHWND - failed") 171 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, " Class::GetBrowserHWND - failed")
157 } 172 }
158 } 173 }
159 174
160 return (HWND)hBrowserWndHandle; 175 return (HWND)hBrowserWndHandle;
161 } 176 }
162 177
163 178
164 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const 179 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const
165 { 180 {
166 CComQIPtr<IWebBrowser2> browser; 181 CComQIPtr<IWebBrowser2> browser;
(...skipping 14 matching lines...) Expand all
181 196
182 s_criticalSectionLocal.Lock(); 197 s_criticalSectionLocal.Lock();
183 { 198 {
184 browser = s_asyncWebBrowser2; 199 browser = s_asyncWebBrowser2;
185 } 200 }
186 s_criticalSectionLocal.Unlock(); 201 s_criticalSectionLocal.Unlock();
187 202
188 return browser; 203 return browser;
189 } 204 }
190 205
191 std::wstring CPluginClass::GetBrowserUrl() const 206 CString CPluginClass::GetBrowserUrl() const
192 { 207 {
193 std::wstring url; 208 CString url;
194 209
195 CComQIPtr<IWebBrowser2> ccom_browser = GetBrowser(); 210 CComQIPtr<IWebBrowser2> browser = GetBrowser();
196 if (ccom_browser) 211 if (browser)
197 { 212 {
198 Wrapper::Browser browser( ccom_browser ); 213 CComBSTR bstrURL;
199 if ( browser.Location_URL( url ) ) 214
200 { 215 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)))
201 Wrapper::Unescape_URL( url ); 216 {
217 url = bstrURL;
218 CPluginClient::UnescapeUrl(url);
202 } 219 }
203 } 220 }
204 else 221 else
205 { 222 {
206 url = m_tab->GetDocumentUrl(); 223 url = m_tab->GetDocumentUrl();
207 } 224 }
225
208 return url; 226 return url;
209 } 227 }
210 228
211 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 229 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
212 { 230 {
213 if (thisPtr == NULL) 231 if (thisPtr == NULL)
214 return 0; 232 return 0;
215 if (!((CPluginClass*)thisPtr)->InitObject(true)) 233 if (!((CPluginClass*)thisPtr)->InitObject(true))
216 { 234 {
217 ((CPluginClass*)thisPtr)->Unadvice(); 235 ((CPluginClass*)thisPtr)->Unadvice();
218 } 236 }
219 237
220 return 0; 238 return 0;
221 } 239 }
222 240
223 241
224 242
225 // This gets called when a new browser window is created (which also triggers th e 243 // This gets called when a new browser window is created (which also triggers th e
226 // creation of this object). The pointer passed in should be to a IWebBrowser2 244 // creation of this object). The pointer passed in should be to a IWebBrowser2
227 // interface that represents the browser for the window. 245 // interface that represents the browser for the window.
228 // it is also called when a tab is closed, this unknownSite will be null 246 // it is also called when a tab is closed, this unknownSite will be null
229 // so we should handle that it is called this way several times during a session 247 // so we should handle that it is called this way several times during a session
230 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 248 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
231 { 249 {
232 CPluginSettings* settings = CPluginSettings::GetInstance(); 250 CPluginSettings* settings = CPluginSettings::GetInstance();
233 CPluginSystem* system = CPluginSystem::GetInstance();
234 251
235 MULTIPLE_VERSIONS_CHECK(); 252 MULTIPLE_VERSIONS_CHECK();
236 253
237 if (unknownSite) 254 if (unknownSite)
238 { 255 {
239 std::wstring t[] = { 256
240 L"======================================================================== ========", 257 DEBUG_GENERAL(L"============================================================ ====================\nNEW TAB UI\n============================================== ==================================")
241 L"NEW TAB UI",
242 L"======================================================================== ========"
243 };
244 DEBUG_GENERAL(t);
245 258
246 HRESULT hr = ::CoInitialize(NULL); 259 HRESULT hr = ::CoInitialize(NULL);
247 if (FAILED(hr)) 260 if (FAILED(hr))
248 { 261 {
249 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, L "Class::SetSite - CoInitialize"); 262 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, " Class::SetSite - CoInitialize");
250 } 263 }
251 264
252 s_criticalSectionBrowser.Lock(); 265 s_criticalSectionBrowser.Lock();
253 { 266 {
254 m_webBrowser2 = unknownSite; 267 m_webBrowser2 = unknownSite;
255 } 268 }
256 s_criticalSectionBrowser.Unlock(); 269 s_criticalSectionBrowser.Unlock();
257 270
258 //register the mimefilter 271 //register the mimefilter
259 //and only mimefilter 272 //and only mimefilter
260 //on some few computers the mimefilter does not get properly registered when it is done on another thread 273 //on some few computers the mimefilter does not get properly registered when it is done on another thread
261 274
262 s_criticalSectionLocal.Lock(); 275 s_criticalSectionLocal.Lock();
263 { 276 {
264 // Always register on startup, then check if we need to unregister in a se parate thread 277 // Always register on startup, then check if we need to unregister in a se parate thread
265 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 278 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
266 s_asyncWebBrowser2 = unknownSite; 279 s_asyncWebBrowser2 = unknownSite;
267 s_instances.Add(this); 280 s_instances.insert(this);
268 } 281 }
269 s_criticalSectionLocal.Unlock(); 282 s_criticalSectionLocal.Unlock();
270 283
271 try 284 try
272 { 285 {
273 // Check if loaded as BHO 286 // Check if loaded as BHO
274 if (GetBrowser()) 287 if (GetBrowser())
275 { 288 {
276 DEBUG_GENERAL(L"Loaded as BHO"); 289 DEBUG_GENERAL("Loaded as BHO");
277 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 290 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint();
278 if (pPoint) 291 if (pPoint)
279 { 292 {
280 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID); 293 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID);
281 if (SUCCEEDED(hr)) 294 if (SUCCEEDED(hr))
282 { 295 {
283 m_isAdviced = true; 296 m_isAdviced = true;
284 297
285 try 298 try
286 { 299 {
287 std::thread startInitObjectThread(StartInitObject, this); 300 std::thread startInitObjectThread(StartInitObject, this);
288 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr. 301 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr.
289 } 302 }
290 catch (const std::system_error& ex) 303 catch (const std::system_error& ex)
291 { 304 {
292 std::wstring errDescription( L"Class::Thread - Failed to create St artInitObject thread, " ); 305 auto errDescription = std::string("Class::Thread - Failed to creat e StartInitObject thread, ") +
293 errDescription += ABP::debug::widen( ex.code().message() + ex.what () ); 306 ex.code().message() + ex.what();
294 DEBUG_ERROR_LOG( ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ER ROR_MAIN_THREAD_CREATE_PROCESS, errDescription ); 307 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERR OR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str());
295 } 308 }
296 } 309 }
297 else 310 else
298 { 311 {
299 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, L"Class::SetSite - Advice"); 312 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advice");
300 } 313 }
301 } 314 }
302 } 315 }
303 else // Check if loaded as toolbar handler 316 else // Check if loaded as toolbar handler
304 { 317 {
305 DEBUG_GENERAL(L"Loaded as toolbar handler"); 318 DEBUG_GENERAL("Loaded as toolbar handler");
306 CComPtr<IServiceProvider> pServiceProvider; 319 CComPtr<IServiceProvider> pServiceProvider;
307 320
308 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); 321 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider);
309 if (SUCCEEDED(hr)) 322 if (SUCCEEDED(hr))
310 { 323 {
311 if (pServiceProvider) 324 if (pServiceProvider)
312 { 325 {
313 s_criticalSectionBrowser.Lock(); 326 s_criticalSectionBrowser.Lock();
314 { 327 {
315 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, &m _webBrowser2); 328 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, &m _webBrowser2);
316 if (SUCCEEDED(hr)) 329 if (SUCCEEDED(hr))
317 { 330 {
318 if (m_webBrowser2) 331 if (m_webBrowser2)
319 { 332 {
320 InitObject(false); 333 InitObject(false);
321 } 334 }
322 } 335 }
323 else 336 else
324 { 337 {
325 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE _QUERY_BROWSER, L"Class::SetSite - QueryService (IID_IWebBrowserApp)"); 338 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE _QUERY_BROWSER, "Class::SetSite - QueryService (IID_IWebBrowserApp)");
326 } 339 }
327 } 340 }
328 s_criticalSectionBrowser.Unlock(); 341 s_criticalSectionBrowser.Unlock();
329 } 342 }
330 } 343 }
331 else 344 else
332 { 345 {
333 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, L"Class::SetSite - QueryInterface (service provider)"); 346 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)");
334 } 347 }
335 } 348 }
336 } 349 }
337 catch (std::runtime_error e) 350 catch (std::runtime_error e)
338 { 351 {
339 DEBUG_ERROR(e.what()); 352 DEBUG_ERROR(e.what());
340 Unadvice(); 353 Unadvice();
341 } 354 }
342 } 355 }
343 else 356 else
(...skipping 17 matching lines...) Expand all
361 374
362 m_hTabWnd = NULL; 375 m_hTabWnd = NULL;
363 m_hStatusBarWnd = NULL; 376 m_hStatusBarWnd = NULL;
364 377
365 // Remove instance from the list, shutdown threads 378 // Remove instance from the list, shutdown threads
366 HANDLE hMainThread = NULL; 379 HANDLE hMainThread = NULL;
367 HANDLE hTabThread = NULL; 380 HANDLE hTabThread = NULL;
368 381
369 s_criticalSectionLocal.Lock(); 382 s_criticalSectionLocal.Lock();
370 { 383 {
371 s_instances.Remove(this); 384 s_instances.erase(this);
372 385
373 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId()); 386 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId());
374 if (it != s_threadInstances.end()) 387 if (it != s_threadInstances.end())
375 { 388 {
376 s_threadInstances.erase(it); 389 s_threadInstances.erase(it);
377 } 390 }
378 if (s_instances.GetSize() == 0) 391 if (s_instances.empty())
379 { 392 {
393 // TODO: Explicitly releasing a resource when a container becomes empty looks like a job better suited for shared_ptr
380 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 394 CPluginClientFactory::ReleaseMimeFilterClientInstance();
381 } 395 }
382 } 396 }
383 s_criticalSectionLocal.Unlock(); 397 s_criticalSectionLocal.Unlock();
384 398
385 // Release browser interface 399 // Release browser interface
386 s_criticalSectionBrowser.Lock(); 400 s_criticalSectionBrowser.Lock();
387 { 401 {
388 m_webBrowser2.Release(); 402 m_webBrowser2.Release();
389 } 403 }
390 s_criticalSectionBrowser.Unlock(); 404 s_criticalSectionBrowser.Unlock();
391 405
392 std::wstring t[] = { 406 DEBUG_GENERAL("============================================================= ===================\nNEW TAB UI - END\n========================================= =======================================")
393 L"======================================================================== ========",
394 L"NEW TAB UI - END",
395 L"======================================================================== ========"
396 };
397 DEBUG_GENERAL( t );
398 407
399 ::CoUninitialize(); 408 ::CoUninitialize();
400 } 409 }
401 410
402 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); 411 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
403 } 412 }
404 413
405 bool CPluginClass::IsStatusBarEnabled() 414 bool CPluginClass::IsStatusBarEnabled()
406 { 415 {
407 DEBUG_GENERAL(L"IsStatusBarEnabled start"); 416 DEBUG_GENERAL("IsStatusBarEnabled start");
408 HKEY pHkey; 417 HKEY pHkey;
409 HKEY pHkeySub; 418 HKEY pHkeySub;
410 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); 419 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey);
411 DWORD trueth = 1; 420 DWORD truth = 1;
412 DWORD truethSize = sizeof(DWORD); 421 DWORD truthSize = sizeof(truth);
413 RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\Main", &pHkeySub); 422 RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\Main", &pHkeySub);
414 LONG res = RegQueryValueEx(pHkeySub, L"StatusBarWeb", NULL, NULL, (BYTE*)&true th, &truethSize); 423 LONG res = RegQueryValueEx(pHkeySub, L"StatusBarWeb", NULL, NULL, (BYTE*)&trut h, &truthSize);
415 RegCloseKey(pHkey); 424 RegCloseKey(pHkey);
416 if (res != ERROR_SUCCESS) 425 if (res != ERROR_SUCCESS)
417 { 426 {
418 res = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\MINIE", &p HkeySub); 427 res = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\MINIE", &p HkeySub);
419 if (res == ERROR_SUCCESS) 428 if (res == ERROR_SUCCESS)
420 { 429 {
421 LONG res = RegQueryValueEx(pHkeySub, L"ShowStatusBar", NULL, NULL, (BYTE*) &trueth, &truethSize); 430 LONG res = RegQueryValueEx(pHkeySub, L"ShowStatusBar", NULL, NULL, (BYTE*) &truth, &truthSize);
422 if (res == ERROR_SUCCESS) 431 if (res == ERROR_SUCCESS)
423 { 432 {
424 RegCloseKey(pHkey); 433 RegCloseKey(pHkey);
425 } 434 }
426 } 435 }
427 } 436 }
428 DEBUG_GENERAL(L"IsStatusBarEnabled end"); 437 DEBUG_GENERAL("IsStatusBarEnabled end");
429 return trueth == 1; 438 return truth == 1;
430 } 439 }
431 440
432 void CPluginClass::ShowStatusBar() 441 void CPluginClass::ShowStatusBar()
433 { 442 {
434 DEBUG_GENERAL(L"ShowStatusBar start"); 443 DEBUG_GENERAL("ShowStatusBar start");
435 444
436 VARIANT_BOOL isVisible; 445 VARIANT_BOOL isVisible;
437 446
438 447
439 CComQIPtr<IWebBrowser2> ccom_browser = GetAsyncBrowser(); 448 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
440 if (ccom_browser) 449 if (browser)
441 { 450 {
442 Wrapper::Browser browser( ccom_browser );
443 HRESULT hr = S_OK; 451 HRESULT hr = S_OK;
444 hr = ccom_browser->get_StatusBar(&isVisible); 452 hr = browser->get_StatusBar(&isVisible);
445 if (SUCCEEDED(hr)) 453 if (SUCCEEDED(hr))
446 { 454 {
447 if (!isVisible) 455 if (!isVisible)
448 { 456 {
449 SHANDLE_PTR pBrowserHWnd; 457 SHANDLE_PTR pBrowserHWnd;
450 ccom_browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd); 458 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd);
451 Dictionary* dictionary = Dictionary::GetInstance(); 459 Dictionary* dictionary = Dictionary::GetInstance();
452 460
453 HKEY pHkey; 461 HKEY pHkey;
454 HKEY pHkeySub; 462 HKEY pHkeySub;
455 LSTATUS regRes = 0; 463 LSTATUS regRes = 0;
456 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey); 464 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey);
457 465
458 // Do we have enough rights to enable a status bar? 466 // Do we have enough rights to enable a status bar?
459 if (regRes != 0) 467 if (regRes != 0)
460 { 468 {
461 // We use the tab window here and in the next few calls, since the bro wser window may still not be available 469 // We use the tab window here and in the next few calls, since the bro wser window may still not be available
462 LRESULT res = MessageBox((HWND)m_hTabWnd, 470 LRESULT res = MessageBox((HWND)m_hTabWnd,
463 dictionary->Lookup("status-bar", "error-text").c_str(), 471 dictionary->Lookup("status-bar", "error-text").c_str(),
464 dictionary->Lookup("status-bar", "error-title").c_str(), 472 dictionary->Lookup("status-bar", "error-title").c_str(),
465 MB_OK); 473 MB_OK);
466 return; 474 return;
467 } 475 }
468 // Ask if a user wants to enable a status bar automatically 476 // Ask if a user wants to enable a status bar automatically
469 LRESULT res = MessageBox((HWND)m_hTabWnd, 477 LRESULT res = MessageBox((HWND)m_hTabWnd,
470 dictionary->Lookup("status-bar", "question").c_str(), 478 dictionary->Lookup("status-bar", "question").c_str(),
471 dictionary->Lookup("status-bar", "title").c_str(), 479 dictionary->Lookup("status-bar", "title").c_str(),
472 MB_YESNO); 480 MB_YESNO);
473 if (res == IDYES) 481 if (res == IDYES)
474 { 482 {
475 DWORD trueth = 1; 483 DWORD truth = 1;
476 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M INIE", &pHkeySub); 484 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M INIE", &pHkeySub);
477 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE *)&trueth, sizeof(DWORD)); 485 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE *)&truth, sizeof(truth));
478 regRes = RegCloseKey(pHkeySub); 486 regRes = RegCloseKey(pHkeySub);
479 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M ain", &pHkeySub); 487 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M ain", &pHkeySub);
480 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE* )&trueth, sizeof(DWORD)); 488 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE* )&truth, sizeof(truth));
481 regRes = RegCloseKey(pHkeySub); 489 regRes = RegCloseKey(pHkeySub);
482 hr = ccom_browser->put_StatusBar(TRUE); 490 hr = browser->put_StatusBar(TRUE);
483 if (FAILED(hr)) 491 if (FAILED(hr))
484 { 492 {
485 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, L"Class::Enable statusbar"); 493 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, "Class::Enable statusbar");
486 } 494 }
487 CreateStatusBarPane(); 495 CreateStatusBarPane();
488 496
489 /* 497 // We need to restart the tab now, to enable the status bar properly
490 * We need to restart the tab now, to enable the status bar properly 498 VARIANT vFlags;
491 */ 499 vFlags.vt = VT_I4;
492 std::wstring location; 500 vFlags.intVal = navOpenInNewTab;
493 browser.Location_URL( location ); 501
494 HRESULT hr = browser.navigate( location ); 502 CComBSTR curLoc;
495 if ( FAILED(hr) ) 503 browser->get_LocationURL(&curLoc);
504 HRESULT hr = browser->Navigate(curLoc, &vFlags, NULL, NULL, NULL);
505 if (FAILED(hr))
496 { 506 {
497 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION , L"Navigation::Failed") 507 vFlags.intVal = navOpenInNewWindow;
508
509 hr = browser->Navigate(CComBSTR(curLoc), &vFlags, NULL, NULL, NULL);
510 if (FAILED(hr))
511 {
512 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATI ON, "Navigation::Failed")
513 }
498 } 514 }
499 ccom_browser->Quit(); 515 browser->Quit();
500 } 516 }
501 } 517 }
502 } 518 }
503 else 519 else
504 { 520 {
505 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, L"Clas s::Get statusbar state"); 521 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
506 } 522 }
507 } 523 }
508 DEBUG_GENERAL(L"ShowStatusBar end"); 524 DEBUG_GENERAL("ShowStatusBar end");
509 } 525 }
510 526
527 /*
528 * #1163 This class is the implementation for method DISPID_BEFORENAVIGATE2 in C PluginClass::Invoke.
529 * - It validates and convertes its own arguments, rather than unifying them in the Invoke body.
530 * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu rn S_OK.
531 */
511 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) 532 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams)
512 { 533 {
513 534
514 if (pDispParams->cArgs < 7) 535 if (pDispParams->cArgs < 7)
515 { 536 {
516 return; 537 return;
517 } 538 }
518 //Register a mime filter if it's not registered yet 539 //Register a mime filter if it's not registered yet
519 if (s_mimeFilter == NULL) 540 if (s_mimeFilter == NULL)
520 { 541 {
521 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 542 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
522 } 543 }
523 544
524 // Get the IWebBrowser2 interface 545 // Get the IWebBrowser2 interface
525 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr; 546 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr;
526 VARTYPE vt = pDispParams->rgvarg[6].vt; 547 VARTYPE vt = pDispParams->rgvarg[6].vt;
527 if (vt == VT_DISPATCH) 548 if (vt == VT_DISPATCH)
528 { 549 {
529 // The implementation of this assignment operator contains the QueryInterfac e call.
530 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; 550 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal;
531 } 551 }
532 else 552 else
533 { 553 {
534 // Wrong type, return. 554 // Wrong type, return.
535 return; 555 return;
536 } 556 }
537 557
538 // Get the URL 558 // Get the URL
539 std::wstring url; 559 CString url;
540 vt = pDispParams->rgvarg[5].vt; 560 vt = pDispParams->rgvarg[5].vt;
541 if (vt == VT_BYREF + VT_VARIANT) 561 if (vt == VT_BYREF + VT_VARIANT)
542 { 562 {
543 url = pDispParams->rgvarg[5].pvarVal->bstrVal; 563 url = pDispParams->rgvarg[5].pvarVal->bstrVal;
544 Wrapper::Unescape_URL( url ); 564
565 CPluginClient::UnescapeUrl(url);
545 } 566 }
546 else 567 else
547 { 568 {
548 // Wrong type, return. 569 // Wrong type, return.
549 return; 570 return;
550 } 571 }
551 572
552 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page 573 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page
553 CPluginClient* client = CPluginClient::GetInstance(); 574 CPluginClient* client = CPluginClient::GetInstance();
554 575
555 // This comparison means "begins with" 576 if (url.Find(L"javascript") == 0)
556 if ( url.compare( 0, 10, L"javascript" ) == 0 )
557 { 577 {
558 } 578 }
559 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) 579 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr))
560 { 580 {
561 m_tab->OnNavigate( url ); 581 m_tab->OnNavigate(url);
562 582
563 std::wstring t[] = { 583 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + url + "\n=================== =============================================================")
564 L"======================================================================== ========",
565 L"Begin main navigation url:" + url,
566 L"======================================================================== ========"
567 };
568 DEBUG_GENERAL( t );
569 584
570 #ifdef ENABLE_DEBUG_RESULT 585 #ifdef ENABLE_DEBUG_RESULT
571 CPluginDebug::DebugResultDomain( url ); 586 CPluginDebug::DebugResultDomain(url);
572 #endif 587 #endif
573 588
574 UpdateStatusBar(); 589 UpdateStatusBar();
575 } 590 }
576 else 591 else
577 { 592 {
578 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 593 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
579 594 m_tab->CacheFrame(url);
580 #ifdef SUPPORT_FRAME_CACHING 595 }
581 m_tab->CacheFrame( url ); 596 }
582 #endif 597
583 } 598 /*
584 } 599 * #1163 implements behavior for method DISPID_WINDOWSTATECHANGED in CPluginClas s::Invoke
600 * - should validate and convert arguments in Invoke, not here
601 * - does not validate number of arguments before indexing into 'rgvarg'
602 * - does not validate type of argument before using its value
603 */
585 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) 604 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags)
586 { 605 {
587 DEBUG_GENERAL(L"Tab changed"); 606 DEBUG_GENERAL("Tab changed");
588 bool newtabshown = pDispParams->rgvarg[1].intVal==3; 607 bool newtabshown = pDispParams->rgvarg[1].intVal==3;
589 if (newtabshown) 608 if (newtabshown)
590 { 609 {
591 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); 610 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId());
592 if (it == s_threadInstances.end()) 611 if (it == s_threadInstances.end())
593 { 612 {
594 s_threadInstances[::GetCurrentThreadId()] = this; 613 s_threadInstances[::GetCurrentThreadId()] = this;
595
596
597 if (!m_isInitializedOk) 614 if (!m_isInitializedOk)
598 { 615 {
599 m_isInitializedOk = true; 616 m_isInitializedOk = true;
600 if (!InitObject(true)) 617 InitObject(true);
601 {
602 //» » » » » Unadvice();
603 }
604 UpdateStatusBar(); 618 UpdateStatusBar();
605 } 619 }
606 } 620 }
607 } 621 }
608 notificationMessage.Hide(); 622 notificationMessage.Hide();
609 DEBUG_GENERAL(L"Tab change end"); 623 DEBUG_GENERAL("Tab change end");
610 return VARIANT_TRUE; 624 return S_OK;
611 } 625 }
612 626
613 // This gets called whenever there's a browser event 627 // This gets called whenever there's a browser event
628 // ENTRY POINT
614 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) 629 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
615 { 630 {
616 WCHAR tmp[256]; 631 try
617 wsprintf(tmp, L"Invoke: %d\n", dispidMember); 632 {
618 DEBUG_GENERAL(tmp); 633 WCHAR tmp[256];
619 switch (dispidMember) 634 wsprintf(tmp, L"Invoke: %d\n", dispidMember);
620 { 635 DEBUG_GENERAL(tmp);
621 636 switch (dispidMember)
622 case DISPID_WINDOWSTATECHANGED: 637 {
623 return OnTabChanged(pDispParams, wFlags); 638 case DISPID_WINDOWSTATECHANGED:
624 break; 639 {
625 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE: 640 // #1163 should validate and convert arguments here
626 return VARIANT_TRUE; 641 return OnTabChanged(pDispParams, wFlags);
627 break; 642 }
628 643
629 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK: 644 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE:
630 return VARIANT_TRUE; 645 break;
631 break; 646
632 647 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK:
633 case DISPID_EVMETH_ONLOAD: 648 break;
634 DEBUG_NAVI("Navi::OnLoad") 649
635 return VARIANT_TRUE; 650 case DISPID_EVMETH_ONLOAD:
636 break; 651 DEBUG_NAVI("Navi::OnLoad")
637 652 break;
638 case DISPID_EVMETH_ONCHANGE: 653
639 return VARIANT_TRUE; 654 case DISPID_EVMETH_ONCHANGE:
640 655 break;
641 case DISPID_EVMETH_ONMOUSEDOWN: 656
642 return VARIANT_TRUE; 657 case DISPID_EVMETH_ONMOUSEDOWN:
643 658 break;
644 case DISPID_EVMETH_ONMOUSEENTER: 659
645 return VARIANT_TRUE; 660 case DISPID_EVMETH_ONMOUSEENTER:
646 661 break;
647 case DISPID_IHTMLIMGELEMENT_START: 662
648 return VARIANT_TRUE; 663 case DISPID_IHTMLIMGELEMENT_START:
649 664 break;
650 case STDDISPID_XOBJ_ERRORUPDATE: 665
651 return VARIANT_TRUE; 666 case STDDISPID_XOBJ_ERRORUPDATE:
652 667 break;
653 case STDDISPID_XOBJ_ONPROPERTYCHANGE: 668
654 return VARIANT_TRUE; 669 case STDDISPID_XOBJ_ONPROPERTYCHANGE:
655 670 break;
656 case DISPID_READYSTATECHANGE: 671
657 DEBUG_NAVI("Navi::ReadyStateChange") 672 case DISPID_READYSTATECHANGE:
658 return VARIANT_TRUE; 673 DEBUG_NAVI("Navi::ReadyStateChange");
659 674 break;
660 case DISPID_BEFORENAVIGATE: 675
661 DEBUG_NAVI("Navi::BeforeNavigate") 676 case DISPID_BEFORENAVIGATE:
662 return VARIANT_TRUE; 677 DEBUG_NAVI("Navi::BeforeNavigate");
663 case DISPID_COMMANDSTATECHANGE: 678 break;
664 if (m_hPaneWnd == NULL) 679
665 { 680 case DISPID_COMMANDSTATECHANGE:
666 CreateStatusBarPane(); 681 if (m_hPaneWnd == NULL)
667 } 682 {
668 else 683 CreateStatusBarPane();
669 { 684 }
670 if ( ABP::IE::installed_major_version() > 6 ) 685 else
671 { 686 {
672 RECT rect; 687 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
673 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); 688 {
674 if (rectRes == TRUE) 689 RECT rect;
675 { 690 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect);
676 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom - rect.top, TRUE); 691 if (rectRes == TRUE)
677 } 692 {
678 } 693 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.botto m - rect.top, TRUE);
679 } 694 }
680 break; 695 }
681 case DISPID_STATUSTEXTCHANGE: 696 }
682 break; 697 break;
683 698
684 case DISPID_BEFORENAVIGATE2: 699 case DISPID_STATUSTEXTCHANGE:
685 BeforeNavigate2(pDispParams); 700 break;
686 break; 701
687 702 case DISPID_BEFORENAVIGATE2:
688 case DISPID_DOWNLOADBEGIN: 703 {
689 { 704 // #1163 should validate and convert parameters here
690 DEBUG_NAVI("Navi::Download Begin") 705 BeforeNavigate2(pDispParams);
691 } 706 }
692 break; 707 break;
693 708
694 case DISPID_DOWNLOADCOMPLETE: 709 case DISPID_DOWNLOADBEGIN:
695 { 710 {
696 DEBUG_NAVI("Navi::Download Complete") 711 DEBUG_NAVI("Navi::Download Begin")
697 712 }
713 break;
714
715 case DISPID_DOWNLOADCOMPLETE:
716 {
717 DEBUG_NAVI("Navi::Download Complete");
698 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 718 CComQIPtr<IWebBrowser2> browser = GetBrowser();
699 if (browser) 719 if (browser)
700 { 720 {
701 m_tab->OnDownloadComplete(browser); 721 m_tab->OnDownloadComplete(browser);
702 } 722 }
703 } 723 }
704 break; 724 break;
705 725
706 case DISPID_DOCUMENTCOMPLETE: 726 case DISPID_DOCUMENTCOMPLETE:
707 { 727 {
708 DEBUG_NAVI("Navi::Document Complete") 728 DEBUG_NAVI("Navi::Document Complete");
709 729 CComQIPtr<IWebBrowser2> browser = GetBrowser();
710 CComQIPtr<IWebBrowser2> ccom_browser = GetBrowser(); 730 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V T_DISPATCH)
711 731 {
712 if (ccom_browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt = = VT_DISPATCH) 732 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
713 { 733 if (pBrowser)
714 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
715 if (pBrowser)
716 {
717 Wrapper::Browser browser( pBrowser );
718 std::wstring url;
719 if ( browser.Location_URL( url ) && !url.empty() )
720 { 734 {
721 Wrapper::Unescape_URL(url); 735 CString url;
722 m_tab->OnDocumentComplete(ccom_browser, url, ccom_browser.IsEqualObj ect(pBrowser)); 736 CComBSTR bstrUrl;
737 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen (bstrUrl) > 0)
738 {
739 url = bstrUrl;
740 CPluginClient::UnescapeUrl(url);
741 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBro wser));
742 }
723 } 743 }
724 } 744 }
725 } 745 }
726 } 746 break;
727 break; 747
728 748 case DISPID_ONQUIT:
729 case DISPID_ONQUIT: 749 case DISPID_QUIT:
730 case DISPID_QUIT: 750 {
731 { 751 Unadvice();
732 Unadvice(); 752 }
733 } 753 break;
734 break; 754
735 755 default:
736 default: 756 {
737 { 757 CString did;
738 std::wostringstream msg; 758 did.Format(L"DispId:%u", dispidMember);
739 msg << L"Navi::Default DispId:"; 759
740 msg << static_cast< unsigned long >( dispidMember ); 760 DEBUG_NAVI(L"Navi::Default " + did)
741 DEBUG_NAVI( msg.str() ) 761 }
742 } 762 /*
743 763 * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND.
744 // do nothing 764 * As a conservative initial change, we leave it behaving as before,
745 break; 765 * which is to do nothing and return S_OK.
746 } 766 */
747 767 // do nothing
748 return VARIANT_TRUE; 768 break;
769 }
770 }
771 catch(...)
772 {
773 DEBUG_GENERAL( "Caught unknown exception in CPluginClass::Invoke" );
774 return E_FAIL;
775 }
776 return S_OK;
749 } 777 }
750 778
751 bool CPluginClass::InitObject(bool bBHO) 779 bool CPluginClass::InitObject(bool bBHO)
752 { 780 {
753 DEBUG_GENERAL(L"InitObject"); 781 DEBUG_GENERAL("InitObject");
754 CPluginSettings* settings = CPluginSettings::GetInstance(); 782 CPluginSettings* settings = CPluginSettings::GetInstance();
755 783
756 if (!settings->GetPluginEnabled()) 784 if (!settings->GetPluginEnabled())
757 { 785 {
758 s_mimeFilter->Unregister(); 786 s_mimeFilter->Unregister();
759 } 787 }
760 788
761 // Load theme module 789 // Load theme module
762 s_criticalSectionLocal.Lock(); 790 s_criticalSectionLocal.Lock();
763 { 791 {
764 if (!s_hUxtheme) 792 if (!s_hUxtheme)
765 { 793 {
766 s_hUxtheme = ::GetModuleHandleW(L"uxtheme.dll"); 794 s_hUxtheme = ::GetModuleHandle(L"uxtheme.dll");
767 if (s_hUxtheme) 795 if (s_hUxtheme)
768 { 796 {
769 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData" ); 797 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData" );
770 if (!pfnClose) 798 if (!pfnClose)
771 { 799 {
772 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_CLOSE, L"Class::InitObject - GetProcAddress(CloseThemeData)"); 800 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_CLOSE, "Class::InitObject - GetProcAddress(CloseThemeData)");
773 } 801 }
774 802
775 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem e, "DrawThemeBackground"); 803 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem e, "DrawThemeBackground");
776 if (!pfnDrawThemeBackground) 804 if (!pfnDrawThemeBackground)
777 { 805 {
778 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_DRAW_BACKGROUND, L"Class::InitObject - GetProcAddress(DrawThemeBackgrou nd)"); 806 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_DRAW_BACKGROUND, "Class::InitObject - GetProcAddress(DrawThemeBackgroun d)");
779 } 807 }
780 808
781 pfnOpenThemeData = (OPENTHEMEDATA)::GetProcAddress(s_hUxtheme, "OpenThem eData"); 809 pfnOpenThemeData = (OPENTHEMEDATA)::GetProcAddress(s_hUxtheme, "OpenThem eData");
782 if (!pfnOpenThemeData) 810 if (!pfnOpenThemeData)
783 { 811 {
784 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_OPEN, L"Class::InitObject - GetProcAddress(pfnOpenThemeData)"); 812 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET _UXTHEME_OPEN, "Class::InitObject - GetProcAddress(pfnOpenThemeData)");
785 } 813 }
786 } 814 }
787 else 815 else
788 { 816 {
789 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_U XTHEME, L"Class::InitObject - GetModuleHandle(uxtheme.dll)"); 817 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_U XTHEME, "Class::InitObject - GetModuleHandle(uxtheme.dll)");
790 } 818 }
791 } 819 }
792 } 820 }
793 s_criticalSectionLocal.Unlock(); 821 s_criticalSectionLocal.Unlock();
794 822
795 // Register pane class 823 // Register pane class
796 if (!GetAtomPaneClass()) 824 if (!GetAtomPaneClass())
797 { 825 {
798 WNDCLASSEX wcex; 826 WNDCLASSEX wcex;
799 827
800 wcex.cbSize = sizeof(WNDCLASSEX); 828 wcex.cbSize = sizeof(wcex);
801 wcex.style = 0; 829 wcex.style = 0;
802 wcex.lpfnWndProc = (WNDPROC)PaneWindowProc; 830 wcex.lpfnWndProc = (WNDPROC)PaneWindowProc;
803 wcex.cbClsExtra = 0; 831 wcex.cbClsExtra = 0;
804 wcex.cbWndExtra = 0; 832 wcex.cbWndExtra = 0;
805 wcex.hInstance = _Module.m_hInst; 833 wcex.hInstance = _Module.m_hInst;
806 wcex.hIcon = NULL; 834 wcex.hIcon = NULL;
807 wcex.hCursor = NULL; 835 wcex.hCursor = NULL;
808 wcex.hbrBackground = NULL; 836 wcex.hbrBackground = NULL;
809 wcex.lpszMenuName = NULL; 837 wcex.lpszMenuName = NULL;
810 wcex.lpszClassName = _T(STATUSBAR_PANE_NAME); 838 wcex.lpszClassName = STATUSBAR_PANE_NAME;
811 wcex.hIconSm = NULL; 839 wcex.hIconSm = NULL;
812 840
813 s_criticalSectionLocal.Lock(); 841 s_criticalSectionLocal.Lock();
814 { 842 {
815 s_atomPaneClass = ::RegisterClassEx(&wcex); 843 s_atomPaneClass = ::RegisterClassEx(&wcex);
816 } 844 }
817 s_criticalSectionLocal.Unlock(); 845 s_criticalSectionLocal.Unlock();
818 846
819 if (!GetAtomPaneClass()) 847 if (!GetAtomPaneClass())
820 { 848 {
821 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, L"Class::InitObject - RegisterClassEx"); 849 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx");
822 return false; 850 return false;
823 } 851 }
824 } 852 }
825 853
826 854 int ieVersion = AdblockPlus::IE::InstalledMajorVersion();
827 int ieVersion = ABP::IE::installed_major_version();
828 // Create status pane 855 // Create status pane
829 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) 856 if (bBHO && ieVersion > 6 && !CreateStatusBarPane())
830 { 857 {
831 return false; 858 return false;
832 } 859 }
833 860
834 if (CPluginClient::GetInstance()->IsFirstRun()) 861 s_criticalSectionLocal.Lock();
862 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2");
863
864 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun();
865 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN _VERSION));
866 // This is the first time ABP was installed
867 // Or ABP was updated from the version that did not support Acceptable Ads (<1 .2)
868 if (isFirstRun || versionCompRes < 0)
835 { 869 {
870 if (!isFirstRun)
871 {
872 CPluginClient::GetInstance()->SetPref(L"displayUpdatePage", true);
873 }
874
836 // IE6 can't be accessed from another thread, execute in current thread 875 // IE6 can't be accessed from another thread, execute in current thread
837 if (ieVersion < 7) 876 if (ieVersion < 7)
838 { 877 {
839 FirstRunThread(); 878 FirstRunThread();
840 } 879 }
841 else 880 else
842 { 881 {
843 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CPluginClass::FirstRunThr ead, NULL, NULL, NULL); 882 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CPluginClass::FirstRunThr ead, NULL, NULL, NULL);
844 } 883 }
845 if ((m_hPaneWnd == NULL) || (!IsStatusBarEnabled())) 884 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun)
846 { 885 {
847 ShowStatusBar(); 886 ShowStatusBar();
848 } 887 }
849 888
850 } 889 // Enable acceptable ads by default
890 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L"");
891 CPluginClient::GetInstance()->AddSubscription(aaUrl);
892 }
893 s_criticalSectionLocal.Unlock();
851 return true; 894 return true;
852 } 895 }
853 896
854 bool CPluginClass::CreateStatusBarPane() 897 bool CPluginClass::CreateStatusBarPane()
855 { 898 {
856 CriticalSection::Lock lock(m_csStatusBar); 899 CriticalSection::Lock lock(m_csStatusBar);
857 900
858 CPluginClient* client = CPluginClient::GetInstance(); 901 CPluginClient* client = CPluginClient::GetInstance();
859 902
860 TCHAR szClassName[MAX_PATH]; 903 std::array<wchar_t, MAX_PATH> className;
861 // Get browser window and url 904 // Get browser window and url
862 HWND hBrowserWnd = GetBrowserHWND(); 905 HWND hBrowserWnd = GetBrowserHWND();
863 if (!hBrowserWnd) 906 if (!hBrowserWnd)
864 { 907 {
865 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, L" Class::CreateStatusBarPane - No status bar") 908 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::CreateStatusBarPane - No status bar")
866 return false; 909 return false;
867 } 910 }
868 911
869 // Looking for a TabWindowClass window in IE7 912 // Looking for a TabWindowClass window in IE7
870 // the last one should be parent for statusbar 913 // the last one should be parent for statusbar
871 HWND hWndStatusBar = NULL; 914 HWND hWndStatusBar = NULL;
872 915
873 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 916 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
874 UINT amoundOfNewTabs = 0; 917 UINT amoundOfNewTabs = 0;
875 HWND uniqueNewTab = NULL; 918 HWND uniqueNewTab = NULL;
876 while (hTabWnd) 919 while (hTabWnd)
877 { 920 {
878 memset(szClassName, 0, MAX_PATH); 921 className[0] = L'\0';
879 GetClassName(hTabWnd, szClassName, MAX_PATH); 922 // GetClassNameW returns the number of characters without '\0'
880 923 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz e());
881 if (_tcscmp(szClassName, _T("TabWindowClass")) == 0 || _tcscmp(szClassName,_ T("Frame Tab")) == 0) 924
925 if (classNameLength && (wcscmp(className.data(), L"TabWindowClass") == 0 || wcscmp(className.data(), L"Frame Tab") == 0))
882 { 926 {
883 // IE8 support 927 // IE8 support
884 HWND hTabWnd2 = hTabWnd; 928 HWND hTabWnd2 = hTabWnd;
885 if (_tcscmp(szClassName,_T("Frame Tab")) == 0) 929 if (wcscmp(className.data(), L"Frame Tab") == 0)
886 { 930 {
887 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, _T("TabWindowClass"), NULL); 931 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL);
888 } 932 }
889 933
890 if (hTabWnd2) 934 if (hTabWnd2)
891 { 935 {
892 DWORD nProcessId; 936 DWORD nProcessId;
893 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); 937 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
894 if (::GetCurrentProcessId() == nProcessId) 938 if (::GetCurrentProcessId() == nProcessId)
895 { 939 {
896 bool bExistingTab = false; 940 bool bExistingTab = false;
897 941
898 s_criticalSectionLocal.Lock(); 942 s_criticalSectionLocal.Lock();
899 { 943 {
900 for (int i = 0; i < s_instances.GetSize(); i++) 944 for (auto instance : s_instances)
901 { 945 {
902 if (s_instances[i]->m_hTabWnd == hTabWnd2) 946 if (instance->m_hTabWnd == hTabWnd2)
903 { 947 {
904
905 bExistingTab = true; 948 bExistingTab = true;
906 break; 949 break;
907 } 950 }
908 } 951 }
909 } 952 }
910 s_criticalSectionLocal.Unlock(); 953 s_criticalSectionLocal.Unlock();
911 954
912 if (!bExistingTab) 955 if (!bExistingTab)
913 { 956 {
914 amoundOfNewTabs ++; 957 amoundOfNewTabs ++;
915 uniqueNewTab = hTabWnd2; 958 uniqueNewTab = hTabWnd2;
916 if (GetCurrentThreadId() == GetWindowThreadProcessId(hTabWnd2, NULL) ) 959 if (GetCurrentThreadId() == GetWindowThreadProcessId(hTabWnd2, NULL) )
917 { 960 {
918 hBrowserWnd = hTabWnd = hTabWnd2; 961 hBrowserWnd = hTabWnd = hTabWnd2;
919 break; 962 break;
920 } 963 }
921 964
922 } 965 }
923 } 966 }
924 } 967 }
925 } 968 }
926 969
927 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 970 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
928 } 971 }
929 972
930 HWND hWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 973 HWND hWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
931 while (hWnd) 974 while (hWnd)
932 { 975 {
933 memset(szClassName, 0, MAX_PATH); 976 className[0] = L'\0';
934 ::GetClassName(hWnd, szClassName, MAX_PATH); 977 int classNameLength = GetClassNameW(hWnd, className.data(), className.size() );
935 978
936 if (_tcscmp(szClassName,_T("msctls_statusbar32")) == 0) 979 if (classNameLength && wcscmp(className.data(), L"msctls_statusbar32") == 0)
937 { 980 {
938 hWndStatusBar = hWnd; 981 hWndStatusBar = hWnd;
939 break; 982 break;
940 } 983 }
941 984
942 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); 985 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT);
943 } 986 }
944 987
945 if (!hWndStatusBar) 988 if (!hWndStatusBar)
946 { 989 {
947 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, L"Clas s::CreateStatusBarPane - No status bar") 990 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_WIN, "Class ::CreateStatusBarPane - No status bar")
948 return true; 991 return true;
949 } 992 }
950 993
951 // Calculate pane height 994 // Calculate pane height
952 CRect rcStatusBar; 995 AdblockPlus::Rectangle rcStatusBar;
953 ::GetClientRect(hWndStatusBar, &rcStatusBar); 996 ::GetClientRect(hWndStatusBar, &rcStatusBar);
954 997
955 if (rcStatusBar.Height() > 0) 998 if (rcStatusBar.Height() > 0)
956 { 999 {
957 #ifdef _DEBUG 1000 #ifdef _DEBUG
958 m_nPaneWidth = 70; 1001 m_nPaneWidth = 70;
959 #else 1002 #else
960 m_nPaneWidth = min(rcStatusBar.Height(), 22); 1003 m_nPaneWidth = min(rcStatusBar.Height(), 22);
961 #endif 1004 #endif
962 } 1005 }
963 else 1006 else
964 { 1007 {
965 #ifdef _DEBUG 1008 #ifdef _DEBUG
966 m_nPaneWidth = 70; 1009 m_nPaneWidth = 70;
967 #else 1010 #else
968 m_nPaneWidth = 22; 1011 m_nPaneWidth = 22;
969 #endif 1012 #endif
970 } 1013 }
971 // Create pane window 1014 // Create pane window
972 HWND hWndNewPane = ::CreateWindowEx( 1015 HWND hWndNewPane = ::CreateWindowEx(
973 NULL, 1016 NULL,
974 MAKEINTATOM(GetAtomPaneClass()), 1017 MAKEINTATOM(GetAtomPaneClass()),
975 _T(""), 1018 L"",
976 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 1019 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
977 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), 1020 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(),
978 hWndStatusBar, 1021 hWndStatusBar,
979 (HMENU)3671, 1022 (HMENU)3671,
980 _Module.m_hInst, 1023 _Module.m_hInst,
981 NULL); 1024 NULL);
982 1025
983 if (!hWndNewPane) 1026 if (!hWndNewPane)
984 { 1027 {
985 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, L"Class::CreateStatusBarPane - CreateWindowEx") 1028 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_ST ATUSBAR_PANE, "Class::CreateStatusBarPane - CreateWindowEx")
986 return false; 1029 return false;
987 } 1030 }
988 1031
989 DEBUG_GENERAL(L"ABP window created"); 1032 DEBUG_GENERAL("ABP window created");
990 m_hTabWnd = hTabWnd; 1033 m_hTabWnd = hTabWnd;
991 m_hStatusBarWnd = hWndStatusBar; 1034 m_hStatusBarWnd = hWndStatusBar;
992 m_hPaneWnd = hWndNewPane; 1035 m_hPaneWnd = hWndNewPane;
993 1036
994 UpdateTheme(); 1037 UpdateTheme();
995 1038
996 // Subclass status bar 1039 // Subclass status bar
997 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA RAM)(WNDPROC)NewStatusProc); 1040 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA RAM)(WNDPROC)NewStatusProc);
998 1041
999 // Adjust pane 1042 // Adjust pane
(...skipping 12 matching lines...) Expand all
1012 HDC hdc = GetWindowDC(m_hStatusBarWnd); 1055 HDC hdc = GetWindowDC(m_hStatusBarWnd);
1013 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); 1056 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0);
1014 ReleaseDC(m_hStatusBarWnd, hdc); 1057 ReleaseDC(m_hStatusBarWnd, hdc);
1015 1058
1016 return true; 1059 return true;
1017 } 1060 }
1018 1061
1019 void CPluginClass::FirstRunThread() 1062 void CPluginClass::FirstRunThread()
1020 { 1063 {
1021 CoInitialize(NULL); 1064 CoInitialize(NULL);
1022 1065 VARIANT vFlags;
1023 Wrapper::Browser browser( GetAsyncBrowser() ); 1066 vFlags.vt = VT_I4;
1024 HRESULT hr = browser.navigate( FirstRunPageFileUrl() ); 1067 vFlags.intVal = navOpenInNewTab;
1025 if ( FAILED( hr ) ) 1068
1026 { 1069 CComBSTR navigatePath = CComBSTR(FirstRunPageFileUrl().c_str());
1027 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_WELCOME , L"Navigation::Welcome page failed") 1070
1028 } 1071 HRESULT hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NU LL);
1029 } 1072 if (FAILED(hr))
1030 1073 {
1074 vFlags.intVal = navOpenInNewWindow;
1075 hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NULL);
1076 }
1077
1078 if (FAILED(hr))
1079 {
1080 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_WELCOME , "Navigation::Welcome page failed")
1081 }
1082 }
1031 void CPluginClass::CloseTheme() 1083 void CPluginClass::CloseTheme()
1032 { 1084 {
1033 if (m_hTheme) 1085 if (m_hTheme)
1034 { 1086 {
1035 if (pfnClose) 1087 if (pfnClose)
1036 { 1088 {
1037 pfnClose(m_hTheme); 1089 pfnClose(m_hTheme);
1038 } 1090 }
1039 1091
1040 m_hTheme = NULL; 1092 m_hTheme = NULL;
1041 } 1093 }
1042 } 1094 }
1043 1095
1044 void CPluginClass::UpdateTheme() 1096 void CPluginClass::UpdateTheme()
1045 { 1097 {
1046 CloseTheme(); 1098 CloseTheme();
1047 1099
1048 if (pfnOpenThemeData) 1100 if (pfnOpenThemeData)
1049 { 1101 {
1050 m_hTheme = pfnOpenThemeData(m_hPaneWnd, L"STATUS"); 1102 m_hTheme = pfnOpenThemeData(m_hPaneWnd, L"STATUS");
1051 if (!m_hTheme) 1103 if (!m_hTheme)
1052 { 1104 {
1053 } 1105 }
1054 } 1106 }
1055 } 1107 }
1056 1108
1057 1109
1058 CPluginClass* CPluginClass::FindInstance(HWND hStatusBarWnd) 1110 CPluginClass* CPluginClass::FindInstance(HWND hStatusBarWnd)
1059 { 1111 {
1060 CPluginClass* instance = NULL; 1112 CPluginClass* result = nullptr;
1061 1113
1062 s_criticalSectionLocal.Lock(); 1114 s_criticalSectionLocal.Lock();
1063 { 1115 {
1064 for (int i = 0; i < s_instances.GetSize(); i++) 1116 for (auto instance : s_instances)
1065 { 1117 {
1066 if (s_instances[i]->m_hStatusBarWnd == hStatusBarWnd) 1118 if (instance->m_hStatusBarWnd == hStatusBarWnd)
1067 { 1119 {
1068 instance = s_instances[i]; 1120 result = instance;
1069 break; 1121 break;
1070 } 1122 }
1071 } 1123 }
1072 } 1124 }
1073 s_criticalSectionLocal.Unlock(); 1125 s_criticalSectionLocal.Unlock();
1074 1126
1075 return instance; 1127 return result;
1076 } 1128 }
1077 1129
1078 CPluginTab* CPluginClass::GetTab() 1130 CPluginTab* CPluginClass::GetTab()
1079 { 1131 {
1080 return m_tab; 1132 return m_tab;
1081 } 1133 }
1082 1134
1083 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) 1135 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId)
1084 { 1136 {
1085 CPluginTab* tab = NULL; 1137 CPluginTab* tab = NULL;
(...skipping 15 matching lines...) Expand all
1101 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1153 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1102 { 1154 {
1103 if (cCmds == 0) return E_INVALIDARG; 1155 if (cCmds == 0) return E_INVALIDARG;
1104 if (prgCmds == 0) return E_POINTER; 1156 if (prgCmds == 0) return E_POINTER;
1105 1157
1106 prgCmds[0].cmdf = OLECMDF_ENABLED; 1158 prgCmds[0].cmdf = OLECMDF_ENABLED;
1107 1159
1108 return S_OK; 1160 return S_OK;
1109 } 1161 }
1110 1162
1111 HMENU CPluginClass::CreatePluginMenu(const std::wstring & url) 1163 HMENU CPluginClass::CreatePluginMenu(const CString& url)
1112 { 1164 {
1113 DEBUG_GENERAL(L"CreatePluginMenu"); 1165 DEBUG_GENERAL("CreatePluginMenu");
1114 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1166 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1115 1167
1116 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1168 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1117 1169
1118 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); 1170 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);
1119 1171
1120 SetMenuBar(hMenuTrackPopup, url); 1172 SetMenuBar(hMenuTrackPopup, url);
1121 1173
1122 return hMenuTrackPopup; 1174 return hMenuTrackPopup;
1123 } 1175 }
1124 BOOL CreateLowProcess(WCHAR* wszProcessName, WCHAR* cmdLine)
1125 {
1126
1127 BOOL fRet;
1128 HANDLE hToken = NULL;
1129 HANDLE hNewToken = NULL;
1130 PSID pIntegritySid = NULL;
1131 TOKEN_MANDATORY_LABEL TIL = {0};
1132 PROCESS_INFORMATION ProcInfo = {0};
1133 STARTUPINFO StartupInfo = {0};
1134
1135
1136
1137 // Low integrity SID
1138 WCHAR wszIntegritySid[20] = L"S-1-16-4096";
1139
1140
1141 fRet = OpenProcessToken(GetCurrentProcess(),
1142 TOKEN_DUPLICATE |
1143 TOKEN_ADJUST_DEFAULT |
1144 TOKEN_QUERY |
1145 TOKEN_ASSIGN_PRIMARY,
1146 &hToken);
1147
1148 if (!fRet)
1149 {
1150 goto CleanExit;
1151 }
1152
1153 fRet = DuplicateTokenEx(hToken,
1154 0,
1155 NULL,
1156 SecurityImpersonation,
1157 TokenPrimary,
1158 &hNewToken);
1159
1160 if (!fRet)
1161 {
1162 goto CleanExit;
1163 }
1164
1165 fRet = ConvertStringSidToSid(wszIntegritySid, &pIntegritySid);
1166
1167 if (!fRet)
1168 {
1169 goto CleanExit;
1170 }
1171
1172
1173 TIL.Label.Attributes = SE_GROUP_INTEGRITY;
1174 TIL.Label.Sid = pIntegritySid;
1175
1176
1177 //
1178 // Set the process integrity level
1179 //
1180
1181 fRet = SetTokenInformation(hNewToken,
1182 TokenIntegrityLevel,
1183 &TIL,
1184 sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(pIntegritySid));
1185
1186 if (!fRet)
1187 {
1188 goto CleanExit;
1189 }
1190
1191 //
1192 // Create the new process at Low integrity
1193 //
1194
1195 fRet = CreateProcessAsUser(hNewToken,
1196 wszProcessName,
1197 cmdLine,
1198 NULL,
1199 NULL,
1200 FALSE,
1201 0,
1202 NULL,
1203 NULL,
1204 &StartupInfo,
1205 &ProcInfo);
1206
1207
1208 CleanExit:
1209
1210 if (ProcInfo.hProcess != NULL)
1211 {
1212 CloseHandle(ProcInfo.hProcess);
1213 }
1214
1215 if (ProcInfo.hThread != NULL)
1216 {
1217 CloseHandle(ProcInfo.hThread);
1218 }
1219
1220 LocalFree(pIntegritySid);
1221
1222 if (hNewToken != NULL)
1223 {
1224 CloseHandle(hNewToken);
1225 }
1226
1227 if (hToken != NULL)
1228 {
1229 CloseHandle(hToken);
1230 }
1231
1232 return fRet;
1233 }
1234 1176
1235 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U INT nMenuFlags) 1177 void CPluginClass::DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, U INT nMenuFlags)
1236 { 1178 {
1237 CPluginClient* client = CPluginClient::GetInstance(); 1179 CPluginClient* client = CPluginClient::GetInstance();
1238
1239 CPluginSystem* system = CPluginSystem::GetInstance();
1240 1180
1241 // Create menu parent window 1181 // Create menu parent window
1242 HWND hMenuWnd = ::CreateWindowEx( 1182 HWND hMenuWnd = ::CreateWindowEx(
1243 NULL, 1183 NULL,
1244 MAKEINTATOM(GetAtomPaneClass()), 1184 MAKEINTATOM(GetAtomPaneClass()),
1245 _T(""), 1185 L"",
1246 0, 1186 0,
1247 0,0,0,0, 1187 0,0,0,0,
1248 NULL, 1188 NULL,
1249 NULL, 1189 NULL,
1250 _Module.m_hInst, 1190 _Module.m_hInst,
1251 NULL); 1191 NULL);
1252 1192
1253 if (!hMenuWnd) 1193 if (!hMenuWnd)
1254 { 1194 {
1255 DestroyMenu(hMenu); 1195 DestroyMenu(hMenu);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 } 1238 }
1299 } 1239 }
1300 s_criticalSectionLocal.Unlock(); 1240 s_criticalSectionLocal.Unlock();
1301 } 1241 }
1302 break; 1242 break;
1303 case ID_MENU_SETTINGS: 1243 case ID_MENU_SETTINGS:
1304 { 1244 {
1305 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 1245 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1306 if (browser) 1246 if (browser)
1307 { 1247 {
1308 Wrapper::Browser b( browser ); 1248 VARIANT vFlags;
1309 HRESULT hr = b.navigate( UserSettingsFileUrl() ); 1249 vFlags.vt = VT_I4;
1310 if ( FAILED(hr) ) 1250 vFlags.intVal = navOpenInNewTab;
1311 { 1251
1312 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_S ETTINGS, L"Navigation::Failed") 1252 BSTR urlToNavigate = BString(UserSettingsFileUrl());
1253 HRESULT hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL) ;
1254 if (FAILED(hr))
1255 {
1256 vFlags.intVal = navOpenInNewWindow;
1257
1258 hr = browser->Navigate(urlToNavigate, &vFlags, NULL, NULL, NULL);
1259 if (FAILED(hr))
1260 {
1261 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1262 }
1313 } 1263 }
1314 } 1264 }
1315 break; 1265 break;
1316 } 1266 }
1317 case ID_MENU_DISABLE_ON_SITE: 1267 case ID_MENU_DISABLE_ON_SITE:
1318 { 1268 {
1319 CPluginSettings* settings = CPluginSettings::GetInstance(); 1269 CPluginSettings* settings = CPluginSettings::GetInstance();
1320 std::wstring urlString = GetTab()->GetDocumentUrl(); 1270 CString urlString = GetTab()->GetDocumentUrl();
1321 if (client->IsWhitelistedUrl(urlString)) 1271 if (client->IsWhitelistedUrl(to_wstring(urlString)))
1322 { 1272 {
1323 settings->RemoveWhiteListedDomain( client->GetHostFromUrl( urlString ).c _str() ); 1273 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w string(urlString))));
1324 } 1274 }
1325 else 1275 else
1326 { 1276 {
1327 settings->AddWhiteListedDomain( client->GetHostFromUrl( urlString).c_str ()); 1277 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr ing(urlString))));
1328 } 1278 }
1329 GetBrowser()->Refresh(); 1279 GetBrowser()->Refresh();
1330 } 1280 }
1331 default: 1281 default:
1332 break; 1282 break;
1333 } 1283 }
1334 1284
1335 // Invalidate and redraw the control 1285 // Invalidate and redraw the control
1336 UpdateStatusBar(); 1286 UpdateStatusBar();
1337 } 1287 }
1338 1288
1339 1289
1340 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring & url) 1290 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url)
1341 { 1291 {
1342 DEBUG_GENERAL(L"SetMenuBar"); 1292 DEBUG_GENERAL("SetMenuBar");
1343 1293
1344 std::wstring ctext; 1294 std::wstring ctext;
1345
1346 s_criticalSectionLocal.Lock();
1347 {
1348 #ifdef SUPPORT_WHITELIST
1349 s_menuDomains.clear();
1350 #endif
1351 }
1352 s_criticalSectionLocal.Unlock();
1353
1354
1355 Dictionary* dictionary = Dictionary::GetInstance(); 1295 Dictionary* dictionary = Dictionary::GetInstance();
1356 1296
1357 MENUITEMINFOW fmii; 1297 MENUITEMINFOW fmii = {};
1358 memset(&fmii, 0, sizeof(MENUITEMINFO)); 1298 fmii.cbSize = sizeof(fmii);
1359 fmii.cbSize = sizeof(MENUITEMINFO); 1299
1360 1300 MENUITEMINFOW miiSep = {};
1361 MENUITEMINFOW miiSep; 1301 miiSep.cbSize = sizeof(miiSep);
1362 memset(&miiSep, 0, sizeof(MENUITEMINFO));
1363 miiSep.cbSize = sizeof(MENUITEMINFO);
1364 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1302 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1365 miiSep.fType = MFT_SEPARATOR; 1303 miiSep.fType = MFT_SEPARATOR;
1366 1304
1367 CPluginClient* client = CPluginClient::GetInstance(); 1305 CPluginClient* client = CPluginClient::GetInstance();
1368
1369 CPluginSettings* settings = CPluginSettings::GetInstance(); 1306 CPluginSettings* settings = CPluginSettings::GetInstance();
1370
1371 #ifdef SUPPORT_WHITELIST
1372 { 1307 {
1373 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1308 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1374 // Is domain in white list? 1309 // Is domain in white list?
1375 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); 1310 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url)));
1376 if (client->IsWhitelistedUrl(std::wstring(GetTab()->GetDocumentUrl()))) 1311 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl())))
1377 { 1312 {
1378 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1313 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1379 } 1314 }
1380 else 1315 else
1381 { 1316 {
1382 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1317 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1383 } 1318 }
1384 fmii.fMask = MIIM_STRING | MIIM_STATE; 1319 fmii.fMask = MIIM_STRING | MIIM_STATE;
1385 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1320 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1386 fmii.cch = static_cast<UINT>(ctext.size()); 1321 fmii.cch = static_cast<UINT>(ctext.size());
1387 1322
1388 ::SetMenuItemInfoW(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE, &fmii); 1323 ::SetMenuItemInfoW(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE, &fmii);
1389 } 1324 }
1390 #else
1391 {
1392 ::DeleteMenu(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE);
1393 }
1394 #endif // SUPPORT_WHITELIST
1395 1325
1396 // Plugin update 1326 // Plugin update
1397 ctext = dictionary->Lookup("menu", "menu-update"); 1327 ctext = dictionary->Lookup("menu", "menu-update");
1398 fmii.fMask = MIIM_STATE | MIIM_STRING; 1328 fmii.fMask = MIIM_STATE | MIIM_STRING;
1399 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED; 1329 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED;
1400 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1330 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1401 fmii.cch = static_cast<UINT>(ctext.size()); 1331 fmii.cch = static_cast<UINT>(ctext.size());
1402 ::SetMenuItemInfoW(hMenu, ID_MENU_UPDATE, FALSE, &fmii); 1332 ::SetMenuItemInfoW(hMenu, ID_MENU_UPDATE, FALSE, &fmii);
1403 1333
1404 1334
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 DWORD nProcessId; 1386 DWORD nProcessId;
1457 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); 1387 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId);
1458 1388
1459 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) 1389 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId)
1460 { 1390 {
1461 ::ScreenToClient(hWndToolBar, &pt); 1391 ::ScreenToClient(hWndToolBar, &pt);
1462 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); 1392 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt);
1463 1393
1464 if (nButton > 0) 1394 if (nButton > 0)
1465 { 1395 {
1466 TBBUTTON pTBBtn; 1396 TBBUTTON pTBBtn = {};
1467 memset(&pTBBtn, 0, sizeof(TBBUTTON));
1468 1397
1469 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) 1398 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn))
1470 { 1399 {
1471 RECT rcButton; 1400 RECT rcButton;
1472 nIDCommand = pTBBtn.idCommand; 1401 nIDCommand = pTBBtn.idCommand;
1473 1402
1474 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) 1403 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton))
1475 { 1404 {
1476 pt.x = rcButton.left; 1405 pt.x = rcButton.left;
1477 pt.y = rcButton.bottom; 1406 pt.y = rcButton.bottom;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); 1483 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1));
1555 LPINT lpParts = (LPINT)LocalLock(hLocal); 1484 LPINT lpParts = (LPINT)LocalLock(hLocal);
1556 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); 1485 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1557 1486
1558 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) 1487 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1559 { 1488 {
1560 lpParts[i] -= pClass->m_nPaneWidth; 1489 lpParts[i] -= pClass->m_nPaneWidth;
1561 } 1490 }
1562 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts); 1491 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts);
1563 1492
1564 CRect rcPane; 1493 AdblockPlus::Rectangle rcPane;
1565 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); 1494 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1566 1495
1567 CRect rcClient; 1496 AdblockPlus::Rectangle rcClient;
1568 ::GetClientRect(hWnd, &rcClient); 1497 ::GetClientRect(hWnd, &rcClient);
1569 1498
1570 ::MoveWindow( 1499 ::MoveWindow(
1571 pClass->m_hPaneWnd, 1500 pClass->m_hPaneWnd,
1572 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, 1501 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1573 0, 1502 0,
1574 pClass->m_nPaneWidth, 1503 pClass->m_nPaneWidth,
1575 rcClient.Height(), 1504 rcClient.Height(),
1576 TRUE); 1505 TRUE);
1577 1506
1578 ::LocalFree(hLocal); 1507 ::LocalFree(hLocal);
1579 1508
1580 1509
1581 return hRet; 1510 return hRet;
1582 } 1511 }
1583 1512
1584 default: 1513 default:
1585 break; 1514 break;
1586 } 1515 }
1587 1516
1588 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); 1517 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1589 1518
1590 1519
1591 return result; 1520 return result;
1592 1521
1593 } 1522 }
1594 1523
1595 1524
1596 HICON CPluginClass::GetStatusBarIcon(const std::wstring & url) 1525 HICON CPluginClass::GetStatusBarIcon(const CString& url)
1597 { 1526 {
1598 // use the disable icon as defualt, if the client doesn't exists 1527 // use the disable icon as defualt, if the client doesn't exists
1599 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1528 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1600 1529
1601 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1530 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1602 if (tab) 1531 if (tab)
1603 { 1532 {
1604 CPluginClient* client = CPluginClient::GetInstance(); 1533 CPluginClient* client = CPluginClient::GetInstance();
1605 1534 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1606 #ifdef PRODUCT_ADBLOCKPLUS 1535 {
1607 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) 1536 if (client->IsWhitelistedUrl(ToWstring(url)))
1608 { 1537 {
1609 } 1538 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1610 #ifdef SUPPORT_WHITELIST 1539 }
1611 else if (client->IsWhitelistedUrl( url )) 1540 else
1612 { 1541 {
1613 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1542 CPluginSettings* settings = CPluginSettings::GetInstance();
1614 } 1543 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1615 #endif // SUPPORT_WHITELIST 1544 }
1616 else 1545 }
1617 { 1546 }
1618 CPluginSettings* settings = CPluginSettings::GetInstance();
1619 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1620 }
1621
1622 #endif // PRODUCT_ADBLOCKPLUS
1623 }
1624
1625 return hIcon; 1547 return hIcon;
1626 } 1548 }
1627 1549
1628 1550
1629 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) 1551 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam)
1630 { 1552 {
1631 // Find tab 1553 // Find tab
1632 CPluginClass *pClass = FindInstance(GetParent(hWnd)); 1554 CPluginClass *pClass = FindInstance(GetParent(hWnd));
1633 if (!pClass) 1555 if (!pClass)
1634 { 1556 {
1635 return ::DefWindowProc(hWnd, message, wParam, lParam); 1557 return ::DefWindowProc(hWnd, message, wParam, lParam);
1636 } 1558 }
1637 1559
1638 CPluginSystem* system = CPluginSystem::GetInstance();
1639
1640 // Process message 1560 // Process message
1641 switch (message) 1561 switch (message)
1642 { 1562 {
1643 1563
1644 case WM_SETCURSOR: 1564 case WM_SETCURSOR:
1645 { 1565 {
1646 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); 1566 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
1647 return TRUE; 1567 return TRUE;
1648 } 1568 }
1649 case WM_PAINT: 1569 case WM_PAINT:
1650 { 1570 {
1651 PAINTSTRUCT ps; 1571 PAINTSTRUCT ps;
1652 HDC hDC = ::BeginPaint(hWnd, &ps); 1572 HDC hDC = ::BeginPaint(hWnd, &ps);
1653 1573
1654 CRect rcClient; 1574 AdblockPlus::Rectangle rcClient;
1655 ::GetClientRect(hWnd, &rcClient); 1575 ::GetClientRect(hWnd, &rcClient);
1656 1576
1657 int nDrawEdge = 0; 1577 int nDrawEdge = 0;
1658 1578
1659 // Old Windows background drawing 1579 // Old Windows background drawing
1660 if (pClass->m_hTheme == NULL) 1580 if (pClass->m_hTheme == NULL)
1661 { 1581 {
1662 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); 1582 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1));
1663 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); 1583 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT);
1664 1584
1665 nDrawEdge = 3; 1585 nDrawEdge = 3;
1666 rcClient.left += 3; 1586 rcClient.left += 3;
1667 1587
1668 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); 1588 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT);
1669 } 1589 }
1670 // Themed background drawing 1590 // Themed background drawing
1671 else 1591 else
1672 { 1592 {
1673 // Draw background 1593 // Draw background
1674 if (pfnDrawThemeBackground) 1594 if (pfnDrawThemeBackground)
1675 { 1595 {
1676 CRect rc = rcClient; 1596 AdblockPlus::Rectangle rc = rcClient;
1677 rc.right -= 2; 1597 rc.right -= 2;
1678 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); 1598 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1679 } 1599 }
1680 1600
1681 // Copy separator picture to left side 1601 // Copy separator picture to left side
1682 int nHeight = rcClient.Height(); 1602 int nHeight = rcClient.Height();
1683 int nWidth = rcClient.Width() - 2; 1603 int nWidth = rcClient.Width() - 2;
1684 1604
1685 for (int i = 0; i < 2; i++) 1605 for (int i = 0; i < 2; i++)
1686 { 1606 {
1687 for (int j = 0; j < nHeight; j++) 1607 for (int j = 0; j < nHeight; j++)
1688 { 1608 {
1689 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); 1609 COLORREF clr = ::GetPixel(hDC, i + nWidth, j);
1690 1610
1691 // Ignore black boxes (if source is obscured by other windows) 1611 // Ignore black boxes (if source is obscured by other windows)
1692 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) 1612 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8))
1693 { 1613 {
1694 ::SetPixel(hDC, i, j, clr); 1614 ::SetPixel(hDC, i, j, clr);
1695 } 1615 }
1696 } 1616 }
1697 } 1617 }
1698 } 1618 }
1699 1619
1700 // Draw icon 1620 // Draw icon
1701 if (CPluginClient::GetInstance()) 1621 if (CPluginClient::GetInstance())
1702 { 1622 {
1703 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl().c_str( )); 1623 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1704 1624
1705 int offx = (rcClient.Height() - 16)/2 + nDrawEdge; 1625 int offx = (rcClient.Height() - 16)/2 + nDrawEdge;
1706 if (hIcon) 1626 if (hIcon)
1707 { 1627 {
1708 ::DrawIconEx(hDC, offx, (rcClient.Height() - 16)/2 + 2, hIcon, 16, 16, NULL, NULL, DI_NORMAL); 1628 ::DrawIconEx(hDC, offx, (rcClient.Height() - 16)/2 + 2, hIcon, 16, 16, NULL, NULL, DI_NORMAL);
1709 offx += 22; 1629 offx += 22;
1710 } 1630 }
1711 #ifdef _DEBUG 1631 #ifdef _DEBUG
1712 // Display version 1632 // Display version
1713 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1633 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0);
1714 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); 1634 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont);
1715 1635
1716 CRect rcText = rcClient; 1636 AdblockPlus::Rectangle rcText = rcClient;
1717 rcText.left += offx; 1637 rcText.left += offx;
1718 ::SetBkMode(hDC, TRANSPARENT); 1638 ::SetBkMode(hDC, TRANSPARENT);
1719 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER); 1639 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER);
1720 1640
1721 ::SelectObject(hDC, hOldFont); 1641 ::SelectObject(hDC, hOldFont);
1722 #endif // _DEBUG 1642 #endif // _DEBUG
1723 } 1643 }
1724 1644
1725 // Done! 1645 // Done!
1726 EndPaint(hWnd, &ps); 1646 EndPaint(hWnd, &ps);
1727 1647
1728 return 0; 1648 return 0;
1729 } 1649 }
1730 1650
1731 case WM_LBUTTONUP: 1651 case WM_LBUTTONUP:
1732 case WM_RBUTTONUP: 1652 case WM_RBUTTONUP:
1733 { 1653 {
1734 std::wstring url = pClass->GetBrowserUrl(); 1654 CString strURL = pClass->GetBrowserUrl();
1735 if (url != pClass->GetTab()->GetDocumentUrl()) 1655 if (strURL != pClass->GetTab()->GetDocumentUrl())
1736 { 1656 {
1737 pClass->GetTab()->SetDocumentUrl( url ); 1657 pClass->GetTab()->SetDocumentUrl(strURL);
1738 } 1658 }
1739 1659
1740 // Create menu 1660 // Create menu
1741 HMENU hMenu = pClass->CreatePluginMenu( url ); 1661 HMENU hMenu = pClass->CreatePluginMenu(strURL);
1742 if (!hMenu) 1662 if (!hMenu)
1743 { 1663 {
1744 return 0; 1664 return 0;
1745 } 1665 }
1746 1666
1747 // Display menu 1667 // Display menu
1748 POINT pt; 1668 POINT pt;
1749 ::GetCursorPos(&pt); 1669 ::GetCursorPos(&pt);
1750 1670
1751 RECT rc; 1671 RECT rc;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 } 1745 }
1826 break; 1746 break;
1827 } 1747 }
1828 1748
1829 return DefWindowProc(hWnd, message, wParam, lParam); 1749 return DefWindowProc(hWnd, message, wParam, lParam);
1830 } 1750 }
1831 1751
1832 1752
1833 void CPluginClass::UpdateStatusBar() 1753 void CPluginClass::UpdateStatusBar()
1834 { 1754 {
1835 DEBUG_GENERAL(L"*** Updating statusbar") 1755 DEBUG_GENERAL("*** Updating statusbar")
1836 if (m_hPaneWnd == NULL) 1756 if (m_hPaneWnd == NULL)
1837 { 1757 {
1838 CreateStatusBarPane(); 1758 CreateStatusBarPane();
1839 } 1759 }
1840 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1760 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1841 { 1761 {
1842 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, L"Class::Invalidate statusbar"); 1762 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1843 } 1763 }
1844 } 1764 }
1845 1765
1846 1766
1847 void CPluginClass::Unadvice() 1767 void CPluginClass::Unadvice()
1848 { 1768 {
1849 s_criticalSectionLocal.Lock(); 1769 s_criticalSectionLocal.Lock();
1850 { 1770 {
1851 if (m_isAdviced) 1771 if (m_isAdviced)
1852 { 1772 {
1853 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 1773 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint();
1854 if (pPoint) 1774 if (pPoint)
1855 { 1775 {
1856 HRESULT hr = pPoint->Unadvise(m_nConnectionID); 1776 HRESULT hr = pPoint->Unadvise(m_nConnectionID);
1857 if (FAILED(hr)) 1777 if (FAILED(hr))
1858 { 1778 {
1859 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV ICE, L"Class::Unadvice - Unadvise"); 1779 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV ICE, "Class::Unadvice - Unadvise");
1860 } 1780 }
1861 } 1781 }
1862 1782
1863 m_isAdviced = false; 1783 m_isAdviced = false;
1864 } 1784 }
1865 } 1785 }
1866 s_criticalSectionLocal.Unlock(); 1786 s_criticalSectionLocal.Unlock();
1867 } 1787 }
1868 1788
1869 HICON CPluginClass::GetIcon(int type) 1789 HICON CPluginClass::GetIcon(int type)
1870 { 1790 {
1871 HICON icon = NULL; 1791 HICON icon = NULL;
1872 1792
1873 s_criticalSectionLocal.Lock(); 1793 s_criticalSectionLocal.Lock();
1874 { 1794 {
1875 if (!s_hIcons[type]) 1795 if (!s_hIcons[type])
1876 { 1796 {
1877 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[ type])); 1797 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[ type]));
1878 if (!s_hIcons[type]) 1798 if (!s_hIcons[type])
1879 { 1799 {
1880 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, L"Class::GetIcon - LoadIcon") 1800 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_LOAD_ ICON, "Class::GetIcon - LoadIcon")
1881 } 1801 }
1882 } 1802 }
1883 1803
1884 icon = s_hIcons[type]; 1804 icon = s_hIcons[type];
1885 } 1805 }
1886 s_criticalSectionLocal.Unlock(); 1806 s_criticalSectionLocal.Unlock();
1887 1807
1888 return icon; 1808 return icon;
1889 } 1809 }
1890 1810
1891 ATOM CPluginClass::GetAtomPaneClass() 1811 ATOM CPluginClass::GetAtomPaneClass()
1892 { 1812 {
1893 return s_atomPaneClass; 1813 return s_atomPaneClass;
1894 } 1814 }
1895 1815
1896 HWND CPluginClass::GetTabHWND() const 1816 HWND CPluginClass::GetTabHWND() const
1897 { 1817 {
1898 1818 std::array<wchar_t, MAX_PATH> className;
1899 TCHAR szClassName[MAX_PATH];
1900 // Get browser window and url 1819 // Get browser window and url
1901 HWND hBrowserWnd = GetBrowserHWND(); 1820 HWND hBrowserWnd = GetBrowserHWND();
1902 if (!hBrowserWnd) 1821 if (!hBrowserWnd)
1903 { 1822 {
1904 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, L" Class::GetTabWindow - No tab window") 1823 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::GetTabWindow - No tab window")
1905 s_criticalSectionWindow.Unlock(); 1824 s_criticalSectionWindow.Unlock();
1906 1825
1907 return false; 1826 return false;
1908 } 1827 }
1909 1828
1910 // Looking for a TabWindowClass window in IE7 1829 // Looking for a TabWindowClass window in IE7
1911 1830
1912 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); 1831 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
1913 while (hTabWnd) 1832 while (hTabWnd)
1914 { 1833 {
1915 memset(szClassName, 0, MAX_PATH); 1834 className[0] = L'\0';
1916 GetClassName(hTabWnd, szClassName, MAX_PATH); 1835 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz e());
1917 1836
1918 if (_tcscmp(szClassName, _T("TabWindowClass")) == 0 || _tcscmp(szClassName,_ T("Frame Tab")) == 0) 1837 if (classNameLength && (wcscmp(className.data(), L"TabWindowClass") == 0 || wcscmp(className.data(), L"Frame Tab") == 0))
1919 { 1838 {
1920 // IE8 support 1839 // IE8 support
1921 HWND hTabWnd2 = hTabWnd; 1840 HWND hTabWnd2 = hTabWnd;
1922 if (_tcscmp(szClassName,_T("Frame Tab")) == 0) 1841 if (wcscmp(className.data(), L"Frame Tab") == 0)
1923 { 1842 {
1924 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, _T("TabWindowClass"), NULL); 1843 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL);
1925 } 1844 }
1926 1845
1927 if (hTabWnd2) 1846 if (hTabWnd2)
1928 { 1847 {
1929 DWORD nProcessId; 1848 DWORD nProcessId;
1930 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); 1849 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
1931 if (::GetCurrentProcessId() == nProcessId) 1850 if (::GetCurrentProcessId() == nProcessId)
1932 { 1851 {
1933 bool bExistingTab = false; 1852 bool bExistingTab = false;
1934 s_criticalSectionLocal.Lock(); 1853 s_criticalSectionLocal.Lock();
1935 1854
1936 { 1855 {
1937 for (int i = 0; i < s_instances.GetSize(); i++) 1856 for (auto instance : s_instances)
1938 { 1857 {
1939 if (s_instances[i]->m_hTabWnd == hTabWnd2) 1858 if (instance->m_hTabWnd == hTabWnd2)
1940 { 1859 {
1941 bExistingTab = true; 1860 bExistingTab = true;
1942 break; 1861 break;
1943 } 1862 }
1944 } 1863 }
1945 } 1864 }
1946 1865
1947 if (!bExistingTab) 1866 if (!bExistingTab)
1948 { 1867 {
1949 hBrowserWnd = hTabWnd2; 1868 hBrowserWnd = hTabWnd2;
1950 hTabWnd = hTabWnd2; 1869 hTabWnd = hTabWnd2;
1951 s_criticalSectionLocal.Unlock(); 1870 s_criticalSectionLocal.Unlock();
1952 break; 1871 break;
1953 } 1872 }
1954 s_criticalSectionLocal.Unlock(); 1873 s_criticalSectionLocal.Unlock();
1955 1874
1956 } 1875 }
1957 } 1876 }
1958 } 1877 }
1959 1878
1960 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1879 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1961 } 1880 }
1962 1881
1963 return hTabWnd; 1882 return hTabWnd;
1964 1883
1965 } 1884 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld