Subversion Repositories Kolibri OS

Rev

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