summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-06-15 10:31:20 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-06-15 10:31:20 +0300
commitd5a87c08b3ed5521a21a72c048e5cf4db68314fa (patch)
treece3bce2b1d0a3349f3faec4e3dab8ca65cdb38f6 /src
parente5e3b291ac0adc2eab0ec5840b7bad99517b4d59 (diff)
DocumentWidget: Caching error page documents
Diffstat (limited to 'src')
-rw-r--r--src/gmdocument.c4
-rw-r--r--src/gmdocument.h1
-rw-r--r--src/history.c1
-rw-r--r--src/ui/documentwidget.c23
4 files changed, 21 insertions, 8 deletions
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) {
919 return d->media; 919 return d->media;
920} 920}
921 921
922const iString *url_GmDocument(const iGmDocument *d) {
923 return &d->url;
924}
925
922#if 0 926#if 0
923void reset_GmDocument(iGmDocument *d) { 927void reset_GmDocument(iGmDocument *d) {
924 clear_Media(d->media); 928 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 *);
179 179
180iMedia * media_GmDocument (iGmDocument *); 180iMedia * media_GmDocument (iGmDocument *);
181const iMedia * constMedia_GmDocument (const iGmDocument *); 181const iMedia * constMedia_GmDocument (const iGmDocument *);
182const iString * url_GmDocument (const iGmDocument *);
182 183
183void render_GmDocument (const iGmDocument *, iRangei visRangeY, 184void render_GmDocument (const iGmDocument *, iRangei visRangeY,
184 iGmDocumentRenderFunc render, void *); /* includes partial overlaps */ 185 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
391 lock_Mutex(d->mtx); 391 lock_Mutex(d->mtx);
392 iRecentUrl *item = mostRecentUrl_History(d); 392 iRecentUrl *item = mostRecentUrl_History(d);
393 if (item) { 393 if (item) {
394 iAssert(equal_String(url_GmDocument(doc), &item->url));
394 item->flags.openedFromSidebar = openedFromSidebar; 395 item->flags.openedFromSidebar = openedFromSidebar;
395 if (item->cachedDoc != doc) { 396 if (item->cachedDoc != doc) {
396 iRelease(item->cachedDoc); 397 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) {
1042 d->flags |= otherRootByDefault_DocumentWidgetFlag; 1042 d->flags |= otherRootByDefault_DocumentWidgetFlag;
1043 } 1043 }
1044 } 1044 }
1045 showOrHidePinningIndicator_DocumentWidget_(d); 1045 showOrHidePinningIndicator_DocumentWidget_(d);
1046 setCachedDocument_History(d->mod.history,
1047 d->doc, /* keeps a ref */
1048 (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0);
1046} 1049}
1047 1050
1048void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { 1051void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) {
@@ -1168,8 +1171,14 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode
1168 { person_Icon " ${menu.identity.new}", newIdentity_KeyShortcut, "ident.new" } }, 1171 { person_Icon " ${menu.identity.new}", newIdentity_KeyShortcut, "ident.new" } },
1169 2); 1172 2);
1170 } 1173 }
1171 setBanner_GmDocument(d->doc, useBanner ? bannerType_DocumentWidget_(d) : none_GmDocumentBanner); 1174 /* Make a new document for the error page.*/ {
1172 setFormat_GmDocument(d->doc, gemini_SourceFormat); 1175 iGmDocument *errorDoc = new_GmDocument();
1176 setUrl_GmDocument(errorDoc, d->mod.url);
1177 setBanner_GmDocument(errorDoc, useBanner ? bannerType_DocumentWidget_(d) : none_GmDocumentBanner);
1178 setFormat_GmDocument(errorDoc, gemini_SourceFormat);
1179 replaceDocument_DocumentWidget_(d, errorDoc);
1180 iRelease(errorDoc);
1181 }
1173 translate_Lang(src); 1182 translate_Lang(src);
1174 d->state = ready_RequestState; 1183 d->state = ready_RequestState;
1175 setSource_DocumentWidget(d, src); 1184 setSource_DocumentWidget(d, src);
@@ -1608,8 +1617,8 @@ static void updateFromCachedResponse_DocumentWidget_(iDocumentWidget *d, float n
1608 format_String(&d->sourceHeader, cstr_Lang("pageinfo.header.cached")); 1617 format_String(&d->sourceHeader, cstr_Lang("pageinfo.header.cached"));
1609 set_Block(&d->sourceContent, &resp->body); 1618 set_Block(&d->sourceContent, &resp->body);
1610 updateDocument_DocumentWidget_(d, resp, cachedDoc, iTrue); 1619 updateDocument_DocumentWidget_(d, resp, cachedDoc, iTrue);
1611 setCachedDocument_History(d->mod.history, d->doc, 1620// setCachedDocument_History(d->mod.history, d->doc,
1612 (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0); 1621// (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0);
1613 } 1622 }
1614 d->state = ready_RequestState; 1623 d->state = ready_RequestState;
1615 postProcessRequestContent_DocumentWidget_(d, iTrue); 1624 postProcessRequestContent_DocumentWidget_(d, iTrue);
@@ -2705,8 +2714,6 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2705 (startsWithCase_String(meta_GmRequest(d->request), "text/") || 2714 (startsWithCase_String(meta_GmRequest(d->request), "text/") ||
2706 !cmp_String(&d->sourceMime, mimeType_Gempub))) { 2715 !cmp_String(&d->sourceMime, mimeType_Gempub))) {
2707 setCachedResponse_History(d->mod.history, lockResponse_GmRequest(d->request)); 2716 setCachedResponse_History(d->mod.history, lockResponse_GmRequest(d->request));
2708 setCachedDocument_History(d->mod.history, d->doc, /* keeps a ref */
2709 (d->flags & openedFromSidebar_DocumentWidgetFlag) != 0);
2710 unlockResponse_GmRequest(d->request); 2717 unlockResponse_GmRequest(d->request);
2711 } 2718 }
2712 } 2719 }
@@ -4917,7 +4924,7 @@ void setRedirectCount_DocumentWidget(iDocumentWidget *d, int count) {
4917 4924
4918void setOpenedFromSidebar_DocumentWidget(iDocumentWidget *d, iBool fromSidebar) { 4925void setOpenedFromSidebar_DocumentWidget(iDocumentWidget *d, iBool fromSidebar) {
4919 iChangeFlags(d->flags, openedFromSidebar_DocumentWidgetFlag, fromSidebar); 4926 iChangeFlags(d->flags, openedFromSidebar_DocumentWidgetFlag, fromSidebar);
4920 setCachedDocument_History(d->mod.history, d->doc, fromSidebar); 4927// setCachedDocument_History(d->mod.history, d->doc, fromSidebar);
4921} 4928}
4922 4929
4923iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) { 4930iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) {