LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://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 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
18 #include "PluginUserSettings.h" | 19 #include "PluginUserSettings.h" |
19 #include <algorithm> | 20 #include <algorithm> |
20 #include "PluginSettings.h" | 21 #include "PluginSettings.h" |
21 #include "PluginClient.h" | 22 #include "PluginClient.h" |
22 #include "../shared/Dictionary.h" | 23 #include "../shared/Dictionary.h" |
23 #include <unordered_map> | 24 #include <unordered_map> |
24 | 25 |
25 namespace | 26 namespace |
26 { | 27 { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 81 |
81 // ENTRY POINT | 82 // ENTRY POINT |
82 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) | 83 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) |
83 { | 84 { |
84 if (!ppvObj) | 85 if (!ppvObj) |
85 { | 86 { |
86 return E_POINTER; | 87 return E_POINTER; |
87 } | 88 } |
88 if (riid == IID_IUnknown || riid == IID_IDispatch) // GUID comparison does not
throw | 89 if (riid == IID_IUnknown || riid == IID_IDispatch) // GUID comparison does not
throw |
89 { | 90 { |
90 *ppvObj = static_cast<void *>(this); | 91 *ppvObj = static_cast<void*>(this); |
91 return S_OK; | 92 return S_OK; |
92 } | 93 } |
93 return E_NOINTERFACE; | 94 return E_NOINTERFACE; |
94 } | 95 } |
95 | 96 |
96 /** | 97 /** |
97 * \par Limitation | 98 * \par Limitation |
98 * CPluginUserSettings is not allocated on the heap. | 99 * CPluginUserSettings is not allocated on the heap. |
99 * It appears only as a member variable in CPluginTabBase. | 100 * It appears only as a member variable in CPluginTabBase. |
100 * 'AddRef' and 'Release' don't need reference counting because they don't pre
sent COM factories. | 101 * 'AddRef' and 'Release' don't need reference counting because they don't pre
sent COM factories. |
(...skipping 29 matching lines...) Expand all Loading... |
130 { | 131 { |
131 if (!name || !id) | 132 if (!name || !id) |
132 { | 133 { |
133 return E_POINTER; | 134 return E_POINTER; |
134 } | 135 } |
135 if (count != 1) | 136 if (count != 1) |
136 { | 137 { |
137 return E_FAIL; | 138 return E_FAIL; |
138 } | 139 } |
139 auto item = methodIndex.find(*name); // unordered_map::find is not declared
noexcept | 140 auto item = methodIndex.find(*name); // unordered_map::find is not declared
noexcept |
140 if (item==methodIndex.end()) | 141 if (item == methodIndex.end()) |
141 { | 142 { |
142 return DISP_E_UNKNOWNNAME; | 143 return DISP_E_UNKNOWNNAME; |
143 } | 144 } |
144 *id = item->second; | 145 *id = item->second; |
145 } | 146 } |
146 catch (...) | 147 catch (...) |
147 { | 148 { |
148 return E_FAIL; | 149 return E_FAIL; |
149 } | 150 } |
150 return S_OK; | 151 return S_OK; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 pVarResult->lVal = static_cast<LONG>(languageList.size()); | 208 pVarResult->lVal = static_cast<LONG>(languageList.size()); |
208 } | 209 } |
209 } | 210 } |
210 break; | 211 break; |
211 case dispatchID_GetLanguageByIndex: | 212 case dispatchID_GetLanguageByIndex: |
212 { | 213 { |
213 if (pDispparams->cArgs != 1) | 214 if (pDispparams->cArgs != 1) |
214 { | 215 { |
215 return DISP_E_BADPARAMCOUNT; | 216 return DISP_E_BADPARAMCOUNT; |
216 } | 217 } |
217 if (VT_I4 != pDispparams->rgvarg[0].vt) | 218 if (pDispparams->rgvarg[0].vt != VT_I4) |
218 { | 219 { |
219 return DISP_E_TYPEMISMATCH; | 220 return DISP_E_TYPEMISMATCH; |
220 } | 221 } |
221 if (pVarResult) | 222 if (pVarResult) |
222 { | 223 { |
223 int indx = pDispparams->rgvarg[0].lVal; | 224 int index = pDispparams->rgvarg[0].lVal; |
224 | 225 |
225 std::map<CString, CString> languageTitleList = settings->GetFilterLang
uageTitleList(); | 226 std::map<CString, CString> languageTitleList = settings->GetFilterLang
uageTitleList(); |
226 | 227 |
227 if (indx < 0 || indx >= (int)languageTitleList.size()) | 228 if (index < 0 || index >= static_cast<int>(languageTitleList.size())
) |
228 return DISP_E_EXCEPTION; | 229 return DISP_E_EXCEPTION; |
229 | 230 |
230 CString language; | 231 CString language; |
231 | 232 |
232 int curIndx = 0; | 233 int loopIndex = 0; |
233 for(std::map<CString, CString>::const_iterator it = languageTitleList.
begin(); it != languageTitleList.end(); ++it) | 234 for (std::map<CString, CString>::const_iterator it = languageTitleList
.begin(); it != languageTitleList.end(); ++it) |
234 { | 235 { |
235 if (curIndx == indx) | 236 if (loopIndex == index) |
236 { | 237 { |
237 language = it->first; | 238 language = it->first; |
238 break; | 239 break; |
239 } | 240 } |
240 curIndx++; | 241 ++loopIndex; |
241 } | 242 } |
242 | 243 |
243 pVarResult->vt = VT_BSTR; | 244 pVarResult->vt = VT_BSTR; |
244 pVarResult->bstrVal = SysAllocString(language); | 245 pVarResult->bstrVal = SysAllocString(language); |
245 } | 246 } |
246 } | 247 } |
247 break; | 248 break; |
248 case dispatchID_GetLanguageTitleByIndex: | 249 case dispatchID_GetLanguageTitleByIndex: |
249 { | 250 { |
250 if (pDispparams->cArgs != 1) | 251 if (pDispparams->cArgs != 1) |
251 { | 252 { |
252 return DISP_E_BADPARAMCOUNT; | 253 return DISP_E_BADPARAMCOUNT; |
253 } | 254 } |
254 if (VT_I4 != pDispparams->rgvarg[0].vt) | 255 if (pDispparams->rgvarg[0].vt != VT_I4) |
255 { | 256 { |
256 return DISP_E_TYPEMISMATCH; | 257 return DISP_E_TYPEMISMATCH; |
257 } | 258 } |
258 if (pVarResult) | 259 if (pVarResult) |
259 { | 260 { |
260 int indx = pDispparams->rgvarg[0].lVal; | 261 int index = pDispparams->rgvarg[0].lVal; |
261 | 262 |
262 std::map<CString, CString> languageTitleList = settings->GetFilterLang
uageTitleList(); | 263 std::map<CString, CString> languageTitleList = settings->GetFilterLang
uageTitleList(); |
263 | 264 |
264 if (indx < 0 || indx >= (int)languageTitleList.size()) | 265 if (index < 0 || index >= static_cast<int>(languageTitleList.size())
) |
265 return DISP_E_EXCEPTION; | 266 return DISP_E_EXCEPTION; |
266 | 267 |
267 CString languageTitle; | 268 CString languageTitle; |
268 | 269 |
269 int curIndx = 0; | 270 int loopIndex = 0; |
270 for(std::map<CString, CString>::const_iterator it = languageTitleList.
begin(); it != languageTitleList.end(); ++it) | 271 for (std::map<CString, CString>::const_iterator it = languageTitleList
.begin(); it != languageTitleList.end(); ++it) |
271 { | 272 { |
272 if (curIndx == indx) | 273 if (loopIndex == index) |
273 { | 274 { |
274 languageTitle = it->second; | 275 languageTitle = it->second; |
275 break; | 276 break; |
276 } | 277 } |
277 curIndx++; | 278 loopIndex++; |
278 } | 279 } |
279 | 280 |
280 pVarResult->vt = VT_BSTR; | 281 pVarResult->vt = VT_BSTR; |
281 pVarResult->bstrVal = SysAllocString(languageTitle); | 282 pVarResult->bstrVal = SysAllocString(languageTitle); |
282 } | 283 } |
283 } | 284 } |
284 break; | 285 break; |
285 case dispatchID_SetLanguage: | 286 case dispatchID_SetLanguage: |
286 { | 287 { |
287 if (pDispparams->cArgs != 1) | 288 if (pDispparams->cArgs != 1) |
288 { | 289 { |
289 return DISP_E_BADPARAMCOUNT; | 290 return DISP_E_BADPARAMCOUNT; |
290 } | 291 } |
291 if (VT_BSTR != pDispparams->rgvarg[0].vt) | 292 if (pDispparams->rgvarg[0].vt != VT_BSTR) |
292 { | 293 { |
293 return DISP_E_TYPEMISMATCH; | 294 return DISP_E_TYPEMISMATCH; |
294 } | 295 } |
295 CComBSTR url = pDispparams->rgvarg[0].bstrVal; | 296 CComBSTR url = pDispparams->rgvarg[0].bstrVal; |
296 settings->SetSubscription((BSTR)url); | 297 settings->SetSubscription((BSTR)url); |
297 } | 298 } |
298 break; | 299 break; |
299 case dispatchID_GetLanguage: | 300 case dispatchID_GetLanguage: |
300 { | 301 { |
301 if (pDispparams->cArgs != 0) | 302 if (pDispparams->cArgs != 0) |
(...skipping 30 matching lines...) Expand all Loading... |
332 pVarResult->bstrVal = SysAllocString(sWhiteList); | 333 pVarResult->bstrVal = SysAllocString(sWhiteList); |
333 } | 334 } |
334 } | 335 } |
335 break; | 336 break; |
336 case dispatchID_AddWhitelistDomain: | 337 case dispatchID_AddWhitelistDomain: |
337 { | 338 { |
338 if (pDispparams->cArgs != 1) | 339 if (pDispparams->cArgs != 1) |
339 { | 340 { |
340 return DISP_E_BADPARAMCOUNT; | 341 return DISP_E_BADPARAMCOUNT; |
341 } | 342 } |
342 if (VT_BSTR != pDispparams->rgvarg[0].vt) | 343 if (pDispparams->rgvarg[0].vt != VT_BSTR) |
343 { | 344 { |
344 return DISP_E_TYPEMISMATCH; | 345 return DISP_E_TYPEMISMATCH; |
345 } | 346 } |
346 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; | 347 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; |
347 if (domain.Length()) | 348 if (domain.Length()) |
348 { | 349 { |
349 settings->AddWhiteListedDomain((BSTR)domain); | 350 settings->AddWhiteListedDomain((BSTR)domain); |
350 } | 351 } |
351 } | 352 } |
352 break; | 353 break; |
353 case dispatchID_RemoveWhitelistDomain: | 354 case dispatchID_RemoveWhitelistDomain: |
354 { | 355 { |
355 if (pDispparams->cArgs != 1) | 356 if (pDispparams->cArgs != 1) |
356 { | 357 { |
357 return DISP_E_BADPARAMCOUNT; | 358 return DISP_E_BADPARAMCOUNT; |
358 } | 359 } |
359 if (VT_BSTR != pDispparams->rgvarg[0].vt) | 360 if (pDispparams->rgvarg[0].vt != VT_BSTR) |
360 { | 361 { |
361 return DISP_E_TYPEMISMATCH; | 362 return DISP_E_TYPEMISMATCH; |
362 } | 363 } |
363 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; | 364 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; |
364 if (domain.Length()) | 365 if (domain.Length()) |
365 { | 366 { |
366 settings->RemoveWhiteListedDomain((BSTR)domain); | 367 settings->RemoveWhiteListedDomain((BSTR)domain); |
367 } | 368 } |
368 } | 369 } |
369 break; | 370 break; |
370 case dispatchID_GetAppLocale: | 371 case dispatchID_GetAppLocale: |
371 { | 372 { |
372 if (pDispparams->cArgs != 0) | 373 if (pDispparams->cArgs != 0) |
373 { | 374 { |
374 return DISP_E_BADPARAMCOUNT; | 375 return DISP_E_BADPARAMCOUNT; |
375 } | 376 } |
376 pVarResult->vt = VT_BSTR; | 377 if (pVarResult) |
377 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); | 378 { |
| 379 pVarResult->vt = VT_BSTR; |
| 380 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); |
| 381 } |
378 } | 382 } |
379 break; | 383 break; |
380 case dispatchID_GetDocumentationLink: | 384 case dispatchID_GetDocumentationLink: |
381 { | 385 { |
382 if (pDispparams->cArgs != 0) | 386 if (pDispparams->cArgs != 0) |
383 { | 387 { |
384 return DISP_E_BADPARAMCOUNT; | 388 return DISP_E_BADPARAMCOUNT; |
385 } | 389 } |
386 pVarResult->vt = VT_BSTR; | 390 if (pVarResult) |
387 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()); | 391 { |
| 392 pVarResult->vt = VT_BSTR; |
| 393 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink())
; |
| 394 } |
388 } | 395 } |
389 break; | 396 break; |
390 case dispatchID_IsAcceptableAdsEnabled: | 397 case dispatchID_IsAcceptableAdsEnabled: |
391 { | 398 { |
392 if (pDispparams->cArgs != 0) | 399 if (pDispparams->cArgs != 0) |
393 { | 400 { |
394 return DISP_E_BADPARAMCOUNT; | 401 return DISP_E_BADPARAMCOUNT; |
395 } | 402 } |
396 pVarResult->vt = VT_BOOL; | 403 if (pVarResult) |
397 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEnabl
ed() ? VARIANT_TRUE : VARIANT_FALSE; | 404 { |
| 405 pVarResult->vt = VT_BOOL; |
| 406 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEna
bled() ? VARIANT_TRUE : VARIANT_FALSE; |
| 407 } |
398 } | 408 } |
399 break; | 409 break; |
400 case dispatchID_SetAcceptableAdsEnabled: | 410 case dispatchID_SetAcceptableAdsEnabled: |
401 { | 411 { |
402 if (pDispparams->cArgs != 1) | 412 if (pDispparams->cArgs != 1) |
403 { | 413 { |
404 return DISP_E_BADPARAMCOUNT; | 414 return DISP_E_BADPARAMCOUNT; |
405 } | 415 } |
406 if (pDispparams->rgvarg[0].vt != VT_BOOL) | 416 if (pDispparams->rgvarg[0].vt != VT_BOOL) |
407 { | 417 { |
(...skipping 10 matching lines...) Expand all Loading... |
418 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsu
rl", L"")); | 428 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsu
rl", L"")); |
419 } | 429 } |
420 } | 430 } |
421 break; | 431 break; |
422 case dispatchID_IsUpdate: | 432 case dispatchID_IsUpdate: |
423 { | 433 { |
424 if (pDispparams->cArgs != 0) | 434 if (pDispparams->cArgs != 0) |
425 { | 435 { |
426 return DISP_E_BADPARAMCOUNT; | 436 return DISP_E_BADPARAMCOUNT; |
427 } | 437 } |
428 pVarResult->vt = VT_BOOL; | 438 if (pVarResult) |
429 pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayUpd
atePage", false) ? VARIANT_TRUE : VARIANT_FALSE; | 439 { |
| 440 pVarResult->vt = VT_BOOL; |
| 441 pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayU
pdatePage", false) ? VARIANT_TRUE : VARIANT_FALSE; |
| 442 } |
430 } | 443 } |
431 break; | 444 break; |
432 default: | 445 default: |
433 return DISP_E_MEMBERNOTFOUND; | 446 return DISP_E_MEMBERNOTFOUND; |
434 break; | 447 break; |
435 } | 448 } |
436 } | 449 } |
437 catch(...) | 450 catch (...) |
438 { | 451 { |
439 return E_FAIL; | 452 return E_FAIL; |
440 } | 453 } |
441 return S_OK; | 454 return S_OK; |
442 } | 455 } |
443 | |
LEFT | RIGHT |