📄 task.c
字号:
static voidses_imgmap(struct session *ses){ struct cache_entry *cached = find_in_cache(ses->loading_uri); struct document_view *doc_view = current_frame(ses); struct fragment *fragment; struct memory_list *ml; struct menu_item *menu; if (!cached) { INTERNAL("can't find cache entry"); return; } fragment = get_cache_fragment(cached); if (!fragment) return; if (!doc_view || !doc_view->document) return; global_doc_opts = &doc_view->document->options; if (get_image_map(cached->head, fragment->data, fragment->data + fragment->length, &menu, &ml, ses->loading_uri, ses->task.target_frame, get_opt_codepage_tree(ses->tab->term->spec, "charset"), get_opt_codepage("document.codepage.assume"), get_opt_bool("document.codepage.force_assumed"))) return; add_empty_window(ses->tab->term, (void (*)(void *)) freeml, ml); do_menu(ses->tab->term, menu, ses, 0);}static intdo_move(struct session *ses, struct download **download_p){ struct cache_entry *cached; assert(download_p && *download_p); assertm(ses->loading_uri, "no ses->loading_uri"); if_assert_failed return 0; if (ses->loading_uri->protocol == PROTOCOL_UNKNOWN) return 0; /* Handling image map needs to scan the source of the loaded document * so all of it has to be available. */ if (ses->task.type == TASK_IMGMAP && is_in_progress_state((*download_p)->state)) return 0; cached = (*download_p)->cached; if (!cached) return 0; if (cached->redirect && ses->redirect_cnt++ < MAX_REDIRECTS) { enum task_type task = ses->task.type; if (task == TASK_HISTORY && !have_location(ses)) goto b; assertm(compare_uri(cached->uri, ses->loading_uri, URI_BASE), "Redirecting using bad base URI"); if (cached->redirect->protocol == PROTOCOL_UNKNOWN) return 0; abort_loading(ses, 0); if (have_location(ses)) *download_p = &cur_loc(ses)->download; else *download_p = NULL; set_session_referrer(ses, cached->uri); switch (task) { case TASK_NONE: break; case TASK_FORWARD: { protocol_external_handler *fn; struct uri *uri = cached->redirect; fn = get_protocol_external_handler(uri->protocol); if (fn) { fn(ses, uri); *download_p = NULL; return 0; } } /* Fall through. */ case TASK_IMGMAP: ses_goto(ses, cached->redirect, ses->task.target_frame, NULL, CACHE_MODE_NORMAL, task, 1); return 2; case TASK_HISTORY: ses_goto(ses, cached->redirect, NULL, ses->task.target_location, CACHE_MODE_NORMAL, TASK_RELOAD, 1); return 2; case TASK_RELOAD: ses_goto(ses, cached->redirect, NULL, NULL, ses->reloadlevel, TASK_RELOAD, 1); return 2; } }b: if (ses->display_timer != -1) { kill_timer(ses->display_timer); ses->display_timer = -1; } switch (ses->task.type) { case TASK_NONE: break; case TASK_FORWARD: if (ses_chktype(ses, &ses->loading, cached, 0)) { free_task(ses); reload(ses, CACHE_MODE_NORMAL); return 2; } break; case TASK_IMGMAP: ses_imgmap(ses); break; case TASK_HISTORY: ses_history_move(ses); break; case TASK_RELOAD: ses->task.target_location = cur_loc(ses)->prev; ses_history_move(ses); ses_forward(ses, 0); break; } if (is_in_progress_state((*download_p)->state)) { *download_p = &cur_loc(ses)->download; change_connection(&ses->loading, *download_p, PRI_MAIN, 0); } else { cur_loc(ses)->download.state = ses->loading.state; } free_task(ses); return 1;}voidloading_callback(struct download *download, struct session *ses){ int d; assertm(ses->task.type, "loading_callback: no ses->task"); if_assert_failed return; d = do_move(ses, &download); if (!download) return; if (d == 2) goto end; if (d == 1) { download->callback = (void (*)(struct download *, void *)) doc_loading_callback; display_timer(ses); } if (is_in_result_state(download->state)) { if (ses->task.type) free_task(ses); if (d == 1) doc_loading_callback(download, ses); } if (is_in_result_state(download->state) && download->state != S_OK) { struct uri *uri = download->conn ? download->conn->uri : NULL; print_error_dialog(ses, download->state, uri, download->pri); if (d == 0) reload(ses, CACHE_MODE_NORMAL); }end: check_questions_queue(ses); print_screen_status(ses);}static voiddo_follow_url(struct session *ses, struct uri *uri, unsigned char *target, enum task_type task, enum cache_mode cache_mode, int do_referrer){ struct uri *referrer = NULL; protocol_external_handler *external_handler; if (!uri) { print_error_dialog(ses, S_BAD_URL, uri, PRI_CANCEL); return; } external_handler = get_protocol_external_handler(uri->protocol); if (external_handler) { external_handler(ses, uri); return; } if (target && !strcmp(target, "_blank")) { int mode = get_opt_int("document.browse.links.target_blank"); if (mode > 0) { struct session *new_ses; new_ses = init_session(ses, ses->tab->term, uri, (mode == 2)); if (new_ses) ses = new_ses; } } ses->reloadlevel = cache_mode; if (ses->task.type == task) { if (compare_uri(ses->loading_uri, uri, 0)) { /* We're already loading the URL. */ return; } } abort_loading(ses, 0); if (do_referrer) { struct document_view *doc_view = current_frame(ses); if (doc_view && doc_view->document) referrer = doc_view->document->uri; } set_session_referrer(ses, referrer); ses_goto(ses, uri, target, NULL, cache_mode, task, 0);}static voidfollow_url(struct session *ses, struct uri *uri, unsigned char *target, enum task_type task, enum cache_mode cache_mode, int referrer){#ifdef CONFIG_SCRIPTING static int follow_url_event_id = EVENT_NONE; unsigned char *uristring = uri ? get_uri_string(uri, URI_BASE | URI_FRAGMENT) : NULL; if (!uristring) { do_follow_url(ses, uri, target, task, cache_mode, referrer); return; } set_event_id(follow_url_event_id, "follow-url"); trigger_event(follow_url_event_id, &uristring, ses); if (!uristring || !*uristring) { mem_free_if(uristring); return; } /* FIXME: Compare if uristring and struri(uri) are equal */ /* FIXME: When uri->post will no longer be an encoded string (but * hopefully some refcounted object) we will have to assign the post * data object to the translated URI. */ uri = get_translated_uri(uristring, ses->tab->term->cwd); mem_free(uristring);#endif do_follow_url(ses, uri, target, task, cache_mode, referrer);#ifdef CONFIG_SCRIPTING if (uri) done_uri(uri);#endif}voidgoto_uri(struct session *ses, struct uri *uri){ follow_url(ses, uri, NULL, TASK_FORWARD, CACHE_MODE_NORMAL, 0);}voidgoto_uri_frame(struct session *ses, struct uri *uri, unsigned char *target, enum cache_mode cache_mode){ follow_url(ses, uri, target, TASK_FORWARD, cache_mode, 1);}/* menu_func */voidmap_selected(struct terminal *term, void *ld_, void *ses_){ struct link_def *ld = ld_; struct session *ses = ses_; struct uri *uri = get_uri(ld->link, 0); goto_uri_frame(ses, uri, ld->target, CACHE_MODE_NORMAL); if (uri) done_uri(uri);}voidgoto_url(struct session *ses, unsigned char *url){ struct uri *uri = get_uri(url, 0); goto_uri(ses, uri); if (uri) done_uri(uri);}struct uri *get_hooked_uri(unsigned char *uristring, struct session *ses, unsigned char *cwd){ struct uri *uri;#if defined(CONFIG_SCRIPTING) || defined(CONFIG_URI_REWRITE) static int goto_url_event_id = EVENT_NONE; uristring = stracpy(uristring); if (!uristring) return NULL; set_event_id(goto_url_event_id, "goto-url"); trigger_event(goto_url_event_id, &uristring, ses); if (!uristring) return NULL;#endif uri = *uristring ? get_translated_uri(uristring, cwd) : NULL;#if defined(CONFIG_SCRIPTING) || defined(CONFIG_URI_REWRITE) mem_free(uristring);#endif return uri;}voidgoto_url_with_hook(struct session *ses, unsigned char *url){ unsigned char *cwd = ses->tab->term->cwd; struct uri *uri; /* Bail out if passed empty string from goto-url dialog */ if (!*url) return; uri = get_hooked_uri(url, ses, cwd); goto_uri(ses, uri); if (uri) done_uri(uri);}intgoto_url_home(struct session *ses){ unsigned char *homepage = get_opt_str("ui.sessions.homepage"); if (!*homepage) homepage = getenv("WWW_HOME"); if (!homepage || !*homepage) homepage = WWW_HOME_URL; if (!homepage || !*homepage) return 0; goto_url_with_hook(ses, homepage); return 1;}/* TODO: Should there be goto_imgmap_reload() ? */voidgoto_imgmap(struct session *ses, struct uri *uri, unsigned char *target){ follow_url(ses, uri, target, TASK_IMGMAP, CACHE_MODE_NORMAL, 1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -