Subversion Repositories Kolibri OS

Rev

Rev 8302 | Rev 8319 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7739 leency 1
//Copyright 2007-2020 by Veliant & Leency
6978 leency 2
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
3067 leency 3
 
4085 leency 4
#ifndef AUTOBUILD
5
	#include "lang.h--"
6
#endif
7
 
3107 leency 8
//libraries
7771 leency 9
#define MEMSIZE 1024 * 1000
5499 leency 10
#include "..\lib\gui.h"
4508 leency 11
#include "..\lib\draw_buf.h"
12
#include "..\lib\list_box.h"
13
#include "..\lib\cursor.h"
5978 leency 14
#include "..\lib\collection.h"
6795 leency 15
#include "..\lib\random.h"
7037 leency 16
#include "..\lib\clipboard.h"
5981 leency 17
 
7437 leency 18
// *.obj libraries
5499 leency 19
#include "..\lib\obj\box_lib.h"
7049 leency 20
#include "..\lib\obj\libio.h"
21
#include "..\lib\obj\libimg.h"
5499 leency 22
#include "..\lib\obj\http.h"
5690 leency 23
#include "..\lib\obj\iconv.h"
7748 leency 24
#include "..\lib\obj\proc_lib.h"
7757 leency 25
 
5408 leency 26
//useful patterns
5978 leency 27
#include "..\lib\patterns\history.h"
7748 leency 28
#include "..\lib\patterns\simple_open_dialog.h"
7759 leency 29
#include "..\lib\patterns\toolbar_button.h"
7914 leency 30
#include "..\lib\patterns\restart_process.h"
5408 leency 31
 
8278 leency 32
char editbox_icons[] = FROM "res/editbox_icons.raw";
33
 
8305 leency 34
char version[]="WebView 2.7b";
8016 leency 35
 
7771 leency 36
#include "texts.h"
37
#include "cache.h"
7757 leency 38
#include "show_src.h"
7771 leency 39
 
7757 leency 40
bool debug_mode = false;
7771 leency 41
 
7791 leency 42
enum {
43
	NEW_TAB=600,
44
	ENCODINGS=700,
45
	BACK_BUTTON=800,
46
	FORWARD_BUTTON,
47
	REFRESH_BUTTON,
48
	GOTOURL_BUTTON,
49
	CHANGE_ENCODING,
50
	SANDWICH_BUTTON,
51
	VIEW_SOURCE,
52
	EDIT_SOURCE,
53
	OPEN_FILE,
54
	NEW_WINDOW,
55
	VIEW_HISTORY,
56
	DOWNLOAD_MANAGER,
57
	CLEAR_CACHE,
58
	UPDATE_BROWSER,
59
	IN_NEW_TAB,
60
	IN_NEW_WINDOW,
61
	COPY_LINK_URL,
8305 leency 62
	DOWNLOAD_LINK_CT,
7791 leency 63
	TAB_ID,
64
	TAB_CLOSE_ID = 900
65
};
66
 
8016 leency 67
_history history;
68
 
7970 leency 69
enum { TARGET_SAME_TAB, TARGET_NEW_WINDOW, TARGET_NEW_TAB };
70
 
7759 leency 71
#include "..\TWB\TWB.c" //HTML Parser, a core component
7757 leency 72
 
7759 leency 73
TWebBrowser WB1;
7758 leency 74
 
7771 leency 75
#include "history.h"
7752 leency 76
 
7758 leency 77
#define PADDING 9
78
#define TSZE 25
7771 leency 79
#define STATUSBAR_H 15
80
#define TAB_H 20
7758 leency 81
dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
4677 leency 82
 
7759 leency 83
_http http = 0;
7758 leency 84
 
7750 leency 85
bool source_mode = false;
7282 leency 86
 
5718 leency 87
progress_bar wv_progress_bar;
7750 leency 88
char stak[4096];
89
proc_info Form;
7748 leency 90
 
7780 leency 91
int menu_id=NULL;
92
 
7771 leency 93
#include "tabs.h"
94
 
7748 leency 95
char default_dir[] = "/rd/1";
7788 leency 96
od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" };
7748 leency 97
 
7755 leency 98
char editURL[URL_SIZE+1];
7758 leency 99
edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff,
100
	0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19};
4534 leency 101
 
7914 leency 102
dword shared_url;
7784 leency 103
 
8016 leency 104
dword http_get_type;
105
 
7748 leency 106
void LoadLibraries()
107
{
108
	load_dll(boxlib,    #box_lib_init,0);
109
	load_dll(libio,     #libio_init,1);
110
	load_dll(libimg,    #libimg_init,1);
111
	load_dll(libHTTP,   #http_lib_init,1);
112
	load_dll(iconv_lib, #iconv_open,0);
113
	load_dll(Proc_lib,  #OpenDialog_init,0);
114
	OpenDialog_init stdcall (#o_dialog);
115
}
116
 
117
void HandleParam()
118
{
8278 leency 119
	if (!param) {
120
		history.add(URL_SERVICE_HOMEPAGE);
121
	} else {
122
		if (!strncmp(#param, "-source ", 8)) {
7750 leency 123
			source_mode = true;
7765 leency 124
			history.add(#param + 8);
7936 leency 125
		} else if (!strncmp(#param, "-new ", 5)) {
126
			history.add(#param + 5);
7748 leency 127
		} else {
7914 leency 128
			if (GetProcessesCount("WEBVIEW") == 1) {
129
				history.add(#param);
130
			} else {
131
				shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_OPEN + SHM_WRITE);
132
				strncpy(shared_url, #param, URL_SIZE);
133
				ExitProcess();
134
			}
7748 leency 135
		}
136
	}
7914 leency 137
	shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_CREATE + SHM_WRITE);
7920 leency 138
	ESDWORD[shared_url] = '\0';
7748 leency 139
}
140
 
3067 leency 141
void main()
142
{
7970 leency 143
	int i, redirect_count=0;
7748 leency 144
	LoadLibraries();
145
	HandleParam();
6045 leency 146
	WB1.list.SetFont(8, 14, 10011000b);
5779 leency 147
	WB1.list.no_selection = true;
7759 leency 148
	WB1.custom_encoding = -1;
6978 leency 149
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
7914 leency 150
	loop() switch(@WaitEventTimeout(30))
6978 leency 151
	{
152
		case evMouse:
153
			edit_box_mouse stdcall (#address_box);
154
			mouse.get();
7970 leency 155
 
7282 leency 156
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
7970 leency 157
 
6978 leency 158
			scrollbar_v_mouse (#scroll_wv);
7970 leency 159
			if (scroll_wv.delta) {
6978 leency 160
				WB1.list.first = scroll_wv.position;
161
				WB1.DrawPage();
3067 leency 162
				break;
6978 leency 163
			}
7970 leency 164
 
165
			if (links.hover(WB1.list.y, WB1.list.first))
7758 leency 166
			{
7970 leency 167
				if (mouse.mkm) {
168
					if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
169
						EventClickLink(TARGET_NEW_WINDOW);
170
					} else {
171
						EventClickLink(TARGET_NEW_TAB);
172
					}
173
				}
174
				if (mouse.lkm) {
175
					CursorPointer.Restore();
176
					EventClickLink(TARGET_SAME_TAB);
177
				}
178
				if (mouse.pkm) {
179
					CursorPointer.Restore();
180
					EventShowLinkMenu();
181
				}
182
			} else {
183
				CursorPointer.Restore();
184
				if (mouse.pkm) && (WB1.list.MouseOver(mouse.x, mouse.y)) {
185
					EventShowPageMenu();
186
				}
7758 leency 187
			}
6978 leency 188
			break;
5711 leency 189
 
6978 leency 190
		case evButton:
8016 leency 191
			ProcessEvent( @GetButtonID() );
6978 leency 192
			break;
5711 leency 193
 
6978 leency 194
		case evKey:
195
			GetKeys();
7771 leency 196
 
197
			if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
198
				if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();break;}
199
			}
200
 
7772 leency 201
			if (ProcessCtrlKeyEvent()) break;
7743 leency 202
 
203
			if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
204
 
7506 leency 205
			if (address_box.flags & ed_focus)
6978 leency 206
			{
7742 leency 207
				if (key_scancode == SCAN_CODE_ENTER) {
208
					ProcessEvent(key_scancode);
7771 leency 209
				} else {
6978 leency 210
					EAX = key_editbox;
211
					edit_box_key stdcall(#address_box);
5530 leency 212
				}
7771 leency 213
			} else {
7422 leency 214
				#define KEY_SCROLL_N 11
215
				if (SCAN_CODE_UP   == key_scancode) for (i=0;i
216
				if (SCAN_CODE_DOWN == key_scancode) for (i=0;i
7743 leency 217
				if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
6978 leency 218
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
219
				else ProcessEvent(key_scancode);
220
			}
221
			break;
222
 
223
		case evReDraw:
7780 leency 224
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80), //40
7755 leency 225
				GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
6978 leency 226
			GetProcessInfo(#Form, SelfInfo);
7780 leency 227
			ProcessMenuClick();
7806 leency 228
			sc.get();
7759 leency 229
			if (Form.status_window>2) break;
6978 leency 230
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
231
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
7748 leency 232
			draw_window();
6978 leency 233
			break;
234
 
235
		case evNetwork:
7758 leency 236
			if (http.transfer <= 0) break;
237
			http.receive();
238
			EventUpdateProgressBar();
8305 leency 239
			CheckContentType();
7758 leency 240
			if (http.receive_result != 0) break;
241
			if (http.status_code >= 300) && (http.status_code < 400)
242
			{
243
				// Handle redirects
244
				if (redirect_count<=5) {
245
					redirect_count++;
8305 leency 246
					HandleRedirect();
7758 leency 247
				} else {
248
					notify("'Too many redirects.' -E");
249
					StopLoading();
7791 leency 250
					redirect_count = 0;
4536 leency 251
				}
7758 leency 252
			} else {
253
				// Loading the page is complete, free resources
254
				redirect_count = 0;
8291 leency 255
				http.hfree();
8016 leency 256
				if (http_get_type==PAGE) {
257
					cache.add(history.current(), http.content_pointer, http.content_received, PAGE);
258
					LoadInternalPage(http.content_pointer, http.content_received);
259
				}
260
				else if (http_get_type==IMG) {
261
					cache.add(WB1.page_img.current_url(), http.content_pointer, http.content_received, IMG);
262
					WB1.page_img.set_data(cache.data.get_last(), http.content_received);
263
					GetImg();
264
				}
6978 leency 265
			}
7914 leency 266
			break;
267
		default:
268
			if (ESDWORD[shared_url] != '\0') {
269
				EventOpenNewTab(shared_url);
270
				ESDWORD[shared_url] = '\0';
271
				ActivateWindow(GetProcessSlot(Form.ID));
272
			}
6978 leency 273
	}
3067 leency 274
}
275
 
7772 leency 276
bool ProcessCtrlKeyEvent()
277
{
278
	if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode)
279
	{
8016 leency 280
		case SCAN_CODE_KEY_O: EventOpenDialog(); return true;
281
		case SCAN_CODE_KEY_H: ProcessEvent(VIEW_HISTORY); return true;
282
		case SCAN_CODE_KEY_U: EventViewSource(); return true;
283
		case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return true;
284
		case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return true;
285
		case SCAN_CODE_KEY_J: ProcessEvent(DOWNLOAD_MANAGER); return true;
286
		case SCAN_CODE_KEY_R: ProcessEvent(REFRESH_BUTTON); return true;
287
		case SCAN_CODE_ENTER: EventSeachWeb(); return true;
288
		case SCAN_CODE_LEFT:  ProcessEvent(BACK_BUTTON); return true;
289
		case SCAN_CODE_RIGHT: ProcessEvent(FORWARD_BUTTON); return true;
290
		case SCAN_CODE_KEY_W: EventCloseActiveTab(); return true;
291
		case SCAN_CODE_TAB:   EventActivateNextTab(); return true;
292
		default: return false;
7772 leency 293
	}
294
}
295
 
3067 leency 296
void SetElementSizes()
297
{
7758 leency 298
	address_box.width = Form.cwidth - address_box.left - 52 - 16;
7771 leency 299
	WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x,
300
		Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H);
7759 leency 301
	WB1.list.wheel_size = 7 * BASIC_LINE_H;
7746 leency 302
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
6794 leency 303
	WB1.list.visible = WB1.list.h;
3067 leency 304
}
305
 
5981 leency 306
 
7748 leency 307
void draw_window()
3067 leency 308
{
7758 leency 309
	int i;
7910 leency 310
	bool burger_active = false;
311
	if (menu_id == OPEN_FILE) burger_active = true;
312
 
3067 leency 313
	SetElementSizes();
7758 leency 314
 
7806 leency 315
	DrawBar(0,0, Form.cwidth,PADDING, sc.work);
316
	DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, sc.work);
317
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(sc.work_dark, sc.work, 180));
318
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, sc.work_graph);
319
	DrawBar(0, PADDING, address_box.left-2, TSZE+1, sc.work);
320
	DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, sc.work);
7758 leency 321
 
7910 leency 322
	DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30, false);
323
	DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31, false);
324
	DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1, burger_active); //burger menu
7758 leency 325
 
7806 leency 326
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
7758 leency 327
 
328
	DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x,
329
		WB1.list.h-1, scroll_wv.bckg_col);
330
 
7771 leency 331
	if (!BrowserWidthChanged()) {
332
		WB1.DrawPage();
333
		DrawOmnibox();
334
	}
335
	DrawProgress();
7970 leency 336
	DrawStatusBar();
7771 leency 337
	DrawTabsBar();
338
}
339
 
340
bool BrowserWidthChanged()
341
{
342
	dword source_mode_holder;
343
	if (WB1.list.w!=DrawBuf.bufw) {
344
		DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
7758 leency 345
		if (!strncmp(history.current(),"http",4)) {
7759 leency 346
			//nihuya ne izyashnoe reshenie, no pust' poka butet tak
7771 leency 347
			source_mode_holder = source_mode;
7758 leency 348
			LoadInternalPage(#loading_text, sizeof(loading_text));
7771 leency 349
			source_mode = source_mode_holder;
7758 leency 350
		}
351
		OpenPage(history.current());
7771 leency 352
		return true;
7282 leency 353
	}
7771 leency 354
	return false;
3067 leency 355
}
356
 
7771 leency 357
 
7759 leency 358
void EventChangeEncodingAndLoadPage(int _new_encoding)
359
{
360
	dword newbuf, newsize;
361
	WB1.custom_encoding = _new_encoding;
362
	newsize = strlen(WB1.o_bufpointer);
363
	newbuf = malloc(newsize);
364
	memmov(newbuf, WB1.o_bufpointer, newsize);
365
	LoadInternalPage(newbuf, newsize);
366
	free(newbuf);
367
}
3067 leency 368
 
7759 leency 369
 
6698 leency 370
void ProcessEvent(dword id__)
4413 leency 371
{
6698 leency 372
	switch (id__)
4413 leency 373
	{
8305 leency 374
		case 1: ExitProcess();
375
		case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: EventTabClose(id__ - TAB_CLOSE_ID); return;
376
		case TAB_ID...TAB_ID+TABS_MAX: EventAllTabsClick(id__ - TAB_ID); return;
377
		case ENCODINGS...ENCODINGS+6: EventChangeEncodingAndLoadPage(id__-ENCODINGS); return;
378
		case NEW_WINDOW:       RunProgram(#program_path, NULL); return;
379
		case NEW_TAB:          if (!http.transfer) EventOpenNewTab(URL_SERVICE_HOMEPAGE); return;
5711 leency 380
		case SCAN_CODE_BS:
8305 leency 381
		case BACK_BUTTON:      if (history.back()) OpenPage(history.current()); return;
382
		case FORWARD_BUTTON:   if (history.forward()) OpenPage(history.current()); return;
5718 leency 383
		case GOTOURL_BUTTON:
8305 leency 384
		case SCAN_CODE_ENTER:  EventSubmitOmnibox();	return;
385
		case REFRESH_BUTTON:   EventRefreshPage(); return;
386
		case CHANGE_ENCODING:  EventShowEncodingsList(); return;
387
		case SANDWICH_BUTTON:  EventShowMainMenu(); return;
388
		case VIEW_SOURCE:      EventViewSource(); return;
389
		case EDIT_SOURCE:      EventEditSource(); return;
390
		case VIEW_HISTORY:     OpenPage(URL_SERVICE_HISTORY); return;
391
		case DOWNLOAD_MANAGER: EventOpenDownloader(""); return;
392
		case UPDATE_BROWSER:   EventUpdateBrowser(); return;
393
		case CLEAR_CACHE:      EventClearCache(); return;
394
		case IN_NEW_TAB:       EventClickLink(TARGET_NEW_TAB); return;
395
		case IN_NEW_WINDOW:    EventClickLink(TARGET_NEW_WINDOW); return;
396
		case COPY_LINK_URL:    EventCopyLinkToClipboard(); return;
397
		case DOWNLOAD_LINK_CT: EventOpenDownloader( GetAbsoluteActiveURL() ); return;
398
		case OPEN_FILE:        EventOpenDialog(); return;
399
		case SCAN_CODE_F12:    EventToggleDebugMode(); return;
4413 leency 400
	}
401
}
402
 
8305 leency 403
void EventToggleDebugMode()
404
{
405
	debug_mode ^= 1;
406
	if (debug_mode) notify("'Debug mode ON'-I");
407
	else notify("'Debug mode OFF'-I");
408
}
409
 
410
void EventAllTabsClick(dword _n)
411
{
412
	if (http.transfer) return;
413
	if (mouse.mkm) {
414
		EventTabClose(_n);
415
	} else {
416
		EventTabClick(_n);
417
	}
418
}
419
 
420
void EventEditSource()
421
{
422
	if (check_is_the_adress_local(history.current())) {
423
		RunProgram("/rd/1/tinypad", history.current());
424
	} else {
425
		CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
426
		if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
427
	}
428
}
429
 
430
void EventClearCache()
431
{
432
	cache.clear();
433
	notify(#clear_cache_ok);
434
	EventRefreshPage();
435
}
436
 
437
void EventCopyLinkToClipboard()
438
{
439
	Clipboard__CopyText(GetAbsoluteActiveURL());
440
	notify("'URL copied to clipboard'O");
441
}
442
 
4636 leency 443
void StopLoading()
444
{
8305 leency 445
	if (http.stop()) pause(10);
5519 leency 446
	wv_progress_bar.value = 0;
7743 leency 447
	DrawOmnibox();
4645 leency 448
}
449
 
7756 leency 450
//rewrite into
7757 leency 451
//bool strrpl(dword dst, from, into, dst_len);
452
bool ReplaceSpaceInUrl(dword url, size) {
7756 leency 453
	unsigned int i, j;
7757 leency 454
	bool was_changed=false;
455
	for (i=url+size-3; i>url; i--)
7720 leency 456
	{
7756 leency 457
		if (ESBYTE[i]!=' ') continue;
7757 leency 458
		for (j=url+size-3; j>=i; j--) {
459
			ESBYTE[j+3]=ESBYTE[j+2];
7756 leency 460
			ESBYTE[j+2]=ESBYTE[j+1];
461
			ESBYTE[j+1]=ESBYTE[j];
462
		}
463
		ESBYTE[i] = '%';
464
		ESBYTE[i+1] = '2';
465
		ESBYTE[i+2] = '0';
7757 leency 466
		was_changed = true;
7720 leency 467
	}
7757 leency 468
	return was_changed;
7720 leency 469
}
470
 
7801 leency 471
bool HandleUrlFiles(dword _path, _data)
472
{
473
	dword url_from_file;
474
	if (!UrlExtIs(_path, "url")) return false;
7945 leency 475
	if (! url_from_file = strstri(_data, "URL=")) return false;
7801 leency 476
	replace_char(url_from_file, '\n', '\0', strlen(url_from_file));
7945 leency 477
	OpenPage(url_from_file);
478
	return true;
7801 leency 479
}
480
 
7755 leency 481
bool GetLocalFileData(dword _path)
4416 leency 482
{
7801 leency 483
	dword data, size;
7755 leency 484
	file_size stdcall (_path);
7801 leency 485
	if (!EBX) return false;
486
 
487
	size = EBX;
488
	data = malloc(size);
489
	ReadFile(0, size, data, _path);
490
	if (!HandleUrlFiles(_path, data)) {
491
		LoadInternalPage(data, size);
4692 leency 492
	}
7801 leency 493
	free(data);
494
	return true;
7755 leency 495
}
7282 leency 496
 
7755 leency 497
void OpenPage(dword _open_URL)
498
{
499
	char new_url[URL_SIZE+1];
7970 leency 500
	char new_url_full[URL_SIZE+1];
7788 leency 501
	int unz_id;
7755 leency 502
 
503
	StopLoading();
504
 
7771 leency 505
	SetOmniboxText(_open_URL);
506
 
7755 leency 507
	strncpy(#new_url, _open_URL, URL_SIZE);
508
 
509
	//Exclude # from the URL to the load page
510
	//We will bring it back when we get the buffer
7970 leency 511
	if (strrchr(#new_url, '#')) {
512
		anchors.take_anchor_from(#new_url);
513
	}
7755 leency 514
 
515
	history.add(#new_url);
516
 
7976 leency 517
	/*
518
	There could be several possible types of addresses:
519
	- cached page (only http/https)
520
	- internal page
521
	- web page
522
	- local file
523
	So we need to detect what incoming address is
524
	and then halndle it in the propper way.
525
	*/
526
 
8016 leency 527
	if (cache.has(#new_url)) {
7764 leency 528
		//CACHED PAGE
8016 leency 529
		LoadInternalPage(cache.current_buf, cache.current_size);
7764 leency 530
 
531
	} else if (!strncmp(#new_url,"WebView:",8)) {
7755 leency 532
		//INTERNAL PAGE
8278 leency 533
		if (streq(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#buildin_page_home, sizeof(buildin_page_home));
534
		else if (streq(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#buildin_page_help, sizeof(buildin_page_help));
7976 leency 535
		else if (streq(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
8278 leency 536
		else LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error));
7800 leency 537
 
7755 leency 538
	} else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
539
		//WEB PAGE
7757 leency 540
		if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
541
			strcpy(#editURL, #new_url);
542
		}
543
 
8016 leency 544
		http_get_type = PAGE;
7755 leency 545
		if (!strncmp(#new_url,"http:",5)) {
546
			http.get(#new_url);
547
		} else if (!strncmp(#new_url,"https://",8)) {
7970 leency 548
			strcpy(#new_url_full, "http://gate.aspero.pro/?site=");
549
			strncat(#new_url_full, #new_url, URL_SIZE);
550
			http.get(#new_url_full);
7282 leency 551
		}
7758 leency 552
 
553
		DrawOmnibox();
554
 
7755 leency 555
		if (!http.transfer) {
4646 leency 556
			StopLoading();
8278 leency 557
			LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error));
4646 leency 558
		}
7755 leency 559
	} else {
560
		//LOCAL PAGE
7788 leency 561
		if (UrlExtIs(#new_url,".docx")) {
562
			DeleteFile("/tmp0/1/temp/word/document.xml");
563
			CreateDir("/tmp0/1/temp");
564
			unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url));
565
			while (GetProcessSlot(unz_id)) pause(2);
566
			strcpy(#new_url, "/tmp0/1/temp/word/document.xml");
567
		}
7755 leency 568
		if (!GetLocalFileData(#new_url)) {
8278 leency 569
			LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error));
4650 leency 570
		}
4636 leency 571
	}
4416 leency 572
}
4415 leency 573
 
8278 leency 574
dword EventOpenDownloader(dword _url)
575
{
576
	//char download_params[URL_SIZE+50];
577
	return RunProgram("/sys/network/dl", _url);
578
}
7970 leency 579
 
580
bool EventClickAnchor()
4508 leency 581
{
7970 leency 582
	dword aURL = links.active_url;
583
 
584
	if (anchors.get_pos_by_name(aURL+1)!=-1) {
585
		WB1.list.first = anchors.get_pos_by_name(aURL+1);
586
		//WB1.list.CheckDoesValuesOkey();
587
		strcpy(#editURL, history.current());
588
		strcat(#editURL, aURL);
589
		DrawOmnibox();
590
		WB1.DrawPage();
591
		return true;
592
	}
593
	return false;
594
}
595
 
596
void EventClickLink(dword _target)
597
{
7756 leency 598
	char new_url[URL_SIZE+1];
7936 leency 599
	char new_url_full[URL_SIZE+1];
7970 leency 600
	dword aURL = GetAbsoluteActiveURL();
601
	if (!aURL) return;
4415 leency 602
 
7970 leency 603
	strcpy(#new_url, aURL);
604
 
605
	if (ESBYTE[aURL]=='#') {
606
		if (_target == TARGET_SAME_TAB) {
607
			EventClickAnchor();
608
			return;
609
		} else {
610
			strcpy(#new_url, history.current());
611
			strcat(#new_url, aURL);
612
		}
613
	}
614
 
615
	if (_target == TARGET_NEW_TAB) {
616
		EventOpenNewTab(#new_url);
7758 leency 617
		return;
618
	}
619
 
7970 leency 620
	if (_target == TARGET_NEW_WINDOW) {
621
		strcpy(#new_url_full, "-new ");
622
		strncat(#new_url_full, #new_url, URL_SIZE);
623
		RunProgram(#program_path, #new_url_full);
7755 leency 624
		return;
5768 leency 625
	}
7742 leency 626
 
7970 leency 627
	if (!strncmp(#new_url,"mailto:", 7)) || (!strncmp(#new_url,"tel:", 4)) {
628
		notify(#new_url);
7755 leency 629
		return;
7742 leency 630
	}
4508 leency 631
 
7771 leency 632
	if (http.transfer) {
5774 leency 633
		StopLoading();
6021 leency 634
		history.back();
5774 leency 635
	}
6730 leency 636
 
7755 leency 637
	if (strrchr(#new_url, '#')!=0) {
638
		anchors.take_anchor_from(#new_url);
639
		OpenPage(#new_url);
6730 leency 640
		return;
641
	}
642
 
7755 leency 643
	if (!strncmp(#new_url,"WebView:",8)) {
644
		OpenPage(#new_url);
7742 leency 645
		return;
646
	}
6730 leency 647
 
7755 leency 648
	if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
5774 leency 649
	{
7755 leency 650
		if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
6730 leency 651
		{
7755 leency 652
			if (strchr(#new_url, '|')) {
653
				ESBYTE[strchr(#new_url, '|')] = NULL;
654
				RunProgram(#new_url, strlen(#new_url)+1+#new_url);
655
			} else {
656
				RunProgram("/sys/@open", #new_url);
7422 leency 657
			}
6730 leency 658
			return;
659
		}
5774 leency 660
	}
7755 leency 661
	OpenPage(#new_url);
662
}
663
 
664
void EventSubmitOmnibox()
665
{
666
	char new_url[URL_SIZE+1];
667
	if (!editURL[0]) return;
668
	if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
669
	|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
670
		OpenPage(#editURL);
671
	} else {
672
		strcpy(#new_url, "http://");
7970 leency 673
		strncat(#new_url, #editURL, URL_SIZE-1);
7755 leency 674
		OpenPage(#new_url);
6931 leency 675
	}
5774 leency 676
}
677
 
7755 leency 678
void LoadInternalPage(dword _bufdata, _in_bufsize){
679
	if (!_bufdata) || (!_in_bufsize) {
8278 leency 680
		LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error));
7755 leency 681
	} else {
682
		WB1.list.first = 0; //scroll page to the top
683
		DrawOmnibox();
684
		if(!strrchr(#editURL, '#')) {
685
			strcat(#editURL, #anchors.current);
686
			DrawOmnibox();
687
		}
7759 leency 688
		WB1.ParseHtml(_bufdata, _in_bufsize);
8302 leency 689
		// REJECTED. Reason: infinite redirect at Google Results.
690
		/*
691
		if (WB1.redirect) { //
692
			get_absolute_url(#WB1.redirect, history.current());
693
			history.back();
694
			OpenPage(#WB1.redirect);
695
		}
696
		*/
7970 leency 697
		DrawStatusBar();
7771 leency 698
		DrawActiveTab();
7756 leency 699
		if (source_mode) {
700
			source_mode = false;
7799 leency 701
			WB1.custom_encoding = CH_CP866;
7759 leency 702
			ShowSource(WB1.bufpointer, _in_bufsize);
7757 leency 703
		} else {
8016 leency 704
			WB1.DrawPage();
7756 leency 705
		}
8016 leency 706
		//GetImg();
7742 leency 707
	}
708
}
709
 
7799 leency 710
bool UrlExtIs(dword base, ext)
7742 leency 711
{
7755 leency 712
	if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true;
7742 leency 713
	return false;
714
}
715
 
716
void DrawProgress()
717
{
718
	dword persent;
719
	if (http.transfer == 0) return;
7755 leency 720
	if (wv_progress_bar.max) {
721
		persent = wv_progress_bar.value*100/wv_progress_bar.max;
722
	} else {
723
		persent = 10;
724
	}
7758 leency 725
	DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
7742 leency 726
}
727
 
7770 leency 728
void EventShowPageMenu()
6782 leency 729
{
8020 leency 730
	open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu);
7780 leency 731
	menu_id = VIEW_SOURCE;
6782 leency 732
}
733
 
7770 leency 734
void EventShowLinkMenu()
7759 leency 735
{
8020 leency 736
	open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #link_menu);
7789 simsanutiy 737
	menu_id = IN_NEW_TAB;
7759 leency 738
}
739
 
7780 leency 740
void EventShowMainMenu()
741
{
8020 leency 742
	open_lmenu(Form.cwidth - PADDING -4, PADDING + TSZE + 3,
743
		MENU_TOP_RIGHT, NULL, #main_menu);
7780 leency 744
	menu_id = OPEN_FILE;
745
}
746
 
7770 leency 747
void EventShowEncodingsList()
7758 leency 748
{
8020 leency 749
	open_lmenu(Form.cwidth-4, Form.cheight - STATUSBAR_H + 12,
750
		MENU_BOT_RIGHT, WB1.cur_encoding + 1,
751
		"UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866");
7780 leency 752
	menu_id = ENCODINGS;
7758 leency 753
}
754
 
7780 leency 755
void ProcessMenuClick()
6795 leency 756
{
7780 leency 757
	int click_id;
7910 leency 758
	if (menu_id) {
759
		if (click_id = get_menu_click()) {
760
			click_id += menu_id - 1;
761
			ProcessEvent(click_id);
762
		}
763
		if (!menu_process_id) menu_id = NULL;
7780 leency 764
	}
6795 leency 765
}
766
 
7281 leency 767
void EventUpdateProgressBar()
768
{
769
	wv_progress_bar.max = http.content_length;
770
	if (wv_progress_bar.value != http.content_received)
771
	{
772
		wv_progress_bar.value = http.content_received;
773
		DrawProgress();
774
	}
775
}
6795 leency 776
 
7743 leency 777
void EventSeachWeb()
778
{
7755 leency 779
	char new_url[URL_SIZE+1];
780
	replace_char(#editURL, ' ', '_', URL_SIZE);
781
	strcpy(#new_url, "https://www.google.com/search?q=");
782
	strncat(#new_url, #editURL, URL_SIZE);
783
	OpenPage(#new_url);
7743 leency 784
}
785
 
7748 leency 786
void EventOpenDialog()
787
{
788
	OpenDialog_start stdcall (#o_dialog);
789
	if (o_dialog.status) {
7755 leency 790
		OpenPage(#openfile_path);
7748 leency 791
	}
792
}
793
 
7750 leency 794
void EventViewSource()
795
{
7771 leency 796
	source_mode = true;
797
	EventOpenNewTab(history.current());
7750 leency 798
}
799
 
7893 leency 800
void EventRefreshPage()
801
{
802
	if (http.transfer) {
803
		StopLoading();
804
		draw_window();
805
	} else {
806
		OpenPage(history.current());
807
	}
808
}
809
 
7765 leency 810
dword GetFileSize(dword _path)
811
{
812
	BDVK bdvk;
813
	if (GetFileInfo(_path, #bdvk)!=0) {
814
		return 0;
815
	} else {
816
		return bdvk.sizelo;
817
	}
818
}
819
 
820
void EventUpdateBrowser()
821
{
822
	dword downloader_id, slot_n;
823
	dword current_size;
824
	dword new_size;
825
	int error;
826
 
827
	draw_window();
828
 
8278 leency 829
	downloader_id = EventOpenDownloader(#update_param);
7765 leency 830
	do {
831
		slot_n = GetProcessSlot(downloader_id);
832
		pause(10);
833
	} while (slot_n!=0);
834
 
835
	current_size = GetFileSize(#program_path);
836
	new_size = GetFileSize("/tmp0/1/Downloads/WebView.com");
837
 
838
	if (!new_size) || (new_size<5000) {
839
		notify(#update_download_error);
840
		return;
841
	}
842
 
843
	if (current_size == new_size) {
844
		notify(#update_is_current);
845
		return;
846
	}
847
 
848
	if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) {
849
		notify(#update_can_not_copy);
850
	} else {
851
		notify(#update_ok);
852
		RunProgram(#program_path, history.current());
853
		ExitProcess();
854
	}
855
}
856
 
7970 leency 857
void DrawStatusBar()
6795 leency 858
{
7970 leency 859
	dword status_y = Form.cheight - STATUSBAR_H + 4;
860
	dword status_w = Form.cwidth - 90;
7806 leency 861
	DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
7970 leency 862
	if (links.active_url) {
863
		ESI = math.min(status_w/6, strlen(links.active_url));
864
		WriteText(10, status_y, 0, sc.work_text, links.active_url);
7758 leency 865
	}
8016 leency 866
	if (http.transfer>0) && (http_get_type==IMG) {
867
		//
868
	}
7970 leency 869
	DefineHiddenButton(status_w+20, status_y-3, 60, 12, CHANGE_ENCODING);
870
	WriteTextCenter(status_w+20, status_y, 60, sc.work_text, WB1.cur_encoding*10+#charsets);
7758 leency 871
}
872
 
873
void DrawOmnibox()
874
{
7784 leency 875
	int imgxoff;
7758 leency 876
 
7806 leency 877
	DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, sc.work_graph,
878
		sc.work_graph, sc.work_graph, sc.work_dark);
7758 leency 879
	DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);
880
	DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color);
881
	DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color);
882
 
883
	if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
884
	EditBox_UpdateText(#address_box, address_box.flags);
885
	edit_box_draw stdcall(#address_box);
7784 leency 886
	if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0;
887
	_PutImage(address_box.left+address_box.width+1, address_box.top-1, 16, 23, imgxoff + #editbox_icons);
888
	DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, 23, REFRESH_BUTTON);
7758 leency 889
 
890
	DrawProgress();
891
}
892
 
7771 leency 893
void SetOmniboxText(dword _text)
894
{
895
	strcpy(#editURL, _text);
896
	address_box.flags=0;
897
	DrawOmnibox();
898
}
7758 leency 899
 
7970 leency 900
dword GetAbsoluteActiveURL()
901
{
902
	char abs_url[URL_SIZE];
903
	if (links.active_url) {
904
		strncpy(#abs_url, links.active_url, URL_SIZE);
8291 leency 905
		get_absolute_url(#abs_url, history.current());
7970 leency 906
		return #abs_url;
907
	}
908
	return 0;
909
}
7771 leency 910
 
8305 leency 911
void CheckContentType()
912
{
913
	char content_type[64];
914
	if (http.header_field("content-type\0", #content_type, sizeof(content_type))) // application || image
915
	if (content_type[0] == 'a') || (content_type[0] == 'i') {
916
		EventOpenDownloader(history.current());
917
		StopLoading();
918
		history.back();
919
		EventRefreshPage();
920
	}
921
}
922
 
923
void HandleRedirect()
924
{
925
	char redirect_url[URL_SIZE];
926
	http.header_field("location\0", #redirect_url, URL_SIZE);
927
	get_absolute_url(#redirect_url, history.current());
928
	history.back();
929
	http.hfree();
930
	if (http_get_type==PAGE) OpenPage(#redirect_url);
931
	else if (http_get_type==IMG) http.get(#redirect_url);
932
}
933
 
8016 leency 934
dword GetImg()
935
{
936
	while (WB1.page_img.next_url()) {
937
		if (cache.has(WB1.page_img.current_url())) continue;
938
		http_get_type = IMG;
939
		http.get(WB1.page_img.current_url());
940
		return;
941
	}
942
	DrawOmnibox();
943
	WB1.DrawPage();
944
}
945
 
5631 pavelyakov 946
stop: