From b1d213acb76a34aa6c258c3b494f256f7451cd19 Mon Sep 17 00:00:00 2001 From: Sandor Molnar Date: Tue, 20 Feb 2024 20:36:30 +0200 Subject: [PATCH] Backed out changeset 8e21fdfc60f0 (bug 1868001) for causing mochitest failures at dom/tests/mochitest/general/test_resource_timing_cross_origin.html CLOSED TREE --- docshell/base/nsDocShell.cpp | 10 +- docshell/base/nsDocShell.h | 3 +- dom/base/nsObjectLoadingContent.cpp | 6 +- dom/base/test/browser.toml | 10 -- dom/base/test/browser_object_attachment.js | 168 ------------------ dom/base/test/file_img_attachment.jpg | Bin 2711 -> 0 bytes .../test/file_img_attachment.jpg^headers^ | 1 - dom/base/test/file_img_object_attachment.html | 6 - dom/base/test/file_pdf_attachment.pdf | Bin 1568 -> 0 bytes .../test/file_pdf_attachment.pdf^headers^ | 2 - dom/base/test/file_pdf_object_attachment.html | 6 - modules/libpref/init/StaticPrefList.yaml | 7 - netwerk/ipc/DocumentLoadListener.cpp | 17 +- uriloader/base/nsURILoader.cpp | 15 +- 14 files changed, 11 insertions(+), 240 deletions(-) delete mode 100644 dom/base/test/browser_object_attachment.js delete mode 100644 dom/base/test/file_img_attachment.jpg delete mode 100644 dom/base/test/file_img_attachment.jpg^headers^ delete mode 100644 dom/base/test/file_img_object_attachment.html delete mode 100644 dom/base/test/file_pdf_attachment.pdf delete mode 100644 dom/base/test/file_pdf_attachment.pdf^headers^ delete mode 100644 dom/base/test/file_pdf_object_attachment.html diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index fd5b91c9bee2..f2a9e0fa5901 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -10590,8 +10590,7 @@ static nsresult AppendSegmentToString(nsIInputStream* aIn, void* aClosure, } /* static */ uint32_t nsDocShell::ComputeURILoaderFlags( - BrowsingContext* aBrowsingContext, uint32_t aLoadType, - bool aIsDocumentLoad) { + BrowsingContext* aBrowsingContext, uint32_t aLoadType) { MOZ_ASSERT(aBrowsingContext); uint32_t openFlags = 0; @@ -10602,13 +10601,6 @@ static nsresult AppendSegmentToString(nsIInputStream* aIn, void* aClosure, openFlags |= nsIURILoader::DONT_RETARGET; } - // Unless the pref is set, object/embed loads always specify DONT_RETARGET. - // See bug 1868001 for details. - if (!aIsDocumentLoad && - !StaticPrefs::dom_navigation_object_embed_allow_retargeting()) { - openFlags |= nsIURILoader::DONT_RETARGET; - } - return openFlags; } diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 82ac6c9ab9db..9f2d9a17dc0d 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -489,8 +489,7 @@ class nsDocShell final : public nsDocLoader, bool HasDocumentViewer() const { return !!mDocumentViewer; } static uint32_t ComputeURILoaderFlags( - mozilla::dom::BrowsingContext* aBrowsingContext, uint32_t aLoadType, - bool aIsDocumentLoad = true); + mozilla::dom::BrowsingContext* aBrowsingContext, uint32_t aLoadType); void SetLoadingSessionHistoryInfo( const mozilla::dom::LoadingSessionHistoryInfo& aLoadingInfo, diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index ab87c58e8713..a50449b84272 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -1249,11 +1249,7 @@ nsresult nsObjectLoadingContent::LoadObject(bool aNotify, bool aForceLoad, break; } - uint32_t uriLoaderFlags = nsDocShell::ComputeURILoaderFlags( - docShell->GetBrowsingContext(), LOAD_NORMAL, - /* aIsDocumentLoad */ false); - - rv = uriLoader->OpenChannel(mChannel, uriLoaderFlags, req, + rv = uriLoader->OpenChannel(mChannel, nsIURILoader::DONT_RETARGET, req, getter_AddRefs(finalListener)); // finalListener will receive OnStartRequest either below, or if // `mChannel` is a `DocumentChannel`, it will be received after diff --git a/dom/base/test/browser.toml b/dom/base/test/browser.toml index a68bd2e8736c..1deeb88d89bf 100644 --- a/dom/base/test/browser.toml +++ b/dom/base/test/browser.toml @@ -109,16 +109,6 @@ skip-if = [ ] support-files = ["browser_multiple_popups.html"] -["browser_object_attachment.js"] -support-files = [ - "file_img_object_attachment.html", - "file_img_attachment.jpg", - "file_img_attachment.jpg^headers^", - "file_pdf_object_attachment.html", - "file_pdf_attachment.pdf", - "file_pdf_attachment.pdf^headers^", -] - ["browser_outline_refocus.js"] ["browser_page_load_event_telemetry.js"] diff --git a/dom/base/test/browser_object_attachment.js b/dom/base/test/browser_object_attachment.js deleted file mode 100644 index b4432862f0a2..000000000000 --- a/dom/base/test/browser_object_attachment.js +++ /dev/null @@ -1,168 +0,0 @@ -ChromeUtils.defineESModuleGetters(this, { - Downloads: "resource://gre/modules/Downloads.sys.mjs", -}); - -const httpsTestRoot = getRootDirectory(gTestPath).replace( - "chrome://mochitests/content", - "https://example.com" -); - -add_task(async function test_pdf_object_attachment() { - await SpecialPowers.pushPrefEnv({ - set: [["dom.navigation.object_embed.allow_retargeting", false]], - }); - - await BrowserTestUtils.withNewTab( - `${httpsTestRoot}/file_pdf_object_attachment.html`, - async browser => { - is( - browser.browsingContext.children.length, - 1, - "Should have a child frame" - ); - await SpecialPowers.spawn(browser, [], async () => { - let obj = content.document.querySelector("object"); - is( - obj.displayedType, - Ci.nsIObjectLoadingContent.TYPE_DOCUMENT, - "should be displaying TYPE_DOCUMENT" - ); - }); - } - ); -}); - -add_task(async function test_img_object_attachment() { - await SpecialPowers.pushPrefEnv({ - set: [["dom.navigation.object_embed.allow_retargeting", false]], - }); - - await BrowserTestUtils.withNewTab( - `${httpsTestRoot}/file_img_object_attachment.html`, - async browser => { - is( - browser.browsingContext.children.length, - 1, - "Should have a child frame" - ); - await SpecialPowers.spawn(browser, [], async () => { - let obj = content.document.querySelector("object"); - is( - obj.displayedType, - Ci.nsIObjectLoadingContent.TYPE_DOCUMENT, - "should be displaying TYPE_DOCUMENT" - ); - }); - } - ); -}); - -async function waitForDownload() { - // Get the downloads list and add a view to listen for a download to be added. - let downloadList = await Downloads.getList(Downloads.ALL); - - // Wait for a single download - let downloadView; - let finishedAllDownloads = new Promise(resolve => { - downloadView = { - onDownloadAdded(aDownload) { - info("download added"); - resolve(aDownload); - }, - }; - }); - await downloadList.addView(downloadView); - let download = await finishedAllDownloads; - await downloadList.removeView(downloadView); - - // Clean up the download from the list. - await downloadList.remove(download); - await download.finalize(true); - - // Return the download - return download; -} - -add_task(async function test_pdf_object_attachment_download() { - await SpecialPowers.pushPrefEnv({ - set: [["dom.navigation.object_embed.allow_retargeting", true]], - }); - - // Set the behaviour to save pdfs to disk and not handle internally, so we - // don't end up with extra tabs after the test. - var gMimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); - var gHandlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService( - Ci.nsIHandlerService - ); - const mimeInfo = gMimeSvc.getFromTypeAndExtension("application/pdf", "pdf"); - let previousAction = mimeInfo.preferredAction; - mimeInfo.preferredAction = Ci.nsIHandlerInfo.saveToDisk; - gHandlerSvc.store(mimeInfo); - registerCleanupFunction(() => { - mimeInfo.preferredAction = previousAction; - gHandlerSvc.store(mimeInfo); - }); - - // Start listening for the download before opening the new tab. - let downloadPromise = waitForDownload(); - await BrowserTestUtils.withNewTab( - `${httpsTestRoot}/file_pdf_object_attachment.html`, - async browser => { - let download = await downloadPromise; - is( - download.source.url, - `${httpsTestRoot}/file_pdf_attachment.pdf`, - "download should be the pdf" - ); - - await SpecialPowers.spawn(browser, [], async () => { - let obj = content.document.querySelector("object"); - is( - obj.displayedType, - Ci.nsIObjectLoadingContent.TYPE_FALLBACK, - "should be displaying TYPE_FALLBACK" - ); - }); - } - ); -}); - -add_task(async function test_img_object_attachment_download() { - // NOTE: This is testing our current behaviour here as of bug 1868001 (which - // is to download an image with `Content-Disposition: attachment` embedded - // within an object or embed element). - // - // Other browsers ignore the `Content-Disposition: attachment` header when - // loading images within object or embed element as-of december 2023, as - // we did prior to the changes in bug 1595491. - // - // If this turns out to be a web-compat issue, we may want to introduce - // special handling to ignore content-disposition when loading images within - // an object or embed element. - await SpecialPowers.pushPrefEnv({ - set: [["dom.navigation.object_embed.allow_retargeting", true]], - }); - - // Start listening for the download before opening the new tab. - let downloadPromise = waitForDownload(); - await BrowserTestUtils.withNewTab( - `${httpsTestRoot}/file_img_object_attachment.html`, - async browser => { - let download = await downloadPromise; - is( - download.source.url, - `${httpsTestRoot}/file_img_attachment.jpg`, - "download should be the jpg" - ); - - await SpecialPowers.spawn(browser, [], async () => { - let obj = content.document.querySelector("object"); - is( - obj.displayedType, - Ci.nsIObjectLoadingContent.TYPE_FALLBACK, - "should be displaying TYPE_FALLBACK" - ); - }); - } - ); -}); diff --git a/dom/base/test/file_img_attachment.jpg b/dom/base/test/file_img_attachment.jpg deleted file mode 100644 index dcd99b967047b034ae4393188a97f156267fbe5e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2711 zcmb8pc|6pM769FTSNey8vWpoju zE4vw6HDeoDBC=Ezi3s!D_j#Ys`@BEjIscr`=bZCBhr{N~0&q)H3sV3D0s-cS32-I> z6M&bShnI(&mzReZ0^#L@!l6)pekcMaC;%5jh>MFMkVwg6@@Pq^<0vFjMpfpxf}*mD zvIJU9T}??{UP)Q$9|Qz}K%jh35hzqdNfIfk^nVAZ9T4IJE(15fpx*#4ArM#y#OVg4 z006{u`0RfJ1aKX`3x*svv2cJ31O{_)bMt_?!T*eaxWE9n5RdS08b-V#I8THukqp5Y zCqDM7Wr`i|_;%XP`*2P2kO2R$3H~>F*gGWza2=ZekUamn3E~n0AA;OQA{ZP|*4XnK z52BVimq>oxvCer12!IbYA+Qi&0IVA--Tkq|lac}F!<7JcH4RlRRT@1fStg2`PbV3A zPo86Gs$m!es$oMW!XE)2lJ?Isq3Li%bHyi7ivh_9|8h_S)iybh+R|~t0yU0?Mfjr1 z7p9l#mC~~)yNx%$2W7IJSJS%W-}PX8nJ+1}`!S^X7geS?tSI*vD-p$#_)2g^)2kF4 zHQJOp#>z832sW>0#=6%MU(Rs$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ghDr zi#z+etJ`ZH1|qRegbz}`nq^hKi<*~eq^neh4t_C{P!WpQl<@Assg35&P?FXV&H(%4 zUs4mvH)kfQH>h$ik6kj6?JXL#y;$CVk}{nfbil5B-$%S;R^{XQBP9S|@Ms{)s3A$`%o z8%8&e4n2Hj_w;6S$ZYQMT{Elk5)ypkVr1pJ`;T7?e=YS1C##F5PC=7*%+GXuc)q!& zThYPTGpp!RR;FLgH^6tPU(Ri(ZUm<;VB)F(C(#1{f6=WGYpxSF#M&m&V}SO1aVK2hb>rW z(CTP=FY1Ivh8ktFYn*0VXOifIYV3oU9uutP0N5Gb{P&HnQ3>9Zw%RApQZBr$E{(yM zZf0X0h2`3d3L|iI&-B=e_j2d}{FBy8MJER{kD|sBAM@r#RRUOnQS;mH4lDR#UI3f` zY@q`@@tf#?r|Iq<#U8NSQS`#bg6;Yi&st9x+`9_xwYQ9 zsAJEYDS)qo30gWd&)u5tLlEolSJ1Fxo+V1Td|xl>1qgAGKO4&Fj{8nFr0z=k)(g)H io6~9Dh4E@I3xdL|&vhk9R< - - - fallback - - diff --git a/dom/base/test/file_pdf_attachment.pdf b/dom/base/test/file_pdf_attachment.pdf deleted file mode 100644 index 89066463f1013406536fec88813da93abca5483a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1568 zcmcIk!EVz)5QXc00mr#iY7fbJ?bxxas)r^Gt)MhbB7syPCGiGlLj#|{SMdjk zD}TX_8_aC&#Mp4)fR!lL+nJr2_uk}S*dMe++W{uP0yVv3Cnt;#!$hvZMr6eJDBf0PDUEvfnP2y@Xhtu4j<+!8cPk{4!M$X8lI^w+**hU4?omLu2xM@Wg2U) zp+ng??R>MGf*>|Vm5%AO?D)CN5SU&ts*Lsh0NE%BSQ##6PsDjwjIR4*hP&eDZ^Gu|Mk*YctAkQ_dX_H;&-+6!zT2$f zchOz7`+UDSTVOTk2<&Fvpi{}!d5EUS%^&(W{fKLe>v@^Y6rgZse@9B;ZtpiW%(amT NeG;&PgY)YF`vu#ZoJ{}# diff --git a/dom/base/test/file_pdf_attachment.pdf^headers^ b/dom/base/test/file_pdf_attachment.pdf^headers^ deleted file mode 100644 index 562009a8de55..000000000000 --- a/dom/base/test/file_pdf_attachment.pdf^headers^ +++ /dev/null @@ -1,2 +0,0 @@ -Content-Type: application/octet-stream -Content-Disposition: attachment diff --git a/dom/base/test/file_pdf_object_attachment.html b/dom/base/test/file_pdf_object_attachment.html deleted file mode 100644 index d87eff992320..000000000000 --- a/dom/base/test/file_pdf_object_attachment.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - fallback - - diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index f8e8342543e6..fb3a834acb4e 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -3099,13 +3099,6 @@ value: 10 mirror: always -# Whether to allow and element loads to be retargeted to an -# external application or download. -- name: dom.navigation.object_embed.allow_retargeting - type: bool - value: false - mirror: always - # Network Information API # This feature is not available on Firefox desktop. It exposes too much # user information. Let's be consistent and disable it on Android. diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index f4d823869324..ca1f59e8847b 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -340,17 +340,6 @@ class ParentProcessDocumentOpenInfo final : public nsDocumentOpenInfo, nsresult OnObjectStartRequest(nsIRequest* request) { LOG(("ParentProcessDocumentOpenInfo OnObjectStartRequest [this=%p]", this)); - - // If this load will be treated as a document load, run through - // nsDocumentOpenInfo for consistency with other document loads. - // - // If the dom.navigation.object_embed.allow_retargeting pref is enabled, - // this may lead to the resource being downloaded. - if (nsCOMPtr channel = do_QueryInterface(request); - channel && channel->IsDocument()) { - return OnDocumentStartRequest(request); - } - // Just redirect to the nsObjectLoadingContent in the content process. m_targetStreamListener = mListener; return m_targetStreamListener->OnStartRequest(request); @@ -826,9 +815,11 @@ auto DocumentLoadListener::Open(nsDocShellLoadState* aLoadState, } // Recalculate the openFlags, matching the logic in use in Content process. + // NOTE: The only case not handled here to mirror Content process is + // redirecting to re-use the channel. MOZ_ASSERT(!aLoadState->GetPendingRedirectedChannel()); - uint32_t openFlags = nsDocShell::ComputeURILoaderFlags( - loadingContext, aLoadState->LoadType(), mIsDocumentLoad); + uint32_t openFlags = + nsDocShell::ComputeURILoaderFlags(loadingContext, aLoadState->LoadType()); RefPtr openInfo = new ParentProcessDocumentOpenInfo(mParentChannelListener, openFlags, diff --git a/uriloader/base/nsURILoader.cpp b/uriloader/base/nsURILoader.cpp index 792f3ea89327..0acd451c9dbf 100644 --- a/uriloader/base/nsURILoader.cpp +++ b/uriloader/base/nsURILoader.cpp @@ -274,19 +274,12 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest* request) { // could happen because the Content-Disposition header is set so, or, in the // future, because the user has specified external handling for the MIME // type. - // - // If we're not going to be able to retarget to an external handler, ignore - // content-disposition, and unconditionally try to display the content. - // This is used for object/embed tags, which expect to display subresources - // marked with an attachment disposition. bool forceExternalHandling = false; - if (!(mFlags & nsIURILoader::DONT_RETARGET)) { - uint32_t disposition; - rv = aChannel->GetContentDisposition(&disposition); + uint32_t disposition; + rv = aChannel->GetContentDisposition(&disposition); - if (NS_SUCCEEDED(rv) && disposition == nsIChannel::DISPOSITION_ATTACHMENT) { - forceExternalHandling = true; - } + if (NS_SUCCEEDED(rv) && disposition == nsIChannel::DISPOSITION_ATTACHMENT) { + forceExternalHandling = true; } LOG((" forceExternalHandling: %s", forceExternalHandling ? "yes" : "no"));