/**
 * ブラウザとのソケットと本来のホストとのソケットを接続するトンネルを作成
 */
void YASWebProxy::openTunnel()
{
    QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
    QByteArray data = socket->readAll();

    HttpParser* parser = socket->findChild<HttpParser*>("requestParser");
    parser->input(data);

    QTcpSocket* proxySocket = socket->findChild<QTcpSocket*>("tunnel");
    if (!proxySocket) {
        // 本来のホストへのソケットを作成
        proxySocket = new QTcpSocket(socket);
        proxySocket->setObjectName("tunnel");
        proxySocket->connectToHost(parser->url.host(), parser->url.port(80));

        connect(proxySocket, SIGNAL(disconnected()), this, SLOT(closeProxySocket()));
        connect(proxySocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(closeProxySocket()));

        connect(proxySocket, SIGNAL(readyRead()), this, SLOT(forwardResponse()));
        if (parser->method == "CONNECT") {
            disconnect(socket, SIGNAL(readyRead()), this, SLOT(openTunnel()));
            connect(socket, SIGNAL(readyRead()), this, SLOT(forwardRequest()));
        } else {
            HttpParser* resParser = new HttpParser(HttpParser::RESPONSE, proxySocket);
            resParser->setObjectName("responseParser");
            resParser->setProperty("url", parser->url.toString());
            connect(resParser, SIGNAL(completeMessage(QByteArray)), this, SLOT(onResponse(QByteArray)));
        }
    }

    if (proxySocket->waitForConnected()) {
        if (parser->method == "CONNECT") {
            socket->write("HTTP/1.0 200 Connection established\r\n\r\n");
        } else {
            proxySocket->write(parser->dequeueData());
        }
    } else {
        proxySocket->disconnect();
    }
}
void CMsgBodyControlEditor::HandlePointerEventL( const TPointerEvent& aPointerEvent )
    {
    TBool forwardRequest( ETrue );
    
    if ( IsActivated() &&
         IsReadOnly() && 
         ( aPointerEvent.iType == TPointerEvent::EButton1Down ||
           aPointerEvent.iType == TPointerEvent::EButton1Up ) )
        {
        TPoint tapPoint( aPointerEvent.iPosition );
        TInt docPos( TextView()->XyPosToDocPosL( tapPoint ) );
        
        TInt start( 0 );
        TInt length( 0 );
        MParser* parser = iItemFinder;
        
        TBool tappedOverTag( RichText()->CursorOverTag( docPos, parser, start, length ) );
            
        if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
            {
            iPreviousItemStart = -1;
            iPreviousItemLength = -1;
            
            if ( tappedOverTag )
                {
                TPoint relativeTapPoint( aPointerEvent.iPosition - iPosition );
                if ( iItemFinder->ItemWasTappedL( relativeTapPoint ) )
                    {                
                    iPreviousItemStart = start;
                    iPreviousItemLength = length;
                    
                    forwardRequest = EFalse;
                    }
                }
            else
                {
                iItemFinder->ResetCurrentItem();
                }
            }
        else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
            {
            if ( tappedOverTag &&
                 start >= iPreviousItemStart &&
                 length <= iPreviousItemLength )
                {
                TKeyEvent event;
                event.iCode = EKeyDevice3;
                event.iScanCode = EStdKeyDevice3;
                event.iModifiers = 0;
                event.iRepeats = 0;
                
                iCoeEnv->WsSession().SimulateKeyEvent( event );
                
                forwardRequest = EFalse;
                }
            }
        }

    if ( forwardRequest )
        {
        CMsgExpandableControlEditor::HandlePointerEventL( aPointerEvent );
        }                
#ifdef RD_TACTILE_FEEDBACK         
    else if(aPointerEvent.iType == TPointerEvent::EButton1Down)
        {                                
        MTouchFeedback* feedback = MTouchFeedback::Instance();
        if ( feedback )
            {
            feedback->InstantFeedback( this, ETouchFeedbackBasic );
            }
        }
#endif //  RD_TACTILE_FEEDBACK      
    }