summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-06-30 08:20:38 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-06-30 08:20:38 +0300
commit73a721fc93c3be7b13361dea41d4431ad14a3fdd (patch)
treee6de1687d1932509789e21ed4232fe2c6def32ad /src/ui
parent42d461f32eb77a83c0f9d7b4fb202de72c64a97f (diff)
Canonical URIs
Internally, all URIs should be converted to a canonical form so that they can be compared against each other. The canonical form is an IRI with spaces and reserved characters percent-encoded.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c14
-rw-r--r--src/ui/inputwidget.c2
-rw-r--r--src/ui/root.c2
-rw-r--r--src/ui/sidebarwidget.c6
4 files changed, 14 insertions, 10 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index cb1fde28..509933af 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1470,7 +1470,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d,
1470 baseName_Path(collect_String(newRange_String(parts.path))).start; 1470 baseName_Path(collect_String(newRange_String(parts.path))).start;
1471 } 1471 }
1472 format_String(&str, "=> %s %s\n", 1472 format_String(&str, "=> %s %s\n",
1473 cstr_String(withSpacesEncoded_String(d->mod.url)), 1473 cstr_String(canonicalUrl_String(d->mod.url)),
1474 linkTitle); 1474 linkTitle);
1475 setData_Media(media_GmDocument(d->doc), 1475 setData_Media(media_GmDocument(d->doc),
1476 imgLinkId, 1476 imgLinkId,
@@ -1638,7 +1638,7 @@ static void updateFromCachedResponse_DocumentWidget_(iDocumentWidget *d, float n
1638} 1638}
1639 1639
1640static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { 1640static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) {
1641 const iRecentUrl *recent = findUrl_History(d->mod.history, withSpacesEncoded_String(d->mod.url)); 1641 const iRecentUrl *recent = findUrl_History(d->mod.history, canonicalUrl_String(d->mod.url));
1642 if (recent && recent->cachedResponse) { 1642 if (recent && recent->cachedResponse) {
1643 iChangeFlags(d->flags, 1643 iChangeFlags(d->flags,
1644 openedFromSidebar_DocumentWidgetFlag, 1644 openedFromSidebar_DocumentWidgetFlag,
@@ -1845,8 +1845,11 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
1845 d->sourceStatus = statusCode; 1845 d->sourceStatus = statusCode;
1846 switch (category_GmStatusCode(statusCode)) { 1846 switch (category_GmStatusCode(statusCode)) {
1847 case categoryInput_GmStatusCode: { 1847 case categoryInput_GmStatusCode: {
1848 /* Let the navigation history know that we have been to this URL even though
1849 it is only displayed as an input dialog. */
1850 visitUrl_Visited(visited_App(), d->mod.url, transient_VisitedUrlFlag);
1848 iUrl parts; 1851 iUrl parts;
1849 init_Url(&parts, d->mod.url); 1852 init_Url(&parts, d->mod.url);
1850 iWidget *dlg = makeValueInput_Widget( 1853 iWidget *dlg = makeValueInput_Widget(
1851 as_Widget(d), 1854 as_Widget(d),
1852 NULL, 1855 NULL,
@@ -2646,11 +2649,11 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2646 } 2649 }
2647 else if (equal_Command(cmd, "document.copylink") && document_App() == d) { 2650 else if (equal_Command(cmd, "document.copylink") && document_App() == d) {
2648 if (d->contextLink) { 2651 if (d->contextLink) {
2649 SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(absoluteUrl_String( 2652 SDL_SetClipboardText(cstr_String(canonicalUrl_String(absoluteUrl_String(
2650 d->mod.url, linkUrl_GmDocument(d->doc, d->contextLink->linkId))))); 2653 d->mod.url, linkUrl_GmDocument(d->doc, d->contextLink->linkId)))));
2651 } 2654 }
2652 else { 2655 else {
2653 SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(d->mod.url))); 2656 SDL_SetClipboardText(cstr_String(canonicalUrl_String(d->mod.url)));
2654 } 2657 }
2655 return iTrue; 2658 return iTrue;
2656 } 2659 }
@@ -4870,6 +4873,7 @@ void deserializeState_DocumentWidget(iDocumentWidget *d, iStream *ins) {
4870} 4873}
4871 4874
4872static void setUrl_DocumentWidget_(iDocumentWidget *d, const iString *url) { 4875static void setUrl_DocumentWidget_(iDocumentWidget *d, const iString *url) {
4876 url = canonicalUrl_String(url);
4873 if (!equal_String(d->mod.url, url)) { 4877 if (!equal_String(d->mod.url, url)) {
4874 d->flags |= urlChanged_DocumentWidgetFlag; 4878 d->flags |= urlChanged_DocumentWidgetFlag;
4875 set_String(d->mod.url, url); 4879 set_String(d->mod.url, url);
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index b108ee17..8ea21cff 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -903,7 +903,7 @@ static iBool copy_InputWidget_(iInputWidget *d, iBool doCut) {
903 iString *str = collect_String(newUnicodeN_String(constAt_Array(&d->text, m.start), 903 iString *str = collect_String(newUnicodeN_String(constAt_Array(&d->text, m.start),
904 size_Range(&m))); 904 size_Range(&m)));
905 SDL_SetClipboardText( 905 SDL_SetClipboardText(
906 cstr_String(d->inFlags & isUrl_InputWidgetFlag ? withSpacesEncoded_String(str) : str)); 906 cstr_String(d->inFlags & isUrl_InputWidgetFlag ? canonicalUrl_String(str) : str));
907 if (doCut) { 907 if (doCut) {
908 pushUndo_InputWidget_(d); 908 pushUndo_InputWidget_(d);
909 deleteMarked_InputWidget_(d); 909 deleteMarked_InputWidget_(d);
diff --git a/src/ui/root.c b/src/ui/root.c
index 5266978b..c78c9632 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -725,7 +725,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
725 const iString *urlStr = collect_String(suffix_Command(cmd, "url")); 725 const iString *urlStr = collect_String(suffix_Command(cmd, "url"));
726 trimCache_App(); 726 trimCache_App();
727 trimMemory_App(); 727 trimMemory_App();
728 visitUrl_Visited(visited_App(), withSpacesEncoded_String(urlStr), 0); /* TODO: internal URI normalization */ 728 visitUrl_Visited(visited_App(), urlStr, 0); /* TODO: internal URI normalization */
729 postCommand_App("visited.changed"); /* sidebar will update */ 729 postCommand_App("visited.changed"); /* sidebar will update */
730 setText_InputWidget(url, urlStr); 730 setText_InputWidget(url, urlStr);
731 checkLoadAnimation_Root_(get_Root()); 731 checkLoadAnimation_Root_(get_Root());
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index c0a22e99..4c2a9d64 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -217,7 +217,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
217 iBool isEmpty = iFalse; /* show blank? */ 217 iBool isEmpty = iFalse; /* show blank? */
218 switch (d->mode) { 218 switch (d->mode) {
219 case feeds_SidebarMode: { 219 case feeds_SidebarMode: {
220 const iString *docUrl = withSpacesEncoded_String(url_DocumentWidget(document_App())); 220 const iString *docUrl = canonicalUrl_String(url_DocumentWidget(document_App()));
221 /* TODO: internal URI normalization */ 221 /* TODO: internal URI normalization */
222 iTime now; 222 iTime now;
223 iDate on; 223 iDate on;
@@ -1111,7 +1111,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1111 else if (isCommand_Widget(w, ev, "bookmark.copy")) { 1111 else if (isCommand_Widget(w, ev, "bookmark.copy")) {
1112 const iSidebarItem *item = d->contextItem; 1112 const iSidebarItem *item = d->contextItem;
1113 if (d->mode == bookmarks_SidebarMode && item) { 1113 if (d->mode == bookmarks_SidebarMode && item) {
1114 SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(&item->url))); 1114 SDL_SetClipboardText(cstr_String(canonicalUrl_String(&item->url)));
1115 } 1115 }
1116 return iTrue; 1116 return iTrue;
1117 } 1117 }
@@ -1374,7 +1374,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1374 else if (isCommand_Widget(w, ev, "history.copy")) { 1374 else if (isCommand_Widget(w, ev, "history.copy")) {
1375 const iSidebarItem *item = d->contextItem; 1375 const iSidebarItem *item = d->contextItem;
1376 if (item && !isEmpty_String(&item->url)) { 1376 if (item && !isEmpty_String(&item->url)) {
1377 SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(&item->url))); 1377 SDL_SetClipboardText(cstr_String(canonicalUrl_String(&item->url)));
1378 } 1378 }
1379 return iTrue; 1379 return iTrue;
1380 } 1380 }