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

Delta Between Two Patch Sets: src/engine/main.cpp

Issue 10783032: Pass browser locale to the JS code (Closed)
Left Patch Set: Created June 4, 2013, 8:57 a.m.
Right Patch Set: Fixed review comments Created June 4, 2013, 11:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/plugin/AdblockPlusClient.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include "stdafx.h" 1 #include "stdafx.h"
2 2
3 #include "../shared/AutoHandle.h" 3 #include "../shared/AutoHandle.h"
4 #include "../shared/Communication.h" 4 #include "../shared/Communication.h"
5 #include "../shared/Version.h"
5 #include "Debug.h" 6 #include "Debug.h"
6 #include "Utils.h" 7 #include "Utils.h"
7 8
8 namespace 9 namespace
9 { 10 {
10 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 11 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
11 12
12 std::string ToUtf8String(std::wstring str) 13 std::string ToUtf8String(std::wstring str)
13 { 14 {
14 size_t length = str.size(); 15 size_t length = str.size();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 158 }
158 159
159 // TODO: Keep the pipe open until the client disconnects 160 // TODO: Keep the pipe open until the client disconnects
160 161
161 return 0; 162 return 0;
162 } 163 }
163 } 164 }
164 165
165 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale) 166 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale)
166 { 167 {
167 AdblockPlus::AppInfo appInfo; 168 AdblockPlus::AppInfo appInfo;
Felix Dahlke 2013/06/04 09:46:09 The version's missing, would like to see at least
169 appInfo.version = ToUtf8String(IEPLUGIN_VERSION);
168 appInfo.name = "adblockplusie"; 170 appInfo.name = "adblockplusie";
169 appInfo.platform = "msie"; 171 appInfo.platform = "msie";
170 appInfo.locale = ToUtf8String(locale); 172 appInfo.locale = ToUtf8String(locale);
171 173
172 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); 174 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
173 std::string dataPath = ToUtf8String(GetAppDataPath()); 175 std::string dataPath = ToUtf8String(GetAppDataPath());
174 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); 176 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath);
175 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); 177 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine));
176 return filterEngine; 178 return filterEngine;
177 } 179 }
178 180
179 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) 181 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
180 { 182 {
181 // TODO: Attempt to create the pipe first, and exit immediately if this 183 // TODO: Attempt to create the pipe first, and exit immediately if this
182 // fails. Since multiple instances of the engine could be running, 184 // fails. Since multiple instances of the engine could be running,
183 // this may need named mutices to avoid race conditions. 185 // this may need named mutices to avoid race conditions.
184 // Note that as soon as the pipe is created first, we can reduce the 186 // Note that as soon as the pipe is created first, we can reduce the
185 // client timeout after CreateProcess(), but should increase the one 187 // client timeout after CreateProcess(), but should increase the one
186 // in WaitNamedPipe(). 188 // in WaitNamedPipe().
187 189
188 int argc; 190 int argc;
189 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); 191 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
Felix Dahlke 2013/06/04 09:46:09 According to the docs, you need to free argv using
190 std::wstring locale(argc >= 1 ? argv[0] : L""); 192 std::wstring locale(argc >= 1 ? argv[0] : L"");
193 LocalFree(argv);
194
191 filterEngine = CreateFilterEngine(locale); 195 filterEngine = CreateFilterEngine(locale);
192 196
193 for (;;) 197 for (;;)
194 { 198 {
195 try 199 try
196 { 200 {
197 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e, 201 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e,
198 Communication::Pipe::MODE_CREATE); 202 Communication::Pipe::MODE_CREATE);
199 203
200 // TODO: Count established connections, kill the engine when none are left 204 // TODO: Count established connections, kill the engine when none are left
201 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0)); 205 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0));
202 if (!thread.get()) 206 if (!thread)
203 { 207 {
204 delete pipe; 208 delete pipe;
205 DebugLastError("CreateThread failed"); 209 DebugLastError("CreateThread failed");
206 return 1; 210 return 1;
207 } 211 }
208 } 212 }
209 catch (std::runtime_error e) 213 catch (std::runtime_error e)
210 { 214 {
211 DebugException(e); 215 DebugException(e);
212 return 1; 216 return 1;
213 } 217 }
214 } 218 }
215 219
216 return 0; 220 return 0;
217 } 221 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld