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

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

Issue 5750789393874944: [IE] First round of ATL removal (Closed)
Patch Set: Created June 20, 2014, 9:22 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 "COM_Client.h"
6 #include "../shared/Dictionary.h" 7 #include "../shared/Dictionary.h"
7 8
8 static const CString s_GetMessage = L"GetMessage"; 9 static const std::wstring s_GetMessage = L"GetMessage";
9 static const CString s_GetLanguageCount = L"GetLanguageCount"; 10 static const std::wstring s_GetLanguageCount = L"GetLanguageCount";
10 static const CString s_GetLanguageByIndex = L"GetLanguageByIndex"; 11 static const std::wstring s_GetLanguageByIndex = L"GetLanguageByIndex";
11 static const CString s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex"; 12 static const std::wstring s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex" ;
12 static const CString s_SetLanguage = L"SetLanguage"; 13 static const std::wstring s_SetLanguage = L"SetLanguage";
13 static const CString s_GetLanguage = L"GetLanguage"; 14 static const std::wstring s_GetLanguage = L"GetLanguage";
14 static const CString s_GetWhitelistDomains = L"GetWhitelistDomains"; 15 static const std::wstring s_GetWhitelistDomains = L"GetWhitelistDomains";
15 static const CString s_AddWhitelistDomain = L"AddWhitelistDomain"; 16 static const std::wstring s_AddWhitelistDomain = L"AddWhitelistDomain";
16 static const CString s_RemoveWhitelistDomain = L"RemoveWhitelistDomain"; 17 static const std::wstring s_RemoveWhitelistDomain = L"RemoveWhitelistDomain";
17 static const CString s_GetAppLocale = L"GetAppLocale"; 18 static const std::wstring s_GetAppLocale = L"GetAppLocale";
18 static const CString s_GetDocumentationLink = L"GetDocumentationLink"; 19 static const std::wstring s_GetDocumentationLink = L"GetDocumentationLink";
19 20
20 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}; 21 static const std::wstring s_Methods[] = {s_GetMessage, s_GetLanguageCount, s_Get LanguageByIndex, s_GetLanguageTitleByIndex, s_SetLanguage, s_GetLanguage, s_GetW hitelistDomains, s_AddWhitelistDomain, s_RemoveWhitelistDomain, s_GetAppLocale, s_GetDocumentationLink};
21 22
22 CPluginUserSettings::CPluginUserSettings() 23 CPluginUserSettings::CPluginUserSettings()
23 { 24 {
24 } 25 }
25 26
26 27
27 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) 28 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj)
28 { 29 {
29 if (IID_IUnknown == riid || IID_IDispatch == riid) 30 if (IID_IUnknown == riid || IID_IDispatch == riid)
30 { 31 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 86
86 if (indxMethod == countof(s_Methods)) 87 if (indxMethod == countof(s_Methods))
87 return DISP_E_MEMBERNOTFOUND; 88 return DISP_E_MEMBERNOTFOUND;
88 89
89 *rgdispid = static_cast<DISPID>(indxMethod); 90 *rgdispid = static_cast<DISPID>(indxMethod);
90 91
91 return S_OK; 92 return S_OK;
92 } 93 }
93 94
94 95
95 static CString sGetLanguage() 96 static std::wstring sGetLanguage()
96 { 97 {
97 CPluginSettings* settings = CPluginSettings::GetInstance(); 98 CPluginSettings* settings = CPluginSettings::GetInstance();
98 return settings->GetSubscription(); 99 return settings->GetSubscription();
99 } 100 }
100 101
101 102
102 CStringW sGetMessage(const CString& section, const CString& key)
103 {
104 Dictionary* dictionary = Dictionary::GetInstance();
105 return CStringW(dictionary->Lookup(std::string(CW2A(section)), std::string(CW2 A(key))).c_str());
106 }
107
108 std::wstring sGetMessage(const std::string& section, const std::string& key) 103 std::wstring sGetMessage(const std::string& section, const std::string& key)
109 { 104 {
110 Dictionary* dictionary = Dictionary::GetInstance(); 105 Dictionary* dictionary = Dictionary::GetInstance();
111 return dictionary->Lookup(section, key); 106 return dictionary->Lookup(section, key);
112 } 107 }
113 108
114 109
115 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult, 110 STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult,
116 EXCEPINFO* pExcepinfo, UINT* pArgErr) 111 EXCEPINFO* pExcepinfo, UINT* pArgErr)
117 { 112 {
118 if (!pDispparams) 113 if (!pDispparams)
119 return E_POINTER; 114 return E_POINTER;
120 115
121 if (!pExcepinfo) 116 if (!pExcepinfo)
122 return E_POINTER; 117 return E_POINTER;
123 118
124 if (pDispparams->cNamedArgs) 119 if (pDispparams->cNamedArgs)
125 return DISP_E_NONAMEDARGS; 120 return DISP_E_NONAMEDARGS;
126 121
127 CPluginSettings* settings = CPluginSettings::GetInstance(); 122 CPluginSettings* settings = CPluginSettings::GetInstance();
128 123
129 if (dispidMember < 0 || dispidMember >= countof(s_Methods)) 124 if (dispidMember < 0 || dispidMember >= countof(s_Methods))
130 return DISP_E_BADINDEX; 125 return DISP_E_BADINDEX;
131 126
132 const CString& method = s_Methods[dispidMember]; 127 const std::wstring method = s_Methods[dispidMember];
133 128
134 if (s_GetMessage == method) 129 if (s_GetMessage == method)
135 { 130 {
136 if (2 != pDispparams->cArgs) 131 if (2 != pDispparams->cArgs)
137 return DISP_E_BADPARAMCOUNT; 132 return DISP_E_BADPARAMCOUNT;
138 133
139 if (VT_BSTR != pDispparams->rgvarg[0].vt) 134 if (VT_BSTR != pDispparams->rgvarg[0].vt)
140 return DISP_E_TYPEMISMATCH; 135 return DISP_E_TYPEMISMATCH;
141 136
142 if (pVarResult) 137 if (pVarResult)
143 { 138 {
144 CComBSTR key = pDispparams->rgvarg[0].bstrVal; 139 std::wstring key = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
145 CComBSTR section = pDispparams->rgvarg[1].bstrVal; 140 std::wstring section = Incoming_BSTR( pDispparams->rgvarg[1].bstrVal );
146 CStringW message = sGetMessage((BSTR)section, (BSTR)key); 141 // [EH] We should change the interface to Dictionary to accept wstring arg uments.
142 std::wstring message = sGetMessage( ABP::debug::narrow( section ), ABP::de bug::narrow( key ) );
147 143
148 pVarResult->vt = VT_BSTR; 144 invoke_result_wstring( *pVarResult, message );
149 pVarResult->bstrVal = SysAllocString(message);
150 } 145 }
151 } 146 }
152 else if (s_GetLanguageCount == method) 147 else if (s_GetLanguageCount == method)
153 { 148 {
154 if (pDispparams->cArgs) 149 if (pDispparams->cArgs)
155 return DISP_E_BADPARAMCOUNT; 150 return DISP_E_BADPARAMCOUNT;
156 151
157 if (pVarResult) 152 if (pVarResult)
158 { 153 {
159 std::map<CString, CString> languageList = settings->GetFilterLanguageTitle List(); 154 std::map<std::wstring, std::wstring> languageList = settings->GetFilterLan guageTitleList();
160 155
161 pVarResult->vt = VT_I4; 156 pVarResult->vt = VT_I4;
162 pVarResult->lVal = static_cast<LONG>(languageList.size()); 157 pVarResult->lVal = static_cast<LONG>(languageList.size());
163 } 158 }
164 } 159 }
165 else if (s_GetLanguageByIndex == method) 160 else if (s_GetLanguageByIndex == method)
166 { 161 {
167 if (1 != pDispparams->cArgs) 162 if (1 != pDispparams->cArgs)
168 return DISP_E_BADPARAMCOUNT; 163 return DISP_E_BADPARAMCOUNT;
169 164
170 if (VT_I4 != pDispparams->rgvarg[0].vt) 165 if (VT_I4 != pDispparams->rgvarg[0].vt)
171 return DISP_E_TYPEMISMATCH; 166 return DISP_E_TYPEMISMATCH;
172 167
173 if (pVarResult) 168 if (pVarResult)
174 { 169 {
175 int indx = pDispparams->rgvarg[0].lVal; 170 int indx = pDispparams->rgvarg[0].lVal;
176 171
177 std::map<CString, CString> languageTitleList = settings->GetFilterLanguage TitleList(); 172 std::map<std::wstring, std::wstring> languageTitleList = settings->GetFilt erLanguageTitleList();
178 173
179 if (indx < 0 || indx >= (int)languageTitleList.size()) 174 if (indx < 0 || indx >= (int)languageTitleList.size())
180 return DISP_E_EXCEPTION; 175 return DISP_E_EXCEPTION;
181 176
182 CString language; 177 std::wstring language;
183 178
184 int curIndx = 0; 179 int curIndx = 0;
185 for(std::map<CString, CString>::const_iterator it = languageTitleList.begi n(); it != languageTitleList.end(); ++it) 180 for(std::map<std::wstring, std::wstring>::const_iterator it = languageTitl eList.begin(); it != languageTitleList.end(); ++it)
186 { 181 {
187 if (curIndx == indx) 182 if (curIndx == indx)
188 { 183 {
189 language = it->first; 184 language = it->first;
190 break; 185 break;
191 } 186 }
192 187
193 curIndx++; 188 curIndx++;
194 } 189 }
195 190 invoke_result_wstring( *pVarResult, language );
196 pVarResult->vt = VT_BSTR;
197 pVarResult->bstrVal = SysAllocString(language);
198 } 191 }
199 } 192 }
200 else if (s_GetLanguageTitleByIndex == method) 193 else if (s_GetLanguageTitleByIndex == method)
201 { 194 {
202 if (1 != pDispparams->cArgs) 195 if (1 != pDispparams->cArgs)
203 return DISP_E_BADPARAMCOUNT; 196 return DISP_E_BADPARAMCOUNT;
204 197
205 if (VT_I4 != pDispparams->rgvarg[0].vt) 198 if (VT_I4 != pDispparams->rgvarg[0].vt)
206 return DISP_E_TYPEMISMATCH; 199 return DISP_E_TYPEMISMATCH;
207 200
208 if (pVarResult) 201 if (pVarResult)
209 { 202 {
210 int indx = pDispparams->rgvarg[0].lVal; 203 int indx = pDispparams->rgvarg[0].lVal;
211 204
212 std::map<CString, CString> languageTitleList = settings->GetFilterLanguage TitleList(); 205 std::map<std::wstring, std::wstring> languageTitleList = settings->GetFilt erLanguageTitleList();
213 206
214 if (indx < 0 || indx >= (int)languageTitleList.size()) 207 if (indx < 0 || indx >= (int)languageTitleList.size())
215 return DISP_E_EXCEPTION; 208 return DISP_E_EXCEPTION;
216 209
217 CString languageTitle; 210 std::wstring languageTitle;
218 211
219 int curIndx = 0; 212 int curIndx = 0;
220 for(std::map<CString, CString>::const_iterator it = languageTitleList.begi n(); it != languageTitleList.end(); ++it) 213 for(std::map<std::wstring, std::wstring>::const_iterator it = languageTitl eList.begin(); it != languageTitleList.end(); ++it)
221 { 214 {
222 if (curIndx == indx) 215 if (curIndx == indx)
223 { 216 {
224 languageTitle = it->second; 217 languageTitle = it->second;
225 break; 218 break;
226 } 219 }
227 220
228 curIndx++; 221 curIndx++;
229 } 222 }
230 223 invoke_result_wstring( *pVarResult, languageTitle );
231 pVarResult->vt = VT_BSTR;
232 pVarResult->bstrVal = SysAllocString(languageTitle);
233 } 224 }
234 } 225 }
235 else if (s_SetLanguage == method) 226 else if (s_SetLanguage == method)
236 { 227 {
237 if (1 != pDispparams->cArgs) 228 if (1 != pDispparams->cArgs)
238 return DISP_E_BADPARAMCOUNT; 229 return DISP_E_BADPARAMCOUNT;
239 230
240 if (VT_BSTR != pDispparams->rgvarg[0].vt) 231 if (VT_BSTR != pDispparams->rgvarg[0].vt)
241 return DISP_E_TYPEMISMATCH; 232 return DISP_E_TYPEMISMATCH;
242 233
243 CComBSTR url = pDispparams->rgvarg[0].bstrVal; 234 std::wstring url = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
244 235 settings->SetSubscription( url );
245 settings->SetSubscription((BSTR)url);
246 } 236 }
247 else if (s_GetLanguage == method) 237 else if (s_GetLanguage == method)
248 { 238 {
249 if (pDispparams->cArgs) 239 if (pDispparams->cArgs)
250 return DISP_E_BADPARAMCOUNT; 240 return DISP_E_BADPARAMCOUNT;
251 241
252 if (pVarResult) 242 if (pVarResult)
253 { 243 {
254 CString url = settings->GetSubscription(); 244 invoke_result_wstring( *pVarResult, settings->GetSubscription() );
255
256 pVarResult->vt = VT_BSTR;
257 pVarResult->bstrVal = SysAllocString(url);
258 } 245 }
259 } 246 }
260 else if (s_GetWhitelistDomains == method) 247 else if (s_GetWhitelistDomains == method)
261 { 248 {
262 if (pDispparams->cArgs) 249 if (pDispparams->cArgs)
263 return DISP_E_BADPARAMCOUNT; 250 return DISP_E_BADPARAMCOUNT;
264 251
265 if (pVarResult) 252 if (pVarResult)
266 { 253 {
267 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainList() ; 254 std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainList() ;
268 CString sWhiteList; 255 std::wstring whitelist_csv;
269 for (size_t i = 0; i < whiteList.size(); i++) 256 for (size_t i = 0; i < whiteList.size(); i++)
270 { 257 {
271 if (!sWhiteList.IsEmpty()) 258 if ( !whitelist_csv.empty() )
272 { 259 {
273 sWhiteList += ','; 260 whitelist_csv += ',';
274 } 261 }
275 sWhiteList += CString(whiteList[i].c_str()); 262 whitelist_csv += whiteList[i];
276 } 263 }
277 264 invoke_result_wstring( *pVarResult, whitelist_csv );
278 pVarResult->vt = VT_BSTR;
279 pVarResult->bstrVal = SysAllocString(sWhiteList);
280 } 265 }
281 } 266 }
282 else if (s_AddWhitelistDomain == method) 267 else if (s_AddWhitelistDomain == method)
283 { 268 {
284 if (1 != pDispparams->cArgs) 269 if (1 != pDispparams->cArgs)
285 return DISP_E_BADPARAMCOUNT; 270 return DISP_E_BADPARAMCOUNT;
286 271
287 if (VT_BSTR != pDispparams->rgvarg[0].vt) 272 if (VT_BSTR != pDispparams->rgvarg[0].vt)
288 return DISP_E_TYPEMISMATCH; 273 return DISP_E_TYPEMISMATCH;
289 274
290 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 275 std::wstring domain = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
291 if (domain.Length()) 276 if ( !domain.empty() )
292 { 277 {
293 settings->AddWhiteListedDomain((BSTR)domain); 278 settings->AddWhiteListedDomain( domain );
294 } 279 }
295 } 280 }
296 else if (s_RemoveWhitelistDomain == method) 281 else if (s_RemoveWhitelistDomain == method)
297 { 282 {
298 if (1 != pDispparams->cArgs) 283 if (1 != pDispparams->cArgs)
299 return DISP_E_BADPARAMCOUNT; 284 return DISP_E_BADPARAMCOUNT;
300 285
301 if (VT_BSTR != pDispparams->rgvarg[0].vt) 286 if (VT_BSTR != pDispparams->rgvarg[0].vt)
302 return DISP_E_TYPEMISMATCH; 287 return DISP_E_TYPEMISMATCH;
303 288
304 CComBSTR domain = pDispparams->rgvarg[0].bstrVal; 289 std::wstring domain = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
305 if (domain.Length()) 290 if ( !domain.empty() )
306 { 291 {
307 settings->RemoveWhiteListedDomain((BSTR)domain); 292 settings->RemoveWhiteListedDomain( domain );
308 } 293 }
309 } 294 }
310 else if (s_GetAppLocale == method) 295 else if (s_GetAppLocale == method)
311 { 296 {
312 if (0 != pDispparams->cArgs) 297 if (0 != pDispparams->cArgs)
313 return DISP_E_BADPARAMCOUNT; 298 return DISP_E_BADPARAMCOUNT;
314 299
315 pVarResult->vt = VT_BSTR; 300 if ( pVarResult )
316 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); 301 {
302 invoke_result_wstring( *pVarResult, settings->GetAppLocale() );
303 }
317 } 304 }
318 else if (s_GetDocumentationLink == method) 305 else if (s_GetDocumentationLink == method)
319 { 306 {
320 if (0 != pDispparams->cArgs) 307 if (0 != pDispparams->cArgs)
321 return DISP_E_BADPARAMCOUNT; 308 return DISP_E_BADPARAMCOUNT;
322 309
323 pVarResult->vt = VT_BSTR; 310 if ( pVarResult )
324 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()); 311 {
312 invoke_result_wstring( *pVarResult, settings->GetDocumentationLink() );
313 }
325 } 314 }
326 else 315 else
327 return DISP_E_MEMBERNOTFOUND; 316 return DISP_E_MEMBERNOTFOUND;
328 317
329 return S_OK; 318 return S_OK;
330 } 319 }
331 320
OLDNEW

Powered by Google App Engine
This is Rietveld