Subversion Repositories Kolibri OS

Rev

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

Rev 8302 Rev 8305
Line 23... Line 23...
23
#include "..\lib\obj\iconv.h"
23
#include "..\lib\obj\iconv.h"
24
#include "..\lib\obj\proc_lib.h"
24
#include "..\lib\obj\proc_lib.h"
Line 25... Line 25...
25
 
25
 
26
//useful patterns
26
//useful patterns
27
#include "..\lib\patterns\history.h"
-
 
28
#include "..\lib\patterns\http_downloader.h"
27
#include "..\lib\patterns\history.h"
29
#include "..\lib\patterns\simple_open_dialog.h"
28
#include "..\lib\patterns\simple_open_dialog.h"
30
#include "..\lib\patterns\toolbar_button.h"
29
#include "..\lib\patterns\toolbar_button.h"
Line 31... Line 30...
31
#include "..\lib\patterns\restart_process.h"
30
#include "..\lib\patterns\restart_process.h"
Line 32... Line 31...
32
 
31
 
Line 33... Line 32...
33
char editbox_icons[] = FROM "res/editbox_icons.raw";
32
char editbox_icons[] = FROM "res/editbox_icons.raw";
34
 
33
 
35
char version[]="WebView 2.7a";
34
char version[]="WebView 2.7b";
Line 58... Line 57...
58
	CLEAR_CACHE,
57
	CLEAR_CACHE,
59
	UPDATE_BROWSER,
58
	UPDATE_BROWSER,
60
	IN_NEW_TAB,
59
	IN_NEW_TAB,
61
	IN_NEW_WINDOW,
60
	IN_NEW_WINDOW,
62
	COPY_LINK_URL,
61
	COPY_LINK_URL,
63
	DOWNLOAD_LINK_CONTENTS,
62
	DOWNLOAD_LINK_CT,
64
	TAB_ID,
63
	TAB_ID,
65
	TAB_CLOSE_ID = 900
64
	TAB_CLOSE_ID = 900
66
};
65
};
Line 67... Line 66...
67
 
66
 
Line 141... Line 140...
141
 
140
 
142
void main()
141
void main()
143
{
142
{
144
	int i, redirect_count=0;
143
	int i, redirect_count=0;
145
	LoadLibraries();
-
 
146
	//CreateDir("/tmp0/1/WebView_Cache");
144
	LoadLibraries();
147
	HandleParam();
145
	HandleParam();
148
	WB1.list.SetFont(8, 14, 10011000b);
146
	WB1.list.SetFont(8, 14, 10011000b);
149
	WB1.list.no_selection = true;
147
	WB1.list.no_selection = true;
150
	WB1.custom_encoding = -1;
148
	WB1.custom_encoding = -1;
Line 236... Line 234...
236
			
234
			
237
		case evNetwork:
235
		case evNetwork:
238
			if (http.transfer <= 0) break;
236
			if (http.transfer <= 0) break;
239
			http.receive();
237
			http.receive();
240
			EventUpdateProgressBar();
-
 
241
			if (http.check_content_type()) // application || image
-
 
242
			if (http.content_type[0] == 'a') || (http.content_type[0] == 'i') { 
-
 
243
				EventOpenDownloader(history.current());
-
 
244
				StopLoading();
-
 
245
				history.back();
238
			EventUpdateProgressBar();
246
				EventRefreshPage();
-
 
247
			}
239
			CheckContentType();
248
			if (http.receive_result != 0) break;
240
			if (http.receive_result != 0) break;
249
			if (http.status_code >= 300) && (http.status_code < 400)
241
			if (http.status_code >= 300) && (http.status_code < 400)
250
			{
242
			{
251
				// Handle redirects
243
				// Handle redirects
252
				if (redirect_count<=5) {
244
				if (redirect_count<=5) {
253
					redirect_count++;
245
					redirect_count++;
254
					http.handle_redirect();
-
 
255
					history.back();
-
 
256
					if (http_get_type==PAGE) OpenPage(#http.redirect_url);
-
 
257
					else if (http_get_type==IMG) http.get(#http.redirect_url);
246
					HandleRedirect();
258
				} else {
247
				} else {
259
					notify("'Too many redirects.' -E");
248
					notify("'Too many redirects.' -E");
260
					StopLoading();
249
					StopLoading();
261
					redirect_count = 0;
250
					redirect_count = 0;
Line 380... Line 369...
380
 
369
 
381
void ProcessEvent(dword id__)
370
void ProcessEvent(dword id__)
382
{
371
{
383
	switch (id__)
372
	switch (id__)
384
	{
-
 
385
		case 1:
373
	{
386
			ExitProcess();
-
 
-
 
374
		case 1: ExitProcess();
387
			break;
375
		case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: EventTabClose(id__ - TAB_CLOSE_ID); return;
388
		case ENCODINGS...ENCODINGS+6:
376
		case TAB_ID...TAB_ID+TABS_MAX: EventAllTabsClick(id__ - TAB_ID); return;
389
			EventChangeEncodingAndLoadPage(id__-ENCODINGS);
-
 
390
			return;
-
 
391
		case NEW_WINDOW:
377
		case ENCODINGS...ENCODINGS+6: EventChangeEncodingAndLoadPage(id__-ENCODINGS); return;
392
			RunProgram(#program_path, NULL);
378
		case NEW_WINDOW:       RunProgram(#program_path, NULL); return;
393
			return;
379
		case NEW_TAB:          if (!http.transfer) EventOpenNewTab(URL_SERVICE_HOMEPAGE); return;
-
 
380
		case SCAN_CODE_BS:
-
 
381
		case BACK_BUTTON:      if (history.back()) OpenPage(history.current()); return;
394
		case SCAN_CODE_BS:
382
		case FORWARD_BUTTON:   if (history.forward()) OpenPage(history.current()); return;
-
 
383
		case GOTOURL_BUTTON:
-
 
384
		case SCAN_CODE_ENTER:  EventSubmitOmnibox();	return;
-
 
385
		case REFRESH_BUTTON:   EventRefreshPage(); return;
-
 
386
		case CHANGE_ENCODING:  EventShowEncodingsList(); return;
-
 
387
		case SANDWICH_BUTTON:  EventShowMainMenu(); return;
-
 
388
		case VIEW_SOURCE:      EventViewSource(); return;
-
 
389
		case EDIT_SOURCE:      EventEditSource(); return;
-
 
390
		case VIEW_HISTORY:     OpenPage(URL_SERVICE_HISTORY); return;
-
 
391
		case DOWNLOAD_MANAGER: EventOpenDownloader(""); return;
395
		case BACK_BUTTON:
392
		case UPDATE_BROWSER:   EventUpdateBrowser(); return;
-
 
393
		case CLEAR_CACHE:      EventClearCache(); return;
-
 
394
		case IN_NEW_TAB:       EventClickLink(TARGET_NEW_TAB); return;
-
 
395
		case IN_NEW_WINDOW:    EventClickLink(TARGET_NEW_WINDOW); return;
-
 
396
		case COPY_LINK_URL:    EventCopyLinkToClipboard(); return;
396
			if (history.back()) {
397
		case DOWNLOAD_LINK_CT: EventOpenDownloader( GetAbsoluteActiveURL() ); return;
-
 
398
		case OPEN_FILE:        EventOpenDialog(); return;
397
				OpenPage(history.current());
399
		case SCAN_CODE_F12:    EventToggleDebugMode(); return;
398
			}
-
 
399
			return;
-
 
400
		case FORWARD_BUTTON:
-
 
401
			if (history.forward()) {
-
 
402
				OpenPage(history.current());
400
	}
403
			}
401
}
404
			return;
402
 
-
 
403
void EventToggleDebugMode()
405
		case GOTOURL_BUTTON:
404
{
406
		case SCAN_CODE_ENTER:
405
	debug_mode ^= 1;
407
			EventSubmitOmnibox();
-
 
408
			return;
406
	if (debug_mode) notify("'Debug mode ON'-I");
-
 
407
	else notify("'Debug mode OFF'-I");
-
 
408
}
409
		case REFRESH_BUTTON:
409
 
-
 
410
void EventAllTabsClick(dword _n)
410
			EventRefreshPage();
411
{
411
			return;
412
	if (http.transfer) return;
412
		case CHANGE_ENCODING:
413
	if (mouse.mkm) {
413
			EventShowEncodingsList();
414
		EventTabClose(_n);
414
			return;
-
 
415
		case SANDWICH_BUTTON:
415
	} else {
416
			EventShowMainMenu();
416
		EventTabClick(_n);
417
			return;
417
	}	
-
 
418
}
418
		case VIEW_SOURCE:
419
 
419
			EventViewSource();
420
void EventEditSource()
420
			break;
-
 
421
		case EDIT_SOURCE:
421
{
422
			if (check_is_the_adress_local(history.current())) {
422
	if (check_is_the_adress_local(history.current())) {
423
				RunProgram("/rd/1/tinypad", history.current());
423
		RunProgram("/rd/1/tinypad", history.current());
424
			} else {
424
	} else {
425
				CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
425
		CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
426
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
426
		if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
427
			}
-
 
428
			return;
-
 
429
		case VIEW_HISTORY:
-
 
430
			OpenPage(URL_SERVICE_HISTORY);
427
	}
431
			return;
-
 
432
		case DOWNLOAD_MANAGER:
-
 
433
			EventOpenDownloader("");
428
}
434
			return;
-
 
435
		case UPDATE_BROWSER:
429
 
436
			EventUpdateBrowser();
430
void EventClearCache()
437
			return;
-
 
438
		case CLEAR_CACHE:
431
{
439
			cache.clear();
432
	cache.clear();
440
			notify(#clear_cache_ok);
433
	notify(#clear_cache_ok);
441
			EventRefreshPage();
434
	EventRefreshPage();
442
			return;
-
 
443
		case IN_NEW_TAB:
-
 
444
			EventClickLink(TARGET_NEW_TAB);
435
}
445
			return;
-
 
446
		case IN_NEW_WINDOW:
436
 
447
			EventClickLink(TARGET_NEW_WINDOW);
437
void EventCopyLinkToClipboard()
448
			return;
-
 
449
		case COPY_LINK_URL:
438
{
450
			Clipboard__CopyText(GetAbsoluteActiveURL()); 
439
	Clipboard__CopyText(GetAbsoluteActiveURL()); 
451
			notify("'URL copied to clipboard'O");
-
 
452
			return;
-
 
453
		case DOWNLOAD_LINK_CONTENTS:
-
 
454
			EventOpenDownloader( GetAbsoluteActiveURL() );
-
 
455
			return;
-
 
456
		case OPEN_FILE:
-
 
457
			EventOpenDialog();
-
 
458
			return;
-
 
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;
-
 
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;
-
 
479
	}
440
	notify("'URL copied to clipboard'O");
Line 480... Line 441...
480
}
441
}
481
 
442
 
482
void StopLoading()
443
void StopLoading()
483
{
-
 
484
	if (http.transfer)
-
 
485
	{
-
 
486
		EAX = http.transfer;
-
 
487
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
-
 
488
		$push	EAX							// save it on the stack
-
 
489
		http_free stdcall (http.transfer);	// abort connection
-
 
490
		$pop	EAX							
-
 
491
		free(EAX);						// free data
-
 
492
		http.transfer=0;
-
 
493
		pause(10);
444
{
494
	}
445
	if (http.stop()) pause(10);
495
	wv_progress_bar.value = 0;
446
	wv_progress_bar.value = 0;
Line 496... Line 447...
496
	DrawOmnibox();
447
	DrawOmnibox();
Line 840... Line 791...
840
	}
791
	}
841
}
792
}
Line 842... Line 793...
842
 
793
 
843
void EventViewSource()
794
void EventViewSource()
844
{
-
 
845
	char source_view_param[URL_SIZE+1];
-
 
846
	//strcpy(#source_view_param, "-source ");
-
 
847
	//strncat(#source_view_param, history.current(), URL_SIZE);
-
 
848
	//RunProgram(#program_path, #source_view_param);
795
{
849
	source_mode = true;
796
	source_mode = true;
850
	EventOpenNewTab(history.current());
797
	EventOpenNewTab(history.current());
Line 851... Line 798...
851
}
798
}
Line 959... Line 906...
959
		return #abs_url;
906
		return #abs_url;
960
	}
907
	}
961
	return 0;
908
	return 0;
962
}
909
}
Line -... Line 910...
-
 
910
 
-
 
911
void CheckContentType()
-
 
912
{
-
 
913
	char content_type[64];
-
 
914
	if (http.header_field("content-type\0", #content_type, sizeof(content_type))) // application || image
-
 
915
	if (content_type[0] == 'a') || (content_type[0] == 'i') { 
-
 
916
		EventOpenDownloader(history.current());
-
 
917
		StopLoading();
-
 
918
		history.back();
-
 
919
		EventRefreshPage();
-
 
920
	}
-
 
921
}
-
 
922
 
-
 
923
void HandleRedirect()
-
 
924
{
-
 
925
	char redirect_url[URL_SIZE];
-
 
926
	http.header_field("location\0", #redirect_url, URL_SIZE);
-
 
927
	get_absolute_url(#redirect_url, history.current());
-
 
928
	history.back();
-
 
929
	http.hfree();
-
 
930
	if (http_get_type==PAGE) OpenPage(#redirect_url);
-
 
931
	else if (http_get_type==IMG) http.get(#redirect_url);
-
 
932
}
963
 
933
 
964
dword GetImg()
934
dword GetImg()
965
{
935
{
966
	while (WB1.page_img.next_url()) {
936
	while (WB1.page_img.next_url()) {
967
		if (cache.has(WB1.page_img.current_url())) continue;
937
		if (cache.has(WB1.page_img.current_url())) continue;