WebView 1.61: fix of downloading timeout, ultimate speedup; thanks hidnplayr for idea use event EVN_STACK instead of timeout

git-svn-id: svn://kolibrios.org@6978 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2017-09-17 01:32:09 +00:00
parent 1c6bb84e7f
commit ad6c634152
4 changed files with 202 additions and 181 deletions

View File

@ -1,6 +1,6 @@
//HTML Viewer in C--
//Copyright 2007-2013 by Veliant & Leency
//Asper, lev, Lrz, Barsuk, Nable...
//Copyright 2007-2017 by Veliant & Leency
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
#ifndef AUTOBUILD
#include "lang.h--"
@ -30,7 +30,7 @@
char homepage[] = FROM "html\\homepage.htm""\0";
#ifdef LANG_RUS
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.6";
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.61";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
@ -43,7 +43,7 @@ char rmb_menu[] =
Žç¨áâ¨âì ªíè ª à⨭®ª
Œ¥­¥¤¦¥à § £à㧮ª";
#else
char version[]="Text-based Browser 1.6";
char version[]="Text-based Browser 1.61";
?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>";
@ -126,140 +126,137 @@ void main()
if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
WB1.list.SetFont(8, 14, 10011000b);
WB1.list.no_selection = true;
SetEventMask(0xa7);
BEGIN_LOOP_APPLICATION:
WaitEventTimeout(2);
switch(EAX & 0xFF)
{
CASE evMouse:
if (!CheckActiveProcess(Form.ID)) break;
edit_box_mouse stdcall (#address_box);
mouse.get();
if (WB1.list.MouseOver(mouse.x, mouse.y))
{
if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
&& (bufsize) && (mouse.pkm) && (mouse.up) {
EventShowPageMenu(mouse.x, mouse.y);
break;
}
if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
}
scrollbar_v_mouse (#scroll_wv);
if (WB1.list.first != scroll_wv.position)
{
WB1.list.first = scroll_wv.position;
WB1.DrawPage();
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
loop() switch(WaitEvent())
{
case evMouse:
if (!CheckActiveProcess(Form.ID)) break;
edit_box_mouse stdcall (#address_box);
mouse.get();
if (WB1.list.MouseOver(mouse.x, mouse.y))
{
if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
&& (bufsize) && (mouse.pkm) && (mouse.up) {
EventShowPageMenu(mouse.x, mouse.y);
break;
}
if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
}
scrollbar_v_mouse (#scroll_wv);
if (WB1.list.first != scroll_wv.position)
{
WB1.list.first = scroll_wv.position;
WB1.DrawPage();
break;
}
break;
case evButton:
ProcessEvent(GetButtonID());
break;
case evButton:
ProcessEvent(GetButtonID());
break;
case evKey:
GetKeys();
if (address_box.flags & 0b10)
case evKey:
GetKeys();
if (address_box.flags & 0b10)
{
if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else {
EAX = key_editbox;
edit_box_key stdcall(#address_box);
}
}
else
{
if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
else ProcessEvent(key_scancode);
}
break;
case evReDraw:
if (menu.list.cur_y) {
ProcessEvent(menu.list.cur_y);
menu.list.cur_y = 0;
}
DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
GetProcessInfo(#Form, SelfInfo);
if (Form.status_window>2) { DrawTitle(#header); break; }
if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
Draw_Window();
break;
case evNetwork:
if (http_transfer > 0) {
http_receive stdcall (http_transfer);
$push EAX
ESI = http_transfer;
wv_progress_bar.max = ESI.http_msg.content_length;
if (wv_progress_bar.value != ESI.http_msg.content_received)
{
if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else {
EAX = key_editbox;
edit_box_key stdcall(#address_box);
}
wv_progress_bar.value = ESI.http_msg.content_received;
DrawProgress();
}
else
{
if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
else ProcessEvent(key_scancode);
}
break;
case evReDraw:
if (menu.list.cur_y) {
ProcessEvent(menu.list.cur_y);
menu.list.cur_y = 0;
}
DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
GetProcessInfo(#Form, SelfInfo);
if (Form.status_window>2) { DrawTitle(#header); break; }
if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
Draw_Window();
break;
case evNetwork:
if (http_transfer > 0) {
http_receive stdcall (http_transfer);
$push EAX
$pop EAX
if (EAX == 0) {
ESI = http_transfer;
wv_progress_bar.max = ESI.http_msg.content_length;
if (wv_progress_bar.value != ESI.http_msg.content_received)
// Handle redirects
if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
{
wv_progress_bar.value = ESI.http_msg.content_received;
DrawProgress();
}
$pop EAX
if (EAX == 0) {
ESI = http_transfer;
// Handle redirects
if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
redirected++;
if (redirected<=5)
{
redirected++;
if (redirected<=5)
{
http_find_header_field stdcall (http_transfer, "location\0");
if (EAX!=0) {
ESI = EAX;
EDI = #URL;
do {
$lodsb;
$stosb;
} while (AL != 0) && (AL != 13) && (AL != 10);
DSBYTE[EDI-1]='\0';
if (!strncmp(#URL,"https://",8))
{
ShowErrorMessageThatHttpsIsNotSupportedYet();
StopLoading();
break;
}
http_find_header_field stdcall (http_transfer, "location\0");
if (EAX!=0) {
ESI = EAX;
EDI = #URL;
do {
$lodsb;
$stosb;
} while (AL != 0) && (AL != 13) && (AL != 10);
DSBYTE[EDI-1]='\0';
if (!strncmp(#URL,"https://",8))
{
ShowErrorMessageThatHttpsIsNotSupportedYet();
StopLoading();
break;
}
}
else
{
notify("Too many redirects");
StopLoading();
break;
}
}
else
{
redirected = 0;
}
// Loading the page is complete, free resources
if (redirected>0)
{
http_free stdcall (http_transfer);
http_transfer=0;
GetAbsoluteURL(#URL);
history.back();
strcpy(#editURL, #URL);
DrawEditBoxWebView();
OpenPage();
}
else
{
history.add(#URL);
ESI = http_transfer;
bufpointer = ESI.http_msg.content_ptr;
bufsize = ESI.http_msg.content_received;
http_free stdcall (http_transfer);
http_transfer=0;
SetPageDefaults();
ShowPage();
notify("Too many redirects");
StopLoading();
break;
}
}
else
{
redirected = 0;
}
// Loading the page is complete, free resources
if (redirected>0)
{
http_free stdcall (http_transfer);
http_transfer=0;
GetAbsoluteURL(#URL);
history.back();
strcpy(#editURL, #URL);
DrawEditBoxWebView();
OpenPage();
}
else
{
history.add(#URL);
ESI = http_transfer;
bufpointer = ESI.http_msg.content_ptr;
bufsize = ESI.http_msg.content_received;
http_free stdcall (http_transfer);
http_transfer=0;
SetPageDefaults();
ShowPage();
}
}
}
goto BEGIN_LOOP_APPLICATION;
}
}
}
void SetElementSizes()

View File

@ -39,7 +39,7 @@ void Downloader()
int key, i;
char notify_message[4296];
downloader_opened = 1;
SetEventMask(0x27);
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
system.color.get();
pb.frame_color = system.color.work_dark;
@ -50,69 +50,65 @@ void Downloader()
if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://");
ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit);
loop()
loop() switch(WaitEvent())
{
WaitEventTimeout(30);
switch(EAX & 0xFF)
{
CASE evMouse:
if (!CheckActiveProcess(DL_Form.ID)) break;
edit_box_mouse stdcall (#ed);
break;
case evMouse:
if (!CheckActiveProcess(DL_Form.ID)) break;
edit_box_mouse stdcall (#ed);
break;
case evButton:
Key_Scan(GetButtonID());
break;
case evKey:
GetKeys();
edit_box_key stdcall(#ed);
if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301);
break;
case evReDraw:
DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
GetProcessInfo(#DL_Form, SelfInfo);
if (DL_Form.status_window>2) break;
if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120);
if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD);
DL_Draw_Window();
break;
default:
if (!downloader.MonitorProgress()) break;
pb.max = downloader.data_full_size;
if (pb.value != downloader.data_downloaded_size)
{
pb.value = downloader.data_downloaded_size;
progressbar_draw stdcall(#pb);
DrawDownloading();
}
if (downloader.state == STATE_COMPLETED)
{
if (!dir_exists(#save_to)) CreateDir(#save_to);
strcpy(#filepath, #save_to);
chrcat(#filepath, '/');
// Clean all slashes at the end
strcpy(#aux, #downloader_edit);
while (aux[strlen(#aux)-1] == '/') {
aux[strlen(#aux)-1] = 0;
}
strcat(#filepath, #aux+strrchr(#aux, '/'));
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
case evButton:
Key_Scan(GetButtonID());
break;
case evKey:
GetKeys();
edit_box_key stdcall(#ed);
if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301);
break;
case evReDraw:
DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
GetProcessInfo(#DL_Form, SelfInfo);
if (DL_Form.status_window>2) break;
if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120);
if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD);
if (WriteFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0)
sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
else
sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
notify(#notify_message);
StopDownloading();
DL_Draw_Window();
break;
default:
if (!downloader.MonitorProgress()) break;
pb.max = downloader.data_full_size;
if (pb.value != downloader.data_downloaded_size)
{
pb.value = downloader.data_downloaded_size;
progressbar_draw stdcall(#pb);
DrawDownloading();
}
if (downloader.state == STATE_COMPLETED)
{
if (!dir_exists(#save_to)) CreateDir(#save_to);
strcpy(#filepath, #save_to);
chrcat(#filepath, '/');
// Clean all slashes at the end
strcpy(#aux, #downloader_edit);
while (aux[strlen(#aux)-1] == '/') {
aux[strlen(#aux)-1] = 0;
}
strcat(#filepath, #aux+strrchr(#aux, '/'));
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
if (WriteFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0)
sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
else
sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
notify(#notify_message);
StopDownloading();
DL_Draw_Window();
break;
}
}
}
}
}

View File

@ -36,12 +36,28 @@ char program_path[4096];
#define evReDraw 1
#define evKey 2
#define evButton 3
#define evExit 4
#define evDesktop 5
#define evMouse 6
#define evIPC 7
#define evNetwork 8
#define evDebug 9
//Event mask bits for function 40
#define EVM_REDRAW 1b
#define EVM_KEY 10b
#define EVM_BUTTON 100b
#define EVM_EXIT 1000b
#define EVM_BACKGROUND 10000b
#define EVM_MOUSE 100000b
#define EVM_IPC 1000000b
#define EVM_STACK 10000000b
#define EVM_DEBUG 100000000b
#define EVM_STACK2 1000000000b
#define EVM_MOUSE_FILTER 0x80000000
#define EVM_CURSOR_FILTER 0x40000000
//Button options
#define BT_DEL 0x80000000
#define BT_HIDE 0x40000000
@ -92,7 +108,7 @@ inline fastcall dword WaitEventTimeout(EBX)
$int 0x40
}
inline fastcall SetEventMask(EBX)
inline fastcall dword SetEventMask(EBX)
{
$mov eax,40
$int 0x40

View File

@ -121,4 +121,16 @@ dword load_image(dword filename)
return 0;
}
void DrawLibImage(dword image_pointer,x,y,w,h,offx,offy) {
img_draw stdcall (
image_pointer,
x,
y,
w,
h,
offx,
offy
);
}
#endif