Subversion Repositories Kolibri OS

Rev

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