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

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

Issue 5979857238360064: Issues #1163, #1173 - refactor CPluginUserSettings (Closed)
Patch Set: rebase + add one final space character Created Feb. 23, 2015, 1: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
« no previous file with comments | « src/plugin/PluginUserSettings.h ('k') | test/plugin/UserSettingsTest.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 /* 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 <algorithm> 20 #include <algorithm>
21 #include "PluginSettings.h" 21 #include "PluginSettings.h"
22 #include "PluginClient.h" 22 #include "PluginClient.h"
23 #include "../shared/Dictionary.h" 23 #include "../shared/Dictionary.h"
24 24 #include <unordered_map>
25 static const CString s_GetMessage = L"GetMessage"; 25
26 static const CString s_GetLanguageCount = L"GetLanguageCount"; 26 namespace
27 static const CString s_GetLanguageByIndex = L"GetLanguageByIndex"; 27 {
28 static const CString s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex"; 28 enum UserSettingsMethods
29 static const CString s_SetLanguage = L"SetLanguage"; 29 {
30 static const CString s_GetLanguage = L"GetLanguage"; 30 dispatchID_GetMessage = 0,
31 static const CString s_GetWhitelistDomains = L"GetWhitelistDomains"; 31 dispatchID_GetLanguageCount,
32 static const CString s_AddWhitelistDomain = L"AddWhitelistDomain"; 32 dispatchID_GetLanguageByIndex,
33 static const CString s_RemoveWhitelistDomain = L"RemoveWhitelistDomain"; 33 dispatchID_GetLanguageTitleByIndex,
34 static const CString s_GetAppLocale = L"GetAppLocale"; 34 dispatchID_SetLanguage,
35 static const CString s_GetDocumentationLink = L"GetDocumentationLink"; 35 dispatchID_GetLanguage,
36 static const CString s_IsAcceptableAdsEnabled = L"IsAcceptableAdsEnabled"; 36 dispatchID_GetWhitelistDomains,
37 static const CString s_SetAcceptableAdsEnabled = L"SetAcceptableAdsEnabled"; 37 dispatchID_AddWhitelistDomain,
38 static const CString s_IsUpdate = L"IsUpdate"; 38 dispatchID_RemoveWhitelistDomain,
39 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, s_GetAppLocale, s_Get DocumentationLink, s_IsAcceptableAdsEnabled, s_SetAcceptableAdsEnabled, s_IsUpda te}; 39 dispatchID_GetAppLocale,
40 40 dispatchID_GetDocumentationLink,
41 CPluginUserSettings::CPluginUserSettings() 41 dispatchID_IsAcceptableAdsEnabled,
42 { 42 dispatchID_SetAcceptableAdsEnabled,
43 } 43 dispatchID_IsUpdate,
44 44 };
45 45
46 /**
47 * Auxiliary for static initialization
48 */
49 std::unordered_map<std::wstring, DISPID> InitMethodIndex()
50 {
51 std::unordered_map<std::wstring, DISPID> m;
52 // try-block for safety during static initialization
53 try
54 {
55 m.emplace(L"GetMessage", dispatchID_GetMessage);
56 m.emplace(L"GetLanguageCount", dispatchID_GetLanguageCount);
57 m.emplace(L"GetLanguageByIndex", dispatchID_GetLanguageByIndex);
58 m.emplace(L"GetLanguageTitleByIndex", dispatchID_GetLanguageTitleByIndex);
59 m.emplace(L"SetLanguage", dispatchID_SetLanguage);
60 m.emplace(L"GetLanguage", dispatchID_GetLanguage);
61 m.emplace(L"GetWhitelistDomains", dispatchID_GetWhitelistDomains);
62 m.emplace(L"AddWhitelistDomain", dispatchID_AddWhitelistDomain);
63 m.emplace(L"RemoveWhitelistDomain", dispatchID_RemoveWhitelistDomain);
64 m.emplace(L"GetAppLocale", dispatchID_GetAppLocale);
65 m.emplace(L"GetDocumentationLink", dispatchID_GetDocumentationLink);
66 m.emplace(L"IsAcceptableAdsEnabled", dispatchID_IsAcceptableAdsEnabled);
67 m.emplace(L"SetAcceptableAdsEnabled", dispatchID_SetAcceptableAdsEnabled);
68 m.emplace(L"IsUpdate", dispatchID_IsUpdate);
69 }
70 catch(...)
71 {
72 }
73 return m;
74 }
75
76 /**
77 * Static map from method names to dispatch identifiers.
78 */
79 std::unordered_map<std::wstring, DISPID> methodIndex = InitMethodIndex();
80 }
81
82 // ENTRY POINT
46 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) 83 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj)
47 { 84 {
48 if (IID_IUnknown == riid || IID_IDispatch == riid) 85 if (!ppvObj)
49 { 86 {
50 *ppvObj = (LPVOID)this; 87 return E_POINTER;
51 return NOERROR; 88 }
52 } 89 if (riid == IID_IUnknown || riid == IID_IDispatch) // GUID comparison does not throw
53 90 {
91 *ppvObj = static_cast<void*>(this);
92 return S_OK;
93 }
54 return E_NOINTERFACE; 94 return E_NOINTERFACE;
55 } 95 }
56 96
57 97 /**
58 /* 98 * \par Limitation
59 Since CPluginUserSettings is not allocated on the heap, 'AddRef' and 'Release' d on't need reference counting, 99 * CPluginUserSettings is not allocated on the heap.
60 because CPluginUserSettings won't be deleted when reference counter == 0 100 * It appears only as a member variable in CPluginTabBase.
61 */ 101 * 'AddRef' and 'Release' don't need reference counting because they don't pre sent COM factories.
62 102 */
63 ULONG __stdcall CPluginUserSettings::AddRef() 103 ULONG __stdcall CPluginUserSettings::AddRef()
64 { 104 {
65 return 1; 105 return 1;
66 } 106 }
67 107
68
69 ULONG __stdcall CPluginUserSettings::Release() 108 ULONG __stdcall CPluginUserSettings::Release()
70 { 109 {
71 return 1; 110 return 1;
72 } 111 }
73 112
74
75 STDMETHODIMP CPluginUserSettings::GetTypeInfoCount(UINT* pctinfo) 113 STDMETHODIMP CPluginUserSettings::GetTypeInfoCount(UINT* pctinfo)
76 { 114 {
77 return E_NOTIMPL; 115 return E_NOTIMPL;
78 } 116 }
79 117
80
81 STDMETHODIMP CPluginUserSettings::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo* * pptinfo) 118 STDMETHODIMP CPluginUserSettings::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo* * pptinfo)
82 { 119 {
83 return E_NOTIMPL; 120 return E_NOTIMPL;
84 } 121 }
85 122
86 123 /**
87 STDMETHODIMP CPluginUserSettings::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames , UINT cNames, LCID lcid, DISPID* rgdispid) 124 * \par Limitation
88 { 125 * The specification for this method in IDispatch maps an array of names to an array of identifiers.
89 if (!rgszNames) 126 * This version only supports single-element arrays, which is enough for IE's JavaScript interpreter.
90 return E_POINTER; 127 */
91 128 STDMETHODIMP CPluginUserSettings::GetIDsOfNames(REFIID, LPOLESTR* name, UINT cou nt, LCID, DISPID* id)
92 if (!rgdispid) 129 {
93 return E_POINTER; 130 try
94 131 {
95 if (cNames != 1) 132 if (!name || !id)
133 {
134 return E_POINTER;
135 }
136 if (count != 1)
137 {
138 return E_FAIL;
139 }
140 auto item = methodIndex.find(*name); // unordered_map::find is not declared noexcept
141 if (item == methodIndex.end())
142 {
143 return DISP_E_UNKNOWNNAME;
144 }
145 *id = item->second;
146 }
147 catch (...)
148 {
96 return E_FAIL; 149 return E_FAIL;
97 150 }
98 size_t indxMethod = 0;
99 for (; indxMethod < countof(s_Methods); indxMethod++)
100 {
101 if (*rgszNames == s_Methods[indxMethod])
102 break;
103 }
104
105 if (indxMethod == countof(s_Methods))
106 return DISP_E_MEMBERNOTFOUND;
107
108 *rgdispid = static_cast<DISPID>(indxMethod);
109
110 return S_OK; 151 return S_OK;
111 } 152 }
112 153
113
114 static CString sGetLanguage()
115 {
116 CPluginSettings* settings = CPluginSettings::GetInstance();
117 return settings->GetSubscription();
118 }
119
120
121 CStringW sGetMessage(const CString& section, const CString& key) 154 CStringW sGetMessage(const CString& section, const CString& key)
122 { 155 {
123 Dictionary* dictionary = Dictionary::GetInstance(); 156 Dictionary* dictionary = Dictionary::GetInstance();
124 return CStringW(dictionary->Lookup(std::string(CW2A(section)), std::string(CW2 A(key))).c_str()); 157 return CStringW(dictionary->Lookup(std::string(CW2A(section)), std::string(CW2 A(key))).c_str());
125 } 158 }
126 159
127 std::wstring sGetMessage(const std::string& section, const std::string& key)
128 {
129 Dictionary* dictionary = Dictionary::GetInstance();
130 return dictionary->Lookup(section, key);
131 }
132
133
134 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult, 160 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult,
135 EXCEPINFO* pExcepinfo, UINT* pArgErr) 161 EXCEPINFO* pExcepinfo, UINT* pArgErr)
136 { 162 {
137 if (!pDispparams) 163 try
138 return E_POINTER; 164 {
139 165 if (!pDispparams)
140 if (!pExcepinfo) 166 {
141 return E_POINTER; 167 return E_POINTER;
142 168 }
143 if (pDispparams->cNamedArgs) 169 if (pDispparams->cNamedArgs != 0)
144 return DISP_E_NONAMEDARGS; 170 {
145 171 return DISP_E_NONAMEDARGS;
146 CPluginSettings* settings = CPluginSettings::GetInstance(); 172 }
147 173 CPluginSettings* settings = CPluginSettings::GetInstance();
148 if (dispidMember < 0 || dispidMember >= countof(s_Methods)) 174 switch (dispidMember)
149 return DISP_E_BADINDEX; 175 {
150 176 case dispatchID_GetMessage:
151 const CString& method = s_Methods[dispidMember]; 177 {
152 178 if (pDispparams->cArgs != 2)
153 if (method == s_GetMessage) 179 {
154 { 180 return DISP_E_BADPARAMCOUNT;
155 if (pDispparams->cArgs != 2) 181 }
156 return DISP_E_BADPARAMCOUNT; 182 if (pDispparams->rgvarg[0].vt != VT_BSTR || pDispparams->rgvarg[1].vt != VT_BSTR)
157 183 {
158 if (pDispparams->rgvarg[0].vt != VT_BSTR) 184 return DISP_E_TYPEMISMATCH;
159 return DISP_E_TYPEMISMATCH; 185 }
160 186 if (pVarResult)
161 if (pVarResult) 187 {
162 { 188 CComBSTR key = pDispparams->rgvarg[0].bstrVal;
163 CComBSTR key = pDispparams->rgvarg[0].bstrVal; 189 CComBSTR section = pDispparams->rgvarg[1].bstrVal;
164 CComBSTR section = pDispparams->rgvarg[1].bstrVal; 190 CStringW message = sGetMessage((BSTR)section, (BSTR)key);
165 CStringW message = sGetMessage((BSTR)section, (BSTR)key); 191
166 192 pVarResult->vt = VT_BSTR;
167 pVarResult->vt = VT_BSTR; 193 pVarResult->bstrVal = SysAllocString(message);
168 pVarResult->bstrVal = SysAllocString(message); 194 }
169 } 195 }
170 } 196 break;
171 else if (method == s_GetLanguageCount) 197 case dispatchID_GetLanguageCount:
172 { 198 {
173 if (pDispparams->cArgs) 199 if (pDispparams->cArgs != 0)
174 return DISP_E_BADPARAMCOUNT; 200 {
175 201 return DISP_E_BADPARAMCOUNT;
176 if (pVarResult) 202 }
177 { 203 if (pVarResult)
178 std::map<CString, CString> languageList = settings->GetFilterLanguageTitle List(); 204 {
179 205 std::map<CString, CString> languageList = settings->GetFilterLanguageT itleList();
180 pVarResult->vt = VT_I4; 206
181 pVarResult->lVal = static_cast<LONG>(languageList.size()); 207 pVarResult->vt = VT_I4;
182 } 208 pVarResult->lVal = static_cast<LONG>(languageList.size());
183 } 209 }
184 else if (method == s_GetLanguageByIndex) 210 }
185 { 211 break;
186 if (pDispparams->cArgs != 1) 212 case dispatchID_GetLanguageByIndex:
187 return DISP_E_BADPARAMCOUNT; 213 {
188 214 if (pDispparams->cArgs != 1)
189 if (pDispparams->rgvarg[0].vt != VT_I4) 215 {
190 return DISP_E_TYPEMISMATCH; 216 return DISP_E_BADPARAMCOUNT;
191 217 }
192 if (pVarResult) 218 if (pDispparams->rgvarg[0].vt != VT_I4)
193 { 219 {
194 int indx = pDispparams->rgvarg[0].lVal; 220 return DISP_E_TYPEMISMATCH;
195 221 }
196 std::map<CString, CString> languageTitleList = settings->GetFilterLanguage TitleList(); 222 if (pVarResult)
197 223 {
198 if (indx < 0 || indx >= (int)languageTitleList.size()) 224 int index = pDispparams->rgvarg[0].lVal;
199 return DISP_E_EXCEPTION; 225
200 226 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList();
201 CString language; 227
202 228 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
203 int curIndx = 0; 229 return DISP_E_EXCEPTION;
204 for(std::map<CString, CString>::const_iterator it = languageTitleList.begi n(); it != languageTitleList.end(); ++it) 230
205 { 231 CString language;
206 if (curIndx == indx) 232
207 { 233 int loopIndex = 0;
208 language = it->first; 234 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it)
209 break; 235 {
210 } 236 if (loopIndex == index)
211 237 {
212 curIndx++; 238 language = it->first;
213 } 239 break;
214 240 }
215 pVarResult->vt = VT_BSTR; 241 ++loopIndex;
216 pVarResult->bstrVal = SysAllocString(language); 242 }
217 } 243
218 } 244 pVarResult->vt = VT_BSTR;
219 else if (method == s_GetLanguageTitleByIndex) 245 pVarResult->bstrVal = SysAllocString(language);
220 { 246 }
221 if (pDispparams->cArgs != 1) 247 }
222 return DISP_E_BADPARAMCOUNT; 248 break;
223 249 case dispatchID_GetLanguageTitleByIndex:
224 if (pDispparams->rgvarg[0].vt != VT_I4) 250 {
225 return DISP_E_TYPEMISMATCH; 251 if (pDispparams->cArgs != 1)
226 252 {
227 if (pVarResult) 253 return DISP_E_BADPARAMCOUNT;
228 { 254 }
229 int indx = pDispparams->rgvarg[0].lVal; 255 if (pDispparams->rgvarg[0].vt != VT_I4)
230 256 {
231 std::map<CString, CString> languageTitleList = settings->GetFilterLanguage TitleList(); 257 return DISP_E_TYPEMISMATCH;
232 258 }
233 if (indx < 0 || indx >= (int)languageTitleList.size()) 259 if (pVarResult)
234 return DISP_E_EXCEPTION; 260 {
235 261 int index = pDispparams->rgvarg[0].lVal;
236 CString languageTitle; 262
237 263 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList();
238 int curIndx = 0; 264
239 for(std::map<CString, CString>::const_iterator it = languageTitleList.begi n(); it != languageTitleList.end(); ++it) 265 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
240 { 266 return DISP_E_EXCEPTION;
241 if (curIndx == indx) 267
242 { 268 CString languageTitle;
243 languageTitle = it->second; 269
244 break; 270 int loopIndex = 0;
245 } 271 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it)
246 272 {
247 curIndx++; 273 if (loopIndex == index)
248 } 274 {
249 275 languageTitle = it->second;
250 pVarResult->vt = VT_BSTR; 276 break;
251 pVarResult->bstrVal = SysAllocString(languageTitle); 277 }
252 } 278 loopIndex++;
253 } 279 }
254 else if (method == s_SetLanguage) 280
255 { 281 pVarResult->vt = VT_BSTR;
256 if (pDispparams->cArgs != 1) 282 pVarResult->bstrVal = SysAllocString(languageTitle);
257 return DISP_E_BADPARAMCOUNT; 283 }
258 284 }
259 if (pDispparams->rgvarg[0].vt != VT_BSTR) 285 break;
260 return DISP_E_TYPEMISMATCH; 286 case dispatchID_SetLanguage:
261 287 {
262 CComBSTR url = pDispparams->rgvarg[0].bstrVal; 288 if (pDispparams->cArgs != 1)
263 289 {
264 settings->SetSubscription((BSTR)url); 290 return DISP_E_BADPARAMCOUNT;
265 } 291 }
266 else if (method == s_GetLanguage) 292 if (pDispparams->rgvarg[0].vt != VT_BSTR)
267 { 293 {
268 if (pDispparams->cArgs) 294 return DISP_E_TYPEMISMATCH;
269 return DISP_E_BADPARAMCOUNT; 295 }
270 296 CComBSTR url = pDispparams->rgvarg[0].bstrVal;
271 if (pVarResult) 297 settings->SetSubscription((BSTR)url);
272 { 298 }
273 CString url = settings->GetSubscription(); 299 break;
274 300 case dispatchID_GetLanguage:
275 pVarResult->vt = VT_BSTR; 301 {
276 pVarResult->bstrVal = SysAllocString(url); 302 if (pDispparams->cArgs != 0)
277 } 303 {
278 } 304 return DISP_E_BADPARAMCOUNT;
279 else if (method == s_GetWhitelistDomains) 305 }
280 { 306 if (pVarResult)
281 if (pDispparams->cArgs) 307 {
282 return DISP_E_BADPARAMCOUNT; 308 CString url = settings->GetSubscription();
283 309 pVarResult->vt = VT_BSTR;
284 if (pVarResult) 310 pVarResult->bstrVal = SysAllocString(url);
285 { 311 }
286 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainList() ; 312 }
287 CString sWhiteList; 313 break;
288 for (size_t i = 0; i < whiteList.size(); i++) 314 case dispatchID_GetWhitelistDomains:
289 { 315 {
290 if (!sWhiteList.IsEmpty()) 316 if (pDispparams->cArgs != 0)
291 { 317 {
292 sWhiteList += ','; 318 return DISP_E_BADPARAMCOUNT;
293 } 319 }
294 sWhiteList += CString(whiteList[i].c_str()); 320 if (pVarResult)
295 } 321 {
296 322 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainLi st();
297 pVarResult->vt = VT_BSTR; 323 CString sWhiteList;
298 pVarResult->bstrVal = SysAllocString(sWhiteList); 324 for (size_t i = 0; i < whiteList.size(); i++)
299 } 325 {
300 } 326 if (!sWhiteList.IsEmpty())
301 else if (method == s_AddWhitelistDomain) 327 {
302 { 328 sWhiteList += ',';
303 if (pDispparams->cArgs != 1) 329 }
304 return DISP_E_BADPARAMCOUNT; 330 sWhiteList += CString(whiteList[i].c_str());
305 331 }
306 if (pDispparams->rgvarg[0].vt != VT_BSTR) 332 pVarResult->vt = VT_BSTR;
307 return DISP_E_TYPEMISMATCH; 333 pVarResult->bstrVal = SysAllocString(sWhiteList);
308 334 }
309 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 335 }
310 if (domain.Length()) 336 break;
311 { 337 case dispatchID_AddWhitelistDomain:
312 settings->AddWhiteListedDomain((BSTR)domain); 338 {
313 } 339 if (pDispparams->cArgs != 1)
314 } 340 {
315 else if (method == s_RemoveWhitelistDomain) 341 return DISP_E_BADPARAMCOUNT;
316 { 342 }
317 if (pDispparams->cArgs != 1) 343 if (pDispparams->rgvarg[0].vt != VT_BSTR)
318 return DISP_E_BADPARAMCOUNT; 344 {
319 345 return DISP_E_TYPEMISMATCH;
320 if (pDispparams->rgvarg[0].vt != VT_BSTR) 346 }
321 return DISP_E_TYPEMISMATCH; 347 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
322 348 if (domain.Length())
323 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 349 {
324 if (domain.Length()) 350 settings->AddWhiteListedDomain((BSTR)domain);
325 { 351 }
326 settings->RemoveWhiteListedDomain((BSTR)domain); 352 }
327 } 353 break;
328 } 354 case dispatchID_RemoveWhitelistDomain:
329 else if (method == s_GetAppLocale) 355 {
330 { 356 if (pDispparams->cArgs != 1)
331 if (pDispparams->cArgs != 0) 357 {
332 return DISP_E_BADPARAMCOUNT; 358 return DISP_E_BADPARAMCOUNT;
333 359 }
334 pVarResult->vt = VT_BSTR; 360 if (pDispparams->rgvarg[0].vt != VT_BSTR)
335 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); 361 {
336 } 362 return DISP_E_TYPEMISMATCH;
337 else if (method == s_GetDocumentationLink) 363 }
338 { 364 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
339 if (pDispparams->cArgs != 0) 365 if (domain.Length())
340 return DISP_E_BADPARAMCOUNT; 366 {
341 367 settings->RemoveWhiteListedDomain((BSTR)domain);
342 pVarResult->vt = VT_BSTR; 368 }
343 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()); 369 }
344 } 370 break;
345 else if (s_IsAcceptableAdsEnabled == method) 371 case dispatchID_GetAppLocale:
346 { 372 {
347 if (pDispparams->cArgs != 0) 373 if (pDispparams->cArgs != 0)
348 return DISP_E_BADPARAMCOUNT; 374 {
349 375 return DISP_E_BADPARAMCOUNT;
350 pVarResult->vt = VT_BOOL; 376 }
351 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEnabled() ? VARIANT_TRUE : VARIANT_FALSE; 377 if (pVarResult)
352 } 378 {
353 else if (method == s_SetAcceptableAdsEnabled) 379 pVarResult->vt = VT_BSTR;
354 { 380 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale());
355 if (pDispparams->cArgs != 1) 381 }
356 return DISP_E_BADPARAMCOUNT; 382 }
357 383 break;
358 if (pDispparams->rgvarg[0].vt != VT_BOOL) 384 case dispatchID_GetDocumentationLink:
359 return DISP_E_TYPEMISMATCH; 385 {
360 386 if (pDispparams->cArgs != 0)
361 bool enable = pDispparams->rgvarg[0].boolVal != VARIANT_FALSE; 387 {
362 388 return DISP_E_BADPARAMCOUNT;
363 if (enable) 389 }
364 { 390 if (pVarResult)
365 CPluginClient* client = CPluginClient::GetInstance(); 391 {
366 client->AddSubscription(client->GetPref(L"subscriptions_exceptionsurl", L" ")); 392 pVarResult->vt = VT_BSTR;
367 } 393 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()) ;
368 else 394 }
369 { 395 }
370 CPluginClient* client = CPluginClient::GetInstance(); 396 break;
371 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsurl", L"")); 397 case dispatchID_IsAcceptableAdsEnabled:
372 } 398 {
373 } 399 if (pDispparams->cArgs != 0)
374 else if (method == s_IsUpdate) 400 {
375 { 401 return DISP_E_BADPARAMCOUNT;
376 if (pDispparams->cArgs != 0) 402 }
377 return DISP_E_BADPARAMCOUNT; 403 if (pVarResult)
378 404 {
379 pVarResult->vt = VT_BOOL; 405 pVarResult->vt = VT_BOOL;
380 pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayUpdateP age", false); 406 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEna bled() ? VARIANT_TRUE : VARIANT_FALSE;
381 } 407 }
382 else 408 }
383 return DISP_E_MEMBERNOTFOUND; 409 break;
384 410 case dispatchID_SetAcceptableAdsEnabled:
411 {
412 if (pDispparams->cArgs != 1)
413 {
414 return DISP_E_BADPARAMCOUNT;
415 }
416 if (pDispparams->rgvarg[0].vt != VT_BOOL)
417 {
418 return DISP_E_TYPEMISMATCH;
419 }
420 if (pDispparams->rgvarg[0].boolVal != VARIANT_FALSE)
421 {
422 CPluginClient* client = CPluginClient::GetInstance();
423 client->AddSubscription(client->GetPref(L"subscriptions_exceptionsurl" , L""));
424 }
425 else
426 {
427 CPluginClient* client = CPluginClient::GetInstance();
428 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsu rl", L""));
429 }
430 }
431 break;
432 case dispatchID_IsUpdate:
433 {
434 if (pDispparams->cArgs != 0)
435 {
436 return DISP_E_BADPARAMCOUNT;
437 }
438 if (pVarResult)
439 {
440 pVarResult->vt = VT_BOOL;
441 pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayU pdatePage", false) ? VARIANT_TRUE : VARIANT_FALSE;
442 }
443 }
444 break;
445 default:
446 return DISP_E_MEMBERNOTFOUND;
447 break;
448 }
449 }
450 catch (...)
451 {
452 return E_FAIL;
453 }
385 return S_OK; 454 return S_OK;
386 } 455 }
387
OLDNEW
« no previous file with comments | « src/plugin/PluginUserSettings.h ('k') | test/plugin/UserSettingsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld