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