Subversion Repositories Kolibri OS

Rev

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