1 /* 2 Copyright (C) 2007 Staikos Computing Services Inc. <info (at) 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 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 */ 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 */ 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 \inmodule QtWebKit 85 86 The QWebHistoryInterface is an interface that can be used to 87 implement link history. It contains two pure virtual methods that 88 are called by the WebKit engine. addHistoryEntry() is used to add 89 pages that have been visited to the interface, while 90 historyContains() is used to query whether this page has been 91 visited by the user. 92 */ 93 94 /*! 95 Constructs a new QWebHistoryInterface with parent \a parent. 96 */ 97 QWebHistoryInterface::QWebHistoryInterface(QObject* parent) 98 : QObject(parent) 99 { 100 } 101 102 /*! 103 Destructor. If this is currently the default interface it will be unset. 104 */ 105 QWebHistoryInterface::~QWebHistoryInterface() 106 { 107 if (default_interface == this) 108 default_interface = 0; 109 } 110 111 /*! 112 \fn bool QWebHistoryInterface::historyContains(const QString &url) const = 0 113 114 Called by the WebKit engine to query whether a certain \a url has been visited by the user already. 115 Returns true if the \a url is part of the history of visited links; otherwise returns false. 116 */ 117 118 /*! 119 \fn void QWebHistoryInterface::addHistoryEntry(const QString &url) = 0 120 121 Called by WebKit to add another \a url to the list of visited pages. 122 */ 123