diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-07 10:52:57 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-07 10:52:57 +0200 |
commit | 5be7f76e30f6655f82a677b73c7fcea4feeda42d (patch) | |
tree | 73423d8ef54ef72c517511e54ffdfa99c7f64750 /src/ui/documentwidget.c | |
parent | e9b2b0fa360c1802ca05f744e85702e8a0a98cd0 (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/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 25 |
1 files changed, 21 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); | |||
358 | static void prerender_DocumentWidget_ (iAny *); | 358 | static void prerender_DocumentWidget_ (iAny *); |
359 | static void scrollBegan_DocumentWidget_ (iAnyObject *, int, uint32_t); | 359 | static void scrollBegan_DocumentWidget_ (iAnyObject *, int, uint32_t); |
360 | static void refreshWhileScrolling_DocumentWidget_ (iAny *); | 360 | static void refreshWhileScrolling_DocumentWidget_ (iAny *); |
361 | static 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 | ||
2391 | static void postProcessRequestContent_DocumentWidget_(iDocumentWidget *d, iBool isCached) { | 2392 | static 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) { |