summaryrefslogtreecommitdiff
path: root/desktop/page-info.c
blob: 416c8e519e05e2b0c8e76b011b24a4cf43ecc2ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/*
 * Copyright 2020 Michael Drake <tlsa@netsurf-browser.org>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * \file
 * Pave info viewer window implementation
 */

#include <stdlib.h>
#include <string.h>

#include "css/utils.h"

#include "utils/nsurl.h"

#include "netsurf/mouse.h"
#include "netsurf/layout.h"
#include "netsurf/keypress.h"
#include "netsurf/plotters.h"
#include "netsurf/core_window.h"
#include "netsurf/browser_window.h"

#include "desktop/knockout.h"
#include "desktop/page-info.h"
#include "desktop/gui_internal.h"
#include "desktop/system_colour.h"

/**
 * Plot style for heading font.
 */
static plot_font_style_t pi__heading[PAGE_STATE__COUNT] = {
	[PAGE_STATE_UNKNOWN] = {
		.family = PLOT_FONT_FAMILY_SANS_SERIF,
		.size = 14 * PLOT_STYLE_SCALE,
		.flags = FONTF_NONE,
		.weight = 400,
	},
	[PAGE_STATE_INTERNAL] = {
		.family = PLOT_FONT_FAMILY_SANS_SERIF,
		.size = 14 * PLOT_STYLE_SCALE,
		.flags = FONTF_NONE,
		.weight = 400,
	},
	[PAGE_STATE_LOCAL] = {
		.family = PLOT_FONT_FAMILY_SANS_SERIF,
		.size = 14 * PLOT_STYLE_SCALE,
		.flags = FONTF_NONE,
		.weight = 400,
	},
	[PAGE_STATE_INSECURE] = {
		.family = PLOT_FONT_FAMILY_SANS_SERIF,
		.size = 14 * PLOT_STYLE_SCALE,
		.flags = FONTF_NONE,
		.weight = 400,
	},
	[PAGE_STATE_SECURE_OVERRIDE] = {
		.family = PLOT_FONT_FAMILY_SANS_SERIF,
		.size = 14 * PLOT_STYLE_SCALE,
		.flags = FONTF_NONE,
		.weight = 400,
	},
	[PAGE_STATE_SECURE_ISSUES] = {
		.family = PLOT_FONT_FAMILY_SANS_SERIF,
		.size = 14 * PLOT_STYLE_SCALE,
		.flags = FONTF_NONE,
		.weight = 400,
	},
	[PAGE_STATE_SECURE] = {
		.family = PLOT_FONT_FAMILY_SANS_SERIF,
		.size = 14 * PLOT_STYLE_SCALE,
		.flags = FONTF_NONE,
		.weight = 400,
	},
};

/**
 * Plot style for domain font.
 */
static plot_font_style_t pi__domain = {
	.family = PLOT_FONT_FAMILY_SANS_SERIF,
	.size = 8 * PLOT_STYLE_SCALE,
	.flags = FONTF_NONE,
	.weight = 700,
};

/**
 * Plot style for item font.
 */
static plot_font_style_t pi__item = {
	.family = PLOT_FONT_FAMILY_SANS_SERIF,
	.size = 11 * PLOT_STYLE_SCALE,
	.flags = FONTF_NONE,
	.weight = 400,
};

/**
 * Plot style for item detail font.
 */
static plot_font_style_t pi__item_detail = {
	.family = PLOT_FONT_FAMILY_SANS_SERIF,
	.size = 11 * PLOT_STYLE_SCALE,
	.flags = FONTF_NONE,
	.weight = 400,
};

/**
 * Plot style for window background.
 */
static plot_style_t pi__bg = {
	.fill_type = PLOT_OP_TYPE_SOLID,
};

/**
 * Plot style for hover background.
 */
static plot_style_t pi__hover = {
	.fill_type = PLOT_OP_TYPE_SOLID,
};

/**
 * An "text" type page info entry.
 */
struct page_info_text {
	const char *text;
	const plot_font_style_t *style;
	int width;
	int height;
	int padding_bottom;
};

/**
 * An "item" type page info entry.
 */
struct page_info_item {
	struct page_info_text item;
	struct page_info_text detail;
	const plot_style_t *hover_bg;
	int padding_bottom;
	int padding_top;
	bool hover;
};

/**
 * List of page info window entries.
 */
enum pi_entry {
	PI_ENTRY_HEADER,
	PI_ENTRY_DOMAIN,
	PI_ENTRY_CERT,
	PI_ENTRY_COOKIES,
	PI_ENTRY__COUNT,
};

/**
 * An entry on a page info window.
 */
struct page_info_entry {
	/**
	 * List of page info entry types.
	 */
	enum page_info_entry_type {
		PAGE_INFO_ENTRY_TYPE_TEXT,
		PAGE_INFO_ENTRY_TYPE_ITEM,
	} type;
	/**
	 * Type-specific page info entry data.
	 */
	union {
		struct page_info_text text;
		struct page_info_item item;
	} u;
};

/**
 * The default page info window data.
 */
struct page_info_entry pi__entries[PI_ENTRY__COUNT] = {
	[PI_ENTRY_HEADER] = {
		.type = PAGE_INFO_ENTRY_TYPE_TEXT,
	},
	[PI_ENTRY_DOMAIN] = {
		.type = PAGE_INFO_ENTRY_TYPE_TEXT,
		.u = {
			.text = {
				.style = &pi__domain,
			},
		},
	},
	[PI_ENTRY_CERT] = {
		.type = PAGE_INFO_ENTRY_TYPE_ITEM,
		.u = {
			.item = {
				.item = {
					.style = &pi__item,
				},
				.detail = {
					.style = &pi__item_detail,
				},
				.hover_bg = &pi__hover,
			},
		},
	},
	[PI_ENTRY_COOKIES] = {
		.type = PAGE_INFO_ENTRY_TYPE_ITEM,
		.u = {
			.item = {
				.item = {
					.style = &pi__item,
				},
				.detail = {
					.style = &pi__item_detail,
				},
				.hover_bg = &pi__hover,
			},
		},
	},
};

/**
 * The page info window structure.
 */
struct page_info {
	const struct core_window_callback_table *cw_t;
	struct core_window *cw_h;

	struct browser_window *bw;
	lwc_string *domain;

	browser_window_page_info_state state;
	unsigned cookies;

	char cookie_text[64];
	struct page_info_entry entries[PI_ENTRY__COUNT];

	int width;
	int height;

	int window_padding;
};

/* Exported interface documented in desktop/page_info.h */
nserror page_info_init(void)
{
	bool dark_on_light;
	nserror err;
	colour good;
	colour bad;
	colour bg;
	colour fg;

	err = ns_system_colour_char("Window", &bg);
	if (err != NSERROR_OK) {
		return err;
	}

	err = ns_system_colour_char("WindowText", &fg);
	if (err != NSERROR_OK) {
		return err;
	}

	dark_on_light = colour_lightness(bg) > colour_lightness(fg);

	pi__bg.fill_colour = bg;
	pi__hover.fill_colour = dark_on_light?
			darken_colour(bg) :
			lighten_colour(bg);

	pi__domain.background = bg;
	pi__domain.foreground = fg;

	pi__item.background = bg;
	pi__item.foreground = fg;

	pi__item_detail.background = bg;
	pi__item_detail.foreground = blend_colour(bg, fg);

	good = colour_engorge_component(fg,
			dark_on_light, PLOT_COLOUR_COMPONENT_GREEN);
	bad = colour_engorge_component(fg,
			dark_on_light, PLOT_COLOUR_COMPONENT_RED);

	pi__heading[PAGE_STATE_UNKNOWN].background = bg;
	pi__heading[PAGE_STATE_UNKNOWN].foreground = bad;
	pi__heading[PAGE_STATE_INTERNAL].background = bg;
	pi__heading[PAGE_STATE_INTERNAL].foreground = fg;
	pi__heading[PAGE_STATE_LOCAL].background = bg;
	pi__heading[PAGE_STATE_LOCAL].foreground = fg;
	pi__heading[PAGE_STATE_INSECURE].background = bg;
	pi__heading[PAGE_STATE_INSECURE].foreground = bad;
	pi__heading[PAGE_STATE_SECURE_OVERRIDE].background = bg;
	pi__heading[PAGE_STATE_SECURE_OVERRIDE].foreground = bad;
	pi__heading[PAGE_STATE_SECURE_ISSUES].background = bg;
	pi__heading[PAGE_STATE_SECURE_ISSUES].foreground = bad;
	pi__heading[PAGE_STATE_SECURE].background = bg;
	pi__heading[PAGE_STATE_SECURE].foreground = good;

	return NSERROR_OK;
}

/* Exported interface documented in desktop/page_info.h */
nserror page_info_fini(void)
{
	return NSERROR_OK;
}

/**
 * Measure the text in the page_info window.
 *
 * \param[in] pi  The page info window handle.
 * \return NSERROR_OK on success, appropriate error code otherwise.
 */
static nserror page_info__measure_text_entry(
		struct page_info_text *pit)
{
	nserror err;
	int height_px;

	err = guit->layout->width(pit->style,
			pit->text, strlen(pit->text),
			&pit->width);
	if (err != NSERROR_OK) {
		return err;
	}

	/* \todo: This needs to be a helper in plot style or in nscss. */
	height_px = ((pit->style->size / PLOT_STYLE_SCALE) *
			FIXTOINT(nscss_screen_dpi) + 36) / 72;

	pit->height = (height_px * 8 + 3) / 6;

	return NSERROR_OK;
}

/**
 * Measure the text in the page_info window.
 *
 * \param[in] pi  The page info window handle.
 * \return NSERROR_OK on success, appropriate error code otherwise.
 */
static nserror page_info__measure_text(
		struct page_info *pi)
{
	nserror err;

	for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
		struct page_info_entry *entry = pi->entries + i;
		int padding;

		switch (entry->type) {
		case PAGE_INFO_ENTRY_TYPE_TEXT:
			err = page_info__measure_text_entry(
					&entry->u.text);
			if (err != NSERROR_OK) {
				return err;
			}
			if (i == PI_ENTRY_DOMAIN) {
				entry->u.text.padding_bottom =
						entry->u.text.height * 3 / 2;
			}
			break;

		case PAGE_INFO_ENTRY_TYPE_ITEM:
			err = page_info__measure_text_entry(
					&entry->u.item.item);
			if (err != NSERROR_OK) {
				return err;
			}
			err = page_info__measure_text_entry(
					&entry->u.item.detail);
			if (err != NSERROR_OK) {
				return err;
			}
			padding = entry->u.item.item.height / 4;
			entry->u.item.padding_top = padding;
			entry->u.item.padding_bottom = padding;

			break;
		}
	}

	pi->window_padding = pi->entries[PI_ENTRY_DOMAIN]
			.u.item.item.height / 2;

	return NSERROR_OK;
}

/**
 * Set the text for the page_info window.
 *
 * \todo Use messages for internationalisation.
 *
 * \param[in] pi  The page info window handle.
 * \return NSERROR_OK on success, appropriate error code otherwise.
 */
static nserror page_info__set_text(
		struct page_info *pi)
{
	int printed;
	static const char *header[PAGE_STATE__COUNT] = {
		[PAGE_STATE_UNKNOWN]         = "Provenance unknown",
		[PAGE_STATE_INTERNAL]        = "NetSurf data",
		[PAGE_STATE_LOCAL]           = "Local data",
		[PAGE_STATE_INSECURE]        = "Connection not secure",
		[PAGE_STATE_SECURE_OVERRIDE] = "Connection not secure",
		[PAGE_STATE_SECURE_ISSUES]   = "Connection not secure",
		[PAGE_STATE_SECURE]          = "Connection is secure",
	};
	static const char *certificate[PAGE_STATE__COUNT] = {
		[PAGE_STATE_UNKNOWN]         = "Missing",
		[PAGE_STATE_INTERNAL]        = "None",
		[PAGE_STATE_LOCAL]           = "None",
		[PAGE_STATE_INSECURE]        = "Not valid",
		[PAGE_STATE_SECURE_OVERRIDE] = "Not valid",
		[PAGE_STATE_SECURE_ISSUES]   = "Not valid",
		[PAGE_STATE_SECURE]          = "Valid",
	};

	assert(pi != NULL);
	assert(pi->state < PAGE_STATE__COUNT);

	pi->entries[PI_ENTRY_HEADER].u.text.style = &pi__heading[pi->state];
	pi->entries[PI_ENTRY_HEADER].u.text.text = header[pi->state];
	pi->entries[PI_ENTRY_DOMAIN].u.text.text = (pi->domain) ?
			lwc_string_data(pi->domain) : "<No domain>";

	pi->entries[PI_ENTRY_CERT].u.item.item.text = "Certificate: ";
	pi->entries[PI_ENTRY_CERT].u.item.detail.text = certificate[pi->state];

	printed = snprintf(pi->cookie_text, sizeof(pi->cookie_text),
			"(%u in use)", pi->cookies);
	if (printed < 0) {
		return NSERROR_UNKNOWN;

	} else if ((unsigned) printed >= sizeof(pi->cookie_text)) {
		return NSERROR_NOSPACE;
	}
	pi->entries[PI_ENTRY_COOKIES].u.item.item.text = "Cookies: ";
	pi->entries[PI_ENTRY_COOKIES].u.item.detail.text = pi->cookie_text;

	return page_info__measure_text(pi);
}

/**
 * Create page info from a browser window.
 *
 * \param[in] pi  The page info window handle.
 * \param[in] bw  Browser window to show page info for.
 * \return NSERROR_OK on success, appropriate error code otherwise.
 */
static nserror page_info__create_from_bw(
		struct page_info *pi,
		struct browser_window *bw)
{
	nsurl *url = browser_window_access_url(bw);

	pi->bw = bw;
	pi->state = browser_window_get_page_info_state(bw);
	pi->cookies = browser_window_get_cookie_count(bw);
	pi->domain = nsurl_get_component(url, NSURL_HOST);

	return page_info__set_text(pi);
}

/**
 * Lay out the page info window.
 *
 * \param[in] pi  The page info window handle.
 * \return NSERROR_OK on success, appropriate error code otherwise.
 */
static nserror page_info__layout(
		struct page_info *pi)
{
	int cur_y = 0;
	int max_x = 0;

	cur_y += pi->window_padding;
	for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
		struct page_info_entry *entry = pi->entries + i;

		switch (entry->type) {
		case PAGE_INFO_ENTRY_TYPE_TEXT:
			cur_y += entry->u.text.height;
			if (max_x < entry->u.text.width) {
				max_x = entry->u.text.width;
			}
			cur_y += entry->u.text.padding_bottom;
			break;

		case PAGE_INFO_ENTRY_TYPE_ITEM:
		{
			int full_width = entry->u.item.item.width +
					entry->u.item.detail.width;
			cur_y += entry->u.item.padding_top;
			cur_y += entry->u.item.item.height;
			if (max_x < full_width) {
				max_x = full_width;
			}
			cur_y += entry->u.item.padding_bottom;
		}
			break;
		}
	}
	cur_y += pi->window_padding;
	max_x += pi->window_padding * 2;

	pi->width = max_x;
	pi->height = cur_y;
	return pi->cw_t->update_size(pi->cw_h, max_x, cur_y);
}

/* Exported interface documented in desktop/page_info.h */
nserror page_info_create(
		const struct core_window_callback_table *cw_t,
		struct core_window *cw_h,
		struct browser_window *bw,
		struct page_info **pi_out)
{
	struct page_info *pi;
	nserror err;

	pi = calloc(1, sizeof(*pi));
	if (pi == NULL) {
		return NSERROR_NOMEM;
	}

	pi->cw_t = cw_t;
	pi->cw_h = cw_h;

	memcpy(pi->entries, pi__entries, sizeof(pi__entries));

	err = page_info__create_from_bw(pi, bw);
	if (err != NSERROR_OK) {
		page_info_destroy(pi);
		return err;
	}

	err = page_info__layout(pi);
	if (err != NSERROR_OK) {
		page_info_destroy(pi);
		return err;
	}

	*pi_out = pi;
	return NSERROR_OK;
}

/* Exported interface documented in desktop/page_info.h */
void page_info_destroy(
		struct page_info *pi)
{
	if (pi->domain != NULL) {
		lwc_string_unref(pi->domain);
	}
	free(pi);
}

/**
 * Render a text entry.
 *
 * \param[in] pit  The page info window handle.
 * \param[in] x    X-coordinate to plot at.
 * \param[in] y    Y-coordinate to plot at.
 * \param[in] ctx  Current redraw context.
 * \return NSERROR_OK on success, appropriate error code otherwise.
 */
static nserror page_info__redraw_text_entry(
		const struct page_info_text *pit,
		int x,
		int y,
		const struct redraw_context *ctx)
{
	int baseline = (pit->height * 3 + 2) / 4;

	ctx->plot->text(ctx, pit->style, x, y + baseline,
			pit->text, strlen(pit->text));

	return NSERROR_OK;
}

/* Exported interface documented in desktop/page_info.h */
nserror page_info_redraw(
		const struct page_info *pi,
		int x,
		int y,
		const struct rect *clip,
		const struct redraw_context *ctx)
{
	struct redraw_context new_ctx = *ctx;
	struct rect r = {
		.x0 = clip->x0 + x,
		.y0 = clip->y0 + y,
		.x1 = clip->x1 + x,
		.y1 = clip->y1 + y,
	};
	int cur_y = 0;
	nserror err;

	/* Start knockout rendering if it's available for this plotter. */
	if (ctx->plot->option_knockout) {
		bool res = knockout_plot_start(ctx, &new_ctx);
		if (res == false) {
			return NSERROR_UNKNOWN;
		}
	}

	/* Set up clip rectangle and draw background. */
	new_ctx.plot->clip(&new_ctx, &r);
	new_ctx.plot->rectangle(&new_ctx, &pi__bg, &r);

	cur_y += pi->window_padding;
	for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
		const struct page_info_entry *entry = pi->entries + i;
		int cur_x = pi->window_padding;

		switch (entry->type) {
		case PAGE_INFO_ENTRY_TYPE_TEXT:
			err = page_info__redraw_text_entry(
					&entry->u.text,
					cur_x, cur_y,
					&new_ctx);
			if (err != NSERROR_OK) {
				goto cleanup;
			}
			cur_y += entry->u.text.height;
			cur_y += entry->u.text.padding_bottom;
			break;

		case PAGE_INFO_ENTRY_TYPE_ITEM:
			if (entry->u.item.hover) {
				r.y0 = cur_y;
				r.y1 = cur_y + entry->u.item.padding_top +
						entry->u.item.item.height +
						entry->u.item.padding_bottom;
				new_ctx.plot->rectangle(&new_ctx,
						&pi__hover, &r);
			}
			cur_y += entry->u.item.padding_top;
			err = page_info__redraw_text_entry(
					&entry->u.item.item,
					cur_x, cur_y,
					&new_ctx);
			if (err != NSERROR_OK) {
				goto cleanup;
			}
			cur_x += entry->u.item.item.width;
			err = page_info__redraw_text_entry(
					&entry->u.item.detail,
					cur_x, cur_y,
					&new_ctx);
			if (err != NSERROR_OK) {
				goto cleanup;
			}
			cur_y += entry->u.item.item.height;
			cur_y += entry->u.item.padding_bottom;
			break;
		}
	}

cleanup:
	/* Rendering complete */
	if (ctx->plot->option_knockout) {
		bool res = knockout_plot_end(ctx);
		if (res == false) {
			return NSERROR_UNKNOWN;
		}
	}

	return NSERROR_OK;
}

/**
 * Handle any clicks on an item.
 *
 * \param[in] pi       The page info window handle.
 * \param[in] mouse    The current mouse state.
 * \param[in] clicked  The page info window entry to consider clicks on.
 * \return NSERROR_OK on success, appropriate error code otherwise.
 */
static nserror page_info__handle_item_click(
		struct page_info *pi,
		enum browser_mouse_state mouse,
		enum pi_entry clicked)
{
	nserror err;

	if (!(mouse & BROWSER_MOUSE_CLICK_1)) {
		return NSERROR_OK;
	}

	switch (clicked) {
	case PI_ENTRY_CERT:
		err = browser_window_show_certificates(pi->bw);
		break;
	case PI_ENTRY_COOKIES:
		err = browser_window_show_cookies(pi->bw);
		break;
	default:
		err = NSERROR_OK;
		break;
	}

	return err;
}

/* Exported interface documented in desktop/page_info.h */
nserror page_info_mouse_action(
		struct page_info *pi,
		enum browser_mouse_state mouse,
		int x,
		int y)
{
	int cur_y = 0;
	nserror err;

	cur_y += pi->window_padding;
	for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
		struct page_info_entry *entry = pi->entries + i;
		bool hovering = false;
		int height;

		switch (entry->type) {
		case PAGE_INFO_ENTRY_TYPE_TEXT:
			cur_y += entry->u.text.height;
			cur_y += entry->u.text.padding_bottom;
			break;

		case PAGE_INFO_ENTRY_TYPE_ITEM:
			height = entry->u.item.padding_top +
			         entry->u.item.item.height +
			         entry->u.item.padding_bottom;

			if (y >= cur_y && y < cur_y + height) {
				hovering = true;
				err = page_info__handle_item_click(
						pi, mouse, i);
				if (err != NSERROR_OK) {
					return err;
				}
			}
			if (entry->u.item.hover != hovering) {
				int w, h;
				struct rect r = {
					.x0 = 0,
					.y0 = cur_y,
					.y1 = cur_y + height,
				};
				pi->cw_t->get_window_dimensions(
						pi->cw_h, &w, &h);
				r.x1 = (pi->width > w) ? pi->width : w;

				pi->cw_t->invalidate(pi->cw_h, &r);
			}
			entry->u.item.hover = hovering;
			cur_y += height;
			break;
		}
	}

	return NSERROR_OK;
}

/* Exported interface documented in desktop/page_info.h */
bool page_info_keypress(
		struct page_info *pi,
		int32_t key)
{
	return NSERROR_OK;
}

/* Exported interface documented in desktop/page_info.h */
nserror page_info_get_size(
		struct page_info *pi,
		int *width,
		int *height)
{
	*width = pi->width;
	*height = pi->height;

	return NSERROR_OK;
}