Pass the UIProvider to FileManager::handle() as needed.

This commit is contained in:
Ms2ger 2016-11-18 13:09:23 +01:00
parent f672bf9eab
commit ae1340bf50
6 changed files with 88 additions and 94 deletions

View file

@ -7,7 +7,7 @@ use connector::create_http_connector;
use data_loader::decode;
use devtools_traits::DevtoolsControlMsg;
use fetch::cors_cache::CorsCache;
use filemanager_thread::{FileManager, UIProvider};
use filemanager_thread::FileManager;
use http_loader::{HttpState, set_default_accept_encoding, set_default_accept_language, set_request_cookies};
use http_loader::{NetworkHttpRequestFactory, ReadResult, StreamedResponse, obtain_response, read_block};
use http_loader::{auth_from_cache, determine_request_referrer, set_cookies_from_headers};
@ -52,28 +52,28 @@ enum Data {
Done,
}
pub struct FetchContext<UI: 'static + UIProvider> {
pub struct FetchContext {
pub state: HttpState,
pub user_agent: Cow<'static, str>,
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,
pub filemanager: FileManager<UI>,
pub filemanager: FileManager,
}
type DoneChannel = Option<(Sender<Data>, Receiver<Data>)>;
/// [Fetch](https://fetch.spec.whatwg.org#concept-fetch)
pub fn fetch<UI: 'static + UIProvider>(request: Rc<Request>,
target: &mut Target,
context: &FetchContext<UI>)
-> Response {
pub fn fetch(request: Rc<Request>,
target: &mut Target,
context: &FetchContext)
-> Response {
fetch_with_cors_cache(request, &mut CorsCache::new(), target, context)
}
pub fn fetch_with_cors_cache<UI: 'static + UIProvider>(request: Rc<Request>,
cache: &mut CorsCache,
target: &mut Target,
context: &FetchContext<UI>)
-> Response {
pub fn fetch_with_cors_cache(request: Rc<Request>,
cache: &mut CorsCache,
target: &mut Target,
context: &FetchContext)
-> Response {
// Step 1
if request.window.get() == Window::Client {
// TODO: Set window to request's client object if client is a Window object
@ -136,14 +136,14 @@ pub fn fetch_with_cors_cache<UI: 'static + UIProvider>(request: Rc<Request>,
}
/// [Main fetch](https://fetch.spec.whatwg.org/#concept-main-fetch)
fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
cache: &mut CorsCache,
cors_flag: bool,
recursive_flag: bool,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext<UI>)
-> Response {
fn main_fetch(request: Rc<Request>,
cache: &mut CorsCache,
cors_flag: bool,
recursive_flag: bool,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext)
-> Response {
// TODO: Implement main fetch spec
// Step 1
@ -400,12 +400,12 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
}
/// [Basic fetch](https://fetch.spec.whatwg.org#basic-fetch)
fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
cache: &mut CorsCache,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext<UI>)
-> Response {
fn basic_fetch(request: Rc<Request>,
cache: &mut CorsCache,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext)
-> Response {
let url = request.current_url();
match url.scheme() {
@ -492,15 +492,15 @@ fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
}
/// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch)
fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
cache: &mut CorsCache,
cors_flag: bool,
cors_preflight_flag: bool,
authentication_fetch_flag: bool,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext<UI>)
-> Response {
fn http_fetch(request: Rc<Request>,
cache: &mut CorsCache,
cors_flag: bool,
cors_preflight_flag: bool,
authentication_fetch_flag: bool,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext)
-> Response {
// This is a new async fetch, reset the channel we are waiting on
*done_chan = None;
// Step 1
@ -667,14 +667,14 @@ fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
}
/// [HTTP redirect fetch](https://fetch.spec.whatwg.org#http-redirect-fetch)
fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
cache: &mut CorsCache,
response: Response,
cors_flag: bool,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext<UI>)
-> Response {
fn http_redirect_fetch(request: Rc<Request>,
cache: &mut CorsCache,
response: Response,
cors_flag: bool,
target: &mut Target,
done_chan: &mut DoneChannel,
context: &FetchContext)
-> Response {
// Step 1
assert_eq!(response.return_internal.get(), true);
@ -748,12 +748,12 @@ fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
}
/// [HTTP network or cache fetch](https://fetch.spec.whatwg.org#http-network-or-cache-fetch)
fn http_network_or_cache_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
credentials_flag: bool,
authentication_fetch_flag: bool,
done_chan: &mut DoneChannel,
context: &FetchContext<UI>)
-> Response {
fn http_network_or_cache_fetch(request: Rc<Request>,
credentials_flag: bool,
authentication_fetch_flag: bool,
done_chan: &mut DoneChannel,
context: &FetchContext)
-> Response {
// TODO: Implement Window enum for Request
let request_has_no_window = true;
@ -970,11 +970,11 @@ fn http_network_or_cache_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
}
/// [HTTP network fetch](https://fetch.spec.whatwg.org/#http-network-fetch)
fn http_network_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
credentials_flag: bool,
done_chan: &mut DoneChannel,
context: &FetchContext<UI>)
-> Response {
fn http_network_fetch(request: Rc<Request>,
credentials_flag: bool,
done_chan: &mut DoneChannel,
context: &FetchContext)
-> Response {
// TODO: Implement HTTP network fetch spec
// Step 1
@ -1158,10 +1158,10 @@ fn http_network_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
}
/// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch)
fn cors_preflight_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
cache: &mut CorsCache,
context: &FetchContext<UI>)
-> Response {
fn cors_preflight_fetch(request: Rc<Request>,
cache: &mut CorsCache,
context: &FetchContext)
-> Response {
// Step 1
let mut preflight = Request::new(request.current_url(), Some(request.origin.borrow().clone()),
request.is_service_worker_global_scope, request.pipeline_id.get());