Subversion Repositories Kolibri OS

Rev

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

  1. //HTML Viewer in C--
  2. //Copyright 2007-2020 by Veliant & Leency
  3. //Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
  4.  
  5. #ifndef AUTOBUILD
  6.         #include "lang.h--"
  7. #endif
  8.  
  9. //libraries
  10. #define MEMSIZE 1024 * 850
  11. #include "..\lib\gui.h"
  12. #include "..\lib\draw_buf.h"
  13. #include "..\lib\list_box.h"
  14. #include "..\lib\cursor.h"
  15. #include "..\lib\collection.h"
  16. #include "..\lib\random.h"
  17. #include "..\lib\clipboard.h"
  18.  
  19. // *.obj libraries
  20. #include "..\lib\obj\box_lib.h"
  21. #include "..\lib\obj\libio.h"
  22. #include "..\lib\obj\libimg.h"
  23. #include "..\lib\obj\http.h"
  24. #include "..\lib\obj\iconv.h"
  25. #include "..\lib\obj\proc_lib.h"
  26.  
  27. //useful patterns
  28. #include "..\lib\patterns\history.h"
  29. #include "..\lib\patterns\http_downloader.h"
  30. #include "..\lib\patterns\simple_open_dialog.h"
  31.  
  32. #include "show_src.h"
  33. _http http = {0, 0, 0, 0, 0, 0, 0};
  34. #include "download_manager.h"
  35. _history history;
  36. #include "history.h"
  37.  
  38. bool debug_mode = false;
  39. dword col_bg = 0xE3E2E2;
  40. dword panel_color  = 0xE3E2E2;
  41. dword border_color = 0x787878;
  42. #include "..\TWB\TWB.c"
  43.  
  44. #ifdef LANG_RUS
  45. char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 2.0 beta4";
  46. char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
  47. char homepage[] = FROM "html\\homepage_ru.htm""\0";
  48. char help[] = FROM "html\\help_ru.htm""\0";
  49. char accept_language[]= "Accept-Language: ru\n";
  50. char rmb_menu[] =
  51. "®á¬®âà¥âì ¨á室­¨ª
  52. ¥¤ ªâ¨à®¢ âì ¨á室­¨ª
  53. ˆáâ®à¨ï
  54. Œ¥­¥¤¦¥à § £à㧮ª";
  55. char link_menu[] =
  56. "Š®¯¨à®¢ âì áá뫪ã
  57. ‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
  58. #else
  59. char version[]="Text-based Browser 2.0 beta4";
  60. char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
  61. char homepage[] = FROM "html\\homepage_en.htm""\0";
  62. char help[] = FROM "html\\help_en.htm""\0";
  63. char accept_language[]= "Accept-Language: en\n";
  64. char rmb_menu[] =
  65. "View source
  66. Edit source
  67. History
  68. Download Manager";
  69. char link_menu[] =
  70. "Copy link
  71. Download link contents";
  72. #endif
  73.  
  74. #define URL_SIZE 4000
  75.  
  76. #define URL_SERVICE_HISTORY "WebView:history"
  77. #define URL_SERVICE_HOMEPAGE "WebView:home"
  78. #define URL_SERVICE_HELP "WebView:help"
  79.  
  80. #define TOOLBAR_GAPS 10
  81. dword TOOLBAR_H = 40;
  82. dword STATUSBAR_H = 15;
  83.  
  84. int action_buf;
  85.  
  86. bool source_mode = false;
  87.  
  88. progress_bar wv_progress_bar;
  89. char stak[4096];
  90. proc_info Form;
  91.  
  92. enum {
  93.         BACK_BUTTON=1000,
  94.         FORWARD_BUTTON,
  95.         REFRESH_BUTTON,
  96.         GOTOURL_BUTTON,
  97.         SANDWICH_BUTTON,
  98.         VIEW_SOURCE,
  99.         EDIT_SOURCE,
  100.         VIEW_HISTORY,
  101.         DOWNLOAD_MANAGER,
  102.         COPY_LINK_URL,
  103.         DOWNLOAD_LINK_CONTENTS,
  104. };
  105.  
  106. char default_dir[] = "/rd/1";
  107. od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
  108.  
  109. char editURL[URL_SIZE+1];
  110. edit_box address_box = {NULL,TOOLBAR_GAPS+TOOLBAR_GAPS+51,10,0xffffff,0x94AECE,0xffffff,
  111.         0xffffff,0x10000000,URL_SIZE-2,#editURL,0,NULL,19,19};
  112.  
  113. #define SKIN_Y 24
  114.  
  115. void LoadLibraries()
  116. {
  117.         load_dll(boxlib,    #box_lib_init,0);
  118.         load_dll(libio,     #libio_init,1);
  119.         load_dll(libimg,    #libimg_init,1);
  120.         load_dll(libHTTP,   #http_lib_init,1);
  121.         load_dll(iconv_lib, #iconv_open,0);
  122.         load_dll(Proc_lib,  #OpenDialog_init,0);
  123.         OpenDialog_init stdcall (#o_dialog);   
  124. }
  125.  
  126. void HandleParam()
  127. {
  128.         if (param) {
  129.                 if (!strncmp(#param, "-d ", 3)) {
  130.                         strcpy(#downloader_edit, #param+3);
  131.                         CreateThread(#Downloader,#downloader_stak+4092);
  132.                         ExitProcess();
  133.                 } else if (!strncmp(#param, "-s ", 3)) {
  134.                         source_mode = true;
  135.                         history.add(#param + 3);
  136.                 } else {
  137.                         history.add(#param);
  138.                 }
  139.         } else {
  140.                 history.add(URL_SERVICE_HOMEPAGE);
  141.         }
  142. }
  143.  
  144. void main()
  145. {
  146.         int redirect_count = 0;
  147.         int i;
  148.         LoadLibraries();
  149.         CreateDir("/tmp0/1/downloads");
  150.         Libimg_LoadImage(#skin, "/sys/toolbar.png");
  151.         HandleParam();
  152.         skin.h = 26;
  153.         WB1.list.SetFont(8, 14, 10011000b);
  154.         WB1.list.no_selection = true;
  155.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
  156.         loop() switch(WaitEvent())
  157.         {
  158.                 case evMouse:
  159.                         edit_box_mouse stdcall (#address_box);
  160.                         mouse.get();
  161.                         if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first))
  162.                         && (mouse.pkm) && (mouse.up) {
  163.                                 if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
  164.                                 break;
  165.                         }
  166.                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  167.                         scrollbar_v_mouse (#scroll_wv);
  168.                         if (WB1.list.first != scroll_wv.position)
  169.                         {
  170.                                 WB1.list.first = scroll_wv.position;
  171.                                 WB1.DrawPage();
  172.                                 break;
  173.                         }
  174.                         break;
  175.  
  176.                 case evButton:
  177.                         ProcessEvent(GetButtonID());
  178.                         break;
  179.  
  180.                 case evKey:
  181.                         GetKeys();
  182.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  183.                                 if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
  184.                                 if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;}
  185.                                 if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;}
  186.                                 if (key_scancode == SCAN_CODE_KEY_T)
  187.                                 || (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;}
  188.                                 if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;}
  189.                                 if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;}
  190.                                 if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;}
  191.                                 if (key_scancode == SCAN_CODE_LEFT)  {ProcessEvent(BACK_BUTTON);break;}
  192.                                 if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;}
  193.                                 if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;}
  194.                         }
  195.                        
  196.                         if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
  197.                        
  198.                         if (address_box.flags & ed_focus)  
  199.                         {
  200.                                 if (key_scancode == SCAN_CODE_ENTER) {
  201.                                         ProcessEvent(key_scancode);
  202.                                 }
  203.                                 else {
  204.                                         EAX = key_editbox;
  205.                                         edit_box_key stdcall(#address_box);
  206.                                 }
  207.                         }
  208.                         else
  209.                         {
  210.                                 #define KEY_SCROLL_N 11
  211.                                 if (SCAN_CODE_UP   == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
  212.                                 if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
  213.                                 if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
  214.                                 if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  215.                                 else ProcessEvent(key_scancode);
  216.                         }
  217.                         break;
  218.  
  219.                 case evReDraw:
  220.                         if (menu.cur_y) {
  221.                                 ProcessEvent(menu.cur_y);
  222.                                 menu.cur_y = 0;
  223.                         }
  224.                         DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),
  225.                                 GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
  226.                         GetProcessInfo(#Form, SelfInfo);
  227.                         system.color.get();
  228.                         col_bg = system.color.work;
  229.                         if (Form.status_window>2) { DrawTitle(#header); break; }
  230.                         if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
  231.                         if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
  232.                         draw_window();
  233.                         break;
  234.                        
  235.                 case evNetwork:
  236.                         if (http.transfer > 0) {
  237.                                 http.receive();
  238.                                 EventUpdateProgressBar();
  239.                                 if (http.receive_result == 0) {
  240.                                         // Handle redirects
  241.                                         if (http.status_code >= 300) && (http.status_code < 400)
  242.                                         {
  243.                                                 redirect_count++;
  244.                                                 if (redirect_count>5)
  245.                                                 {
  246.                                                         notify("'Too many redirects.' -E");
  247.                                                         StopLoading();
  248.                                                 }
  249.                                                 else
  250.                                                 {
  251.                                                         http.handle_redirect();
  252.                                                         http.free();
  253.                                                         GetAbsoluteURL(#http.redirect_url, history.current());
  254.                                                         debug("Redirect: "); debugln(#http.redirect_url);
  255.                                                         history.back();
  256.                                                         OpenPage(#http.redirect_url);
  257.                                                 }
  258.                                                 break;
  259.                                         }
  260.                                         redirect_count = 0;
  261.                                         // Loading the page is complete, free resources
  262.                                         http.free();
  263.                                         LoadInternalPage(http.content_pointer, http.content_received);
  264.                                 }
  265.                         }
  266.         }
  267. }
  268.  
  269. void SetElementSizes()
  270. {
  271.         address_box.top = TOOLBAR_H/2-10;
  272.         basic_line_h = calc(WB1.list.font_h * 130) / 100;
  273.         address_box.width = Form.cwidth - address_box.left - 55;
  274.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
  275.                 Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
  276.         WB1.list.wheel_size = 7 * basic_line_h;
  277.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
  278.         WB1.list.visible = WB1.list.h;
  279.         if (WB1.list.w!=WB1.DrawBuf.bufw) {
  280.                 WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
  281.                 OpenPage(history.current());
  282.         }
  283. }
  284.  
  285.  
  286.  
  287. void draw_window()
  288. {
  289.         DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
  290.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
  291.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
  292.         SetElementSizes();
  293.         DefineHiddenButton(TOOLBAR_GAPS, address_box.top-2, 24, skin.h-2, BACK_BUTTON);
  294.         DefineHiddenButton(TOOLBAR_GAPS+25, address_box.top-2, 24, skin.h-2, FORWARD_BUTTON);
  295.         img_draw stdcall(skin.image, TOOLBAR_GAPS-1, address_box.top-3, 51, skin.h, 0, SKIN_Y);
  296.         DefineHiddenButton(address_box.left+address_box.width-4, address_box.top-2, 20, skin.h-3, REFRESH_BUTTON);
  297.         DefineHiddenButton(Form.cwidth-31, address_box.top-3, 24, skin.h-1, SANDWICH_BUTTON);
  298.         img_draw stdcall(skin.image, Form.cwidth-27, address_box.top+1, 17, 18, 51, SKIN_Y);
  299.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
  300.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
  301.         if (!header) {
  302.                 OpenPage(history.current());
  303.                 WB1.DrawScroller();
  304.         } else {
  305.                 WB1.DrawPage();
  306.                 DrawOmnibox();
  307.                 DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x,
  308.                         scroll_wv.size_y-1, scroll_wv.bckg_col);
  309.         }
  310.         DrawProgress();
  311. }
  312.  
  313.  
  314. void ProcessEvent(dword id__)
  315. {
  316.         switch (id__)
  317.         {
  318.                 case 1:
  319.                         ExitProcess();
  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 SANDWICH_BUTTON:
  345.                         EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
  346.                         return;
  347.                 case VIEW_SOURCE:
  348.                         EventViewSource();
  349.                         break;
  350.                 case EDIT_SOURCE:
  351.                         if (check_is_the_adress_local(history.current())) {
  352.                                 RunProgram("/rd/1/tinypad", history.current());
  353.                         } else {
  354.                                 CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
  355.                                 if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
  356.                         }
  357.                         return;
  358.                 case VIEW_HISTORY:
  359.                         OpenPage(URL_SERVICE_HISTORY);
  360.                         return;
  361.                 case DOWNLOAD_MANAGER:
  362.                         if (!downloader_opened) {
  363.                                 downloader_edit = NULL;
  364.                                 CreateThread(#Downloader,#downloader_stak+4092);
  365.                         }
  366.                         return;
  367.                 case COPY_LINK_URL:
  368.                         Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
  369.                         notify("'URL copied to clipboard'O");
  370.                         return;
  371.                 case DOWNLOAD_LINK_CONTENTS:
  372.                         if (!downloader_opened) {
  373.                                 strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
  374.                                 CreateThread(#Downloader,#downloader_stak+4092);
  375.                         }
  376.                         return;
  377.                 case SCAN_CODE_F12:
  378.                         debug_mode ^= 1;
  379.                         if (debug_mode) notify("'Debug mode ON'-I");
  380.                         else notify("'Debug mode OFF'-I");
  381.                         return;
  382.         }
  383. }
  384.  
  385. void StopLoading()
  386. {
  387.         if (http.transfer)
  388.         {
  389.                 EAX = http.transfer;
  390.                 EAX = EAX.http_msg.content_ptr;         // get pointer to data
  391.                 $push   EAX                                                     // save it on the stack
  392.                 http_free stdcall (http.transfer);      // abort connection
  393.                 $pop    EAX                                                    
  394.                 free(EAX);                                              // free data
  395.                 http.transfer=0;
  396.                 pause(10);
  397.         }
  398.         wv_progress_bar.value = 0;
  399.         DrawOmnibox();
  400. }
  401.  
  402. //rewrite into
  403. //bool strrpl(dword dst, from, into, dst_len);
  404. bool ReplaceSpaceInUrl(dword url, size) {
  405.         unsigned int i, j;
  406.         bool was_changed=false;
  407.         for (i=url+size-3; i>url; i--)
  408.         {
  409.                 if (ESBYTE[i]!=' ') continue;
  410.                 for (j=url+size-3; j>=i; j--) {
  411.                         ESBYTE[j+3]=ESBYTE[j+2];
  412.                         ESBYTE[j+2]=ESBYTE[j+1];
  413.                         ESBYTE[j+1]=ESBYTE[j];
  414.                 }
  415.                 ESBYTE[i] = '%';
  416.                 ESBYTE[i+1] = '2';
  417.                 ESBYTE[i+2] = '0';
  418.                 was_changed = true;
  419.         }
  420.         return was_changed;
  421. }
  422.  
  423. bool GetLocalFileData(dword _path)
  424. {
  425.         dword data, size;
  426.         file_size stdcall (_path);
  427.         if (!EBX) {
  428.                 return false;
  429.         } else {
  430.                 size = EBX;
  431.                 data = malloc(size);
  432.                 ReadFile(0, size, data, _path);
  433.                 LoadInternalPage(data, size);
  434.                 free(data);
  435.                 return true;
  436.         }
  437. }
  438.  
  439. void OpenPage(dword _open_URL)
  440. {
  441.         char new_url[URL_SIZE+1];
  442.  
  443.         StopLoading();
  444.  
  445.         strcpy(#editURL, _open_URL);
  446.         DrawOmnibox();
  447.  
  448.         strncpy(#new_url, _open_URL, URL_SIZE);
  449.  
  450.         //Exclude # from the URL to the load page
  451.         //We will bring it back when we get the buffer
  452.         if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url);
  453.  
  454.         history.add(#new_url);
  455.  
  456.         if (!strncmp(#new_url,"WebView:",8)) {
  457.                 //INTERNAL PAGE
  458.                 if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
  459.                 else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
  460.                 else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
  461.                 else LoadInternalPage(#page_not_found, sizeof(page_not_found));
  462.         } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
  463.                 //WEB PAGE
  464.                 img_draw stdcall(skin.image, address_box.left+address_box.width+1,
  465.                         address_box.top-3, 17, skin.h, 85, SKIN_Y);
  466.  
  467.                 if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
  468.                         strcpy(#editURL, #new_url);
  469.                         DrawOmnibox();
  470.                 }
  471.  
  472.                 if (!strncmp(#new_url,"http:",5)) {
  473.                         http.get(#new_url);
  474.                 } else if (!strncmp(#new_url,"https://",8)) {
  475.                         strcpy(#new_url, "http://gate.aspero.pro/?site=");
  476.                         strncat(#new_url, _open_URL, URL_SIZE);
  477.                         http.get(#new_url);
  478.                 }
  479.                 if (!http.transfer) {
  480.                         StopLoading();
  481.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  482.                 }
  483.         } else {
  484.                 //LOCAL PAGE
  485.                 if (!GetLocalFileData(#new_url)) {
  486.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  487.                 }
  488.         }
  489. }
  490.  
  491. void EventClickLink(dword _click_URL)
  492. {
  493.         char new_url[URL_SIZE+1];
  494.  
  495.         if (ESBYTE[_click_URL]=='#') {
  496.                 if (anchors.get_pos_by_name(_click_URL+1)!=-1) {
  497.                         WB1.list.first = anchors.get_pos_by_name(_click_URL+1);
  498.                         WB1.list.CheckDoesValuesOkey();
  499.                 }
  500.                 strcpy(#editURL, history.current());
  501.                 strcat(#editURL, _click_URL);
  502.                 DrawOmnibox();
  503.                 WB1.DrawPage();
  504.                 return;
  505.         }
  506.  
  507.         if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) {
  508.                 notify(_click_URL);
  509.                 return;
  510.         }
  511.  
  512.         if (http.transfer > 0) {
  513.                 StopLoading();
  514.                 history.back();
  515.         }
  516.  
  517.         strcpy(#new_url, _click_URL);
  518.         GetAbsoluteURL(#new_url, history.current());
  519.  
  520.         if (strrchr(#new_url, '#')!=0) {
  521.                 anchors.take_anchor_from(#new_url);
  522.                 OpenPage(#new_url);
  523.                 return;
  524.         }
  525.  
  526.         if (!strncmp(#new_url,"WebView:",8)) {
  527.                 OpenPage(#new_url);
  528.                 return;
  529.         }
  530.  
  531.         if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
  532.         {
  533.                 if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
  534.                 {      
  535.                         if (strchr(#new_url, '|')) {
  536.                                 ESBYTE[strchr(#new_url, '|')] = NULL;
  537.                                 RunProgram(#new_url, strlen(#new_url)+1+#new_url);
  538.                         } else {
  539.                                 RunProgram("/sys/@open", #new_url);
  540.                         }
  541.                         return;
  542.                 }
  543.         } else {
  544.                 if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true)
  545.                 || (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true)
  546.                 || (UrlExtIs(#new_url,".7z")==true) {
  547.                         if (!downloader_opened) {
  548.                                 strcpy(#downloader_edit, #new_url);
  549.                                 CreateThread(#Downloader,#downloader_stak+4092);
  550.                         }
  551.                         else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
  552.                         return;
  553.                 }
  554.         }
  555.         OpenPage(#new_url);
  556. }
  557.  
  558. void EventSubmitOmnibox()
  559. {
  560.         char new_url[URL_SIZE+1];
  561.         if (!editURL[0]) return;
  562.         if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
  563.         || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
  564.                 OpenPage(#editURL);
  565.         } else {
  566.                 strcpy(#new_url, "http://");
  567.                 strncat(#new_url, #editURL, sizeof(new_url)-1);
  568.                 OpenPage(#new_url);
  569.         }
  570. }
  571.  
  572. void DrawOmnibox()
  573. {
  574.         int skin_x_offset;
  575.        
  576.         DrawRectangle(address_box.left-2, address_box.top-3, address_box.width+5, 25,border_color);
  577.  
  578.         DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 1,0xD8DCD8);
  579.         DrawBar(address_box.left-2, address_box.top-1, address_box.width+3, 1, address_box.color);
  580.         img_draw stdcall(skin.image, address_box.left-2, address_box.top-3, 2, skin.h, 102, SKIN_Y);
  581.         if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
  582.         EditBox_UpdateText(#address_box, address_box.flags);
  583.         edit_box_draw stdcall(#address_box);
  584.         if (http.transfer > 0) skin_x_offset = 85; else skin_x_offset = 68;
  585.         img_draw stdcall(skin.image, address_box.left+address_box.width+1,
  586.                 address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
  587. }
  588.  
  589. void LoadInternalPage(dword _bufdata, _in_bufsize){
  590.         if (!_bufdata) || (!_in_bufsize) {
  591.                 LoadInternalPage(#page_not_found, sizeof(page_not_found));
  592.         } else {
  593.                 bufsize = _in_bufsize;
  594.                 if (bufpointer!=_bufdata) free(bufpointer);
  595.                 bufpointer = malloc(bufsize);
  596.                 memmov(bufpointer, _bufdata, bufsize);
  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();
  604.                 if (source_mode) {
  605.                         source_mode = false;
  606.                         ShowSource(bufpointer, 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/100, 2, 0x72B7EB);
  629. }
  630.  
  631. void EventShowPageMenu(dword _left, _top)
  632. {
  633.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
  634. }
  635.  
  636. void EventShowLinkMenu(dword _left, _top)
  637. {
  638.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
  639. }
  640.  
  641. void EventUpdateProgressBar()
  642. {
  643.         wv_progress_bar.max = http.content_length;
  644.         if (wv_progress_bar.value != http.content_received)
  645.         {
  646.                 wv_progress_bar.value = http.content_received; 
  647.                 DrawProgress();
  648.         }
  649. }
  650.  
  651. void EventSeachWeb()
  652. {
  653.         char new_url[URL_SIZE+1];
  654.         replace_char(#editURL, ' ', '_', URL_SIZE);
  655.         strcpy(#new_url, "https://www.google.com/search?q=");
  656.         strncat(#new_url, #editURL, URL_SIZE);
  657.         OpenPage(#new_url);
  658. }
  659.  
  660. void EventOpenDialog()
  661. {
  662.         OpenDialog_start stdcall (#o_dialog);
  663.         if (o_dialog.status) {
  664.                 OpenPage(#openfile_path);
  665.         }
  666. }
  667.  
  668. void EventViewSource()
  669. {
  670.         char source_view_param[URL_SIZE+1];
  671.         strcpy(#source_view_param, "-s ");
  672.         strncat(#source_view_param, history.current(), URL_SIZE);
  673.         RunProgram(#program_path, #source_view_param);
  674. }
  675.  
  676. void DrawStatusBar(dword _status_text)
  677. {
  678.         status_text.start_x = 10;
  679.         status_text.start_y = Form.cheight - STATUSBAR_H + 3;
  680.         status_text.area_size_x = Form.cwidth - status_text.start_x -3;
  681.         DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
  682.         status_text.text_pointer = _status_text;
  683.         PathShow_prepare stdcall(#status_text);
  684.         PathShow_draw stdcall(#status_text);
  685. }
  686.  
  687. stop: