• 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   for managing history.
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
72   default interface has been set, QtWebkit will not track history.
73 */
defaultInterface()74 QWebHistoryInterface* QWebHistoryInterface::defaultInterface()
75 {
76     return default_interface;
77 }
78 
79 /*!
80   \class QWebHistoryInterface
81   \since 4.4
82   \brief The QWebHistoryInterface class provides an interface to implement link history.
83 
84   The QWebHistoryInterface is an interface that can be used to
85   implement link history. It contains two pure virtual methods that
86   are called by the WebKit engine.  addHistoryEntry() is used to add
87   pages that have been visited to the interface, while
88   historyContains() is used to query whether this page has been
89   visited by the user.
90 */
91 
92 /*!
93     Constructs a new QWebHistoryInterface with parent \a parent.
94 */
QWebHistoryInterface(QObject * parent)95 QWebHistoryInterface::QWebHistoryInterface(QObject* parent)
96     : QObject(parent)
97 {
98 }
99 
100 /*!
101     Destructor.  If this is currently the default interface it will be unset.
102 */
~QWebHistoryInterface()103 QWebHistoryInterface::~QWebHistoryInterface()
104 {
105     if (default_interface == this)
106         default_interface = 0;
107 }
108 
109 /*!
110   \fn bool QWebHistoryInterface::historyContains(const QString &url) const = 0
111 
112   Called by the WebKit engine to query whether a certain \a url has been visited by the user already.
113   Returns true if the \a url is part of the history of visited links; otherwise returns false.
114 */
115 
116 /*!
117   \fn void QWebHistoryInterface::addHistoryEntry(const QString &url) = 0
118 
119   Called by WebKit to add another \a url to the list of visited pages.
120 */
121