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

Side by Side Diff: src/engine/main.cpp

Issue 10783032: Pass browser locale to the JS code (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.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 #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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 { 156 {
156 DebugException(e); 157 DebugException(e);
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() 166 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale)
166 { 167 {
167 // TODO: Pass appInfo in, which should be sent by the client 168 AdblockPlus::AppInfo appInfo;
168 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(); 169 appInfo.version = ToUtf8String(IEPLUGIN_VERSION);
170 appInfo.name = "adblockplusie";
171 appInfo.platform = "msie";
172 appInfo.locale = ToUtf8String(locale);
173
174 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
169 std::string dataPath = ToUtf8String(GetAppDataPath()); 175 std::string dataPath = ToUtf8String(GetAppDataPath());
170 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); 176 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath);
171 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); 177 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine));
172 return filterEngine; 178 return filterEngine;
173 } 179 }
174 180
175 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) 181 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
176 { 182 {
177 // 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
178 // fails. Since multiple instances of the engine could be running, 184 // fails. Since multiple instances of the engine could be running,
179 // this may need named mutices to avoid race conditions. 185 // this may need named mutices to avoid race conditions.
180 // 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
181 // client timeout after CreateProcess(), but should increase the one 187 // client timeout after CreateProcess(), but should increase the one
182 // in WaitNamedPipe(). 188 // in WaitNamedPipe().
183 189
184 filterEngine = CreateFilterEngine(); 190 int argc;
191 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
192 std::wstring locale(argc >= 1 ? argv[0] : L"");
193 LocalFree(argv);
194
195 filterEngine = CreateFilterEngine(locale);
185 196
186 for (;;) 197 for (;;)
187 { 198 {
188 try 199 try
189 { 200 {
190 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e, 201 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e,
191 Communication::Pipe::MODE_CREATE); 202 Communication::Pipe::MODE_CREATE);
192 203
193 // TODO: Count established connections, kill the engine when none are left 204 // TODO: Count established connections, kill the engine when none are left
194 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));
195 if (!thread) 206 if (!thread)
196 { 207 {
197 delete pipe; 208 delete pipe;
198 DebugLastError("CreateThread failed"); 209 DebugLastError("CreateThread failed");
199 return 1; 210 return 1;
200 } 211 }
201 } 212 }
202 catch (std::runtime_error e) 213 catch (std::runtime_error e)
203 { 214 {
204 DebugException(e); 215 DebugException(e);
205 return 1; 216 return 1;
206 } 217 }
207 } 218 }
208 219
209 return 0; 220 return 0;
210 } 221 }
OLDNEW
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld