Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 7987 → Rev 8016

/programs/cmm/browser/WebView.c
1,8 → 1,6
//Copyright 2007-2020 by Veliant & Leency
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
 
//Licence restriction: compiling this app for WIN32 is forbidden.
 
#ifndef AUTOBUILD
#include "lang.h--"
#endif
32,6 → 30,10
#include "..\lib\patterns\toolbar_button.h"
#include "..\lib\patterns\restart_process.h"
 
#define URL_SIZE 4000
 
char version[]="WebView 2.65";
 
#include "texts.h"
#include "cache.h"
#include "show_src.h"
64,12 → 66,13
TAB_CLOSE_ID = 900
};
 
_history history;
 
enum { TARGET_SAME_TAB, TARGET_NEW_WINDOW, TARGET_NEW_TAB };
 
#include "..\TWB\TWB.c" //HTML Parser, a core component
 
TWebBrowser WB1;
_history history;
 
#include "history.h"
 
79,10 → 82,6
#define TAB_H 20
dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
 
#define URL_SIZE 4000
 
int action_buf;
 
_http http = 0;
 
bool source_mode = false;
106,6 → 105,8
 
dword shared_url;
 
dword http_get_type;
 
void LoadLibraries()
{
load_dll(boxlib, #box_lib_init,0);
202,7 → 203,7
break;
 
case evButton:
ProcessEvent( GetButtonID() );
ProcessEvent( @GetButtonID() );
break;
 
case evKey:
260,7 → 261,8
http.free();
GetAbsoluteURL(#http.redirect_url, history.current());
history.back();
OpenPage(#http.redirect_url);
if (http_get_type==PAGE) OpenPage(#http.redirect_url);
else if (http_get_type==IMG) http.get(#http.redirect_url);
} else {
notify("'Too many redirects.' -E");
StopLoading();
270,9 → 272,16
// Loading the page is complete, free resources
redirect_count = 0;
http.free();
pages_cache.add(history.current(), http.content_pointer, http.content_received);
if (http_get_type==PAGE) {
cache.add(history.current(), http.content_pointer, http.content_received, PAGE);
LoadInternalPage(http.content_pointer, http.content_received);
}
else if (http_get_type==IMG) {
cache.add(WB1.page_img.current_url(), http.content_pointer, http.content_received, IMG);
WB1.page_img.set_data(cache.data.get_last(), http.content_received);
GetImg();
}
}
break;
default:
if (ESDWORD[shared_url] != '\0') {
287,44 → 296,20
{
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode)
{
case SCAN_CODE_KEY_O:
EventOpenDialog();
return true;
case SCAN_CODE_KEY_H:
ProcessEvent(VIEW_HISTORY);
return true;
case SCAN_CODE_KEY_U:
EventViewSource();
return true;
case SCAN_CODE_KEY_T:
EventOpenNewTab(URL_SERVICE_HOMEPAGE);
return true;
case SCAN_CODE_KEY_N:
RunProgram(#program_path, NULL);
return true;
case SCAN_CODE_KEY_J:
ProcessEvent(DOWNLOAD_MANAGER);
return true;
case SCAN_CODE_KEY_R:
ProcessEvent(REFRESH_BUTTON);
return true;
case SCAN_CODE_ENTER:
EventSeachWeb();
return true;
case SCAN_CODE_LEFT:
ProcessEvent(BACK_BUTTON);
return true;
case SCAN_CODE_RIGHT:
ProcessEvent(FORWARD_BUTTON);
return true;
case SCAN_CODE_KEY_W:
EventCloseActiveTab();
return true;
case SCAN_CODE_TAB:
EventActivateNextTab();
return true;
case SCAN_CODE_KEY_O: EventOpenDialog(); return true;
case SCAN_CODE_KEY_H: ProcessEvent(VIEW_HISTORY); return true;
case SCAN_CODE_KEY_U: EventViewSource(); return true;
case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return true;
case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return true;
case SCAN_CODE_KEY_J: ProcessEvent(DOWNLOAD_MANAGER); return true;
case SCAN_CODE_KEY_R: ProcessEvent(REFRESH_BUTTON); return true;
case SCAN_CODE_ENTER: EventSeachWeb(); return true;
case SCAN_CODE_LEFT: ProcessEvent(BACK_BUTTON); return true;
case SCAN_CODE_RIGHT: ProcessEvent(FORWARD_BUTTON); return true;
case SCAN_CODE_KEY_W: EventCloseActiveTab(); return true;
case SCAN_CODE_TAB: EventActivateNextTab(); return true;
default: return false;
}
return false;
}
 
void SetElementSizes()
462,7 → 447,7
EventUpdateBrowser();
return;
case CLEAR_CACHE:
pages_cache.clear();
cache.clear();
notify(#clear_cache_ok);
EventRefreshPage();
return;
603,9 → 588,9
and then halndle it in the propper way.
*/
 
if (pages_cache.has(#new_url)) {
if (cache.has(#new_url)) {
//CACHED PAGE
LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size);
LoadInternalPage(cache.current_buf, cache.current_size);
 
} else if (!strncmp(#new_url,"WebView:",8)) {
//INTERNAL PAGE
620,6 → 605,7
strcpy(#editURL, #new_url);
}
 
http_get_type = PAGE;
if (!strncmp(#new_url,"http:",5)) {
http.get(#new_url);
} else if (!strncmp(#new_url,"https://",8)) {
779,6 → 765,7
} else {
WB1.DrawPage();
}
//GetImg();
}
}
 
941,6 → 928,9
ESI = math.min(status_w/6, strlen(links.active_url));
WriteText(10, status_y, 0, sc.work_text, links.active_url);
}
if (http.transfer>0) && (http_get_type==IMG) {
//
}
DefineHiddenButton(status_w+20, status_y-3, 60, 12, CHANGE_ENCODING);
WriteTextCenter(status_w+20, status_y, 60, sc.work_text, WB1.cur_encoding*10+#charsets);
}
983,4 → 973,16
return 0;
}
 
dword GetImg()
{
while (WB1.page_img.next_url()) {
if (cache.has(WB1.page_img.current_url())) continue;
http_get_type = IMG;
http.get(WB1.page_img.current_url());
return;
}
DrawOmnibox();
WB1.DrawPage();
}
 
stop:
/programs/cmm/browser/cache.h
1,17 → 1,21
enum {
PAGE=1, IMG
};
 
struct PAGES_CACHE
struct _cache
{
dword current_page_buf;
dword current_page_size;
dword current_buf;
dword current_size;
collection url;
collection_int data;
collection_int size;
collection_int type;
void add();
bool has();
void clear();
} pages_cache=0;
} cache=0;
 
void PAGES_CACHE::add(dword _url, _data, _size)
void _cache::add(dword _url, _data, _size, _type)
{
dword data_pointer;
data_pointer = malloc(_size);
20,25 → 24,26
 
url.add(_url);
size.add(_size);
type.add(_type);
}
 
bool PAGES_CACHE::has(dword _link)
bool _cache::has(dword _link)
{
int pos;
pos = url.get_pos_by_name(_link);
if (pos != -1) {
current_page_buf = data.get(pos);
current_page_size = size.get(pos);
current_buf = data.get(pos);
current_size = size.get(pos);
return true;
}
return false;
}
 
void PAGES_CACHE::clear()
void _cache::clear()
{
url.drop();
data.drop();
size.drop();
current_page_buf = NULL;
current_page_size = NULL;
current_buf = NULL;
current_size = NULL;
}
/programs/cmm/browser/history.h
30,7 → 30,7
free(history_pointer);
history_pointer = malloc(history.items.data_size+256);
strcat(history_pointer, HISTORY_HEADER);
for (i=0; i<history.items.count-1; i++)
for (i=0; i<history.items.count-1; i++) //if (cache.type.get(i) == PAGE)
{
strcat(history_pointer, "\t<a href='");
strcat(history_pointer, history.items.get(i));
38,14 → 38,14
strcat(history_pointer, history.items.get(i));
strcat(history_pointer, "</a><br>");
}
/*
 
strcat(history_pointer, "<br><b>Cached images</b><br>");
for (i=1; i<ImgCache.pics_count; i++)
for (i=1; i<cache.url.count; i++) if (cache.type.get(i) == IMG)
{
strcat(history_pointer, "<a href='");
strcat(history_pointer, #pics[i].path);
strcat(history_pointer, cache.url.get(i));
strcat(history_pointer, "'>");
strcat(history_pointer, #pics[i].path);
strcat(history_pointer, cache.url.get(i));
strcat(history_pointer, "</a><br>");
// strcat(history_pointer, "<img src='");
53,7 → 53,7
// strcat(history_pointer, "'><br>");
// strcat(history_pointer, #pics[i].path);
}
*/
 
strcat(history_pointer, "</body></html>");
LoadInternalPage(history_pointer, strlen(history_pointer));
}
/programs/cmm/browser/texts.h
1,5 → 1,3
char version[]="WebView 2.61b";
 
#ifdef LANG_RUS
char buidin_page_error[] = FROM "buidin_pages\\page_not_found_ru.htm""\0";
char buidin_page_home[] = FROM "buidin_pages\\homepage_ru.htm""\0";