mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +01:00
Add fetch_async to PendingAsyncLoad, DocumentLoader and Document
This commit is contained in:
parent
2bb95989c5
commit
d4816762fa
3 changed files with 32 additions and 3 deletions
|
@ -520,6 +520,13 @@ impl PendingAsyncLoad {
|
|||
let consumer = LoadConsumer::Listener(listener);
|
||||
self.core_resource_thread.send(CoreResourceMsg::Load(load_data, consumer, None)).unwrap();
|
||||
}
|
||||
|
||||
/// Initiate the fetch associated with this pending load.
|
||||
pub fn fetch_async(mut self, request: RequestInit, fetch_target: IpcSender<FetchResponseMsg>) {
|
||||
self.guard.neuter();
|
||||
|
||||
self.core_resource_thread.send(CoreResourceMsg::Fetch(request, fetch_target)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Message sent in response to `Load`. Contains metadata, and a port
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
use dom::bindings::js::JS;
|
||||
use dom::document::Document;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
||||
use net_traits::{PendingAsyncLoad, AsyncResponseTarget, LoadContext};
|
||||
use net_traits::{ResourceThreads, IpcSend};
|
||||
use net_traits::request::RequestInit;
|
||||
use net_traits::{AsyncResponseTarget, PendingAsyncLoad, LoadContext};
|
||||
use net_traits::{FetchResponseMsg, ResourceThreads, IpcSend};
|
||||
use std::thread;
|
||||
use url::Url;
|
||||
|
||||
|
@ -148,6 +150,17 @@ impl DocumentLoader {
|
|||
pending.load_async(listener)
|
||||
}
|
||||
|
||||
/// Initiate a new fetch.
|
||||
pub fn fetch_async(&mut self,
|
||||
load: LoadType,
|
||||
request: RequestInit,
|
||||
fetch_target: IpcSender<FetchResponseMsg>,
|
||||
referrer: &Document,
|
||||
referrer_policy: Option<ReferrerPolicy>) {
|
||||
let pending = self.prepare_async_load(load, referrer, referrer_policy);
|
||||
pending.fetch_async(request, fetch_target);
|
||||
}
|
||||
|
||||
/// Mark an in-progress network request complete.
|
||||
pub fn finish_load(&mut self, load: &LoadType) {
|
||||
let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == *load);
|
||||
|
|
|
@ -95,9 +95,10 @@ use js::jsapi::JS_GetRuntime;
|
|||
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
||||
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
||||
use net_traits::{AsyncResponseTarget, IpcSend, PendingAsyncLoad};
|
||||
use net_traits::{AsyncResponseTarget, FetchResponseMsg, IpcSend, PendingAsyncLoad};
|
||||
use net_traits::CookieSource::NonHTTP;
|
||||
use net_traits::CoreResourceMsg::{GetCookiesForUrl, SetCookiesForUrl};
|
||||
use net_traits::request::RequestInit;
|
||||
use net_traits::response::HttpsState;
|
||||
use num_traits::ToPrimitive;
|
||||
use origin::Origin;
|
||||
|
@ -1433,6 +1434,14 @@ impl Document {
|
|||
loader.load_async(load, listener, self, referrer_policy);
|
||||
}
|
||||
|
||||
pub fn fetch_async(&self, load: LoadType,
|
||||
request: RequestInit,
|
||||
fetch_target: IpcSender<FetchResponseMsg>,
|
||||
referrer_policy: Option<ReferrerPolicy>) {
|
||||
let mut loader = self.loader.borrow_mut();
|
||||
loader.fetch_async(load, request, fetch_target, self, referrer_policy);
|
||||
}
|
||||
|
||||
pub fn finish_load(&self, load: LoadType) {
|
||||
debug!("Document got finish_load: {:?}", load);
|
||||
// The parser might need the loader, so restrict the lifetime of the borrow.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue