MainQt.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 University of Szeged
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  15. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  18. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  24. * THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <qglobal.h>
  27. #if defined(QT_NO_WIDGETS)
  28. #include <QGuiApplication>
  29. typedef QGuiApplication ApplicationType;
  30. #else
  31. #include <QApplication>
  32. typedef QApplication ApplicationType;
  33. #endif
  34. #include <stdio.h>
  35. #if !defined(NDEBUG) && defined(Q_OS_UNIX)
  36. #include <signal.h>
  37. #include <unistd.h>
  38. #endif
  39. namespace WebKit {
  40. Q_DECL_IMPORT int WebProcessMainQt(QGuiApplication*);
  41. #if !defined(QT_NO_WIDGETS)
  42. Q_DECL_IMPORT void initializeWebKitWidgets();
  43. #endif
  44. }
  45. #if !defined(NDEBUG) && defined(Q_OS_UNIX)
  46. static void sigcontHandler(int)
  47. {
  48. }
  49. #endif
  50. static void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& message)
  51. {
  52. if (type == QtCriticalMsg) {
  53. fprintf(stderr, "%s\n", qPrintable(message));
  54. return;
  55. }
  56. // Do nothing
  57. }
  58. // The framework entry point.
  59. // We call our platform specific entry point directly rather than WebKitMain because it makes little sense
  60. // to reimplement the handling of command line arguments from QApplication.
  61. int main(int argc, char** argv)
  62. {
  63. #if !defined(NDEBUG) && defined(Q_OS_UNIX)
  64. if (qgetenv("QT_WEBKIT_PAUSE_WEB_PROCESS") == "1" || qgetenv("QT_WEBKIT2_DEBUG") == "1") {
  65. struct sigaction newAction, oldAction;
  66. newAction.sa_handler = sigcontHandler;
  67. sigemptyset(&newAction.sa_mask);
  68. newAction.sa_flags = 0;
  69. sigaction(SIGCONT, &newAction, &oldAction);
  70. fprintf(stderr, "Pausing UI process, please attach to PID %d and send signal SIGCONT... ", getpid());
  71. pause();
  72. sigaction(SIGCONT, &oldAction, 0);
  73. fprintf(stderr, " OK\n");
  74. }
  75. #endif
  76. // Has to be done before QApplication is constructed in case
  77. // QApplication itself produces debug output.
  78. QByteArray suppressOutput = qgetenv("QT_WEBKIT_SUPPRESS_WEB_PROCESS_OUTPUT");
  79. if (!suppressOutput.isEmpty() && suppressOutput != "0")
  80. qInstallMessageHandler(messageHandler);
  81. // QApplication must be created before we call initializeWebKitWidgets() so that
  82. // the standard pixmaps can be fetched from the style.
  83. ApplicationType* appInstance = new ApplicationType(argc, argv);
  84. #if !defined(QT_NO_WIDGETS)
  85. if (qgetenv("QT_WEBKIT_THEME_NAME") == "qstyle")
  86. WebKit::initializeWebKitWidgets();
  87. #endif
  88. return WebKit::WebProcessMainQt(appInstance);
  89. }