/c/src/qruntime/runtimepage.cpp

https://github.com/jondo/paperpile · C++ · 65 lines · 35 code · 12 blank · 18 comment · 7 complexity · 52f82bc791aab255667ee974ef4f8463 MD5 · raw file

  1. /* Copyright 2009-2011 Paperpile
  2. This file is part of Paperpile
  3. Paperpile is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Paperpile is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Affero General Public License for more details. You should have
  11. received a copy of the GNU Affero General Public License along with
  12. Paperpile. If not, see http://www.gnu.org/licenses. */
  13. #include <QtGlobal>
  14. #include <QtGui>
  15. #include <QWebPage>
  16. #include "runtimepage.h"
  17. RuntimePage::RuntimePage(QObject * parent) : QWebPage(parent) {
  18. QWebPage::QWebPage();
  19. };
  20. void RuntimePage::javaScriptConsoleMessage ( const QString & message, int lineNumber, const QString & sourceID ) {
  21. if (!sourceID.isEmpty()){
  22. QFileInfo fileInfo(QUrl(sourceID).toLocalFile());
  23. fprintf( stderr, "[%s] %s (Line: %i, %s)\n",
  24. qPrintable(QDateTime::currentDateTime().toString()),
  25. qPrintable(message),
  26. lineNumber,
  27. qPrintable(fileInfo.fileName()));
  28. } else {
  29. fprintf( stderr, "[%s] %s\n", qPrintable(QDateTime::currentDateTime().toString()), qPrintable(message));
  30. }
  31. }
  32. bool RuntimePage::acceptNavigationRequest ( QWebFrame * frame, const QNetworkRequest & request, NavigationType type ){
  33. // Webpage wants to open a new window, we delegate to the system browser
  34. if (frame == 0){
  35. QDesktopServices::openUrl(QUrl(request.url()));
  36. return 0;
  37. // Call parent function for all other requests
  38. } else {
  39. return(QWebPage::acceptNavigationRequest (frame, request, type ));
  40. }
  41. }
  42. bool RuntimePage::shouldInterruptJavaScript() {
  43. fprintf( stderr, "[%s] %s\n", qPrintable(QDateTime::currentDateTime().toString()), "Caught Javascript timeout warning.");
  44. // In debug mode we want to see the warning in the frontend, we never show it to the user though.
  45. if (QCoreApplication::arguments().contains("--debug")){
  46. return QWebPage::shouldInterruptJavaScript();
  47. } else {
  48. return false;
  49. }
  50. }