Subversion Repositories Kolibri OS

Rev

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