Subversion Repositories Kolibri OS

Rev

Rev 7281 | Rev 7283 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7281 Rev 7282
Line 30... Line 30...
30
_http http = {0, 0, 0, 0, 0, 0, 0};
30
_http http = {0, 0, 0, 0, 0, 0, 0};
Line 31... Line 31...
31
 
31
 
Line 32... Line 32...
32
char homepage[] = FROM "html\\homepage.htm""\0";
32
char homepage[] = FROM "html\\homepage.htm""\0";
33
 
33
 
34
#ifdef LANG_RUS
34
#ifdef LANG_RUS
35
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.74";
35
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.8";
36
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
36
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
37
?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
37
?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
38
char loading[] = "‡ £à㧪  áâà ­¨æë...
";
38
char loading[] = "‡ £à㧪  áâà ­¨æë...
";
Line 45... Line 45...
45
Œ¥­¥¤¦¥à § £à㧮ª";
45
Œ¥­¥¤¦¥à § £à㧮ª";
46
char link_menu[] =
46
char link_menu[] =
47
"Š®¯¨à®¢ âì áá뫪ã
47
"Š®¯¨à®¢ âì áá뫪ã
48
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
48
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
49
#else
49
#else
50
char version[]="Text-based Browser 1.74";
50
char version[]="Text-based Browser 1.8";
51
?define IMAGES_CACHE_CLEARED "Images cache cleared"
51
?define IMAGES_CACHE_CLEARED "Images cache cleared"
52
?define T_LAST_SLIDE "This slide is the last"
52
?define T_LAST_SLIDE "This slide is the last"
53
char loading[] = "Loading...
";
53
char loading[] = "Loading...
";
54
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
54
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
55
char accept_language[]= "Accept-Language: en\n";
55
char accept_language[]= "Accept-Language: en\n";
Line 81... Line 81...
81
dword STATUSBAR_H = 15;
81
dword STATUSBAR_H = 15;
82
dword col_bg;
82
dword col_bg;
83
dword panel_color;
83
dword panel_color;
84
dword border_color;
84
dword border_color;
Line -... Line 85...
-
 
85
 
-
 
86
bool debug_mode = false;
-
 
87
bool old_tag_parser_mode = false;
85
 
88
 
86
progress_bar wv_progress_bar;
89
progress_bar wv_progress_bar;
87
bool souce_mode = false;
90
bool souce_mode = false;
Line 88... Line 91...
88
bool open_in_a_new_window = false;
91
bool open_in_a_new_window = false;
Line 96... Line 99...
96
	VIEW_SOURCE=1100,
99
	VIEW_SOURCE=1100,
97
	EDIT_SOURCE,
100
	EDIT_SOURCE,
98
	VIEW_HISTORY,
101
	VIEW_HISTORY,
99
	//FREE_IMG_CACHE,
102
	//FREE_IMG_CACHE,
100
	DOWNLOAD_MANAGER,
103
	DOWNLOAD_MANAGER,
101
	COPY_LINK=1200,
104
	COPY_LINK_URL=1200,
102
	DOWNLOAD_LINK_CONTENTS,
105
	DOWNLOAD_LINK_CONTENTS,
103
};
106
};
Line 104... Line 107...
104
 
107
 
105
#include "..\TWB\TWB.c"
108
#include "..\TWB\TWB.c"
Line 112... Line 115...
112
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19};
115
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19};
Line 113... Line 116...
113
 
116
 
114
 
117
 
115
void main()
-
 
116
{
118
void main()
117
	CursorPointer.Load(#CursorFile);
119
{
118
	load_dll(boxlib, #box_lib_init,0);
120
	load_dll(boxlib, #box_lib_init,0);
119
	load_dll(libio, #libio_init,1);
121
	load_dll(libio, #libio_init,1);
120
	load_dll(libimg, #libimg_init,1);
122
	load_dll(libimg, #libimg_init,1);
Line 130... Line 132...
130
	loop() switch(WaitEvent())
132
	loop() switch(WaitEvent())
131
	{
133
	{
132
		case evMouse:
134
		case evMouse:
133
			edit_box_mouse stdcall (#address_box);
135
			edit_box_mouse stdcall (#address_box);
134
			mouse.get();
136
			mouse.get();
135
			if (WB1.list.MouseOver(mouse.x, mouse.y))
-
 
136
			{
-
 
137
				if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
137
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
138
				&& (bufsize) && (mouse.pkm) && (mouse.up) {
138
			&& (bufsize) && (mouse.pkm) && (mouse.up) {
139
					EventShowPageMenu(mouse.x, mouse.y);
139
				if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
140
					break;
140
				break;
141
				}
141
			}
142
				if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
142
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
143
			}
-
 
144
			scrollbar_v_mouse (#scroll_wv);
143
			scrollbar_v_mouse (#scroll_wv);
145
			if (WB1.list.first != scroll_wv.position)
144
			if (WB1.list.first != scroll_wv.position)
146
			{
145
			{
147
				WB1.list.first = scroll_wv.position;
146
				WB1.list.first = scroll_wv.position;
148
				WB1.DrawPage();
147
				WB1.DrawPage();
Line 190... Line 189...
190
				if (http.receive_result == 0) {
189
				if (http.receive_result == 0) {
191
					// Handle redirects
190
					// Handle redirects
192
					if (http.status_code >= 300) && (http.status_code < 400)
191
					if (http.status_code >= 300) && (http.status_code < 400)
193
					{
192
					{
194
						redirected++;
193
						redirected++;
195
						if (redirected<=5)
194
						if (redirected>5)
196
						{
-
 
197
							if (http.handle_redirect()) {
-
 
198
								if (!strncmp(#URL,"https://",8))
-
 
199
								{
195
						{
200
									history.back();
-
 
201
									strcpy(#editURL, history.current());
-
 
202
									strcpy(#URL, history.current());
196
							notify("'Too many redirects.' -E");
203
									ShowErrorMessageThatHttpsIsNotSupportedYet();
-
 
204
									StopLoading();
197
							StopLoading();
205
									break;	
-
 
206
								}
-
 
207
							}
-
 
208
						}
198
						}
209
						else
199
						else
210
						{
200
						{
211
							notify("Too many redirects");
201
							http.handle_redirect();
212
							StopLoading();
-
 
213
							break;
-
 
214
						}
-
 
215
					} 
-
 
216
					else
-
 
217
					{
-
 
218
						redirected = 0;
-
 
219
					}
-
 
220
					// Loading the page is complete, free resources
-
 
221
					if (redirected>0)
-
 
222
					{
-
 
223
						http.free();
202
							http.free();
224
						GetAbsoluteURL(#URL);
203
							GetAbsoluteURL(#http.redirect_url);
225
						history.back();
204
							history.back();
226
						strcpy(#editURL, #URL);
205
							strcpy(#editURL, #URL);
227
						DrawEditBoxWebView();
206
							DrawEditBoxWebView();
228
						OpenPage();
207
							OpenPage();
229
					}
208
						}
230
					else
209
						break;
231
					{
210
					} 
-
 
211
					redirected = 0;
-
 
212
					// Loading the page is complete, free resources
232
						history.add(#URL);
213
					history.add(#URL);
233
						ESI = http.transfer;
-
 
234
						bufpointer = ESI.http_msg.content_ptr;
214
					bufpointer = http.content_pointer;
235
						bufsize = ESI.http_msg.content_received;
215
					bufsize = http.content_received;
236
						http.free();
216
					http.free();
237
						SetPageDefaults();
217
					SetPageDefaults();
238
						ShowPage();
218
					ShowPage();
239
					}
219
				}
240
				}
220
			}
241
			}
221
	}
242
	}
222
}
243
}
-
 
Line 244... Line 223...
244
 
223
 
245
void SetElementSizes()
224
void SetElementSizes()
246
{
225
{
247
	address_box.top = TOOLBAR_H/2-10;
226
	address_box.top = TOOLBAR_H/2-10;
Line 273... Line 252...
273
	DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0);
252
	DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0);
274
	DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0);
253
	DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0);
275
	img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 87, 0);
254
	img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 87, 0);
276
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
255
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
277
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
256
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
-
 
257
	if (!header) 
-
 
258
		OpenPage(); 
-
 
259
	else { 
-
 
260
		WB1.DrawPage(); 
278
	if (!header) OpenPage(); else { WB1.DrawPage(); DrawEditBoxWebView(); }
261
		DrawEditBoxWebView(); 
-
 
262
	}
279
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
263
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
280
	DrawProgress();
264
	DrawProgress();
281
}
265
}
Line 301... Line 285...
301
				OpenPage();
285
				OpenPage();
302
			}
286
			}
303
			return;
287
			return;
304
		case GOTOURL_BUTTON:
288
		case GOTOURL_BUTTON:
305
		case SCAN_CODE_ENTER:
289
		case SCAN_CODE_ENTER:
-
 
290
			if (!editURL[0]) {
-
 
291
				strcpy(#URL, URL_SERVICE_HOME);
-
 
292
			}
306
			if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') 
293
			else if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') 
307
			|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
294
			|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
308
			{
295
			{
309
				strcpy(#URL, #editURL);
296
				strcpy(#URL, #editURL);
310
			}
297
			}
311
			else
298
			else
Line 332... Line 319...
332
			WB1.list.first = 0;
319
			WB1.list.first = 0;
333
			ShowSource();
320
			ShowSource();
334
			WB1.LoadInternalPage(bufpointer, bufsize);
321
			WB1.LoadInternalPage(bufpointer, bufsize);
335
			break;
322
			break;
336
		case EDIT_SOURCE:
323
		case EDIT_SOURCE:
337
			if (!strncmp(#URL,"http:",5)) 
324
			if (!strncmp(#URL,"http",4)) 
338
			{
325
			{
339
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
326
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
340
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
327
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
341
			}
328
			}
342
			else RunProgram("/rd/1/tinypad", #URL);
329
			else RunProgram("/rd/1/tinypad", #URL);
Line 354... Line 341...
354
			if (!downloader_opened) {
341
			if (!downloader_opened) {
355
				downloader_edit = NULL;
342
				downloader_edit = NULL;
356
				CreateThread(#Downloader,#downloader_stak+4092);
343
				CreateThread(#Downloader,#downloader_stak+4092);
357
			}
344
			}
358
			return;
345
			return;
359
		case COPY_LINK:
346
		case COPY_LINK_URL:
360
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
347
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
361
			notify("'URL copied to clipboard'O");
348
			notify("'URL copied to clipboard'O");
362
			return;
349
			return;
363
		case DOWNLOAD_LINK_CONTENTS:
350
		case DOWNLOAD_LINK_CONTENTS:
364
			if (!downloader_opened) {
351
			if (!downloader_opened) {
365
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
352
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
366
				CreateThread(#Downloader,#downloader_stak+4092);
353
				CreateThread(#Downloader,#downloader_stak+4092);
367
			}
354
			}
368
			return;
355
			return;
-
 
356
		case SCAN_CODE_F12:
-
 
357
			debug_mode ^= 1;
-
 
358
			if (debug_mode) notify("'Debug mode ON'-I");
-
 
359
			else notify("'Debug mode OFF'-I");
-
 
360
			return;
-
 
361
		case SCAN_CODE_F11:
-
 
362
			old_tag_parser_mode ^= 1;
-
 
363
			if (old_tag_parser_mode) notify("'Old tag parser ON'-I");
-
 
364
			else notify("'Old tag parser OFF'-I");
-
 
365
			return;
369
	}
366
	}
370
}
367
}
Line 371... Line 368...
371
 
368
 
372
void StopLoading()
369
void StopLoading()
Line 395... Line 392...
395
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
392
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
396
}
393
}
Line 397... Line 394...
397
 
394
 
398
void OpenPage()
395
void OpenPage()
-
 
396
{
399
{
397
	char getUrl[sizeof(URL)];
400
	StopLoading();
398
	StopLoading();
401
	souce_mode = false;
399
	souce_mode = false;
402
	strcpy(#editURL, #URL);
400
	strcpy(#editURL, #URL);
403
	history.add(#URL);
401
	history.add(#URL);
Line 407... Line 405...
407
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
405
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
408
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
406
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
409
		DrawEditBoxWebView();
407
		DrawEditBoxWebView();
410
		return;
408
		return;
411
	}
409
	}
412
	if (!strncmp(#URL,"http:",5))
410
	if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8)) 
413
	{
411
	{
414
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0);
412
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0);
-
 
413
 
-
 
414
		if (!strncmp(#URL,"http:",5)) {
415
		http.get(#URL);
415
			http.get(#URL);
-
 
416
		}
-
 
417
		if (!strncmp(#URL,"https://",8)) {
-
 
418
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
-
 
419
			http.get(#getUrl);
-
 
420
		}
-
 
421
		//http.get(#URL);
416
		if (!http.transfer)
422
		if (!http.transfer)
417
		{
423
		{
418
			StopLoading();
424
			StopLoading();
419
			bufsize = 0;
425
			bufsize = 0;
420
			bufpointer = free(bufpointer);
426
			bufpointer = free(bufpointer);
Line 450... Line 456...
450
 
456
 
451
 
457
 
452
void ShowPage()
458
void ShowPage()
453
{
-
 
454
	DrawEditBoxWebView();
459
{
455
	debugval("bufsize", bufsize);
460
	DrawEditBoxWebView();
456
	if (!bufsize)
461
	if (!bufsize)
457
	{
462
	{
458
		if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
463
		if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
Line 484... Line 489...
484
	$and wv_progress_bar.progress_color, 0x00ffffff
489
	$and wv_progress_bar.progress_color, 0x00ffffff
485
}
490
}
Line 486... Line 491...
486
 
491
 
487
void DrawProgress()
492
void DrawProgress()
488
{
493
{
489
	unsigned long btn;
494
	dword persent;
490
	if (http.transfer == 0) return;
495
	if (http.transfer == 0) return;
491
	if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30;
496
	if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
492
	DrawBar(address_box.left-2, address_box.top+20, btn, 2, wv_progress_bar.progress_color);
497
	DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color);
Line 493... Line 498...
493
}
498
}
494
 
499
 
Line 499... Line 504...
499
	if (http.transfer > 0) 
504
	if (http.transfer > 0) 
500
	{
505
	{
501
		StopLoading();
506
		StopLoading();
502
		history.back();
507
		history.back();
503
	}
508
	}
504
 
-
 
505
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));	
509
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));
506
	//#1
510
	//#1
507
	if (URL[0] == '#')
511
	if (URL[0] == '#')
508
	{
512
	{
509
		if (URL[1] == NULL) {
513
		if (URL[1] == NULL) {
Line 530... Line 534...
530
		strcpy(#editURL, history.current());
534
		strcpy(#editURL, history.current());
531
		strcpy(#URL, history.current());
535
		strcpy(#URL, history.current());
532
		return;
536
		return;
533
	}
537
	}
Line 534... Line -...
534
 
-
 
535
	if (!strncmp(#URL,"https://",8))
-
 
536
	{
-
 
537
		ShowErrorMessageThatHttpsIsNotSupportedYet();
-
 
538
		strcpy(#editURL, history.current());
-
 
539
		strcpy(#URL, history.current());
-
 
540
		return;
-
 
541
	}
-
 
542
	
538
 
Line 543... Line 539...
543
	GetAbsoluteURL(#URL);
539
	GetAbsoluteURL(#URL);
544
 
540
 
545
	if (strncmp(#URL,"http://",7)!=0)
541
	if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
546
	{
542
	{
547
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
543
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
548
		{	
544
		{	
Line 585... Line 581...
585
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
581
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
586
}
582
}
Line 587... Line 583...
587
 
583
 
588
void EventShowLinkMenu(dword _left, _top)
584
void EventShowLinkMenu(dword _left, _top)
589
{
585
{
590
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK);
586
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
Line 591... Line 587...
591
}
587
}
592
 
588
 
593
void EventUpdateProgressBar()
589
void EventUpdateProgressBar()
Line 598... Line 594...
598
		wv_progress_bar.value = http.content_received;	
594
		wv_progress_bar.value = http.content_received;	
599
		DrawProgress();
595
		DrawProgress();
600
	}
596
	}
601
}
597
}
Line 602... Line -...
602
 
-
 
603
 
-
 
604
void ShowErrorMessageThatHttpsIsNotSupportedYet()
-
 
605
{
-
 
606
	notify("'HTTPS protocol is not supported yet' -E");
-
 
607
}
-
 
608
 
598
 
609
DrawStatusBar(dword _status_text)
599
DrawStatusBar(dword _status_text)
610
{
600
{
611
	status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;
601
	status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;
612
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
602
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;