mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
fadc450e48
Previously, for `rel=preload as=fetch`, the internal priority, `nsISupportsPriority`, was not adjusted. Now, the adjustment happens in `FetchPreloader::CreateChannel`. For `rel=preload as=font`, previously, the internal priority was always set to high in `FontLoaderUtils::BuildChannelSetup`. Now, the internal priority is a parameter, whose value potentially depends on the `fetchpriority` attribute. Note the minor correction of calling `SetPriority` instead of `AdjustPriority` in `FontLoaderUtils::BuildChannelSetup`. Differential Revision: https://phabricator.services.mozilla.com/D194205
109 lines
3.4 KiB
C++
109 lines
3.4 KiB
C++
/* -*- 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/. */
|
|
|
|
#ifndef FetchPreloader_h_
|
|
#define FetchPreloader_h_
|
|
|
|
#include "mozilla/PreloaderBase.h"
|
|
#include "mozilla/Variant.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIAsyncOutputStream.h"
|
|
#include "nsIAsyncInputStream.h"
|
|
#include "nsIContentPolicy.h"
|
|
#include "nsIStreamListener.h"
|
|
|
|
class nsIChannel;
|
|
class nsILoadGroup;
|
|
class nsIInterfaceRequestor;
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
enum class ReferrerPolicy : uint8_t;
|
|
}
|
|
|
|
class FetchPreloader : public PreloaderBase, public nsIStreamListener {
|
|
NS_DECL_ISUPPORTS
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
FetchPreloader();
|
|
|
|
// @param aSupportsPriorityValue see <nsISupportsPriority.idl>.
|
|
nsresult OpenChannel(const PreloadHashKey& aKey, nsIURI* aURI,
|
|
const CORSMode aCORSMode,
|
|
const dom::ReferrerPolicy& aReferrerPolicy,
|
|
dom::Document* aDocument, uint64_t aEarlyHintPreloaderId,
|
|
int32_t aSupportsPriorityValue);
|
|
|
|
// PreloaderBase
|
|
nsresult AsyncConsume(nsIStreamListener* aListener) override;
|
|
|
|
static void PrioritizeAsPreload(nsIChannel* aChannel);
|
|
|
|
protected:
|
|
explicit FetchPreloader(nsContentPolicyType aContentPolicyType);
|
|
virtual ~FetchPreloader() = default;
|
|
|
|
// Create and setup the channel with necessary security properties and
|
|
// the nsISupportsPriority value. This is overridable by
|
|
// subclasses to allow different initial conditions.
|
|
//
|
|
// @param aSupportsPriorityValue see <nsISupportsPriority.idl>.
|
|
virtual nsresult CreateChannel(
|
|
nsIChannel** aChannel, nsIURI* aURI, const CORSMode aCORSMode,
|
|
const dom::ReferrerPolicy& aReferrerPolicy, dom::Document* aDocument,
|
|
nsILoadGroup* aLoadGroup, nsIInterfaceRequestor* aCallbacks,
|
|
uint64_t aEarlyHintPreloaderId, int32_t aSupportsPriorityValue);
|
|
|
|
private:
|
|
// @param aSupportsPriorityValue see <nsISupportsPriority.idl>.
|
|
static void AdjustPriority(nsIChannel* aChannel,
|
|
int32_t aSupportsPriorityValue);
|
|
|
|
nsresult CheckContentPolicy(nsIURI* aURI, dom::Document* aDocument);
|
|
|
|
class Cache final : public nsIStreamListener {
|
|
NS_DECL_ISUPPORTS
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
void AsyncConsume(nsIStreamListener* aListener);
|
|
void Consume(nsCOMPtr<nsIStreamListener> aListener);
|
|
|
|
private:
|
|
virtual ~Cache() = default;
|
|
|
|
struct StartRequest {};
|
|
struct DataAvailable {
|
|
nsCString mData;
|
|
};
|
|
struct StopRequest {
|
|
nsresult mStatus;
|
|
};
|
|
|
|
typedef Variant<StartRequest, DataAvailable, StopRequest> Call;
|
|
nsCOMPtr<nsIRequest> mRequest;
|
|
nsCOMPtr<nsIStreamListener> mFinalListener;
|
|
nsTArray<Call> mCalls;
|
|
};
|
|
|
|
// The listener passed to AsyncConsume in case we haven't started getting the
|
|
// data from the channel yet.
|
|
nsCOMPtr<nsIStreamListener> mConsumeListener;
|
|
|
|
// Returned by AsyncConsume when a failure. This remembers the result of
|
|
// opening the channel and prevents duplicate consumation.
|
|
nsresult mAsyncConsumeResult = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
// The CP type to check against. Derived classes have to override call to CSP
|
|
// constructor of this class.
|
|
nsContentPolicyType mContentPolicyType;
|
|
};
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif
|