Files
palemoon27/image/ImageURL.h
T
roytam1 dd0f21a905 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1169680 - Don't merge image cache entries for blob URIs with different refs. r=tn (e92302f2b)
- pointer style (257a9dfea)
- Bug 1136768 - Tidy detection of possibly relocated types r=terrence (8e3df5395)
- Bug 1130640 - Don't unroll loops based on bounds using terms that have been discarded, r=jandem. (911c9b6ee)
- Bug 1158131 - Add local resource whitelisting for string bundle channels. r=snorp (d05af5eef)
- Bug 1153901 - Disable PlatformThread::SetName functions on builds with no SEH support. r=nfroyd (4d07581ba)
- missing bit of Bug 1170124 - Remove unnecessary type monitoring (d6d882389)
- pointer style (f6d3c6ae4)
- Bug 1143966 - Remove type specifier from AllocKind to avoid miscompilations on GCC. r=terrence (44c061df3)
- Bug 1052728 - Add telemetry to record GC phases that cause jank; r=sfink (f1e588798)
- space and pointer style (51d4d5e46)
- Bug 1118615 - Flash hangs displaying a camera/microphone access dialog in HiDPI mode, workaround. r=mstange (022d8139a)
- Bug 1118615 - Flash hangs in HiDPI mode on OS X running peopleroulette app, fix comments. r=fix-comments (83b2c4852)
- style cleanup (677ea587a)
- Bug 1152661 - Fix -Wuninitialized warnings about Operand member variables. r=jandem (5a464818f)
- align values to TenFourFox (48c2ac62b)
- style (a60da64d0)
- missing bit of Backout 7959ffacd30f (Bug 1176090) for being on top of a regression (be8e9cd57)
2021-12-03 09:21:29 +08:00

126 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 mozilla_image_ImageURL_h
#define mozilla_image_ImageURL_h
#include "nsIURI.h"
#include "MainThreadUtils.h"
#include "nsNetUtil.h"
namespace mozilla {
namespace image {
/** ImageURL
*
* nsStandardURL is not threadsafe, so this class is created to hold only the
* necessary URL data required for image loading and decoding.
*
* Note: Although several APIs have the same or similar prototypes as those
* found in nsIURI/nsStandardURL, the class does not implement nsIURI. This is
* intentional; functionality is limited, and is only useful for imagelib code.
* By not implementing nsIURI, external code cannot unintentionally be given an
* nsIURI pointer with this limited class behind it; instead, conversion to a
* fully implemented nsIURI is required (e.g. through NS_NewURI).
*/
class ImageURL
{
public:
explicit ImageURL(nsIURI* aURI)
{
MOZ_ASSERT(NS_IsMainThread(), "Cannot use nsIURI off main thread!");
aURI->GetSpec(mSpec);
aURI->GetScheme(mScheme);
aURI->GetRef(mRef);
}
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageURL)
nsresult GetSpec(nsACString& result)
{
result = mSpec;
return NS_OK;
}
/// A weak pointer to the URI spec for this ImageURL. For logging only.
const char* Spec() const { return mSpec.get(); }
enum TruncatedSpecStatus {
FitsInto1k,
TruncatedTo1k
};
TruncatedSpecStatus GetSpecTruncatedTo1k(nsACString& result)
{
static const size_t sMaxTruncatedLength = 1024;
if (sMaxTruncatedLength >= mSpec.Length()) {
result = mSpec;
return FitsInto1k;
}
result = Substring(mSpec, 0, sMaxTruncatedLength);
return TruncatedTo1k;
}
nsresult GetScheme(nsACString& result)
{
result = mScheme;
return NS_OK;
}
nsresult SchemeIs(const char* scheme, bool* result)
{
NS_PRECONDITION(scheme, "scheme is null");
NS_PRECONDITION(result, "result is null");
*result = mScheme.Equals(scheme);
return NS_OK;
}
nsresult GetRef(nsACString& result)
{
result = mRef;
return NS_OK;
}
already_AddRefed<nsIURI> ToIURI()
{
MOZ_ASSERT(NS_IsMainThread(),
"Convert to nsIURI on main thread only; it is not threadsafe.");
nsCOMPtr<nsIURI> newURI;
NS_NewURI(getter_AddRefs(newURI), mSpec);
return newURI.forget();
}
bool operator==(const ImageURL& aOther) const
{
// Note that we don't need to consider mScheme and mRef, because they're
// already represented in mSpec.
return mSpec == aOther.mSpec;
}
bool HasSameRef(const ImageURL& aOther) const
{
return mRef == aOther.mRef;
}
private:
// Since this is a basic storage class, no duplication of spec parsing is
// included in the functionality. Instead, the class depends upon the
// parsing implementation in the nsIURI class used in object construction.
// This means each field is stored separately, but since only a few are
// required, this small memory tradeoff for threadsafe usage should be ok.
nsAutoCString mSpec;
nsAutoCString mScheme;
nsAutoCString mRef;
~ImageURL() { }
};
} // namespace image
} // namespace mozilla
#endif // mozilla_image_ImageURL_h