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

Side by Side Diff: src/plugin/PluginClass.cpp

Issue 5032147387678720: NoIssue - Refactor HTTP and HTTPS namespaces registration
Patch Set: Created April 13, 2015, 3:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
19 19
20 #include "PluginClass.h" 20 #include "PluginClass.h"
21 #include "PluginSettings.h" 21 #include "PluginSettings.h"
22 #include "PluginSystem.h" 22 #include "PluginSystem.h"
23 #include "PluginFilter.h" 23 #include "PluginFilter.h"
24 #include "PluginMimeFilterClient.h" 24 #include "PluginMimeFilterClient.h"
25 #include "PluginClient.h" 25 #include "PluginClient.h"
26 #include "PluginClientFactory.h"
27 #include "PluginMutex.h" 26 #include "PluginMutex.h"
28 #include "sddl.h" 27 #include "sddl.h"
29 #include "PluginUtil.h" 28 #include "PluginUtil.h"
30 #include "PluginUserSettings.h" 29 #include "PluginUserSettings.h"
31 #include "../shared/Utils.h" 30 #include "../shared/Utils.h"
32 #include "../shared/Dictionary.h" 31 #include "../shared/Dictionary.h"
33 #include "../shared/IE_version.h" 32 #include "../shared/IE_version.h"
34 #include <thread> 33 #include <thread>
35 #include <array> 34 #include <array>
36 35
37 #ifdef DEBUG_HIDE_EL 36 #ifdef DEBUG_HIDE_EL
38 DWORD profileTime = 0; 37 DWORD profileTime = 0;
39 #endif 38 #endif
40 39
41 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); 40 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR);
42 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT); 41 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT);
43 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); 42 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE);
44 43
45 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; 44 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL };
46 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED }; 45 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED };
47 uint32_t iconHeight = 32; 46 uint32_t iconHeight = 32;
48 uint32_t iconWidth = 32; 47 uint32_t iconWidth = 32;
49 48
50 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; 49 std::shared_ptr<CPluginMimeFilterClient> CPluginClass::s_mimeFilter = NULL;
51 50
52 CLOSETHEMEDATA pfnClose = NULL; 51 CLOSETHEMEDATA pfnClose = NULL;
53 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; 52 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL;
54 OPENTHEMEDATA pfnOpenThemeData = NULL; 53 OPENTHEMEDATA pfnOpenThemeData = NULL;
55 54
56 ATOM CPluginClass::s_atomPaneClass = NULL; 55 ATOM CPluginClass::s_atomPaneClass = NULL;
57 HINSTANCE CPluginClass::s_hUxtheme = NULL; 56 HINSTANCE CPluginClass::s_hUxtheme = NULL;
58 std::set<CPluginClass*> CPluginClass::s_instances; 57 std::set<CPluginClass*> CPluginClass::s_instances;
59 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; 58 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances;
60 59
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 239 }
241 s_criticalSectionBrowser.Unlock(); 240 s_criticalSectionBrowser.Unlock();
242 241
243 //register the mimefilter 242 //register the mimefilter
244 //and only mimefilter 243 //and only mimefilter
245 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 244 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
246 245
247 s_criticalSectionLocal.Lock(); 246 s_criticalSectionLocal.Lock();
248 { 247 {
249 // Always register on startup, then check if we need to unregister in a separate thread 248 // Always register on startup, then check if we need to unregister in a separate thread
250 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 249 if (!s_mimeFilter)
250 {
251 s_mimeFilter.reset(new CPluginMimeFilterClient());
252 }
251 s_asyncWebBrowser2 = unknownSite; 253 s_asyncWebBrowser2 = unknownSite;
252 s_instances.insert(this); 254 s_instances.insert(this);
253 } 255 }
254 s_criticalSectionLocal.Unlock(); 256 s_criticalSectionLocal.Unlock();
255 257
256 try 258 try
257 { 259 {
258 auto webBrowser = GetBrowser(); 260 auto webBrowser = GetBrowser();
259 if (webBrowser) 261 if (webBrowser)
260 { 262 {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 315
314 s_criticalSectionLocal.Lock(); 316 s_criticalSectionLocal.Lock();
315 { 317 {
316 s_instances.erase(this); 318 s_instances.erase(this);
317 319
318 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge tCurrentThreadId()); 320 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge tCurrentThreadId());
319 if (it != s_threadInstances.end()) 321 if (it != s_threadInstances.end())
320 { 322 {
321 s_threadInstances.erase(it); 323 s_threadInstances.erase(it);
322 } 324 }
323 if (s_instances.empty())
324 {
325 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
326 CPluginClientFactory::ReleaseMimeFilterClientInstance();
327 }
328 } 325 }
329 s_criticalSectionLocal.Unlock(); 326 s_criticalSectionLocal.Unlock();
330 327
331 // Release browser interface 328 // Release browser interface
332 s_criticalSectionBrowser.Lock(); 329 s_criticalSectionBrowser.Lock();
333 { 330 {
334 m_webBrowser2.Release(); 331 m_webBrowser2.Release();
335 } 332 }
336 s_criticalSectionBrowser.Unlock(); 333 s_criticalSectionBrowser.Unlock();
337 334
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 620 }
624 } 621 }
625 622
626 bool CPluginClass::InitObject() 623 bool CPluginClass::InitObject()
627 { 624 {
628 DEBUG_GENERAL("InitObject"); 625 DEBUG_GENERAL("InitObject");
629 CPluginSettings* settings = CPluginSettings::GetInstance(); 626 CPluginSettings* settings = CPluginSettings::GetInstance();
630 627
631 if (!settings->GetPluginEnabled()) 628 if (!settings->GetPluginEnabled())
632 { 629 {
633 s_mimeFilter->Unregister(); 630 s_mimeFilter.reset();
634 } 631 }
635 632
636 // Load theme module 633 // Load theme module
637 s_criticalSectionLocal.Lock(); 634 s_criticalSectionLocal.Lock();
638 { 635 {
639 if (!s_hUxtheme) 636 if (!s_hUxtheme)
640 { 637 {
641 s_hUxtheme = ::GetModuleHandle(L"uxtheme.dll"); 638 s_hUxtheme = ::GetModuleHandle(L"uxtheme.dll");
642 if (s_hUxtheme) 639 if (s_hUxtheme)
643 { 640 {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 { 1079 {
1083 CPluginSettings* settings = CPluginSettings::GetInstance(); 1080 CPluginSettings* settings = CPluginSettings::GetInstance();
1084 1081
1085 settings->TogglePluginEnabled(); 1082 settings->TogglePluginEnabled();
1086 1083
1087 // Enable / disable mime filter 1084 // Enable / disable mime filter
1088 s_criticalSectionLocal.Lock(); 1085 s_criticalSectionLocal.Lock();
1089 { 1086 {
1090 if (settings->GetPluginEnabled()) 1087 if (settings->GetPluginEnabled())
1091 { 1088 {
1092 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 1089 s_mimeFilter.reset(new CPluginMimeFilterClient());
1093 } 1090 }
1094 else 1091 else
1095 { 1092 {
1096 s_mimeFilter = NULL; 1093 s_mimeFilter.reset();
1097
1098 CPluginClientFactory::ReleaseMimeFilterClientInstance();
1099 } 1094 }
1100 } 1095 }
1101 s_criticalSectionLocal.Unlock(); 1096 s_criticalSectionLocal.Unlock();
1102 } 1097 }
1103 break; 1098 break;
1104 case ID_MENU_SETTINGS: 1099 case ID_MENU_SETTINGS:
1105 { 1100 {
1106 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 1101 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1107 if (browser) 1102 if (browser)
1108 { 1103 {
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 s_criticalSectionLocal.Unlock(); 1731 s_criticalSectionLocal.Unlock();
1737 1732
1738 } 1733 }
1739 } 1734 }
1740 } 1735 }
1741 1736
1742 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1737 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1743 } 1738 }
1744 return hTabWnd; 1739 return hTabWnd;
1745 } 1740 }
OLDNEW
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld