Bug 920630 - Part 4. Change rest of imagelib to use nsIURI directly instead of ImageURL. r=tnikkel

This commit is contained in:
Andrew Osmond 2018-06-05 20:42:57 -04:00
parent ce228623ab
commit 594cd79ec7
7 changed files with 36 additions and 98 deletions

View file

@ -178,16 +178,8 @@ ProgressTracker::Notify(IProgressObserver* aObserver)
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) { if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
RefPtr<Image> image = GetImage(); RefPtr<Image> image = GetImage();
if (image && image->GetURI()) {
RefPtr<ImageURL> uri(image->GetURI());
nsAutoCString spec;
uri->GetSpec(spec);
LOG_FUNC_WITH_PARAM(gImgLog, LOG_FUNC_WITH_PARAM(gImgLog,
"ProgressTracker::Notify async", "uri", spec.get()); "ProgressTracker::Notify async", "uri", image);
} else {
LOG_FUNC_WITH_PARAM(gImgLog,
"ProgressTracker::Notify async", "uri", "<unknown>");
}
} }
aObserver->MarkPendingNotify(); aObserver->MarkPendingNotify();
@ -253,12 +245,8 @@ ProgressTracker::NotifyCurrentState(IProgressObserver* aObserver)
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) { if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
RefPtr<Image> image = GetImage(); RefPtr<Image> image = GetImage();
nsAutoCString spec;
if (image && image->GetURI()) {
image->GetURI()->GetSpec(spec);
}
LOG_FUNC_WITH_PARAM(gImgLog, LOG_FUNC_WITH_PARAM(gImgLog,
"ProgressTracker::NotifyCurrentState", "uri", spec.get()); "ProgressTracker::NotifyCurrentState", "uri", image);
} }
aObserver->MarkPendingNotify(); aObserver->MarkPendingNotify();
@ -401,13 +389,8 @@ ProgressTracker::SyncNotify(IProgressObserver* aObserver)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
RefPtr<Image> image = GetImage(); RefPtr<Image> image = GetImage();
nsAutoCString spec;
if (image && image->GetURI()) {
image->GetURI()->GetSpec(spec);
}
LOG_SCOPE_WITH_PARAM(gImgLog, LOG_SCOPE_WITH_PARAM(gImgLog,
"ProgressTracker::SyncNotify", "uri", spec.get()); "ProgressTracker::SyncNotify", "uri", image);
nsIntRect rect; nsIntRect rect;
if (image) { if (image) {
@ -596,11 +579,7 @@ ProgressTracker::FireFailureNotification()
RefPtr<Image> image = GetImage(); RefPtr<Image> image = GetImage();
if (image) { if (image) {
// Should be on main thread, so ok to create a new nsIURI. // Should be on main thread, so ok to create a new nsIURI.
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri = image->GetURI();
{
RefPtr<ImageURL> threadsafeUriData = image->GetURI();
uri = threadsafeUriData ? threadsafeUriData->ToIURI() : nullptr;
}
if (uri) { if (uri) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) { if (os) {

View file

@ -994,10 +994,10 @@ imgCacheEntry::SetHasNoProxies(bool hasNoProxies)
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) { if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
if (hasNoProxies) { if (hasNoProxies) {
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies true", LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies true",
"uri", mRequest->CacheKey().Spec()); "uri", mRequest->CacheKey().URI());
} else { } else {
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies false", LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies false",
"uri", mRequest->CacheKey().Spec()); "uri", mRequest->CacheKey().URI());
} }
} }
@ -1172,7 +1172,7 @@ imgLoader::CreateNewProxyForRequest(imgRequest* aRequest,
*/ */
proxyRequest->SetLoadFlags(aLoadFlags); proxyRequest->SetLoadFlags(aLoadFlags);
RefPtr<ImageURL> uri; nsCOMPtr<nsIURI> uri;
aRequest->GetURI(getter_AddRefs(uri)); aRequest->GetURI(getter_AddRefs(uri));
// init adds itself to imgRequest's list of observers // init adds itself to imgRequest's list of observers
@ -1215,7 +1215,7 @@ imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
if (req) { if (req) {
LOG_FUNC_WITH_PARAM(gImgLog, LOG_FUNC_WITH_PARAM(gImgLog,
"imgCacheExpirationTracker::NotifyExpired", "imgCacheExpirationTracker::NotifyExpired",
"entry", req->CacheKey().Spec()); "entry", req->CacheKey().URI());
} }
} }
@ -1580,7 +1580,7 @@ imgLoader::PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* entry)
imgCacheTable& cache = GetCache(aKey); imgCacheTable& cache = GetCache(aKey);
LOG_STATIC_FUNC_WITH_PARAM(gImgLog, LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::PutIntoCache", "uri", aKey.Spec()); "imgLoader::PutIntoCache", "uri", aKey.URI());
// Check to see if this request already exists in the cache. If so, we'll // Check to see if this request already exists in the cache. If so, we'll
// replace the old version. // replace the old version.
@ -1638,7 +1638,7 @@ imgLoader::SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry)
{ {
LOG_STATIC_FUNC_WITH_PARAM(gImgLog, LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::SetHasNoProxies", "uri", "imgLoader::SetHasNoProxies", "uri",
aRequest->CacheKey().Spec()); aRequest->CacheKey().URI());
aEntry->SetHasNoProxies(true); aEntry->SetHasNoProxies(true);
@ -1673,7 +1673,7 @@ imgLoader::SetHasProxies(imgRequest* aRequest)
imgCacheTable& cache = GetCache(key); imgCacheTable& cache = GetCache(key);
LOG_STATIC_FUNC_WITH_PARAM(gImgLog, LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::SetHasProxies", "uri", key.Spec()); "imgLoader::SetHasProxies", "uri", key.URI());
RefPtr<imgCacheEntry> entry; RefPtr<imgCacheEntry> entry;
if (cache.Get(key, getter_AddRefs(entry)) && entry) { if (cache.Get(key, getter_AddRefs(entry)) && entry) {
@ -1729,7 +1729,7 @@ imgLoader::CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue)
if (req) { if (req) {
LOG_STATIC_FUNC_WITH_PARAM(gImgLog, LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::CheckCacheLimits", "imgLoader::CheckCacheLimits",
"entry", req->CacheKey().Spec()); "entry", req->CacheKey().URI());
} }
} }
@ -2004,7 +2004,7 @@ bool
imgLoader::RemoveFromCache(const ImageCacheKey& aKey) imgLoader::RemoveFromCache(const ImageCacheKey& aKey)
{ {
LOG_STATIC_FUNC_WITH_PARAM(gImgLog, LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::RemoveFromCache", "uri", aKey.Spec()); "imgLoader::RemoveFromCache", "uri", aKey.URI());
imgCacheTable& cache = GetCache(aKey); imgCacheTable& cache = GetCache(aKey);
imgCacheQueue& queue = GetCacheQueue(aKey); imgCacheQueue& queue = GetCacheQueue(aKey);
@ -2046,7 +2046,7 @@ imgLoader::RemoveFromCache(imgCacheEntry* entry, QueueState aQueueState)
LOG_STATIC_FUNC_WITH_PARAM(gImgLog, LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::RemoveFromCache", "entry's uri", "imgLoader::RemoveFromCache", "entry's uri",
key.Spec()); key.URI());
cache.Remove(key); cache.Remove(key);
@ -2214,8 +2214,7 @@ imgLoader::LoadImage(nsIURI* aURI,
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
} }
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::LoadImage", "aURI", LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::LoadImage", "aURI", aURI);
aURI->GetSpecOrDefault().get());
*_retval = nullptr; *_retval = nullptr;
@ -2310,7 +2309,7 @@ imgLoader::LoadImage(nsIURI* aURI,
// entry. // entry.
if (entry->HasNoProxies()) { if (entry->HasNoProxies()) {
LOG_FUNC_WITH_PARAM(gImgLog, LOG_FUNC_WITH_PARAM(gImgLog,
"imgLoader::LoadImage() adding proxyless entry", "uri", key.Spec()); "imgLoader::LoadImage() adding proxyless entry", "uri", key.URI());
MOZ_ASSERT(!request->HasCacheEntry(), MOZ_ASSERT(!request->HasCacheEntry(),
"Proxyless entry's request has cache entry!"); "Proxyless entry's request has cache entry!");
request->SetCacheEntry(entry); request->SetCacheEntry(entry);
@ -2598,7 +2597,7 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel,
if (entry->HasNoProxies()) { if (entry->HasNoProxies()) {
LOG_FUNC_WITH_PARAM(gImgLog, LOG_FUNC_WITH_PARAM(gImgLog,
"imgLoader::LoadImageWithChannel() adding proxyless entry", "imgLoader::LoadImageWithChannel() adding proxyless entry",
"uri", key.Spec()); "uri", key.URI());
MOZ_ASSERT(!request->HasCacheEntry(), MOZ_ASSERT(!request->HasCacheEntry(),
"Proxyless entry's request has cache entry!"); "Proxyless entry's request has cache entry!");
request->SetCacheEntry(entry); request->SetCacheEntry(entry);
@ -3067,17 +3066,11 @@ imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
// We can't load out of cache. We have to create a whole new request for the // We can't load out of cache. We have to create a whole new request for the
// data that's coming in off the channel. // data that's coming in off the channel.
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
{ mRequest->GetURI(getter_AddRefs(uri));
RefPtr<ImageURL> imageURL;
mRequest->GetURI(getter_AddRefs(imageURL));
uri = imageURL->ToIURI();
}
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
LOG_MSG_WITH_PARAM(gImgLog, LOG_MSG_WITH_PARAM(gImgLog,
"imgCacheValidator::OnStartRequest creating new request", "imgCacheValidator::OnStartRequest creating new request",
"uri", uri->GetSpecOrDefault().get()); "uri", uri);
}
int32_t corsmode = mRequest->GetCORSMode(); int32_t corsmode = mRequest->GetCORSMode();
ReferrerPolicy refpol = mRequest->GetReferrerPolicy(); ReferrerPolicy refpol = mRequest->GetReferrerPolicy();

View file

@ -34,7 +34,6 @@ class imgMemoryReporter;
namespace mozilla { namespace mozilla {
namespace image { namespace image {
class ImageURL;
} // namespace image } // namespace image
} // namespace mozilla } // namespace mozilla
@ -234,7 +233,6 @@ class imgLoader final : public imgILoader,
public: public:
typedef mozilla::image::ImageCacheKey ImageCacheKey; typedef mozilla::image::ImageCacheKey ImageCacheKey;
typedef mozilla::image::ImageURL ImageURL;
typedef nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>, typedef nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>,
imgCacheEntry> imgCacheTable; imgCacheEntry> imgCacheTable;
typedef nsTHashtable<nsPtrHashKey<imgRequest>> imgSet; typedef nsTHashtable<nsPtrHashKey<imgRequest>> imgSet;

View file

@ -80,10 +80,8 @@ imgRequest::~imgRequest()
mLoader->RemoveFromUncachedImages(this); mLoader->RemoveFromUncachedImages(this);
} }
if (mURI) { if (mURI) {
nsAutoCString spec;
mURI->GetSpec(spec);
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequest::~imgRequest()", LOG_FUNC_WITH_PARAM(gImgLog, "imgRequest::~imgRequest()",
"keyuri", spec.get()); "keyuri", mURI);
} else } else
LOG_FUNC(gImgLog, "imgRequest::~imgRequest()"); LOG_FUNC(gImgLog, "imgRequest::~imgRequest()");
} }
@ -111,17 +109,11 @@ imgRequest::Init(nsIURI *aURI,
MOZ_ASSERT(aChannel, "No channel"); MOZ_ASSERT(aChannel, "No channel");
mProperties = do_CreateInstance("@mozilla.org/properties;1"); mProperties = do_CreateInstance("@mozilla.org/properties;1");
mURI = aURI;
// Use ImageURL to ensure access to URI data off main thread.
nsresult rv;
mURI = new ImageURL(aURI, rv);
NS_ENSURE_SUCCESS(rv, rv);
mFinalURI = aFinalURI; mFinalURI = aFinalURI;
mRequest = aRequest; mRequest = aRequest;
mChannel = aChannel; mChannel = aChannel;
mTimedChannel = do_QueryInterface(mChannel); mTimedChannel = do_QueryInterface(mChannel);
mTriggeringPrincipal = aTriggeringPrincipal; mTriggeringPrincipal = aTriggeringPrincipal;
mCORSMode = aCORSMode; mCORSMode = aCORSMode;
mReferrerPolicy = aReferrerPolicy; mReferrerPolicy = aReferrerPolicy;
@ -265,12 +257,10 @@ imgRequest::RemoveProxy(imgRequestProxy* proxy, nsresult aStatus)
if (mLoader) { if (mLoader) {
mLoader->SetHasNoProxies(this, mCacheEntry); mLoader->SetHasNoProxies(this, mCacheEntry);
} }
} else if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) { } else {
nsAutoCString spec;
mURI->GetSpec(spec);
LOG_MSG_WITH_PARAM(gImgLog, LOG_MSG_WITH_PARAM(gImgLog,
"imgRequest::RemoveProxy no cache entry", "imgRequest::RemoveProxy no cache entry",
"uri", spec.get()); "uri", mURI);
} }
/* If |aStatus| is a failure code, then cancel the load if it is still in /* If |aStatus| is a failure code, then cancel the load if it is still in
@ -422,7 +412,7 @@ imgRequest::IsDecodeRequested() const
return mDecodeRequested; return mDecodeRequested;
} }
nsresult imgRequest::GetURI(ImageURL** aURI) nsresult imgRequest::GetURI(nsIURI** aURI)
{ {
MOZ_ASSERT(aURI); MOZ_ASSERT(aURI);
@ -988,7 +978,7 @@ struct NewPartResult final
static NewPartResult static NewPartResult
PrepareForNewPart(nsIRequest* aRequest, nsIInputStream* aInStr, uint32_t aCount, PrepareForNewPart(nsIRequest* aRequest, nsIInputStream* aInStr, uint32_t aCount,
ImageURL* aURI, bool aIsMultipart, image::Image* aExistingImage, nsIURI* aURI, bool aIsMultipart, image::Image* aExistingImage,
ProgressTracker* aProgressTracker, uint32_t aInnerWindowId) ProgressTracker* aProgressTracker, uint32_t aInnerWindowId)
{ {
NewPartResult result(aExistingImage); NewPartResult result(aExistingImage);

View file

@ -35,7 +35,6 @@ class nsIURI;
namespace mozilla { namespace mozilla {
namespace image { namespace image {
class Image; class Image;
class ImageURL;
class ProgressTracker; class ProgressTracker;
} // namespace image } // namespace image
} // namespace mozilla } // namespace mozilla
@ -50,7 +49,6 @@ class imgRequest final : public nsIStreamListener,
{ {
typedef mozilla::image::Image Image; typedef mozilla::image::Image Image;
typedef mozilla::image::ImageCacheKey ImageCacheKey; typedef mozilla::image::ImageCacheKey ImageCacheKey;
typedef mozilla::image::ImageURL ImageURL;
typedef mozilla::image::ProgressTracker ProgressTracker; typedef mozilla::image::ProgressTracker ProgressTracker;
typedef mozilla::net::ReferrerPolicy ReferrerPolicy; typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
@ -151,7 +149,7 @@ public:
void ResetCacheEntry(); void ResetCacheEntry();
// OK to use on any thread. // OK to use on any thread.
nsresult GetURI(ImageURL** aURI); nsresult GetURI(nsIURI** aURI);
nsresult GetFinalURI(nsIURI** aURI); nsresult GetFinalURI(nsIURI** aURI);
bool IsScheme(const char* aScheme) const; bool IsScheme(const char* aScheme) const;
bool IsChrome() const; bool IsChrome() const;
@ -235,7 +233,7 @@ private:
// The original URI we were loaded with. This is the same as the URI we are // The original URI we were loaded with. This is the same as the URI we are
// keyed on in the cache. We store a string here to avoid off main thread // keyed on in the cache. We store a string here to avoid off main thread
// refcounting issues with nsStandardURL. // refcounting issues with nsStandardURL.
RefPtr<ImageURL> mURI; nsCOMPtr<nsIURI> mURI;
// The URI of the resource we ended up loading after all redirects, etc. // The URI of the resource we ended up loading after all redirects, etc.
nsCOMPtr<nsIURI> mFinalURI; nsCOMPtr<nsIURI> mFinalURI;
// The principal which triggered the load of this image. Generally either // The principal which triggered the load of this image. Generally either

View file

@ -180,7 +180,7 @@ nsresult
imgRequestProxy::Init(imgRequest* aOwner, imgRequestProxy::Init(imgRequest* aOwner,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsIDocument* aLoadingDocument, nsIDocument* aLoadingDocument,
ImageURL* aURI, nsIURI* aURI,
imgINotificationObserver* aObserver) imgINotificationObserver* aObserver)
{ {
MOZ_ASSERT(!GetOwner() && !mListener, MOZ_ASSERT(!GetOwner() && !mListener,
@ -772,7 +772,7 @@ NS_IMETHODIMP
imgRequestProxy::GetURI(nsIURI** aURI) imgRequestProxy::GetURI(nsIURI** aURI)
{ {
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread to convert URI"); MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread to convert URI");
nsCOMPtr<nsIURI> uri = mURI->ToIURI(); nsCOMPtr<nsIURI> uri = mURI;
uri.forget(aURI); uri.forget(aURI);
return NS_OK; return NS_OK;
} }
@ -787,18 +787,6 @@ imgRequestProxy::GetFinalURI(nsIURI** aURI)
return GetOwner()->GetFinalURI(aURI); return GetOwner()->GetFinalURI(aURI);
} }
nsresult
imgRequestProxy::GetURI(ImageURL** aURI)
{
if (!mURI) {
return NS_ERROR_FAILURE;
}
NS_ADDREF(*aURI = mURI);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
imgRequestProxy::GetNotificationObserver(imgINotificationObserver** aObserver) imgRequestProxy::GetNotificationObserver(imgINotificationObserver** aObserver)
{ {
@ -1095,12 +1083,8 @@ imgRequestProxy::Notify(int32_t aType, const mozilla::gfx::IntRect* aRect)
void void
imgRequestProxy::OnLoadComplete(bool aLastPart) imgRequestProxy::OnLoadComplete(bool aLastPart)
{ {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnLoadComplete", LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnLoadComplete",
"name", name.get()); "uri", mURI);
}
// There's all sorts of stuff here that could kill us (the OnStopRequest call // There's all sorts of stuff here that could kill us (the OnStopRequest call
// on the listener, the removal from the loadgroup, the release of the // on the listener, the removal from the loadgroup, the release of the

View file

@ -42,7 +42,6 @@ class TabGroup;
namespace image { namespace image {
class Image; class Image;
class ImageURL;
class ProgressTracker; class ProgressTracker;
} // namespace image } // namespace image
} // namespace mozilla } // namespace mozilla
@ -58,7 +57,6 @@ protected:
public: public:
typedef mozilla::image::Image Image; typedef mozilla::image::Image Image;
typedef mozilla::image::ImageURL ImageURL;
typedef mozilla::image::ProgressTracker ProgressTracker; typedef mozilla::image::ProgressTracker ProgressTracker;
MOZ_DECLARE_REFCOUNTED_TYPENAME(imgRequestProxy) MOZ_DECLARE_REFCOUNTED_TYPENAME(imgRequestProxy)
@ -76,7 +74,7 @@ public:
nsresult Init(imgRequest* aOwner, nsresult Init(imgRequest* aOwner,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsIDocument* aLoadingDocument, nsIDocument* aLoadingDocument,
ImageURL* aURI, nsIURI* aURI,
imgINotificationObserver* aObserver); imgINotificationObserver* aObserver);
nsresult ChangeOwner(imgRequest* aNewOwner); // this will change mOwner. nsresult ChangeOwner(imgRequest* aNewOwner); // this will change mOwner.
@ -150,8 +148,6 @@ public:
nsresult GetStaticRequest(nsIDocument* aLoadingDocument, nsresult GetStaticRequest(nsIDocument* aLoadingDocument,
imgRequestProxy** aReturn); imgRequestProxy** aReturn);
nsresult GetURI(ImageURL** aURI);
protected: protected:
friend class mozilla::image::ProgressTracker; friend class mozilla::image::ProgressTracker;
friend class imgStatusNotifyRunnable; friend class imgStatusNotifyRunnable;
@ -230,7 +226,7 @@ private:
void DispatchWithTarget(already_AddRefed<nsIRunnable> aEvent); void DispatchWithTarget(already_AddRefed<nsIRunnable> aEvent);
// The URI of our request. // The URI of our request.
RefPtr<ImageURL> mURI; nsCOMPtr<nsIURI> mURI;
// mListener is only promised to be a weak ref (see imgILoader.idl), // mListener is only promised to be a weak ref (see imgILoader.idl),
// but we actually keep a strong ref to it until we've seen our // but we actually keep a strong ref to it until we've seen our