diff --git a/embedding/browser/nsContextMenuInfo.cpp b/embedding/browser/nsContextMenuInfo.cpp index f63cd8046318..5052dda65550 100644 --- a/embedding/browser/nsContextMenuInfo.cpp +++ b/embedding/browser/nsContextMenuInfo.cpp @@ -270,8 +270,7 @@ nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode, nsAutoString bgStringValue; nsCOMPtr doc(do_QueryInterface(document)); - NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); - nsCOMPtr principal = doc->NodePrincipal(); + nsCOMPtr principal = doc ? doc->NodePrincipal() : nullptr; while (true) { nsCOMPtr domElement(do_QueryInterface(domNode)); diff --git a/image/ImageCacheKey.cpp b/image/ImageCacheKey.cpp index 1f4b2e64c2ae..8366141d6686 100644 --- a/image/ImageCacheKey.cpp +++ b/image/ImageCacheKey.cpp @@ -45,11 +45,8 @@ BlobSerial(ImageURL* aURI) return Nothing(); } -ImageCacheKey::ImageCacheKey(nsIURI* aURI, - const PrincipalOriginAttributes& aAttrs, - nsIDocument* aDocument) +ImageCacheKey::ImageCacheKey(nsIURI* aURI, nsIDocument* aDocument) : mURI(new ImageURL(aURI)) - , mOriginAttributes(aAttrs) , mControlledDocument(GetControlledDocumentToken(aDocument)) , mIsChrome(URISchemeIs(mURI, "chrome")) { @@ -59,14 +56,11 @@ ImageCacheKey::ImageCacheKey(nsIURI* aURI, mBlobSerial = BlobSerial(mURI); } - mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument); + mHash = ComputeHash(mURI, mBlobSerial, mControlledDocument); } -ImageCacheKey::ImageCacheKey(ImageURL* aURI, - const PrincipalOriginAttributes& aAttrs, - nsIDocument* aDocument) +ImageCacheKey::ImageCacheKey(ImageURL* aURI, nsIDocument* aDocument) : mURI(aURI) - , mOriginAttributes(aAttrs) , mControlledDocument(GetControlledDocumentToken(aDocument)) , mIsChrome(URISchemeIs(mURI, "chrome")) { @@ -76,13 +70,12 @@ ImageCacheKey::ImageCacheKey(ImageURL* aURI, mBlobSerial = BlobSerial(mURI); } - mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument); + mHash = ComputeHash(mURI, mBlobSerial, mControlledDocument); } ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther) : mURI(aOther.mURI) , mBlobSerial(aOther.mBlobSerial) - , mOriginAttributes(aOther.mOriginAttributes) , mControlledDocument(aOther.mControlledDocument) , mHash(aOther.mHash) , mIsChrome(aOther.mIsChrome) @@ -91,7 +84,6 @@ ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther) ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther) : mURI(Move(aOther.mURI)) , mBlobSerial(Move(aOther.mBlobSerial)) - , mOriginAttributes(aOther.mOriginAttributes) , mControlledDocument(aOther.mControlledDocument) , mHash(aOther.mHash) , mIsChrome(aOther.mIsChrome) @@ -104,10 +96,6 @@ ImageCacheKey::operator==(const ImageCacheKey& aOther) const if (mControlledDocument != aOther.mControlledDocument) { return false; } - // The origin attributes always have to match. - if (mOriginAttributes != aOther.mOriginAttributes) { - return false; - } if (mBlobSerial || aOther.mBlobSerial) { // If at least one of us has a blob serial, just compare the blob serial and // the ref portion of the URIs. @@ -128,16 +116,12 @@ ImageCacheKey::Spec() const /* static */ uint32_t ImageCacheKey::ComputeHash(ImageURL* aURI, const Maybe& aBlobSerial, - const PrincipalOriginAttributes& aAttrs, void* aControlledDocument) { // Since we frequently call Hash() several times in a row on the same // ImageCacheKey, as an optimization we compute our hash once and store it. nsPrintfCString ptr("%p", aControlledDocument); - nsAutoCString suffix; - aAttrs.CreateSuffix(suffix); - if (aBlobSerial) { // For blob URIs, we hash the serial number of the underlying blob, so that // different blob URIs which point to the same blob share a cache entry. We @@ -146,13 +130,13 @@ ImageCacheKey::ComputeHash(ImageURL* aURI, // the same. nsAutoCString ref; aURI->GetRef(ref); - return HashGeneric(*aBlobSerial, HashString(ref + suffix + ptr)); + return HashGeneric(*aBlobSerial, HashString(ref + ptr)); } // For non-blob URIs, we hash the URI spec. nsAutoCString spec; aURI->GetSpec(spec); - return HashString(spec + suffix + ptr); + return HashString(spec + ptr); } /* static */ void* diff --git a/image/ImageCacheKey.h b/image/ImageCacheKey.h index 924b81ee8044..0fb276e9872c 100644 --- a/image/ImageCacheKey.h +++ b/image/ImageCacheKey.h @@ -10,7 +10,6 @@ #ifndef mozilla_image_src_ImageCacheKey_h #define mozilla_image_src_ImageCacheKey_h -#include "mozilla/BasePrincipal.h" #include "mozilla/Maybe.h" class nsIDocument; @@ -32,10 +31,8 @@ class ImageURL; class ImageCacheKey final { public: - ImageCacheKey(nsIURI* aURI, const PrincipalOriginAttributes& aAttrs, - nsIDocument* aDocument); - ImageCacheKey(ImageURL* aURI, const PrincipalOriginAttributes& aAttrs, - nsIDocument* aDocument); + ImageCacheKey(nsIURI* aURI, nsIDocument* aDocument); + ImageCacheKey(ImageURL* aURI, nsIDocument* aDocument); ImageCacheKey(const ImageCacheKey& aOther); ImageCacheKey(ImageCacheKey&& aOther); @@ -56,13 +53,11 @@ public: private: static uint32_t ComputeHash(ImageURL* aURI, const Maybe& aBlobSerial, - const PrincipalOriginAttributes& aAttrs, void* aControlledDocument); static void* GetControlledDocumentToken(nsIDocument* aDocument); RefPtr mURI; Maybe mBlobSerial; - PrincipalOriginAttributes mOriginAttributes; void* mControlledDocument; uint32_t mHash; bool mIsChrome; diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index 8469ae3b9bda..d19674239dae 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -1368,20 +1368,7 @@ imgLoader::FindEntryProperties(nsIURI* uri, *_retval = nullptr; nsCOMPtr doc = do_QueryInterface(aDOMDoc); - nsCOMPtr principal; - if (doc) { - principal = doc->NodePrincipal(); - } else { - nsCOMPtr ssm = nsContentUtils::GetSecurityManager(); - NS_ENSURE_TRUE(ssm, NS_ERROR_FAILURE); - ssm->GetSystemPrincipal(getter_AddRefs(principal)); - } - NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE); - - const PrincipalOriginAttributes& attrs = - BasePrincipal::Cast(principal)->OriginAttributesRef(); - - ImageCacheKey key(uri, attrs, doc); + ImageCacheKey key(uri, doc); imgCacheTable& cache = GetCache(key); RefPtr entry; @@ -2138,11 +2125,7 @@ imgLoader::LoadImage(nsIURI* aURI, // XXX For now ignore aCacheKey. We will need it in the future // for correctly dealing with image load requests that are a result // of post data. - NS_ENSURE_TRUE(aLoadingPrincipal, NS_ERROR_FAILURE); - const PrincipalOriginAttributes& attrs = - BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef(); - - ImageCacheKey key(aURI, attrs, aLoadingDocument); + ImageCacheKey key(aURI, aLoadingDocument); imgCacheTable& cache = GetCache(key); if (cache.Get(key, getter_AddRefs(entry)) && entry) { @@ -2346,19 +2329,7 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel, nsCOMPtr uri; channel->GetURI(getter_AddRefs(uri)); nsCOMPtr doc = do_QueryInterface(aCX); - - NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE); - nsCOMPtr loadInfo = channel->GetLoadInfo(); - NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - - nsCOMPtr principal; - loadInfo->GetLoadingPrincipal(getter_AddRefs(principal)); - NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE); - - const PrincipalOriginAttributes& attrs = - BasePrincipal::Cast(principal)->OriginAttributesRef(); - - ImageCacheKey key(uri, attrs, doc); + ImageCacheKey key(uri, doc); nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL; channel->GetLoadFlags(&requestFlags); @@ -2460,7 +2431,7 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel, // constructed above with the *current URI* and not the *original URI*. I'm // pretty sure this is a bug, and it's preventing us from ever getting a // cache hit in LoadImageWithChannel when redirects are involved. - ImageCacheKey originalURIKey(originalURI, attrs, doc); + ImageCacheKey originalURIKey(originalURI, doc); // Default to doing a principal check because we don't know who // started that load and whether their principal ended up being diff --git a/image/test/unit/async_load_tests.js b/image/test/unit/async_load_tests.js index 97d3f809db6b..fafb26f75805 100644 --- a/image/test/unit/async_load_tests.js +++ b/image/test/unit/async_load_tests.js @@ -13,9 +13,6 @@ var Cr = Components.results; Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://gre/modules/NetUtil.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); - -var ssm = Services.scriptSecurityManager; var server = new HttpServer(); server.registerDirectory("/", do_get_file('')); @@ -100,9 +97,7 @@ function checkSecondLoad() var listener = new ImageListener(checkClone, secondLoadDone); var outer = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) .createScriptedObserver(listener); - var systemPrincipal = ssm.getSystemPrincipal(); - requests.push(gCurrentLoader.loadImageXPCOM(uri, null, null, "default", - systemPrincipal, null, outer, null, 0, null)); + requests.push(gCurrentLoader.loadImageXPCOM(uri, null, null, "default", null, null, outer, null, 0, null)); listener.synchronous = false; } @@ -182,9 +177,7 @@ function startImageCallback(otherCb) var listener2 = new ImageListener(null, function(foo, bar) { do_test_finished(); }); var outer = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) .createScriptedObserver(listener2); - var systemPrincipal = ssm.getSystemPrincipal(); - requests.push(gCurrentLoader.loadImageXPCOM(uri, null, null, "default", - systemPrincipal, null, outer, null, 0, null)); + requests.push(gCurrentLoader.loadImageXPCOM(uri, null, null, "default", null, null, outer, null, 0, null)); listener2.synchronous = false; // Now that we've started another load, chain to the callback. @@ -211,9 +204,7 @@ function run_test() var listener = new ImageListener(startImageCallback(checkClone), firstLoadDone); var outer = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) .createScriptedObserver(listener); - var systemPrincipal = ssm.getSystemPrincipal(); - var req = gCurrentLoader.loadImageXPCOM(uri, null, null, "default", - systemPrincipal, null, outer, null, 0, null); + var req = gCurrentLoader.loadImageXPCOM(uri, null, null, "default", null, null, outer, null, 0, null); requests.push(req); // Ensure that we don't cause any mayhem when we lock an image. diff --git a/image/test/unit/test_private_channel.js b/image/test/unit/test_private_channel.js index 7ba4a72ff082..bf20af59526f 100644 --- a/image/test/unit/test_private_channel.js +++ b/image/test/unit/test_private_channel.js @@ -7,8 +7,6 @@ Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://testing-common/httpd.js"); -var ssm = Services.scriptSecurityManager; - var server = new HttpServer(); server.registerPathHandler('/image.png', imageHandler); server.start(-1); @@ -86,9 +84,7 @@ function loadImage(isPrivate, callback) { var loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance(Ci.nsILoadGroup); loadGroup.notificationCallbacks = new NotificationCallbacks(isPrivate); var loader = isPrivate ? gPrivateLoader : gPublicLoader; - var systemPrincipal = ssm.getSystemPrincipal(); - requests.push(loader.loadImageXPCOM(uri, null, null, "default", - systemPrincipal, loadGroup, outer, null, 0, null)); + requests.push(loader.loadImageXPCOM(uri, null, null, "default", null, loadGroup, outer, null, 0, null)); listener.synchronous = false; } @@ -108,9 +104,6 @@ function run_loadImage_tests() { }); } - gPrivateLoader.QueryInterface(Ci.imgICache).clearCache(false); - gPublicLoader.QueryInterface(Ci.imgICache).clearCache(false); - Services.obs.addObserver(observer, "cacheservice:empty-cache", false); let cs = Cc["@mozilla.org/netwerk/cache-storage-service;1"] .getService(Ci.nsICacheStorageService); diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 622272e226f6..f8a688e53445 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -2207,19 +2207,13 @@ nsImageFrame::LoadIcon(const nsAString& aSpec, nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL; nsContentPolicyType contentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE; - nsCOMPtr ssm = nsContentUtils::GetSecurityManager(); - NS_ENSURE_TRUE(ssm, NS_ERROR_FAILURE); - nsCOMPtr systemPrincipal; - ssm->GetSystemPrincipal(getter_AddRefs(systemPrincipal)); - NS_ENSURE_TRUE(systemPrincipal, NS_ERROR_FAILURE); - return il->LoadImage(realURI, /* icon URI */ nullptr, /* initial document URI; this is only relevant for cookies, so does not apply to icons. */ nullptr, /* referrer (not relevant for icons) */ mozilla::net::RP_Default, - systemPrincipal, /* principal (not relevant for icons) */ + nullptr, /* principal (not relevant for icons) */ loadGroup, gIconLoad, nullptr, /* No context */ diff --git a/toolkit/system/gnome/nsAlertsIconListener.cpp b/toolkit/system/gnome/nsAlertsIconListener.cpp index 3a50922d7445..51d29e0b1159 100644 --- a/toolkit/system/gnome/nsAlertsIconListener.cpp +++ b/toolkit/system/gnome/nsAlertsIconListener.cpp @@ -6,7 +6,6 @@ #include "nsAlertsIconListener.h" #include "imgIContainer.h" #include "imgIRequest.h" -#include "nsContentUtils.h" #include "imgLoader.h" #include "nsNetUtil.h" #include "nsServiceManagerUtils.h" @@ -249,19 +248,14 @@ nsAlertsIconListener::StartRequest(const nsAString & aImageUrl, bool aInPrivateB if (!imageUri) return ShowAlert(nullptr); - nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1")); + imgLoader* il = aInPrivateBrowsing ? imgLoader::PrivateBrowsingLoader() + : imgLoader::NormalLoader(); if (!il) return ShowAlert(nullptr); - nsCOMPtr ssm = nsContentUtils::GetSecurityManager(); - NS_ENSURE_TRUE(ssm, NS_ERROR_FAILURE); - nsCOMPtr systemPrincipal; - ssm->GetSystemPrincipal(getter_AddRefs(systemPrincipal)); - NS_ENSURE_TRUE(systemPrincipal, NS_ERROR_FAILURE); - nsresult rv = il->LoadImageXPCOM(imageUri, nullptr, nullptr, - NS_LITERAL_STRING("default"), - systemPrincipal, nullptr, this, nullptr, + NS_LITERAL_STRING("default"), nullptr, nullptr, + this, nullptr, aInPrivateBrowsing ? nsIRequest::LOAD_ANONYMOUS : nsIRequest::LOAD_NORMAL, nullptr, 0 /* use default */,