Rev 8490 | Rev 8499 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7739 | leency | 1 | //Copyright 2007-2020 by Veliant & Leency |
6978 | leency | 2 | //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... |
3067 | leency | 3 | |
4085 | leency | 4 | #ifndef AUTOBUILD |
5 | #include "lang.h--" |
||
6 | #endif |
||
7 | |||
8332 | leency | 8 | //===================================================// |
9 | // // |
||
10 | // LIB // |
||
11 | // // |
||
12 | //===================================================// |
||
13 | |||
8413 | leency | 14 | #define MEMSIZE 1024 * 130 |
5499 | leency | 15 | #include "..\lib\gui.h" |
4508 | leency | 16 | #include "..\lib\draw_buf.h" |
17 | #include "..\lib\list_box.h" |
||
18 | #include "..\lib\cursor.h" |
||
5978 | leency | 19 | #include "..\lib\collection.h" |
6795 | leency | 20 | #include "..\lib\random.h" |
7037 | leency | 21 | #include "..\lib\clipboard.h" |
5981 | leency | 22 | |
5499 | leency | 23 | #include "..\lib\obj\box_lib.h" |
7049 | leency | 24 | #include "..\lib\obj\libimg.h" |
5499 | leency | 25 | #include "..\lib\obj\http.h" |
5690 | leency | 26 | #include "..\lib\obj\iconv.h" |
7748 | leency | 27 | #include "..\lib\obj\proc_lib.h" |
8330 | leency | 28 | #include "..\lib\obj\netcode.h" |
7757 | leency | 29 | |
5978 | leency | 30 | #include "..\lib\patterns\history.h" |
7748 | leency | 31 | #include "..\lib\patterns\simple_open_dialog.h" |
7759 | leency | 32 | #include "..\lib\patterns\toolbar_button.h" |
7914 | leency | 33 | #include "..\lib\patterns\restart_process.h" |
5408 | leency | 34 | |
8336 | leency | 35 | #include "const.h" |
36 | #include "cache.h" |
||
37 | #include "show_src.h" |
||
38 | |||
8332 | leency | 39 | //===================================================// |
40 | // // |
||
41 | // DATA // |
||
42 | // // |
||
43 | //===================================================// |
||
7757 | leency | 44 | bool debug_mode = false; |
8396 | leency | 45 | bool show_images = true; |
7771 | leency | 46 | |
8016 | leency | 47 | _history history; |
48 | |||
7970 | leency | 49 | enum { TARGET_SAME_TAB, TARGET_NEW_WINDOW, TARGET_NEW_TAB }; |
50 | |||
8330 | leency | 51 | #include "TWB\TWB.c" //HTML Parser, a core component |
7757 | leency | 52 | |
7759 | leency | 53 | TWebBrowser WB1; |
7758 | leency | 54 | |
7771 | leency | 55 | #include "history.h" |
7752 | leency | 56 | |
7758 | leency | 57 | #define PADDING 9 |
58 | #define TSZE 25 |
||
7771 | leency | 59 | #define STATUSBAR_H 15 |
60 | #define TAB_H 20 |
||
7758 | leency | 61 | dword TOOLBAR_H = PADDING+TSZE+PADDING+2; |
4677 | leency | 62 | |
7759 | leency | 63 | _http http = 0; |
7758 | leency | 64 | |
7750 | leency | 65 | bool source_mode = false; |
7282 | leency | 66 | |
8330 | leency | 67 | progress_bar prbar; |
7750 | leency | 68 | proc_info Form; |
7748 | leency | 69 | |
8336 | leency | 70 | #include "tabs.h" |
71 | |||
72 | dword cur_img_url; |
||
73 | dword shared_url; |
||
8445 | leency | 74 | dword http_get_type=PAGE; |
8365 | leency | 75 | dword render_start_time; |
7780 | leency | 76 | int menu_id=NULL; |
77 | |||
7748 | leency | 78 | char default_dir[] = "/rd/1"; |
7788 | leency | 79 | od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" }; |
7748 | leency | 80 | |
7755 | leency | 81 | char editURL[URL_SIZE+1]; |
8332 | leency | 82 | edit_box omnibox_edit = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff, |
7758 | leency | 83 | 0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19}; |
4534 | leency | 84 | |
8332 | leency | 85 | //===================================================// |
86 | // // |
||
87 | // CODE // |
||
88 | // // |
||
89 | //===================================================// |
||
90 | |||
7748 | leency | 91 | void LoadLibraries() |
92 | { |
||
8330 | leency | 93 | load_dll(boxlib, #box_lib_init,0); |
94 | load_dll(libimg, #libimg_init,1); |
||
95 | load_dll(libHTTP, #http_lib_init,1); |
||
96 | load_dll(iconv_lib, #iconv_open,0); |
||
97 | load_dll(netcode_lib, #base64_encode,0); |
||
98 | load_dll(Proc_lib, #OpenDialog_init,0); |
||
7748 | leency | 99 | OpenDialog_init stdcall (#o_dialog); |
100 | } |
||
101 | |||
102 | void HandleParam() |
||
103 | { |
||
8278 | leency | 104 | if (!param) { |
8336 | leency | 105 | history.add(DEFAULT_URL); |
8278 | leency | 106 | } else { |
107 | if (!strncmp(#param, "-source ", 8)) { |
||
7750 | leency | 108 | source_mode = true; |
7765 | leency | 109 | history.add(#param + 8); |
7936 | leency | 110 | } else if (!strncmp(#param, "-new ", 5)) { |
111 | history.add(#param + 5); |
||
7748 | leency | 112 | } else { |
7914 | leency | 113 | if (GetProcessesCount("WEBVIEW") == 1) { |
114 | history.add(#param); |
||
115 | } else { |
||
116 | shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_OPEN + SHM_WRITE); |
||
117 | strncpy(shared_url, #param, URL_SIZE); |
||
118 | ExitProcess(); |
||
119 | } |
||
7748 | leency | 120 | } |
121 | } |
||
7914 | leency | 122 | shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_CREATE + SHM_WRITE); |
7920 | leency | 123 | ESDWORD[shared_url] = '\0'; |
7748 | leency | 124 | } |
125 | |||
3067 | leency | 126 | void main() |
127 | { |
||
8332 | leency | 128 | int redirect_count=0; |
7748 | leency | 129 | LoadLibraries(); |
130 | HandleParam(); |
||
6045 | leency | 131 | WB1.list.SetFont(8, 14, 10011000b); |
5779 | leency | 132 | WB1.list.no_selection = true; |
7759 | leency | 133 | WB1.custom_encoding = -1; |
8332 | leency | 134 | @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
7914 | leency | 135 | loop() switch(@WaitEventTimeout(30)) |
6978 | leency | 136 | { |
137 | case evMouse: |
||
8332 | leency | 138 | edit_box_mouse stdcall (#omnibox_edit); |
6978 | leency | 139 | mouse.get(); |
7970 | leency | 140 | |
7282 | leency | 141 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
7970 | leency | 142 | |
8490 | leency | 143 | if (WB1.list.count > WB1.list.visible) { |
144 | scrollbar_v_mouse (#scroll_wv); |
||
145 | if (scroll_wv.delta2) { |
||
146 | WB1.list.first = scroll_wv.position; |
||
147 | WB1.DrawPage(); |
||
148 | break; |
||
149 | } |
||
6978 | leency | 150 | } |
7970 | leency | 151 | |
152 | if (links.hover(WB1.list.y, WB1.list.first)) |
||
7758 | leency | 153 | { |
8330 | leency | 154 | if (mouse.key&MOUSE_MIDDLE) && (mouse.up) { |
7970 | leency | 155 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { |
156 | EventClickLink(TARGET_NEW_WINDOW); |
||
157 | } else { |
||
158 | EventClickLink(TARGET_NEW_TAB); |
||
159 | } |
||
160 | } |
||
8330 | leency | 161 | if (mouse.key&MOUSE_LEFT) && (mouse.up) { |
7970 | leency | 162 | CursorPointer.Restore(); |
163 | EventClickLink(TARGET_SAME_TAB); |
||
164 | } |
||
8330 | leency | 165 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) { |
7970 | leency | 166 | CursorPointer.Restore(); |
167 | EventShowLinkMenu(); |
||
168 | } |
||
169 | } else { |
||
170 | CursorPointer.Restore(); |
||
8330 | leency | 171 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) && (WB1.list.MouseOver(mouse.x, mouse.y)) { |
7970 | leency | 172 | EventShowPageMenu(); |
173 | } |
||
7758 | leency | 174 | } |
6978 | leency | 175 | break; |
5711 | leency | 176 | |
6978 | leency | 177 | case evButton: |
8332 | leency | 178 | ProcessButtonClick( @GetButtonID() ); |
6978 | leency | 179 | break; |
5711 | leency | 180 | |
6978 | leency | 181 | case evKey: |
8332 | leency | 182 | @GetKeys(); |
183 | edit_box_key stdcall(#omnibox_edit); |
||
184 | ProcessKeyEvent(); |
||
6978 | leency | 185 | break; |
186 | |||
187 | case evReDraw: |
||
8490 | leency | 188 | DefineAndDrawWindow(GetScreenWidth()-WIN_W/2-random(80),GetScreenHeight()-WIN_H/2-random(80), |
189 | //DefineAndDrawWindow(0,0, |
||
190 | WIN_W,WIN_H,0x73,0,0,0); |
||
6978 | leency | 191 | GetProcessInfo(#Form, SelfInfo); |
7780 | leency | 192 | ProcessMenuClick(); |
7806 | leency | 193 | sc.get(); |
7759 | leency | 194 | if (Form.status_window>2) break; |
6978 | leency | 195 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
196 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
||
7748 | leency | 197 | draw_window(); |
6978 | leency | 198 | break; |
199 | |||
200 | case evNetwork: |
||
7758 | leency | 201 | if (http.transfer <= 0) break; |
202 | http.receive(); |
||
8336 | leency | 203 | |
204 | if (http_get_type==PAGE) { |
||
205 | CheckContentType(); |
||
206 | prbar.max = http.content_length; |
||
207 | if (prbar.value != http.content_received) { |
||
208 | prbar.value = http.content_received; |
||
209 | DrawProgress(); |
||
210 | } |
||
211 | } |
||
212 | |||
7758 | leency | 213 | if (http.receive_result != 0) break; |
8413 | leency | 214 | if (debug_mode) debugval("HTTP", http.status_code); |
7758 | leency | 215 | if (http.status_code >= 300) && (http.status_code < 400) |
216 | { |
||
217 | // Handle redirects |
||
218 | if (redirect_count<=5) { |
||
219 | redirect_count++; |
||
8305 | leency | 220 | HandleRedirect(); |
7758 | leency | 221 | } else { |
222 | StopLoading(); |
||
7791 | leency | 223 | redirect_count = 0; |
8440 | leency | 224 | if (http_get_type==IMG) goto _IMG_RES; |
8457 | leency | 225 | notify("'Too many redirects.' -E"); |
4536 | leency | 226 | } |
7758 | leency | 227 | } else { |
228 | // Loading the page is complete, free resources |
||
229 | redirect_count = 0; |
||
8291 | leency | 230 | http.hfree(); |
8016 | leency | 231 | if (http_get_type==PAGE) { |
8413 | leency | 232 | history.add(http.cur_url); |
8462 | leency | 233 | if (!strchr(http.cur_url, '?')) { |
8492 | leency | 234 | cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE, WB1.custom_encoding); |
8462 | leency | 235 | } |
236 | LoadInternalPage(http.content_pointer, http.content_received); |
||
8425 | leency | 237 | free(http.content_pointer); |
8016 | leency | 238 | } |
239 | else if (http_get_type==IMG) { |
||
8440 | leency | 240 | _IMG_RES: |
8454 | leency | 241 | if (http.status_code >= 200) && (http.status_code < 300) { |
8492 | leency | 242 | cache.add(cur_img_url, http.content_pointer, http.content_received, IMG, NULL); |
8454 | leency | 243 | } else { |
8492 | leency | 244 | cache.add(cur_img_url, 0, 0, IMG, NULL); |
8454 | leency | 245 | } |
8425 | leency | 246 | free(http.content_pointer); |
8336 | leency | 247 | GetImg(false); |
8016 | leency | 248 | } |
6978 | leency | 249 | } |
7914 | leency | 250 | break; |
251 | default: |
||
252 | if (ESDWORD[shared_url] != '\0') { |
||
253 | EventOpenNewTab(shared_url); |
||
254 | ESDWORD[shared_url] = '\0'; |
||
255 | ActivateWindow(GetProcessSlot(Form.ID)); |
||
256 | } |
||
6978 | leency | 257 | } |
3067 | leency | 258 | } |
259 | |||
8332 | leency | 260 | |
261 | //===================================================// |
||
262 | // // |
||
263 | // EVENTS // |
||
264 | // // |
||
265 | //===================================================// |
||
266 | |||
267 | void ProcessButtonClick(dword id__) |
||
7772 | leency | 268 | { |
8332 | leency | 269 | switch (id__) |
270 | { |
||
271 | case 1: ExitProcess(); |
||
272 | case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: EventTabClose(id__ - TAB_CLOSE_ID); return; |
||
273 | case TAB_ID...TAB_ID+TABS_MAX: EventAllTabsClick(id__ - TAB_ID); return; |
||
8492 | leency | 274 | case ENCODINGS...ENCODINGS+6: EventManuallyChangeEncoding(id__-ENCODINGS); return; |
8332 | leency | 275 | case NEW_WINDOW: RunProgram(#program_path, NULL); return; |
276 | case NEW_TAB: if (!http.transfer) EventOpenNewTab(URL_SERVICE_HOMEPAGE); return; |
||
277 | case SCAN_CODE_BS: |
||
278 | case BACK_BUTTON: if (history.back()) OpenPage(history.current()); return; |
||
279 | case FORWARD_BUTTON: if (history.forward()) OpenPage(history.current()); return; |
||
280 | case GOTOURL_BUTTON: EventSubmitOmnibox(); return; |
||
281 | case REFRESH_BUTTON: EventRefreshPage(); return; |
||
282 | case CHANGE_ENCODING: EventShowEncodingsList(); return; |
||
283 | case SANDWICH_BUTTON: EventShowMainMenu(); return; |
||
284 | case VIEW_SOURCE: EventViewSource(); return; |
||
285 | case EDIT_SOURCE: EventEditSource(); return; |
||
286 | case VIEW_HISTORY: OpenPage(URL_SERVICE_HISTORY); return; |
||
287 | case DOWNLOAD_MANAGER: EventOpenDownloader(""); return; |
||
288 | case UPDATE_BROWSER: EventUpdateBrowser(); return; |
||
289 | case CLEAR_CACHE: EventClearCache(); return; |
||
290 | case IN_NEW_TAB: EventClickLink(TARGET_NEW_TAB); return; |
||
291 | case IN_NEW_WINDOW: EventClickLink(TARGET_NEW_WINDOW); return; |
||
292 | case COPY_LINK_URL: EventCopyLinkToClipboard(); return; |
||
293 | case DOWNLOAD_LINK_CT: EventOpenDownloader( GetAbsoluteActiveURL() ); return; |
||
294 | case OPEN_FILE: EventOpenDialog(); return; |
||
295 | } |
||
296 | } |
||
297 | |||
298 | bool ProcessKeyEvent() |
||
299 | { |
||
300 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) |
||
301 | { |
||
302 | if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();return;} |
||
303 | } |
||
304 | |||
7772 | leency | 305 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode) |
306 | { |
||
8016 | leency | 307 | case SCAN_CODE_KEY_O: EventOpenDialog(); return true; |
8332 | leency | 308 | case SCAN_CODE_KEY_H: ProcessButtonClick(VIEW_HISTORY); return true; |
8016 | leency | 309 | case SCAN_CODE_KEY_U: EventViewSource(); return true; |
310 | case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return true; |
||
311 | case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return true; |
||
8332 | leency | 312 | case SCAN_CODE_KEY_J: ProcessButtonClick(DOWNLOAD_MANAGER); return true; |
313 | case SCAN_CODE_KEY_R: ProcessButtonClick(REFRESH_BUTTON); return true; |
||
8016 | leency | 314 | case SCAN_CODE_ENTER: EventSeachWeb(); return true; |
8332 | leency | 315 | case SCAN_CODE_LEFT: ProcessButtonClick(BACK_BUTTON); return true; |
316 | case SCAN_CODE_RIGHT: ProcessButtonClick(FORWARD_BUTTON); return true; |
||
8016 | leency | 317 | case SCAN_CODE_KEY_W: EventCloseActiveTab(); return true; |
318 | case SCAN_CODE_TAB: EventActivateNextTab(); return true; |
||
8336 | leency | 319 | case SCAN_CODE_F5: EventClearCache(); return; |
8016 | leency | 320 | default: return false; |
7772 | leency | 321 | } |
8332 | leency | 322 | |
323 | switch(key_scancode) |
||
324 | { |
||
325 | case SCAN_CODE_UP: EventScrollUpAndDown(SCAN_CODE_UP); return; |
||
326 | case SCAN_CODE_DOWN: EventScrollUpAndDown(SCAN_CODE_DOWN); return; |
||
327 | case SCAN_CODE_F6: {omnibox_edit.flags=ed_focus; DrawOmnibox();} return; |
||
328 | case SCAN_CODE_F5: EventRefreshPage(); return; |
||
329 | case SCAN_CODE_ENTER: if (omnibox_edit.flags & ed_focus) EventSubmitOmnibox(); return; |
||
330 | case SCAN_CODE_F12: EventToggleDebugMode(); return; |
||
331 | case SCAN_CODE_F11: show_images^=1; EventClearCache(); return; |
||
332 | default: if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); return; |
||
333 | } |
||
7772 | leency | 334 | } |
335 | |||
3067 | leency | 336 | void SetElementSizes() |
337 | { |
||
8332 | leency | 338 | omnibox_edit.width = Form.cwidth - omnibox_edit.left - 52 - 16; |
8457 | leency | 339 | WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.cwidth - scroll_wv.size_x, |
7771 | leency | 340 | Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H); |
7759 | leency | 341 | WB1.list.wheel_size = 7 * BASIC_LINE_H; |
7746 | leency | 342 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; |
6794 | leency | 343 | WB1.list.visible = WB1.list.h; |
3067 | leency | 344 | } |
345 | |||
5981 | leency | 346 | |
7748 | leency | 347 | void draw_window() |
3067 | leency | 348 | { |
7910 | leency | 349 | bool burger_active = false; |
350 | if (menu_id == OPEN_FILE) burger_active = true; |
||
351 | |||
3067 | leency | 352 | SetElementSizes(); |
7758 | leency | 353 | |
7806 | leency | 354 | DrawBar(0,0, Form.cwidth,PADDING, sc.work); |
355 | DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, sc.work); |
||
356 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(sc.work_dark, sc.work, 180)); |
||
357 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, sc.work_graph); |
||
8332 | leency | 358 | DrawBar(0, PADDING, omnibox_edit.left-2, TSZE+1, sc.work); |
359 | DrawBar(omnibox_edit.left+omnibox_edit.width+18, PADDING, Form.cwidth-omnibox_edit.left-omnibox_edit.width-18, TSZE+1, sc.work); |
||
7758 | leency | 360 | |
7910 | leency | 361 | DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30, false); |
362 | DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31, false); |
||
363 | DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1, burger_active); //burger menu |
||
7758 | leency | 364 | |
7806 | leency | 365 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph); |
7758 | leency | 366 | |
367 | DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, |
||
368 | WB1.list.h-1, scroll_wv.bckg_col); |
||
369 | |||
8457 | leency | 370 | if (!canvas.bufw) { |
371 | OpenPage(history.current()); |
||
372 | } else { |
||
7771 | leency | 373 | WB1.DrawPage(); |
8457 | leency | 374 | DrawOmnibox(); |
7771 | leency | 375 | } |
376 | DrawProgress(); |
||
8413 | leency | 377 | DrawStatusBar(NULL); |
7771 | leency | 378 | DrawTabsBar(); |
379 | } |
||
380 | |||
8492 | leency | 381 | void EventManuallyChangeEncoding(int _new_encoding) |
7759 | leency | 382 | { |
383 | dword newbuf, newsize; |
||
384 | WB1.custom_encoding = _new_encoding; |
||
385 | newsize = strlen(WB1.o_bufpointer); |
||
386 | newbuf = malloc(newsize); |
||
387 | memmov(newbuf, WB1.o_bufpointer, newsize); |
||
388 | LoadInternalPage(newbuf, newsize); |
||
389 | free(newbuf); |
||
390 | } |
||
3067 | leency | 391 | |
7759 | leency | 392 | |
8332 | leency | 393 | void EventScrollUpAndDown(int _direction) |
4413 | leency | 394 | { |
8332 | leency | 395 | int i; |
396 | for (i=0;i |
||
397 | if (_direction == SCAN_CODE_UP) WB1.list.KeyUp(); |
||
398 | if (_direction == SCAN_CODE_DOWN) WB1.list.KeyDown(); |
||
399 | } |
||
400 | WB1.DrawPage(); |
||
4413 | leency | 401 | } |
402 | |||
8305 | leency | 403 | void EventToggleDebugMode() |
404 | { |
||
405 | debug_mode ^= 1; |
||
406 | if (debug_mode) notify("'Debug mode ON'-I"); |
||
407 | else notify("'Debug mode OFF'-I"); |
||
408 | } |
||
409 | |||
410 | void EventAllTabsClick(dword _n) |
||
411 | { |
||
412 | if (mouse.mkm) { |
||
8490 | leency | 413 | StopLoading(); |
8305 | leency | 414 | EventTabClose(_n); |
415 | } else { |
||
8490 | leency | 416 | if (!http.transfer) EventTabClick(_n); |
8355 | leency | 417 | } |
8305 | leency | 418 | } |
419 | |||
420 | void EventEditSource() |
||
421 | { |
||
422 | if (check_is_the_adress_local(history.current())) { |
||
8330 | leency | 423 | RunProgram("/rd/1/quark", history.current()); |
8305 | leency | 424 | } else { |
425 | CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm"); |
||
8330 | leency | 426 | if (!EAX) RunProgram("/rd/1/quark", "/tmp0/1/WebView_tmp.htm"); |
8305 | leency | 427 | } |
428 | } |
||
429 | |||
430 | void EventClearCache() |
||
431 | { |
||
432 | cache.clear(); |
||
433 | notify(#clear_cache_ok); |
||
434 | EventRefreshPage(); |
||
435 | } |
||
436 | |||
437 | void EventCopyLinkToClipboard() |
||
438 | { |
||
439 | Clipboard__CopyText(GetAbsoluteActiveURL()); |
||
440 | notify("'URL copied to clipboard'O"); |
||
441 | } |
||
442 | |||
4636 | leency | 443 | void StopLoading() |
444 | { |
||
8305 | leency | 445 | if (http.stop()) pause(10); |
8330 | leency | 446 | prbar.value = 0; |
4645 | leency | 447 | } |
448 | |||
7756 | leency | 449 | //rewrite into |
7757 | leency | 450 | //bool strrpl(dword dst, from, into, dst_len); |
451 | bool ReplaceSpaceInUrl(dword url, size) { |
||
7756 | leency | 452 | unsigned int i, j; |
7757 | leency | 453 | bool was_changed=false; |
454 | for (i=url+size-3; i>url; i--) |
||
7720 | leency | 455 | { |
7756 | leency | 456 | if (ESBYTE[i]!=' ') continue; |
7757 | leency | 457 | for (j=url+size-3; j>=i; j--) { |
458 | ESBYTE[j+3]=ESBYTE[j+2]; |
||
7756 | leency | 459 | ESBYTE[j+2]=ESBYTE[j+1]; |
460 | ESBYTE[j+1]=ESBYTE[j]; |
||
461 | } |
||
462 | ESBYTE[i] = '%'; |
||
463 | ESBYTE[i+1] = '2'; |
||
464 | ESBYTE[i+2] = '0'; |
||
7757 | leency | 465 | was_changed = true; |
7720 | leency | 466 | } |
7757 | leency | 467 | return was_changed; |
7720 | leency | 468 | } |
469 | |||
7801 | leency | 470 | bool HandleUrlFiles(dword _path, _data) |
471 | { |
||
472 | dword url_from_file; |
||
473 | if (!UrlExtIs(_path, "url")) return false; |
||
7945 | leency | 474 | if (! url_from_file = strstri(_data, "URL=")) return false; |
7801 | leency | 475 | replace_char(url_from_file, '\n', '\0', strlen(url_from_file)); |
7945 | leency | 476 | OpenPage(url_from_file); |
477 | return true; |
||
7801 | leency | 478 | } |
479 | |||
7755 | leency | 480 | bool GetLocalFileData(dword _path) |
4416 | leency | 481 | { |
7801 | leency | 482 | dword data, size; |
8392 | leency | 483 | read_file(_path, #data, #size); |
7801 | leency | 484 | if (!HandleUrlFiles(_path, data)) { |
485 | LoadInternalPage(data, size); |
||
4692 | leency | 486 | } |
7801 | leency | 487 | free(data); |
488 | return true; |
||
7755 | leency | 489 | } |
7282 | leency | 490 | |
8336 | leency | 491 | bool GetUrl(dword _http_url) |
8330 | leency | 492 | { |
493 | char new_url_full[URL_SIZE+1]; |
||
494 | |||
495 | if (!strncmp(_http_url,"http:",5)) { |
||
496 | http.get(_http_url); |
||
8336 | leency | 497 | return true; |
8330 | leency | 498 | } else if (!strncmp(_http_url,"https://",8)) { |
499 | strcpy(#new_url_full, "http://gate.aspero.pro/?site="); |
||
500 | strncat(#new_url_full, _http_url, URL_SIZE); |
||
501 | http.get(#new_url_full); |
||
8336 | leency | 502 | return true; |
8330 | leency | 503 | } |
8336 | leency | 504 | return false; |
8330 | leency | 505 | } |
506 | |||
7755 | leency | 507 | void OpenPage(dword _open_URL) |
508 | { |
||
509 | char new_url[URL_SIZE+1]; |
||
7788 | leency | 510 | int unz_id; |
7755 | leency | 511 | |
512 | StopLoading(); |
||
513 | |||
7771 | leency | 514 | SetOmniboxText(_open_URL); |
515 | |||
7755 | leency | 516 | strncpy(#new_url, _open_URL, URL_SIZE); |
517 | |||
518 | //Exclude # from the URL to the load page |
||
519 | //We will bring it back when we get the buffer |
||
7970 | leency | 520 | if (strrchr(#new_url, '#')) { |
521 | anchors.take_anchor_from(#new_url); |
||
522 | } |
||
7755 | leency | 523 | |
7976 | leency | 524 | /* |
525 | There could be several possible types of addresses: |
||
526 | - cached page (only http/https) |
||
527 | - internal page |
||
528 | - web page |
||
529 | - local file |
||
530 | So we need to detect what incoming address is |
||
531 | and then halndle it in the propper way. |
||
532 | */ |
||
533 | |||
8016 | leency | 534 | if (cache.has(#new_url)) { |
7764 | leency | 535 | //CACHED PAGE |
8413 | leency | 536 | if (cache.current_type==PAGE) { |
537 | history.add(#new_url); |
||
8492 | leency | 538 | WB1.custom_encoding = cache.current_charset; |
8413 | leency | 539 | LoadInternalPage(cache.current_buf, cache.current_size); |
540 | } |
||
541 | else { |
||
542 | EventDownloadAndOpenImage(#new_url); |
||
543 | } |
||
7764 | leency | 544 | |
545 | } else if (!strncmp(#new_url,"WebView:",8)) { |
||
7755 | leency | 546 | //INTERNAL PAGE |
8413 | leency | 547 | history.add(#new_url); |
8492 | leency | 548 | WB1.custom_encoding = -1; |
8278 | leency | 549 | if (streq(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#buildin_page_home, sizeof(buildin_page_home)); |
550 | else if (streq(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#buildin_page_help, sizeof(buildin_page_help)); |
||
8457 | leency | 551 | else if (streq(#new_url, URL_SERVICE_TEST)) LoadInternalPage(#buildin_page_test, sizeof(buildin_page_test)); |
7976 | leency | 552 | else if (streq(#new_url, URL_SERVICE_HISTORY)) ShowHistory(); |
8278 | leency | 553 | else LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
7800 | leency | 554 | |
7755 | leency | 555 | } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) { |
556 | //WEB PAGE |
||
7757 | leency | 557 | if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) { |
558 | strcpy(#editURL, #new_url); |
||
559 | } |
||
560 | |||
8016 | leency | 561 | http_get_type = PAGE; |
8330 | leency | 562 | GetUrl(#new_url); |
7758 | leency | 563 | |
564 | DrawOmnibox(); |
||
565 | |||
7755 | leency | 566 | if (!http.transfer) { |
8413 | leency | 567 | history.add(#new_url); |
8278 | leency | 568 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
4646 | leency | 569 | } |
7755 | leency | 570 | } else { |
571 | //LOCAL PAGE |
||
8413 | leency | 572 | history.add(#new_url); |
7788 | leency | 573 | if (UrlExtIs(#new_url,".docx")) { |
574 | DeleteFile("/tmp0/1/temp/word/document.xml"); |
||
575 | CreateDir("/tmp0/1/temp"); |
||
576 | unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url)); |
||
577 | while (GetProcessSlot(unz_id)) pause(2); |
||
578 | strcpy(#new_url, "/tmp0/1/temp/word/document.xml"); |
||
579 | } |
||
7755 | leency | 580 | if (!GetLocalFileData(#new_url)) { |
8278 | leency | 581 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
4650 | leency | 582 | } |
4636 | leency | 583 | } |
4416 | leency | 584 | } |
4415 | leency | 585 | |
8278 | leency | 586 | dword EventOpenDownloader(dword _url) |
587 | { |
||
588 | //char download_params[URL_SIZE+50]; |
||
589 | return RunProgram("/sys/network/dl", _url); |
||
590 | } |
||
7970 | leency | 591 | |
592 | bool EventClickAnchor() |
||
4508 | leency | 593 | { |
7970 | leency | 594 | dword aURL = links.active_url; |
595 | |||
596 | if (anchors.get_pos_by_name(aURL+1)!=-1) { |
||
597 | WB1.list.first = anchors.get_pos_by_name(aURL+1); |
||
8417 | leency | 598 | WB1.list.CheckDoesValuesOkey(); |
7970 | leency | 599 | strcpy(#editURL, history.current()); |
600 | strcat(#editURL, aURL); |
||
601 | DrawOmnibox(); |
||
602 | WB1.DrawPage(); |
||
603 | return true; |
||
604 | } |
||
605 | return false; |
||
606 | } |
||
607 | |||
608 | void EventClickLink(dword _target) |
||
609 | { |
||
7756 | leency | 610 | char new_url[URL_SIZE+1]; |
7936 | leency | 611 | char new_url_full[URL_SIZE+1]; |
7970 | leency | 612 | dword aURL = GetAbsoluteActiveURL(); |
613 | if (!aURL) return; |
||
4415 | leency | 614 | |
7970 | leency | 615 | strcpy(#new_url, aURL); |
616 | |||
617 | if (ESBYTE[aURL]=='#') { |
||
618 | if (_target == TARGET_SAME_TAB) { |
||
619 | EventClickAnchor(); |
||
620 | return; |
||
621 | } else { |
||
622 | strcpy(#new_url, history.current()); |
||
623 | strcat(#new_url, aURL); |
||
624 | } |
||
625 | } |
||
626 | |||
627 | if (_target == TARGET_NEW_TAB) { |
||
628 | EventOpenNewTab(#new_url); |
||
7758 | leency | 629 | return; |
630 | } |
||
631 | |||
7970 | leency | 632 | if (_target == TARGET_NEW_WINDOW) { |
633 | strcpy(#new_url_full, "-new "); |
||
634 | strncat(#new_url_full, #new_url, URL_SIZE); |
||
635 | RunProgram(#program_path, #new_url_full); |
||
7755 | leency | 636 | return; |
5768 | leency | 637 | } |
7742 | leency | 638 | |
7970 | leency | 639 | if (!strncmp(#new_url,"mailto:", 7)) || (!strncmp(#new_url,"tel:", 4)) { |
640 | notify(#new_url); |
||
7755 | leency | 641 | return; |
7742 | leency | 642 | } |
4508 | leency | 643 | |
7771 | leency | 644 | if (http.transfer) { |
5774 | leency | 645 | StopLoading(); |
646 | } |
||
6730 | leency | 647 | |
7755 | leency | 648 | if (strrchr(#new_url, '#')!=0) { |
649 | anchors.take_anchor_from(#new_url); |
||
650 | OpenPage(#new_url); |
||
6730 | leency | 651 | return; |
652 | } |
||
653 | |||
7755 | leency | 654 | if (!strncmp(#new_url,"WebView:",8)) { |
655 | OpenPage(#new_url); |
||
7742 | leency | 656 | return; |
657 | } |
||
6730 | leency | 658 | |
7755 | leency | 659 | if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0) |
5774 | leency | 660 | { |
7755 | leency | 661 | if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true) |
6730 | leency | 662 | { |
7755 | leency | 663 | if (strchr(#new_url, '|')) { |
664 | ESBYTE[strchr(#new_url, '|')] = NULL; |
||
665 | RunProgram(#new_url, strlen(#new_url)+1+#new_url); |
||
666 | } else { |
||
667 | RunProgram("/sys/@open", #new_url); |
||
7422 | leency | 668 | } |
6730 | leency | 669 | return; |
670 | } |
||
5774 | leency | 671 | } |
7755 | leency | 672 | OpenPage(#new_url); |
673 | } |
||
674 | |||
675 | void EventSubmitOmnibox() |
||
676 | { |
||
677 | char new_url[URL_SIZE+1]; |
||
678 | if (!editURL[0]) return; |
||
679 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
||
680 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) { |
||
681 | OpenPage(#editURL); |
||
682 | } else { |
||
683 | strcpy(#new_url, "http://"); |
||
7970 | leency | 684 | strncat(#new_url, #editURL, URL_SIZE-1); |
7755 | leency | 685 | OpenPage(#new_url); |
6931 | leency | 686 | } |
5774 | leency | 687 | } |
688 | |||
7755 | leency | 689 | void LoadInternalPage(dword _bufdata, _in_bufsize){ |
690 | if (!_bufdata) || (!_in_bufsize) { |
||
8278 | leency | 691 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
7755 | leency | 692 | } else { |
693 | WB1.list.first = 0; //scroll page to the top |
||
694 | DrawOmnibox(); |
||
695 | if(!strrchr(#editURL, '#')) { |
||
696 | strcat(#editURL, #anchors.current); |
||
697 | DrawOmnibox(); |
||
698 | } |
||
8365 | leency | 699 | render_start_time = GetStartTime(); |
7759 | leency | 700 | WB1.ParseHtml(_bufdata, _in_bufsize); |
8302 | leency | 701 | // REJECTED. Reason: infinite redirect at Google Results. |
702 | /* |
||
703 | if (WB1.redirect) { // |
||
704 | get_absolute_url(#WB1.redirect, history.current()); |
||
705 | history.back(); |
||
706 | OpenPage(#WB1.redirect); |
||
707 | } |
||
708 | */ |
||
8413 | leency | 709 | DrawStatusBar(NULL); |
7771 | leency | 710 | DrawActiveTab(); |
7756 | leency | 711 | if (source_mode) { |
712 | source_mode = false; |
||
7799 | leency | 713 | WB1.custom_encoding = CH_CP866; |
7759 | leency | 714 | ShowSource(WB1.bufpointer, _in_bufsize); |
7757 | leency | 715 | } else { |
8016 | leency | 716 | WB1.DrawPage(); |
7756 | leency | 717 | } |
8445 | leency | 718 | if (WB1.img_url.count) { GetImg(true); DrawOmnibox(); } |
7742 | leency | 719 | } |
720 | } |
||
721 | |||
7799 | leency | 722 | bool UrlExtIs(dword base, ext) |
7742 | leency | 723 | { |
7755 | leency | 724 | if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true; |
7742 | leency | 725 | return false; |
726 | } |
||
727 | |||
728 | void DrawProgress() |
||
729 | { |
||
8330 | leency | 730 | dword pct; |
731 | if (!http.transfer) return; |
||
732 | if (http_get_type==PAGE) && (prbar.max) pct = prbar.value*30/prbar.max; else pct = 10; |
||
8336 | leency | 733 | if (http_get_type==IMG) pct = prbar.value * 70 / prbar.max + 30; |
8332 | leency | 734 | DrawBar(omnibox_edit.left-1, omnibox_edit.top+20, pct*omnibox_edit.width+16/100, 2, 0x72B7EB); |
7742 | leency | 735 | } |
736 | |||
7770 | leency | 737 | void EventShowPageMenu() |
6782 | leency | 738 | { |
8020 | leency | 739 | open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu); |
7780 | leency | 740 | menu_id = VIEW_SOURCE; |
6782 | leency | 741 | } |
742 | |||
7770 | leency | 743 | void EventShowLinkMenu() |
7759 | leency | 744 | { |
8020 | leency | 745 | open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #link_menu); |
7789 | simsanutiy | 746 | menu_id = IN_NEW_TAB; |
7759 | leency | 747 | } |
748 | |||
7780 | leency | 749 | void EventShowMainMenu() |
750 | { |
||
8020 | leency | 751 | open_lmenu(Form.cwidth - PADDING -4, PADDING + TSZE + 3, |
752 | MENU_TOP_RIGHT, NULL, #main_menu); |
||
7780 | leency | 753 | menu_id = OPEN_FILE; |
754 | } |
||
755 | |||
7770 | leency | 756 | void EventShowEncodingsList() |
7758 | leency | 757 | { |
8020 | leency | 758 | open_lmenu(Form.cwidth-4, Form.cheight - STATUSBAR_H + 12, |
759 | MENU_BOT_RIGHT, WB1.cur_encoding + 1, |
||
760 | "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866"); |
||
7780 | leency | 761 | menu_id = ENCODINGS; |
7758 | leency | 762 | } |
763 | |||
7780 | leency | 764 | void ProcessMenuClick() |
6795 | leency | 765 | { |
7780 | leency | 766 | int click_id; |
7910 | leency | 767 | if (menu_id) { |
768 | if (click_id = get_menu_click()) { |
||
769 | click_id += menu_id - 1; |
||
8332 | leency | 770 | ProcessButtonClick(click_id); |
7910 | leency | 771 | } |
772 | if (!menu_process_id) menu_id = NULL; |
||
7780 | leency | 773 | } |
6795 | leency | 774 | } |
775 | |||
7743 | leency | 776 | void EventSeachWeb() |
777 | { |
||
7755 | leency | 778 | char new_url[URL_SIZE+1]; |
8492 | leency | 779 | replace_char(#editURL, ' ', '+', URL_SIZE); |
7755 | leency | 780 | strcpy(#new_url, "https://www.google.com/search?q="); |
781 | strncat(#new_url, #editURL, URL_SIZE); |
||
782 | OpenPage(#new_url); |
||
7743 | leency | 783 | } |
784 | |||
7748 | leency | 785 | void EventOpenDialog() |
786 | { |
||
787 | OpenDialog_start stdcall (#o_dialog); |
||
788 | if (o_dialog.status) { |
||
7755 | leency | 789 | OpenPage(#openfile_path); |
7748 | leency | 790 | } |
791 | } |
||
792 | |||
7750 | leency | 793 | void EventViewSource() |
794 | { |
||
7771 | leency | 795 | source_mode = true; |
796 | EventOpenNewTab(history.current()); |
||
7750 | leency | 797 | } |
798 | |||
7893 | leency | 799 | void EventRefreshPage() |
800 | { |
||
801 | if (http.transfer) { |
||
802 | StopLoading(); |
||
803 | draw_window(); |
||
804 | } else { |
||
805 | OpenPage(history.current()); |
||
806 | } |
||
807 | } |
||
808 | |||
7765 | leency | 809 | void EventUpdateBrowser() |
810 | { |
||
811 | dword downloader_id, slot_n; |
||
812 | dword current_size; |
||
813 | dword new_size; |
||
814 | |||
815 | draw_window(); |
||
816 | |||
8278 | leency | 817 | downloader_id = EventOpenDownloader(#update_param); |
7765 | leency | 818 | do { |
819 | slot_n = GetProcessSlot(downloader_id); |
||
820 | pause(10); |
||
821 | } while (slot_n!=0); |
||
822 | |||
8392 | leency | 823 | current_size = get_file_size(#program_path); |
824 | new_size = get_file_size("/tmp0/1/Downloads/WebView.com"); |
||
7765 | leency | 825 | |
8413 | leency | 826 | if (!new_size) || (new_size<5000) { notify(#update_download_error); return; } |
827 | if (current_size == new_size) { notify(#update_is_current); return; } |
||
7765 | leency | 828 | |
8332 | leency | 829 | if (CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) { |
7765 | leency | 830 | notify(#update_can_not_copy); |
831 | } else { |
||
832 | notify(#update_ok); |
||
833 | RunProgram(#program_path, history.current()); |
||
834 | ExitProcess(); |
||
835 | } |
||
836 | } |
||
837 | |||
8413 | leency | 838 | void DrawStatusBar(dword _msg) |
6795 | leency | 839 | { |
7970 | leency | 840 | dword status_y = Form.cheight - STATUSBAR_H + 4; |
841 | dword status_w = Form.cwidth - 90; |
||
8417 | leency | 842 | if (Form.status_window>2) return; |
7806 | leency | 843 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); |
8413 | leency | 844 | if (_msg) { |
845 | ESI = math.min(status_w/6, strlen(_msg)); |
||
846 | WriteText(10, status_y, 0, sc.work_text, _msg); |
||
7758 | leency | 847 | } |
7970 | leency | 848 | DefineHiddenButton(status_w+20, status_y-3, 60, 12, CHANGE_ENCODING); |
849 | WriteTextCenter(status_w+20, status_y, 60, sc.work_text, WB1.cur_encoding*10+#charsets); |
||
7758 | leency | 850 | } |
851 | |||
852 | void DrawOmnibox() |
||
853 | { |
||
7784 | leency | 854 | int imgxoff; |
7758 | leency | 855 | |
8332 | leency | 856 | DrawOvalBorder(omnibox_edit.left-2, omnibox_edit.top-3, omnibox_edit.width+18, 24, sc.work_graph, |
7806 | leency | 857 | sc.work_graph, sc.work_graph, sc.work_dark); |
8332 | leency | 858 | DrawBar(omnibox_edit.left-1, omnibox_edit.top-2, omnibox_edit.width+18, 1, 0xD8DCD8); |
859 | DrawBar(omnibox_edit.left-1, omnibox_edit.top-1, omnibox_edit.width+18, 1, omnibox_edit.color); |
||
860 | DrawBar(omnibox_edit.left-1, omnibox_edit.top, 1, 22, omnibox_edit.color); |
||
7758 | leency | 861 | |
8332 | leency | 862 | if (omnibox_edit.flags & ed_focus) omnibox_edit.flags = ed_focus; else omnibox_edit.flags = 0; |
863 | EditBox_UpdateText(#omnibox_edit, omnibox_edit.flags); |
||
864 | edit_box_draw stdcall(#omnibox_edit); |
||
7784 | leency | 865 | if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0; |
8332 | leency | 866 | _PutImage(omnibox_edit.left+omnibox_edit.width+1, omnibox_edit.top-1, 16, 23, imgxoff + #editbox_icons); |
867 | DefineHiddenButton(omnibox_edit.left+omnibox_edit.width-1, omnibox_edit.top-2, 17, 23, REFRESH_BUTTON); |
||
7758 | leency | 868 | |
869 | DrawProgress(); |
||
870 | } |
||
871 | |||
7771 | leency | 872 | void SetOmniboxText(dword _text) |
873 | { |
||
8336 | leency | 874 | edit_box_set_text stdcall (#omnibox_edit, _text); |
8355 | leency | 875 | omnibox_edit.pos = omnibox_edit.flags = 0; |
876 | DrawOmnibox(); |
||
7771 | leency | 877 | } |
7758 | leency | 878 | |
7970 | leency | 879 | dword GetAbsoluteActiveURL() |
880 | { |
||
881 | char abs_url[URL_SIZE]; |
||
882 | if (links.active_url) { |
||
883 | strncpy(#abs_url, links.active_url, URL_SIZE); |
||
8291 | leency | 884 | get_absolute_url(#abs_url, history.current()); |
7970 | leency | 885 | return #abs_url; |
886 | } |
||
887 | return 0; |
||
888 | } |
||
7771 | leency | 889 | |
8305 | leency | 890 | void CheckContentType() |
891 | { |
||
892 | char content_type[64]; |
||
8319 | leency | 893 | if (http.header_field("content-type", #content_type, sizeof(content_type))) // application || image |
8413 | leency | 894 | |
8492 | leency | 895 | if (strchr(#content_type, '=')) { |
896 | WB1.custom_encoding = get_encoding_type_by_name(EAX+1); |
||
897 | } |
||
898 | |||
8413 | leency | 899 | if (content_type[0] == 'i') { |
900 | EventDownloadAndOpenImage(http.cur_url); |
||
901 | StopLoading(); |
||
902 | }if (content_type[0] == 'a') { |
||
8444 | leency | 903 | EventOpenDownloader(http.cur_url); |
8305 | leency | 904 | StopLoading(); |
905 | } |
||
906 | } |
||
907 | |||
8413 | leency | 908 | void EventDownloadAndOpenImage(dword _url) |
909 | { |
||
910 | char image_download_url[URL_SIZE]; |
||
911 | strcpy(#image_download_url, "-eo "); |
||
912 | strncat(#image_download_url, _url, URL_SIZE); |
||
913 | EventOpenDownloader(#image_download_url); |
||
914 | } |
||
915 | |||
8305 | leency | 916 | void HandleRedirect() |
917 | { |
||
918 | char redirect_url[URL_SIZE]; |
||
8319 | leency | 919 | http.header_field("location", #redirect_url, URL_SIZE); |
8413 | leency | 920 | get_absolute_url(#redirect_url, http.cur_url); |
8305 | leency | 921 | http.hfree(); |
922 | if (http_get_type==PAGE) OpenPage(#redirect_url); |
||
8330 | leency | 923 | else if (http_get_type==IMG) GetUrl(#redirect_url); |
8305 | leency | 924 | } |
925 | |||
8336 | leency | 926 | dword GetImg(bool _new) |
8016 | leency | 927 | { |
8336 | leency | 928 | int i; |
8330 | leency | 929 | if (!show_images) return; |
8336 | leency | 930 | http_get_type = IMG; |
931 | |||
8396 | leency | 932 | for (i = 0; i < WB1.img_url.count; i++) |
8336 | leency | 933 | { |
8396 | leency | 934 | cur_img_url = WB1.img_url.get(i); |
8440 | leency | 935 | if (debug_mode) {debug("get img: ");debugln(cur_img_url);} |
8336 | leency | 936 | if (cache.has(cur_img_url)==false) { |
8396 | leency | 937 | prbar.max = WB1.img_url.count; |
8336 | leency | 938 | prbar.value = i; |
8413 | leency | 939 | if (GetUrl(cur_img_url)) {DrawStatusBar(cur_img_url); DrawProgress(); return;} |
8336 | leency | 940 | } |
8016 | leency | 941 | } |
8336 | leency | 942 | if (_new) return; |
8016 | leency | 943 | DrawOmnibox(); |
8413 | leency | 944 | DrawStatusBar(T_RENDERING); |
8457 | leency | 945 | WB1.ParseHtml(WB1.bufpointer, WB1.bufsize); |
8016 | leency | 946 | WB1.DrawPage(); |
8413 | leency | 947 | debugln(sprintf(#param, T_DONE_IN_SEC, GetStartTime()-render_start_time/100)); |
948 | DrawStatusBar(NULL); |
||
8016 | leency | 949 | } |
950 | |||
5631 | pavelyakov | 951 | stop:>5000)>>=5)>>=>280)>120)> |