Image and protocol changes: Add a `stretch` param to the protocol. When false (the default), treat the given size as a maximum bound on the final size such that the image's intrinsic aspect ratio is preserved. When true or when the image doesn't have an intrinsic size, treat the given size as the desired final size and stretch the image, ignoring its intrinsic aspect ratio (if known). Front-end changes: I tried to keep these minimal in order to focus on the image changes and finally get those landed. There are two follow-ups I'd like to do, noted in the summary below. Default `stretch` to true in the `getMozRemoteImageURL()` helper so that existing callers aren't accidentally broken. There's at least one test, `browser_taskbarTabs_icons.js`, that asserts that the image is stretched. I'd like for this to be a temporary thing and as a follow-up audit callers to make sure they can tolerate non-stretched images. That's why the protocol defaults to false but the front-end defaults to true. That's the first follow-up. I kept the single `size` param of `getMozRemoteImageURL()` even though separate width and height params would make more sense. That's the second follow-up. As part of that, I'd also like to move `getMozRemoteImageURL()` out of `FaviconUtils`. There are a lot of callers that don't use it for favicons. Differential Revision: https://phabricator.services.mozilla.com/D297542
47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
/* 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 mozilla_image_remote_RemoteImageProtocolHandler_h
|
|
#define mozilla_image_remote_RemoteImageProtocolHandler_h
|
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
#include "mozilla/MozPromise.h"
|
|
#include "mozilla/StaticPtr.h"
|
|
#include "mozilla/dom/ContentParent.h"
|
|
#include "nsIProtocolHandler.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "nsWeakReference.h"
|
|
|
|
namespace mozilla::image {
|
|
|
|
class RemoteImageProtocolHandler : public nsIProtocolHandler,
|
|
public nsSupportsWeakReference {
|
|
public:
|
|
NS_DECL_ISUPPORTS
|
|
NS_DECL_NSIPROTOCOLHANDLER
|
|
|
|
static already_AddRefed<RemoteImageProtocolHandler> GetSingleton() {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
if (MOZ_UNLIKELY(!sSingleton)) {
|
|
sSingleton = new RemoteImageProtocolHandler();
|
|
ClearOnShutdown(&sSingleton);
|
|
}
|
|
return do_AddRef(sSingleton);
|
|
}
|
|
|
|
static already_AddRefed<gfx::SourceSurface> GetImageSurface(
|
|
imgIContainer* aContainer, gfx::IntSize aSize, bool aStretch,
|
|
ColorScheme aColorScheme);
|
|
|
|
private:
|
|
virtual ~RemoteImageProtocolHandler() = default;
|
|
|
|
static StaticRefPtr<RemoteImageProtocolHandler> sSingleton;
|
|
};
|
|
|
|
} // namespace mozilla::image
|
|
|
|
#endif // mozilla_image_remote_RemoteImageProtocolHandler_h
|