From d5a87c08b3ed5521a21a72c048e5cf4db68314fa Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 15 Jun 2021 10:31:20 +0300 Subject: DocumentWidget: Caching error page documents --- src/gmdocument.c | 4 ++++ src/gmdocument.h | 1 + src/history.c | 1 + src/ui/documentwidget.c | 23 +++++++++++++++-------- 4 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gmdocument.c b/src/gmdocument.c index 0ab09604..aa2baa4a 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -919,6 +919,10 @@ const iMedia *constMedia_GmDocument(const iGmDocument *d) { return d->media; } +const iString *url_GmDocument(const iGmDocument *d) { + return &d->url; +} + #if 0 void reset_GmDocument(iGmDocument *d) { clear_Media(d->media); diff --git a/src/gmdocument.h b/src/gmdocument.h index 221e5c00..831459d8 100644 --- a/src/gmdocument.h +++ b/src/gmdocument.h @@ -179,6 +179,7 @@ typedef void (*iGmDocumentRenderFunc)(void *, const iGmRun *); iMedia * media_GmDocument (iGmDocument *); const iMedia * constMedia_GmDocument (const iGmDocument *); +const iString * url_GmDocument (const iGmDocument *); void render_GmDocument (const iGmDocument *, iRangei visRangeY, iGmDocumentRenderFunc render, void *); /* includes partial overlaps */ diff --git a/src/history.c b/src/history.c index c592838e..2cea393d 100644 --- a/src/history.c +++ b/src/history.c @@ -391,6 +391,7 @@ void setCachedDocument_History(iHistory *d, iGmDocument *doc, iBool openedFromSi lock_Mutex(d->mtx); iRecentUrl *item = mostRecentUrl_History(d); if (item) { + iAssert(equal_String(url_GmDocument(doc), &item->url)); item->flags.openedFromSidebar = openedFromSidebar; if (item->cachedDoc != doc) { iRelease(item->cachedDoc); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 0fe8220e..599e7ef3 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1042,7 +1042,10 @@ static void documentWasChanged_DocumentWidget_(iDocumentWidget *d) { d->flags |= otherRootByDefault_DocumentWidgetFlag; } } - showOrHidePinningIndicator_DocumentWidget_(d); + showOrHidePinningIndicator_DocumentWidget_(d); + setCachedDocument_History(d->mod.history, + d->doc, /* keeps a ref */ + (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0); } void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { @@ -1168,8 +1171,14 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode { person_Icon " ${menu.identity.new}", newIdentity_KeyShortcut, "ident.new" } }, 2); } - setBanner_GmDocument(d->doc, useBanner ? bannerType_DocumentWidget_(d) : none_GmDocumentBanner); - setFormat_GmDocument(d->doc, gemini_SourceFormat); + /* Make a new document for the error page.*/ { + iGmDocument *errorDoc = new_GmDocument(); + setUrl_GmDocument(errorDoc, d->mod.url); + setBanner_GmDocument(errorDoc, useBanner ? bannerType_DocumentWidget_(d) : none_GmDocumentBanner); + setFormat_GmDocument(errorDoc, gemini_SourceFormat); + replaceDocument_DocumentWidget_(d, errorDoc); + iRelease(errorDoc); + } translate_Lang(src); d->state = ready_RequestState; setSource_DocumentWidget(d, src); @@ -1608,8 +1617,8 @@ static void updateFromCachedResponse_DocumentWidget_(iDocumentWidget *d, float n format_String(&d->sourceHeader, cstr_Lang("pageinfo.header.cached")); set_Block(&d->sourceContent, &resp->body); updateDocument_DocumentWidget_(d, resp, cachedDoc, iTrue); - setCachedDocument_History(d->mod.history, d->doc, - (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0); +// setCachedDocument_History(d->mod.history, d->doc, +// (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0); } d->state = ready_RequestState; postProcessRequestContent_DocumentWidget_(d, iTrue); @@ -2705,8 +2714,6 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) (startsWithCase_String(meta_GmRequest(d->request), "text/") || !cmp_String(&d->sourceMime, mimeType_Gempub))) { setCachedResponse_History(d->mod.history, lockResponse_GmRequest(d->request)); - setCachedDocument_History(d->mod.history, d->doc, /* keeps a ref */ - (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0); unlockResponse_GmRequest(d->request); } } @@ -4917,7 +4924,7 @@ void setRedirectCount_DocumentWidget(iDocumentWidget *d, int count) { void setOpenedFromSidebar_DocumentWidget(iDocumentWidget *d, iBool fromSidebar) { iChangeFlags(d->flags, openedFromSidebar_DocumentWidgetFlag, fromSidebar); - setCachedDocument_History(d->mod.history, d->doc, fromSidebar); +// setCachedDocument_History(d->mod.history, d->doc, fromSidebar); } iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) { -- cgit v1.2.3