Index: src/plugin/PluginUserSettings.cpp |
=================================================================== |
--- a/src/plugin/PluginUserSettings.cpp |
+++ b/src/plugin/PluginUserSettings.cpp |
@@ -4,367 +4,424 @@ |
#include "PluginSettings.h" |
#include "PluginClient.h" |
#include "../shared/Dictionary.h" |
+#include <unordered_map> |
-static const CString s_GetMessage = L"GetMessage"; |
-static const CString s_GetLanguageCount = L"GetLanguageCount"; |
-static const CString s_GetLanguageByIndex = L"GetLanguageByIndex"; |
-static const CString s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex"; |
-static const CString s_SetLanguage = L"SetLanguage"; |
-static const CString s_GetLanguage = L"GetLanguage"; |
-static const CString s_GetWhitelistDomains = L"GetWhitelistDomains"; |
-static const CString s_AddWhitelistDomain = L"AddWhitelistDomain"; |
-static const CString s_RemoveWhitelistDomain = L"RemoveWhitelistDomain"; |
-static const CString s_GetAppLocale = L"GetAppLocale"; |
-static const CString s_GetDocumentationLink = L"GetDocumentationLink"; |
-static const CString s_IsAcceptableAdsEnabled = L"IsAcceptableAdsEnabled"; |
-static const CString s_SetAcceptableAdsEnabled = L"SetAcceptableAdsEnabled"; |
-static const CString s_IsUpdate = L"IsUpdate"; |
-static const CString s_Methods[] = {s_GetMessage, s_GetLanguageCount, s_GetLanguageByIndex, s_GetLanguageTitleByIndex, s_SetLanguage, s_GetLanguage, s_GetWhitelistDomains, s_AddWhitelistDomain, s_RemoveWhitelistDomain, s_GetAppLocale, s_GetDocumentationLink, s_IsAcceptableAdsEnabled, s_SetAcceptableAdsEnabled, s_IsUpdate}; |
+namespace |
+{ |
+ enum UserSettingsMethods |
+ { |
+ dispatchID_GetMessage = 0, |
+ dispatchID_GetLanguageCount, |
+ dispatchID_GetLanguageByIndex, |
+ dispatchID_GetLanguageTitleByIndex, |
+ dispatchID_SetLanguage, |
+ dispatchID_GetLanguage, |
+ dispatchID_GetWhitelistDomains, |
+ dispatchID_AddWhitelistDomain, |
+ dispatchID_RemoveWhitelistDomain, |
+ dispatchID_GetAppLocale, |
+ dispatchID_GetDocumentationLink, |
+ dispatchID_IsAcceptableAdsEnabled, |
+ dispatchID_SetAcceptableAdsEnabled, |
+ dispatchID_IsUpdate, |
+ }; |
-CPluginUserSettings::CPluginUserSettings() |
-{ |
+ /** |
+ * Auxiliary for static initialization |
+ */ |
+ std::unordered_map<std::wstring, DISPID> InitMethodIndex() |
+ { |
+ std::unordered_map<std::wstring, DISPID> m; |
+ // try-block for safety during static initialization |
+ try |
+ { |
+ m.emplace(L"GetMessage", dispatchID_GetMessage); |
+ m.emplace(L"GetLanguageCount", dispatchID_GetLanguageCount); |
+ m.emplace(L"GetLanguageByIndex", dispatchID_GetLanguageByIndex); |
+ m.emplace(L"GetLanguageTitleByIndex", dispatchID_GetLanguageTitleByIndex); |
+ m.emplace(L"SetLanguage", dispatchID_SetLanguage); |
+ m.emplace(L"GetLanguage", dispatchID_GetLanguage); |
+ m.emplace(L"GetWhitelistDomains", dispatchID_GetWhitelistDomains); |
+ m.emplace(L"AddWhitelistDomain", dispatchID_AddWhitelistDomain); |
+ m.emplace(L"RemoveWhitelistDomain", dispatchID_RemoveWhitelistDomain); |
+ m.emplace(L"GetAppLocale", dispatchID_GetAppLocale); |
+ m.emplace(L"GetDocumentationLink", dispatchID_GetDocumentationLink); |
+ m.emplace(L"IsAcceptableAdsEnabled", dispatchID_IsAcceptableAdsEnabled); |
+ m.emplace(L"SetAcceptableAdsEnabled", dispatchID_SetAcceptableAdsEnabled); |
+ m.emplace(L"IsUpdate", dispatchID_IsUpdate); |
+ } |
+ catch(...) |
+ { |
+ } |
+ return m; |
+ } |
+ |
+ /** |
+ * Static map from method names to dispatch identifiers. |
+ */ |
+ std::unordered_map<std::wstring, DISPID> methodIndex = InitMethodIndex(); |
} |
- |
+// ENTRY POINT |
STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) |
{ |
- if (IID_IUnknown == riid || IID_IDispatch == riid) |
+ if (!ppvObj) |
{ |
- *ppvObj = (LPVOID)this; |
- return NOERROR; |
+ return E_POINTER; |
} |
- |
+ if (riid == IID_IUnknown || riid == IID_IDispatch) // GUID comparison does not throw |
+ { |
+ *ppvObj = static_cast<void *>(this); |
+ return S_OK; |
+ } |
return E_NOINTERFACE; |
} |
- |
-/* |
-Since CPluginUserSettings is not allocated on the heap, 'AddRef' and 'Release' don't need reference counting, |
-because CPluginUserSettings won't be deleted when reference counter == 0 |
-*/ |
- |
+/** |
+ * \par Limitation |
+ * CPluginUserSettings is not allocated on the heap. |
+ * It appears only as a member variable in CPluginTabBase. |
+ * 'AddRef' and 'Release' don't need reference counting because they don't present COM factories. |
+ */ |
ULONG __stdcall CPluginUserSettings::AddRef() |
{ |
return 1; |
} |
- |
ULONG __stdcall CPluginUserSettings::Release() |
{ |
return 1; |
} |
- |
STDMETHODIMP CPluginUserSettings::GetTypeInfoCount(UINT* pctinfo) |
{ |
return E_NOTIMPL; |
} |
- |
STDMETHODIMP CPluginUserSettings::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) |
{ |
return E_NOTIMPL; |
} |
- |
-STDMETHODIMP CPluginUserSettings::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) |
+/** |
+ * \par Limitation |
+ * The specification for this method in IDispatch maps an array of names to an array of identifiers. |
+ * This version only supports single-element arrays, which is enough for IE's JavaScript interpreter. |
+ */ |
+STDMETHODIMP CPluginUserSettings::GetIDsOfNames(REFIID, LPOLESTR* name, UINT count, LCID, DISPID* id) |
{ |
- if (!rgszNames) |
- return E_POINTER; |
- |
- if (!rgdispid) |
- return E_POINTER; |
- |
- if (1 != cNames) |
+ try |
+ { |
+ if (!name || !id) |
+ { |
+ return E_POINTER; |
+ } |
+ if (count != 1) |
+ { |
+ return E_FAIL; |
+ } |
+ auto item = methodIndex.find(*name); // unordered_map::find is not declared noexcept |
+ if (item==methodIndex.end()) |
+ { |
+ return DISP_E_UNKNOWNNAME; |
+ } |
+ *id = item->second; |
+ } |
+ catch (...) |
+ { |
return E_FAIL; |
- |
- size_t indxMethod = 0; |
- for (; indxMethod < countof(s_Methods); indxMethod++) |
- { |
- if (*rgszNames == s_Methods[indxMethod]) |
- break; |
} |
- |
- if (indxMethod == countof(s_Methods)) |
- return DISP_E_MEMBERNOTFOUND; |
- |
- *rgdispid = static_cast<DISPID>(indxMethod); |
- |
return S_OK; |
} |
- |
-static CString sGetLanguage() |
-{ |
- CPluginSettings* settings = CPluginSettings::GetInstance(); |
- return settings->GetSubscription(); |
-} |
- |
- |
CStringW sGetMessage(const CString& section, const CString& key) |
{ |
Dictionary* dictionary = Dictionary::GetInstance(); |
return CStringW(dictionary->Lookup(std::string(CW2A(section)), std::string(CW2A(key))).c_str()); |
} |
-std::wstring sGetMessage(const std::string& section, const std::string& key) |
-{ |
- Dictionary* dictionary = Dictionary::GetInstance(); |
- return dictionary->Lookup(section, key); |
-} |
- |
- |
STDMETHODIMP CPluginUserSettings::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispparams, VARIANT* pVarResult, |
EXCEPINFO* pExcepinfo, UINT* pArgErr) |
{ |
- if (!pDispparams) |
- return E_POINTER; |
+ try |
+ { |
+ 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
|
+ { |
+ return E_POINTER; |
+ } |
+ if (pDispparams->cNamedArgs != 0) |
+ { |
+ return DISP_E_NONAMEDARGS; |
+ } |
+ CPluginSettings* settings = CPluginSettings::GetInstance(); |
+ switch (dispidMember) |
+ { |
+ case dispatchID_GetMessage: |
+ { |
+ if (pDispparams->cArgs != 2) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (pDispparams->rgvarg[0].vt != VT_BSTR || pDispparams->rgvarg[1].vt != VT_BSTR) |
+ { |
+ return DISP_E_TYPEMISMATCH; |
+ } |
+ 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'
|
+ { |
+ CComBSTR key = pDispparams->rgvarg[0].bstrVal; |
+ CComBSTR section = pDispparams->rgvarg[1].bstrVal; |
+ CStringW message = sGetMessage((BSTR)section, (BSTR)key); |
- if (!pExcepinfo) |
- return E_POINTER; |
+ pVarResult->vt = VT_BSTR; |
+ pVarResult->bstrVal = SysAllocString(message); |
+ } |
+ } |
+ break; |
+ case dispatchID_GetLanguageCount: |
+ { |
+ if (pDispparams->cArgs != 0) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (pVarResult) |
+ { |
+ std::map<CString, CString> languageList = settings->GetFilterLanguageTitleList(); |
- if (pDispparams->cNamedArgs) |
- return DISP_E_NONAMEDARGS; |
+ pVarResult->vt = VT_I4; |
+ pVarResult->lVal = static_cast<LONG>(languageList.size()); |
+ } |
+ } |
+ break; |
+ case dispatchID_GetLanguageByIndex: |
+ { |
+ if (pDispparams->cArgs != 1) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (VT_I4 != pDispparams->rgvarg[0].vt) |
+ { |
+ return DISP_E_TYPEMISMATCH; |
+ } |
+ if (pVarResult) |
+ { |
+ int indx = pDispparams->rgvarg[0].lVal; |
- CPluginSettings* settings = CPluginSettings::GetInstance(); |
+ std::map<CString, CString> languageTitleList = settings->GetFilterLanguageTitleList(); |
- if (dispidMember < 0 || dispidMember >= countof(s_Methods)) |
- return DISP_E_BADINDEX; |
+ if (indx < 0 || indx >= (int)languageTitleList.size()) |
+ return DISP_E_EXCEPTION; |
- const CString& method = s_Methods[dispidMember]; |
+ CString language; |
- if (s_GetMessage == method) |
- { |
- if (2 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
+ int curIndx = 0; |
+ for(std::map<CString, CString>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it) |
+ { |
+ if (curIndx == indx) |
+ { |
+ language = it->first; |
+ break; |
+ } |
+ curIndx++; |
+ } |
- if (VT_BSTR != pDispparams->rgvarg[0].vt) |
- return DISP_E_TYPEMISMATCH; |
+ pVarResult->vt = VT_BSTR; |
+ pVarResult->bstrVal = SysAllocString(language); |
+ } |
+ } |
+ break; |
+ case dispatchID_GetLanguageTitleByIndex: |
+ { |
+ if (pDispparams->cArgs != 1) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (VT_I4 != pDispparams->rgvarg[0].vt) |
+ { |
+ return DISP_E_TYPEMISMATCH; |
+ } |
+ if (pVarResult) |
+ { |
+ int indx = pDispparams->rgvarg[0].lVal; |
- if (pVarResult) |
- { |
- CComBSTR key = pDispparams->rgvarg[0].bstrVal; |
- CComBSTR section = pDispparams->rgvarg[1].bstrVal; |
- CStringW message = sGetMessage((BSTR)section, (BSTR)key); |
+ std::map<CString, CString> languageTitleList = settings->GetFilterLanguageTitleList(); |
- pVarResult->vt = VT_BSTR; |
- pVarResult->bstrVal = SysAllocString(message); |
+ if (indx < 0 || indx >= (int)languageTitleList.size()) |
+ return DISP_E_EXCEPTION; |
+ |
+ CString languageTitle; |
+ |
+ int curIndx = 0; |
+ for(std::map<CString, CString>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it) |
+ { |
+ if (curIndx == indx) |
+ { |
+ languageTitle = it->second; |
+ break; |
+ } |
+ curIndx++; |
+ } |
+ |
+ pVarResult->vt = VT_BSTR; |
+ pVarResult->bstrVal = SysAllocString(languageTitle); |
+ } |
+ } |
+ break; |
+ case dispatchID_SetLanguage: |
+ { |
+ if (pDispparams->cArgs != 1) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (VT_BSTR != pDispparams->rgvarg[0].vt) |
+ { |
+ return DISP_E_TYPEMISMATCH; |
+ } |
+ CComBSTR url = pDispparams->rgvarg[0].bstrVal; |
+ settings->SetSubscription((BSTR)url); |
+ } |
+ break; |
+ case dispatchID_GetLanguage: |
+ { |
+ if (pDispparams->cArgs != 0) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (pVarResult) |
+ { |
+ CString url = settings->GetSubscription(); |
+ pVarResult->vt = VT_BSTR; |
+ pVarResult->bstrVal = SysAllocString(url); |
+ } |
+ } |
+ break; |
+ case dispatchID_GetWhitelistDomains: |
+ { |
+ if (pDispparams->cArgs != 0) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (pVarResult) |
+ { |
+ std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainList(); |
+ CString sWhiteList; |
+ for (size_t i = 0; i < whiteList.size(); i++) |
+ { |
+ if (!sWhiteList.IsEmpty()) |
+ { |
+ sWhiteList += ','; |
+ } |
+ sWhiteList += CString(whiteList[i].c_str()); |
+ } |
+ pVarResult->vt = VT_BSTR; |
+ pVarResult->bstrVal = SysAllocString(sWhiteList); |
+ } |
+ } |
+ break; |
+ case dispatchID_AddWhitelistDomain: |
+ { |
+ if (pDispparams->cArgs != 1) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (VT_BSTR != pDispparams->rgvarg[0].vt) |
+ { |
+ return DISP_E_TYPEMISMATCH; |
+ } |
+ CComBSTR domain = pDispparams->rgvarg[0].bstrVal; |
+ if (domain.Length()) |
+ { |
+ settings->AddWhiteListedDomain((BSTR)domain); |
+ } |
+ } |
+ break; |
+ case dispatchID_RemoveWhitelistDomain: |
+ { |
+ if (pDispparams->cArgs != 1) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (VT_BSTR != pDispparams->rgvarg[0].vt) |
+ { |
+ return DISP_E_TYPEMISMATCH; |
+ } |
+ CComBSTR domain = pDispparams->rgvarg[0].bstrVal; |
+ if (domain.Length()) |
+ { |
+ settings->RemoveWhiteListedDomain((BSTR)domain); |
+ } |
+ } |
+ break; |
+ case dispatchID_GetAppLocale: |
+ { |
+ if (pDispparams->cArgs != 0) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ pVarResult->vt = VT_BSTR; |
+ pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); |
+ } |
+ break; |
+ case dispatchID_GetDocumentationLink: |
+ { |
+ if (pDispparams->cArgs != 0) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ pVarResult->vt = VT_BSTR; |
+ pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()); |
+ } |
+ break; |
+ case dispatchID_IsAcceptableAdsEnabled: |
+ { |
+ if (pDispparams->cArgs != 0) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ pVarResult->vt = VT_BOOL; |
+ pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEnabled() ? VARIANT_TRUE : VARIANT_FALSE; |
+ } |
+ break; |
+ case dispatchID_SetAcceptableAdsEnabled: |
+ { |
+ if (pDispparams->cArgs != 1) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ if (pDispparams->rgvarg[0].vt != VT_BOOL) |
+ { |
+ return DISP_E_TYPEMISMATCH; |
+ } |
+ if (pDispparams->rgvarg[0].boolVal != VARIANT_FALSE) |
+ { |
+ CPluginClient* client = CPluginClient::GetInstance(); |
+ client->AddSubscription(client->GetPref(L"subscriptions_exceptionsurl", L"")); |
+ } |
+ else |
+ { |
+ CPluginClient* client = CPluginClient::GetInstance(); |
+ client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsurl", L"")); |
+ } |
+ } |
+ break; |
+ case dispatchID_IsUpdate: |
+ { |
+ if (pDispparams->cArgs != 0) |
+ { |
+ return DISP_E_BADPARAMCOUNT; |
+ } |
+ pVarResult->vt = VT_BOOL; |
+ pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayUpdatePage", false) ? VARIANT_TRUE : VARIANT_FALSE; |
+ } |
+ break; |
+ default: |
+ return DISP_E_MEMBERNOTFOUND; |
+ break; |
} |
} |
- else if (s_GetLanguageCount == method) |
+ catch(...) |
{ |
- if (pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (pVarResult) |
- { |
- std::map<CString, CString> languageList = settings->GetFilterLanguageTitleList(); |
- |
- pVarResult->vt = VT_I4; |
- pVarResult->lVal = static_cast<LONG>(languageList.size()); |
- } |
+ return E_FAIL; |
} |
- else if (s_GetLanguageByIndex == method) |
- { |
- if (1 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (VT_I4 != pDispparams->rgvarg[0].vt) |
- return DISP_E_TYPEMISMATCH; |
- |
- if (pVarResult) |
- { |
- int indx = pDispparams->rgvarg[0].lVal; |
- |
- std::map<CString, CString> languageTitleList = settings->GetFilterLanguageTitleList(); |
- |
- if (indx < 0 || indx >= (int)languageTitleList.size()) |
- return DISP_E_EXCEPTION; |
- |
- CString language; |
- |
- int curIndx = 0; |
- for(std::map<CString, CString>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it) |
- { |
- if (curIndx == indx) |
- { |
- language = it->first; |
- break; |
- } |
- |
- curIndx++; |
- } |
- |
- pVarResult->vt = VT_BSTR; |
- pVarResult->bstrVal = SysAllocString(language); |
- } |
- } |
- else if (s_GetLanguageTitleByIndex == method) |
- { |
- if (1 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (VT_I4 != pDispparams->rgvarg[0].vt) |
- return DISP_E_TYPEMISMATCH; |
- |
- if (pVarResult) |
- { |
- int indx = pDispparams->rgvarg[0].lVal; |
- |
- std::map<CString, CString> languageTitleList = settings->GetFilterLanguageTitleList(); |
- |
- if (indx < 0 || indx >= (int)languageTitleList.size()) |
- return DISP_E_EXCEPTION; |
- |
- CString languageTitle; |
- |
- int curIndx = 0; |
- for(std::map<CString, CString>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it) |
- { |
- if (curIndx == indx) |
- { |
- languageTitle = it->second; |
- break; |
- } |
- |
- curIndx++; |
- } |
- |
- pVarResult->vt = VT_BSTR; |
- pVarResult->bstrVal = SysAllocString(languageTitle); |
- } |
- } |
- else if (s_SetLanguage == method) |
- { |
- if (1 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (VT_BSTR != pDispparams->rgvarg[0].vt) |
- return DISP_E_TYPEMISMATCH; |
- |
- CComBSTR url = pDispparams->rgvarg[0].bstrVal; |
- |
- settings->SetSubscription((BSTR)url); |
- } |
- else if (s_GetLanguage == method) |
- { |
- if (pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (pVarResult) |
- { |
- CString url = settings->GetSubscription(); |
- |
- pVarResult->vt = VT_BSTR; |
- pVarResult->bstrVal = SysAllocString(url); |
- } |
- } |
- else if (s_GetWhitelistDomains == method) |
- { |
- if (pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (pVarResult) |
- { |
- std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainList(); |
- CString sWhiteList; |
- for (size_t i = 0; i < whiteList.size(); i++) |
- { |
- if (!sWhiteList.IsEmpty()) |
- { |
- sWhiteList += ','; |
- } |
- sWhiteList += CString(whiteList[i].c_str()); |
- } |
- |
- pVarResult->vt = VT_BSTR; |
- pVarResult->bstrVal = SysAllocString(sWhiteList); |
- } |
- } |
- else if (s_AddWhitelistDomain == method) |
- { |
- if (1 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (VT_BSTR != pDispparams->rgvarg[0].vt) |
- return DISP_E_TYPEMISMATCH; |
- |
- CComBSTR domain = pDispparams->rgvarg[0].bstrVal; |
- if (domain.Length()) |
- { |
- settings->AddWhiteListedDomain((BSTR)domain); |
- } |
- } |
- else if (s_RemoveWhitelistDomain == method) |
- { |
- if (1 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (VT_BSTR != pDispparams->rgvarg[0].vt) |
- return DISP_E_TYPEMISMATCH; |
- |
- CComBSTR domain = pDispparams->rgvarg[0].bstrVal; |
- if (domain.Length()) |
- { |
- settings->RemoveWhiteListedDomain((BSTR)domain); |
- } |
- } |
- else if (s_GetAppLocale == method) |
- { |
- if (0 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- pVarResult->vt = VT_BSTR; |
- pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); |
- } |
- else if (s_GetDocumentationLink == method) |
- { |
- if (0 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- pVarResult->vt = VT_BSTR; |
- pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()); |
- } |
- else if (s_IsAcceptableAdsEnabled == method) |
- { |
- if (0 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- pVarResult->vt = VT_BOOL; |
- pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEnabled() ? VARIANT_TRUE : VARIANT_FALSE; |
- } |
- else if (s_SetAcceptableAdsEnabled == method) |
- { |
- if (1 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- if (VT_BOOL != pDispparams->rgvarg[0].vt) |
- return DISP_E_TYPEMISMATCH; |
- |
- bool enable = VARIANT_FALSE != pDispparams->rgvarg[0].boolVal; |
- |
- if (enable) |
- { |
- CPluginClient* client = CPluginClient::GetInstance(); |
- client->AddSubscription(client->GetPref(L"subscriptions_exceptionsurl", L"")); |
- } |
- else |
- { |
- CPluginClient* client = CPluginClient::GetInstance(); |
- client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsurl", L"")); |
- } |
- } |
- else if (s_IsUpdate == method) |
- { |
- if (0 != pDispparams->cArgs) |
- return DISP_E_BADPARAMCOUNT; |
- |
- pVarResult->vt = VT_BOOL; |
- pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayUpdatePage", false); |
- } |
- else |
- return DISP_E_MEMBERNOTFOUND; |
- |
return S_OK; |
} |