summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2022-02-07 10:52:57 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2022-02-07 10:52:57 +0200
commit5be7f76e30f6655f82a677b73c7fcea4feeda42d (patch)
tree73423d8ef54ef72c517511e54ffdfa99c7f64750 /src/ui
parente9b2b0fa360c1802ca05f744e85702e8a0a98cd0 (diff)
GmDocument: Handling images in "data:" URLs
One can embed arbitrary data inside a "data:" URL. If an image is recognized, attempt to show it as part of the document.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c25
-rw-r--r--src/ui/linkinfo.c8
2 files changed, 29 insertions, 4 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 31b96644..b19958b2 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -358,6 +358,7 @@ static void updateSideIconBuf_DocumentWidget_ (const iDocumentWidget *d);
358static void prerender_DocumentWidget_ (iAny *); 358static void prerender_DocumentWidget_ (iAny *);
359static void scrollBegan_DocumentWidget_ (iAnyObject *, int, uint32_t); 359static void scrollBegan_DocumentWidget_ (iAnyObject *, int, uint32_t);
360static void refreshWhileScrolling_DocumentWidget_ (iAny *); 360static void refreshWhileScrolling_DocumentWidget_ (iAny *);
361static iBool requestMedia_DocumentWidget_ (iDocumentWidget *d, iGmLinkId linkId, iBool enableFilters);
361 362
362/* TODO: The following methods are called from DocumentView, which goes the wrong way. */ 363/* TODO: The following methods are called from DocumentView, which goes the wrong way. */
363 364
@@ -2390,6 +2391,19 @@ static const char *zipPageHeading_(const iRangecc mime) {
2390 2391
2391static void postProcessRequestContent_DocumentWidget_(iDocumentWidget *d, iBool isCached) { 2392static void postProcessRequestContent_DocumentWidget_(iDocumentWidget *d, iBool isCached) {
2392 iWidget *w = as_Widget(d); 2393 iWidget *w = as_Widget(d);
2394 /* Embedded images in data links should be shown immediately as they are already fetched
2395 data that is part of the document. */ {
2396 iGmDocument *doc = d->view.doc;
2397 for (size_t linkId = 1; ; linkId++) {
2398 const int linkFlags = linkFlags_GmDocument(doc, linkId);
2399 const iString *linkUrl = linkUrl_GmDocument(doc, linkId);
2400 if (!linkUrl) break;
2401 if (scheme_GmLinkFlag(linkFlags) == data_GmLinkScheme &&
2402 (linkFlags & imageFileExtension_GmLinkFlag)) {
2403 requestMedia_DocumentWidget_(d, linkId, 0);
2404 }
2405 }
2406 }
2393 /* Gempub page behavior and footer actions. */ { 2407 /* Gempub page behavior and footer actions. */ {
2394 /* TODO: move this to gempub.c */ 2408 /* TODO: move this to gempub.c */
2395 delete_Gempub(d->sourceGempub); 2409 delete_Gempub(d->sourceGempub);
@@ -3136,6 +3150,9 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
3136 setUrl_DocumentWidget_(d, url_GmDocument(d->view.doc)); 3150 setUrl_DocumentWidget_(d, url_GmDocument(d->view.doc));
3137 updateFetchProgress_DocumentWidget_(d); 3151 updateFetchProgress_DocumentWidget_(d);
3138 postCommand_Widget(d, "media.updated link:%u request:%p", d->requestLinkId, mr); 3152 postCommand_Widget(d, "media.updated link:%u request:%p", d->requestLinkId, mr);
3153 if (isFinished_GmRequest(mr->req)) {
3154 postCommand_Widget(d, "media.finished link:%u request:%p", d->requestLinkId, mr);
3155 }
3139 return; 3156 return;
3140 } 3157 }
3141 /* Get ready for the incoming new document. */ 3158 /* Get ready for the incoming new document. */
@@ -5515,10 +5532,10 @@ static void prerender_DocumentWidget_(iAny *context) {
5515 } 5532 }
5516 const iDocumentWidget *d = context; 5533 const iDocumentWidget *d = context;
5517 iDrawContext ctx = { 5534 iDrawContext ctx = {
5518 .view = &d->view, 5535 .view = &d->view,
5519 .docBounds = documentBounds_DocumentView_(&d->view), 5536 .docBounds = documentBounds_DocumentView_(&d->view),
5520 .vis = visibleRange_DocumentView_(&d->view), 5537 .vis = visibleRange_DocumentView_(&d->view),
5521 .showLinkNumbers = (d->flags & showLinkNumbers_DocumentWidgetFlag) != 0 5538 .showLinkNumbers = (d->flags & showLinkNumbers_DocumentWidgetFlag) != 0
5522 }; 5539 };
5523 // printf("%u prerendering\n", SDL_GetTicks()); 5540 // printf("%u prerendering\n", SDL_GetTicks());
5524 if (d->view.visBuf->buffers[0].texture) { 5541 if (d->view.visBuf->buffers[0].texture) {
diff --git a/src/ui/linkinfo.c b/src/ui/linkinfo.c
index 5102f9b3..8974a486 100644
--- a/src/ui/linkinfo.c
+++ b/src/ui/linkinfo.c
@@ -91,6 +91,14 @@ void infoText_LinkInfo(const iGmDocument *doc, iGmLinkId linkId, iString *text_o
91 appendCStr_String(text_out, "\x1b[0m"); 91 appendCStr_String(text_out, "\x1b[0m");
92 appendRange_String(text_out, (iRangecc){ parts.path.start, constEnd_String(url) }); 92 appendRange_String(text_out, (iRangecc){ parts.path.start, constEnd_String(url) });
93 } 93 }
94 else if (scheme == data_GmLinkScheme) {
95 appendCStr_String(text_out, "\U0001f4e6 ");
96 const char *comma = strchr(cstr_String(url), ',');
97 if (!comma) {
98 comma = iMin(constEnd_String(url), constBegin_String(url) + 256);
99 }
100 appendRange_String(text_out, (iRangecc){ constBegin_String(url), comma });
101 }
94 else if (scheme != gemini_GmLinkScheme) { 102 else if (scheme != gemini_GmLinkScheme) {
95 appendCStr_String(text_out, scheme == file_GmLinkScheme ? "" : globe_Icon " "); 103 appendCStr_String(text_out, scheme == file_GmLinkScheme ? "" : globe_Icon " ");
96 append_String(text_out, url); 104 append_String(text_out, url);