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

Side by Side 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.
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/engine/NotificationWindow.cpp ('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 #include "AdblockPlusClient.h" 19 #include "AdblockPlusClient.h"
20 #include "PluginSettings.h" 20 #include "PluginSettings.h"
21 #include "PluginSystem.h" 21 #include "PluginSystem.h"
22 #include "PluginFilter.h" 22 #include "PluginFilter.h"
23 #include "PluginMutex.h" 23 #include "PluginMutex.h"
24 #include "PluginClass.h" 24 #include "PluginClass.h"
25 #include "../shared/Utils.h" 25 #include "../shared/Utils.h"
26 26
27 namespace 27 namespace
28 { 28 {
29 class ScopedProcessInformation : public PROCESS_INFORMATION {
30 public:
31 ScopedProcessInformation()
32 {
33 hProcess = hThread = 0;
34 dwProcessId = dwThreadId = 0;
35 }
36 ~ScopedProcessInformation()
37 {
38 if (hThread != nullptr)
39 {
40 CloseHandle(hThread);
41 }
42 if (hProcess != nullptr)
43 {
44 CloseHandle(hProcess);
45 }
46 }
47 };
48
29 void SpawnAdblockPlusEngine() 49 void SpawnAdblockPlusEngine()
30 { 50 {
31 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; 51 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe";
32 CString params = ToCString(L"AdblockPlusEngine.exe " + GetBrowserLanguage()) ; 52 std::wstring params = L"AdblockPlusEngine.exe " + GetBrowserLanguage();
33 53
34 STARTUPINFO startupInfo = {}; 54 STARTUPINFO startupInfo = {};
35 PROCESS_INFORMATION processInformation = {}; 55 ScopedProcessInformation processInformation;
36 56
37 HANDLE token; 57 // We need to break out from AppContainer. Launch with default security - re gistry entry will eat the user prompt
38 OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token); 58 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_el ebp
39 59 BOOL createProcRes = CreateProcessW(engineExecutablePath.c_str(), &params[0] ,
40 TOKEN_APPCONTAINER_INFORMATION *acs = NULL; 60 0, 0, false, 0, 0, 0, &startupInfo, &processInformation);
41 DWORD length = 0;
42
43 // Get AppContainer SID
44 if (!GetTokenInformation(token, TokenAppContainerSid, acs, 0, &length) && Ge tLastError() == ERROR_INSUFFICIENT_BUFFER)
45 {
46 acs = (TOKEN_APPCONTAINER_INFORMATION*) HeapAlloc(GetProcessHeap(), HEAP _ZERO_MEMORY, length);
47 if (acs != NULL)
48 {
49 GetTokenInformation(token, TokenAppContainerSid, acs, length, &length) ;
50 }
51 else
52 {
53 throw std::runtime_error("Out of memory");
54 }
55 }
56
57 BOOL createProcRes = 0;
58 // Running inside AppContainer or in Windows XP
59 if ((acs != NULL && acs->TokenAppContainer != NULL) || !IsWindowsVistaOrLate r())
60 {
61 // We need to break out from AppContainer. Launch with default security - registry entry will eat the user prompt
62 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_ elebp
63 createProcRes = CreateProcessW(engineExecutablePath.c_str(), params.GetBuf fer(params.GetLength() + 1),
64 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
65 }
66 else
67 {
68 // Launch with Low Integrity explicitly
69 HANDLE newToken;
70 DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newTok en);
71
72 PSID integritySid = 0;
73 ConvertStringSidToSid(L"S-1-16-4096", &integritySid);
74 std::tr1::shared_ptr<SID> sharedIntegritySid(static_cast<SID*>(integritySi d), FreeSid); // Just to simplify cleanup
75
76 TOKEN_MANDATORY_LABEL tml = {};
77 tml.Label.Attributes = SE_GROUP_INTEGRITY;
78 tml.Label.Sid = integritySid;
79
80 // Set the process integrity level
81 SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(tml));
82
83 STARTUPINFO startupInfo = {};
84 PROCESS_INFORMATION processInformation = {};
85
86 createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str( ), params.GetBuffer(params.GetLength() + 1),
87 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
88 }
89
90 if (!createProcRes) 61 if (!createProcRes)
91 { 62 {
92 throw std::runtime_error("Failed to start Adblock Plus Engine"); 63 throw std::runtime_error("Failed to start Adblock Plus Engine");
93 } 64 }
94
95 CloseHandle(processInformation.hProcess);
96 CloseHandle(processInformation.hThread);
97 } 65 }
98 66
99 Communication::Pipe* OpenEnginePipe() 67 Communication::Pipe* OpenEnginePipe()
100 { 68 {
101 try 69 try
102 { 70 {
103 return new Communication::Pipe(Communication::pipeName, Communication::Pip e::MODE_CONNECT); 71 return new Communication::Pipe(Communication::pipeName, Communication::Pip e::MODE_CONNECT);
104 } 72 }
105 catch (Communication::PipeConnectionError e) 73 catch (Communication::PipeConnectionError e)
106 { 74 {
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 DEBUG_GENERAL("CompareVersions"); 533 DEBUG_GENERAL("CompareVersions");
566 Communication::OutputBuffer request; 534 Communication::OutputBuffer request;
567 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2); 535 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2);
568 Communication::InputBuffer response; 536 Communication::InputBuffer response;
569 if (!CallEngine(request, response)) 537 if (!CallEngine(request, response))
570 return 0; 538 return 0;
571 int result; 539 int result;
572 response >> result; 540 response >> result;
573 return result; 541 return result;
574 } 542 }
OLDNEW
« 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