2014-12-23 21:54:03 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
2014-12-27 06:25:10 +00:00
|
|
|
// Copyright (C) 2014-2015 University of California
|
2014-12-23 21:54:03 +00:00
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#define _ATL_FREE_THREADED
|
|
|
|
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
|
|
|
|
#include <AtlBase.h>
|
|
|
|
#include <AtlCom.h>
|
|
|
|
#include <AtlCtl.h>
|
|
|
|
#include <AtlWin.h>
|
|
|
|
#include <AtlStr.h>
|
|
|
|
#include <AtlFile.h>
|
|
|
|
#include <AtlTypes.h>
|
|
|
|
#include <exdisp.h>
|
|
|
|
#include <exdispid.h>
|
2014-12-24 06:59:37 +00:00
|
|
|
#include <stdlib.h>
|
2014-12-23 21:54:03 +00:00
|
|
|
#include <string>
|
2014-12-26 23:56:31 +00:00
|
|
|
#include "util.h"
|
2014-12-23 21:54:03 +00:00
|
|
|
#include "win_util.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "boinc_api.h"
|
|
|
|
#include "diagnostics.h"
|
|
|
|
#include "filesys.h"
|
2014-12-24 19:01:35 +00:00
|
|
|
#include "browser_i.h"
|
2014-12-23 21:54:03 +00:00
|
|
|
#include "browser_win.h"
|
|
|
|
#include "browserlog.h"
|
2014-12-25 01:30:19 +00:00
|
|
|
#include "browserctrlui_win.h"
|
2014-12-23 21:54:03 +00:00
|
|
|
#include "browserctrl_win.h"
|
|
|
|
#include "browserwnd_win.h"
|
2014-12-27 06:25:10 +00:00
|
|
|
#include "graphics.h"
|
|
|
|
#include "vboxwrapper.h"
|
2014-12-23 21:54:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
CHTMLBrowserWnd::CHTMLBrowserWnd()
|
|
|
|
{
|
|
|
|
m_pBrowserHost = NULL;
|
2014-12-24 06:59:37 +00:00
|
|
|
m_hIcon = NULL;
|
|
|
|
m_hIconSmall = NULL;
|
2014-12-26 23:56:31 +00:00
|
|
|
|
|
|
|
aid.clear();
|
|
|
|
status.abort_request = 0;
|
|
|
|
status.no_heartbeat = 0;
|
|
|
|
status.quit_request = 0;
|
|
|
|
status.reread_init_data_file = 0;
|
|
|
|
status.suspended = 0;
|
|
|
|
status.network_suspended = 0;
|
|
|
|
m_dUpdateTime = 0.0;
|
|
|
|
m_dCPUTime = 0.0;
|
|
|
|
m_dElapsedTime = 0.0;
|
|
|
|
m_dFractionDone = 0.0;
|
|
|
|
m_bScreensaverMode = false;
|
2014-12-27 06:25:10 +00:00
|
|
|
m_bVboxwrapperJob = false;
|
|
|
|
m_lRemoteDesktopPort = 0;
|
|
|
|
m_lWebAPIPort = 0;
|
2014-12-23 21:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHTMLBrowserWnd::~CHTMLBrowserWnd()
|
|
|
|
{
|
2014-12-24 06:59:37 +00:00
|
|
|
if(m_hIcon)
|
|
|
|
{
|
|
|
|
::DestroyIcon(m_hIcon);
|
|
|
|
m_hIcon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_hIconSmall)
|
|
|
|
{
|
|
|
|
::DestroyIcon(m_hIconSmall);
|
|
|
|
m_hIconSmall = NULL;
|
|
|
|
}
|
2014-12-29 01:38:15 +00:00
|
|
|
|
|
|
|
if (aid.project_preferences)
|
|
|
|
{
|
|
|
|
delete aid.project_preferences;
|
|
|
|
aid.project_preferences = NULL;
|
|
|
|
}
|
2014-12-23 21:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CHTMLBrowserWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
RECT rcClient;
|
2014-12-24 06:59:37 +00:00
|
|
|
TCHAR szExecutable[MAX_PATH];
|
2014-12-23 21:54:03 +00:00
|
|
|
CComPtr<IUnknown> pCtrl;
|
2014-12-25 01:30:19 +00:00
|
|
|
|
2014-12-23 21:54:03 +00:00
|
|
|
|
2014-12-24 06:59:37 +00:00
|
|
|
// Load Icon Resources
|
|
|
|
m_hIcon = (HICON)::LoadImage(
|
|
|
|
_AtlBaseModule.GetResourceInstance(),
|
|
|
|
MAKEINTRESOURCE(IDI_ICON),
|
|
|
|
IMAGE_ICON,
|
|
|
|
0, 0,
|
|
|
|
LR_DEFAULTSIZE | LR_DEFAULTCOLOR);
|
|
|
|
ATLASSERT(m_hIcon);
|
|
|
|
|
|
|
|
m_hIconSmall = (HICON)::LoadImage(
|
|
|
|
_AtlBaseModule.GetResourceInstance(),
|
|
|
|
MAKEINTRESOURCE(IDI_ICON),
|
|
|
|
IMAGE_ICON,
|
2014-12-26 23:56:31 +00:00
|
|
|
GetSystemMetrics(SM_CXSMICON),
|
|
|
|
GetSystemMetrics(SM_CYSMICON),
|
2014-12-24 06:59:37 +00:00
|
|
|
LR_DEFAULTCOLOR);
|
|
|
|
ATLASSERT(m_hIconSmall);
|
|
|
|
|
|
|
|
SetIcon(m_hIcon);
|
|
|
|
SetIcon(m_hIconSmall, FALSE);
|
2014-12-23 21:54:03 +00:00
|
|
|
|
|
|
|
// Create Control Host
|
|
|
|
hr = CComObject<CHTMLBrowserHost>::CreateInstance(&m_pBrowserHost);
|
|
|
|
ATLASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
|
|
// Create Control Window
|
|
|
|
GetClientRect(&rcClient);
|
|
|
|
m_pBrowserHost->Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE);
|
2014-12-25 01:30:19 +00:00
|
|
|
ATLASSERT(m_pBrowserHost->IsWindow());
|
2014-12-23 21:54:03 +00:00
|
|
|
|
|
|
|
// Create Control
|
2014-12-24 19:01:35 +00:00
|
|
|
hr = m_pBrowserHost->CreateControlEx(
|
2014-12-23 21:54:03 +00:00
|
|
|
L"Shell.Explorer",
|
|
|
|
m_pBrowserHost->m_hWnd,
|
|
|
|
NULL,
|
|
|
|
&pCtrl,
|
|
|
|
__uuidof(DWebBrowserEvents2),
|
|
|
|
(IUnknown*)(IDispEventImpl<1, CHTMLBrowserWnd, &__uuidof(DWebBrowserEvents2), &LIBID_SHDocVw, 1, 1>*)this
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get an IWebBrowser2 interface on the control and navigate to a page.
|
|
|
|
m_pBrowserCtrl = pCtrl;
|
|
|
|
|
2014-12-25 01:30:19 +00:00
|
|
|
// Configure the Embedded URL
|
|
|
|
GetModuleFileName(NULL, szExecutable, sizeof(szExecutable));
|
|
|
|
m_strEmbeddedURL += "res://";
|
|
|
|
m_strEmbeddedURL += szExecutable;
|
|
|
|
m_strEmbeddedURL += "/default_win.htm";
|
|
|
|
|
2014-12-26 23:56:31 +00:00
|
|
|
// Stage rereading of all the state files
|
|
|
|
status.reread_init_data_file = true;
|
2014-12-25 01:30:19 +00:00
|
|
|
|
2014-12-26 23:56:31 +00:00
|
|
|
// Start the timer
|
|
|
|
SetTimer(1, 1000);
|
|
|
|
|
2014-12-23 21:54:03 +00:00
|
|
|
bHandled = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CHTMLBrowserWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2014-12-26 23:56:31 +00:00
|
|
|
KillTimer(1);
|
2014-12-23 21:54:03 +00:00
|
|
|
DestroyWindow();
|
2014-12-26 23:56:31 +00:00
|
|
|
PostQuitMessage(0);
|
2014-12-23 21:54:03 +00:00
|
|
|
bHandled = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-25 01:30:19 +00:00
|
|
|
LRESULT CHTMLBrowserWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2014-12-23 21:54:03 +00:00
|
|
|
{
|
2014-12-25 01:30:19 +00:00
|
|
|
m_pBrowserHost->MoveWindow(0, 0, LOWORD(lParam), HIWORD(lParam));
|
2014-12-23 21:54:03 +00:00
|
|
|
bHandled = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-27 00:22:32 +00:00
|
|
|
LRESULT CHTMLBrowserWnd::OnInputActivity(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (m_bScreensaverMode)
|
|
|
|
{
|
|
|
|
PostMessage(WM_CLOSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Forward event to the browser control
|
|
|
|
MSG msg = { m_hWnd, uMsg, wParam, lParam, 0, { 0, 0 } };
|
|
|
|
SendMessage(m_pBrowserHost->m_hWnd, WM_FORWARDMSG, 0, (LPARAM)&msg);
|
|
|
|
}
|
|
|
|
bHandled = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-25 01:30:19 +00:00
|
|
|
LRESULT CHTMLBrowserWnd::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2014-12-23 21:54:03 +00:00
|
|
|
{
|
2014-12-27 06:25:10 +00:00
|
|
|
int retval = ERR_FREAD;
|
2014-12-27 00:22:32 +00:00
|
|
|
HRESULT hr = E_FAIL;
|
2014-12-29 01:38:15 +00:00
|
|
|
BOOL bExit = false;
|
|
|
|
double dExitTimeout = 0.0;
|
2014-12-27 06:25:10 +00:00
|
|
|
int temp = 0;
|
2014-12-26 23:56:31 +00:00
|
|
|
CComQIPtr<IHTMLBrowserHostUI> pHostUI;
|
|
|
|
|
2014-12-27 00:22:32 +00:00
|
|
|
boinc_parse_graphics_status(
|
2014-12-26 23:56:31 +00:00
|
|
|
&m_dUpdateTime,
|
|
|
|
&m_dCPUTime,
|
|
|
|
&m_dElapsedTime,
|
|
|
|
&m_dFractionDone,
|
|
|
|
&status
|
|
|
|
);
|
2014-12-27 00:22:32 +00:00
|
|
|
|
|
|
|
// Query for the IHTMLBrowserHostUI interface so we can setup the browser with
|
|
|
|
// information that doesn't change very much.
|
|
|
|
//
|
|
|
|
hr = m_pBrowserHost->GetExternal((IDispatch**)&pHostUI);
|
|
|
|
if (SUCCEEDED(hr) && pHostUI.p)
|
2014-12-26 23:56:31 +00:00
|
|
|
{
|
2014-12-29 01:38:15 +00:00
|
|
|
bExit = status.abort_request || status.no_heartbeat || status.quit_request;
|
|
|
|
if (bExit && ((dtime() - m_dUpdateTime) > 5.0))
|
2014-12-27 06:25:10 +00:00
|
|
|
{
|
2014-12-29 01:38:15 +00:00
|
|
|
dExitTimeout = dtime() - m_dUpdateTime - 5;
|
2014-12-27 06:25:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-29 01:38:15 +00:00
|
|
|
dExitTimeout = 0.0;
|
2014-12-27 06:25:10 +00:00
|
|
|
}
|
2014-12-27 00:22:32 +00:00
|
|
|
|
2014-12-29 01:38:15 +00:00
|
|
|
if (dExitTimeout > 5.0)
|
2014-12-27 00:22:32 +00:00
|
|
|
{
|
|
|
|
PostMessage(WM_CLOSE);
|
|
|
|
}
|
|
|
|
|
2014-12-29 01:38:15 +00:00
|
|
|
pHostUI->put_suspended(status.suspended);
|
|
|
|
pHostUI->put_networkSuspended(status.network_suspended);
|
|
|
|
pHostUI->put_exiting(bExit);
|
|
|
|
pHostUI->put_exitTimeout(dExitTimeout);
|
|
|
|
pHostUI->put_cpuTime(m_dCPUTime);
|
|
|
|
pHostUI->put_elapsedTime(m_dElapsedTime);
|
|
|
|
pHostUI->put_fractionDone(m_dFractionDone);
|
2014-12-27 00:22:32 +00:00
|
|
|
|
|
|
|
if (status.reread_init_data_file)
|
2014-12-26 23:56:31 +00:00
|
|
|
{
|
2014-12-27 00:32:42 +00:00
|
|
|
status.reread_init_data_file = 0;
|
|
|
|
|
2014-12-27 00:22:32 +00:00
|
|
|
// Get updated state
|
|
|
|
//
|
2014-12-27 00:32:42 +00:00
|
|
|
if (aid.project_preferences) delete aid.project_preferences;
|
2014-12-27 00:22:32 +00:00
|
|
|
boinc_parse_init_data_file();
|
|
|
|
boinc_get_init_data(aid);
|
|
|
|
|
|
|
|
// Inform the HTML Document DOM about the state changes
|
|
|
|
//
|
2014-12-29 01:38:15 +00:00
|
|
|
pHostUI->resetStateUpdate(TRUE);
|
|
|
|
pHostUI->put_scrsaveMode(m_bScreensaverMode);
|
|
|
|
pHostUI->put_appName(CComBSTR(aid.app_name));
|
|
|
|
pHostUI->put_appVersion(aid.app_version);
|
|
|
|
pHostUI->put_wuName(CComBSTR(aid.wu_name));
|
|
|
|
pHostUI->put_resName(CComBSTR(aid.result_name));
|
|
|
|
pHostUI->put_userName(CComBSTR(aid.user_name));
|
|
|
|
pHostUI->put_teamName(CComBSTR(aid.team_name));
|
|
|
|
pHostUI->put_userCreditTotal(aid.user_total_credit);
|
|
|
|
pHostUI->put_userCreditAverage(aid.user_expavg_credit);
|
|
|
|
pHostUI->put_hostCreditTotal(aid.host_total_credit);
|
|
|
|
pHostUI->put_hostCreditAverage(aid.host_expavg_credit);
|
2014-12-27 06:25:10 +00:00
|
|
|
|
|
|
|
// Check for vboxwrapper state
|
|
|
|
//
|
|
|
|
m_bVboxwrapperJob = is_vboxwrapper_job();
|
|
|
|
if (m_bVboxwrapperJob)
|
|
|
|
{
|
2014-12-29 01:38:15 +00:00
|
|
|
pHostUI->put_vboxJob(m_bVboxwrapperJob);
|
2014-12-27 06:25:10 +00:00
|
|
|
if (0 == parse_vbox_remote_desktop_port(temp))
|
|
|
|
{
|
|
|
|
m_lRemoteDesktopPort = temp;
|
2014-12-29 01:38:15 +00:00
|
|
|
pHostUI->put_rdpPort(m_lRemoteDesktopPort);
|
2014-12-27 06:25:10 +00:00
|
|
|
}
|
|
|
|
if (0 == parse_vbox_webapi_port(temp))
|
|
|
|
{
|
|
|
|
m_lWebAPIPort = temp;
|
2014-12-29 01:38:15 +00:00
|
|
|
pHostUI->put_apiPort(m_lWebAPIPort);
|
2014-12-27 06:25:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
2014-12-27 16:28:43 +00:00
|
|
|
parse_graphics(
|
|
|
|
m_strDefaultURL, m_strRunningURL, m_strSuspendedURL, m_strNetworkSuspendedURL, m_strExitingURL
|
|
|
|
);
|
2014-12-27 06:25:10 +00:00
|
|
|
|
|
|
|
// Forcefully switch to the required URL.
|
|
|
|
NavigateToStateURL(true);
|
2014-12-26 23:56:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Switch to the correct URL
|
|
|
|
NavigateToStateURL(false);
|
|
|
|
|
2014-12-23 21:54:03 +00:00
|
|
|
bHandled = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-26 17:59:49 +00:00
|
|
|
|
|
|
|
STDMETHODIMP_(void) CHTMLBrowserWnd::OnNewProcess(LONG lCauseFlag, IDispatch* pDisp, VARIANT_BOOL* pCancel)
|
2014-12-23 21:54:03 +00:00
|
|
|
{
|
2014-12-26 17:59:49 +00:00
|
|
|
*pCancel = TRUE;
|
2014-12-23 21:54:03 +00:00
|
|
|
}
|
|
|
|
|
2014-12-26 17:59:49 +00:00
|
|
|
STDMETHODIMP_(void) CHTMLBrowserWnd::OnNewWindow2(IDispatch** ppDisp, VARIANT_BOOL* pCancel)
|
|
|
|
{
|
|
|
|
*pCancel = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(void) CHTMLBrowserWnd::OnNewWindow3(IDispatch** ppDisp, VARIANT_BOOL* pCancel, DWORD dwFlags, BSTR bstrUrlContext, BSTR bstrUrl)
|
|
|
|
{
|
|
|
|
*pCancel = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-25 01:30:19 +00:00
|
|
|
void CHTMLBrowserWnd::NavigateToStateURL(bool bForce)
|
|
|
|
{
|
|
|
|
CComBSTR bstr;
|
|
|
|
CComVariant v;
|
|
|
|
|
|
|
|
// Start out with the default URL
|
2014-12-27 16:28:43 +00:00
|
|
|
bstr = m_strDefaultURL.c_str();
|
2014-12-25 01:30:19 +00:00
|
|
|
|
|
|
|
// See if we need to override the default
|
2014-12-28 05:34:06 +00:00
|
|
|
if ((status.abort_request || status.quit_request || status.no_heartbeat) && !m_strExitingURL.empty()) {
|
2014-12-27 16:28:43 +00:00
|
|
|
bstr = m_strExitingURL.c_str();
|
2014-12-28 05:34:06 +00:00
|
|
|
} else if (status.suspended && !m_strSuspendedURL.empty()) {
|
2014-12-27 16:28:43 +00:00
|
|
|
bstr = m_strSuspendedURL.c_str();
|
2014-12-28 05:34:06 +00:00
|
|
|
} else if (status.network_suspended && !m_strNetworkSuspendedURL.empty()) {
|
2014-12-27 16:28:43 +00:00
|
|
|
bstr = m_strNetworkSuspendedURL.c_str();
|
2014-12-28 05:34:06 +00:00
|
|
|
} else if (!m_strRunningURL.empty()) {
|
2014-12-27 16:28:43 +00:00
|
|
|
bstr = m_strRunningURL.c_str();
|
2014-12-25 01:30:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-27 06:25:10 +00:00
|
|
|
// Are we running a vboxwrapper job? If so, does it expose a webapi port number?
|
2014-12-28 19:53:21 +00:00
|
|
|
if ((m_bVboxwrapperJob && m_lWebAPIPort) && (bstr.Length() == 0)) {
|
2014-12-27 06:25:10 +00:00
|
|
|
bstr = "http://localhost:";
|
|
|
|
bstr += m_lWebAPIPort;
|
|
|
|
bstr += "/";
|
|
|
|
}
|
|
|
|
|
2014-12-25 01:30:19 +00:00
|
|
|
// If nothing has been approved to the point, use the embedded HTML page
|
|
|
|
if (bstr.Length() == 0) {
|
|
|
|
bstr = m_strEmbeddedURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Navigate to URL
|
|
|
|
if ((m_strCurrentURL != bstr) || bForce) {
|
|
|
|
m_strCurrentURL = bstr;
|
|
|
|
m_pBrowserCtrl->Navigate(bstr, &v, &v, &v, &v);
|
|
|
|
}
|
|
|
|
}
|