00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023 #include "kjavaappletserver.h"
00024 #include "kjavaappletcontext.h"
00025 #include "kjavaprocess.h"
00026 #include "kjavadownloader.h"
00027
00028 #include <kdebug.h>
00029 #include <kconfig.h>
00030 #include <klocale.h>
00031 #include <kparts/browserextension.h>
00032 #include <kapplication.h>
00033 #include <kstandarddirs.h>
00034
00035 #include <kio/job.h>
00036 #include <kio/kprotocolmanager.h>
00037 #include <ksslcertificate.h>
00038 #include <ksslcertchain.h>
00039 #include <kssl.h>
00040
00041 #include <qtimer.h>
00042 #include <qguardedptr.h>
00043 #include <qvaluelist.h>
00044 #include <qptrlist.h>
00045 #include <qdir.h>
00046 #include <qeventloop.h>
00047 #include <qapplication.h>
00048 #include <qlabel.h>
00049 #include <qdialog.h>
00050 #include <qpushbutton.h>
00051 #include <qlayout.h>
00052 #include <qregexp.h>
00053
00054 #include <stdlib.h>
00055 #include <assert.h>
00056
00057 #define KJAS_CREATE_CONTEXT (char)1
00058 #define KJAS_DESTROY_CONTEXT (char)2
00059 #define KJAS_CREATE_APPLET (char)3
00060 #define KJAS_DESTROY_APPLET (char)4
00061 #define KJAS_START_APPLET (char)5
00062 #define KJAS_STOP_APPLET (char)6
00063 #define KJAS_INIT_APPLET (char)7
00064 #define KJAS_SHOW_DOCUMENT (char)8
00065 #define KJAS_SHOW_URLINFRAME (char)9
00066 #define KJAS_SHOW_STATUS (char)10
00067 #define KJAS_RESIZE_APPLET (char)11
00068 #define KJAS_GET_URLDATA (char)12
00069 #define KJAS_URLDATA (char)13
00070 #define KJAS_SHUTDOWN_SERVER (char)14
00071 #define KJAS_JAVASCRIPT_EVENT (char)15
00072 #define KJAS_GET_MEMBER (char)16
00073 #define KJAS_CALL_MEMBER (char)17
00074 #define KJAS_PUT_MEMBER (char)18
00075 #define KJAS_DEREF_OBJECT (char)19
00076 #define KJAS_AUDIOCLIP_PLAY (char)20
00077 #define KJAS_AUDIOCLIP_LOOP (char)21
00078 #define KJAS_AUDIOCLIP_STOP (char)22
00079 #define KJAS_APPLET_STATE (char)23
00080 #define KJAS_APPLET_FAILED (char)24
00081 #define KJAS_DATA_COMMAND (char)25
00082 #define KJAS_PUT_URLDATA (char)26
00083 #define KJAS_PUT_DATA (char)27
00084 #define KJAS_SECURITY_CONFIRM (char)28
00085 #define KJAS_SHOW_CONSOLE (char)29
00086
00087
00088 class JSStackFrame;
00089
00090 typedef QMap< int, KJavaKIOJob* > KIOJobMap;
00091 typedef QMap< int, JSStackFrame* > JSStack;
00092
00093 class JSStackFrame {
00094 public:
00095 JSStackFrame(JSStack & stack, QStringList & a)
00096 : jsstack(stack), args(a), ticket(counter++), ready(false), exit (false) {
00097 jsstack.insert( ticket, this );
00098 }
00099 ~JSStackFrame() {
00100 jsstack.erase( ticket );
00101 }
00102 JSStack & jsstack;
00103 QStringList & args;
00104 int ticket;
00105 bool ready : 1;
00106 bool exit : 1;
00107 static int counter;
00108 };
00109
00110 int JSStackFrame::counter = 0;
00111
00112 class KJavaAppletServerPrivate
00113 {
00114 friend class KJavaAppletServer;
00115 private:
00116 KJavaAppletServerPrivate() : kssl( 0L ) {}
00117 ~KJavaAppletServerPrivate() {
00118 delete kssl;
00119 }
00120 int counter;
00121 QMap< int, QGuardedPtr<KJavaAppletContext> > contexts;
00122 QString appletLabel;
00123 JSStack jsstack;
00124 KIOJobMap kiojobs;
00125 bool javaProcessFailed;
00126 bool useKIO;
00127 KSSL * kssl;
00128
00129
00130 };
00131
00132 static KJavaAppletServer* self = 0;
00133
00134 KJavaAppletServer::KJavaAppletServer()
00135 {
00136 d = new KJavaAppletServerPrivate;
00137 process = new KJavaProcess();
00138
00139 connect( process, SIGNAL(received(const QByteArray&)),
00140 this, SLOT(slotJavaRequest(const QByteArray&)) );
00141
00142 setupJava( process );
00143
00144 if( process->startJava() ) {
00145 d->appletLabel = i18n( "Loading Applet" );
00146 d->javaProcessFailed = false;
00147 }
00148 else {
00149 d->appletLabel = i18n( "Error: java executable not found" );
00150 d->javaProcessFailed = true;
00151 }
00152 }
00153
00154 KJavaAppletServer::~KJavaAppletServer()
00155 {
00156 quit();
00157
00158 delete process;
00159 delete d;
00160 }
00161
00162 QString KJavaAppletServer::getAppletLabel()
00163 {
00164 if( self )
00165 return self->appletLabel();
00166 else
00167 return QString::null;
00168 }
00169
00170 QString KJavaAppletServer::appletLabel()
00171 {
00172 return d->appletLabel;
00173 }
00174
00175 KJavaAppletServer* KJavaAppletServer::allocateJavaServer()
00176 {
00177 if( self == 0 )
00178 {
00179 self = new KJavaAppletServer();
00180 self->d->counter = 0;
00181 }
00182
00183 ++(self->d->counter);
00184 return self;
00185 }
00186
00187 void KJavaAppletServer::freeJavaServer()
00188 {
00189 --(self->d->counter);
00190
00191 if( self->d->counter == 0 )
00192 {
00193
00194
00195
00196 KConfig config( "konquerorrc", true );
00197 config.setGroup( "Java/JavaScript Settings" );
00198 if( config.readBoolEntry( "ShutdownAppletServer", true ) )
00199 {
00200 const int value = config.readNumEntry( "AppletServerTimeout", 60 );
00201 QTimer::singleShot( value*1000, self, SLOT( checkShutdown() ) );
00202 }
00203 }
00204 }
00205
00206 void KJavaAppletServer::checkShutdown()
00207 {
00208 if( self->d->counter == 0 )
00209 {
00210 delete self;
00211 self = 0;
00212 }
00213 }
00214
00215 void KJavaAppletServer::setupJava( KJavaProcess *p )
00216 {
00217 KConfig config ( "konquerorrc", true );
00218 config.setGroup( "Java/JavaScript Settings" );
00219
00220 QString jvm_path = "java";
00221
00222 QString jPath = config.readPathEntry( "JavaPath" );
00223 if ( !jPath.isEmpty() && jPath != "java" )
00224 {
00225
00226 if( jPath[jPath.length()-1] == '/' )
00227 jPath.remove(jPath.length()-1, 1);
00228
00229 QDir dir( jPath );
00230 if( dir.exists( "bin/java" ) )
00231 {
00232 jvm_path = jPath + "/bin/java";
00233 }
00234 else if (dir.exists( "/jre/bin/java" ) )
00235 {
00236 jvm_path = jPath + "/jre/bin/java";
00237 }
00238 else if( QFile::exists(jPath) )
00239 {
00240
00241 jvm_path = jPath;
00242 }
00243 }
00244
00245
00246 p->setJVMPath( jvm_path );
00247
00248
00249 QString kjava_class = locate("data", "kjava/kjava.jar");
00250 kdDebug(6100) << "kjava_class = " << kjava_class << endl;
00251 if( kjava_class.isNull() )
00252 return;
00253
00254 QDir dir( kjava_class );
00255 dir.cdUp();
00256 kdDebug(6100) << "dir = " << dir.absPath() << endl;
00257
00258 const QStringList entries = dir.entryList( "*.jar" );
00259 kdDebug(6100) << "entries = " << entries.join( ":" ) << endl;
00260
00261 QString classes;
00262 {
00263 QStringList::ConstIterator it = entries.begin();
00264 const QStringList::ConstIterator itEnd = entries.end();
00265 for( ; it != itEnd; ++it )
00266 {
00267 if( !classes.isEmpty() )
00268 classes += ":";
00269 classes += dir.absFilePath( *it );
00270 }
00271 }
00272 p->setClasspath( classes );
00273
00274
00275 const QString extraArgs = config.readEntry( "JavaArgs" );
00276 p->setExtraArgs( extraArgs );
00277
00278 if( config.readBoolEntry( "UseSecurityManager", true ) )
00279 {
00280 QString class_file = locate( "data", "kjava/kjava.policy" );
00281 p->setSystemProperty( "java.security.policy", class_file );
00282
00283 p->setSystemProperty( "java.security.manager",
00284 "org.kde.kjas.server.KJASSecurityManager" );
00285 }
00286
00287 d->useKIO = config.readBoolEntry( "UseKio", false);
00288 if( d->useKIO )
00289 {
00290 p->setSystemProperty( "kjas.useKio", QString::null );
00291 }
00292
00293
00294 if( KProtocolManager::useProxy() )
00295 {
00296
00297
00298
00299
00300 const KURL dummyURL( "http://www.kde.org/" );
00301 const QString httpProxy = KProtocolManager::proxyForURL(dummyURL);
00302 kdDebug(6100) << "httpProxy is " << httpProxy << endl;
00303
00304 const KURL url( httpProxy );
00305 p->setSystemProperty( "http.proxyHost", url.host() );
00306 p->setSystemProperty( "http.proxyPort", QString::number( url.port() ) );
00307 }
00308
00309
00310 p->setMainClass( "org.kde.kjas.server.Main" );
00311 }
00312
00313 void KJavaAppletServer::createContext( int contextId, KJavaAppletContext* context )
00314 {
00315
00316 if ( d->javaProcessFailed ) return;
00317
00318 d->contexts.insert( contextId, context );
00319
00320 QStringList args;
00321 args.append( QString::number( contextId ) );
00322 process->send( KJAS_CREATE_CONTEXT, args );
00323 }
00324
00325 void KJavaAppletServer::destroyContext( int contextId )
00326 {
00327
00328 if ( d->javaProcessFailed ) return;
00329 d->contexts.remove( contextId );
00330
00331 QStringList args;
00332 args.append( QString::number( contextId ) );
00333 process->send( KJAS_DESTROY_CONTEXT, args );
00334 }
00335
00336 bool KJavaAppletServer::createApplet( int contextId, int appletId,
00337 const QString & name, const QString & clazzName,
00338 const QString & baseURL, const QString & user,
00339 const QString & password, const QString & authname,
00340 const QString & codeBase, const QString & jarFile,
00341 QSize size, const QMap<QString,QString>& params,
00342 const QString & windowTitle )
00343 {
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 if ( d->javaProcessFailed ) return false;
00355
00356 QStringList args;
00357 args.append( QString::number( contextId ) );
00358 args.append( QString::number( appletId ) );
00359
00360
00361 args.append( name );
00362 args.append( clazzName );
00363 args.append( baseURL );
00364 args.append( user );
00365 args.append( password );
00366 args.append( authname );
00367 args.append( codeBase );
00368 args.append( jarFile );
00369
00370 args.append( QString::number( size.width() ) );
00371 args.append( QString::number( size.height() ) );
00372
00373 args.append( windowTitle );
00374
00375
00376 const int num = params.count();
00377 const QString num_params = QString("%1").arg( num, 8 );
00378 args.append( num_params );
00379
00380 QMap< QString, QString >::ConstIterator it = params.begin();
00381 const QMap< QString, QString >::ConstIterator itEnd = params.end();
00382
00383 for( ; it != itEnd; ++it )
00384 {
00385 args.append( it.key() );
00386 args.append( it.data() );
00387 }
00388
00389 process->send( KJAS_CREATE_APPLET, args );
00390
00391 return true;
00392 }
00393
00394 void KJavaAppletServer::initApplet( int contextId, int appletId )
00395 {
00396 if ( d->javaProcessFailed ) return;
00397 QStringList args;
00398 args.append( QString::number( contextId ) );
00399 args.append( QString::number( appletId ) );
00400
00401 process->send( KJAS_INIT_APPLET, args );
00402 }
00403
00404 void KJavaAppletServer::destroyApplet( int contextId, int appletId )
00405 {
00406 if ( d->javaProcessFailed ) return;
00407 QStringList args;
00408 args.append( QString::number(contextId) );
00409 args.append( QString::number(appletId) );
00410
00411 process->send( KJAS_DESTROY_APPLET, args );
00412 }
00413
00414 void KJavaAppletServer::startApplet( int contextId, int appletId )
00415 {
00416 if ( d->javaProcessFailed ) return;
00417 QStringList args;
00418 args.append( QString::number(contextId) );
00419 args.append( QString::number(appletId) );
00420
00421 process->send( KJAS_START_APPLET, args );
00422 }
00423
00424 void KJavaAppletServer::stopApplet( int contextId, int appletId )
00425 {
00426 if ( d->javaProcessFailed ) return;
00427 QStringList args;
00428 args.append( QString::number(contextId) );
00429 args.append( QString::number(appletId) );
00430
00431 process->send( KJAS_STOP_APPLET, args );
00432 }
00433
00434 void KJavaAppletServer::showConsole() {
00435 if ( d->javaProcessFailed ) return;
00436 QStringList args;
00437 process->send( KJAS_SHOW_CONSOLE, args );
00438 }
00439
00440 void KJavaAppletServer::sendURLData( int loaderID, int code, const QByteArray& data )
00441 {
00442 QStringList args;
00443 args.append( QString::number(loaderID) );
00444 args.append( QString::number(code) );
00445
00446 process->send( KJAS_URLDATA, args, data );
00447 }
00448
00449 void KJavaAppletServer::removeDataJob( int loaderID )
00450 {
00451 const KIOJobMap::iterator it = d->kiojobs.find( loaderID );
00452 if (it != d->kiojobs.end()) {
00453 it.data()->deleteLater();
00454 d->kiojobs.erase( it );
00455 }
00456 }
00457
00458 void KJavaAppletServer::quit()
00459 {
00460 const QStringList args;
00461
00462 process->send( KJAS_SHUTDOWN_SERVER, args );
00463 process->flushBuffers();
00464 process->wait( 10 );
00465 }
00466
00467 void KJavaAppletServer::slotJavaRequest( const QByteArray& qb )
00468 {
00469
00470
00471 QString cmd;
00472 QStringList args;
00473 int index = 0;
00474 const int qb_size = qb.size();
00475
00476
00477 const char cmd_code = qb[ index++ ];
00478 ++index;
00479
00480
00481 QString contextID;
00482 while( qb[index] != 0 && index < qb_size )
00483 {
00484 contextID += qb[ index++ ];
00485 }
00486 bool ok;
00487 const int ID_num = contextID.toInt( &ok );
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 ++index;
00501
00502 if (cmd_code == KJAS_PUT_DATA) {
00503
00504 if (ok) {
00505 KIOJobMap::iterator it = d->kiojobs.find( ID_num );
00506 if (ok && it != d->kiojobs.end()) {
00507 QByteArray qba;
00508 qba.setRawData(qb.data() + index, qb.size() - index - 1);
00509 it.data()->data(qba);
00510 qba.resetRawData(qb.data() + index, qb.size() - index - 1);
00511 }
00512 kdDebug(6100) << "PutData(" << ID_num << ") size=" << qb.size() - index << endl;
00513 } else
00514 kdError(6100) << "PutData error " << ok << endl;
00515 return;
00516 }
00517
00518 while( index < qb_size )
00519 {
00520 int sep_pos = qb.find( 0, index );
00521 if (sep_pos < 0) {
00522 kdError(6100) << "Missing separation byte" << endl;
00523 sep_pos = qb_size;
00524 }
00525
00526 args.append( QString::fromLocal8Bit( qb.data() + index, sep_pos - index ) );
00527 index = sep_pos + 1;
00528 }
00529
00530
00531 switch( cmd_code )
00532 {
00533 case KJAS_SHOW_DOCUMENT:
00534 cmd = QString::fromLatin1( "showdocument" );
00535 break;
00536
00537 case KJAS_SHOW_URLINFRAME:
00538 cmd = QString::fromLatin1( "showurlinframe" );
00539 break;
00540
00541 case KJAS_SHOW_STATUS:
00542 cmd = QString::fromLatin1( "showstatus" );
00543 break;
00544
00545 case KJAS_RESIZE_APPLET:
00546 cmd = QString::fromLatin1( "resizeapplet" );
00547 break;
00548
00549 case KJAS_GET_URLDATA:
00550 if (ok && !args.empty() ) {
00551 d->kiojobs.insert(ID_num, new KJavaDownloader(ID_num, args.first()));
00552 kdDebug(6100) << "GetURLData(" << ID_num << ") url=" << args.first() << endl;
00553 } else
00554 kdError(6100) << "GetURLData error " << ok << " args:" << args.size() << endl;
00555 return;
00556 case KJAS_PUT_URLDATA:
00557 if (ok && !args.empty()) {
00558 KJavaUploader* const job = new KJavaUploader(ID_num, args.first());
00559 d->kiojobs.insert(ID_num, job);
00560 job->start();
00561 kdDebug(6100) << "PutURLData(" << ID_num << ") url=" << args.first() << endl;
00562 } else
00563 kdError(6100) << "PutURLData error " << ok << " args:" << args.size() << endl;
00564 return;
00565 case KJAS_DATA_COMMAND:
00566 if (ok && !args.empty()) {
00567 const int cmd = args.first().toInt( &ok );
00568 KIOJobMap::iterator it = d->kiojobs.find( ID_num );
00569 if (ok && it != d->kiojobs.end())
00570 it.data()->jobCommand( cmd );
00571 kdDebug(6100) << "KIO Data command: " << ID_num << " " << args.first() << endl;
00572 } else
00573 kdError(6100) << "KIO Data command error " << ok << " args:" << args.size() << endl;
00574 return;
00575 case KJAS_JAVASCRIPT_EVENT:
00576 cmd = QString::fromLatin1( "JS_Event" );
00577 kdDebug(6100) << "Javascript request: "<< contextID
00578 << " code: " << args[0] << endl;
00579 break;
00580 case KJAS_GET_MEMBER:
00581 case KJAS_PUT_MEMBER:
00582 case KJAS_CALL_MEMBER: {
00583 const int ticket = args[0].toInt();
00584 JSStack::iterator it = d->jsstack.find(ticket);
00585 if (it != d->jsstack.end()) {
00586 kdDebug(6100) << "slotJavaRequest: " << ticket << endl;
00587 args.pop_front();
00588 it.data()->args.operator=(args);
00589 it.data()->ready = true;
00590 it.data()->exit = true;
00591 } else
00592 kdDebug(6100) << "Error: Missed return member data" << endl;
00593 return;
00594 }
00595 case KJAS_AUDIOCLIP_PLAY:
00596 cmd = QString::fromLatin1( "audioclip_play" );
00597 kdDebug(6100) << "Audio Play: url=" << args[0] << endl;
00598 break;
00599 case KJAS_AUDIOCLIP_LOOP:
00600 cmd = QString::fromLatin1( "audioclip_loop" );
00601 kdDebug(6100) << "Audio Loop: url=" << args[0] << endl;
00602 break;
00603 case KJAS_AUDIOCLIP_STOP:
00604 cmd = QString::fromLatin1( "audioclip_stop" );
00605 kdDebug(6100) << "Audio Stop: url=" << args[0] << endl;
00606 break;
00607 case KJAS_APPLET_STATE:
00608 kdDebug(6100) << "Applet State Notification for Applet " << args[0] << ". New state=" << args[1] << endl;
00609 cmd = QString::fromLatin1( "AppletStateNotification" );
00610 break;
00611 case KJAS_APPLET_FAILED:
00612 kdDebug(6100) << "Applet " << args[0] << " Failed: " << args[1] << endl;
00613 cmd = QString::fromLatin1( "AppletFailed" );
00614 break;
00615 case KJAS_SECURITY_CONFIRM: {
00616 if (KSSL::doesSSLWork() && !d->kssl)
00617 d->kssl = new KSSL;
00618 QStringList sl;
00619 QCString answer( "invalid" );
00620
00621 if (!d->kssl) {
00622 answer = "nossl";
00623 } else if (args.size() > 2) {
00624 const int certsnr = args[1].toInt();
00625 QString text;
00626 QPtrList<KSSLCertificate> certs;
00627 certs.setAutoDelete( true );
00628 for (int i = certsnr; i >= 0; --i) {
00629 KSSLCertificate * cert = KSSLCertificate::fromString(args[i+2].ascii());
00630 if (cert) {
00631 certs.prepend(cert);
00632 if (cert->isSigner())
00633 text += i18n("Signed by (validation: ");
00634 else
00635 text += i18n("Certificate (validation: ");
00636 switch (cert->validate()) {
00637 case KSSLCertificate::Ok:
00638 text += i18n("Ok"); break;
00639 case KSSLCertificate::NoCARoot:
00640 text += i18n("NoCARoot"); break;
00641 case KSSLCertificate::InvalidPurpose:
00642 text += i18n("InvalidPurpose"); break;
00643 case KSSLCertificate::PathLengthExceeded:
00644 text += i18n("PathLengthExceeded"); break;
00645 case KSSLCertificate::InvalidCA:
00646 text += i18n("InvalidCA"); break;
00647 case KSSLCertificate::Expired:
00648 text += i18n("Expired"); break;
00649 case KSSLCertificate::SelfSigned:
00650 text += i18n("SelfSigned"); break;
00651 case KSSLCertificate::ErrorReadingRoot:
00652 text += i18n("ErrorReadingRoot"); break;
00653 case KSSLCertificate::Revoked:
00654 text += i18n("Revoked"); break;
00655 case KSSLCertificate::Untrusted:
00656 text += i18n("Untrusted"); break;
00657 case KSSLCertificate::SignatureFailed:
00658 text += i18n("SignatureFailed"); break;
00659 case KSSLCertificate::Rejected:
00660 text += i18n("Rejected"); break;
00661 case KSSLCertificate::PrivateKeyFailed:
00662 text += i18n("PrivateKeyFailed"); break;
00663 case KSSLCertificate::InvalidHost:
00664 text += i18n("InvalidHost"); break;
00665 case KSSLCertificate::Unknown:
00666 default:
00667 text += i18n("Unknown"); break;
00668 }
00669 text += QString(")\n");
00670 QString subject = cert->getSubject() + QChar('\n');
00671 QRegExp reg(QString("/[A-Z]+="));
00672 int pos = 0;
00673 while ((pos = subject.find(reg, pos)) > -1)
00674 subject.replace(pos, 1, QString("\n "));
00675 text += subject.mid(1);
00676 }
00677 }
00678 kdDebug(6100) << "Security confirm " << args.first() << certs.count() << endl;
00679 if ( !certs.isEmpty() ) {
00680 KSSLCertChain chain;
00681 chain.setChain( certs );
00682 if ( chain.isValid() )
00683 answer = PermissionDialog( qApp->activeWindow() ).exec( text, args[0] );
00684 }
00685 }
00686 sl.push_front( QString(answer) );
00687 sl.push_front( QString::number(ID_num) );
00688 process->send( KJAS_SECURITY_CONFIRM, sl );
00689 return;
00690 }
00691 default:
00692 return;
00693 break;
00694 }
00695
00696
00697 if( !ok )
00698 {
00699 kdError(6100) << "could not parse out contextID to call command on" << endl;
00700 return;
00701 }
00702
00703 KJavaAppletContext* const context = d->contexts[ ID_num ];
00704 if( context )
00705 context->processCmd( cmd, args );
00706 else if (cmd != "AppletStateNotification")
00707 kdError(6100) << "no context object for this id" << endl;
00708 }
00709
00710 void KJavaAppletServer::endWaitForReturnData() {
00711 kdDebug(6100) << "KJavaAppletServer::endWaitForReturnData" << endl;
00712 killTimers();
00713 JSStack::iterator it = d->jsstack.begin();
00714 JSStack::iterator itEnd = d->jsstack.end();
00715 for (; it != itEnd; ++it)
00716 it.data()->exit = true;
00717 }
00718
00719 void KJavaAppletServer::timerEvent(QTimerEvent *) {
00720 endWaitForReturnData();
00721 kdDebug(6100) << "KJavaAppletServer::timerEvent timeout" << endl;
00722 }
00723
00724 void KJavaAppletServer::waitForReturnData(JSStackFrame * frame) {
00725 kdDebug(6100) << ">KJavaAppletServer::waitForReturnData" << endl;
00726 killTimers();
00727 startTimer(15000);
00728 while (!frame->exit)
00729 kapp->eventLoop()->processEvents (QEventLoop::AllEvents | QEventLoop::WaitForMore);
00730 if (d->jsstack.size() <= 1)
00731 killTimers();
00732 kdDebug(6100) << "<KJavaAppletServer::waitForReturnData stacksize:" << d->jsstack.size() << endl;
00733 }
00734
00735 bool KJavaAppletServer::getMember(QStringList & args, QStringList & ret_args) {
00736 JSStackFrame frame( d->jsstack, ret_args );
00737 args.push_front( QString::number(frame.ticket) );
00738
00739 process->send( KJAS_GET_MEMBER, args );
00740 waitForReturnData( &frame );
00741
00742 return frame.ready;
00743 }
00744
00745 bool KJavaAppletServer::putMember( QStringList & args ) {
00746 QStringList ret_args;
00747 JSStackFrame frame( d->jsstack, ret_args );
00748 args.push_front( QString::number(frame.ticket) );
00749
00750 process->send( KJAS_PUT_MEMBER, args );
00751 waitForReturnData( &frame );
00752
00753 return frame.ready && ret_args.count() > 0 && ret_args[0].toInt();
00754 }
00755
00756 bool KJavaAppletServer::callMember(QStringList & args, QStringList & ret_args) {
00757 JSStackFrame frame( d->jsstack, ret_args );
00758 args.push_front( QString::number(frame.ticket) );
00759
00760 process->send( KJAS_CALL_MEMBER, args );
00761 waitForReturnData( &frame );
00762
00763 return frame.ready;
00764 }
00765
00766 void KJavaAppletServer::derefObject( QStringList & args ) {
00767 process->send( KJAS_DEREF_OBJECT, args );
00768 }
00769
00770 bool KJavaAppletServer::usingKIO() {
00771 return d->useKIO;
00772 }
00773
00774
00775 PermissionDialog::PermissionDialog( QWidget* parent )
00776 : QObject(parent), m_button("no")
00777 {}
00778
00779 QCString PermissionDialog::exec( const QString & cert, const QString & perm ) {
00780 QGuardedPtr<QDialog> dialog = new QDialog( static_cast<QWidget*>(parent()), "PermissionDialog");
00781
00782 dialog->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, dialog->sizePolicy().hasHeightForWidth() ) );
00783 dialog->setModal( true );
00784 dialog->setCaption( i18n("Security Alert") );
00785
00786 QVBoxLayout* const dialogLayout = new QVBoxLayout( dialog, 11, 6, "dialogLayout");
00787
00788 dialogLayout->addWidget( new QLabel( i18n("Do you grant Java applet with certificate(s):"), dialog ) );
00789 dialogLayout->addWidget( new QLabel( cert, dialog, "message" ) );
00790 dialogLayout->addWidget( new QLabel( i18n("the following permission"), dialog, "message" ) );
00791 dialogLayout->addWidget( new QLabel( perm, dialog, "message" ) );
00792 QSpacerItem* const spacer2 = new QSpacerItem( 20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding );
00793 dialogLayout->addItem( spacer2 );
00794
00795 QHBoxLayout* const buttonLayout = new QHBoxLayout( 0, 0, 6, "buttonLayout");
00796
00797 QPushButton* const no = new QPushButton( i18n("&No"), dialog, "no" );
00798 no->setDefault( true );
00799 buttonLayout->addWidget( no );
00800
00801 QPushButton* const reject = new QPushButton( i18n("&Reject All"), dialog, "reject" );
00802 buttonLayout->addWidget( reject );
00803
00804 QPushButton* const yes = new QPushButton( i18n("&Yes"), dialog, "yes" );
00805 buttonLayout->addWidget( yes );
00806
00807 QPushButton* const grant = new QPushButton( i18n("&Grant All"), dialog, "grant" );
00808 buttonLayout->addWidget( grant );
00809 dialogLayout->addLayout( buttonLayout );
00810 dialog->resize( dialog->minimumSizeHint() );
00811
00812
00813 connect( no, SIGNAL( clicked() ), this, SLOT( clicked() ) );
00814 connect( reject, SIGNAL( clicked() ), this, SLOT( clicked() ) );
00815 connect( yes, SIGNAL( clicked() ), this, SLOT( clicked() ) );
00816 connect( grant, SIGNAL( clicked() ), this, SLOT( clicked() ) );
00817
00818 dialog->exec();
00819 delete dialog;
00820
00821 return m_button;
00822 }
00823
00824 PermissionDialog::~PermissionDialog()
00825 {}
00826
00827 void PermissionDialog::clicked()
00828 {
00829 m_button = sender()->name();
00830 static_cast<const QWidget*>(sender())->parentWidget()->close();
00831 }
00832
00833 #include "kjavaappletserver.moc"