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

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

Issue 6650591174459392: Issues #276, #1163 - introduce class IncomingParam (Closed)
Patch Set: rewrite incomparable with patch set 1 Created July 29, 2014, 7:52 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/PluginClass.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 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 #include "PluginUserSettings.h" 2 #include "PluginUserSettings.h"
3 #include <algorithm> 3 #include <algorithm>
4 #include "COM_Value.h"
4 #include "PluginSettings.h" 5 #include "PluginSettings.h"
5 #include "PluginClient.h" 6 #include "PluginClient.h"
6 #include "../shared/Dictionary.h" 7 #include "../shared/Dictionary.h"
7 8
8 static const CString s_GetMessage = L"GetMessage"; 9 static const CString s_GetMessage = L"GetMessage";
9 static const CString s_GetLanguageCount = L"GetLanguageCount"; 10 static const CString s_GetLanguageCount = L"GetLanguageCount";
10 static const CString s_GetLanguageByIndex = L"GetLanguageByIndex"; 11 static const CString s_GetLanguageByIndex = L"GetLanguageByIndex";
11 static const CString s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex"; 12 static const CString s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex";
12 static const CString s_SetLanguage = L"SetLanguage"; 13 static const CString s_SetLanguage = L"SetLanguage";
13 static const CString s_GetLanguage = L"GetLanguage"; 14 static const CString s_GetLanguage = L"GetLanguage";
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 return E_POINTER; 124 return E_POINTER;
124 125
125 if (pDispparams->cNamedArgs) 126 if (pDispparams->cNamedArgs)
126 return DISP_E_NONAMEDARGS; 127 return DISP_E_NONAMEDARGS;
127 128
128 CPluginSettings* settings = CPluginSettings::GetInstance(); 129 CPluginSettings* settings = CPluginSettings::GetInstance();
129 130
130 if (dispidMember < 0 || dispidMember >= countof(s_Methods)) 131 if (dispidMember < 0 || dispidMember >= countof(s_Methods))
131 return DISP_E_BADINDEX; 132 return DISP_E_BADINDEX;
132 133
134 /*
135 * See Issue #1163.
136 * TODO: Rewrite this linear sequence of string comparisons as a switch statem ent.
137 * TODO: Add a try-catch block at the top level of the switch body to rational ize argument checking etc.
138 */
133 const CString& method = s_Methods[dispidMember]; 139 const CString& method = s_Methods[dispidMember];
134
135 if (s_GetMessage == method) 140 if (s_GetMessage == method)
136 { 141 {
137 if (2 != pDispparams->cArgs) 142 /*
138 return DISP_E_BADPARAMCOUNT; 143 * If the caller ignores the value, we can elide the body since it has no si de-effects.
139 144 */
140 if (VT_BSTR != pDispparams->rgvarg[0].vt)
141 return DISP_E_TYPEMISMATCH;
142 if (VT_BSTR != pDispparams->rgvarg[1].vt)
143 return DISP_E_TYPEMISMATCH;
144
145 if (pVarResult) 145 if (pVarResult)
146 { 146 {
147 CComBSTR key = pDispparams->rgvarg[0].bstrVal; 147 if (2 != pDispparams->cArgs)
148 CComBSTR section = pDispparams->rgvarg[1].bstrVal; 148 return DISP_E_BADPARAMCOUNT;
149 CStringW message = sGetMessage((BSTR)section, (BSTR)key); 149
150 AdblockPlus::COM::IncomingParam key(pDispparams->rgvarg[0]);
151 AdblockPlus::COM::IncomingParam section(pDispparams->rgvarg[1]);
152 if (!key.wstringConvertible() || !section.wstringConvertible())
153 {
154 return DISP_E_TYPEMISMATCH;
155 }
156 CStringW message = sGetMessage(to_CString(section.wstringValueNoexcept()), to_CString(key.wstringValueNoexcept()));
150 157
151 pVarResult->vt = VT_BSTR; 158 pVarResult->vt = VT_BSTR;
152 pVarResult->bstrVal = SysAllocString(message); 159 pVarResult->bstrVal = SysAllocString(message);
153 } 160 }
154 } 161 }
155 else if (s_GetLanguageCount == method) 162 else if (s_GetLanguageCount == method)
156 { 163 {
157 if (pDispparams->cArgs) 164 if (pDispparams->cArgs)
158 return DISP_E_BADPARAMCOUNT; 165 return DISP_E_BADPARAMCOUNT;
159 166
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 243 }
237 } 244 }
238 else if (s_SetLanguage == method) 245 else if (s_SetLanguage == method)
239 { 246 {
240 if (1 != pDispparams->cArgs) 247 if (1 != pDispparams->cArgs)
241 return DISP_E_BADPARAMCOUNT; 248 return DISP_E_BADPARAMCOUNT;
242 249
243 if (VT_BSTR != pDispparams->rgvarg[0].vt) 250 if (VT_BSTR != pDispparams->rgvarg[0].vt)
244 return DISP_E_TYPEMISMATCH; 251 return DISP_E_TYPEMISMATCH;
245 252
246 CComBSTR url = pDispparams->rgvarg[0].bstrVal; 253 AdblockPlus::COM::IncomingParam url(pDispparams->rgvarg[0]);
247 254 if (!url.wstringConvertible())
248 settings->SetSubscription((BSTR)url); 255 {
256 return DISP_E_TYPEMISMATCH;
257 }
258 settings->SetSubscription(url.wstringValueNoexcept());
249 } 259 }
250 else if (s_GetLanguage == method) 260 else if (s_GetLanguage == method)
251 { 261 {
252 if (pDispparams->cArgs) 262 if (pDispparams->cArgs)
253 return DISP_E_BADPARAMCOUNT; 263 return DISP_E_BADPARAMCOUNT;
254 264
255 if (pVarResult) 265 if (pVarResult)
256 { 266 {
257 CString url = settings->GetSubscription(); 267 CString url = settings->GetSubscription();
258 268
(...skipping 24 matching lines...) Expand all
283 } 293 }
284 } 294 }
285 else if (s_AddWhitelistDomain == method) 295 else if (s_AddWhitelistDomain == method)
286 { 296 {
287 if (1 != pDispparams->cArgs) 297 if (1 != pDispparams->cArgs)
288 return DISP_E_BADPARAMCOUNT; 298 return DISP_E_BADPARAMCOUNT;
289 299
290 if (VT_BSTR != pDispparams->rgvarg[0].vt) 300 if (VT_BSTR != pDispparams->rgvarg[0].vt)
291 return DISP_E_TYPEMISMATCH; 301 return DISP_E_TYPEMISMATCH;
292 302
293 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 303 AdblockPlus::COM::IncomingParam domain_arg(pDispparams->rgvarg[0]);
294 if (domain.Length()) 304 if (!domain_arg.wstringConvertible())
295 { 305 {
296 settings->AddWhiteListedDomain((BSTR)domain); 306 return DISP_E_TYPEMISMATCH;
307 }
308 std::wstring domain = domain_arg.wstringValueNoexcept();
309 if (!domain.empty())
310 {
311 settings->AddWhiteListedDomain(to_CString(domain));
297 } 312 }
298 } 313 }
299 else if (s_RemoveWhitelistDomain == method) 314 else if (s_RemoveWhitelistDomain == method)
300 { 315 {
301 if (1 != pDispparams->cArgs) 316 if (1 != pDispparams->cArgs)
302 return DISP_E_BADPARAMCOUNT; 317 return DISP_E_BADPARAMCOUNT;
303 318
304 if (VT_BSTR != pDispparams->rgvarg[0].vt) 319 if (VT_BSTR != pDispparams->rgvarg[0].vt)
305 return DISP_E_TYPEMISMATCH; 320 return DISP_E_TYPEMISMATCH;
306 321
307 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 322 AdblockPlus::COM::IncomingParam domain_arg(pDispparams->rgvarg[0]);
308 if (domain.Length()) 323 if (!domain_arg.wstringConvertible())
309 { 324 {
310 settings->RemoveWhiteListedDomain((BSTR)domain); 325 return DISP_E_TYPEMISMATCH;
326 }
327 std::wstring domain = domain_arg.wstringValueNoexcept();
328 if (!domain.empty())
329 {
330 settings->RemoveWhiteListedDomain(to_CString(domain));
311 } 331 }
312 } 332 }
313 else if (s_GetAppLocale == method) 333 else if (s_GetAppLocale == method)
314 { 334 {
315 if (0 != pDispparams->cArgs) 335 if (0 != pDispparams->cArgs)
316 return DISP_E_BADPARAMCOUNT; 336 return DISP_E_BADPARAMCOUNT;
317 337
318 pVarResult->vt = VT_BSTR; 338 pVarResult->vt = VT_BSTR;
319 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); 339 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale());
320 } 340 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 CPluginClient* client = CPluginClient::GetInstance(); 374 CPluginClient* client = CPluginClient::GetInstance();
355 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsurl", L"")); 375 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsurl", L""));
356 } 376 }
357 } 377 }
358 else 378 else
359 return DISP_E_MEMBERNOTFOUND; 379 return DISP_E_MEMBERNOTFOUND;
360 380
361 return S_OK; 381 return S_OK;
362 } 382 }
363 383
OLDNEW
« no previous file with comments | « src/plugin/PluginClass.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld