Subversion Repositories Kolibri OS

Rev

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