Ejemplo n.º 1
0
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
                                     const CefString& message,
                                     const CefString& source,
                                     int line)
{
  REQUIRE_UI_THREAD();

  bool first_message;
  std::string logFile;

  {
    AutoLock lock_scope(this);
    
    first_message = m_LogFile.empty();
    if(first_message) {
      std::stringstream ss;
      ss << AppGetWorkingDirectory();
#if defined(OS_WIN)
      ss << "\\";
#else
      ss << "/";
#endif
      ss << "console.log";
      m_LogFile = ss.str();
    }
    logFile = m_LogFile;
}
  
  FILE* file = fopen(logFile.c_str(), "a");
  if(file) {
    std::stringstream ss;
    ss << "Message: " << std::string(message) << "\r\nSource: " <<
        std::string(source) << "\r\nLine: " << line <<
        "\r\n-----------------------\r\n";
    fputs(ss.str().c_str(), file);
    fclose(file);

    if(first_message)
      SendNotification(NOTIFY_CONSOLE_MESSAGE);
  }

  if( browser ) {
    //auto show console if something is Uncaught
    std::string strMsg(message);
    const char * err = "Uncaught ";
    if( 0 == strncmp(strMsg.c_str(), err, strlen(err) ) ) {
      browser->ShowDevTools();
    }
  }

  return false;
}
Ejemplo n.º 2
0
std::string AppGetRunningDirectory() {
  if(szRunningDir.length() > 0)
    return szRunningDir;

  char buf[512];
  int len = readlink("/proc/self/exe", buf, 512);

  if(len < 0)
    return AppGetWorkingDirectory();  //# Well, can't think of any real-world case where this would be happen

  for(; len >= 0; len--){
    if(buf[len] == '/'){
      buf[len] = '\0';
      szRunningDir.append(buf);
      return szRunningDir;
    }
  }
}
Ejemplo n.º 3
0
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
                                     const CefString& message,
                                     const CefString& source,
                                     int line)
{
  REQUIRE_UI_THREAD();

  bool first_message;
  std::string logFile;

  {
    AutoLock lock_scope(this);
    
    first_message = m_LogFile.empty();
    if(first_message) {
      std::stringstream ss;
      ss << AppGetWorkingDirectory();
#if defined(OS_WIN)
      ss << "\\";
#else
      ss << "/";
#endif
      ss << "console.log";
      m_LogFile = ss.str();
    }
    logFile = m_LogFile;
}
  
  FILE* file = fopen(logFile.c_str(), "a");
  if(file) {
    std::stringstream ss;
    ss << "Message: " << std::string(message) << "\r\nSource: " <<
        std::string(source) << "\r\nLine: " << line <<
        "\r\n-----------------------\r\n";
    fputs(ss.str().c_str(), file);
    fclose(file);

    if(first_message)
      SendNotification(NOTIFY_CONSOLE_MESSAGE);
  }

  return false;
}