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: Created Nov. 20, 2015, 6:37 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
« src/plugin/PluginSettings.cpp ('K') | « 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
Eric 2015/11/20 18:46:04 Inlined.
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(ToUtf8String(std::wstring(se ction)), ToUtf8String(std::wstring(key)));
sergei 2015/11/25 09:27:08 Nit: strictly speaking we should use the length ob
Eric 2015/11/25 17:31:02 Done. There are a few other places where we need
sergei 2015/11/26 11:06:18 Sure, feel free to create the issue for it.
190 187
191 pVarResult->vt = VT_BSTR; 188 pVarResult->vt = VT_BSTR;
192 pVarResult->bstrVal = SysAllocString(message); 189 pVarResult->bstrVal = SysAllocString(message.c_str());
193 } 190 }
194 } 191 }
195 break; 192 break;
196 case dispatchID_GetLanguageCount: 193 case dispatchID_GetLanguageCount:
197 { 194 {
198 if (pDispparams->cArgs != 0) 195 if (pDispparams->cArgs != 0)
199 { 196 {
200 return DISP_E_BADPARAMCOUNT; 197 return DISP_E_BADPARAMCOUNT;
201 } 198 }
202 if (pVarResult) 199 if (pVarResult)
203 { 200 {
204 std::map<CString, CString> languageList = settings->GetFilterLanguageT itleList(); 201 auto languageList = settings->GetFilterLanguageTitleList();
205 202
206 pVarResult->vt = VT_I4; 203 pVarResult->vt = VT_I4;
207 pVarResult->lVal = static_cast<LONG>(languageList.size()); 204 pVarResult->lVal = static_cast<LONG>(languageList.size());
208 } 205 }
209 } 206 }
210 break; 207 break;
211 case dispatchID_GetLanguageByIndex: 208 case dispatchID_GetLanguageByIndex:
212 { 209 {
213 if (pDispparams->cArgs != 1) 210 if (pDispparams->cArgs != 1)
214 { 211 {
215 return DISP_E_BADPARAMCOUNT; 212 return DISP_E_BADPARAMCOUNT;
216 } 213 }
217 if (pDispparams->rgvarg[0].vt != VT_I4) 214 if (pDispparams->rgvarg[0].vt != VT_I4)
218 { 215 {
219 return DISP_E_TYPEMISMATCH; 216 return DISP_E_TYPEMISMATCH;
220 } 217 }
221 if (pVarResult) 218 if (pVarResult)
222 { 219 {
223 int index = pDispparams->rgvarg[0].lVal; 220 int index = pDispparams->rgvarg[0].lVal;
224 221
225 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 222 auto languageTitleList = settings->GetFilterLanguageTitleList();
226 223
227 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) ) 224 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
228 return DISP_E_EXCEPTION; 225 return DISP_E_BADINDEX;
Oleksandr 2015/11/25 03:22:07 Nit: unrelated change.
sergei 2015/11/25 09:27:09 I would not mind to commit it but it's likely not
Eric 2015/11/25 17:31:02 It fixes a defect, actually. Rather than bicker ov
229 226
230 CString language; 227 std::wstring language;
231 228
232 int loopIndex = 0; 229 int loopIndex = 0;
233 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it) 230 for (auto it = languageTitleList.begin(); it != languageTitleList.end( ); ++it)
234 { 231 {
235 if (loopIndex == index) 232 if (loopIndex == index)
236 { 233 {
237 language = it->first; 234 language = it->first;
238 break; 235 break;
239 } 236 }
240 ++loopIndex; 237 ++loopIndex;
241 } 238 }
242 239
243 pVarResult->vt = VT_BSTR; 240 pVarResult->vt = VT_BSTR;
244 pVarResult->bstrVal = SysAllocString(language); 241 pVarResult->bstrVal = SysAllocString(language.c_str());
245 } 242 }
246 } 243 }
247 break; 244 break;
248 case dispatchID_GetLanguageTitleByIndex: 245 case dispatchID_GetLanguageTitleByIndex:
249 { 246 {
250 if (pDispparams->cArgs != 1) 247 if (pDispparams->cArgs != 1)
251 { 248 {
252 return DISP_E_BADPARAMCOUNT; 249 return DISP_E_BADPARAMCOUNT;
253 } 250 }
254 if (pDispparams->rgvarg[0].vt != VT_I4) 251 if (pDispparams->rgvarg[0].vt != VT_I4)
255 { 252 {
256 return DISP_E_TYPEMISMATCH; 253 return DISP_E_TYPEMISMATCH;
257 } 254 }
258 if (pVarResult) 255 if (pVarResult)
259 { 256 {
260 int index = pDispparams->rgvarg[0].lVal; 257 int index = pDispparams->rgvarg[0].lVal;
261 258
262 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 259 auto languageTitleList = settings->GetFilterLanguageTitleList();
263 260
264 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) ) 261 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
265 return DISP_E_EXCEPTION; 262 return DISP_E_BADINDEX;
Oleksandr 2015/11/25 03:22:08 Nit: unrelated change.
266 263
267 CString languageTitle; 264 std::wstring languageTitle;
268
269 int loopIndex = 0; 265 int loopIndex = 0;
270 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it) 266 for (auto it = languageTitleList.begin(); it != languageTitleList.end( ); ++it)
271 { 267 {
272 if (loopIndex == index) 268 if (loopIndex == index)
273 { 269 {
274 languageTitle = it->second; 270 languageTitle = it->second;
275 break; 271 break;
276 } 272 }
277 loopIndex++; 273 loopIndex++;
278 } 274 }
279 275
280 pVarResult->vt = VT_BSTR; 276 pVarResult->vt = VT_BSTR;
281 pVarResult->bstrVal = SysAllocString(languageTitle); 277 pVarResult->bstrVal = SysAllocString(languageTitle.c_str());
282 } 278 }
283 } 279 }
284 break; 280 break;
285 case dispatchID_SetLanguage: 281 case dispatchID_SetLanguage:
286 { 282 {
287 if (pDispparams->cArgs != 1) 283 if (pDispparams->cArgs != 1)
288 { 284 {
289 return DISP_E_BADPARAMCOUNT; 285 return DISP_E_BADPARAMCOUNT;
290 } 286 }
291 if (pDispparams->rgvarg[0].vt != VT_BSTR) 287 if (pDispparams->rgvarg[0].vt != VT_BSTR)
292 { 288 {
293 return DISP_E_TYPEMISMATCH; 289 return DISP_E_TYPEMISMATCH;
294 } 290 }
295 CComBSTR url = pDispparams->rgvarg[0].bstrVal; 291 CComBSTR url = pDispparams->rgvarg[0].bstrVal;
296 settings->SetSubscription((BSTR)url); 292 settings->SetSubscription((BSTR)url);
297 } 293 }
298 break; 294 break;
299 case dispatchID_GetLanguage: 295 case dispatchID_GetLanguage:
300 { 296 {
301 if (pDispparams->cArgs != 0) 297 if (pDispparams->cArgs != 0)
302 { 298 {
303 return DISP_E_BADPARAMCOUNT; 299 return DISP_E_BADPARAMCOUNT;
304 } 300 }
305 if (pVarResult) 301 if (pVarResult)
306 { 302 {
307 CString url = settings->GetSubscription(); 303 std::wstring url = settings->GetSubscription();
308 pVarResult->vt = VT_BSTR; 304 pVarResult->vt = VT_BSTR;
309 pVarResult->bstrVal = SysAllocString(url); 305 pVarResult->bstrVal = SysAllocString(url.c_str());
310 } 306 }
311 } 307 }
312 break; 308 break;
313 case dispatchID_GetWhitelistDomains: 309 case dispatchID_GetWhitelistDomains:
314 { 310 {
315 if (pDispparams->cArgs != 0) 311 if (pDispparams->cArgs != 0)
316 { 312 {
317 return DISP_E_BADPARAMCOUNT; 313 return DISP_E_BADPARAMCOUNT;
318 } 314 }
319 if (pVarResult) 315 if (pVarResult)
320 { 316 {
321 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainLi st(); 317 auto whiteListDomains = settings->GetWhiteListedDomainList();
322 CString sWhiteList; 318 std::wstring commaSeparatedDomains;
323 for (size_t i = 0; i < whiteList.size(); i++) 319 for (size_t i = 0; i < whiteListDomains.size(); i++)
324 { 320 {
325 if (!sWhiteList.IsEmpty()) 321 if (!commaSeparatedDomains.empty())
326 { 322 {
327 sWhiteList += ','; 323 commaSeparatedDomains += ',';
328 } 324 }
329 sWhiteList += CString(whiteList[i].c_str()); 325 commaSeparatedDomains += whiteListDomains[i];
330 } 326 }
331 pVarResult->vt = VT_BSTR; 327 pVarResult->vt = VT_BSTR;
332 pVarResult->bstrVal = SysAllocString(sWhiteList); 328 pVarResult->bstrVal = SysAllocString(commaSeparatedDomains.c_str());
333 } 329 }
334 } 330 }
335 break; 331 break;
336 case dispatchID_AddWhitelistDomain: 332 case dispatchID_AddWhitelistDomain:
337 { 333 {
338 if (pDispparams->cArgs != 1) 334 if (pDispparams->cArgs != 1)
339 { 335 {
340 return DISP_E_BADPARAMCOUNT; 336 return DISP_E_BADPARAMCOUNT;
341 } 337 }
342 if (pDispparams->rgvarg[0].vt != VT_BSTR) 338 if (pDispparams->rgvarg[0].vt != VT_BSTR)
(...skipping 13 matching lines...) Expand all
356 { 352 {
357 return DISP_E_BADPARAMCOUNT; 353 return DISP_E_BADPARAMCOUNT;
358 } 354 }
359 if (pDispparams->rgvarg[0].vt != VT_BSTR) 355 if (pDispparams->rgvarg[0].vt != VT_BSTR)
360 { 356 {
361 return DISP_E_TYPEMISMATCH; 357 return DISP_E_TYPEMISMATCH;
362 } 358 }
363 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 359 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
364 if (domain.Length()) 360 if (domain.Length())
365 { 361 {
366 settings->RemoveWhiteListedDomain((BSTR)domain); 362 settings->RemoveWhiteListedDomain(std::wstring(domain));
367 } 363 }
368 } 364 }
369 break; 365 break;
370 case dispatchID_GetAppLocale: 366 case dispatchID_GetAppLocale:
371 { 367 {
372 if (pDispparams->cArgs != 0) 368 if (pDispparams->cArgs != 0)
373 { 369 {
374 return DISP_E_BADPARAMCOUNT; 370 return DISP_E_BADPARAMCOUNT;
375 } 371 }
376 if (pVarResult) 372 if (pVarResult)
377 { 373 {
378 pVarResult->vt = VT_BSTR; 374 pVarResult->vt = VT_BSTR;
379 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); 375 pVarResult->bstrVal = SysAllocString(GetBrowserLanguage().c_str());
380 } 376 }
381 } 377 }
382 break; 378 break;
383 case dispatchID_GetDocumentationLink: 379 case dispatchID_GetDocumentationLink:
384 { 380 {
385 if (pDispparams->cArgs != 0) 381 if (pDispparams->cArgs != 0)
386 { 382 {
387 return DISP_E_BADPARAMCOUNT; 383 return DISP_E_BADPARAMCOUNT;
388 } 384 }
389 if (pVarResult) 385 if (pVarResult)
390 { 386 {
391 pVarResult->vt = VT_BSTR; 387 pVarResult->vt = VT_BSTR;
392 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()) ; 388 pVarResult->bstrVal = SysAllocString(CPluginClient::GetInstance()->Get DocumentationLink().c_str());
393 } 389 }
394 } 390 }
395 break; 391 break;
396 case dispatchID_IsAcceptableAdsEnabled: 392 case dispatchID_IsAcceptableAdsEnabled:
397 { 393 {
398 if (pDispparams->cArgs != 0) 394 if (pDispparams->cArgs != 0)
399 { 395 {
400 return DISP_E_BADPARAMCOUNT; 396 return DISP_E_BADPARAMCOUNT;
401 } 397 }
402 if (pVarResult) 398 if (pVarResult)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return DISP_E_MEMBERNOTFOUND; 441 return DISP_E_MEMBERNOTFOUND;
446 break; 442 break;
447 } 443 }
448 } 444 }
449 catch (...) 445 catch (...)
450 { 446 {
451 return E_FAIL; 447 return E_FAIL;
452 } 448 }
453 return S_OK; 449 return S_OK;
454 } 450 }
OLDNEW
« src/plugin/PluginSettings.cpp ('K') | « src/plugin/PluginSettings.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld