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

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

Issue 6650591174459392: Issues #276, #1163 - introduce class IncomingParam (Closed)
Left Patch Set: Created July 25, 2014, 11:27 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginClass.cpp ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 "COM_Value.h"
5 #include "PluginSettings.h" 5 #include "PluginSettings.h"
6 #include "PluginClient.h" 6 #include "PluginClient.h"
7 #include "../shared/Dictionary.h" 7 #include "../shared/Dictionary.h"
8 8
9 static const CString s_GetMessage = L"GetMessage"; 9 static const CString s_GetMessage = L"GetMessage";
10 static const CString s_GetLanguageCount = L"GetLanguageCount"; 10 static const CString s_GetLanguageCount = L"GetLanguageCount";
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return E_POINTER; 124 return E_POINTER;
125 125
126 if (pDispparams->cNamedArgs) 126 if (pDispparams->cNamedArgs)
127 return DISP_E_NONAMEDARGS; 127 return DISP_E_NONAMEDARGS;
128 128
129 CPluginSettings* settings = CPluginSettings::GetInstance(); 129 CPluginSettings* settings = CPluginSettings::GetInstance();
130 130
131 if (dispidMember < 0 || dispidMember >= countof(s_Methods)) 131 if (dispidMember < 0 || dispidMember >= countof(s_Methods))
132 return DISP_E_BADINDEX; 132 return DISP_E_BADINDEX;
133 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 */
134 const CString& method = s_Methods[dispidMember]; 139 const CString& method = s_Methods[dispidMember];
135
136 if (s_GetMessage == method) 140 if (s_GetMessage == method)
137 { 141 {
138 if (2 != pDispparams->cArgs) 142 /*
139 return DISP_E_BADPARAMCOUNT; 143 * If the caller ignores the value, we can elide the body since it has no si de-effects.
140 144 */
141 if (VT_BSTR != pDispparams->rgvarg[0].vt) 145 if (pVarResult)
142 return DISP_E_TYPEMISMATCH; 146 {
143 147 if (2 != pDispparams->cArgs)
144 if (pVarResult) 148 return DISP_E_BADPARAMCOUNT;
145 { 149
146 AdblockPlus::COM::Incoming_Param key(pDispparams->rgvarg[0].bstrVal); 150 AdblockPlus::COM::IncomingParam key(pDispparams->rgvarg[0]);
147 AdblockPlus::COM::Incoming_Param section(pDispparams->rgvarg[1].bstrVal); 151 AdblockPlus::COM::IncomingParam section(pDispparams->rgvarg[1]);
148 CStringW message = sGetMessage(to_CString(section), to_CString(key)); 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()));
149 157
150 pVarResult->vt = VT_BSTR; 158 pVarResult->vt = VT_BSTR;
151 pVarResult->bstrVal = SysAllocString(message); 159 pVarResult->bstrVal = SysAllocString(message);
152 } 160 }
153 } 161 }
154 else if (s_GetLanguageCount == method) 162 else if (s_GetLanguageCount == method)
155 { 163 {
156 if (pDispparams->cArgs) 164 if (pDispparams->cArgs)
157 return DISP_E_BADPARAMCOUNT; 165 return DISP_E_BADPARAMCOUNT;
158 166
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 243 }
236 } 244 }
237 else if (s_SetLanguage == method) 245 else if (s_SetLanguage == method)
238 { 246 {
239 if (1 != pDispparams->cArgs) 247 if (1 != pDispparams->cArgs)
240 return DISP_E_BADPARAMCOUNT; 248 return DISP_E_BADPARAMCOUNT;
241 249
242 if (VT_BSTR != pDispparams->rgvarg[0].vt) 250 if (VT_BSTR != pDispparams->rgvarg[0].vt)
243 return DISP_E_TYPEMISMATCH; 251 return DISP_E_TYPEMISMATCH;
244 252
245 AdblockPlus::COM::Incoming_Param url(pDispparams->rgvarg[0].bstrVal); 253 AdblockPlus::COM::IncomingParam url(pDispparams->rgvarg[0]);
246 settings->SetSubscription(url); 254 if (!url.wstringConvertible())
255 {
256 return DISP_E_TYPEMISMATCH;
257 }
258 settings->SetSubscription(url.wstringValueNoexcept());
247 } 259 }
248 else if (s_GetLanguage == method) 260 else if (s_GetLanguage == method)
249 { 261 {
250 if (pDispparams->cArgs) 262 if (pDispparams->cArgs)
251 return DISP_E_BADPARAMCOUNT; 263 return DISP_E_BADPARAMCOUNT;
252 264
253 if (pVarResult) 265 if (pVarResult)
254 { 266 {
255 CString url = settings->GetSubscription(); 267 CString url = settings->GetSubscription();
256 268
(...skipping 24 matching lines...) Expand all
281 } 293 }
282 } 294 }
283 else if (s_AddWhitelistDomain == method) 295 else if (s_AddWhitelistDomain == method)
284 { 296 {
285 if (1 != pDispparams->cArgs) 297 if (1 != pDispparams->cArgs)
286 return DISP_E_BADPARAMCOUNT; 298 return DISP_E_BADPARAMCOUNT;
287 299
288 if (VT_BSTR != pDispparams->rgvarg[0].vt) 300 if (VT_BSTR != pDispparams->rgvarg[0].vt)
289 return DISP_E_TYPEMISMATCH; 301 return DISP_E_TYPEMISMATCH;
290 302
291 AdblockPlus::COM::Incoming_Param domain(pDispparams->rgvarg[0].bstrVal); 303 AdblockPlus::COM::IncomingParam domain_arg(pDispparams->rgvarg[0]);
304 if (!domain_arg.wstringConvertible())
305 {
306 return DISP_E_TYPEMISMATCH;
307 }
308 std::wstring domain = domain_arg.wstringValueNoexcept();
292 if (!domain.empty()) 309 if (!domain.empty())
293 { 310 {
294 settings->AddWhiteListedDomain(to_CString(domain)); 311 settings->AddWhiteListedDomain(to_CString(domain));
295 } 312 }
296 } 313 }
297 else if (s_RemoveWhitelistDomain == method) 314 else if (s_RemoveWhitelistDomain == method)
298 { 315 {
299 if (1 != pDispparams->cArgs) 316 if (1 != pDispparams->cArgs)
300 return DISP_E_BADPARAMCOUNT; 317 return DISP_E_BADPARAMCOUNT;
301 318
302 if (VT_BSTR != pDispparams->rgvarg[0].vt) 319 if (VT_BSTR != pDispparams->rgvarg[0].vt)
303 return DISP_E_TYPEMISMATCH; 320 return DISP_E_TYPEMISMATCH;
304 321
305 AdblockPlus::COM::Incoming_Param domain(pDispparams->rgvarg[0].bstrVal); 322 AdblockPlus::COM::IncomingParam domain_arg(pDispparams->rgvarg[0]);
323 if (!domain_arg.wstringConvertible())
324 {
325 return DISP_E_TYPEMISMATCH;
326 }
327 std::wstring domain = domain_arg.wstringValueNoexcept();
306 if (!domain.empty()) 328 if (!domain.empty())
307 { 329 {
308 settings->RemoveWhiteListedDomain(to_CString(domain)); 330 settings->RemoveWhiteListedDomain(to_CString(domain));
309 } 331 }
310 } 332 }
311 else if (s_GetAppLocale == method) 333 else if (s_GetAppLocale == method)
312 { 334 {
313 if (0 != pDispparams->cArgs) 335 if (0 != pDispparams->cArgs)
314 return DISP_E_BADPARAMCOUNT; 336 return DISP_E_BADPARAMCOUNT;
315 337
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 CPluginClient* client = CPluginClient::GetInstance(); 374 CPluginClient* client = CPluginClient::GetInstance();
353 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsurl", L"")); 375 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsurl", L""));
354 } 376 }
355 } 377 }
356 else 378 else
357 return DISP_E_MEMBERNOTFOUND; 379 return DISP_E_MEMBERNOTFOUND;
358 380
359 return S_OK; 381 return S_OK;
360 } 382 }
361 383
LEFTRIGHT

Powered by Google App Engine
This is Rietveld