WebView 1.42

1) Download Manager: separate code logic from internal implementation, show notice on error
2) do not show href="javascript:xxx" links
3) show all image alt's

git-svn-id: svn://kolibrios.org@6001 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-12-22 18:14:35 +00:00
parent 56073f44de
commit 1841e3982c
8 changed files with 250 additions and 263 deletions

View File

@ -302,7 +302,7 @@ void TWebBrowser::SetStyle() {
{ {
if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
do{ do{
if (isattr("href=")) if (isattr("href=")) && (!strstr(#val,"javascript:"))
{ {
text_color_index++; text_color_index++;
text_colors[text_color_index] = text_colors[text_color_index-1]; text_colors[text_color_index] = text_colors[text_color_index-1];

View File

@ -58,7 +58,7 @@ void ImageCache::Images(int left1, top1, width1)
if (!pics[cur_pic].image) if (!pics[cur_pic].image)
{ {
if (alt) && (link) strcat(#line, #alt); if (alt) strcat(#line, #alt);
//cur_pic = GetImage("/sys/network/noimg.png"); //cur_pic = GetImage("/sys/network/noimg.png");
return; return;
} }

View File

@ -29,14 +29,14 @@
char homepage[] = FROM "html\\homepage.htm"; char homepage[] = FROM "html\\homepage.htm";
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.41"; char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.42";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­" ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤" ?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>"; char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
char page_not_found[] = FROM "html\page_not_found_ru.htm"; char page_not_found[] = FROM "html\page_not_found_ru.htm";
char accept_language[]= "Accept-Language: ru\n"; char accept_language[]= "Accept-Language: ru\n";
#else #else
char version[]=" Text-based Browser 1.41"; char version[]=" Text-based Browser 1.42";
?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last" ?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>"; char loading[] = "Loading...<br>";
@ -89,8 +89,8 @@ enum {
#include "menu.h" #include "menu.h"
#include "history.h" #include "history.h"
#include "show_src.h" #include "show_src.h"
#include "network_get.h" #include "http_downloader.h"
#include "downloader.h" #include "download_manager.h"
char editURL[sizeof(URL)]; char editURL[sizeof(URL)];
int mouse_twb; int mouse_twb;
@ -358,7 +358,7 @@ void Scan(dword id__)
return; return;
case DOWNLOAD_MANAGER: case DOWNLOAD_MANAGER:
if (!downloader_opened) { if (!downloader_opened) {
strlcpy(#DL_URL, "http://",7); downloader_edit = NULL;
CreateThread(#Downloader,#downloader_stak+4092); CreateThread(#Downloader,#downloader_stak+4092);
} }
return; return;
@ -526,7 +526,7 @@ void ClickLink()
//notify(#URL); //notify(#URL);
if (!strncmp(#URL,"http://", 7)) if (!strncmp(#URL,"http://", 7))
{ {
strcpy(#DL_URL, #URL); strcpy(#downloader_edit, #URL);
CreateThread(#Downloader,#downloader_stak+4092); CreateThread(#Downloader,#downloader_stak+4092);
} }
else RunProgram("@open", #URL); else RunProgram("@open", #URL);

View File

@ -0,0 +1,173 @@
#ifdef LANG_RUS
#define DL_WINDOW_HEADER "Œ¥­¥¤¦¥à § £à㧮ª"
#define START_DOWNLOADING "<22> ç âì § ª çªã"
#define STOP_DOWNLOADING "Žáâ ­®¢¨âì ᪠稢 ­¨¥"
#define SHOW_IN_FOLDER "<22>®ª § âì ¢ ¯ ¯ª¥"
#define OPEN_FILE "Žâªàëâì ä ©«"
#define FILE_SAVED_AS "'Œ¥­¥¤¦¥à § £à㧮ª\n” ©« á®åà ­¥­ ª ª "
#define KB_RECEIVED " ¯®«ã祭®"
#else
#define DL_WINDOW_HEADER "Download Manager"
#define START_DOWNLOADING "Start downloading"
#define STOP_DOWNLOADING "Stop downloading"
#define SHOW_IN_FOLDER "Show in folder"
#define OPEN_FILE "Open file"
#define FILE_SAVED_AS "'Download manager\nFile saved as "
#define KB_RECEIVED " received"
#endif
char save_to[4096] = "/tmp0/1/Downloads/";
proc_info DL_Form;
char downloader_edit[10000];
char filepath[4096];
int mouse_twbi;
edit_box ed = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(downloader_edit),#downloader_edit,#mouse_twbi,2,19,19};
progress_bar pb = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
byte downloader_opened;
void Downloader()
{
int key;
char notify_message[4296];
downloader_opened = 1;
SetEventMask(0x27);
downloader.Stop();
if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://");
ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit);
loop()
{
WaitEventTimeout(40);
switch(EAX & 0xFF)
{
CASE evMouse:
if (!CheckActiveProcess(DL_Form.ID)) break;
edit_box_mouse stdcall (#ed);
break;
case evButton:
Key_Scan(GetButtonID());
break;
case evKey:
GetKeys();
EAX = key_ascii << 8;
edit_box_key stdcall(#ed);
if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301);
break;
case evReDraw:
system.color.get();
DefineAndDrawWindow(215, 100, 420, 120, 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 (DL_Form.width==0) break; //WTF?
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)
{
strcpy(#filepath, #save_to);
strcat(#filepath, #downloader.url+strrchr(#downloader.url, '/'));
if (WriteFile(downloader.bufsize, 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;
}
}
}
}
void Key_Scan(int id)
{
if (id==001) { downloader_opened=0; StopDownloading(); ExitProcess(); }
if (id==301) && (downloader.http_transfer <= 0) StartDownloading();
if (id==302) StopDownloading();
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
if (id==306) RunProgram("@open", #filepath);
}
void DL_Draw_Window()
{
byte cleft = 15;
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
DeleteButton(305);
DeleteButton(306);
if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
{
DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING);
}
if (downloader.state == STATE_IN_PROGRESS)
{
DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING);
DrawDownloading();
}
if (downloader.state == STATE_COMPLETED)
{
DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER);
DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE);
}
WriteText(cleft, ed.top + 4, 0x80, system.color.work_text, "URL:");
ed.left = strlen("URL:")*6 + 10 + cleft;
ed.width = DL_Form.cwidth - ed.left - cleft - 3;
ed.offset=0;
edit_box_draw stdcall(#ed);
DrawRectangle(ed.left-1, ed.top-1, ed.width+2, 16, ed.blur_border_color);
DrawRectangle(ed.left-2, ed.top-2, ed.width+4, 18, border_color);
}
void StartDownloading()
{
StopDownloading();
if (strncmp(#downloader_edit,"http://",7)!=0) {
notify("'File address should start from http://' -E");
return;
}
if (!downloader.Start(#downloader_edit)) {
notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E");
StopDownloading();
return;
}
ed.blur_border_color = 0xCACACA;
ed.flags = 100000000000b;
pb.value = 0;
DL_Draw_Window();
}
void DrawDownloading()
{
char bytes_received[70];
dword tmp = ConvertSizeToKb(downloader.data_downloaded_size);
sprintf(#bytes_received, "%s%s", tmp, KB_RECEIVED);
DrawBar(pb.left, pb.top + 17, DL_Form.cwidth - pb.left, 9, system.color.work);
WriteText(pb.left, pb.top + 17, 0x80, system.color.work_text, #bytes_received);
progressbar_draw stdcall(#pb);
}
void StopDownloading()
{
downloader.Stop();
ed.blur_border_color = 0xFFFfff;
ed.flags = 10b;
DL_Draw_Window();
}

View File

@ -1,203 +0,0 @@
#ifdef LANG_RUS
#define DL_WINDOW_HEADER "Œ¥­¥¤¦¥à § £à㧮ª"
#define START_DOWNLOADING "<22> ç âì § ª çªã"
#define STOP_DOWNLOADING "Žáâ ­®¢¨âì ᪠稢 ­¨¥"
#define SHOW_IN_FOLDER "<22>®ª § âì ¢ ¯ ¯ª¥"
#define OPEN_FILE "Žâªàëâì ä ©«"
#define FILE_SAVED_AS "'Œ¥­¥¤¦¥à § £à㧮ª\n” ©« á®åà ­¥­ ª ª "
#define KB_RECEIVED " ¯®«ã祭®"
#else
#define DL_WINDOW_HEADER "Download Manager"
#define START_DOWNLOADING "Start downloading"
#define STOP_DOWNLOADING "Stop downloading"
#define SHOW_IN_FOLDER "Show in folder"
#define OPEN_FILE "Open file"
#define FILE_SAVED_AS "'Download manager\nFile saved as "
#define KB_RECEIVED " received"
#endif
proc_info DL_Form;
char filepath[4096];
int mouse_twbi;
edit_box dl_edit = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19};
progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
char save_to[4096] = "/tmp0/1/Downloads/";
byte cleft = 15;
byte downloader_opened;
void Downloader()
{
int key;
char notify_message[4296];
downloader_opened = 1;
SetEventMask(0x27);
if (DL_URL[0]) StartDownloading(); else strcpy(#DL_URL, "http://");
dl_edit.size = dl_edit.pos = dl_edit.shift = dl_edit.shift_old = strlen(#DL_URL);
Downloading_SetDefaults();
loop()
{
WaitEventTimeout(40);
switch(EAX & 0xFF)
{
CASE evMouse:
if (!CheckActiveProcess(DL_Form.ID)) break;
edit_box_mouse stdcall (#dl_edit);
break;
case evButton:
DL_Scan(GetButtonID());
break;
case evKey:
key = GetKey();
EAX=key<<8;
edit_box_key stdcall(#dl_edit);
if (key==13) DL_Scan(301);
break;
case evReDraw:
system.color.get();
DefineAndDrawWindow(215, 100, 420, 120, 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 (DL_Form.width==0) || (DL_http_transfer <= 0) break;
http_receive stdcall (DL_http_transfer);
$push EAX
ESI = DL_http_transfer;
DL_progress_bar.max = ESI.http_msg.content_length;
if (DL_progress_bar.value != ESI.http_msg.content_received)
{
DL_progress_bar.value = ESI.http_msg.content_received;
progressbar_draw stdcall(#DL_progress_bar);
}
$pop EAX
if (EAX == 0) {
Downloading_Completed();
strcpy(#filepath, #save_to);
strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/'));
if (WriteFile(DL_bufsize, DL_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);
dl_edit.blur_border_color = 0xFFFfff;
dl_edit.flags = 10b;
DL_Draw_Window();
break;
}
ESI = DL_http_transfer;
downloaded_size = ESI.http_msg.content_received;
full_size = ESI.http_msg.content_length;
DrawDownloading();
}
}
}
void DL_Draw_Window()
{
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
DeleteButton(305);
DeleteButton(306);
if (download_state == STATE_NOT_STARTED) || (download_state == STATE_COMPLETED)
{
DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING);
}
if (download_state == STATE_IN_PROGRESS)
{
DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING);
DrawDownloading();
}
if (download_state == STATE_COMPLETED)
{
DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER);
DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE);
}
WriteText(cleft, dl_edit.top + 4, 0x80, system.color.work_text, "URL:");
dl_edit.left = strlen("URL:")*6 + 10 + cleft;
dl_edit.width = DL_Form.cwidth - dl_edit.left - cleft - 3;
dl_edit.offset=0;
edit_box_draw stdcall(#dl_edit);
DrawRectangle(dl_edit.left-1, dl_edit.top-1, dl_edit.width+2, 16, dl_edit.blur_border_color);
DrawRectangle(dl_edit.left-2, dl_edit.top-2, dl_edit.width+4, 18, border_color);
}
void DrawDownloading()
{
dword tmp;
char bytes_received[70];
tmp = ConvertSizeToKb(downloaded_size);
strcpy(#bytes_received, tmp);
strcat(#bytes_received, KB_RECEIVED);
DrawBar(DL_progress_bar.left, DL_progress_bar.top + 17, DL_Form.cwidth - DL_progress_bar.left, 9, system.color.work);
WriteText(DL_progress_bar.left, DL_progress_bar.top + 17, 0x80, system.color.work_text, #bytes_received);
progressbar_draw stdcall(#DL_progress_bar);
}
void DL_Scan(int id)
{
if (id==001) {
downloader_opened=0;
StopDownloading();
ExitProcess();
}
if (id==301) && (DL_http_transfer <= 0) StartDownloading();
if (id==302) StopDownloading();
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
if (id==306) RunProgram("@open", #filepath);
}
void StopDownloading()
{
Downloading_Stop();
dl_edit.blur_border_color = 0xFFFfff;
dl_edit.flags = 10b;
DL_Draw_Window();
}
void StartDownloading()
{
StopDownloading();
if (strncmp(#DL_URL,"http:",5)==0)
{
Downloading_Start();
dl_edit.blur_border_color = 0xCACACA;
dl_edit.flags = 100000000000b;
DL_progress_bar.value = 0;
DL_Draw_Window();
if (DL_http_transfer == 0)
{
StopDownloading();
DL_bufsize = 0;
DL_bufpointer = mem_Free(DL_bufpointer);
return;
}
}
else
{
notify("File adress should starts from http://");
}
}

View File

@ -0,0 +1,68 @@
enum {
STATE_NOT_STARTED,
STATE_IN_PROGRESS,
STATE_COMPLETED
};
struct DOWNLOADER {
char url[10000];
int data_downloaded_size, data_full_size;
dword bufpointer, bufsize;
byte state;
dword http_transfer;
dword Start();
void Stop();
void Completed();
int MonitorProgress();
} downloader;
dword DOWNLOADER::Start(dword _url)
{
state = STATE_IN_PROGRESS;
strcpy(#url, _url); //need to replace my malloc()
http_get stdcall (#url, 0, 0, #accept_language);
http_transfer = EAX;
return http_transfer;
}
void DOWNLOADER::Stop()
{
state = STATE_NOT_STARTED;
if (http_transfer!=0)
{
EAX = http_transfer;
EAX = EAX.http_msg.content_ptr; // get pointer to data
$push EAX // save it on the stack
http_free stdcall (http_transfer); // abort connection
$pop EAX
mem_Free(EAX); // free data
http_transfer=0;
bufsize = 0;
bufpointer = mem_Free(bufpointer);
}
data_downloaded_size = data_full_size = 0;
}
void DOWNLOADER::Completed()
{
state = STATE_COMPLETED;
ESI = http_transfer;
bufpointer = ESI.http_msg.content_ptr;
bufsize = ESI.http_msg.content_received;
http_free stdcall (http_transfer);
http_transfer=0;
}
int DOWNLOADER::MonitorProgress()
{
dword receive_result;
if (http_transfer <= 0) return false;
http_receive stdcall (http_transfer);
receive_result = EAX;
EDI = http_transfer;
data_full_size = EDI.http_msg.content_length;
data_downloaded_size = EDI.http_msg.content_received;
if (receive_result == 0) Completed();
return true;
}

View File

@ -1,51 +0,0 @@
char DL_URL[10000];
dword DL_bufpointer, DL_bufsize, DL_http_transfer, DL_http_buffer;
int downloaded_size, full_size;
byte download_state;
enum { STATE_NOT_STARTED, STATE_IN_PROGRESS, STATE_COMPLETED };
void Downloading_SetDefaults()
{
downloaded_size = full_size = 0;
}
void Downloading_Stop()
{
download_state = STATE_NOT_STARTED;
if (DL_http_transfer<>0)
{
EAX = DL_http_transfer;
EAX = EAX.http_msg.content_ptr; // get pointer to data
$push EAX // save it on the stack
http_free stdcall (DL_http_transfer); // abort connection
$pop EAX
mem_Free(EAX); // free data
DL_http_transfer=0;
DL_bufsize = 0;
DL_bufpointer = mem_Free(DL_bufpointer);
Downloading_SetDefaults();
}
}
void Downloading_Start()
{
download_state = STATE_IN_PROGRESS;
http_get stdcall (#DL_URL, 0, 0, #accept_language);
DL_http_transfer = EAX;
}
void Downloading_Completed()
{
ESI = DL_http_transfer;
DL_bufpointer = ESI.http_msg.content_ptr;
DL_bufsize = ESI.http_msg.content_received;
http_free stdcall (DL_http_transfer);
DL_http_transfer=0;
download_state = STATE_COMPLETED;
}

View File

@ -50,7 +50,7 @@ char aURIunescape[9] = "unescape\0";
// user flags // user flags
#define FLAG_KEEPALIVE 1 << 8 #define FLAG_KEEPALIVE 1 << 8
#define FLAG_MULTIBUFF 1 << 9 #define FLAG_MULTIBUFF 1 << 9
// error flags // error flags
#define FLAG_INVALID_HEADER 1 << 16 #define FLAG_INVALID_HEADER 1 << 16