LEFT | RIGHT |
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 Loading... |
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 Loading... |
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 Loading... |
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 RECT rect; | 685 else |
671 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); | 686 { |
672 if (rectRes == TRUE) | 687 if (AdblockPlus::IE::InstalledMajorVersion() > 6) |
673 { | 688 { |
674 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom -
rect.top, TRUE); | 689 RECT rect; |
675 } | 690 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); |
676 } | 691 if (rectRes == TRUE) |
677 break; | 692 { |
678 case DISPID_STATUSTEXTCHANGE: | 693 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.botto
m - rect.top, TRUE); |
679 break; | 694 } |
680 | 695 } |
681 case DISPID_BEFORENAVIGATE2: | 696 } |
682 BeforeNavigate2(pDispParams); | 697 break; |
683 break; | 698 |
684 | 699 case DISPID_STATUSTEXTCHANGE: |
685 case DISPID_DOWNLOADBEGIN: | 700 break; |
686 { | 701 |
687 DEBUG_NAVI("Navi::Download Begin") | 702 case DISPID_BEFORENAVIGATE2: |
688 } | 703 { |
689 break; | 704 // #1163 should validate and convert parameters here |
690 | 705 BeforeNavigate2(pDispParams); |
691 case DISPID_DOWNLOADCOMPLETE: | 706 } |
692 { | 707 break; |
693 DEBUG_NAVI("Navi::Download Complete") | 708 |
694 | 709 case DISPID_DOWNLOADBEGIN: |
| 710 { |
| 711 DEBUG_NAVI("Navi::Download Begin") |
| 712 } |
| 713 break; |
| 714 |
| 715 case DISPID_DOWNLOADCOMPLETE: |
| 716 { |
| 717 DEBUG_NAVI("Navi::Download Complete"); |
695 CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 718 CComQIPtr<IWebBrowser2> browser = GetBrowser(); |
696 if (browser) | 719 if (browser) |
697 { | 720 { |
698 m_tab->OnDownloadComplete(browser); | 721 m_tab->OnDownloadComplete(browser); |
699 } | 722 } |
700 } | 723 } |
701 break; | 724 break; |
702 | 725 |
703 case DISPID_DOCUMENTCOMPLETE: | 726 case DISPID_DOCUMENTCOMPLETE: |
704 { | 727 { |
705 DEBUG_NAVI("Navi::Document Complete") | 728 DEBUG_NAVI("Navi::Document Complete"); |
706 | 729 CComQIPtr<IWebBrowser2> browser = GetBrowser(); |
707 CComQIPtr<IWebBrowser2> ccom_browser = GetBrowser(); | 730 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V
T_DISPATCH) |
708 | 731 { |
709 if (ccom_browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt =
= VT_DISPATCH) | 732 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; |
710 { | 733 if (pBrowser) |
711 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; | |
712 if (pBrowser) | |
713 { | |
714 Wrapper::Browser browser( pBrowser ); | |
715 std::wstring url; | |
716 if ( browser.Location_URL( url ) && !url.empty() ) | |
717 { | 734 { |
718 Wrapper::Unescape_URL(url); | 735 CString url; |
719 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 } |
720 } | 743 } |
721 } | 744 } |
722 } | 745 } |
723 } | 746 break; |
724 break; | 747 |
725 | 748 case DISPID_ONQUIT: |
726 case DISPID_ONQUIT: | 749 case DISPID_QUIT: |
727 case DISPID_QUIT: | 750 { |
728 { | 751 Unadvice(); |
729 Unadvice(); | 752 } |
730 } | 753 break; |
731 break; | 754 |
732 | 755 default: |
733 default: | 756 { |
734 { | 757 CString did; |
735 std::wostringstream msg; | 758 did.Format(L"DispId:%u", dispidMember); |
736 msg << L"Navi::Default DispId:"; | 759 |
737 msg << static_cast< unsigned long >( dispidMember ); | 760 DEBUG_NAVI(L"Navi::Default " + did) |
738 DEBUG_NAVI( msg.str() ) | 761 } |
739 } | 762 /* |
740 | 763 * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND. |
741 // do nothing | 764 * As a conservative initial change, we leave it behaving as before, |
742 break; | 765 * which is to do nothing and return S_OK. |
743 } | 766 */ |
744 | 767 // do nothing |
745 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; |
746 } | 777 } |
747 | 778 |
748 bool CPluginClass::InitObject(bool bBHO) | 779 bool CPluginClass::InitObject(bool bBHO) |
749 { | 780 { |
750 DEBUG_GENERAL(L"InitObject"); | 781 DEBUG_GENERAL("InitObject"); |
751 CPluginSettings* settings = CPluginSettings::GetInstance(); | 782 CPluginSettings* settings = CPluginSettings::GetInstance(); |
752 | 783 |
753 if (!settings->GetPluginEnabled()) | 784 if (!settings->GetPluginEnabled()) |
754 { | 785 { |
755 s_mimeFilter->Unregister(); | 786 s_mimeFilter->Unregister(); |
756 } | 787 } |
757 | 788 |
758 // Load theme module | 789 // Load theme module |
759 s_criticalSectionLocal.Lock(); | 790 s_criticalSectionLocal.Lock(); |
760 { | 791 { |
761 if (!s_hUxtheme) | 792 if (!s_hUxtheme) |
762 { | 793 { |
763 s_hUxtheme = ::GetModuleHandleW(L"uxtheme.dll"); | 794 s_hUxtheme = ::GetModuleHandle(L"uxtheme.dll"); |
764 if (s_hUxtheme) | 795 if (s_hUxtheme) |
765 { | 796 { |
766 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData"
); | 797 pfnClose = (CLOSETHEMEDATA)::GetProcAddress(s_hUxtheme, "CloseThemeData"
); |
767 if (!pfnClose) | 798 if (!pfnClose) |
768 { | 799 { |
769 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)"); |
770 } | 801 } |
771 | 802 |
772 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem
e, "DrawThemeBackground"); | 803 pfnDrawThemeBackground = (DRAWTHEMEBACKGROUND)::GetProcAddress(s_hUxthem
e, "DrawThemeBackground"); |
773 if (!pfnDrawThemeBackground) | 804 if (!pfnDrawThemeBackground) |
774 { | 805 { |
775 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)"); |
776 } | 807 } |
777 | 808 |
778 pfnOpenThemeData = (OPENTHEMEDATA)::GetProcAddress(s_hUxtheme, "OpenThem
eData"); | 809 pfnOpenThemeData = (OPENTHEMEDATA)::GetProcAddress(s_hUxtheme, "OpenThem
eData"); |
779 if (!pfnOpenThemeData) | 810 if (!pfnOpenThemeData) |
780 { | 811 { |
781 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)"); |
782 } | 813 } |
783 } | 814 } |
784 else | 815 else |
785 { | 816 { |
786 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)"); |
787 } | 818 } |
788 } | 819 } |
789 } | 820 } |
790 s_criticalSectionLocal.Unlock(); | 821 s_criticalSectionLocal.Unlock(); |
791 | 822 |
792 // Register pane class | 823 // Register pane class |
793 if (!GetAtomPaneClass()) | 824 if (!GetAtomPaneClass()) |
794 { | 825 { |
795 WNDCLASSEX wcex; | 826 WNDCLASSEX wcex; |
796 | 827 |
797 wcex.cbSize = sizeof(WNDCLASSEX); | 828 wcex.cbSize = sizeof(wcex); |
798 wcex.style = 0; | 829 wcex.style = 0; |
799 wcex.lpfnWndProc = (WNDPROC)PaneWindowProc; | 830 wcex.lpfnWndProc = (WNDPROC)PaneWindowProc; |
800 wcex.cbClsExtra = 0; | 831 wcex.cbClsExtra = 0; |
801 wcex.cbWndExtra = 0; | 832 wcex.cbWndExtra = 0; |
802 wcex.hInstance = _Module.m_hInst; | 833 wcex.hInstance = _Module.m_hInst; |
803 wcex.hIcon = NULL; | 834 wcex.hIcon = NULL; |
804 wcex.hCursor = NULL; | 835 wcex.hCursor = NULL; |
805 wcex.hbrBackground = NULL; | 836 wcex.hbrBackground = NULL; |
806 wcex.lpszMenuName = NULL; | 837 wcex.lpszMenuName = NULL; |
807 wcex.lpszClassName = _T(STATUSBAR_PANE_NAME); | 838 wcex.lpszClassName = STATUSBAR_PANE_NAME; |
808 wcex.hIconSm = NULL; | 839 wcex.hIconSm = NULL; |
809 | 840 |
810 s_criticalSectionLocal.Lock(); | 841 s_criticalSectionLocal.Lock(); |
811 { | 842 { |
812 s_atomPaneClass = ::RegisterClassEx(&wcex); | 843 s_atomPaneClass = ::RegisterClassEx(&wcex); |
813 } | 844 } |
814 s_criticalSectionLocal.Unlock(); | 845 s_criticalSectionLocal.Unlock(); |
815 | 846 |
816 if (!GetAtomPaneClass()) | 847 if (!GetAtomPaneClass()) |
817 { | 848 { |
818 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"); |
819 return false; | 850 return false; |
820 } | 851 } |
821 } | 852 } |
822 | 853 |
| 854 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); |
823 // Create status pane | 855 // Create status pane |
824 if (bBHO && !CreateStatusBarPane()) | 856 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) |
825 { | 857 { |
826 return false; | 858 return false; |
827 } | 859 } |
828 | 860 |
829 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) |
830 { | 869 { |
831 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CPluginClass::FirstRunThrea
d, NULL, NULL, NULL); | 870 if (!isFirstRun) |
832 if ((m_hPaneWnd == NULL) || (!IsStatusBarEnabled())) | 871 { |
| 872 CPluginClient::GetInstance()->SetPref(L"displayUpdatePage", true); |
| 873 } |
| 874 |
| 875 // IE6 can't be accessed from another thread, execute in current thread |
| 876 if (ieVersion < 7) |
| 877 { |
| 878 FirstRunThread(); |
| 879 } |
| 880 else |
| 881 { |
| 882 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CPluginClass::FirstRunThr
ead, NULL, NULL, NULL); |
| 883 } |
| 884 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun) |
833 { | 885 { |
834 ShowStatusBar(); | 886 ShowStatusBar(); |
835 } | 887 } |
836 | 888 |
837 } | 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(); |
838 return true; | 894 return true; |
839 } | 895 } |
840 | 896 |
841 bool CPluginClass::CreateStatusBarPane() | 897 bool CPluginClass::CreateStatusBarPane() |
842 { | 898 { |
843 CriticalSection::Lock lock(m_csStatusBar); | 899 CriticalSection::Lock lock(m_csStatusBar); |
844 | 900 |
845 CPluginClient* client = CPluginClient::GetInstance(); | 901 CPluginClient* client = CPluginClient::GetInstance(); |
846 | 902 |
847 TCHAR szClassName[MAX_PATH]; | 903 std::array<wchar_t, MAX_PATH> className; |
848 // Get browser window and url | 904 // Get browser window and url |
849 HWND hBrowserWnd = GetBrowserHWND(); | 905 HWND hBrowserWnd = GetBrowserHWND(); |
850 if (!hBrowserWnd) | 906 if (!hBrowserWnd) |
851 { | 907 { |
852 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") |
853 return false; | 909 return false; |
854 } | 910 } |
855 | 911 |
856 // Looking for a TabWindowClass window in IE7 | 912 // Looking for a TabWindowClass window in IE7 |
857 // the last one should be parent for statusbar | 913 // the last one should be parent for statusbar |
858 HWND hWndStatusBar = NULL; | 914 HWND hWndStatusBar = NULL; |
859 | 915 |
860 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); | 916 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); |
861 UINT amoundOfNewTabs = 0; | 917 UINT amoundOfNewTabs = 0; |
862 HWND uniqueNewTab = NULL; | 918 HWND uniqueNewTab = NULL; |
863 while (hTabWnd) | 919 while (hTabWnd) |
864 { | 920 { |
865 memset(szClassName, 0, MAX_PATH); | 921 className[0] = L'\0'; |
866 GetClassName(hTabWnd, szClassName, MAX_PATH); | 922 // GetClassNameW returns the number of characters without '\0' |
867 | 923 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz
e()); |
868 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)) |
869 { | 926 { |
870 // IE8 support | 927 // IE8 support |
871 HWND hTabWnd2 = hTabWnd; | 928 HWND hTabWnd2 = hTabWnd; |
872 if (_tcscmp(szClassName,_T("Frame Tab")) == 0) | 929 if (wcscmp(className.data(), L"Frame Tab") == 0) |
873 { | 930 { |
874 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, _T("TabWindowClass"), NULL); | 931 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL); |
875 } | 932 } |
876 | 933 |
877 if (hTabWnd2) | 934 if (hTabWnd2) |
878 { | 935 { |
879 DWORD nProcessId; | 936 DWORD nProcessId; |
880 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); | 937 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); |
881 if (::GetCurrentProcessId() == nProcessId) | 938 if (::GetCurrentProcessId() == nProcessId) |
882 { | 939 { |
883 bool bExistingTab = false; | 940 bool bExistingTab = false; |
884 | 941 |
885 s_criticalSectionLocal.Lock(); | 942 s_criticalSectionLocal.Lock(); |
886 { | 943 { |
887 for (int i = 0; i < s_instances.GetSize(); i++) | 944 for (auto instance : s_instances) |
888 { | 945 { |
889 if (s_instances[i]->m_hTabWnd == hTabWnd2) | 946 if (instance->m_hTabWnd == hTabWnd2) |
890 { | 947 { |
891 | |
892 bExistingTab = true; | 948 bExistingTab = true; |
893 break; | 949 break; |
894 } | 950 } |
895 } | 951 } |
896 } | 952 } |
897 s_criticalSectionLocal.Unlock(); | 953 s_criticalSectionLocal.Unlock(); |
898 | 954 |
899 if (!bExistingTab) | 955 if (!bExistingTab) |
900 { | 956 { |
901 amoundOfNewTabs ++; | 957 amoundOfNewTabs ++; |
902 uniqueNewTab = hTabWnd2; | 958 uniqueNewTab = hTabWnd2; |
903 if (GetCurrentThreadId() == GetWindowThreadProcessId(hTabWnd2, NULL)
) | 959 if (GetCurrentThreadId() == GetWindowThreadProcessId(hTabWnd2, NULL)
) |
904 { | 960 { |
905 hBrowserWnd = hTabWnd = hTabWnd2; | 961 hBrowserWnd = hTabWnd = hTabWnd2; |
906 break; | 962 break; |
907 } | 963 } |
908 | 964 |
909 } | 965 } |
910 } | 966 } |
911 } | 967 } |
912 } | 968 } |
913 | 969 |
914 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 970 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |
915 } | 971 } |
916 | 972 |
917 HWND hWnd = ::GetWindow(hBrowserWnd, GW_CHILD); | 973 HWND hWnd = ::GetWindow(hBrowserWnd, GW_CHILD); |
918 while (hWnd) | 974 while (hWnd) |
919 { | 975 { |
920 memset(szClassName, 0, MAX_PATH); | 976 className[0] = L'\0'; |
921 ::GetClassName(hWnd, szClassName, MAX_PATH); | 977 int classNameLength = GetClassNameW(hWnd, className.data(), className.size()
); |
922 | 978 |
923 if (_tcscmp(szClassName,_T("msctls_statusbar32")) == 0) | 979 if (classNameLength && wcscmp(className.data(), L"msctls_statusbar32") == 0) |
924 { | 980 { |
925 hWndStatusBar = hWnd; | 981 hWndStatusBar = hWnd; |
926 break; | 982 break; |
927 } | 983 } |
928 | 984 |
929 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); | 985 hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); |
930 } | 986 } |
931 | 987 |
932 if (!hWndStatusBar) | 988 if (!hWndStatusBar) |
933 { | 989 { |
934 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") |
935 return true; | 991 return true; |
936 } | 992 } |
937 | 993 |
938 // Calculate pane height | 994 // Calculate pane height |
939 CRect rcStatusBar; | 995 AdblockPlus::Rectangle rcStatusBar; |
940 ::GetClientRect(hWndStatusBar, &rcStatusBar); | 996 ::GetClientRect(hWndStatusBar, &rcStatusBar); |
941 | 997 |
942 if (rcStatusBar.Height() > 0) | 998 if (rcStatusBar.Height() > 0) |
943 { | 999 { |
944 #ifdef _DEBUG | 1000 #ifdef _DEBUG |
945 m_nPaneWidth = 70; | 1001 m_nPaneWidth = 70; |
946 #else | 1002 #else |
947 m_nPaneWidth = min(rcStatusBar.Height(), 22); | 1003 m_nPaneWidth = min(rcStatusBar.Height(), 22); |
948 #endif | 1004 #endif |
949 } | 1005 } |
950 else | 1006 else |
951 { | 1007 { |
952 #ifdef _DEBUG | 1008 #ifdef _DEBUG |
953 m_nPaneWidth = 70; | 1009 m_nPaneWidth = 70; |
954 #else | 1010 #else |
955 m_nPaneWidth = 22; | 1011 m_nPaneWidth = 22; |
956 #endif | 1012 #endif |
957 } | 1013 } |
958 // Create pane window | 1014 // Create pane window |
959 HWND hWndNewPane = ::CreateWindowEx( | 1015 HWND hWndNewPane = ::CreateWindowEx( |
960 NULL, | 1016 NULL, |
961 MAKEINTATOM(GetAtomPaneClass()), | 1017 MAKEINTATOM(GetAtomPaneClass()), |
962 _T(""), | 1018 L"", |
963 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, | 1019 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, |
964 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), | 1020 rcStatusBar.Width() - 500,0,m_nPaneWidth,rcStatusBar.Height(), |
965 hWndStatusBar, | 1021 hWndStatusBar, |
966 (HMENU)3671, | 1022 (HMENU)3671, |
967 _Module.m_hInst, | 1023 _Module.m_hInst, |
968 NULL); | 1024 NULL); |
969 | 1025 |
970 if (!hWndNewPane) | 1026 if (!hWndNewPane) |
971 { | 1027 { |
972 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") |
973 return false; | 1029 return false; |
974 } | 1030 } |
975 | 1031 |
976 DEBUG_GENERAL(L"ABP window created"); | 1032 DEBUG_GENERAL("ABP window created"); |
977 m_hTabWnd = hTabWnd; | 1033 m_hTabWnd = hTabWnd; |
978 m_hStatusBarWnd = hWndStatusBar; | 1034 m_hStatusBarWnd = hWndStatusBar; |
979 m_hPaneWnd = hWndNewPane; | 1035 m_hPaneWnd = hWndNewPane; |
980 | 1036 |
981 UpdateTheme(); | 1037 UpdateTheme(); |
982 | 1038 |
983 // Subclass status bar | 1039 // Subclass status bar |
984 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA
RAM)(WNDPROC)NewStatusProc); | 1040 m_pWndProcStatus = (WNDPROC)SetWindowLongPtr(hWndStatusBar, GWLP_WNDPROC, (LPA
RAM)(WNDPROC)NewStatusProc); |
985 | 1041 |
986 // Adjust pane | 1042 // Adjust pane |
(...skipping 12 matching lines...) Expand all Loading... |
999 HDC hdc = GetWindowDC(m_hStatusBarWnd); | 1055 HDC hdc = GetWindowDC(m_hStatusBarWnd); |
1000 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); | 1056 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); |
1001 ReleaseDC(m_hStatusBarWnd, hdc); | 1057 ReleaseDC(m_hStatusBarWnd, hdc); |
1002 | 1058 |
1003 return true; | 1059 return true; |
1004 } | 1060 } |
1005 | 1061 |
1006 void CPluginClass::FirstRunThread() | 1062 void CPluginClass::FirstRunThread() |
1007 { | 1063 { |
1008 CoInitialize(NULL); | 1064 CoInitialize(NULL); |
1009 | 1065 VARIANT vFlags; |
1010 Wrapper::Browser browser( GetAsyncBrowser() ); | 1066 vFlags.vt = VT_I4; |
1011 HRESULT hr = browser.navigate( FirstRunPageFileUrl() ); | 1067 vFlags.intVal = navOpenInNewTab; |
1012 if ( FAILED( hr ) ) | 1068 |
1013 { | 1069 CComBSTR navigatePath = CComBSTR(FirstRunPageFileUrl().c_str()); |
1014 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_WELCOME
, L"Navigation::Welcome page failed") | 1070 |
1015 } | 1071 HRESULT hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NU
LL); |
1016 } | 1072 if (FAILED(hr)) |
1017 | 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 } |
1018 void CPluginClass::CloseTheme() | 1083 void CPluginClass::CloseTheme() |
1019 { | 1084 { |
1020 if (m_hTheme) | 1085 if (m_hTheme) |
1021 { | 1086 { |
1022 if (pfnClose) | 1087 if (pfnClose) |
1023 { | 1088 { |
1024 pfnClose(m_hTheme); | 1089 pfnClose(m_hTheme); |
1025 } | 1090 } |
1026 | 1091 |
1027 m_hTheme = NULL; | 1092 m_hTheme = NULL; |
1028 } | 1093 } |
1029 } | 1094 } |
1030 | 1095 |
1031 void CPluginClass::UpdateTheme() | 1096 void CPluginClass::UpdateTheme() |
1032 { | 1097 { |
1033 CloseTheme(); | 1098 CloseTheme(); |
1034 | 1099 |
1035 if (pfnOpenThemeData) | 1100 if (pfnOpenThemeData) |
1036 { | 1101 { |
1037 m_hTheme = pfnOpenThemeData(m_hPaneWnd, L"STATUS"); | 1102 m_hTheme = pfnOpenThemeData(m_hPaneWnd, L"STATUS"); |
1038 if (!m_hTheme) | 1103 if (!m_hTheme) |
1039 { | 1104 { |
1040 } | 1105 } |
1041 } | 1106 } |
1042 } | 1107 } |
1043 | 1108 |
1044 | 1109 |
1045 CPluginClass* CPluginClass::FindInstance(HWND hStatusBarWnd) | 1110 CPluginClass* CPluginClass::FindInstance(HWND hStatusBarWnd) |
1046 { | 1111 { |
1047 CPluginClass* instance = NULL; | 1112 CPluginClass* result = nullptr; |
1048 | 1113 |
1049 s_criticalSectionLocal.Lock(); | 1114 s_criticalSectionLocal.Lock(); |
1050 { | 1115 { |
1051 for (int i = 0; i < s_instances.GetSize(); i++) | 1116 for (auto instance : s_instances) |
1052 { | 1117 { |
1053 if (s_instances[i]->m_hStatusBarWnd == hStatusBarWnd) | 1118 if (instance->m_hStatusBarWnd == hStatusBarWnd) |
1054 { | 1119 { |
1055 instance = s_instances[i]; | 1120 result = instance; |
1056 break; | 1121 break; |
1057 } | 1122 } |
1058 } | 1123 } |
1059 } | 1124 } |
1060 s_criticalSectionLocal.Unlock(); | 1125 s_criticalSectionLocal.Unlock(); |
1061 | 1126 |
1062 return instance; | 1127 return result; |
1063 } | 1128 } |
1064 | 1129 |
1065 CPluginTab* CPluginClass::GetTab() | 1130 CPluginTab* CPluginClass::GetTab() |
1066 { | 1131 { |
1067 return m_tab; | 1132 return m_tab; |
1068 } | 1133 } |
1069 | 1134 |
1070 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) | 1135 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) |
1071 { | 1136 { |
1072 CPluginTab* tab = NULL; | 1137 CPluginTab* tab = NULL; |
(...skipping 15 matching lines...) Expand all Loading... |
1088 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) |
1089 { | 1154 { |
1090 if (cCmds == 0) return E_INVALIDARG; | 1155 if (cCmds == 0) return E_INVALIDARG; |
1091 if (prgCmds == 0) return E_POINTER; | 1156 if (prgCmds == 0) return E_POINTER; |
1092 | 1157 |
1093 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1158 prgCmds[0].cmdf = OLECMDF_ENABLED; |
1094 | 1159 |
1095 return S_OK; | 1160 return S_OK; |
1096 } | 1161 } |
1097 | 1162 |
1098 HMENU CPluginClass::CreatePluginMenu(const std::wstring & url) | 1163 HMENU CPluginClass::CreatePluginMenu(const CString& url) |
1099 { | 1164 { |
1100 DEBUG_GENERAL(L"CreatePluginMenu"); | 1165 DEBUG_GENERAL("CreatePluginMenu"); |
1101 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1166 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
1102 | 1167 |
1103 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1168 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
1104 | 1169 |
1105 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); | 1170 HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); |
1106 | 1171 |
1107 SetMenuBar(hMenuTrackPopup, url); | 1172 SetMenuBar(hMenuTrackPopup, url); |
1108 | 1173 |
1109 return hMenuTrackPopup; | 1174 return hMenuTrackPopup; |
1110 } | 1175 } |
1111 BOOL CreateLowProcess(WCHAR* wszProcessName, WCHAR* cmdLine) | |
1112 { | |
1113 | |
1114 BOOL fRet; | |
1115 HANDLE hToken = NULL; | |
1116 HANDLE hNewToken = NULL; | |
1117 PSID pIntegritySid = NULL; | |
1118 TOKEN_MANDATORY_LABEL TIL = {0}; | |
1119 PROCESS_INFORMATION ProcInfo = {0}; | |
1120 STARTUPINFO StartupInfo = {0}; | |
1121 | |
1122 | |
1123 | |
1124 // Low integrity SID | |
1125 WCHAR wszIntegritySid[20] = L"S-1-16-4096"; | |
1126 | |
1127 | |
1128 fRet = OpenProcessToken(GetCurrentProcess(), | |
1129 TOKEN_DUPLICATE | | |
1130 TOKEN_ADJUST_DEFAULT | | |
1131 TOKEN_QUERY | | |
1132 TOKEN_ASSIGN_PRIMARY, | |
1133 &hToken); | |
1134 | |
1135 if (!fRet) | |
1136 { | |
1137 goto CleanExit; | |
1138 } | |
1139 | |
1140 fRet = DuplicateTokenEx(hToken, | |
1141 0, | |
1142 NULL, | |
1143 SecurityImpersonation, | |
1144 TokenPrimary, | |
1145 &hNewToken); | |
1146 | |
1147 if (!fRet) | |
1148 { | |
1149 goto CleanExit; | |
1150 } | |
1151 | |
1152 fRet = ConvertStringSidToSid(wszIntegritySid, &pIntegritySid); | |
1153 | |
1154 if (!fRet) | |
1155 { | |
1156 goto CleanExit; | |
1157 } | |
1158 | |
1159 | |
1160 TIL.Label.Attributes = SE_GROUP_INTEGRITY; | |
1161 TIL.Label.Sid = pIntegritySid; | |
1162 | |
1163 | |
1164 // | |
1165 // Set the process integrity level | |
1166 // | |
1167 | |
1168 fRet = SetTokenInformation(hNewToken, | |
1169 TokenIntegrityLevel, | |
1170 &TIL, | |
1171 sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(pIntegritySid)); | |
1172 | |
1173 if (!fRet) | |
1174 { | |
1175 goto CleanExit; | |
1176 } | |
1177 | |
1178 // | |
1179 // Create the new process at Low integrity | |
1180 // | |
1181 | |
1182 fRet = CreateProcessAsUser(hNewToken, | |
1183 wszProcessName, | |
1184 cmdLine, | |
1185 NULL, | |
1186 NULL, | |
1187 FALSE, | |
1188 0, | |
1189 NULL, | |
1190 NULL, | |
1191 &StartupInfo, | |
1192 &ProcInfo); | |
1193 | |
1194 | |
1195 CleanExit: | |
1196 | |
1197 if (ProcInfo.hProcess != NULL) | |
1198 { | |
1199 CloseHandle(ProcInfo.hProcess); | |
1200 } | |
1201 | |
1202 if (ProcInfo.hThread != NULL) | |
1203 { | |
1204 CloseHandle(ProcInfo.hThread); | |
1205 } | |
1206 | |
1207 LocalFree(pIntegritySid); | |
1208 | |
1209 if (hNewToken != NULL) | |
1210 { | |
1211 CloseHandle(hNewToken); | |
1212 } | |
1213 | |
1214 if (hToken != NULL) | |
1215 { | |
1216 CloseHandle(hToken); | |
1217 } | |
1218 | |
1219 return fRet; | |
1220 } | |
1221 | 1176 |
1222 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) |
1223 { | 1178 { |
1224 CPluginClient* client = CPluginClient::GetInstance(); | 1179 CPluginClient* client = CPluginClient::GetInstance(); |
1225 | |
1226 CPluginSystem* system = CPluginSystem::GetInstance(); | |
1227 | 1180 |
1228 // Create menu parent window | 1181 // Create menu parent window |
1229 HWND hMenuWnd = ::CreateWindowEx( | 1182 HWND hMenuWnd = ::CreateWindowEx( |
1230 NULL, | 1183 NULL, |
1231 MAKEINTATOM(GetAtomPaneClass()), | 1184 MAKEINTATOM(GetAtomPaneClass()), |
1232 _T(""), | 1185 L"", |
1233 0, | 1186 0, |
1234 0,0,0,0, | 1187 0,0,0,0, |
1235 NULL, | 1188 NULL, |
1236 NULL, | 1189 NULL, |
1237 _Module.m_hInst, | 1190 _Module.m_hInst, |
1238 NULL); | 1191 NULL); |
1239 | 1192 |
1240 if (!hMenuWnd) | 1193 if (!hMenuWnd) |
1241 { | 1194 { |
1242 DestroyMenu(hMenu); | 1195 DestroyMenu(hMenu); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 } | 1238 } |
1286 } | 1239 } |
1287 s_criticalSectionLocal.Unlock(); | 1240 s_criticalSectionLocal.Unlock(); |
1288 } | 1241 } |
1289 break; | 1242 break; |
1290 case ID_MENU_SETTINGS: | 1243 case ID_MENU_SETTINGS: |
1291 { | 1244 { |
1292 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); | 1245 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); |
1293 if (browser) | 1246 if (browser) |
1294 { | 1247 { |
1295 Wrapper::Browser b( browser ); | 1248 VARIANT vFlags; |
1296 HRESULT hr = b.navigate( UserSettingsFileUrl() ); | 1249 vFlags.vt = VT_I4; |
1297 if ( FAILED(hr) ) | 1250 vFlags.intVal = navOpenInNewTab; |
1298 { | 1251 |
1299 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 } |
1300 } | 1263 } |
1301 } | 1264 } |
1302 break; | 1265 break; |
1303 } | 1266 } |
1304 case ID_MENU_DISABLE_ON_SITE: | 1267 case ID_MENU_DISABLE_ON_SITE: |
1305 { | 1268 { |
1306 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1269 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1307 std::wstring urlString = GetTab()->GetDocumentUrl(); | 1270 CString urlString = GetTab()->GetDocumentUrl(); |
1308 if (client->IsWhitelistedUrl(urlString)) | 1271 if (client->IsWhitelistedUrl(to_wstring(urlString))) |
1309 { | 1272 { |
1310 settings->RemoveWhiteListedDomain( client->GetHostFromUrl( urlString ).c
_str() ); | 1273 settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w
string(urlString)))); |
1311 } | 1274 } |
1312 else | 1275 else |
1313 { | 1276 { |
1314 settings->AddWhiteListedDomain( client->GetHostFromUrl( urlString).c_str
()); | 1277 settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr
ing(urlString)))); |
1315 } | 1278 } |
1316 GetBrowser()->Refresh(); | 1279 GetBrowser()->Refresh(); |
1317 } | 1280 } |
1318 default: | 1281 default: |
1319 break; | 1282 break; |
1320 } | 1283 } |
1321 | 1284 |
1322 // Invalidate and redraw the control | 1285 // Invalidate and redraw the control |
1323 UpdateStatusBar(); | 1286 UpdateStatusBar(); |
1324 } | 1287 } |
1325 | 1288 |
1326 | 1289 |
1327 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring & url) | 1290 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) |
1328 { | 1291 { |
1329 DEBUG_GENERAL(L"SetMenuBar"); | 1292 DEBUG_GENERAL("SetMenuBar"); |
1330 | 1293 |
1331 std::wstring ctext; | 1294 std::wstring ctext; |
1332 | |
1333 s_criticalSectionLocal.Lock(); | |
1334 { | |
1335 #ifdef SUPPORT_WHITELIST | |
1336 s_menuDomains.clear(); | |
1337 #endif | |
1338 } | |
1339 s_criticalSectionLocal.Unlock(); | |
1340 | |
1341 | |
1342 Dictionary* dictionary = Dictionary::GetInstance(); | 1295 Dictionary* dictionary = Dictionary::GetInstance(); |
1343 | 1296 |
1344 MENUITEMINFOW fmii; | 1297 MENUITEMINFOW fmii = {}; |
1345 memset(&fmii, 0, sizeof(MENUITEMINFO)); | 1298 fmii.cbSize = sizeof(fmii); |
1346 fmii.cbSize = sizeof(MENUITEMINFO); | 1299 |
1347 | 1300 MENUITEMINFOW miiSep = {}; |
1348 MENUITEMINFOW miiSep; | 1301 miiSep.cbSize = sizeof(miiSep); |
1349 memset(&miiSep, 0, sizeof(MENUITEMINFO)); | |
1350 miiSep.cbSize = sizeof(MENUITEMINFO); | |
1351 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 1302 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |
1352 miiSep.fType = MFT_SEPARATOR; | 1303 miiSep.fType = MFT_SEPARATOR; |
1353 | 1304 |
1354 CPluginClient* client = CPluginClient::GetInstance(); | 1305 CPluginClient* client = CPluginClient::GetInstance(); |
1355 | |
1356 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1306 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1357 | |
1358 #ifdef SUPPORT_WHITELIST | |
1359 { | 1307 { |
1360 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 1308 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |
1361 // Is domain in white list? | 1309 // Is domain in white list? |
1362 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); | 1310 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); |
1363 if (client->IsWhitelistedUrl(std::wstring(GetTab()->GetDocumentUrl()))) | 1311 if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) |
1364 { | 1312 { |
1365 fmii.fState = MFS_CHECKED | MFS_ENABLED; | 1313 fmii.fState = MFS_CHECKED | MFS_ENABLED; |
1366 } | 1314 } |
1367 else | 1315 else |
1368 { | 1316 { |
1369 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 1317 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |
1370 } | 1318 } |
1371 fmii.fMask = MIIM_STRING | MIIM_STATE; | 1319 fmii.fMask = MIIM_STRING | MIIM_STATE; |
1372 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1320 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1373 fmii.cch = static_cast<UINT>(ctext.size()); | 1321 fmii.cch = static_cast<UINT>(ctext.size()); |
1374 | 1322 |
1375 ::SetMenuItemInfoW(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE, &fmii); | 1323 ::SetMenuItemInfoW(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE, &fmii); |
1376 } | 1324 } |
1377 #else | |
1378 { | |
1379 ::DeleteMenu(hMenu, ID_MENU_DISABLE_ON_SITE, FALSE); | |
1380 } | |
1381 #endif // SUPPORT_WHITELIST | |
1382 | 1325 |
1383 // Plugin update | 1326 // Plugin update |
1384 ctext = dictionary->Lookup("menu", "menu-update"); | 1327 ctext = dictionary->Lookup("menu", "menu-update"); |
1385 fmii.fMask = MIIM_STATE | MIIM_STRING; | 1328 fmii.fMask = MIIM_STATE | MIIM_STRING; |
1386 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED; | 1329 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED; |
1387 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1330 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1388 fmii.cch = static_cast<UINT>(ctext.size()); | 1331 fmii.cch = static_cast<UINT>(ctext.size()); |
1389 ::SetMenuItemInfoW(hMenu, ID_MENU_UPDATE, FALSE, &fmii); | 1332 ::SetMenuItemInfoW(hMenu, ID_MENU_UPDATE, FALSE, &fmii); |
1390 | 1333 |
1391 | 1334 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 DWORD nProcessId; | 1386 DWORD nProcessId; |
1444 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | 1387 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |
1445 | 1388 |
1446 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | 1389 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |
1447 { | 1390 { |
1448 ::ScreenToClient(hWndToolBar, &pt); | 1391 ::ScreenToClient(hWndToolBar, &pt); |
1449 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | 1392 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |
1450 | 1393 |
1451 if (nButton > 0) | 1394 if (nButton > 0) |
1452 { | 1395 { |
1453 TBBUTTON pTBBtn; | 1396 TBBUTTON pTBBtn = {}; |
1454 memset(&pTBBtn, 0, sizeof(TBBUTTON)); | |
1455 | 1397 |
1456 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 1398 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |
1457 { | 1399 { |
1458 RECT rcButton; | 1400 RECT rcButton; |
1459 nIDCommand = pTBBtn.idCommand; | 1401 nIDCommand = pTBBtn.idCommand; |
1460 | 1402 |
1461 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) | 1403 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) |
1462 { | 1404 { |
1463 pt.x = rcButton.left; | 1405 pt.x = rcButton.left; |
1464 pt.y = rcButton.bottom; | 1406 pt.y = rcButton.bottom; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); | 1483 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); |
1542 LPINT lpParts = (LPINT)LocalLock(hLocal); | 1484 LPINT lpParts = (LPINT)LocalLock(hLocal); |
1543 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | 1485 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); |
1544 | 1486 |
1545 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | 1487 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) |
1546 { | 1488 { |
1547 lpParts[i] -= pClass->m_nPaneWidth; | 1489 lpParts[i] -= pClass->m_nPaneWidth; |
1548 } | 1490 } |
1549 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); |
1550 | 1492 |
1551 CRect rcPane; | 1493 AdblockPlus::Rectangle rcPane; |
1552 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | 1494 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); |
1553 | 1495 |
1554 CRect rcClient; | 1496 AdblockPlus::Rectangle rcClient; |
1555 ::GetClientRect(hWnd, &rcClient); | 1497 ::GetClientRect(hWnd, &rcClient); |
1556 | 1498 |
1557 ::MoveWindow( | 1499 ::MoveWindow( |
1558 pClass->m_hPaneWnd, | 1500 pClass->m_hPaneWnd, |
1559 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | 1501 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, |
1560 0, | 1502 0, |
1561 pClass->m_nPaneWidth, | 1503 pClass->m_nPaneWidth, |
1562 rcClient.Height(), | 1504 rcClient.Height(), |
1563 TRUE); | 1505 TRUE); |
1564 | 1506 |
1565 ::LocalFree(hLocal); | 1507 ::LocalFree(hLocal); |
1566 | 1508 |
1567 | 1509 |
1568 return hRet; | 1510 return hRet; |
1569 } | 1511 } |
1570 | 1512 |
1571 default: | 1513 default: |
1572 break; | 1514 break; |
1573 } | 1515 } |
1574 | 1516 |
1575 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
m, lParam); | 1517 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
m, lParam); |
1576 | 1518 |
1577 | 1519 |
1578 return result; | 1520 return result; |
1579 | 1521 |
1580 } | 1522 } |
1581 | 1523 |
1582 | 1524 |
1583 HICON CPluginClass::GetStatusBarIcon(const std::wstring & url) | 1525 HICON CPluginClass::GetStatusBarIcon(const CString& url) |
1584 { | 1526 { |
1585 // 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 |
1586 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1528 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1587 | 1529 |
1588 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1530 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
1589 if (tab) | 1531 if (tab) |
1590 { | 1532 { |
1591 CPluginClient* client = CPluginClient::GetInstance(); | 1533 CPluginClient* client = CPluginClient::GetInstance(); |
1592 | 1534 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1593 #ifdef PRODUCT_ADBLOCKPLUS | 1535 { |
1594 if (!CPluginSettings::GetInstance()->IsPluginEnabled()) | 1536 if (client->IsWhitelistedUrl(ToWstring(url))) |
1595 { | 1537 { |
1596 } | 1538 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1597 #ifdef SUPPORT_WHITELIST | 1539 } |
1598 else if (client->IsWhitelistedUrl( url )) | 1540 else |
1599 { | 1541 { |
1600 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1542 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1601 } | 1543 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1602 #endif // SUPPORT_WHITELIST | 1544 } |
1603 else | 1545 } |
1604 { | 1546 } |
1605 CPluginSettings* settings = CPluginSettings::GetInstance(); | |
1606 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | |
1607 } | |
1608 | |
1609 #endif // PRODUCT_ADBLOCKPLUS | |
1610 } | |
1611 | |
1612 return hIcon; | 1547 return hIcon; |
1613 } | 1548 } |
1614 | 1549 |
1615 | 1550 |
1616 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) |
1617 { | 1552 { |
1618 // Find tab | 1553 // Find tab |
1619 CPluginClass *pClass = FindInstance(GetParent(hWnd)); | 1554 CPluginClass *pClass = FindInstance(GetParent(hWnd)); |
1620 if (!pClass) | 1555 if (!pClass) |
1621 { | 1556 { |
1622 return ::DefWindowProc(hWnd, message, wParam, lParam); | 1557 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1623 } | 1558 } |
1624 | 1559 |
1625 CPluginSystem* system = CPluginSystem::GetInstance(); | |
1626 | |
1627 // Process message | 1560 // Process message |
1628 switch (message) | 1561 switch (message) |
1629 { | 1562 { |
1630 | 1563 |
1631 case WM_SETCURSOR: | 1564 case WM_SETCURSOR: |
1632 { | 1565 { |
1633 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); | 1566 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); |
1634 return TRUE; | 1567 return TRUE; |
1635 } | 1568 } |
1636 case WM_PAINT: | 1569 case WM_PAINT: |
1637 { | 1570 { |
1638 PAINTSTRUCT ps; | 1571 PAINTSTRUCT ps; |
1639 HDC hDC = ::BeginPaint(hWnd, &ps); | 1572 HDC hDC = ::BeginPaint(hWnd, &ps); |
1640 | 1573 |
1641 CRect rcClient; | 1574 AdblockPlus::Rectangle rcClient; |
1642 ::GetClientRect(hWnd, &rcClient); | 1575 ::GetClientRect(hWnd, &rcClient); |
1643 | 1576 |
1644 int nDrawEdge = 0; | 1577 int nDrawEdge = 0; |
1645 | 1578 |
1646 // Old Windows background drawing | 1579 // Old Windows background drawing |
1647 if (pClass->m_hTheme == NULL) | 1580 if (pClass->m_hTheme == NULL) |
1648 { | 1581 { |
1649 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); | 1582 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); |
1650 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); | 1583 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); |
1651 | 1584 |
1652 nDrawEdge = 3; | 1585 nDrawEdge = 3; |
1653 rcClient.left += 3; | 1586 rcClient.left += 3; |
1654 | 1587 |
1655 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); | 1588 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); |
1656 } | 1589 } |
1657 // Themed background drawing | 1590 // Themed background drawing |
1658 else | 1591 else |
1659 { | 1592 { |
1660 // Draw background | 1593 // Draw background |
1661 if (pfnDrawThemeBackground) | 1594 if (pfnDrawThemeBackground) |
1662 { | 1595 { |
1663 CRect rc = rcClient; | 1596 AdblockPlus::Rectangle rc = rcClient; |
1664 rc.right -= 2; | 1597 rc.right -= 2; |
1665 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); | 1598 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); |
1666 } | 1599 } |
1667 | 1600 |
1668 // Copy separator picture to left side | 1601 // Copy separator picture to left side |
1669 int nHeight = rcClient.Height(); | 1602 int nHeight = rcClient.Height(); |
1670 int nWidth = rcClient.Width() - 2; | 1603 int nWidth = rcClient.Width() - 2; |
1671 | 1604 |
1672 for (int i = 0; i < 2; i++) | 1605 for (int i = 0; i < 2; i++) |
1673 { | 1606 { |
1674 for (int j = 0; j < nHeight; j++) | 1607 for (int j = 0; j < nHeight; j++) |
1675 { | 1608 { |
1676 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); | 1609 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); |
1677 | 1610 |
1678 // Ignore black boxes (if source is obscured by other windows) | 1611 // Ignore black boxes (if source is obscured by other windows) |
1679 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)) |
1680 { | 1613 { |
1681 ::SetPixel(hDC, i, j, clr); | 1614 ::SetPixel(hDC, i, j, clr); |
1682 } | 1615 } |
1683 } | 1616 } |
1684 } | 1617 } |
1685 } | 1618 } |
1686 | 1619 |
1687 // Draw icon | 1620 // Draw icon |
1688 if (CPluginClient::GetInstance()) | 1621 if (CPluginClient::GetInstance()) |
1689 { | 1622 { |
1690 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl().c_str(
)); | 1623 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); |
1691 | 1624 |
1692 int offx = (rcClient.Height() - 16)/2 + nDrawEdge; | 1625 int offx = (rcClient.Height() - 16)/2 + nDrawEdge; |
1693 if (hIcon) | 1626 if (hIcon) |
1694 { | 1627 { |
1695 ::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); |
1696 offx += 22; | 1629 offx += 22; |
1697 } | 1630 } |
1698 #ifdef _DEBUG | 1631 #ifdef _DEBUG |
1699 // Display version | 1632 // Display version |
1700 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT,
0, 0); | 1633 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT,
0, 0); |
1701 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); | 1634 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); |
1702 | 1635 |
1703 CRect rcText = rcClient; | 1636 AdblockPlus::Rectangle rcText = rcClient; |
1704 rcText.left += offx; | 1637 rcText.left += offx; |
1705 ::SetBkMode(hDC, TRANSPARENT); | 1638 ::SetBkMode(hDC, TRANSPARENT); |
1706 ::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); |
1707 | 1640 |
1708 ::SelectObject(hDC, hOldFont); | 1641 ::SelectObject(hDC, hOldFont); |
1709 #endif // _DEBUG | 1642 #endif // _DEBUG |
1710 } | 1643 } |
1711 | 1644 |
1712 // Done! | 1645 // Done! |
1713 EndPaint(hWnd, &ps); | 1646 EndPaint(hWnd, &ps); |
1714 | 1647 |
1715 return 0; | 1648 return 0; |
1716 } | 1649 } |
1717 | 1650 |
1718 case WM_LBUTTONUP: | 1651 case WM_LBUTTONUP: |
1719 case WM_RBUTTONUP: | 1652 case WM_RBUTTONUP: |
1720 { | 1653 { |
1721 std::wstring url = pClass->GetBrowserUrl(); | 1654 CString strURL = pClass->GetBrowserUrl(); |
1722 if (url != pClass->GetTab()->GetDocumentUrl()) | 1655 if (strURL != pClass->GetTab()->GetDocumentUrl()) |
1723 { | 1656 { |
1724 pClass->GetTab()->SetDocumentUrl( url ); | 1657 pClass->GetTab()->SetDocumentUrl(strURL); |
1725 } | 1658 } |
1726 | 1659 |
1727 // Create menu | 1660 // Create menu |
1728 HMENU hMenu = pClass->CreatePluginMenu( url ); | 1661 HMENU hMenu = pClass->CreatePluginMenu(strURL); |
1729 if (!hMenu) | 1662 if (!hMenu) |
1730 { | 1663 { |
1731 return 0; | 1664 return 0; |
1732 } | 1665 } |
1733 | 1666 |
1734 // Display menu | 1667 // Display menu |
1735 POINT pt; | 1668 POINT pt; |
1736 ::GetCursorPos(&pt); | 1669 ::GetCursorPos(&pt); |
1737 | 1670 |
1738 RECT rc; | 1671 RECT rc; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1812 } | 1745 } |
1813 break; | 1746 break; |
1814 } | 1747 } |
1815 | 1748 |
1816 return DefWindowProc(hWnd, message, wParam, lParam); | 1749 return DefWindowProc(hWnd, message, wParam, lParam); |
1817 } | 1750 } |
1818 | 1751 |
1819 | 1752 |
1820 void CPluginClass::UpdateStatusBar() | 1753 void CPluginClass::UpdateStatusBar() |
1821 { | 1754 { |
1822 DEBUG_GENERAL(L"*** Updating statusbar") | 1755 DEBUG_GENERAL("*** Updating statusbar") |
1823 if (m_hPaneWnd == NULL) | 1756 if (m_hPaneWnd == NULL) |
1824 { | 1757 { |
1825 CreateStatusBarPane(); | 1758 CreateStatusBarPane(); |
1826 } | 1759 } |
1827 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) | 1760 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) |
1828 { | 1761 { |
1829 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"); |
1830 } | 1763 } |
1831 } | 1764 } |
1832 | 1765 |
1833 | 1766 |
1834 void CPluginClass::Unadvice() | 1767 void CPluginClass::Unadvice() |
1835 { | 1768 { |
1836 s_criticalSectionLocal.Lock(); | 1769 s_criticalSectionLocal.Lock(); |
1837 { | 1770 { |
1838 if (m_isAdviced) | 1771 if (m_isAdviced) |
1839 { | 1772 { |
1840 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); | 1773 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); |
1841 if (pPoint) | 1774 if (pPoint) |
1842 { | 1775 { |
1843 HRESULT hr = pPoint->Unadvise(m_nConnectionID); | 1776 HRESULT hr = pPoint->Unadvise(m_nConnectionID); |
1844 if (FAILED(hr)) | 1777 if (FAILED(hr)) |
1845 { | 1778 { |
1846 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"); |
1847 } | 1780 } |
1848 } | 1781 } |
1849 | 1782 |
1850 m_isAdviced = false; | 1783 m_isAdviced = false; |
1851 } | 1784 } |
1852 } | 1785 } |
1853 s_criticalSectionLocal.Unlock(); | 1786 s_criticalSectionLocal.Unlock(); |
1854 } | 1787 } |
1855 | 1788 |
1856 HICON CPluginClass::GetIcon(int type) | 1789 HICON CPluginClass::GetIcon(int type) |
1857 { | 1790 { |
1858 HICON icon = NULL; | 1791 HICON icon = NULL; |
1859 | 1792 |
1860 s_criticalSectionLocal.Lock(); | 1793 s_criticalSectionLocal.Lock(); |
1861 { | 1794 { |
1862 if (!s_hIcons[type]) | 1795 if (!s_hIcons[type]) |
1863 { | 1796 { |
1864 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[
type])); | 1797 s_hIcons[type] = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(s_hIconTypes[
type])); |
1865 if (!s_hIcons[type]) | 1798 if (!s_hIcons[type]) |
1866 { | 1799 { |
1867 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") |
1868 } | 1801 } |
1869 } | 1802 } |
1870 | 1803 |
1871 icon = s_hIcons[type]; | 1804 icon = s_hIcons[type]; |
1872 } | 1805 } |
1873 s_criticalSectionLocal.Unlock(); | 1806 s_criticalSectionLocal.Unlock(); |
1874 | 1807 |
1875 return icon; | 1808 return icon; |
1876 } | 1809 } |
1877 | 1810 |
1878 ATOM CPluginClass::GetAtomPaneClass() | 1811 ATOM CPluginClass::GetAtomPaneClass() |
1879 { | 1812 { |
1880 return s_atomPaneClass; | 1813 return s_atomPaneClass; |
1881 } | 1814 } |
1882 | 1815 |
1883 HWND CPluginClass::GetTabHWND() const | 1816 HWND CPluginClass::GetTabHWND() const |
1884 { | 1817 { |
1885 | 1818 std::array<wchar_t, MAX_PATH> className; |
1886 TCHAR szClassName[MAX_PATH]; | |
1887 // Get browser window and url | 1819 // Get browser window and url |
1888 HWND hBrowserWnd = GetBrowserHWND(); | 1820 HWND hBrowserWnd = GetBrowserHWND(); |
1889 if (!hBrowserWnd) | 1821 if (!hBrowserWnd) |
1890 { | 1822 { |
1891 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") |
1892 s_criticalSectionWindow.Unlock(); | 1824 s_criticalSectionWindow.Unlock(); |
1893 | 1825 |
1894 return false; | 1826 return false; |
1895 } | 1827 } |
1896 | 1828 |
1897 // Looking for a TabWindowClass window in IE7 | 1829 // Looking for a TabWindowClass window in IE7 |
1898 | 1830 |
1899 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); | 1831 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD); |
1900 while (hTabWnd) | 1832 while (hTabWnd) |
1901 { | 1833 { |
1902 memset(szClassName, 0, MAX_PATH); | 1834 className[0] = L'\0'; |
1903 GetClassName(hTabWnd, szClassName, MAX_PATH); | 1835 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz
e()); |
1904 | 1836 |
1905 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)) |
1906 { | 1838 { |
1907 // IE8 support | 1839 // IE8 support |
1908 HWND hTabWnd2 = hTabWnd; | 1840 HWND hTabWnd2 = hTabWnd; |
1909 if (_tcscmp(szClassName,_T("Frame Tab")) == 0) | 1841 if (wcscmp(className.data(), L"Frame Tab") == 0) |
1910 { | 1842 { |
1911 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, _T("TabWindowClass"), NULL); | 1843 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL); |
1912 } | 1844 } |
1913 | 1845 |
1914 if (hTabWnd2) | 1846 if (hTabWnd2) |
1915 { | 1847 { |
1916 DWORD nProcessId; | 1848 DWORD nProcessId; |
1917 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); | 1849 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId); |
1918 if (::GetCurrentProcessId() == nProcessId) | 1850 if (::GetCurrentProcessId() == nProcessId) |
1919 { | 1851 { |
1920 bool bExistingTab = false; | 1852 bool bExistingTab = false; |
1921 s_criticalSectionLocal.Lock(); | 1853 s_criticalSectionLocal.Lock(); |
1922 | 1854 |
1923 { | 1855 { |
1924 for (int i = 0; i < s_instances.GetSize(); i++) | 1856 for (auto instance : s_instances) |
1925 { | 1857 { |
1926 if (s_instances[i]->m_hTabWnd == hTabWnd2) | 1858 if (instance->m_hTabWnd == hTabWnd2) |
1927 { | 1859 { |
1928 bExistingTab = true; | 1860 bExistingTab = true; |
1929 break; | 1861 break; |
1930 } | 1862 } |
1931 } | 1863 } |
1932 } | 1864 } |
1933 | 1865 |
1934 if (!bExistingTab) | 1866 if (!bExistingTab) |
1935 { | 1867 { |
1936 hBrowserWnd = hTabWnd2; | 1868 hBrowserWnd = hTabWnd2; |
1937 hTabWnd = hTabWnd2; | 1869 hTabWnd = hTabWnd2; |
1938 s_criticalSectionLocal.Unlock(); | 1870 s_criticalSectionLocal.Unlock(); |
1939 break; | 1871 break; |
1940 } | 1872 } |
1941 s_criticalSectionLocal.Unlock(); | 1873 s_criticalSectionLocal.Unlock(); |
1942 | 1874 |
1943 } | 1875 } |
1944 } | 1876 } |
1945 } | 1877 } |
1946 | 1878 |
1947 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 1879 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |
1948 } | 1880 } |
1949 | 1881 |
1950 return hTabWnd; | 1882 return hTabWnd; |
1951 | 1883 |
1952 } | 1884 } |
LEFT | RIGHT |