Subversion Repositories Kolibri OS

Rev

Rev 7764 | Rev 7767 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //Copyright 2007-2020 by Veliant & Leency
  2. //Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
  3.  
  4. #ifndef AUTOBUILD
  5.         #include "lang.h--"
  6. #endif
  7.  
  8. //libraries
  9. #define MEMSIZE 1024 * 850
  10. #include "..\lib\gui.h"
  11. #include "..\lib\draw_buf.h"
  12. #include "..\lib\list_box.h"
  13. #include "..\lib\cursor.h"
  14. #include "..\lib\collection.h"
  15. #include "..\lib\random.h"
  16. #include "..\lib\clipboard.h"
  17.  
  18. // *.obj libraries
  19. #include "..\lib\obj\box_lib.h"
  20. #include "..\lib\obj\libio.h"
  21. #include "..\lib\obj\libimg.h"
  22. #include "..\lib\obj\http.h"
  23. #include "..\lib\obj\iconv.h"
  24. #include "..\lib\obj\proc_lib.h"
  25.  
  26. //useful patterns
  27. #include "..\lib\patterns\history.h"
  28. #include "..\lib\patterns\http_downloader.h"
  29. #include "..\lib\patterns\simple_open_dialog.h"
  30. #include "..\lib\patterns\toolbar_button.h"
  31.  
  32. #include "show_src.h"
  33. bool download_and_exit = false;
  34. #include "download_manager.h"
  35. _history history;
  36. #include "history.h"
  37. bool debug_mode = false;
  38. #include "..\TWB\TWB.c" //HTML Parser, a core component
  39. #include "texts.h"
  40. #include "cache.h"
  41.  
  42. TWebBrowser WB1;
  43.  
  44. #define URL_SIZE 4000
  45.  
  46. #define PADDING 9
  47. #define SKIN_Y 24
  48. #define TSZE 25
  49. dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
  50. dword STATUSBAR_H = 15;
  51.  
  52. int action_buf;
  53.  
  54. _http http = 0;
  55.  
  56. bool source_mode = false;
  57.  
  58. progress_bar wv_progress_bar;
  59. char stak[4096];
  60. proc_info Form;
  61.  
  62. enum {
  63.         ENCODINGS=900,
  64.         BACK_BUTTON=1000,
  65.         FORWARD_BUTTON,
  66.         REFRESH_BUTTON,
  67.         GOTOURL_BUTTON,
  68.         CHANGE_ENCODING,
  69.         SANDWICH_BUTTON,
  70.         VIEW_SOURCE,
  71.         EDIT_SOURCE,
  72.         OPEN_FILE,
  73.         NEW_WINDOW,
  74.         VIEW_HISTORY,
  75.         DOWNLOAD_MANAGER,
  76.         UPDATE_BROWSER,
  77.         COPY_LINK_URL,
  78.         DOWNLOAD_LINK_CONTENTS,
  79. };
  80.  
  81. char default_dir[] = "/rd/1";
  82. od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
  83.  
  84. char editURL[URL_SIZE+1];
  85. edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff,
  86.         0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19};
  87.  
  88.  
  89. void LoadLibraries()
  90. {
  91.         load_dll(boxlib,    #box_lib_init,0);
  92.         load_dll(libio,     #libio_init,1);
  93.         load_dll(libimg,    #libimg_init,1);
  94.         load_dll(libHTTP,   #http_lib_init,1);
  95.         load_dll(iconv_lib, #iconv_open,0);
  96.         load_dll(Proc_lib,  #OpenDialog_init,0);
  97.         OpenDialog_init stdcall (#o_dialog);   
  98. }
  99.  
  100. void HandleParam()
  101. {
  102.         if (param) {
  103.                 if (!strncmp(#param, "-download_and_exit ", 19)) {
  104.                         download_and_exit = true;
  105.                         strcpy(#downloader_edit, #param+19);
  106.                         Downloader();
  107.                         ExitProcess();
  108.                 } else if (!strncmp(#param, "-download ", 10)) {
  109.                         strcpy(#downloader_edit, #param+10);
  110.                         //CreateThread(#Downloader,#downloader_stak+4092);
  111.                         Downloader();
  112.                         ExitProcess();
  113.                 } else if (!strncmp(#param, "-source ", 8)) {
  114.                         source_mode = true;
  115.                         history.add(#param + 8);
  116.                 } else {
  117.                         history.add(#param);
  118.                 }
  119.         } else {
  120.                 history.add(URL_SERVICE_HOMEPAGE);
  121.         }
  122. }
  123.  
  124. void main()
  125. {
  126.         int i, btn, redirect_count=0;
  127.         LoadLibraries();
  128.         CreateDir("/tmp0/1/Downloads");
  129.         //CreateDir("/tmp0/1/WebView_Cache");
  130.         Libimg_LoadImage(#skin, "/sys/toolbar.png");
  131.         HandleParam();
  132.         skin.h = 26;
  133.         WB1.list.SetFont(8, 14, 10011000b);
  134.         WB1.list.no_selection = true;
  135.         WB1.custom_encoding = -1;
  136.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
  137.         loop() switch(WaitEvent())
  138.         {
  139.                 case evMouse:
  140.                         edit_box_mouse stdcall (#address_box);
  141.                         mouse.get();
  142.                         if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first))
  143.                         && (mouse.pkm) && (mouse.up) {
  144.                                 if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
  145.                                 break;
  146.                         }
  147.                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  148.                         scrollbar_v_mouse (#scroll_wv);
  149.                         if (WB1.list.first != scroll_wv.position)
  150.                         {
  151.                                 WB1.list.first = scroll_wv.position;
  152.                                 WB1.DrawPage();
  153.                                 break;
  154.                         }
  155.                         if (mouse.up) && (! address_box.flags & ed_focus) && (address_box.flags & ed_shift_bac)
  156.                         {
  157.                                 DrawOmnibox(); //reset text selection
  158.                         }
  159.                         break;
  160.  
  161.                 case evButton:
  162.                         btn = GetButtonID();
  163.                         if (1==btn) ExitProcess(); else ProcessEvent(btn);
  164.                         break;
  165.  
  166.                 case evKey:
  167.                         GetKeys();
  168.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  169.                                 if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
  170.                                 if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;}
  171.                                 if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;}
  172.                                 if (key_scancode == SCAN_CODE_KEY_T)
  173.                                 || (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;}
  174.                                 if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;}
  175.                                 if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;}
  176.                                 if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;}
  177.                                 if (key_scancode == SCAN_CODE_LEFT)  {ProcessEvent(BACK_BUTTON);break;}
  178.                                 if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;}
  179.                                 if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;}
  180.                         }
  181.                        
  182.                         if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
  183.                        
  184.                         if (address_box.flags & ed_focus)  
  185.                         {
  186.                                 if (key_scancode == SCAN_CODE_ENTER) {
  187.                                         ProcessEvent(key_scancode);
  188.                                 }
  189.                                 else {
  190.                                         EAX = key_editbox;
  191.                                         edit_box_key stdcall(#address_box);
  192.                                 }
  193.                         }
  194.                         else
  195.                         {
  196.                                 #define KEY_SCROLL_N 11
  197.                                 if (SCAN_CODE_UP   == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
  198.                                 if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
  199.                                 if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
  200.                                 if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  201.                                 else ProcessEvent(key_scancode);
  202.                         }
  203.                         break;
  204.  
  205.                 case evReDraw:
  206.                         if (menu.cur_y) {
  207.                                 ProcessEvent(menu.cur_y);
  208.                                 menu.cur_y = 0;
  209.                         }
  210.                         DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),
  211.                                 GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
  212.                         GetProcessInfo(#Form, SelfInfo);
  213.                         system.color.get();
  214.                         if (Form.status_window>2) break;
  215.                         if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
  216.                         if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
  217.                         draw_window();
  218.                         break;
  219.                        
  220.                 case evNetwork:
  221.                         if (http.transfer <= 0) break;
  222.                         http.receive();
  223.                         EventUpdateProgressBar();
  224.                         if (http.receive_result != 0) break;
  225.                         if (http.status_code >= 300) && (http.status_code < 400)
  226.                         {
  227.                                 // Handle redirects
  228.                                 if (redirect_count<=5) {
  229.                                         redirect_count++;
  230.                                         http.handle_redirect();
  231.                                         http.free();
  232.                                         GetAbsoluteURL(#http.redirect_url, history.current());
  233.                                         history.back();
  234.                                         OpenPage(#http.redirect_url);
  235.                                 } else {
  236.                                         notify("'Too many redirects.' -E");
  237.                                         StopLoading();
  238.                                 }
  239.                         } else {
  240.                                 // Loading the page is complete, free resources
  241.                                 redirect_count = 0;
  242.                                 http.free();
  243.                                 pages_cache.add(history.current(), http.content_pointer, http.content_received);
  244.                                 LoadInternalPage(http.content_pointer, http.content_received);
  245.                         }
  246.         }
  247. }
  248.  
  249. void SetElementSizes()
  250. {
  251.         address_box.width = Form.cwidth - address_box.left - 52 - 16;
  252.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
  253.                 Form.cheight - TOOLBAR_H - STATUSBAR_H, BASIC_LINE_H);
  254.         WB1.list.wheel_size = 7 * BASIC_LINE_H;
  255.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
  256.         WB1.list.visible = WB1.list.h;
  257. }
  258.  
  259.  
  260. void draw_window()
  261. {
  262.         int i;
  263.         SetElementSizes();
  264.  
  265.         DrawBar(0,0, Form.cwidth,PADDING, system.color.work);
  266.         DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work);
  267.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, system.color.work_dark);
  268.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
  269.         DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
  270.         DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
  271.  
  272.         DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30);
  273.         DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31);
  274.         DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1);
  275.         for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph);
  276.  
  277.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph);
  278.  
  279.         DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x,
  280.                 WB1.list.h-1, scroll_wv.bckg_col);
  281.  
  282.         if (WB1.list.w!=WB1.DrawBuf.bufw) {
  283.                 WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
  284.                 if (!strncmp(history.current(),"http",4)) {
  285.                         //nihuya ne izyashnoe reshenie, no pust' poka butet tak
  286.                         i=source_mode;
  287.                         LoadInternalPage(#loading_text, sizeof(loading_text));
  288.                         source_mode=i;
  289.                 }
  290.                 OpenPage(history.current());
  291.         } else {
  292.                 WB1.DrawPage();
  293.                 DrawOmnibox();
  294.         }
  295.         DrawProgress();
  296.         DrawStatusBar(NULL);
  297. }
  298.  
  299. void EventChangeEncodingAndLoadPage(int _new_encoding)
  300. {
  301.         dword newbuf, newsize;
  302.         WB1.custom_encoding = _new_encoding;
  303.         newsize = strlen(WB1.o_bufpointer);
  304.         newbuf = malloc(newsize);
  305.         memmov(newbuf, WB1.o_bufpointer, newsize);
  306.         LoadInternalPage(newbuf, newsize);
  307.         free(newbuf);
  308. }
  309.  
  310.  
  311. void ProcessEvent(dword id__)
  312. {
  313.         switch (id__)
  314.         {
  315.                 case ENCODINGS...ENCODINGS+6:
  316.                         EventChangeEncodingAndLoadPage(id__-ENCODINGS);
  317.                         return;
  318.                 case NEW_WINDOW:
  319.                         RunProgram(#program_path, NULL);
  320.                         return;
  321.                 case SCAN_CODE_BS:
  322.                 case BACK_BUTTON:
  323.                         if (history.back()) {
  324.                                 OpenPage(history.current());
  325.                         }
  326.                         return;
  327.                 case FORWARD_BUTTON:
  328.                         if (history.forward()) {
  329.                                 OpenPage(history.current());
  330.                         }
  331.                         return;
  332.                 case GOTOURL_BUTTON:
  333.                 case SCAN_CODE_ENTER:
  334.                         EventSubmitOmnibox();
  335.                         return;
  336.                 case REFRESH_BUTTON:
  337.                         if (http.transfer > 0) {
  338.                                 StopLoading();
  339.                                 draw_window();
  340.                         } else {
  341.                                 OpenPage(history.current());
  342.                         }
  343.                         return;
  344.                 case CHANGE_ENCODING:
  345.                         EventShowEncodingsList(Form.cwidth - 150, status_text.start_y-117);
  346.                         return;
  347.                 case SANDWICH_BUTTON:
  348.                         EventShowMainMenu(Form.cwidth - 215, TOOLBAR_H-6);
  349.                         return;
  350.                 case VIEW_SOURCE:
  351.                         EventViewSource();
  352.                         break;
  353.                 case EDIT_SOURCE:
  354.                         if (check_is_the_adress_local(history.current())) {
  355.                                 RunProgram("/rd/1/tinypad", history.current());
  356.                         } else {
  357.                                 CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
  358.                                 if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
  359.                         }
  360.                         return;
  361.                 case VIEW_HISTORY:
  362.                         OpenPage(URL_SERVICE_HISTORY);
  363.                         return;
  364.                 case DOWNLOAD_MANAGER:
  365.                         if (!downloader_opened) {
  366.                                 downloader_edit = NULL;
  367.                                 CreateThread(#Downloader,#downloader_stak+4092);
  368.                         }
  369.                         return;
  370.                 case UPDATE_BROWSER:
  371.                         EventUpdateBrowser();
  372.                         return;
  373.                 case COPY_LINK_URL:
  374.                         Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
  375.                         notify("'URL copied to clipboard'O");
  376.                         return;
  377.                 case DOWNLOAD_LINK_CONTENTS:
  378.                         if (!downloader_opened) {
  379.                                 strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
  380.                                 CreateThread(#Downloader,#downloader_stak+4092);
  381.                         }
  382.                         return;
  383.                 case OPEN_FILE:
  384.                         EventOpenDialog();
  385.                         return;
  386.                 case SCAN_CODE_F12:
  387.                         debug_mode ^= 1;
  388.                         if (debug_mode) notify("'Debug mode ON'-I");
  389.                         else notify("'Debug mode OFF'-I");
  390.                         return;
  391.         }
  392. }
  393.  
  394. void StopLoading()
  395. {
  396.         if (http.transfer)
  397.         {
  398.                 EAX = http.transfer;
  399.                 EAX = EAX.http_msg.content_ptr;         // get pointer to data
  400.                 $push   EAX                                                     // save it on the stack
  401.                 http_free stdcall (http.transfer);      // abort connection
  402.                 $pop    EAX                                                    
  403.                 free(EAX);                                              // free data
  404.                 http.transfer=0;
  405.                 pause(10);
  406.         }
  407.         wv_progress_bar.value = 0;
  408.         DrawOmnibox();
  409. }
  410.  
  411. //rewrite into
  412. //bool strrpl(dword dst, from, into, dst_len);
  413. bool ReplaceSpaceInUrl(dword url, size) {
  414.         unsigned int i, j;
  415.         bool was_changed=false;
  416.         for (i=url+size-3; i>url; i--)
  417.         {
  418.                 if (ESBYTE[i]!=' ') continue;
  419.                 for (j=url+size-3; j>=i; j--) {
  420.                         ESBYTE[j+3]=ESBYTE[j+2];
  421.                         ESBYTE[j+2]=ESBYTE[j+1];
  422.                         ESBYTE[j+1]=ESBYTE[j];
  423.                 }
  424.                 ESBYTE[i] = '%';
  425.                 ESBYTE[i+1] = '2';
  426.                 ESBYTE[i+2] = '0';
  427.                 was_changed = true;
  428.         }
  429.         return was_changed;
  430. }
  431.  
  432. bool GetLocalFileData(dword _path)
  433. {
  434.         dword data, size;
  435.         file_size stdcall (_path);
  436.         if (!EBX) {
  437.                 return false;
  438.         } else {
  439.                 size = EBX;
  440.                 data = malloc(size);
  441.                 ReadFile(0, size, data, _path);
  442.                 LoadInternalPage(data, size);
  443.                 free(data);
  444.                 return true;
  445.         }
  446. }
  447.  
  448. void OpenPage(dword _open_URL)
  449. {
  450.         char new_url[URL_SIZE+1];
  451.  
  452.         StopLoading();
  453.  
  454.         strcpy(#editURL, _open_URL);
  455.         address_box.flags=0;
  456.         DrawOmnibox();
  457.  
  458.         strncpy(#new_url, _open_URL, URL_SIZE);
  459.  
  460.         //Exclude # from the URL to the load page
  461.         //We will bring it back when we get the buffer
  462.         if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url);
  463.  
  464.         history.add(#new_url);
  465.  
  466.         if (pages_cache.has(#new_url)) {
  467.                 //CACHED PAGE
  468.                 LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size);
  469.  
  470.         } else if (!strncmp(#new_url,"WebView:",8)) {
  471.                 //INTERNAL PAGE
  472.                 if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
  473.                 else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
  474.                 else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
  475.                 else LoadInternalPage(#page_not_found, sizeof(page_not_found));
  476.                
  477.         } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
  478.                 //WEB PAGE
  479.                 if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
  480.                         strcpy(#editURL, #new_url);
  481.                 }
  482.  
  483.                 if (!strncmp(#new_url,"http:",5)) {
  484.                         http.get(#new_url);
  485.                 } else if (!strncmp(#new_url,"https://",8)) {
  486.                         strcpy(#new_url, "http://gate.aspero.pro/?site=");
  487.                         strncat(#new_url, _open_URL, URL_SIZE);
  488.                         http.get(#new_url);
  489.                 }
  490.  
  491.                 DrawOmnibox();
  492.  
  493.                 if (!http.transfer) {
  494.                         StopLoading();
  495.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  496.                 }
  497.         } else {
  498.                 //LOCAL PAGE
  499.                 if (!GetLocalFileData(#new_url)) {
  500.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  501.                 }
  502.         }
  503. }
  504.  
  505. void EventClickLink(dword _click_URL)
  506. {
  507.         char new_url[URL_SIZE+1];
  508.  
  509.         if (open_new_window) {
  510.                 strcpy(#new_url, _click_URL);
  511.                 GetAbsoluteURL(#new_url, history.current());
  512.                 RunProgram(#program_path, #new_url);
  513.                 return;
  514.         }
  515.  
  516.         if (ESBYTE[_click_URL]=='#') {
  517.                 if (anchors.get_pos_by_name(_click_URL+1)!=-1) {
  518.                         WB1.list.first = anchors.get_pos_by_name(_click_URL+1);
  519.                         WB1.list.CheckDoesValuesOkey();
  520.                 }
  521.                 strcpy(#editURL, history.current());
  522.                 strcat(#editURL, _click_URL);
  523.                 DrawOmnibox();
  524.                 WB1.DrawPage();
  525.                 return;
  526.         }
  527.  
  528.         if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) {
  529.                 notify(_click_URL);
  530.                 return;
  531.         }
  532.  
  533.         if (http.transfer > 0) {
  534.                 StopLoading();
  535.                 history.back();
  536.         }
  537.  
  538.         strcpy(#new_url, _click_URL);
  539.         GetAbsoluteURL(#new_url, history.current());
  540.  
  541.         if (strrchr(#new_url, '#')!=0) {
  542.                 anchors.take_anchor_from(#new_url);
  543.                 OpenPage(#new_url);
  544.                 return;
  545.         }
  546.  
  547.         if (!strncmp(#new_url,"WebView:",8)) {
  548.                 OpenPage(#new_url);
  549.                 return;
  550.         }
  551.  
  552.         if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
  553.         {
  554.                 if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
  555.                 {      
  556.                         if (strchr(#new_url, '|')) {
  557.                                 ESBYTE[strchr(#new_url, '|')] = NULL;
  558.                                 RunProgram(#new_url, strlen(#new_url)+1+#new_url);
  559.                         } else {
  560.                                 RunProgram("/sys/@open", #new_url);
  561.                         }
  562.                         return;
  563.                 }
  564.         } else {
  565.                 if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true)
  566.                 || (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true)
  567.                 || (UrlExtIs(#new_url,".7z")==true) {
  568.                         if (!downloader_opened) {
  569.                                 strcpy(#downloader_edit, #new_url);
  570.                                 CreateThread(#Downloader,#downloader_stak+4092);
  571.                         }
  572.                         else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
  573.                         return;
  574.                 }
  575.         }
  576.         OpenPage(#new_url);
  577. }
  578.  
  579. void EventSubmitOmnibox()
  580. {
  581.         char new_url[URL_SIZE+1];
  582.         if (!editURL[0]) return;
  583.         if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
  584.         || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
  585.                 OpenPage(#editURL);
  586.         } else {
  587.                 strcpy(#new_url, "http://");
  588.                 strncat(#new_url, #editURL, sizeof(new_url)-1);
  589.                 OpenPage(#new_url);
  590.         }
  591. }
  592.  
  593. void LoadInternalPage(dword _bufdata, _in_bufsize){
  594.         if (!_bufdata) || (!_in_bufsize) {
  595.                 LoadInternalPage(#page_not_found, sizeof(page_not_found));
  596.         } else {
  597.                 WB1.list.first = 0; //scroll page to the top
  598.                 DrawOmnibox();
  599.                 if(!strrchr(#editURL, '#')) {
  600.                         strcat(#editURL, #anchors.current);
  601.                         DrawOmnibox();
  602.                 }
  603.                 WB1.ParseHtml(_bufdata, _in_bufsize);
  604.                 DrawStatusBar(NULL);
  605.                 if (source_mode) {
  606.                         source_mode = false;
  607.                         ShowSource(WB1.bufpointer, _in_bufsize);
  608.                 } else {
  609.                         WB1.DrawPage();                
  610.                 }
  611.         }
  612. }
  613.  
  614. byte UrlExtIs(dword base, ext)
  615. {
  616.         if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true;
  617.         return false;
  618. }
  619.  
  620. void DrawProgress()
  621. {
  622.         dword persent;
  623.         if (http.transfer == 0) return;
  624.         if (wv_progress_bar.max) {
  625.                 persent = wv_progress_bar.value*100/wv_progress_bar.max;
  626.         } else {
  627.                 persent = 10;
  628.         }
  629.         DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
  630. }
  631.  
  632. void EventShowPageMenu(dword _left, _top)
  633. {
  634.         menu.selected = 0;
  635.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
  636. }
  637.  
  638. void EventShowEncodingsList(dword _left, _top)
  639. {
  640.         menu.selected = WB1.cur_encoding + 1;
  641.         menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 100,
  642.                 "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", ENCODINGS);
  643. }
  644.  
  645. void EventShowMainMenu(dword _left, _top)
  646. {
  647.         menu.selected = 0;
  648.         menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 140, #main_menu, OPEN_FILE);
  649. }
  650.  
  651. void EventShowLinkMenu(dword _left, _top)
  652. {
  653.         menu.selected = 0;
  654.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
  655. }
  656.  
  657. void EventUpdateProgressBar()
  658. {
  659.         wv_progress_bar.max = http.content_length;
  660.         if (wv_progress_bar.value != http.content_received)
  661.         {
  662.                 wv_progress_bar.value = http.content_received; 
  663.                 DrawProgress();
  664.         }
  665. }
  666.  
  667. void EventSeachWeb()
  668. {
  669.         char new_url[URL_SIZE+1];
  670.         replace_char(#editURL, ' ', '_', URL_SIZE);
  671.         strcpy(#new_url, "https://www.google.com/search?q=");
  672.         strncat(#new_url, #editURL, URL_SIZE);
  673.         OpenPage(#new_url);
  674. }
  675.  
  676. void EventOpenDialog()
  677. {
  678.         OpenDialog_start stdcall (#o_dialog);
  679.         if (o_dialog.status) {
  680.                 OpenPage(#openfile_path);
  681.         }
  682. }
  683.  
  684. void EventViewSource()
  685. {
  686.         char source_view_param[URL_SIZE+1];
  687.         strcpy(#source_view_param, "-source ");
  688.         strncat(#source_view_param, history.current(), URL_SIZE);
  689.         RunProgram(#program_path, #source_view_param);
  690. }
  691.  
  692. dword GetFileSize(dword _path)
  693. {
  694.         BDVK bdvk;
  695.         if (GetFileInfo(_path, #bdvk)!=0) {
  696.                 return 0;
  697.         } else {
  698.                 return bdvk.sizelo;
  699.         }
  700. }
  701.  
  702. void EventUpdateBrowser()
  703. {
  704.         dword downloader_id, slot_n;
  705.         dword current_size;
  706.         dword new_size;
  707.         int error;
  708.  
  709.         draw_window();
  710.  
  711.         downloader_id = RunProgram(#program_path, #update_param);
  712.         do {
  713.                 slot_n = GetProcessSlot(downloader_id);
  714.                 pause(10);
  715.         } while (slot_n!=0);
  716.  
  717.         current_size = GetFileSize(#program_path);
  718.         new_size = GetFileSize("/tmp0/1/Downloads/WebView.com");
  719.  
  720.         if (!new_size) || (new_size<5000) {
  721.                 notify(#update_download_error);
  722.                 return;
  723.         }
  724.  
  725.         if (current_size == new_size) {
  726.                 notify(#update_is_current);
  727.                 return;
  728.         }
  729.  
  730.         if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) {
  731.                 notify(#update_can_not_copy);
  732.         } else {
  733.                 notify(#update_ok);
  734.                 RunProgram(#program_path, history.current());
  735.                 ExitProcess();
  736.         }
  737. }
  738.  
  739. void DrawStatusBar(dword _status_text)
  740. {
  741.         status_text.font_color = system.color.work_text;
  742.         status_text.start_x = 10;
  743.         status_text.start_y = Form.cheight - STATUSBAR_H + 4;
  744.         status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70;
  745.         //DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work);
  746.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work);
  747.         if (_status_text) {
  748.                 status_text.text_pointer = _status_text;
  749.                 PathShow_prepare stdcall(#status_text);
  750.                 PathShow_draw stdcall(#status_text);           
  751.         }
  752.         DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3,
  753.                 60, 12, CHANGE_ENCODING);
  754.         WriteTextCenter(status_text.start_x+status_text.area_size_x+10,
  755.                 status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets);
  756. }
  757.  
  758. void DrawOmnibox()
  759. {
  760.         int skin_x_offset;
  761.        
  762.         DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph,
  763.                 system.color.work_graph, system.color.work_graph, system.color.work_dark);
  764.         DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);
  765.         DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color);
  766.         DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color);
  767.  
  768.         if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
  769.         EditBox_UpdateText(#address_box, address_box.flags);
  770.         edit_box_draw stdcall(#address_box);
  771.         if (http.transfer > 0) skin_x_offset = 85; else skin_x_offset = 68;
  772.         img_draw stdcall(skin.image, address_box.left+address_box.width+1,
  773.                 address_box.top-1, 16, skin.h-3, skin_x_offset, SKIN_Y+2);
  774.         DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, skin.h-3, REFRESH_BUTTON);
  775.  
  776.         DrawProgress();
  777. }
  778.  
  779.  
  780. stop: