qwebhistoryinterface.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. This class provides all functionality needed for tracking global history.
  16. */
  17. #include "config.h"
  18. #include "qwebhistoryinterface.h"
  19. #include <QCoreApplication>
  20. #include "PageGroup.h"
  21. #include <wtf/text/WTFString.h>
  22. static QWebHistoryInterface* default_interface;
  23. static bool gRoutineAdded;
  24. static void gCleanupInterface()
  25. {
  26. if (default_interface && !default_interface->parent())
  27. delete default_interface;
  28. default_interface = 0;
  29. }
  30. /*!
  31. Sets a new default interface, \a defaultInterface, that will be used by all of WebKit
  32. to keep track of visited links.
  33. If an interface without a parent has already been set, the old interface will be deleted.
  34. When the application exists QWebHistoryInterface will automatically delete the
  35. \a defaultInterface if it does not have a parent.
  36. */
  37. void QWebHistoryInterface::setDefaultInterface(QWebHistoryInterface* defaultInterface)
  38. {
  39. if (default_interface == defaultInterface)
  40. return;
  41. if (default_interface && !default_interface->parent())
  42. delete default_interface;
  43. default_interface = defaultInterface;
  44. WebCore::PageGroup::removeAllVisitedLinks();
  45. //### enable after the introduction of a version
  46. //WebCore::PageGroup::setShouldTrackVisitedLinks(true);
  47. if (!gRoutineAdded) {
  48. qAddPostRoutine(gCleanupInterface);
  49. gRoutineAdded = true;
  50. }
  51. }
  52. /*!
  53. Returns the default interface that will be used by WebKit. If no default interface has been set,
  54. WebKit will not keep track of visited links and a null pointer will be returned.
  55. \sa setDefaultInterface()
  56. */
  57. QWebHistoryInterface* QWebHistoryInterface::defaultInterface()
  58. {
  59. return default_interface;
  60. }
  61. /*!
  62. \class QWebHistoryInterface
  63. \since 4.4
  64. \brief The QWebHistoryInterface class provides an interface to implement link history.
  65. \inmodule QtWebKit
  66. The QWebHistoryInterface is an interface that can be used to
  67. keep track of visited links. It contains two pure virtual methods that
  68. are called by the WebKit engine: addHistoryEntry() is used to add
  69. urls that have been visited to the interface, while
  70. historyContains() is used to query whether the given url has been
  71. visited by the user. By default the QWebHistoryInterface is not set, so WebKit does not keep
  72. track of visited links.
  73. \note The history tracked by QWebHistoryInterface is not specific to an instance of QWebPage
  74. but applies to all pages.
  75. */
  76. /*!
  77. Constructs a new QWebHistoryInterface with parent \a parent.
  78. */
  79. QWebHistoryInterface::QWebHistoryInterface(QObject* parent)
  80. : QObject(parent)
  81. {
  82. }
  83. /*!
  84. Destroys the interface. If this is currently the default interface it will be unset.
  85. */
  86. QWebHistoryInterface::~QWebHistoryInterface()
  87. {
  88. if (default_interface == this)
  89. default_interface = 0;
  90. }
  91. /*!
  92. \fn bool QWebHistoryInterface::historyContains(const QString &url) const = 0
  93. Called by the WebKit engine to query whether a certain \a url has been visited by the user already.
  94. Returns true if the \a url is part of the history of visited links; otherwise returns false.
  95. */
  96. /*!
  97. \fn void QWebHistoryInterface::addHistoryEntry(const QString &url) = 0
  98. Called by WebKit to add another \a url to the list of visited pages.
  99. */