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