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

Unified Diff: src/plugin/PluginClass.cpp

Issue 10897028: Create a shared dictionary class for plugin and engine (Closed)
Patch Set: Created June 7, 2013, 12:42 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/PluginClass.cpp
===================================================================
--- a/src/plugin/PluginClass.cpp
+++ b/src/plugin/PluginClass.cpp
@@ -1,27 +1,28 @@
#include "PluginStdAfx.h"
#include "PluginClass.h"
-#include "PluginDictionary.h"
#include "PluginSettings.h"
#include "PluginSystem.h"
#ifdef SUPPORT_FILTER
#include "PluginFilter.h"
#endif
#include "PluginMimeFilterClient.h"
#include "PluginClient.h"
#include "PluginClientFactory.h"
#include "PluginHttpRequest.h"
#include "PluginMutex.h"
#include "DownloadSource.h"
#include "sddl.h"
#include "PluginUtil.h"
#include "PluginUserSettings.h"
+#include "../shared/Dictionary.h"
+
#ifdef DEBUG_HIDE_EL
DWORD profileTime = 0;
#endif
typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR);
typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPRECT);
typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE);
@@ -551,36 +552,40 @@ void CPluginClass::ShowStatusBar()
if (SUCCEEDED(hr))
{
if (!isVisible)
{
if (!settings->GetBool("statusbarasked", false))
{
SHANDLE_PTR pBrowserHWnd;
browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd);
- CPluginDictionary* dictionary = CPluginDictionary::GetInstance(false);
+ Dictionary* dictionary = Dictionary::GetInstance();
settings->SetBool("statusbarasked", true);
settings->Write();
HKEY pHkey;
HKEY pHkeySub;
LSTATUS regRes = 0;
regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey);
// Do we have enough rights to enable a status bar?
if (regRes != 0)
{
// We use the tab window here and in the next few calls, since the browser window may still not be available
- LRESULT res = MessageBox((HWND)m_hTabWnd, dictionary->Lookup("ERROR_CAN_NOT_ENABLE_STATUS_BAR"),
- dictionary->Lookup("ERROR_CAN_NOT_ENABLE_STATUS_BAR_TITLE"), MB_OK);
+ LRESULT res = MessageBox((HWND)m_hTabWnd,
+ dictionary->Lookup("status-bar", "error-text").c_str(),
+ dictionary->Lookup("status-bar", "error-title").c_str(),
+ MB_OK);
return;
}
// Ask if a user wants to enable a status bar automatically
- LRESULT res = MessageBox((HWND)m_hTabWnd, dictionary->Lookup("ERROR_STATUS_BAR_DISABLED"),
- dictionary->Lookup("ERROR_STATUS_BAR_DISABLED_TITLE"), MB_YESNO);
+ LRESULT res = MessageBox((HWND)m_hTabWnd,
+ dictionary->Lookup("status-bar", "question").c_str(),
+ dictionary->Lookup("status-bar", "title").c_str(),
+ MB_YESNO);
if (res == IDYES)
{
DWORD trueth = 1;
regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\MINIE", &pHkeySub);
regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE*)&trueth, sizeof(DWORD));
regRes = RegCloseKey(pHkeySub);
regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\Main", &pHkeySub);
regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE*)&trueth, sizeof(DWORD));
@@ -1464,39 +1469,39 @@ void CPluginClass::DisplayPluginMenu(HME
}
}
}
}
bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url)
{
- CString ctext;
+ std::wstring ctext;
s_criticalSectionLocal.Lock();
{
#ifdef SUPPORT_WHITELIST
s_menuDomains.clear();
#endif
}
s_criticalSectionLocal.Unlock();
CPluginTab* tab = GetTab(::GetCurrentThreadId());
if (!tab)
{
return false;
}
- CPluginDictionary* dictionary = CPluginDictionary::GetInstance();
+ Dictionary* dictionary = Dictionary::GetInstance();
- MENUITEMINFO fmii;
+ MENUITEMINFOW fmii;
memset(&fmii, 0, sizeof(MENUITEMINFO));
fmii.cbSize = sizeof(MENUITEMINFO);
- MENUITEMINFO miiSep;
+ MENUITEMINFOW miiSep;
memset(&miiSep, 0, sizeof(MENUITEMINFO));
miiSep.cbSize = sizeof(MENUITEMINFO);
miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
miiSep.fType = MFT_SEPARATOR;
CPluginClient* client = CPluginClient::GetInstance();
CPluginSettings* settings = CPluginSettings::GetInstance();
@@ -1504,94 +1509,92 @@ bool CPluginClass::SetMenuBar(HMENU hMen
settings->RefreshTab();
// Update settings
m_tab->OnUpdateSettings(false);
#ifdef SUPPORT_WHITELIST
{
// White list domain
- ctext = dictionary->Lookup("MENU_DISABLE_ON");
+ ctext = dictionary->Lookup("menu", "disable-on-site");
fmii.fMask = MIIM_STRING | MIIM_STATE;
fmii.fState = MFS_DISABLED;
- fmii.dwTypeData = ctext.GetBuffer();
- fmii.cch = ctext.GetLength();
+ fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
+ fmii.cch = ctext.size();
UINT index = WM_WHITELIST_DOMAIN;
- ::SetMenuItemInfo(hMenu, ID_WHITELISTDOMAIN, FALSE, &fmii);
+ ::SetMenuItemInfoW(hMenu, ID_WHITELISTDOMAIN, FALSE, &fmii);
}
#else
{
::DeleteMenu(hMenu, ID_WHITELISTDOMAIN, FALSE);
}
#endif // SUPPORT_WHITELIST
Oleksandr 2013/06/18 07:41:09 This is a menu that has been shown when a user cli
Wladimir Palant 2013/06/18 08:17:48 It's quite the opposite actually - we should make
// Invite friends
- ctext = dictionary->Lookup("MENU_INVITE_FRIENDS");
+ ctext = dictionary->Lookup("menu", "invite");
fmii.fMask = MIIM_STATE | MIIM_STRING;
fmii.fState = MFS_ENABLED;
- fmii.dwTypeData = ctext.GetBuffer();
- fmii.cch = ctext.GetLength();
- ::SetMenuItemInfo(hMenu, ID_INVITEFRIENDS, FALSE, &fmii);
+ fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
+ fmii.cch = ctext.size();
+ ::SetMenuItemInfoW(hMenu, ID_INVITEFRIENDS, FALSE, &fmii);
// FAQ
- ctext = dictionary->Lookup("MENU_FAQ");
+ ctext = dictionary->Lookup("menu", "faq");
fmii.fMask = MIIM_STATE | MIIM_STRING;
fmii.fState = MFS_ENABLED;
- fmii.dwTypeData = ctext.GetBuffer();
- fmii.cch = ctext.GetLength();
- ::SetMenuItemInfo(hMenu, ID_FAQ, FALSE, &fmii);
+ fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
+ fmii.cch = ctext.size();
+ ::SetMenuItemInfoW(hMenu, ID_FAQ, FALSE, &fmii);
// About
- ctext = dictionary->Lookup("MENU_ABOUT");
+ ctext = dictionary->Lookup("menu", "about");
fmii.fMask = MIIM_STATE | MIIM_STRING;
fmii.fState = MFS_ENABLED;
- fmii.dwTypeData = ctext.GetBuffer();
- fmii.cch = ctext.GetLength();
- ::SetMenuItemInfo(hMenu, ID_ABOUT, FALSE, &fmii);
+ fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
+ fmii.cch = ctext.size();
+ ::SetMenuItemInfoW(hMenu, ID_ABOUT, FALSE, &fmii);
// Feedback
- ctext = dictionary->Lookup("MENU_FEEDBACK");
+ ctext = dictionary->Lookup("menu", "feedback");
fmii.fMask = MIIM_STATE | MIIM_STRING;
fmii.fState = MFS_ENABLED;
- fmii.dwTypeData = ctext.GetBuffer();
- fmii.cch = ctext.GetLength();
- ::SetMenuItemInfo(hMenu, ID_FEEDBACK, FALSE, &fmii);
+ fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
+ fmii.cch = ctext.size();
+ ::SetMenuItemInfoW(hMenu, ID_FEEDBACK, FALSE, &fmii);
// Plugin enable
if (settings->GetPluginEnabled())
{
- ctext = dictionary->Lookup("MENU_DISABLE");
+ ctext = dictionary->Lookup("menu", "disable");
}
else
{
- ctext = dictionary->Lookup("MENU_ENABLE");
+ ctext = dictionary->Lookup("menu", "enable");
}
fmii.fMask = MIIM_STATE | MIIM_STRING;
fmii.fState = client ? MFS_ENABLED : MFS_DISABLED;
- fmii.dwTypeData = ctext.GetBuffer();
- fmii.cch = ctext.GetLength();
- ::SetMenuItemInfo(hMenu, ID_PLUGIN_ENABLE, FALSE, &fmii);
+ fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
+ fmii.cch = ctext.size();
+ ::SetMenuItemInfoW(hMenu, ID_PLUGIN_ENABLE, FALSE, &fmii);
// Settings
#ifndef ENTERPRISE
- ctext = dictionary->Lookup("MENU_SETTINGS");
+ ctext = dictionary->Lookup("menu", "settings");
fmii.fMask = MIIM_STATE | MIIM_STRING;
fmii.fState = MFS_ENABLED;
- fmii.dwTypeData = ctext.GetBuffer();
- fmii.cch = ctext.GetLength();
- ::SetMenuItemInfo(hMenu, ID_SETTINGS, FALSE, &fmii);
+ fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
+ fmii.cch = ctext.size();
+ ::SetMenuItemInfoW(hMenu, ID_SETTINGS, FALSE, &fmii);
#else
RemoveMenu(hMenu, ID_SETTINGS, MF_BYCOMMAND);
RemoveMenu(hMenu, 5, MF_BYPOSITION);
#endif
- ctext.ReleaseBuffer();
-
return true;
}
STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, VARIANTARG*)
{
HWND hBrowserWnd = GetBrowserHWND();
if (!hBrowserWnd)
@@ -1966,19 +1969,22 @@ LRESULT CALLBACK CPluginClass::PaneWindo
{
HRESULT hr = S_OK;
hr = browser->get_StatusBar(&isVisible);
if (SUCCEEDED(hr))
{
if (!isVisible)
{
- CPluginDictionary* dictionary = CPluginDictionary::GetInstance();
+ Dictionary* dictionary = Dictionary::GetInstance();
- LRESULT res = MessageBox(NULL, dictionary->Lookup("ERROR_STATUS_BAR_DISABLED"), dictionary->Lookup("ERROR_STATUS_BAR_DISABLED_TITLE"), MB_YESNO);
+ LRESULT res = MessageBox(NULL,
+ dictionary->Lookup("status-bar", "question").c_str(),
+ dictionary->Lookup("status-bar", "title").c_str(),
+ MB_YESNO);
if (res == IDYES)
{
hr = browser->put_StatusBar(TRUE);
if (FAILED(hr))
{
DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, "Class::Enable statusbar");
}
}

Powered by Google App Engine
This is Rietveld