Add JS command

master
boisso 8 years ago
parent 2a0ab853eb
commit 70943b0e25
  1. 10
      k-meleon/BrowserFrm.cpp
  2. 3
      k-meleon/BrowserFrm.h
  3. 8
      k-meleon/BrowserFrmTab.cpp
  4. 1
      k-meleon/BrowserFrmTab.h
  5. 74
      k-meleon/BrowserView.cpp
  6. 4
      k-meleon/BrowserView.h
  7. 14
      k-meleon/BrowserWindow.h
  8. 11
      k-meleon/KmCommand.cpp
  9. 2
      k-meleon/KmCommand.h
  10. 34
      k-meleon/MfcEmbed.cpp
  11. 2
      k-meleon/MfcEmbed.h
  12. 12
      k-meleon/resource.h

@ -1850,7 +1850,7 @@ LRESULT CBrowserFrame::OnToolbarContextMenu(WPARAM wParam, LPARAM lParam)
KmToolbar* ktoolbar = (KmToolbar*)::GetProp(toolbar->GetSafeHwnd(), _T("kmToolbar"));
if (ktoolbar) {
KmButton* button = ktoolbar->GetButton(wParam);
CMenu* menu = button ? theApp.menus.GetMenu(button->mMenuName) : theApp.menus.GetMenu(_T("Toolbars"));
CMenu* menu = button && button->mMenuName.GetLength() ? theApp.menus.GetMenu(button->mMenuName) : theApp.menus.GetMenu(_T("Toolbars"));
if (menu) menu->TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this);
}
}
@ -1866,8 +1866,12 @@ void CBrowserFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
}
BOOL CBrowserFrame::OnToolTipText(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
return CFrameWnd::OnToolTipText(id, pNMHDR, pResult);
}
}
void CBrowserFrame::AllowJS(BOOL allow)
{
GetActiveView()->GetBrowserWrapper()->AllowJS(allow);
}

@ -260,7 +260,7 @@ public:
CToolBarEx* CreateToolbar(UINT style);
void SetBackImage ();
virtual void AllowJS(BOOL allow);
protected:
int InitLayout();
@ -271,6 +271,7 @@ protected:
void OnFind(BOOL backward = FALSE);
#ifdef INTERNAL_SITEICONS
void SetFavIcon(int iIcon);
#endif
//

@ -937,3 +937,11 @@ void CBrowserFrmTab::OnSysCommand(UINT nID, LPARAM lParam)
if (nID == SC_MAXIMIZE || nID == SC_RESTORE)
m_wndTabs->FixMaximizeRestoreRebarBug();
}
void CBrowserFrmTab::AllowJS(BOOL allow)
{
for (int i=0;i<m_iBrowserCount;i++) {
if (m_Tabs[i])
m_Tabs[i]->GetBrowserWrapper()->AllowJS(allow);
}
}

@ -124,6 +124,7 @@ public:
BOOL CloseTab(CBrowserTab*);
virtual CBrowserView* GetActiveView() { return (CBrowserView*)m_wndCBrowserTab; }
CBrowserTab* GetActiveTab() { return m_wndCBrowserTab; }
virtual void AllowJS(BOOL allow);
BOOL SetTabIcon(CBrowserTab* tab, int icon) {
return m_wndTabs->SetItemImage(TABINDEXTOID(tab->m_iIndex), icon);

@ -107,6 +107,11 @@ BEGIN_MESSAGE_MAP(CBrowserView, CWnd)
ON_COMMAND(ID_EDIT_UNDO, OnUndo)
ON_COMMAND(ID_EDIT_REDO, OnRedo)
ON_COMMAND(ID_EDIT_CLEAR, OnDelete)
ON_COMMAND(ID_PAGE_ENABLE_JS, OnEnableJS)
ON_COMMAND(ID_PAGE_DISABLE_JS, OnDisableJS)
ON_COMMAND(ID_PAGE_TOGGLE_JS, OnToggleJS)
ON_UPDATE_COMMAND_UI(ID_PAGE_TOGGLE_JS, OnUpdateToggleJS)
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdatePaste)
@ -570,30 +575,39 @@ void CBrowserView::OnFileSaveAs()
AfxMessageBox(IDS_SAVE_FAILED, MB_OK|MB_ICONERROR);
}
void CBrowserView::OnCopyLinkLocation()
void SetClipboardTextData(HWND hwnd, CString& str)
{
CString href, title;
if (!::GetLinkTitleAndHref(m_contextNode, href, title))
return;
if (!OpenClipboard())
if (!OpenClipboard(hwnd))
return;
HGLOBAL hClipData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, href.GetLength() + 1);
size_t l = (str.GetLength() + 1) * sizeof(TCHAR);
HGLOBAL hClipData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, l);
if (hClipData) {
char *pszClipData = (char*)::GlobalLock(hClipData);
TCHAR *pszClipData = (TCHAR*)::GlobalLock(hClipData);
if (pszClipData) {
USES_CONVERSION;
strcpy(pszClipData, T2CA(href));
memcpy(pszClipData, str.GetBuffer(0), l);
::GlobalUnlock(hClipData);
::EmptyClipboard();
::SetClipboardData(CF_TEXT, hClipData);
::SetClipboardData(CF_UNICODETEXT, hClipData);
}
}
CloseClipboard();
}
void CBrowserView::OnCopyLinkLocation()
{
CString href, title;
if (!::GetLinkTitleAndHref(m_contextNode, href, title))
return;
if (!OpenClipboard())
return;
SetClipboardTextData(m_hWnd, href);
}
void CBrowserView::OnOpenLink()
{
CString url, title;
@ -887,22 +901,7 @@ void CBrowserView::OnCopyImageLocation()
if (! OpenClipboard())
return;
HGLOBAL hClipData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, imgSrc.GetLength() + 1);
if(hClipData) {
char *pszClipData = (char*)::GlobalLock(hClipData);
if(pszClipData) {
USES_CONVERSION;
strcpy(pszClipData, T2CA(imgSrc));
::GlobalUnlock(hClipData);
::EmptyClipboard();
::SetClipboardData(CF_TEXT, hClipData);
}
}
CloseClipboard();
SetClipboardTextData(m_hWnd, imgSrc);
}
void CBrowserView::OnCopyImageContent()
@ -1019,7 +1018,7 @@ void CBrowserView::OnFilePrint()
void CBrowserView::OnFilePrintPreview()
{
if (m_pWindow->PrintPreview())
m_InPrintPreview = ! m_InPrintPreview;
;//m_InPrintPreview = ! m_InPrintPreview;
}
void CBrowserView::OnFilePrintSetup()
@ -1107,3 +1106,24 @@ bool CBrowserView::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
return false;
}
void CBrowserView::OnToggleJS()
{
m_pWindow->AllowJS(!m_pWindow->IsJSAllowed());
}
void CBrowserView::OnUpdateToggleJS(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
pCmdUI->SetCheck(!m_pWindow->IsJSAllowed());
}
void CBrowserView::OnEnableJS()
{
m_pWindow->AllowJS(TRUE);
}
void CBrowserView::OnDisableJS()
{
m_pWindow->AllowJS(FALSE);
}

@ -327,6 +327,10 @@ protected:
afx_msg void OnBeginEditURL( NMHDR * pNotifyStruct, LRESULT * result );
afx_msg void OnEndEditURL( NMHDR * pNotifyStruct, LRESULT * result );
afx_msg void OnDragURL( NMHDR * pNotifyStruct, LRESULT * result );
afx_msg void OnDisableJS();
afx_msg void OnEnableJS();
afx_msg void OnToggleJS();
afx_msg void OnUpdateToggleJS(CCmdUI* pCmdUI);
//afx_msg void OnDropFiles( HDROP );
//}}AFX_MSG

@ -85,6 +85,20 @@ public:
void GoForward() { if (mWebNav) mWebNav->GoForward(); }
void Stop() { if(mWebNav) mWebNav->Stop(nsIWebNavigation::STOP_ALL); }
BOOL AllowJS(BOOL allow)
{
nsCOMPtr<nsIDocShell> ds = GetDocShell();
return NS_SUCCEEDED(ds->SetAllowJavascript(allow));
}
BOOL IsJSAllowed()
{
nsCOMPtr<nsIDocShell> ds = GetDocShell();
bool res = false;
ds->GetAllowJavascript(&res);
return res;
}
BOOL Reload(BOOL force)
{
PRUint32 loadFlags = nsIWebNavigation::LOAD_FLAGS_NONE;

@ -25,8 +25,7 @@ UINT KmCmdService::RegisterCommand(LPCTSTR name, LPCTSTR desc, LPCTSTR icon)
{
UINT id = AllocateId();
mCommandList[name] = KmCommand(id, desc);
if (icon && theApp.skin.mImages)
theApp.skin.mImages->AddIcon(icon, 0, 0, id);
if (icon) theApp.skin.mImages->AddIcon(icon, 0, 0, id);
return id;
}
@ -44,7 +43,7 @@ CString KmCmdService::GetDescription(LPCTSTR command)
}
if (kcommand.GetDesc().GetLength())
return kcommand.GetDesc();
return theApp.lang.Translate(kcommand.GetDesc());
USES_CONVERSION;
char *desc = NULL;
@ -145,6 +144,9 @@ void KmCmdService::InitDefaultCmd()
mCommandList[_T("navSearch")] = KmCommand(ID_NAV_SEARCH);
mCommandList[_T("navGo")] = KmCommand(ID_NAV_GO);
mCommandList[_T("navOffline")] = KmCommand(ID_OFFLINE);
ADD_DEFCMD(navDisableJS, ID_DISABLE_JS);
ADD_DEFCMD(navEnableJS, ID_ENABLE_JS);
ADD_DEFCMD(navToggleJS, ID_TOGGLE_JS);
mCommandList[_T("viewSource")] = KmCommand(ID_VIEW_SOURCE);
mCommandList[_T("viewToolbar")] = KmCommand(ID_VIEW_TOOLBAR);
@ -185,6 +187,9 @@ void KmCmdService::InitDefaultCmd()
ADD_DEFCMD(pageFontDecrease, ID_FONT_DECREASE);
ADD_DEFCMD(pageZoomIncrease, ID_FULLZOOM_INCREASE);
ADD_DEFCMD(pageZoomDecrease, ID_FULLZOOM_DECREASE);
ADD_DEFCMD(pageEnableJS, ID_PAGE_ENABLE_JS);
ADD_DEFCMD(pageDisableJS, ID_PAGE_DISABLE_JS);
ADD_DEFCMD(pageToggleJS, ID_PAGE_TOGGLE_JS);
ADD_DEFCMD(appExit, ID_APP_EXIT);
ADD_DEFCMD(appAbout, ID_APP_ABOUT);

@ -99,7 +99,7 @@ public:
mIdList[--mCurrentId] = id;
}
void UnregisterCommand(LPCTSTR plugin, LPCTSTR command)
void UnregisterCommand(LPCTSTR command)
{
KmCommand kcommand;
if (!mCommandList.Lookup(command, kcommand))

@ -125,6 +125,8 @@ ON_COMMAND(ID_NEW_BROWSER, OnNewBrowser)
ON_COMMAND(ID_MANAGE_PROFILES, OnManageProfiles)
ON_COMMAND(ID_PREFERENCES, OnPreferences)
ON_COMMAND(ID_OFFLINE, OnToggleOffline)
ON_COMMAND(ID_TOGGLE_JS, OnToggleJS)
ON_UPDATE_COMMAND_UI(ID_TOGGLE_JS, OnUpdateToggleJS)
ON_UPDATE_COMMAND_UI(ID_OFFLINE, OnUpdateToggleOffline)
ON_UPDATE_COMMAND_UI_RANGE(WINDOW_MENU_START_ID, WINDOW_MENU_STOP_ID, OnUpdateWindows)
ON_COMMAND_RANGE(WINDOW_MENU_START_ID, WINDOW_MENU_STOP_ID, OnWindowSelect)
@ -546,16 +548,15 @@ BOOL CMfcEmbedApp::InitEmbedding(const char* profile)
BOOL CMfcEmbedApp::InitInstance()
{
CWinApp::InitInstance();
AfxOleInit();
USES_CONVERSION;
cmdline.Initialize(T2A(m_lpCmdLine));
// check for prior instances
m_bAlreadyRunning = FALSE;
if (cmdline.GetSwitch("-new", NULL, TRUE)<0 && !CheckInstance())
if (cmdline.GetSwitch("-new", NULL, TRUE)<0 && !CheckInstance()) {
m_bAlreadyRunning = TRUE;
return FALSE;
}
// Security
#ifdef _UNICODE
@ -571,6 +572,9 @@ BOOL CMfcEmbedApp::InitInstance()
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
CWinApp::InitInstance();
AfxOleInit();
// Profile selection
int len = cmdline.GetSwitch("-P", NULL, FALSE);
char *profile = NULL;
@ -1064,6 +1068,25 @@ void CMfcEmbedApp::OnToggleOffline()
m_pMostRecentBrowserFrame->UpdateStatus(status);
}
void CMfcEmbedApp::OnToggleJS()
{
int enable = !preferences.GetBool("javascript.enabled", 1);
preferences.SetBool("javascript.enabled", enable);
CBrowserFrame* pBrowserFrame = NULL;
POSITION pos = m_FrameWndLst.GetHeadPosition();
int i = 0;
while( pos != NULL ) {
pBrowserFrame = (CBrowserFrame *) m_FrameWndLst.GetNext(pos);
pBrowserFrame->AllowJS(enable);
}
}
void CMfcEmbedApp::OnUpdateToggleJS(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(!preferences.GetBool("javascript.enabled", 1));
}
void CMfcEmbedApp::OnUpdateToggleOffline(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(preferences.bOffline);
@ -1200,6 +1223,9 @@ int CMfcEmbedApp::ExitInstance()
m_pMostRecentBrowserFrame = NULL; // In case plugins are weird
if (m_pMainWnd)
m_pMainWnd->DestroyWindow();
// unload the plugins before we terminate embedding,
// this way plugins can still call the preference functions
plugins.SendMessage("*", "* Plugin Manager", "Quit");

@ -168,6 +168,8 @@ public:
afx_msg void OnManageProfiles();
afx_msg void OnPreferences();
afx_msg void OnToggleOffline();
afx_msg void OnToggleJS();
afx_msg void OnUpdateToggleJS(CCmdUI* pCmdUI);
afx_msg void OnUpdateToggleOffline(CCmdUI* pCmdUI);
afx_msg void OnUpdateWindows(CCmdUI* pCmdUI);
afx_msg void OnWindowSelect(UINT id);

@ -451,12 +451,10 @@
#define ID_MOUSE_ACTION 32818
#define ID_NAV_GO 32819
#define ID_OFFLINE 32820
#define IDS_STRING32820 32820
#define ID_COPY_IMAGE_CONTENT 32821
#define ID_FULLZOOM_INCREASE 32822
#define ID_CLOSE_FINDBAR 32822
#define ID_FULLZOOM_DECREASE 32823
#define ID_COOKIES_VIEWER 32823
#define ID_COOKIES_VIEWER 32919
#define ID_PASSWORDS_VIEWER 32824
#define ID_COOKIE_PERM 32825
#define ID_IMAGE_PERM 32826
@ -481,6 +479,14 @@
#define ID_MATCH_CASE 32915
#define ID_HIGHLIGHT 32916
#define ID_WRAP_AROUND 32917
#define ID_CLOSE_FINDBAR 32918
#define ID_PAGE_ENABLE_JS 32919
#define ID_PAGE_DISABLE_JS 32920
#define ID_ENABLE_JS 32921
#define ID_DISABLE_JS 32922
#define ID_TOGGLE_JS 32923
#define ID_PAGE_TOGGLE_JS 32924
#define IDS_FAILED_TO_CREATE_BROWSER 61204
#define IDS_NEW_PLUGIN_FOUND 61205
#define IDS_PLUGIN_NO_OPTIONS 61206

Loading…
Cancel
Save