WebView 1.8:

1. possibility to open HTTPS sites via gate.aspero.pro (invisible for user), not working for files
2. rewrite parse tag function to fix broken URLs on page in some cases ("/user" instead of "/user/")
3. fix hand cursor appearance, fix progress bar on page load
4. load homepage on submitting empty url in adressbox
5. F12 - debug on, F11 - old tag parser on
6. unify page/file downloading code

git-svn-id: svn://kolibrios.org@7282 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-05-20 13:40:58 +00:00
parent e59b0f053b
commit 873fc290d5
8 changed files with 180 additions and 144 deletions

View File

@ -1,24 +1,4 @@
int UrlIsAbsolute(dword in)
{
if(!strncmp(in,"http:",5)) return true;
if(!strncmp(in,"https:",6)) return true;
if(!strncmp(in,"file:",5)) return true;
if(!strncmp(in,"mailto:",7)) return true;
if(!strncmp(in,"ftp:",4)) return true;
if(!strncmp(in,"WebView:",8)) return true;
if(!strncmp(in,"/sys/",5)) return true;
if(!strncmp(in,"/hd/",4)) return true;
if(!strncmp(in,"/fd/",4)) return true;
if(!strncmp(in,"/rd/",4)) return true;
if(!strncmp(in,"/tmp/",5)) return true;
if(!strncmp(in,"/cd/",4)) return true;
if(!strncmp(in,"/bd/",4)) return true;
if(!strncmp(in,"/usbhd/",7)) return true;
if(!strncmp(in,"/kolibrios/",11)) return true;
return false;
}
void GetAbsoluteURL(dword in_URL)
{
int i;
@ -30,7 +10,7 @@ void GetAbsoluteURL(dword in_URL)
strcpy(i+1, i+5);
}
if (UrlIsAbsolute(in_URL)) return;
if (check_is_the_url_absolute(in_URL)) return;
IF (!strcmpn(in_URL,"//", 2))
{

View File

@ -88,6 +88,7 @@ bool LinksArray::HoverAndProceed(dword mx, my)
return false;
}
if (active==i) return false;
CursorPointer.Load(#CursorFile);
CursorPointer.Set();
if (links[active].underline) DrawBar(links[active].x, -WB1.list.first + links[active].y
+ links[active].h, links[active].w, links[active].underline_h, link_color_inactive);

View File

@ -1,4 +1,81 @@
unsigned int GetNextParam()
bool GetNextParam() {
if (!old_tag_parser_mode)
return GetNextParam_NEW();
else
return GetNextParam_OLD();
}
bool GetNextParam_NEW()
{
byte quotes = NULL;
int i;
if (!tagparam) return false;
if (debug_mode) {
debug("tagparam: "); debugln(#tagparam);
}
i = strlen(#tagparam) - 1;
if (tagparam[i] == '/') i--;
while (i>0) && (__isWhite(tagparam[i])) i--;
if (tagparam[i] == '"') || (tagparam[i] == '\'')
{
//find VAL end
quotes = tagparam[i];
tagparam[i] = '\0'; i--;
//find VAL start and copy
i = strrchr(#tagparam, quotes);
strlcpy(#val, #tagparam + i, sizeof(val));
tagparam[i] = '\0'; i--;
//find ATTR end
while (i > 0) && (tagparam[i] != '=') i--;
tagparam[i+1] = '\0';
}
else
{
//find VAL end
//already have
//find VAL start and copy
while (i > 0) && (tagparam[i] != '=') i--;
i++;
strlcpy(#val, #tagparam + i, sizeof(val));
tagparam[i] = '\0';
//find ATTR end
//already have
}
//find ATTR start and copy
while (i>0) && (!__isWhite(tagparam[i])) i--;
strlcpy(#attr, #tagparam + i + 1, sizeof(attr));
tagparam[i] = '\0';
strlwr(#attr);
if (debug_mode) {
if (quotes) {
debug("quote: "); debugch(quotes); debugln(" ");
}
else {
debugln("unquoted text");
}
sprintf(#param, "val: %s\nattr: %s\n\n", #val, #attr);
debug(#param);
}
return true;
}
unsigned int GetNextParam_OLD()
{
byte kavichki=0;
int i = strlen(#tagparam) - 1;
@ -30,7 +107,7 @@ unsigned int GetNextParam()
FOR ( ; ((tagparam[i] <>' ') && (i > 0); i--)
{
IF (tagparam[i] == '=') //äåðçêàÿ çàãëóøêà
IF (tagparam[i] == '=') //dirty fix (kludge)
tagparam[i + 1] = 0x00;
}
strlcpy(#attr, #tagparam + i + 1, sizeof(attr));

View File

@ -58,7 +58,7 @@ char *unicode_tags[]={
"#1031", "\244",
"#8470", "N",
"bull", "-", //вообще здесь точка
"bull", "\31", //вообще здесь точка
"percnt","%",
0};

View File

@ -32,7 +32,7 @@ _http http = {0, 0, 0, 0, 0, 0, 0};
char homepage[] = FROM "html\\homepage.htm""\0";
#ifdef LANG_RUS
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.74";
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.8";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
@ -47,7 +47,7 @@ char link_menu[] =
"Š®¯¨à®¢ âì áá뫪ã
ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
#else
char version[]="Text-based Browser 1.74";
char version[]="Text-based Browser 1.8";
?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>";
@ -83,6 +83,9 @@ dword col_bg;
dword panel_color;
dword border_color;
bool debug_mode = false;
bool old_tag_parser_mode = false;
progress_bar wv_progress_bar;
bool souce_mode = false;
bool open_in_a_new_window = false;
@ -98,7 +101,7 @@ enum {
VIEW_HISTORY,
//FREE_IMG_CACHE,
DOWNLOAD_MANAGER,
COPY_LINK=1200,
COPY_LINK_URL=1200,
DOWNLOAD_LINK_CONTENTS,
};
@ -114,7 +117,6 @@ edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000
void main()
{
CursorPointer.Load(#CursorFile);
load_dll(boxlib, #box_lib_init,0);
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
@ -132,15 +134,12 @@ void main()
case evMouse:
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);
if (WB1.list.MouseOver(mouse.x, mouse.y)) 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)
{
@ -192,54 +191,34 @@ void main()
if (http.status_code >= 300) && (http.status_code < 400)
{
redirected++;
if (redirected<=5)
if (redirected>5)
{
if (http.handle_redirect()) {
if (!strncmp(#URL,"https://",8))
{
history.back();
strcpy(#editURL, history.current());
strcpy(#URL, history.current());
ShowErrorMessageThatHttpsIsNotSupportedYet();
notify("'Too many redirects.' -E");
StopLoading();
break;
}
}
}
else
{
notify("Too many redirects");
StopLoading();
break;
}
}
else
{
redirected = 0;
}
// Loading the page is complete, free resources
if (redirected>0)
{
http.handle_redirect();
http.free();
GetAbsoluteURL(#URL);
GetAbsoluteURL(#http.redirect_url);
history.back();
strcpy(#editURL, #URL);
DrawEditBoxWebView();
OpenPage();
}
else
{
break;
}
redirected = 0;
// Loading the page is complete, free resources
history.add(#URL);
ESI = http.transfer;
bufpointer = ESI.http_msg.content_ptr;
bufsize = ESI.http_msg.content_received;
bufpointer = http.content_pointer;
bufsize = http.content_received;
http.free();
SetPageDefaults();
ShowPage();
}
}
}
}
}
void SetElementSizes()
@ -275,7 +254,12 @@ void Draw_Window()
img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 87, 0);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
if (!header) OpenPage(); else { WB1.DrawPage(); DrawEditBoxWebView(); }
if (!header)
OpenPage();
else {
WB1.DrawPage();
DrawEditBoxWebView();
}
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
DrawProgress();
}
@ -303,7 +287,10 @@ void ProcessEvent(dword id__)
return;
case GOTOURL_BUTTON:
case SCAN_CODE_ENTER:
if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
if (!editURL[0]) {
strcpy(#URL, URL_SERVICE_HOME);
}
else if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
{
strcpy(#URL, #editURL);
@ -334,7 +321,7 @@ void ProcessEvent(dword id__)
WB1.LoadInternalPage(bufpointer, bufsize);
break;
case EDIT_SOURCE:
if (!strncmp(#URL,"http:",5))
if (!strncmp(#URL,"http",4))
{
CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
@ -356,7 +343,7 @@ void ProcessEvent(dword id__)
CreateThread(#Downloader,#downloader_stak+4092);
}
return;
case COPY_LINK:
case COPY_LINK_URL:
Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
notify("'URL copied to clipboard'O");
return;
@ -366,6 +353,16 @@ void ProcessEvent(dword id__)
CreateThread(#Downloader,#downloader_stak+4092);
}
return;
case SCAN_CODE_F12:
debug_mode ^= 1;
if (debug_mode) notify("'Debug mode ON'-I");
else notify("'Debug mode OFF'-I");
return;
case SCAN_CODE_F11:
old_tag_parser_mode ^= 1;
if (old_tag_parser_mode) notify("'Old tag parser ON'-I");
else notify("'Old tag parser OFF'-I");
return;
}
}
@ -397,6 +394,7 @@ void SetPageDefaults()
void OpenPage()
{
char getUrl[sizeof(URL)];
StopLoading();
souce_mode = false;
strcpy(#editURL, #URL);
@ -409,10 +407,18 @@ void OpenPage()
DrawEditBoxWebView();
return;
}
if (!strncmp(#URL,"http:",5))
if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8))
{
img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0);
if (!strncmp(#URL,"http:",5)) {
http.get(#URL);
}
if (!strncmp(#URL,"https://",8)) {
sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
http.get(#getUrl);
}
//http.get(#URL);
if (!http.transfer)
{
StopLoading();
@ -452,7 +458,6 @@ DrawEditBoxWebView()
void ShowPage()
{
DrawEditBoxWebView();
debugval("bufsize", bufsize);
if (!bufsize)
{
if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
@ -486,10 +491,10 @@ int SetSkinColors()
void DrawProgress()
{
unsigned long btn;
dword persent;
if (http.transfer == 0) return;
if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30;
DrawBar(address_box.left-2, address_box.top+20, btn, 2, wv_progress_bar.progress_color);
if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color);
}
@ -501,7 +506,6 @@ void ClickLink()
StopLoading();
history.back();
}
strcpy(#URL, PageLinks.GetURL(PageLinks.active));
//#1
if (URL[0] == '#')
@ -532,17 +536,9 @@ void ClickLink()
return;
}
if (!strncmp(#URL,"https://",8))
{
ShowErrorMessageThatHttpsIsNotSupportedYet();
strcpy(#editURL, history.current());
strcpy(#URL, history.current());
return;
}
GetAbsoluteURL(#URL);
if (strncmp(#URL,"http://",7)!=0)
if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
{
if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
{
@ -587,7 +583,7 @@ void EventShowPageMenu(dword _left, _top)
void EventShowLinkMenu(dword _left, _top)
{
menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK);
menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
}
void EventUpdateProgressBar()
@ -600,12 +596,6 @@ void EventUpdateProgressBar()
}
}
void ShowErrorMessageThatHttpsIsNotSupportedYet()
{
notify("'HTTPS protocol is not supported yet' -E");
}
DrawStatusBar(dword _status_text)
{
status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;

View File

@ -73,10 +73,10 @@ void Downloader()
default:
if (!downloader.MonitorProgress()) break;
pb.max = downloader.data_full_size;
if (pb.value != downloader.data_downloaded_size)
pb.max = downloader.httpd.content_length;
if (pb.value != downloader.httpd.content_received)
{
pb.value = downloader.data_downloaded_size;
pb.value = downloader.httpd.content_received;
progressbar_draw stdcall(#pb);
DrawDownloading();
}
@ -153,7 +153,7 @@ void StartDownloading()
void DrawDownloading()
{
char bytes_received[70];
sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.data_downloaded_size) );
sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.httpd.content_received) );
DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work);
WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received);
progressbar_draw stdcall(#pb);
@ -182,7 +182,7 @@ void SaveDownloadedFile()
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
if (CreateFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0)
if (CreateFile(downloader.httpd.content_received, 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");

View File

@ -41,6 +41,8 @@
#define SCAN_CODE_PLUS 013
#define SCAN_CODE_F1 059
#define SCAN_CODE_F11 087
#define SCAN_CODE_F12 088
#define SCAN_CODE_KEY_B 048
#define SCAN_CODE_KEY_C 046

View File

@ -13,6 +13,8 @@ struct _http
dword status_code;
dword receive_result;
dword content_pointer;
char redirect_url[4096*3];
char finaladress[4096*3];
dword get();
void free();
@ -39,17 +41,19 @@ void _http::receive()
http_receive stdcall (transfer);
receive_result = EAX;
ESI = transfer;
if (!EAX) status_code = ESI.http_msg.status;
content_length = ESI.http_msg.content_length;
content_received = ESI.http_msg.content_received;
EDI = transfer;
if (!EAX) {
status_code = EDI.http_msg.status;
content_pointer = EDI.http_msg.content_ptr;
}
content_length = EDI.http_msg.content_length;
content_received = EDI.http_msg.content_received;
}
bool _http::handle_redirect()
{
dword redirect, i;
char redirect_url[4096*3], finaladress[4096*3];
dword redirect;
http_find_header_field stdcall (transfer, "location\0");
if (EAX!=0) {
ESI = EAX;
@ -81,13 +85,11 @@ enum {
struct DOWNLOADER {
_http httpd;
unsigned data_downloaded_size, data_full_size;
dword bufpointer, bufsize, url;
int state;
dword Start();
void Stop();
void Completed();
int MonitorProgress();
bool MonitorProgress();
} downloader;
dword DOWNLOADER::Start(dword _url)
@ -113,43 +115,30 @@ void DOWNLOADER::Stop()
bufsize = 0;
bufpointer = free(bufpointer);
}
data_downloaded_size = data_full_size = 0;
httpd.content_received = httpd.content_length = 0;
}
void DOWNLOADER::Completed()
bool DOWNLOADER::MonitorProgress()
{
state = STATE_COMPLETED;
ESI = httpd.transfer;
bufpointer = ESI.http_msg.content_ptr;
bufsize = ESI.http_msg.content_received;
httpd.free();
}
int DOWNLOADER::MonitorProgress()
{
dword receive_result;
char redirect_url[4096*3], finaladress[4096*3];
if (httpd.transfer <= 0) return false;
http_receive stdcall (httpd.transfer);
receive_result = EAX;
EDI = httpd.transfer;
httpd.status_code = EDI.http_msg.status;
data_full_size = EDI.http_msg.content_length;
data_downloaded_size = EDI.http_msg.content_received;
if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1;
httpd.receive();
if (!httpd.content_length) httpd.content_length = httpd.content_received * 20;
if (receive_result == 0) {
if (httpd.receive_result == 0) {
if (httpd.status_code >= 300) && (httpd.status_code < 400)
{
httpd.handle_redirect();
strcpy(url, httpd.url);
get_absolute_url(#finaladress, url, #redirect_url);
get_absolute_url(#httpd.finaladress, url, #httpd.redirect_url);
Stop();
Start(#finaladress);
url = #finaladress;
Start(#httpd.finaladress);
url = #httpd.finaladress;
return false;
}
Completed();
state = STATE_COMPLETED;
bufpointer = httpd.content_pointer;
bufsize = httpd.content_received;
httpd.free();
}
return true;
}
@ -191,8 +180,6 @@ int check_is_the_url_absolute(dword _in)
void get_absolute_url(dword _rez, _base, _new)
{
int i;
debug("_base:");debugln(_base);
debug("_new:");debugln(_new);
//case: ./valera.html
if (!strncmp(_new,"./", 2)) _new+=2;
//case: http://site.name
@ -222,5 +209,4 @@ void get_absolute_url(dword _rez, _base, _new)
strcat(_rez, _new);
_GET_ABSOLUTE_URL_END:
while (i=strstr(_rez, "&amp;")) strcpy(i+1, i+5);
debug("_rez:");debugln(_rez);
}