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

Powered by Google App Engine
This is Rietveld