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

Unified Diff: src/plugin/AdblockPlusClient.cpp

Issue 6505394822184960: Issue 1109 - Support notifications (Closed)
Patch Set: improve ReplaceMulti and change loading of html template Created June 29, 2015, 11:09 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/engine/NotificationWindow.cpp ('k') | src/plugin/PluginFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/AdblockPlusClient.cpp
diff --git a/src/plugin/AdblockPlusClient.cpp b/src/plugin/AdblockPlusClient.cpp
index edee79b6f91613cd86688ea9040b6c05bccae5cb..a68e149c3abedc990f40d194984f9012af980834 100644
--- a/src/plugin/AdblockPlusClient.cpp
+++ b/src/plugin/AdblockPlusClient.cpp
@@ -26,74 +26,42 @@
namespace
{
- void SpawnAdblockPlusEngine()
- {
- std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe";
- CString params = ToCString(L"AdblockPlusEngine.exe " + GetBrowserLanguage());
-
- STARTUPINFO startupInfo = {};
- PROCESS_INFORMATION processInformation = {};
-
- HANDLE token;
- OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token);
-
- TOKEN_APPCONTAINER_INFORMATION *acs = NULL;
- DWORD length = 0;
-
- // Get AppContainer SID
- if (!GetTokenInformation(token, TokenAppContainerSid, acs, 0, &length) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+ class ScopedProcessInformation : public PROCESS_INFORMATION {
+ public:
+ ScopedProcessInformation()
{
- acs = (TOKEN_APPCONTAINER_INFORMATION*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, length);
- if (acs != NULL)
- {
- GetTokenInformation(token, TokenAppContainerSid, acs, length, &length);
- }
- else
- {
- throw std::runtime_error("Out of memory");
- }
+ hProcess = hThread = 0;
+ dwProcessId = dwThreadId = 0;
}
-
- BOOL createProcRes = 0;
- // Running inside AppContainer or in Windows XP
- if ((acs != NULL && acs->TokenAppContainer != NULL) || !IsWindowsVistaOrLater())
+ ~ScopedProcessInformation()
{
- // We need to break out from AppContainer. Launch with default security - registry entry will eat the user prompt
- // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_elebp
- createProcRes = CreateProcessW(engineExecutablePath.c_str(), params.GetBuffer(params.GetLength() + 1),
- 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
+ if (hThread != nullptr)
+ {
+ CloseHandle(hThread);
+ }
+ if (hProcess != nullptr)
+ {
+ CloseHandle(hProcess);
+ }
}
- else
- {
- // Launch with Low Integrity explicitly
- HANDLE newToken;
- DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newToken);
-
- PSID integritySid = 0;
- ConvertStringSidToSid(L"S-1-16-4096", &integritySid);
- std::tr1::shared_ptr<SID> sharedIntegritySid(static_cast<SID*>(integritySid), FreeSid); // Just to simplify cleanup
-
- TOKEN_MANDATORY_LABEL tml = {};
- tml.Label.Attributes = SE_GROUP_INTEGRITY;
- tml.Label.Sid = integritySid;
-
- // Set the process integrity level
- SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(tml));
+ };
- STARTUPINFO startupInfo = {};
- PROCESS_INFORMATION processInformation = {};
+ void SpawnAdblockPlusEngine()
+ {
+ std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe";
+ std::wstring params = L"AdblockPlusEngine.exe " + GetBrowserLanguage();
- createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str(), params.GetBuffer(params.GetLength() + 1),
- 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
- }
+ STARTUPINFO startupInfo = {};
+ ScopedProcessInformation processInformation;
+ // We need to break out from AppContainer. Launch with default security - registry entry will eat the user prompt
+ // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_elebp
+ BOOL createProcRes = CreateProcessW(engineExecutablePath.c_str(), &params[0],
+ 0, 0, false, 0, 0, 0, &startupInfo, &processInformation);
if (!createProcRes)
{
throw std::runtime_error("Failed to start Adblock Plus Engine");
}
-
- CloseHandle(processInformation.hProcess);
- CloseHandle(processInformation.hThread);
}
Communication::Pipe* OpenEnginePipe()
@@ -148,7 +116,7 @@ namespace
}
CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL;
-CComAutoCriticalSection CAdblockPlusClient::s_criticalSectionLocal;
+CComAutoCriticalSection CAdblockPlusClient::s_criticalSectionLocal;
CAdblockPlusClient::CAdblockPlusClient()
{
« no previous file with comments | « src/engine/NotificationWindow.cpp ('k') | src/plugin/PluginFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld