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