mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Make sure that we ignore responses from old requests
This commit is contained in:
parent
c8806767a0
commit
f1d012d782
1 changed files with 19 additions and 11 deletions
|
@ -1030,10 +1030,8 @@ impl HTMLMediaElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
if self.seeking.get() {
|
// The fetch request associated with this seek already takes
|
||||||
// This will cancel only the sync part of the seek algorithm.
|
// care of cancelling any previous requests.
|
||||||
self.generation_id.set(self.generation_id.get() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
// The flag will be cleared when the media engine tells us the seek was done.
|
// The flag will be cleared when the media engine tells us the seek was done.
|
||||||
|
@ -1687,6 +1685,11 @@ impl FetchResponseListener for HTMLMediaElementContext {
|
||||||
fn process_response(&mut self, metadata: Result<FetchMetadata, NetworkError>) {
|
fn process_response(&mut self, metadata: Result<FetchMetadata, NetworkError>) {
|
||||||
let elem = self.elem.root();
|
let elem = self.elem.root();
|
||||||
|
|
||||||
|
if elem.generation_id.get() != self.generation_id {
|
||||||
|
// A new fetch request was triggered, so we ignore this response.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.metadata = metadata.ok().map(|m| match m {
|
self.metadata = metadata.ok().map(|m| match m {
|
||||||
FetchMetadata::Unfiltered(m) => m,
|
FetchMetadata::Unfiltered(m) => m,
|
||||||
FetchMetadata::Filtered { unsafe_, .. } => unsafe_,
|
FetchMetadata::Filtered { unsafe_, .. } => unsafe_,
|
||||||
|
@ -1740,17 +1743,20 @@ impl FetchResponseListener for HTMLMediaElementContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_response_chunk(&mut self, payload: Vec<u8>) {
|
fn process_response_chunk(&mut self, payload: Vec<u8>) {
|
||||||
if self.ignore_response {
|
let elem = self.elem.root();
|
||||||
// An error was received previously, skip processing the payload.
|
if self.ignore_response || elem.generation_id.get() != self.generation_id {
|
||||||
|
// An error was received previously or we triggered a new fetch request,
|
||||||
|
// skip processing the payload.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.bytes_fetched += payload.len();
|
self.bytes_fetched += payload.len();
|
||||||
|
|
||||||
let elem = self.elem.root();
|
|
||||||
// Push input data into the player.
|
// Push input data into the player.
|
||||||
if let Err(e) = elem.player.push_data(payload) {
|
if let Err(e) = elem.player.push_data(payload) {
|
||||||
eprintln!("Could not push input data to player {:?}", e);
|
warn!("Could not push input data to player {:?}", e);
|
||||||
|
elem.fetch_canceller.borrow_mut().cancel();
|
||||||
|
self.ignore_response = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1769,9 +1775,10 @@ impl FetchResponseListener for HTMLMediaElementContext {
|
||||||
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
|
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
|
||||||
fn process_response_eof(&mut self, status: Result<ResourceFetchTiming, NetworkError>) {
|
fn process_response_eof(&mut self, status: Result<ResourceFetchTiming, NetworkError>) {
|
||||||
let elem = self.elem.root();
|
let elem = self.elem.root();
|
||||||
if self.ignore_response {
|
if self.ignore_response && elem.generation_id.get() == self.generation_id {
|
||||||
// An error was received previously, skip processing the payload
|
// An error was received previously and no new fetch request was triggered, so
|
||||||
// and notify the media backend that we are done pushing data.
|
// we skip processing the payload and notify the media backend that we are done
|
||||||
|
// pushing data.
|
||||||
if let Err(e) = elem.player.end_of_stream() {
|
if let Err(e) = elem.player.end_of_stream() {
|
||||||
warn!("Could not signal EOS to player {:?}", e);
|
warn!("Could not signal EOS to player {:?}", e);
|
||||||
}
|
}
|
||||||
|
@ -1858,6 +1865,7 @@ impl PreInvoke for HTMLMediaElementContext {
|
||||||
|
|
||||||
impl HTMLMediaElementContext {
|
impl HTMLMediaElementContext {
|
||||||
fn new(elem: &HTMLMediaElement, url: ServoUrl) -> HTMLMediaElementContext {
|
fn new(elem: &HTMLMediaElement, url: ServoUrl) -> HTMLMediaElementContext {
|
||||||
|
elem.generation_id.set(elem.generation_id.get() + 1);
|
||||||
HTMLMediaElementContext {
|
HTMLMediaElementContext {
|
||||||
elem: Trusted::new(elem),
|
elem: Trusted::new(elem),
|
||||||
metadata: None,
|
metadata: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue