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

Unified Diff: src/plugin/PluginUserSettings.cpp

Issue 5750789393874944: [IE] First round of ATL removal (Closed)
Patch Set: Created June 20, 2014, 9:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/plugin/PluginUserSettings.cpp
===================================================================
--- a/src/plugin/PluginUserSettings.cpp
+++ b/src/plugin/PluginUserSettings.cpp
@@ -3,21 +3,22 @@
#include <algorithm>
#include "PluginSettings.h"
#include "PluginClient.h"
+#include "COM_Client.h"
#include "../shared/Dictionary.h"
-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 std::wstring s_GetMessage = L"GetMessage";
+static const std::wstring s_GetLanguageCount = L"GetLanguageCount";
+static const std::wstring s_GetLanguageByIndex = L"GetLanguageByIndex";
+static const std::wstring s_GetLanguageTitleByIndex = L"GetLanguageTitleByIndex";
+static const std::wstring s_SetLanguage = L"SetLanguage";
+static const std::wstring s_GetLanguage = L"GetLanguage";
+static const std::wstring s_GetWhitelistDomains = L"GetWhitelistDomains";
+static const std::wstring s_AddWhitelistDomain = L"AddWhitelistDomain";
+static const std::wstring s_RemoveWhitelistDomain = L"RemoveWhitelistDomain";
+static const std::wstring s_GetAppLocale = L"GetAppLocale";
+static const std::wstring s_GetDocumentationLink = L"GetDocumentationLink";
-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};
+static const std::wstring s_Methods[] = {s_GetMessage, s_GetLanguageCount, s_GetLanguageByIndex, s_GetLanguageTitleByIndex, s_SetLanguage, s_GetLanguage, s_GetWhitelistDomains, s_AddWhitelistDomain, s_RemoveWhitelistDomain, s_GetAppLocale, s_GetDocumentationLink};
CPluginUserSettings::CPluginUserSettings()
{
@@ -92,19 +93,13 @@
}
-static CString sGetLanguage()
+static std::wstring 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();
@@ -129,7 +124,7 @@
if (dispidMember < 0 || dispidMember >= countof(s_Methods))
return DISP_E_BADINDEX;
- const CString& method = s_Methods[dispidMember];
+ const std::wstring method = s_Methods[dispidMember];
if (s_GetMessage == method)
{
@@ -141,12 +136,12 @@
if (pVarResult)
{
- CComBSTR key = pDispparams->rgvarg[0].bstrVal;
- CComBSTR section = pDispparams->rgvarg[1].bstrVal;
- CStringW message = sGetMessage((BSTR)section, (BSTR)key);
+ std::wstring key = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
+ std::wstring section = Incoming_BSTR( pDispparams->rgvarg[1].bstrVal );
+ // [EH] We should change the interface to Dictionary to accept wstring arguments.
+ std::wstring message = sGetMessage( ABP::debug::narrow( section ), ABP::debug::narrow( key ) );
- pVarResult->vt = VT_BSTR;
- pVarResult->bstrVal = SysAllocString(message);
+ invoke_result_wstring( *pVarResult, message );
}
}
else if (s_GetLanguageCount == method)
@@ -156,7 +151,7 @@
if (pVarResult)
{
- std::map<CString, CString> languageList = settings->GetFilterLanguageTitleList();
+ std::map<std::wstring, std::wstring> languageList = settings->GetFilterLanguageTitleList();
pVarResult->vt = VT_I4;
pVarResult->lVal = static_cast<LONG>(languageList.size());
@@ -174,15 +169,15 @@
{
int indx = pDispparams->rgvarg[0].lVal;
- std::map<CString, CString> languageTitleList = settings->GetFilterLanguageTitleList();
+ std::map<std::wstring, std::wstring> languageTitleList = settings->GetFilterLanguageTitleList();
if (indx < 0 || indx >= (int)languageTitleList.size())
return DISP_E_EXCEPTION;
- CString language;
+ std::wstring language;
int curIndx = 0;
- for(std::map<CString, CString>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it)
+ for(std::map<std::wstring, std::wstring>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it)
{
if (curIndx == indx)
{
@@ -192,9 +187,7 @@
curIndx++;
}
-
- pVarResult->vt = VT_BSTR;
- pVarResult->bstrVal = SysAllocString(language);
+ invoke_result_wstring( *pVarResult, language );
}
}
else if (s_GetLanguageTitleByIndex == method)
@@ -209,15 +202,15 @@
{
int indx = pDispparams->rgvarg[0].lVal;
- std::map<CString, CString> languageTitleList = settings->GetFilterLanguageTitleList();
+ std::map<std::wstring, std::wstring> languageTitleList = settings->GetFilterLanguageTitleList();
if (indx < 0 || indx >= (int)languageTitleList.size())
return DISP_E_EXCEPTION;
- CString languageTitle;
+ std::wstring languageTitle;
int curIndx = 0;
- for(std::map<CString, CString>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it)
+ for(std::map<std::wstring, std::wstring>::const_iterator it = languageTitleList.begin(); it != languageTitleList.end(); ++it)
{
if (curIndx == indx)
{
@@ -227,9 +220,7 @@
curIndx++;
}
-
- pVarResult->vt = VT_BSTR;
- pVarResult->bstrVal = SysAllocString(languageTitle);
+ invoke_result_wstring( *pVarResult, languageTitle );
}
}
else if (s_SetLanguage == method)
@@ -240,9 +231,8 @@
if (VT_BSTR != pDispparams->rgvarg[0].vt)
return DISP_E_TYPEMISMATCH;
- CComBSTR url = pDispparams->rgvarg[0].bstrVal;
-
- settings->SetSubscription((BSTR)url);
+ std::wstring url = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
+ settings->SetSubscription( url );
}
else if (s_GetLanguage == method)
{
@@ -251,10 +241,7 @@
if (pVarResult)
{
- CString url = settings->GetSubscription();
-
- pVarResult->vt = VT_BSTR;
- pVarResult->bstrVal = SysAllocString(url);
+ invoke_result_wstring( *pVarResult, settings->GetSubscription() );
}
}
else if (s_GetWhitelistDomains == method)
@@ -265,18 +252,16 @@
if (pVarResult)
{
std::vector<std::wstring> whiteList = settings->GetWhiteListedDomainList();
- CString sWhiteList;
+ std::wstring whitelist_csv;
for (size_t i = 0; i < whiteList.size(); i++)
{
- if (!sWhiteList.IsEmpty())
+ if ( !whitelist_csv.empty() )
{
- sWhiteList += ',';
+ whitelist_csv += ',';
}
- sWhiteList += CString(whiteList[i].c_str());
+ whitelist_csv += whiteList[i];
}
-
- pVarResult->vt = VT_BSTR;
- pVarResult->bstrVal = SysAllocString(sWhiteList);
+ invoke_result_wstring( *pVarResult, whitelist_csv );
}
}
else if (s_AddWhitelistDomain == method)
@@ -287,10 +272,10 @@
if (VT_BSTR != pDispparams->rgvarg[0].vt)
return DISP_E_TYPEMISMATCH;
- CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
- if (domain.Length())
+ std::wstring domain = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
+ if ( !domain.empty() )
{
- settings->AddWhiteListedDomain((BSTR)domain);
+ settings->AddWhiteListedDomain( domain );
}
}
else if (s_RemoveWhitelistDomain == method)
@@ -301,10 +286,10 @@
if (VT_BSTR != pDispparams->rgvarg[0].vt)
return DISP_E_TYPEMISMATCH;
- CComBSTR domain = pDispparams->rgvarg[0].bstrVal;
- if (domain.Length())
+ std::wstring domain = Incoming_BSTR( pDispparams->rgvarg[0].bstrVal );
+ if ( !domain.empty() )
{
- settings->RemoveWhiteListedDomain((BSTR)domain);
+ settings->RemoveWhiteListedDomain( domain );
}
}
else if (s_GetAppLocale == method)
@@ -312,16 +297,20 @@
if (0 != pDispparams->cArgs)
return DISP_E_BADPARAMCOUNT;
- pVarResult->vt = VT_BSTR;
- pVarResult->bstrVal = SysAllocString(settings->GetAppLocale());
+ if ( pVarResult )
+ {
+ invoke_result_wstring( *pVarResult, settings->GetAppLocale() );
+ }
}
else if (s_GetDocumentationLink == method)
{
if (0 != pDispparams->cArgs)
return DISP_E_BADPARAMCOUNT;
- pVarResult->vt = VT_BSTR;
- pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink());
+ if ( pVarResult )
+ {
+ invoke_result_wstring( *pVarResult, settings->GetDocumentationLink() );
+ }
}
else
return DISP_E_MEMBERNOTFOUND;

Powered by Google App Engine
This is Rietveld