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

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

Issue 10845030: Marshal all libadblockplus calls to the engine process (Closed)
Patch Set: Created May 31, 2013, 2:20 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 #include "PluginUserSettings.h" 2 #include "PluginUserSettings.h"
3 #include <algorithm> 3 #include <algorithm>
4 #include "PluginSettings.h" 4 #include "PluginSettings.h"
5 #include "PluginClient.h" 5 #include "PluginClient.h"
6 #include "PluginIniFileW.h" 6 #include "PluginIniFileW.h"
7 #include "PluginDictionary.h" 7 #include "PluginDictionary.h"
8 8
9 static const CString s_GetMessage = L"GetMessage"; 9 static const CString s_GetMessage = L"GetMessage";
10 static const CString s_GetLanguageCount = L"GetLanguageCount"; 10 static const CString s_GetLanguageCount = L"GetLanguageCount";
11 static const CString s_GetLanguageByIndex = L"GetLanguageByIndex"; 11 static const CString s_GetLanguageByIndex = L"GetLanguageByIndex";
12 static const CString s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex"; 12 static const CString s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex";
13 static const CString s_SetLanguage = L"SetLanguage"; 13 static const CString s_SetLanguage = L"SetLanguage";
14 static const CString s_GetLanguage = L"GetLanguage"; 14 static const CString s_GetLanguage = L"GetLanguage";
15 static const CString s_GetWhitelistDomains = L"GetWhitelistDomains"; 15 static const CString s_GetWhitelistDomains = L"GetWhitelistDomains";
16 static const CString s_AddWhitelistDomain = L"AddWhitelistDomain"; 16 static const CString s_AddWhitelistDomain = L"AddWhitelistDomain";
17 static const CString s_RemoveWhitelistDomain = L"RemoveWhitelistDomain"; 17 static const CString s_RemoveWhitelistDomain = L"RemoveWhitelistDomain";
18 18
19 static const CString s_Methods[] = {s_GetMessage, s_GetLanguageCount, s_GetLangu ageByIndex, s_GetLanguageTitleByIndex, s_SetLanguage, s_GetLanguage, s_GetWhitel istDomains, s_AddWhitelistDomain, s_RemoveWhitelistDomain}; 19 static const CString s_Methods[] = {s_GetMessage, s_GetLanguageCount, s_GetLangu ageByIndex, s_GetLanguageTitleByIndex, s_SetLanguage, s_GetLanguage, s_GetWhitel istDomains, s_AddWhitelistDomain, s_RemoveWhitelistDomain};
20 20
21 CPluginUserSettings::CPluginUserSettings() 21 CPluginUserSettings::CPluginUserSettings()
22 { 22 {
23 } 23 }
24 24
25 25
26 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) 26 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj)
27 { 27 {
28 if (IID_IUnknown == riid || IID_IDispatch == riid) 28 if (IID_IUnknown == riid || IID_IDispatch == riid)
29 { 29 {
30 *ppvObj = (LPVOID)this; 30 *ppvObj = (LPVOID)this;
31 return NOERROR; 31 return NOERROR;
32 } 32 }
33 33
34 return E_NOINTERFACE; 34 return E_NOINTERFACE;
35 } 35 }
36 36
37 37
38 /* 38 /*
39 Since CPluginUserSettings is not allocated on the heap, 'AddRef' and 'Release' d on't need reference counting, 39 Since CPluginUserSettings is not allocated on the heap, 'AddRef' and 'Release' d on't need reference counting,
40 because CPluginUserSettings won't be deleted when reference counter == 0 40 because CPluginUserSettings won't be deleted when reference counter == 0
41 */ 41 */
42 42
43 ULONG __stdcall CPluginUserSettings::AddRef() 43 ULONG __stdcall CPluginUserSettings::AddRef()
44 { 44 {
45 return 1; 45 return 1;
46 } 46 }
47 47
48 48
49 ULONG __stdcall CPluginUserSettings::Release() 49 ULONG __stdcall CPluginUserSettings::Release()
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 127
128 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult, 128 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult,
129 EXCEPINFO* pExcepinfo, UINT* pArgErr) 129 EXCEPINFO* pExcepinfo, UINT* pArgErr)
130 { 130 {
131 if (!pDispparams) 131 if (!pDispparams)
132 return E_POINTER; 132 return E_POINTER;
133 133
134 if (!pExcepinfo) 134 if (!pExcepinfo)
135 return E_POINTER; 135 return E_POINTER;
136 136
137 if (pDispparams->cNamedArgs) 137 if (pDispparams->cNamedArgs)
138 return DISP_E_NONAMEDARGS; 138 return DISP_E_NONAMEDARGS;
139 139
140 CPluginSettings* settings = CPluginSettings::GetInstance(); 140 CPluginSettings* settings = CPluginSettings::GetInstance();
141 141
142 if (dispidMember < 0 || dispidMember >= countof(s_Methods)) 142 if (dispidMember < 0 || dispidMember >= countof(s_Methods))
143 return DISP_E_BADINDEX; 143 return DISP_E_BADINDEX;
144 144
145 const CString& method = s_Methods[dispidMember]; 145 const CString& method = s_Methods[dispidMember];
146 146
147 if (s_GetMessage == method) 147 if (s_GetMessage == method)
148 { 148 {
149 if (1 != pDispparams->cArgs) 149 if (1 != pDispparams->cArgs)
150 return DISP_E_BADPARAMCOUNT; 150 return DISP_E_BADPARAMCOUNT;
151 151
152 if (VT_BSTR != pDispparams->rgvarg[0].vt) 152 if (VT_BSTR != pDispparams->rgvarg[0].vt)
153 return DISP_E_TYPEMISMATCH; 153 return DISP_E_TYPEMISMATCH;
154 154
155 if (pVarResult) 155 if (pVarResult)
156 { 156 {
157 CComBSTR key = pDispparams->rgvarg[0].bstrVal; 157 CComBSTR key = pDispparams->rgvarg[0].bstrVal;
158 CStringW message = sGetMessage((BSTR)key); 158 CStringW message = sGetMessage((BSTR)key);
159 159
160 pVarResult->vt = VT_BSTR; 160 pVarResult->vt = VT_BSTR;
161 pVarResult->bstrVal = SysAllocString(message); 161 pVarResult->bstrVal = SysAllocString(message);
162 } 162 }
163 } 163 }
164 else if (s_GetLanguageCount == method) 164 else if (s_GetLanguageCount == method)
165 { 165 {
166 if (pDispparams->cArgs) 166 if (pDispparams->cArgs)
167 return DISP_E_BADPARAMCOUNT; 167 return DISP_E_BADPARAMCOUNT;
168 168
169 if (pVarResult) 169 if (pVarResult)
170 { 170 {
171 std::map<CString, CString> languageList = settings->GetFilterLanguageTitle List(); 171 std::map<CString, CString> languageList = settings->GetFilterLanguageTitle List();
172 172
173 pVarResult->vt = VT_I4; 173 pVarResult->vt = VT_I4;
174 pVarResult->lVal = languageList.size(); 174 pVarResult->lVal = languageList.size();
175 } 175 }
176 } 176 }
177 else if (s_GetLanguageByIndex == method) 177 else if (s_GetLanguageByIndex == method)
178 { 178 {
179 if (1 != pDispparams->cArgs) 179 if (1 != pDispparams->cArgs)
180 return DISP_E_BADPARAMCOUNT; 180 return DISP_E_BADPARAMCOUNT;
181 181
182 if (VT_I4 != pDispparams->rgvarg[0].vt) 182 if (VT_I4 != pDispparams->rgvarg[0].vt)
183 return DISP_E_TYPEMISMATCH; 183 return DISP_E_TYPEMISMATCH;
(...skipping 14 matching lines...) Expand all
198 { 198 {
199 if (curIndx == indx) 199 if (curIndx == indx)
200 { 200 {
201 language = it->first; 201 language = it->first;
202 break; 202 break;
203 } 203 }
204 204
205 curIndx++; 205 curIndx++;
206 } 206 }
207 207
208 pVarResult->vt = VT_BSTR; 208 pVarResult->vt = VT_BSTR;
209 pVarResult->bstrVal = SysAllocString(language); 209 pVarResult->bstrVal = SysAllocString(language);
210 } 210 }
211 } 211 }
212 else if (s_GetLanguageTitleByIndex == method) 212 else if (s_GetLanguageTitleByIndex == method)
213 { 213 {
214 if (1 != pDispparams->cArgs) 214 if (1 != pDispparams->cArgs)
215 return DISP_E_BADPARAMCOUNT; 215 return DISP_E_BADPARAMCOUNT;
216 216
217 if (VT_I4 != pDispparams->rgvarg[0].vt) 217 if (VT_I4 != pDispparams->rgvarg[0].vt)
218 return DISP_E_TYPEMISMATCH; 218 return DISP_E_TYPEMISMATCH;
(...skipping 14 matching lines...) Expand all
233 { 233 {
234 if (curIndx == indx) 234 if (curIndx == indx)
235 { 235 {
236 languageTitle = it->second; 236 languageTitle = it->second;
237 break; 237 break;
238 } 238 }
239 239
240 curIndx++; 240 curIndx++;
241 } 241 }
242 242
243 pVarResult->vt = VT_BSTR; 243 pVarResult->vt = VT_BSTR;
244 pVarResult->bstrVal = SysAllocString(languageTitle); 244 pVarResult->bstrVal = SysAllocString(languageTitle);
245 } 245 }
246 } 246 }
247 else if (s_SetLanguage == method) 247 else if (s_SetLanguage == method)
248 { 248 {
249 if (1 != pDispparams->cArgs) 249 if (1 != pDispparams->cArgs)
250 return DISP_E_BADPARAMCOUNT; 250 return DISP_E_BADPARAMCOUNT;
251 251
252 if (VT_BSTR != pDispparams->rgvarg[0].vt) 252 if (VT_BSTR != pDispparams->rgvarg[0].vt)
253 return DISP_E_TYPEMISMATCH; 253 return DISP_E_TYPEMISMATCH;
254 254
255 CComBSTR url = pDispparams->rgvarg[0].bstrVal; 255 CComBSTR url = pDispparams->rgvarg[0].bstrVal;
256 256
257 settings->SetSubscription((BSTR)url); 257 settings->SetSubscription((BSTR)url);
258 } 258 }
259 else if (s_GetLanguage == method) 259 else if (s_GetLanguage == method)
260 { 260 {
261 if (pDispparams->cArgs) 261 if (pDispparams->cArgs)
262 return DISP_E_BADPARAMCOUNT; 262 return DISP_E_BADPARAMCOUNT;
263 263
264 if (pVarResult) 264 if (pVarResult)
265 { 265 {
266 CString url = settings->GetSubscription(); 266 CString url = settings->GetSubscription();
267 267
268 pVarResult->vt = VT_BSTR; 268 pVarResult->vt = VT_BSTR;
269 pVarResult->bstrVal = SysAllocString(url); 269 pVarResult->bstrVal = SysAllocString(url);
270 } 270 }
271 } 271 }
272 else if (s_GetWhitelistDomains == method) 272 else if (s_GetWhitelistDomains == method)
273 { 273 {
274 if (pDispparams->cArgs) 274 if (pDispparams->cArgs)
275 return DISP_E_BADPARAMCOUNT; 275 return DISP_E_BADPARAMCOUNT;
276 276
277 if (pVarResult) 277 if (pVarResult)
278 { 278 {
279 std::vector<std::string> whiteList = settings->GetWhiteListedDomainList(); 279 std::vector<std::string> whiteList = settings->GetWhiteListedDomainList();
280 CString sWhiteList; 280 CString sWhiteList;
281 for (int i = 0; i < whiteList.size(); i++) 281 for (size_t i = 0; i < whiteList.size(); i++)
282 { 282 {
283 if (!sWhiteList.IsEmpty()) 283 if (!sWhiteList.IsEmpty())
284 { 284 {
285 sWhiteList += ','; 285 sWhiteList += ',';
286 } 286 }
287 sWhiteList += CString(CA2W(whiteList[i].c_str(), CP_UTF8)); 287 sWhiteList += CString(CA2W(whiteList[i].c_str(), CP_UTF8));
288 } 288 }
289 289
290 pVarResult->vt = VT_BSTR; 290 pVarResult->vt = VT_BSTR;
291 pVarResult->bstrVal = SysAllocString(sWhiteList); 291 pVarResult->bstrVal = SysAllocString(sWhiteList);
292 } 292 }
293 } 293 }
294 else if (s_AddWhitelistDomain == method) 294 else if (s_AddWhitelistDomain == method)
295 { 295 {
296 if (1 != pDispparams->cArgs) 296 if (1 != pDispparams->cArgs)
297 return DISP_E_BADPARAMCOUNT; 297 return DISP_E_BADPARAMCOUNT;
298 298
299 if (VT_BSTR != pDispparams->rgvarg[0].vt) 299 if (VT_BSTR != pDispparams->rgvarg[0].vt)
300 return DISP_E_TYPEMISMATCH; 300 return DISP_E_TYPEMISMATCH;
301 301
302 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 302 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
303 if (domain.Length()) 303 if (domain.Length())
304 { 304 {
305 settings->AddWhiteListedDomain((BSTR)domain); 305 settings->AddWhiteListedDomain((BSTR)domain);
306 } 306 }
307 } 307 }
308 else if (s_RemoveWhitelistDomain == method) 308 else if (s_RemoveWhitelistDomain == method)
309 { 309 {
310 if (1 != pDispparams->cArgs) 310 if (1 != pDispparams->cArgs)
311 return DISP_E_BADPARAMCOUNT; 311 return DISP_E_BADPARAMCOUNT;
312 312
313 if (VT_BSTR != pDispparams->rgvarg[0].vt) 313 if (VT_BSTR != pDispparams->rgvarg[0].vt)
314 return DISP_E_TYPEMISMATCH; 314 return DISP_E_TYPEMISMATCH;
315 315
316 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 316 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
317 if (settings->IsWhiteListedDomain((BSTR)domain)) 317 if (settings->IsWhiteListedDomain((BSTR)domain))
318 { 318 {
319 settings->AddWhiteListedDomain((BSTR)domain); 319 settings->AddWhiteListedDomain((BSTR)domain);
320 CPluginClient::GetInstance()->ClearWhiteListCache(); 320 CPluginClient::GetInstance()->ClearWhiteListCache();
321 } 321 }
322 } 322 }
323 else 323 else
324 return DISP_E_MEMBERNOTFOUND; 324 return DISP_E_MEMBERNOTFOUND;
325 325
326 return S_OK; 326 return S_OK;
327 } 327 }
328 328
OLDNEW

Powered by Google App Engine
This is Rietveld