Subversion Repositories Kolibri OS

Rev

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