From 6e1379973413c40114ac5fa02fc5a2196b905a92 Mon Sep 17 00:00:00 2001 From: Daniel Varga Date: Mon, 9 Dec 2019 12:51:07 +0200 Subject: [PATCH] Backed out changeset e65c1bcb013f (bug 1601475) for causing build bustage. On a CLOSED TREE --- devtools/client/responsive/browser/tunnel.js | 3 ++ dom/html/ImageDocument.cpp | 9 ++++++ image/test/mochitest/mochitest.ini | 1 + .../mochitest/test_ImageContentLoaded.html | 28 ++++++++++++++++++ toolkit/content/browser-child.js | 17 +++++++++++ .../content/widgets/browser-custom-element.js | 29 +++++++++++++++++++ xpcom/ds/StaticAtoms.py | 1 + 7 files changed, 88 insertions(+) create mode 100644 image/test/mochitest/test_ImageContentLoaded.html diff --git a/devtools/client/responsive/browser/tunnel.js b/devtools/client/responsive/browser/tunnel.js index 6ea418df6f53..442007a3b873 100644 --- a/devtools/client/responsive/browser/tunnel.js +++ b/devtools/client/responsive/browser/tunnel.js @@ -30,6 +30,7 @@ const SWAPPED_BROWSER_STATE = [ "_contentTitle", "_characterSet", "_contentPrincipal", + "_imageDocument", "_isSyntheticDocument", "_innerWindowID", ]; @@ -103,6 +104,7 @@ function tunnelToInnerBrowser(outer, inner) { inner._contentTitle = outer._contentTitle; inner._characterSet = outer._characterSet; inner._contentPrincipal = outer._contentPrincipal; + inner._imageDocument = outer._imageDocument; inner._isSyntheticDocument = outer._isSyntheticDocument; inner._innerWindowID = outer._innerWindowID; inner._remoteWebNavigation._currentURI = @@ -457,6 +459,7 @@ MessageManagerTunnel.prototype = { "PageStyle:StyleSheets", // Messages sent to browser.js "DOMTitleChanged", + "ImageDocumentLoaded", "InPermitUnload", "PermitUnload", // Messages sent to SessionStore.jsm diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index 3533828b1ca1..0a9af1fea0a9 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -126,6 +126,15 @@ ImageListener::OnStartRequest(nsIRequest* request) { return MediaDocumentStreamListener::OnStartRequest(request); } +NS_IMETHODIMP +ImageListener::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) { + ImageDocument* imgDoc = static_cast(mDocument.get()); + nsContentUtils::DispatchChromeEvent(imgDoc, ToSupports(imgDoc), + NS_LITERAL_STRING("ImageContentLoaded"), + CanBubble::eYes, Cancelable::eYes); + return MediaDocumentStreamListener::OnStopRequest(aRequest, aStatus); +} + ImageDocument::ImageDocument() : MediaDocument(), mVisibleWidth(0.0), diff --git a/image/test/mochitest/mochitest.ini b/image/test/mochitest/mochitest.ini index 7e9004077811..d208f19c20a2 100644 --- a/image/test/mochitest/mochitest.ini +++ b/image/test/mochitest/mochitest.ini @@ -137,6 +137,7 @@ skip-if = verify [test_drawDiscardedImage.html] [test_error_events.html] [test_image_crossorigin_data_url.html] +[test_ImageContentLoaded.html] [test_has_transparency.html] [test_net_failedtoprocess.html] skip-if = verify diff --git a/image/test/mochitest/test_ImageContentLoaded.html b/image/test/mochitest/test_ImageContentLoaded.html new file mode 100644 index 000000000000..7a9c46b52413 --- /dev/null +++ b/image/test/mochitest/test_ImageContentLoaded.html @@ -0,0 +1,28 @@ + + + + +Test for Bug 691610 + + + + + + + diff --git a/toolkit/content/browser-child.js b/toolkit/content/browser-child.js index 981cda6725be..5d5acfc66996 100644 --- a/toolkit/content/browser-child.js +++ b/toolkit/content/browser-child.js @@ -52,6 +52,23 @@ addEventListener( false ); +addEventListener( + "ImageContentLoaded", + function(aEvent) { + if (content.document instanceof Ci.nsIImageDocument) { + let req = content.document.imageRequest; + if (!req.image) { + return; + } + sendAsyncMessage("ImageDocumentLoaded", { + width: req.image.width, + height: req.image.height, + }); + } + }, + false +); + // This is here for now until we find a better way of forcing an about:blank load // with a particular principal that doesn't involve the message manager. We can't // do this with JS Window Actors for now because JS Window Actors are tied to the diff --git a/toolkit/content/widgets/browser-custom-element.js b/toolkit/content/widgets/browser-custom-element.js index 8d8533d0b37c..2e0f9f1aa2f0 100644 --- a/toolkit/content/widgets/browser-custom-element.js +++ b/toolkit/content/widgets/browser-custom-element.js @@ -291,6 +291,8 @@ this._loadContext = null; + this._imageDocument = null; + this._webBrowserFind = null; this._finder = null; @@ -565,6 +567,24 @@ return this.docShellIsActive; } + get imageDocument() { + if (this.isRemoteBrowser) { + return this._imageDocument; + } + var document = this.contentDocument; + if (!document || !(document instanceof Ci.nsIImageDocument)) { + return null; + } + + try { + return { + width: document.imageRequest.image.width, + height: document.imageRequest.image.height, + }; + } catch (e) {} + return null; + } + get isRemoteBrowser() { return this.getAttribute("remote") == "true"; } @@ -1243,6 +1263,7 @@ this.messageManager.addMessageListener("Browser:Init", this); this.messageManager.addMessageListener("DOMTitleChanged", this); + this.messageManager.addMessageListener("ImageDocumentLoaded", this); let jsm = "resource://gre/modules/RemoteWebProgress.jsm"; let { RemoteWebProgressManager } = ChromeUtils.import(jsm, {}); @@ -1475,6 +1496,12 @@ case "DOMTitleChanged": this._contentTitle = data.title; break; + case "ImageDocumentLoaded": + this._imageDocument = { + width: data.width, + height: data.height, + }; + break; default: return this._receiveMessage(aMessage); } @@ -1574,6 +1601,7 @@ this._remoteWebNavigation._currentURI = aLocation; this._documentURI = aDocumentURI; this._contentTitle = aTitle; + this._imageDocument = null; this._contentPrincipal = aContentPrincipal; this._contentStoragePrincipal = aContentStoragePrincipal; this._contentBlockingAllowListPrincipal = aContentBlockingAllowListPrincipal; @@ -1923,6 +1951,7 @@ "_contentPrincipal", "_contentStoragePrincipal", "_contentBlockingAllowListPrincipal", + "_imageDocument", "_fullZoom", "_textZoom", "_isSyntheticDocument", diff --git a/xpcom/ds/StaticAtoms.py b/xpcom/ds/StaticAtoms.py index 4433f6fe6291..0c11553ed463 100644 --- a/xpcom/ds/StaticAtoms.py +++ b/xpcom/ds/StaticAtoms.py @@ -1913,6 +1913,7 @@ STATIC_ATOMS = [ Atom("onFullZoomChange", "onFullZoomChange"), Atom("onGloballyAutoplayBlocked", "onGloballyAutoplayBlocked"), Atom("onHiddenPlugin", "onHiddenPlugin"), + Atom("onImageContentLoaded", "onImageContentLoaded"), Atom("onMozApplicationManifest", "onMozApplicationManifest"), Atom("onMozDOMFullscreen_Entered", "onMozDOMFullscreen:Entered"), Atom("onMozDOMFullscreen_Exit", "onMozDOMFullscreen:Exit"),