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