/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * * License, v. 2.0. If a copy of the MPL was not distributed with this * file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
auto notify = MakeScopeExit([&]() { if (NS_FAILED(rv)) { // Make sure we notify any <link preload> elements when opening fails // because of various technical or security reasons.
NotifyStart(channel); // Using the non-channel overload of this method to make it work even // before NotifyOpen has been called on this preload. We are not // switching between channels, so it's safe to do so.
NotifyStop(rv);
}
});
// Doing this now so that we have the channel and tainting set on it properly // to notify the proper event (load or error) on the associated preload tags // when the CSP check fails.
rv = CheckContentPolicy(aURI, aDocument); if (NS_FAILED(rv)) { return rv;
}
nsresult FetchPreloader::AsyncConsume(nsIStreamListener* aListener) { if (NS_FAILED(mAsyncConsumeResult)) { // Already being consumed or failed to open. return mAsyncConsumeResult;
}
if (!mConsumeListener) { // Called before we are getting response from the channel.
mConsumeListener = aListener;
} else { // Channel already started, push cached calls to this listener. // Can't be anything else than the `Cache`, hence a safe static_cast.
Cache* cache = static_cast<Cache*>(mConsumeListener.get());
cache->AsyncConsume(aListener);
}
return NS_OK;
}
// static void FetchPreloader::PrioritizeAsPreload(nsIChannel* aChannel) { if (nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(aChannel)) {
cos->AddClassFlags(nsIClassOfService::Unblocked);
}
}
// We want 404 or other types of server responses to be treated as 'error'. if (nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(request)) {
uint32_t responseStatus = 0;
Unused << httpChannel->GetResponseStatus(&responseStatus); if (responseStatus / 100 != 2) {
status = NS_ERROR_FAILURE;
}
}
// Fetch preloader wants to keep the channel around so that consumers like XHR // can access it even after the preload is done.
nsCOMPtr<nsIChannel> channel = mChannel;
NotifyStop(request, status);
mChannel.swap(channel); return NS_OK;
}
void FetchPreloader::Cache::AsyncConsume(nsIStreamListener* aListener) { // Must dispatch for two reasons: // 1. This is called directly from FetchLoader::AsyncConsume, which must // behave the same way as nsIChannel::AsyncOpen. // 2. In case there are already stream listener events scheduled on the main // thread we preserve the order - those will still end up in Cache.
// * The `Cache` object is fully main thread only for now, doesn't support // retargeting, but it can be improved to allow it.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.