Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

This adds a new patch to Qt/WebKit (qtwebkit-004-add-prepend-API.patc…

…h) that adds a new API that facilitates adding history items so that the browser may be pre-loaded with history items on startup.

Then API was added to llmozlib to access this new feature, as well as new API
to clear the History and dump it to a string for debugging.

Modified ubrowser as well to facilitate testing of new API.

See https://jira.lindenlab.com/jira/browse/DEV-33640
and https://bugs.webkit.org/show_bug.cgi?id=26452
for more info.
  • Loading branch information...
commit 56c004737edfbf3d0addeb9d0e80b9430a82574e 1 parent 45e52cb
Rick Linden authored Rick Linden committed
View
28 llmozlib2/llembeddedbrowserwindow.cpp
@@ -37,6 +37,8 @@
*
* ***** END LICENSE BLOCK ***** */
+#include <sstream>
+
#include "llembeddedbrowserwindow.h"
#include "llembeddedbrowserwindow_p.h"
@@ -585,6 +587,32 @@ std::string LLEmbeddedBrowserWindow::getNoFollowScheme()
return d->mNoFollowScheme.toStdString();
}
+void LLEmbeddedBrowserWindow::prependHistoryUrl(std::string url)
+{
+ // *HACK: we only have a URL here, we set a "" title and "current time" as
+ // last visited time.
+ d->mPage->history()->prependItem(QString::fromStdString(url),
+ QString::fromAscii(""),
+ QDateTime::currentDateTime());
+}
+
+void LLEmbeddedBrowserWindow::clearHistory()
+{
+ d->mPage->history()->clear();
+}
+
+std::string LLEmbeddedBrowserWindow::dumpHistory()
+{
+ std::ostringstream oss;
+ const QList<QWebHistoryItem> &items = d->mPage->history()->backItems(9999);
+ oss << "cur: " << d->mPage->history()->currentItemIndex() << ":"
+ << d->mPage->history()->currentItem().url().toString().toAscii().data() << "\n";
+ for (int i=0; i< items.count(); i++) {
+ oss << items[i].url().toString().toAscii().data() << "\n";
+ }
+ return oss.str();
+}
+
LLGraphicsScene::LLGraphicsScene()
: QGraphicsScene()
, window(0)
View
6 llmozlib2/llembeddedbrowserwindow.h
@@ -125,6 +125,12 @@ class LLEmbeddedBrowserWindow
void setNoFollowScheme(std::string scheme);
std::string getNoFollowScheme();
+ // prepend the current history with the given url
+ void prependHistoryUrl(std::string url);
+ // clear the URL history
+ void clearHistory();
+ std::string dumpHistory();
+
private:
friend class LLWebPage;
friend class LLGraphicsScene;
View
34 llmozlib2/llmozlib2.cpp
@@ -606,6 +606,40 @@ bool LLMozLib::clr404RedirectUrl(int browser_window_in)
}
////////////////////////////////////////////////////////////////////////////////
+//
+void LLMozLib::prependHistoryUrl(int browser_window_id, std::string url)
+{
+ LLEmbeddedBrowserWindow* browser_window = getBrowserWindowFromWindowId(browser_window_id);
+ if (browser_window)
+ {
+ browser_window->prependHistoryUrl(url);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void LLMozLib::clearHistory(int browser_window_id)
+{
+ LLEmbeddedBrowserWindow* browser_window = getBrowserWindowFromWindowId(browser_window_id);
+ if (browser_window)
+ {
+ browser_window->clearHistory();
+ }
+}
+
+std::string LLMozLib::dumpHistory(int browser_window_id)
+{
+ LLEmbeddedBrowserWindow* browser_window = getBrowserWindowFromWindowId(browser_window_id);
+ if (browser_window)
+ {
+ return browser_window->dumpHistory();
+ }
+
+ return NULL;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
// utility method to get an LLEmbeddedBrowserWindow* from a window id (int)
LLEmbeddedBrowserWindow* LLMozLib::getBrowserWindowFromWindowId(int browser_window_id)
{
View
4 llmozlib2/llmozlib2.h
@@ -273,6 +273,10 @@ class LLMozLib
void pump(int max_milliseconds);
+ void prependHistoryUrl(int browser_window_id, std::string url);
+ void clearHistory(int browser_window_id);
+ std::string dumpHistory(int browser_window_id);
+
private:
LLMozLib();
LLEmbeddedBrowserWindow* getBrowserWindowFromWindowId(int browser_window_id);
View
108 llmozlib2/qt_patches/qtwebkit-004-add-prepend-API.patch
@@ -0,0 +1,108 @@
+From: Rick Linden (rick@lindenlab.com)
+Date: Tue Jun 16 15:53:38 PDT 2009
+Subject: Add API for prepending URLs to history
+
+This patch adds a new API to WebKit to add a "prepend URL" API, to facilitate
+adding history items so that the browser history can be pre-loaded upon startup.
+
+See https://jira.lindenlab.com/jira/browse/DEV-33640
+and https://bugs.webkit.org/show_bug.cgi?id=26452
+for more info
+
+diff -rup a/src/3rdparty/webkit/WebCore/history/BackForwardList.cpp b/src/3rdparty/webkit/WebCore/history/BackForwardList.cpp
+--- a/src/3rdparty/webkit/WebCore/history/BackForwardList.cpp 2009-02-25 12:32:34.000000000 -0800
++++ b/src/3rdparty/webkit/WebCore/history/BackForwardList.cpp 2009-06-16 14:39:22.007250000 -0700
+@@ -52,9 +52,9 @@ BackForwardList::~BackForwardList()
+ ASSERT(m_closed);
+ }
+
+-void BackForwardList::addItem(PassRefPtr<HistoryItem> prpItem)
++void BackForwardList::addItem(PassRefPtr<HistoryItem> newItem)
+ {
+- ASSERT(prpItem);
++ ASSERT(newItem);
+ if (m_capacity == 0 || !m_enabled)
+ return;
+
+@@ -79,10 +79,31 @@ void BackForwardList::addItem(PassRefPtr
+ m_current--;
+ }
+
+- m_entries.append(prpItem);
++ m_entries.append(newItem);
+ m_entryHash.add(m_entries.last());
+ m_current++;
+ }
++
++void BackForwardList::prependItem(PassRefPtr<HistoryItem> newItem)
++{
++ ASSERT(newItem);
++ if (m_capacity == 0 || !m_enabled)
++ return;
++
++ // Toss the first item if the list is getting too big, as long as we're not using it
++ // (or even if we are, if we only want 1 entry).
++ if (m_entries.size() == m_capacity && (m_current != 0 || m_capacity == 1)) {
++ RefPtr<HistoryItem> item = m_entries[0];
++ m_entries.remove(0);
++ m_entryHash.remove(item);
++ pageCache()->remove(item.get());
++ m_current--;
++ }
++
++ m_entries.prepend(newItem);
++ m_entryHash.add(newItem);
++ m_current++;
++}
+
+ void BackForwardList::goBack()
+ {
+diff -rup a/src/3rdparty/webkit/WebCore/history/BackForwardList.h b/src/3rdparty/webkit/WebCore/history/BackForwardList.h
+--- a/src/3rdparty/webkit/WebCore/history/BackForwardList.h 2009-02-25 12:32:34.000000000 -0800
++++ b/src/3rdparty/webkit/WebCore/history/BackForwardList.h 2009-06-11 13:31:12.078125000 -0700
+@@ -48,6 +48,7 @@ public:
+ Page* page() { return m_page; }
+
+ void addItem(PassRefPtr<HistoryItem>);
++ void prependItem(PassRefPtr<HistoryItem>);
+ void goBack();
+ void goForward();
+ void goToItem(HistoryItem*);
+diff -rup a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp
+--- a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp 2009-02-25 12:32:34.000000000 -0800
++++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp 2009-06-12 10:23:42.890625000 -0700
+@@ -248,6 +248,22 @@ void QWebHistory::clear()
+ }
+
+ /*!
++ Prepends history item given url, title, and lastVisited time
++
++ \sa count(), clear()
++*/
++void QWebHistory::prependItem(const QString &urlString, const QString &title,
++ const QDateTime &lastVisited)
++{
++ RefPtr<WebCore::HistoryItem> item =
++ WebCore::HistoryItem::create(WebCore::String(urlString), WebCore::String(title),
++ (double)lastVisited.toTime_t());
++
++ d->lst->prependItem(item);
++}
++
++
++/*!
+ Returns a list of all items currently in the history.
+
+ \sa count(), clear()
+diff -rup a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h
+--- a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h 2009-02-25 12:32:34.000000000 -0800
++++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h 2009-06-12 10:23:29.218750000 -0700
+@@ -69,6 +69,8 @@ class QWEBKIT_EXPORT QWebHistory
+ public:
+ void clear();
+
++ void prependItem(const QString &urlString, const QString &title, const QDateTime &lastVisited);
++
+ QList<QWebHistoryItem> items() const;
+ QList<QWebHistoryItem> backItems(int maxItems) const;
+ QList<QWebHistoryItem> forwardItems(int maxItems) const;
View
30 llmozlib2/tests/ubrowser/ubrowser.cpp
@@ -88,6 +88,7 @@ uBrowser::uBrowser() :
mIdNavHome( 0x0016 ),
mIdNavForward( 0x0017 ),
mIdNavReload( 0x001b ),
+ mIdNavAddToHistory( 0x001c ),
mIdBrowserSmall( 0x0018 ),
mIdBrowserMedium( 0x0019 ),
mIdBrowserLarge( 0x001a ),
@@ -310,6 +311,7 @@ void uBrowser::reshape( int widthIn, int heightIn )
// just a rough calculation
mUrlEdit->set_w( mWindowWidth - 400 );
+ mUrlAddToHistoryEdit->set_w( mWindowWidth - 500 );
mStatusText->set_w( mWindowWidth - 100 );
// update viewport (the active window inside the chrome stuff)
@@ -725,13 +727,13 @@ void uBrowser::idle()
}
// enable/disable back button depending on whether we can go back or not
- if ( LLMozLib::getInstance()->canNavigateBack( mCurWindowId ) )
+ if ( LLMozLib::getInstance()->userActionIsEnabled( mCurWindowId, LLMozLib::UA_NAVIGATE_BACK ) )
mNavBackButton->enable();
else
mNavBackButton->disable();
// enable/disable back button depending on whether we can go back or not
- if ( LLMozLib::getInstance()->canNavigateForward( mCurWindowId ) )
+ if ( LLMozLib::getInstance()->userActionIsEnabled( mCurWindowId, LLMozLib::UA_NAVIGATE_FORWARD ) )
mNavForwardButton->enable();
else
mNavForwardButton->disable();
@@ -808,6 +810,14 @@ void uBrowser::makeChrome()
{
bookmarkList->add_item( each, const_cast< char* >( mBookmarks[ each ].first.c_str() ) );
};
+
+ mTop2GLUIWindow->add_column( false );
+#ifdef LL_NEWER_GLUI
+ mUrlAddToHistoryEdit = mTop2GLUIWindow->add_edittext( "Add Url History item:", GLUI_EDITTEXT_TEXT, mNavUrl, mIdNavAddToHistory, gluiCallbackWrapper );
+#else // LL_NEWER_GLUI
+ // Friendly to older GLUI versions.
+ mUrlAddToHistoryEdit = mTop2GLUIWindow->add_edittext( "Add Url History item:", mNavUrl, mIdNavAddToHistory, gluiCallbackWrapper );
+#endif // LL_NEWER_GLU
mTop2GLUIWindow->set_main_gfx_window( mAppWindow );
// bottom UI bar
@@ -1095,12 +1105,12 @@ void uBrowser::gluiCallback( int controlIdIn )
else
if ( controlIdIn == mIdNavBack )
{
- LLMozLib::getInstance()->navigateBack( mCurWindowId );
+ LLMozLib::getInstance()->userAction( mCurWindowId, LLMozLib::UA_NAVIGATE_BACK );
}
else
if ( controlIdIn == mIdNavStop )
{
- LLMozLib::getInstance()->navigateStop( mCurWindowId );
+ LLMozLib::getInstance()->userAction( mCurWindowId, LLMozLib::UA_NAVIGATE_STOP );
}
else
if ( controlIdIn == mIdNavHome )
@@ -1110,12 +1120,20 @@ void uBrowser::gluiCallback( int controlIdIn )
else
if ( controlIdIn == mIdNavForward )
{
- LLMozLib::getInstance()->navigateForward( mCurWindowId );
+ LLMozLib::getInstance()->userAction( mCurWindowId, LLMozLib::UA_NAVIGATE_FORWARD );
}
else
if ( controlIdIn == mIdNavReload )
{
- LLMozLib::getInstance()->navigateReload( mCurWindowId );
+ LLMozLib::getInstance()->userAction( mCurWindowId, LLMozLib::UA_NAVIGATE_RELOAD );
+ }
+ else
+ if ( controlIdIn == mIdNavAddToHistory )
+ {
+ LLMozLib::getInstance()->prependHistoryUrl( mCurWindowId, mUrlAddToHistoryEdit->get_text() );
+ mUrlAddToHistoryEdit->set_text("");
+ const std::string &foo = LLMozLib::getInstance()->dumpHistory(mCurWindowId);
+ std::cout << foo << "\n";
}
else
if ( controlIdIn == mIdUrlEdit )
View
2  llmozlib2/tests/ubrowser/ubrowser.h
@@ -133,6 +133,7 @@ class uBrowser :
GLUI_Button* mNavForwardButton;
GLUI* mTop2GLUIWindow;
GLUI_EditText* mUrlEdit;
+ GLUI_EditText* mUrlAddToHistoryEdit;
GLUI_String mNavUrl;
GLUI* mRightGLUIWindow;
GLUI_Rotation* mViewRotationCtrl;
@@ -156,6 +157,7 @@ class uBrowser :
const int mIdNavHome;
const int mIdNavForward;
const int mIdNavReload;
+ const int mIdNavAddToHistory;
const int mIdBrowserSmall;
const int mIdBrowserMedium;
const int mIdBrowserLarge;
Please sign in to comment.
Something went wrong with that request. Please try again.