onPluginFail for IE

This commit is contained in:
David Rose 2009-11-21 23:16:03 +00:00
parent 2b004124f9
commit 2d32638895
2 changed files with 54 additions and 0 deletions

View File

@ -84,6 +84,7 @@ PPInstance::PPInstance( CP3DActiveXCtrl& parentCtrl ) :
m_logger.Open( m_rootDir );
m_pluginLoaded = false;
_failed = false;
}
PPInstance::~PPInstance( )
@ -447,6 +448,7 @@ int PPInstance::LoadPlugin( const std::string& dllFilename )
nout << "Attempting to load core API from " << pathname << "\n";
if (!load_plugin(pathname, "", "", true, "", "", "", false, false, nout)) {
nout << "Unable to launch core API in " << pathname << "\n";
set_failed();
error = 1;
} else {
#ifdef PANDA_OFFICIAL_VERSION
@ -682,5 +684,54 @@ void PPInstance::HandleRequest( P3D_request *request )
P3D_request_finish( request, handled );
}
////////////////////////////////////////////////////////////////////
// Function: PPInstance::set_failed
// Access: Private
// Description: Called when something has gone wrong that prevents
// the plugin instance from running. Specifically, this
// means it failed to load the core API.
////////////////////////////////////////////////////////////////////
void PPInstance::
set_failed() {
if (!_failed) {
_failed = true;
nout << "Plugin failed.\n";
string expression;
// Look for the "onpluginfail" token.
for (UINT i = 0; i < m_parentCtrl.m_parameters.size(); i++) {
std::pair<CString, CString> keyAndValue = m_parentCtrl.m_parameters[i];
// Make the token lowercase, since HTML is case-insensitive but
// we're not.
const CString &orig_keyword = m_parentCtrl.m_parameters[i].first;
string keyword;
for (const char *p = orig_keyword; *p; ++p) {
keyword += tolower(*p);
}
if (keyword == "onpluginfail") {
expression = m_parentCtrl.m_parameters[i].second;
break;
}
}
if (!expression.empty()) {
// Now attempt to evaluate the expression.
COleVariant varResult;
CComPtr<IDispatch> pDispatch;
CString evalExpression( expression.c_str() );
HRESULT hr = m_parentCtrl.EvalExpression( pDispatch, evalExpression , varResult );
if (FAILED(hr)) {
nout << "Unable to eval " << expression << "\n";
} else {
nout << "Eval " << expression << "\n";
}
}
}
}

View File

@ -80,6 +80,8 @@ protected:
void HandleRequest( P3D_request *request );
static void HandleRequestGetUrl( void *data );
void set_failed();
P3D_instance* m_p3dInstance;
CP3DActiveXCtrl& m_parentCtrl;
PPLogger m_logger;
@ -92,6 +94,7 @@ protected:
typedef std::vector<std::string> Mirrors;
Mirrors _mirrors;
FileSpec _core_api_dll;
bool _failed;
std::string m_rootDir;
};