예제 #1
0
파일: logger.cpp 프로젝트: 7kbird/chrome
void Logger::logCall(NPAPI_Action action, DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5, DWORD dw6, DWORD dw7)
{
  if(isMuted(action))
    return;

  std::string log;

  LogItemStruct * lis = makeLogItemStruct(action, dw1, dw2, dw3, dw4, dw5, dw6, dw7);
  formatLogItem(lis, &log, TRUE);
  freeLogItemStruct(lis);

  if(bToConsole)
    printf("%s", log.c_str());
  
  if(bToFile)
    filer.write(log);

  if(bToWindow)
    dumpStringToMainWindow(log);
}
예제 #2
0
BOOL CLogger::appendToLog(NPAPI_Action action, DWORD dwTickEnter, DWORD dwTickReturn, 
                          DWORD dwRet, 
                          DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, 
                          DWORD dw5, DWORD dw6, DWORD dw7)
{
  if(m_pLog == NULL)
    return FALSE;

  if(!m_bLogToFrame && !m_bLogToFile)
    return TRUE;

  DWORD dwTimeEnter;
  DWORD dwTimeReturn;
  if(m_dwStartTime == 0xFFFFFFFF)
  {
    m_dwStartTime = dwTickEnter;
    dwTimeEnter = 0L;
  }
  else
    dwTimeEnter = dwTickEnter - m_dwStartTime;

  dwTimeReturn = dwTickReturn - m_dwStartTime;

  LogItemStruct * plis = makeLogItemStruct(action, dwTimeEnter, dwTimeReturn, dwRet, 
                                           dw1, dw2, dw3, dw4, dw5, dw6, dw7);

  static char szOutput[1024];

  // dump to file
  if(m_bLogToFile && !m_bBlockLogToFile)
  {
    if(m_pLogFile == NULL)
    {
      m_pLogFile = new CLogFile();
      if(m_pLogFile == NULL)
        return FALSE;

      char szFile[256];
      m_pPlugin->getLogFileName(szFile, sizeof(szFile));

      if(m_pPlugin->getMode() == NP_EMBED)
      {
        if(!m_pLogFile->create(szFile, FALSE))
        {
          char szMessage[512];
          wsprintf(szMessage, "File '%s'\n probably exists. Overwrite?", szFile);
          if(IDYES == m_pPlugin->messageBox(szMessage, "", MB_ICONQUESTION | MB_YESNO))
          {
            if(!m_pLogFile->create(szFile, TRUE))
            {
              m_pPlugin->messageBox("Cannot create file.", "", MB_ICONERROR | MB_OK);
              delete m_pLogFile;
              m_pLogFile = NULL;
              return FALSE;
            }
          }
          else
          {
            delete m_pLogFile;
            m_pLogFile = NULL;
            goto Frame;
          }
        }
      }
      else // NP_FULL
      {
        if(!m_pLogFile->create(szFile, TRUE))
        {
          delete m_pLogFile;
          m_pLogFile = NULL;
          return FALSE;
        }
      }
    }

    formatLogItem(plis, szOutput, m_szItemSeparator, TRUE);
    m_pLogFile->write(szOutput);
    m_pLogFile->flush();
  }

Frame:

  // dump to frame
  if(m_bLogToFrame && !m_bBlockLogToFrame)
  {
    if(m_bShowImmediately)
    {
      BOOL dosstyle = (m_pPlugin && m_pPlugin->isStandAlone());

      int iLength = formatLogItem(plis, szOutput, "", dosstyle);

      // we should fix the output string if it contains symbols <html
      // If this is the case the browser will display the whole output
      // in HTML format while we still want it to be in plain text.
      // I do not know if this is a bug in the browser or not.
      FixUpOutputString(szOutput);

      if (m_pPlugin && m_pPlugin->isStandAlone())
      {
        m_pPlugin->outputToNativeWindow(szOutput);
      }
      else
      {
        if(m_pStream == NULL)
          NPN_NewStream(m_pPluginInstance, m_szStreamType, m_szTarget, &m_pStream);

        NPN_Write(m_pPluginInstance, m_pStream, iLength, (void *)szOutput);
      }
      delete plis;
    }
    else
      m_pLog->add(plis);
  }

  return TRUE;
}