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

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

Issue 29330618: Issue #1234 - Eliminate CString from PluginSettings.* and PluginUserSettings.* (Closed)
Patch Set: address comments Created Nov. 25, 2015, 5:15 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
« no previous file with comments | « src/plugin/PluginSettings.cpp ('k') | no next file » | 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 "PluginUserSettings.h" 19 #include "PluginUserSettings.h"
20 #include "AdblockPlusClient.h" 20 #include "AdblockPlusClient.h"
21 #include "PluginSettings.h" 21 #include "PluginSettings.h"
22 #include "PluginSystem.h"
22 #include "../shared/Dictionary.h" 23 #include "../shared/Dictionary.h"
24 #include "../shared/Utils.h"
23 #include <unordered_map> 25 #include <unordered_map>
24 26
25 namespace 27 namespace
26 { 28 {
27 enum UserSettingsMethods 29 enum UserSettingsMethods
28 { 30 {
29 dispatchID_GetMessage = 0, 31 dispatchID_GetMessage = 0,
30 dispatchID_GetLanguageCount, 32 dispatchID_GetLanguageCount,
31 dispatchID_GetLanguageByIndex, 33 dispatchID_GetLanguageByIndex,
32 dispatchID_GetLanguageTitleByIndex, 34 dispatchID_GetLanguageTitleByIndex,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 145 }
144 *id = item->second; 146 *id = item->second;
145 } 147 }
146 catch (...) 148 catch (...)
147 { 149 {
148 return E_FAIL; 150 return E_FAIL;
149 } 151 }
150 return S_OK; 152 return S_OK;
151 } 153 }
152 154
153 CStringW sGetMessage(const CString& section, const CString& key)
154 {
155 Dictionary* dictionary = Dictionary::GetInstance();
156 return CStringW(dictionary->Lookup(std::string(CW2A(section)), std::string(CW2 A(key))).c_str());
157 }
158
159 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult, 155 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult,
160 EXCEPINFO* pExcepinfo, UINT* pArgErr) 156 EXCEPINFO* pExcepinfo, UINT* pArgErr)
161 { 157 {
162 try 158 try
163 { 159 {
164 if (!pDispparams) 160 if (!pDispparams)
165 { 161 {
166 return E_POINTER; 162 return E_POINTER;
167 } 163 }
168 if (pDispparams->cNamedArgs != 0) 164 if (pDispparams->cNamedArgs != 0)
(...skipping 10 matching lines...) Expand all
179 return DISP_E_BADPARAMCOUNT; 175 return DISP_E_BADPARAMCOUNT;
180 } 176 }
181 if (pDispparams->rgvarg[0].vt != VT_BSTR || pDispparams->rgvarg[1].vt != VT_BSTR) 177 if (pDispparams->rgvarg[0].vt != VT_BSTR || pDispparams->rgvarg[1].vt != VT_BSTR)
182 { 178 {
183 return DISP_E_TYPEMISMATCH; 179 return DISP_E_TYPEMISMATCH;
184 } 180 }
185 if (pVarResult) 181 if (pVarResult)
186 { 182 {
187 CComBSTR key = pDispparams->rgvarg[0].bstrVal; 183 CComBSTR key = pDispparams->rgvarg[0].bstrVal;
188 CComBSTR section = pDispparams->rgvarg[1].bstrVal; 184 CComBSTR section = pDispparams->rgvarg[1].bstrVal;
189 CStringW message = sGetMessage((BSTR)section, (BSTR)key); 185 Dictionary* dictionary = Dictionary::GetInstance();
186 std::wstring message = dictionary->Lookup(
187 ToUtf8String(std::wstring(section, ::SysStringLen(section))),
188 ToUtf8String(std::wstring(key, ::SysStringLen(key)))
189 );
190 190
191 pVarResult->vt = VT_BSTR; 191 pVarResult->vt = VT_BSTR;
192 pVarResult->bstrVal = SysAllocString(message); 192 pVarResult->bstrVal = SysAllocString(message.c_str());
193 } 193 }
194 } 194 }
195 break; 195 break;
196 case dispatchID_GetLanguageCount: 196 case dispatchID_GetLanguageCount:
197 { 197 {
198 if (pDispparams->cArgs != 0) 198 if (pDispparams->cArgs != 0)
199 { 199 {
200 return DISP_E_BADPARAMCOUNT; 200 return DISP_E_BADPARAMCOUNT;
201 } 201 }
202 if (pVarResult) 202 if (pVarResult)
203 { 203 {
204 std::map<CString, CString> languageList = settings->GetFilterLanguageT itleList(); 204 auto languageList = settings->GetFilterLanguageTitleList();
205 205
206 pVarResult->vt = VT_I4; 206 pVarResult->vt = VT_I4;
207 pVarResult->lVal = static_cast<LONG>(languageList.size()); 207 pVarResult->lVal = static_cast<LONG>(languageList.size());
208 } 208 }
209 } 209 }
210 break; 210 break;
211 case dispatchID_GetLanguageByIndex: 211 case dispatchID_GetLanguageByIndex:
212 { 212 {
213 if (pDispparams->cArgs != 1) 213 if (pDispparams->cArgs != 1)
214 { 214 {
215 return DISP_E_BADPARAMCOUNT; 215 return DISP_E_BADPARAMCOUNT;
216 } 216 }
217 if (pDispparams->rgvarg[0].vt != VT_I4) 217 if (pDispparams->rgvarg[0].vt != VT_I4)
218 { 218 {
219 return DISP_E_TYPEMISMATCH; 219 return DISP_E_TYPEMISMATCH;
220 } 220 }
221 if (pVarResult) 221 if (pVarResult)
222 { 222 {
223 int index = pDispparams->rgvarg[0].lVal; 223 int index = pDispparams->rgvarg[0].lVal;
224 224
225 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 225 auto languageTitleList = settings->GetFilterLanguageTitleList();
226 226
227 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) ) 227 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
228 return DISP_E_EXCEPTION; 228 return DISP_E_EXCEPTION;
229 229
230 CString language; 230 std::wstring language;
231 231
232 int loopIndex = 0; 232 int loopIndex = 0;
233 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it) 233 for (auto it = languageTitleList.begin(); it != languageTitleList.end( ); ++it)
234 { 234 {
235 if (loopIndex == index) 235 if (loopIndex == index)
236 { 236 {
237 language = it->first; 237 language = it->first;
238 break; 238 break;
239 } 239 }
240 ++loopIndex; 240 ++loopIndex;
241 } 241 }
242 242
243 pVarResult->vt = VT_BSTR; 243 pVarResult->vt = VT_BSTR;
244 pVarResult->bstrVal = SysAllocString(language); 244 pVarResult->bstrVal = SysAllocString(language.c_str());
245 } 245 }
246 } 246 }
247 break; 247 break;
248 case dispatchID_GetLanguageTitleByIndex: 248 case dispatchID_GetLanguageTitleByIndex:
249 { 249 {
250 if (pDispparams->cArgs != 1) 250 if (pDispparams->cArgs != 1)
251 { 251 {
252 return DISP_E_BADPARAMCOUNT; 252 return DISP_E_BADPARAMCOUNT;
253 } 253 }
254 if (pDispparams->rgvarg[0].vt != VT_I4) 254 if (pDispparams->rgvarg[0].vt != VT_I4)
255 { 255 {
256 return DISP_E_TYPEMISMATCH; 256 return DISP_E_TYPEMISMATCH;
257 } 257 }
258 if (pVarResult) 258 if (pVarResult)
259 { 259 {
260 int index = pDispparams->rgvarg[0].lVal; 260 int index = pDispparams->rgvarg[0].lVal;
261 261
262 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 262 auto languageTitleList = settings->GetFilterLanguageTitleList();
263 263
264 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) ) 264 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
265 return DISP_E_EXCEPTION; 265 return DISP_E_EXCEPTION;
266 266
267 CString languageTitle; 267 std::wstring languageTitle;
268
269 int loopIndex = 0; 268 int loopIndex = 0;
270 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it) 269 for (auto it = languageTitleList.begin(); it != languageTitleList.end( ); ++it)
271 { 270 {
272 if (loopIndex == index) 271 if (loopIndex == index)
273 { 272 {
274 languageTitle = it->second; 273 languageTitle = it->second;
275 break; 274 break;
276 } 275 }
277 loopIndex++; 276 loopIndex++;
278 } 277 }
279 278
280 pVarResult->vt = VT_BSTR; 279 pVarResult->vt = VT_BSTR;
281 pVarResult->bstrVal = SysAllocString(languageTitle); 280 pVarResult->bstrVal = SysAllocString(languageTitle.c_str());
282 } 281 }
283 } 282 }
284 break; 283 break;
285 case dispatchID_SetLanguage: 284 case dispatchID_SetLanguage:
286 { 285 {
287 if (pDispparams->cArgs != 1) 286 if (pDispparams->cArgs != 1)
288 { 287 {
289 return DISP_E_BADPARAMCOUNT; 288 return DISP_E_BADPARAMCOUNT;
290 } 289 }
291 if (pDispparams->rgvarg[0].vt != VT_BSTR) 290 if (pDispparams->rgvarg[0].vt != VT_BSTR)
292 { 291 {
293 return DISP_E_TYPEMISMATCH; 292 return DISP_E_TYPEMISMATCH;
294 } 293 }
295 CComBSTR url = pDispparams->rgvarg[0].bstrVal; 294 CComBSTR url = pDispparams->rgvarg[0].bstrVal;
296 settings->SetSubscription((BSTR)url); 295 settings->SetSubscription((BSTR)url);
297 } 296 }
298 break; 297 break;
299 case dispatchID_GetLanguage: 298 case dispatchID_GetLanguage:
300 { 299 {
301 if (pDispparams->cArgs != 0) 300 if (pDispparams->cArgs != 0)
302 { 301 {
303 return DISP_E_BADPARAMCOUNT; 302 return DISP_E_BADPARAMCOUNT;
304 } 303 }
305 if (pVarResult) 304 if (pVarResult)
306 { 305 {
307 CString url = settings->GetSubscription(); 306 std::wstring url = settings->GetSubscription();
308 pVarResult->vt = VT_BSTR; 307 pVarResult->vt = VT_BSTR;
309 pVarResult->bstrVal = SysAllocString(url); 308 pVarResult->bstrVal = SysAllocString(url.c_str());
310 } 309 }
311 } 310 }
312 break; 311 break;
313 case dispatchID_GetWhitelistDomains: 312 case dispatchID_GetWhitelistDomains:
314 { 313 {
315 if (pDispparams->cArgs != 0) 314 if (pDispparams->cArgs != 0)
316 { 315 {
317 return DISP_E_BADPARAMCOUNT; 316 return DISP_E_BADPARAMCOUNT;
318 } 317 }
319 if (pVarResult) 318 if (pVarResult)
320 { 319 {
321 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainLi st(); 320 auto whiteListDomains = settings->GetWhiteListedDomainList();
322 CString sWhiteList; 321 std::wstring commaSeparatedDomains;
323 for (size_t i = 0; i < whiteList.size(); i++) 322 for (size_t i = 0; i < whiteListDomains.size(); i++)
324 { 323 {
325 if (!sWhiteList.IsEmpty()) 324 if (!commaSeparatedDomains.empty())
326 { 325 {
327 sWhiteList += ','; 326 commaSeparatedDomains += ',';
328 } 327 }
329 sWhiteList += CString(whiteList[i].c_str()); 328 commaSeparatedDomains += whiteListDomains[i];
330 } 329 }
331 pVarResult->vt = VT_BSTR; 330 pVarResult->vt = VT_BSTR;
332 pVarResult->bstrVal = SysAllocString(sWhiteList); 331 pVarResult->bstrVal = SysAllocString(commaSeparatedDomains.c_str());
333 } 332 }
334 } 333 }
335 break; 334 break;
336 case dispatchID_AddWhitelistDomain: 335 case dispatchID_AddWhitelistDomain:
337 { 336 {
338 if (pDispparams->cArgs != 1) 337 if (pDispparams->cArgs != 1)
339 { 338 {
340 return DISP_E_BADPARAMCOUNT; 339 return DISP_E_BADPARAMCOUNT;
341 } 340 }
342 if (pDispparams->rgvarg[0].vt != VT_BSTR) 341 if (pDispparams->rgvarg[0].vt != VT_BSTR)
(...skipping 13 matching lines...) Expand all
356 { 355 {
357 return DISP_E_BADPARAMCOUNT; 356 return DISP_E_BADPARAMCOUNT;
358 } 357 }
359 if (pDispparams->rgvarg[0].vt != VT_BSTR) 358 if (pDispparams->rgvarg[0].vt != VT_BSTR)
360 { 359 {
361 return DISP_E_TYPEMISMATCH; 360 return DISP_E_TYPEMISMATCH;
362 } 361 }
363 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 362 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
364 if (domain.Length()) 363 if (domain.Length())
365 { 364 {
366 settings->RemoveWhiteListedDomain((BSTR)domain); 365 settings->RemoveWhiteListedDomain(std::wstring(domain));
367 } 366 }
368 } 367 }
369 break; 368 break;
370 case dispatchID_GetAppLocale: 369 case dispatchID_GetAppLocale:
371 { 370 {
372 if (pDispparams->cArgs != 0) 371 if (pDispparams->cArgs != 0)
373 { 372 {
374 return DISP_E_BADPARAMCOUNT; 373 return DISP_E_BADPARAMCOUNT;
375 } 374 }
376 if (pVarResult) 375 if (pVarResult)
377 { 376 {
378 pVarResult->vt = VT_BSTR; 377 pVarResult->vt = VT_BSTR;
379 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); 378 pVarResult->bstrVal = SysAllocString(GetBrowserLanguage().c_str());
380 } 379 }
381 } 380 }
382 break; 381 break;
383 case dispatchID_GetDocumentationLink: 382 case dispatchID_GetDocumentationLink:
384 { 383 {
385 if (pDispparams->cArgs != 0) 384 if (pDispparams->cArgs != 0)
386 { 385 {
387 return DISP_E_BADPARAMCOUNT; 386 return DISP_E_BADPARAMCOUNT;
388 } 387 }
389 if (pVarResult) 388 if (pVarResult)
390 { 389 {
391 pVarResult->vt = VT_BSTR; 390 pVarResult->vt = VT_BSTR;
392 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()) ; 391 pVarResult->bstrVal = SysAllocString(CPluginClient::GetInstance()->Get DocumentationLink().c_str());
393 } 392 }
394 } 393 }
395 break; 394 break;
396 case dispatchID_IsAcceptableAdsEnabled: 395 case dispatchID_IsAcceptableAdsEnabled:
397 { 396 {
398 if (pDispparams->cArgs != 0) 397 if (pDispparams->cArgs != 0)
399 { 398 {
400 return DISP_E_BADPARAMCOUNT; 399 return DISP_E_BADPARAMCOUNT;
401 } 400 }
402 if (pVarResult) 401 if (pVarResult)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return DISP_E_MEMBERNOTFOUND; 444 return DISP_E_MEMBERNOTFOUND;
446 break; 445 break;
447 } 446 }
448 } 447 }
449 catch (...) 448 catch (...)
450 { 449 {
451 return E_FAIL; 450 return E_FAIL;
452 } 451 }
453 return S_OK; 452 return S_OK;
454 } 453 }
OLDNEW
« no previous file with comments | « src/plugin/PluginSettings.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld