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

Delta Between Two Patch Sets: src/plugin/PluginUserSettings.cpp

Issue 5979857238360064: Issues #1163, #1173 - refactor CPluginUserSettings (Closed)
Left Patch Set: Created Aug. 6, 2014, 4:56 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginUserSettings.h ('k') | test/plugin/UserSettingsTest.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
1 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
2 #include "PluginUserSettings.h" 19 #include "PluginUserSettings.h"
3 #include <algorithm> 20 #include <algorithm>
4 #include "PluginSettings.h" 21 #include "PluginSettings.h"
5 #include "PluginClient.h" 22 #include "PluginClient.h"
6 #include "../shared/Dictionary.h" 23 #include "../shared/Dictionary.h"
7 #include <unordered_map> 24 #include <unordered_map>
8 25
9 namespace 26 namespace
10 { 27 {
11 enum UserSettingsMethods 28 enum UserSettingsMethods
12 { 29 {
13 dispatchID_GetMessage = 0, 30 dispatchID_GetMessage = 0,
14 dispatchID_GetLanguageCount, 31 dispatchID_GetLanguageCount,
15 dispatchID_GetLanguageByIndex, 32 dispatchID_GetLanguageByIndex,
16 dispatchID_GetLanguageTitleByIndex, 33 dispatchID_GetLanguageTitleByIndex,
17 dispatchID_SetLanguage, 34 dispatchID_SetLanguage,
18 dispatchID_GetLanguage, 35 dispatchID_GetLanguage,
19 dispatchID_GetWhitelistDomains, 36 dispatchID_GetWhitelistDomains,
20 dispatchID_AddWhitelistDomain, 37 dispatchID_AddWhitelistDomain,
21 dispatchID_RemoveWhitelistDomain, 38 dispatchID_RemoveWhitelistDomain,
22 dispatchID_GetAppLocale, 39 dispatchID_GetAppLocale,
23 dispatchID_GetDocumentationLink, 40 dispatchID_GetDocumentationLink,
24 dispatchID_IsAcceptableAdsEnabled, 41 dispatchID_IsAcceptableAdsEnabled,
25 dispatchID_SetAcceptableAdsEnabled 42 dispatchID_SetAcceptableAdsEnabled,
43 dispatchID_IsUpdate,
26 }; 44 };
27 45
46 /**
47 * Auxiliary for static initialization
48 */
28 std::unordered_map<std::wstring, DISPID> InitMethodIndex() 49 std::unordered_map<std::wstring, DISPID> InitMethodIndex()
29 { 50 {
30 std::unordered_map<std::wstring, DISPID> m; 51 std::unordered_map<std::wstring, DISPID> m;
31 // try-block for safety during static initialization 52 // try-block for safety during static initialization
32 try 53 try
33 { 54 {
34 m.emplace(L"GetMessage", dispatchID_GetMessage); 55 m.emplace(L"GetMessage", dispatchID_GetMessage);
Oleksandr 2014/08/17 22:52:01 It's outside the scope of this review, but since w
Eric 2014/09/29 18:45:41 Discussion points. 1. I wouldn't mind breaking up
Oleksandr 2014/10/02 20:36:53 Creating a low priority issue in our issue tracker
Eric 2014/10/14 22:23:50 I wrote an issue for the slightly larger task of c
35 m.emplace(L"GetLanguageCount", dispatchID_GetLanguageCount); 56 m.emplace(L"GetLanguageCount", dispatchID_GetLanguageCount);
36 m.emplace(L"GetLanguageByIndex", dispatchID_GetLanguageByIndex); 57 m.emplace(L"GetLanguageByIndex", dispatchID_GetLanguageByIndex);
37 m.emplace(L"GetLanguageTitleByIndex", dispatchID_GetLanguageTitleByIndex); 58 m.emplace(L"GetLanguageTitleByIndex", dispatchID_GetLanguageTitleByIndex);
38 m.emplace(L"SetLanguage", dispatchID_SetLanguage); 59 m.emplace(L"SetLanguage", dispatchID_SetLanguage);
39 m.emplace(L"GetLanguage", dispatchID_GetLanguage); 60 m.emplace(L"GetLanguage", dispatchID_GetLanguage);
40 m.emplace(L"GetWhitelistDomains", dispatchID_GetWhitelistDomains); 61 m.emplace(L"GetWhitelistDomains", dispatchID_GetWhitelistDomains);
41 m.emplace(L"AddWhitelistDomain", dispatchID_AddWhitelistDomain); 62 m.emplace(L"AddWhitelistDomain", dispatchID_AddWhitelistDomain);
42 m.emplace(L"RemoveWhitelistDomain", dispatchID_RemoveWhitelistDomain); 63 m.emplace(L"RemoveWhitelistDomain", dispatchID_RemoveWhitelistDomain);
43 m.emplace(L"GetAppLocale", dispatchID_GetAppLocale); 64 m.emplace(L"GetAppLocale", dispatchID_GetAppLocale);
44 m.emplace(L"GetDocumentationLink", dispatchID_GetDocumentationLink); 65 m.emplace(L"GetDocumentationLink", dispatchID_GetDocumentationLink);
45 m.emplace(L"IsAcceptableAdsEnabled", dispatchID_IsAcceptableAdsEnabled); 66 m.emplace(L"IsAcceptableAdsEnabled", dispatchID_IsAcceptableAdsEnabled);
46 m.emplace(L"SetAcceptableAdsEnabled", dispatchID_SetAcceptableAdsEnabled); 67 m.emplace(L"SetAcceptableAdsEnabled", dispatchID_SetAcceptableAdsEnabled);
68 m.emplace(L"IsUpdate", dispatchID_IsUpdate);
47 } 69 }
48 catch(...) 70 catch(...)
49 { 71 {
50 } 72 }
51 return m; 73 return m;
52 } 74 }
53 75
76 /**
77 * Static map from method names to dispatch identifiers.
78 */
54 std::unordered_map<std::wstring, DISPID> methodIndex = InitMethodIndex(); 79 std::unordered_map<std::wstring, DISPID> methodIndex = InitMethodIndex();
55 } 80 }
56 81
82 // ENTRY POINT
57 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) 83 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj)
58 { 84 {
59 // Entry point, but no exception handler; nothing here can throw
Oleksandr 2014/08/17 22:52:01 This comment and all the others concerning the exc
Eric 2014/09/29 18:45:41 I would like to have some kind of documentation in
Oleksandr 2014/10/02 20:36:53 In that case, it would seem less intrusive to have
60 if (!ppvObj) 85 if (!ppvObj)
61 { 86 {
62 return E_POINTER; 87 return E_POINTER;
63 } 88 }
64 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
65 { 90 {
66 *ppvObj = static_cast<void *>(this); 91 *ppvObj = static_cast<void*>(this);
67 return S_OK; 92 return S_OK;
68 } 93 }
69 return E_NOINTERFACE; 94 return E_NOINTERFACE;
70 } 95 }
71 96
72 /** 97 /**
73 * \par Limitation 98 * \par Limitation
74 * CPluginUserSettings is not allocated on the heap. 99 * CPluginUserSettings is not allocated on the heap.
75 * It appears only as a member variable in CPluginTabBase. 100 * It appears only as a member variable in CPluginTabBase.
76 * '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 18 matching lines...) Expand all
95 return E_NOTIMPL; 120 return E_NOTIMPL;
96 } 121 }
97 122
98 /** 123 /**
99 * \par Limitation 124 * \par Limitation
100 * The specification for this method in IDispatch maps an array of names to an array of identifiers. 125 * The specification for this method in IDispatch maps an array of names to an array of identifiers.
101 * This version only supports single-element arrays, which is enough for IE's JavaScript interpreter. 126 * This version only supports single-element arrays, which is enough for IE's JavaScript interpreter.
102 */ 127 */
103 STDMETHODIMP CPluginUserSettings::GetIDsOfNames(REFIID, LPOLESTR* name, UINT cou nt, LCID, DISPID* id) 128 STDMETHODIMP CPluginUserSettings::GetIDsOfNames(REFIID, LPOLESTR* name, UINT cou nt, LCID, DISPID* id)
104 { 129 {
105 // Entry point exception handler
106 try 130 try
107 { 131 {
108 if (!name || !id) 132 if (!name || !id)
109 { 133 {
110 return E_POINTER; 134 return E_POINTER;
111 } 135 }
112 if (count != 1) 136 if (count != 1)
113 { 137 {
114 return E_FAIL; 138 return E_FAIL;
115 } 139 }
116 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
117 if (item==methodIndex.end()) 141 if (item == methodIndex.end())
118 { 142 {
119 return DISP_E_UNKNOWNNAME; 143 return DISP_E_UNKNOWNNAME;
120 } 144 }
121 *id = item->second; 145 *id = item->second;
122 } 146 }
123 catch(...) 147 catch (...)
124 { 148 {
125 return E_FAIL; 149 return E_FAIL;
126 } 150 }
127 return S_OK; 151 return S_OK;
128 } 152 }
129 153
130 CStringW sGetMessage(const CString& section, const CString& key) 154 CStringW sGetMessage(const CString& section, const CString& key)
131 { 155 {
132 Dictionary* dictionary = Dictionary::GetInstance(); 156 Dictionary* dictionary = Dictionary::GetInstance();
133 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());
134 } 158 }
135 159
136 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,
137 EXCEPINFO* pExcepinfo, UINT* pArgErr) 161 EXCEPINFO* pExcepinfo, UINT* pArgErr)
138 { 162 {
139 // Entry point exception handler
140 try 163 try
141 { 164 {
142 if (!pDispparams || !pExcepinfo) 165 if (!pDispparams)
143 { 166 {
144 return E_POINTER; 167 return E_POINTER;
145 } 168 }
146 if (pDispparams->cNamedArgs != 0) 169 if (pDispparams->cNamedArgs != 0)
147 { 170 {
148 return DISP_E_NONAMEDARGS; 171 return DISP_E_NONAMEDARGS;
149 } 172 }
150
151 CPluginSettings* settings = CPluginSettings::GetInstance(); 173 CPluginSettings* settings = CPluginSettings::GetInstance();
152
153 switch (dispidMember) 174 switch (dispidMember)
154 { 175 {
155 case dispatchID_GetMessage: 176 case dispatchID_GetMessage:
156 { 177 {
157 if (2 != pDispparams->cArgs) 178 if (pDispparams->cArgs != 2)
158 return DISP_E_BADPARAMCOUNT; 179 {
159 180 return DISP_E_BADPARAMCOUNT;
160 if (VT_BSTR != pDispparams->rgvarg[0].vt) 181 }
161 return DISP_E_TYPEMISMATCH; 182 if (pDispparams->rgvarg[0].vt != VT_BSTR || pDispparams->rgvarg[1].vt != VT_BSTR)
162 if (VT_BSTR != pDispparams->rgvarg[1].vt) 183 {
163 return DISP_E_TYPEMISMATCH; 184 return DISP_E_TYPEMISMATCH;
164 185 }
165 if (pVarResult) 186 if (pVarResult)
166 { 187 {
167 CComBSTR key = pDispparams->rgvarg[0].bstrVal; 188 CComBSTR key = pDispparams->rgvarg[0].bstrVal;
168 CComBSTR section = pDispparams->rgvarg[1].bstrVal; 189 CComBSTR section = pDispparams->rgvarg[1].bstrVal;
169 CStringW message = sGetMessage((BSTR)section, (BSTR)key); 190 CStringW message = sGetMessage((BSTR)section, (BSTR)key);
170 191
171 pVarResult->vt = VT_BSTR; 192 pVarResult->vt = VT_BSTR;
172 pVarResult->bstrVal = SysAllocString(message); 193 pVarResult->bstrVal = SysAllocString(message);
173 } 194 }
174 } 195 }
175 break; 196 break;
176 case dispatchID_GetLanguageCount: 197 case dispatchID_GetLanguageCount:
177 { 198 {
178 if (pDispparams->cArgs) 199 if (pDispparams->cArgs != 0)
179 return DISP_E_BADPARAMCOUNT; 200 {
180 201 return DISP_E_BADPARAMCOUNT;
202 }
181 if (pVarResult) 203 if (pVarResult)
182 { 204 {
183 std::map<CString, CString> languageList = settings->GetFilterLanguageT itleList(); 205 std::map<CString, CString> languageList = settings->GetFilterLanguageT itleList();
184 206
185 pVarResult->vt = VT_I4; 207 pVarResult->vt = VT_I4;
186 pVarResult->lVal = static_cast<LONG>(languageList.size()); 208 pVarResult->lVal = static_cast<LONG>(languageList.size());
187 } 209 }
188 } 210 }
189 break; 211 break;
190 case dispatchID_GetLanguageByIndex: 212 case dispatchID_GetLanguageByIndex:
191 { 213 {
192 if (1 != pDispparams->cArgs) 214 if (pDispparams->cArgs != 1)
193 return DISP_E_BADPARAMCOUNT; 215 {
194 216 return DISP_E_BADPARAMCOUNT;
195 if (VT_I4 != pDispparams->rgvarg[0].vt) 217 }
196 return DISP_E_TYPEMISMATCH; 218 if (pDispparams->rgvarg[0].vt != VT_I4)
197 219 {
198 if (pVarResult) 220 return DISP_E_TYPEMISMATCH;
199 { 221 }
200 int indx = pDispparams->rgvarg[0].lVal; 222 if (pVarResult)
223 {
224 int index = pDispparams->rgvarg[0].lVal;
201 225
202 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 226 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList();
203 227
204 if (indx < 0 || indx >= (int)languageTitleList.size()) 228 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
205 return DISP_E_EXCEPTION; 229 return DISP_E_EXCEPTION;
206 230
207 CString language; 231 CString language;
208 232
209 int curIndx = 0; 233 int loopIndex = 0;
210 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)
211 { 235 {
212 if (curIndx == indx) 236 if (loopIndex == index)
213 { 237 {
214 language = it->first; 238 language = it->first;
215 break; 239 break;
216 } 240 }
217 241 ++loopIndex;
218 curIndx++;
219 } 242 }
220 243
221 pVarResult->vt = VT_BSTR; 244 pVarResult->vt = VT_BSTR;
222 pVarResult->bstrVal = SysAllocString(language); 245 pVarResult->bstrVal = SysAllocString(language);
223 } 246 }
224 } 247 }
225 break; 248 break;
226 case dispatchID_GetLanguageTitleByIndex: 249 case dispatchID_GetLanguageTitleByIndex:
227 { 250 {
228 if (1 != pDispparams->cArgs) 251 if (pDispparams->cArgs != 1)
229 return DISP_E_BADPARAMCOUNT; 252 {
230 253 return DISP_E_BADPARAMCOUNT;
231 if (VT_I4 != pDispparams->rgvarg[0].vt) 254 }
232 return DISP_E_TYPEMISMATCH; 255 if (pDispparams->rgvarg[0].vt != VT_I4)
233 256 {
234 if (pVarResult) 257 return DISP_E_TYPEMISMATCH;
235 { 258 }
236 int indx = pDispparams->rgvarg[0].lVal; 259 if (pVarResult)
260 {
261 int index = pDispparams->rgvarg[0].lVal;
237 262
238 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 263 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList();
239 264
240 if (indx < 0 || indx >= (int)languageTitleList.size()) 265 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
241 return DISP_E_EXCEPTION; 266 return DISP_E_EXCEPTION;
242 267
243 CString languageTitle; 268 CString languageTitle;
244 269
245 int curIndx = 0; 270 int loopIndex = 0;
246 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)
247 { 272 {
248 if (curIndx == indx) 273 if (loopIndex == index)
249 { 274 {
250 languageTitle = it->second; 275 languageTitle = it->second;
251 break; 276 break;
252 } 277 }
253 278 loopIndex++;
254 curIndx++;
255 } 279 }
256 280
257 pVarResult->vt = VT_BSTR; 281 pVarResult->vt = VT_BSTR;
258 pVarResult->bstrVal = SysAllocString(languageTitle); 282 pVarResult->bstrVal = SysAllocString(languageTitle);
259 } 283 }
260 } 284 }
261 break; 285 break;
262 case dispatchID_SetLanguage: 286 case dispatchID_SetLanguage:
263 { 287 {
264 if (1 != pDispparams->cArgs) 288 if (pDispparams->cArgs != 1)
265 return DISP_E_BADPARAMCOUNT; 289 {
266 290 return DISP_E_BADPARAMCOUNT;
267 if (VT_BSTR != pDispparams->rgvarg[0].vt) 291 }
268 return DISP_E_TYPEMISMATCH; 292 if (pDispparams->rgvarg[0].vt != VT_BSTR)
269 293 {
294 return DISP_E_TYPEMISMATCH;
295 }
270 CComBSTR url = pDispparams->rgvarg[0].bstrVal; 296 CComBSTR url = pDispparams->rgvarg[0].bstrVal;
271
272 settings->SetSubscription((BSTR)url); 297 settings->SetSubscription((BSTR)url);
273 } 298 }
274 break; 299 break;
275 case dispatchID_GetLanguage: 300 case dispatchID_GetLanguage:
276 { 301 {
277 if (pDispparams->cArgs) 302 if (pDispparams->cArgs != 0)
278 return DISP_E_BADPARAMCOUNT; 303 {
279 304 return DISP_E_BADPARAMCOUNT;
305 }
280 if (pVarResult) 306 if (pVarResult)
281 { 307 {
282 CString url = settings->GetSubscription(); 308 CString url = settings->GetSubscription();
283
284 pVarResult->vt = VT_BSTR; 309 pVarResult->vt = VT_BSTR;
285 pVarResult->bstrVal = SysAllocString(url); 310 pVarResult->bstrVal = SysAllocString(url);
286 } 311 }
287 } 312 }
288 break; 313 break;
289 case dispatchID_GetWhitelistDomains: 314 case dispatchID_GetWhitelistDomains:
290 { 315 {
291 if (pDispparams->cArgs) 316 if (pDispparams->cArgs != 0)
292 return DISP_E_BADPARAMCOUNT; 317 {
293 318 return DISP_E_BADPARAMCOUNT;
319 }
294 if (pVarResult) 320 if (pVarResult)
295 { 321 {
296 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainLi st(); 322 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainLi st();
297 CString sWhiteList; 323 CString sWhiteList;
298 for (size_t i = 0; i < whiteList.size(); i++) 324 for (size_t i = 0; i < whiteList.size(); i++)
299 { 325 {
300 if (!sWhiteList.IsEmpty()) 326 if (!sWhiteList.IsEmpty())
301 { 327 {
302 sWhiteList += ','; 328 sWhiteList += ',';
303 } 329 }
304 sWhiteList += CString(whiteList[i].c_str()); 330 sWhiteList += CString(whiteList[i].c_str());
305 } 331 }
306
307 pVarResult->vt = VT_BSTR; 332 pVarResult->vt = VT_BSTR;
308 pVarResult->bstrVal = SysAllocString(sWhiteList); 333 pVarResult->bstrVal = SysAllocString(sWhiteList);
309 } 334 }
310 } 335 }
311 break; 336 break;
312 case dispatchID_AddWhitelistDomain: 337 case dispatchID_AddWhitelistDomain:
313 { 338 {
314 if (1 != pDispparams->cArgs) 339 if (pDispparams->cArgs != 1)
315 return DISP_E_BADPARAMCOUNT; 340 {
316 341 return DISP_E_BADPARAMCOUNT;
317 if (VT_BSTR != pDispparams->rgvarg[0].vt) 342 }
318 return DISP_E_TYPEMISMATCH; 343 if (pDispparams->rgvarg[0].vt != VT_BSTR)
319 344 {
345 return DISP_E_TYPEMISMATCH;
346 }
320 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 347 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
321 if (domain.Length()) 348 if (domain.Length())
322 { 349 {
323 settings->AddWhiteListedDomain((BSTR)domain); 350 settings->AddWhiteListedDomain((BSTR)domain);
324 } 351 }
325 } 352 }
326 break; 353 break;
327 case dispatchID_RemoveWhitelistDomain: 354 case dispatchID_RemoveWhitelistDomain:
328 { 355 {
329 if (1 != pDispparams->cArgs) 356 if (pDispparams->cArgs != 1)
330 return DISP_E_BADPARAMCOUNT; 357 {
331 358 return DISP_E_BADPARAMCOUNT;
332 if (VT_BSTR != pDispparams->rgvarg[0].vt) 359 }
333 return DISP_E_TYPEMISMATCH; 360 if (pDispparams->rgvarg[0].vt != VT_BSTR)
334 361 {
362 return DISP_E_TYPEMISMATCH;
363 }
335 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 364 CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
336 if (domain.Length()) 365 if (domain.Length())
337 { 366 {
338 settings->RemoveWhiteListedDomain((BSTR)domain); 367 settings->RemoveWhiteListedDomain((BSTR)domain);
339 } 368 }
340 } 369 }
341 break; 370 break;
342 case dispatchID_GetAppLocale: 371 case dispatchID_GetAppLocale:
343 { 372 {
344 if (0 != pDispparams->cArgs) 373 if (pDispparams->cArgs != 0)
345 return DISP_E_BADPARAMCOUNT; 374 {
346 375 return DISP_E_BADPARAMCOUNT;
347 pVarResult->vt = VT_BSTR; 376 }
348 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); 377 if (pVarResult)
378 {
379 pVarResult->vt = VT_BSTR;
380 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale());
381 }
349 } 382 }
350 break; 383 break;
351 case dispatchID_GetDocumentationLink: 384 case dispatchID_GetDocumentationLink:
352 { 385 {
353 if (0 != pDispparams->cArgs) 386 if (pDispparams->cArgs != 0)
354 return DISP_E_BADPARAMCOUNT; 387 {
355 388 return DISP_E_BADPARAMCOUNT;
356 pVarResult->vt = VT_BSTR; 389 }
357 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()); 390 if (pVarResult)
391 {
392 pVarResult->vt = VT_BSTR;
393 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()) ;
394 }
358 } 395 }
359 break; 396 break;
360 case dispatchID_IsAcceptableAdsEnabled: 397 case dispatchID_IsAcceptableAdsEnabled:
361 { 398 {
362 if (0 != pDispparams->cArgs) 399 if (pDispparams->cArgs != 0)
363 return DISP_E_BADPARAMCOUNT; 400 {
364 401 return DISP_E_BADPARAMCOUNT;
365 pVarResult->vt = VT_BOOL; 402 }
366 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEnabl ed(); 403 if (pVarResult)
404 {
405 pVarResult->vt = VT_BOOL;
406 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEna bled() ? VARIANT_TRUE : VARIANT_FALSE;
407 }
367 } 408 }
368 break; 409 break;
369 case dispatchID_SetAcceptableAdsEnabled: 410 case dispatchID_SetAcceptableAdsEnabled:
370 { 411 {
371 if (1 != pDispparams->cArgs) 412 if (pDispparams->cArgs != 1)
372 return DISP_E_BADPARAMCOUNT; 413 {
373 414 return DISP_E_BADPARAMCOUNT;
374 if (VT_BOOL != pDispparams->rgvarg[0].vt) 415 }
375 return DISP_E_TYPEMISMATCH; 416 if (pDispparams->rgvarg[0].vt != VT_BOOL)
376 417 {
377 bool enable = pDispparams->rgvarg[0].boolVal; 418 return DISP_E_TYPEMISMATCH;
378 419 }
379 if (enable) 420 if (pDispparams->rgvarg[0].boolVal != VARIANT_FALSE)
380 { 421 {
381 CPluginClient* client = CPluginClient::GetInstance(); 422 CPluginClient* client = CPluginClient::GetInstance();
382 client->AddSubscription(client->GetPref(L"subscriptions_exceptionsurl" , L"")); 423 client->AddSubscription(client->GetPref(L"subscriptions_exceptionsurl" , L""));
383 } 424 }
384 else 425 else
385 { 426 {
386 CPluginClient* client = CPluginClient::GetInstance(); 427 CPluginClient* client = CPluginClient::GetInstance();
387 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsu rl", L"")); 428 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsu rl", L""));
388 } 429 }
389 } 430 }
390 break; 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;
391 default: 445 default:
392 return DISP_E_MEMBERNOTFOUND; 446 return DISP_E_MEMBERNOTFOUND;
393 break; 447 break;
394 } 448 }
395 } 449 }
396 catch(...) 450 catch (...)
397 { 451 {
398 return E_FAIL; 452 return E_FAIL;
399 } 453 }
400 return S_OK; 454 return S_OK;
401 } 455 }
402
LEFTRIGHT

Powered by Google App Engine
This is Rietveld