2010-09-09 00:40:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
#include "SVGDocumentWrapper.h"
|
2011-10-15 11:33:26 +04:00
|
|
|
|
2019-04-16 05:47:26 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
|
|
|
#include "mozilla/SMILAnimationController.h"
|
2020-07-12 19:38:26 +03:00
|
|
|
#include "mozilla/SVGObserverUtils.h"
|
2021-01-04 17:20:22 +03:00
|
|
|
#include "mozilla/dom/Animation.h"
|
2019-04-16 05:47:26 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-02-22 16:05:20 +03:00
|
|
|
#include "mozilla/dom/DocumentTimeline.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2019-04-16 05:47:26 +03:00
|
|
|
#include "mozilla/dom/ImageTracker.h"
|
2018-04-21 19:48:29 +03:00
|
|
|
#include "mozilla/dom/SVGDocument.h"
|
2019-04-16 05:47:26 +03:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIChannel.h"
|
2023-11-21 15:45:59 +03:00
|
|
|
#include "nsIDocumentViewer.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIParser.h"
|
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2020-08-05 00:17:50 +03:00
|
|
|
#include "nsRefreshDriver.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-07-23 08:39:48 +03:00
|
|
|
|
|
|
|
using namespace dom;
|
|
|
|
using namespace gfx;
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(SVGDocumentWrapper, nsIStreamListener, nsIRequestObserver,
|
|
|
|
nsIObserver, nsISupportsWeakReference)
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2017-07-25 15:33:56 +03:00
|
|
|
SVGDocumentWrapper::SVGDocumentWrapper()
|
2021-04-29 17:15:01 +03:00
|
|
|
: mIgnoreInvalidation(false),
|
|
|
|
mRegisteredForXPCOMShutdown(false),
|
|
|
|
mIsDrawing(false) {}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
SVGDocumentWrapper::~SVGDocumentWrapper() {
|
|
|
|
DestroyViewer();
|
2010-11-08 20:45:18 +03:00
|
|
|
if (mRegisteredForXPCOMShutdown) {
|
|
|
|
UnregisterForXPCOMShutdown();
|
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::DestroyViewer() {
|
|
|
|
if (mViewer) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewer->GetDocument()->OnPageHide(false, nullptr);
|
|
|
|
mViewer->Close(nullptr);
|
2010-09-09 00:40:39 +04:00
|
|
|
mViewer->Destroy();
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewer = nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* SVGDocumentWrapper::GetRootLayoutFrame() {
|
|
|
|
Element* rootElem = GetRootSVGElem();
|
2012-07-30 18:20:58 +04:00
|
|
|
return rootElem ? rootElem->GetPrimaryFrame() : nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::UpdateViewportBounds(const nsIntSize& aViewportSize) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant");
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = true;
|
2012-11-08 23:54:47 +04:00
|
|
|
|
|
|
|
nsIntRect currentBounds;
|
|
|
|
mViewer->GetBounds(currentBounds);
|
2013-03-30 00:14:19 +04:00
|
|
|
|
2012-11-08 23:54:47 +04:00
|
|
|
// If the bounds have changed, we need to do a layout flush.
|
|
|
|
if (currentBounds.Size() != aViewportSize) {
|
2015-04-21 18:04:57 +03:00
|
|
|
mViewer->SetBounds(IntRect(IntPoint(0, 0), aViewportSize));
|
2012-11-08 23:54:47 +04:00
|
|
|
FlushLayout();
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = false;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2011-02-09 23:13:18 +03:00
|
|
|
void SVGDocumentWrapper::FlushImageTransformInvalidation() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant");
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!svgElem) {
|
2010-12-20 03:45:29 +03:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = true;
|
2011-02-09 23:13:18 +03:00
|
|
|
svgElem->FlushImageTransformInvalidation();
|
2010-12-20 03:45:29 +03:00
|
|
|
FlushLayout();
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = false;
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
bool SVGDocumentWrapper::IsAnimated() {
|
2016-03-06 23:59:19 +03:00
|
|
|
// Can be called for animated images during shutdown, after we've
|
|
|
|
// already Observe()'d XPCOM shutdown and cleared out our mViewer pointer.
|
|
|
|
if (!mViewer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = mViewer->GetDocument();
|
2016-02-22 16:05:20 +03:00
|
|
|
if (!doc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (doc->Timeline()->HasAnimations()) {
|
|
|
|
// CSS animations (technically HasAnimations() also checks for CSS
|
|
|
|
// transitions and Web animations but since SVG-as-an-image doesn't run
|
|
|
|
// script they will never run in the document that we wrap).
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (doc->HasAnimationController() &&
|
|
|
|
doc->GetAnimationController()->HasRegisteredAnimations()) {
|
|
|
|
// SMIL animations
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::StartAnimation() {
|
2010-12-20 21:44:05 +03:00
|
|
|
// Can be called for animated images during shutdown, after we've
|
|
|
|
// already Observe()'d XPCOM shutdown and cleared out our mViewer pointer.
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2010-12-20 21:44:05 +03:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-12-20 21:44:05 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = mViewer->GetDocument();
|
2010-11-06 22:13:01 +03:00
|
|
|
if (doc) {
|
2018-12-28 14:47:58 +03:00
|
|
|
SMILAnimationController* controller = doc->GetAnimationController();
|
2011-01-11 08:58:00 +03:00
|
|
|
if (controller) {
|
2019-01-02 10:21:13 +03:00
|
|
|
controller->Resume(SMILTimeContainer::PAUSE_IMAGE);
|
2011-01-11 08:58:00 +03:00
|
|
|
}
|
2016-10-13 10:04:19 +03:00
|
|
|
doc->ImageTracker()->SetAnimatingState(true);
|
2010-11-06 22:13:01 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::StopAnimation() {
|
2010-12-20 21:44:05 +03:00
|
|
|
// Can be called for animated images during shutdown, after we've
|
2010-09-09 00:40:39 +04:00
|
|
|
// already Observe()'d XPCOM shutdown and cleared out our mViewer pointer.
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2010-09-09 00:40:39 +04:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = mViewer->GetDocument();
|
2010-11-06 22:13:01 +03:00
|
|
|
if (doc) {
|
2018-12-28 14:47:58 +03:00
|
|
|
SMILAnimationController* controller = doc->GetAnimationController();
|
2011-01-11 08:58:00 +03:00
|
|
|
if (controller) {
|
2019-01-02 10:21:13 +03:00
|
|
|
controller->Pause(SMILTimeContainer::PAUSE_IMAGE);
|
2011-01-11 08:58:00 +03:00
|
|
|
}
|
2016-10-13 10:04:19 +03:00
|
|
|
doc->ImageTracker()->SetAnimatingState(false);
|
2010-11-06 22:13:01 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::ResetAnimation() {
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!svgElem) {
|
2010-09-09 00:40:39 +04:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2013-02-08 23:55:07 +04:00
|
|
|
svgElem->SetCurrentTime(0.0f);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:37:58 +03:00
|
|
|
float SVGDocumentWrapper::GetCurrentTimeAsFloat() {
|
2013-03-11 05:43:37 +04:00
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2018-12-21 08:37:58 +03:00
|
|
|
return svgElem ? svgElem->GetCurrentTimeAsFloat() : 0.0f;
|
2013-03-11 05:43:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::SetCurrentTime(float aTime) {
|
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2018-12-21 08:37:58 +03:00
|
|
|
if (svgElem && svgElem->GetCurrentTimeAsFloat() != aTime) {
|
2013-03-11 05:43:37 +04:00
|
|
|
svgElem->SetCurrentTime(aTime);
|
|
|
|
}
|
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2014-05-01 20:31:54 +04:00
|
|
|
void SVGDocumentWrapper::TickRefreshDriver() {
|
2019-04-16 05:47:26 +03:00
|
|
|
if (RefPtr<PresShell> presShell = mViewer->GetPresShell()) {
|
|
|
|
if (RefPtr<nsPresContext> presContext = presShell->GetPresContext()) {
|
2022-09-08 06:29:36 +03:00
|
|
|
if (RefPtr<nsRefreshDriver> driver = presContext->RefreshDriver()) {
|
|
|
|
driver->DoTick();
|
|
|
|
}
|
2014-05-01 20:31:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
/** nsIStreamListener methods **/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-02-28 02:42:27 +03:00
|
|
|
SVGDocumentWrapper::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* inStr,
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t sourceOffset, uint32_t count) {
|
2019-02-28 02:42:27 +03:00
|
|
|
return mListener->OnDataAvailable(aRequest, inStr, sourceOffset, count);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIRequestObserver methods **/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-02-28 02:41:04 +03:00
|
|
|
SVGDocumentWrapper::OnStartRequest(nsIRequest* aRequest) {
|
2010-09-09 00:40:39 +04:00
|
|
|
nsresult rv = SetupViewer(aRequest, getter_AddRefs(mViewer),
|
|
|
|
getter_AddRefs(mLoadGroup));
|
|
|
|
|
2019-02-28 02:41:04 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(mListener->OnStartRequest(aRequest))) {
|
2010-09-09 00:40:39 +04:00
|
|
|
mViewer->GetDocument()->SetIsBeingUsedAsImage();
|
2010-11-16 21:35:59 +03:00
|
|
|
StopAnimation(); // otherwise animations start automatically in helper doc
|
|
|
|
|
2019-08-08 19:07:12 +03:00
|
|
|
rv = mViewer->Init(nullptr, nsIntRect(0, 0, 0, 0), nullptr);
|
2010-09-09 00:40:39 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = mViewer->Open(nullptr, nullptr);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-02-28 02:41:31 +03:00
|
|
|
SVGDocumentWrapper::OnStopRequest(nsIRequest* aRequest, nsresult status) {
|
2010-09-09 00:40:39 +04:00
|
|
|
if (mListener) {
|
2019-02-28 02:41:31 +03:00
|
|
|
mListener->OnStopRequest(aRequest, status);
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIObserver Methods **/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SVGDocumentWrapper::Observe(nsISupports* aSubject, const char* aTopic,
|
2015-03-04 15:18:00 +03:00
|
|
|
const char16_t* aData) {
|
2010-09-09 00:40:39 +04:00
|
|
|
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
2010-11-16 21:35:59 +03:00
|
|
|
// Sever ties from rendering observers to helper-doc's root SVG node
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2010-11-16 21:35:59 +03:00
|
|
|
if (svgElem) {
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::RemoveAllRenderingObservers(svgElem);
|
2010-11-16 21:35:59 +03:00
|
|
|
}
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
// Clean up at XPCOM shutdown time.
|
|
|
|
DestroyViewer();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (mListener) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
|
|
|
if (mLoadGroup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadGroup = nullptr;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-11-10 08:50:29 +03:00
|
|
|
|
|
|
|
// Turn off "registered" flag, or else we'll try to unregister when we die.
|
|
|
|
// (No need for that now, and the try would fail anyway -- it's too late.)
|
2011-10-17 18:59:28 +04:00
|
|
|
mRegisteredForXPCOMShutdown = false;
|
2010-09-09 00:40:39 +04:00
|
|
|
} else {
|
|
|
|
NS_ERROR("Unexpected observer topic.");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Private helper methods **/
|
|
|
|
|
|
|
|
// This method is largely cribbed from
|
|
|
|
// nsExternalResourceMap::PendingLoad::SetupViewer.
|
|
|
|
nsresult SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest,
|
2023-11-21 15:45:59 +03:00
|
|
|
nsIDocumentViewer** aViewer,
|
2010-09-09 00:40:39 +04:00
|
|
|
nsILoadGroup** aLoadGroup) {
|
|
|
|
nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));
|
|
|
|
NS_ENSURE_TRUE(chan, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// Check for HTTP error page
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
|
|
|
|
if (httpChannel) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool requestSucceeded;
|
2010-09-09 00:40:39 +04:00
|
|
|
if (NS_FAILED(httpChannel->GetRequestSucceeded(&requestSucceeded)) ||
|
|
|
|
!requestSucceeded) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give this document its own loadgroup
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
chan->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> newLoadGroup =
|
|
|
|
do_CreateInstance(NS_LOADGROUP_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(newLoadGroup, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
newLoadGroup->SetLoadGroup(loadGroup);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(catMan, NS_ERROR_NOT_AVAILABLE);
|
2017-08-21 13:01:27 +03:00
|
|
|
nsCString contractId;
|
2013-01-09 01:40:47 +04:00
|
|
|
nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", IMAGE_SVG_XML,
|
2018-07-24 03:41:06 +03:00
|
|
|
contractId);
|
2010-09-09 00:40:39 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
|
2017-08-21 13:01:27 +03:00
|
|
|
do_GetService(contractId.get());
|
2010-09-09 00:40:39 +04:00
|
|
|
NS_ENSURE_TRUE(docLoaderFactory, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
2023-11-21 15:45:59 +03:00
|
|
|
nsCOMPtr<nsIDocumentViewer> viewer;
|
2010-09-09 00:40:39 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
rv = docLoaderFactory->CreateInstance(
|
|
|
|
"external-resource", chan, newLoadGroup, nsLiteralCString(IMAGE_SVG_XML),
|
|
|
|
nullptr, nullptr, getter_AddRefs(listener), getter_AddRefs(viewer));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-15 11:33:26 +04:00
|
|
|
NS_ENSURE_TRUE(viewer, NS_ERROR_UNEXPECTED);
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2016-09-02 13:53:36 +03:00
|
|
|
// Create a navigation time object and pass it to the SVG document through
|
|
|
|
// the viewer.
|
|
|
|
// The timeline(DocumentTimeline, used in CSS animation) of this SVG
|
|
|
|
// document needs this navigation timing object for time computation, such
|
|
|
|
// as to calculate current time stamp based on the start time of navigation
|
|
|
|
// time object.
|
|
|
|
//
|
|
|
|
// For a root document, DocShell would do these sort of things
|
|
|
|
// automatically. Since there is no DocShell for this wrapped SVG document,
|
|
|
|
// we must set it up manually.
|
2017-04-19 09:00:00 +03:00
|
|
|
RefPtr<nsDOMNavigationTiming> timing = new nsDOMNavigationTiming(nullptr);
|
2016-11-10 22:26:54 +03:00
|
|
|
timing->NotifyNavigationStart(
|
|
|
|
nsDOMNavigationTiming::DocShellState::eInactive);
|
2016-09-02 13:53:36 +03:00
|
|
|
viewer->SetNavigationTiming(timing);
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
nsCOMPtr<nsIParser> parser = do_QueryInterface(listener);
|
|
|
|
NS_ENSURE_TRUE(parser, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// XML-only, because this is for SVG content
|
2016-07-18 19:44:45 +03:00
|
|
|
nsCOMPtr<nsIContentSink> sink = parser->GetContentSink();
|
2010-09-09 00:40:39 +04:00
|
|
|
NS_ENSURE_TRUE(sink, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
listener.swap(mListener);
|
2011-10-15 11:33:26 +04:00
|
|
|
viewer.forget(aViewer);
|
|
|
|
newLoadGroup.forget(aLoadGroup);
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
RegisterForXPCOMShutdown();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::RegisterForXPCOMShutdown() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mRegisteredForXPCOMShutdown, "re-registering for XPCOM shutdown");
|
2010-09-09 00:40:39 +04:00
|
|
|
// Listen for xpcom-shutdown so that we can drop references to our
|
|
|
|
// helper-document at that point. (Otherwise, we won't get cleaned up
|
|
|
|
// until imgLoader::Shutdown, which can happen after the JAR service
|
|
|
|
// and RDF service have been unregistered.)
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = do_GetService(OBSERVER_SVC_CID, &rv);
|
|
|
|
if (NS_FAILED(rv) || NS_FAILED(obsSvc->AddObserver(
|
|
|
|
this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true))) {
|
|
|
|
NS_WARNING("Failed to register as observer of XPCOM shutdown");
|
2010-11-08 20:45:18 +03:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mRegisteredForXPCOMShutdown = true;
|
2010-11-08 20:45:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::UnregisterForXPCOMShutdown() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mRegisteredForXPCOMShutdown,
|
|
|
|
"unregistering for XPCOM shutdown w/out being registered");
|
2010-11-08 20:45:18 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = do_GetService(OBSERVER_SVC_CID, &rv);
|
|
|
|
if (NS_FAILED(rv) ||
|
|
|
|
NS_FAILED(obsSvc->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
|
|
|
|
NS_WARNING("Failed to unregister as observer of XPCOM shutdown");
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mRegisteredForXPCOMShutdown = false;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVGDocumentWrapper::FlushLayout() {
|
2018-04-21 19:48:29 +03:00
|
|
|
if (SVGDocument* doc = GetDocument()) {
|
2018-01-20 01:51:30 +03:00
|
|
|
doc->FlushPendingNotifications(FlushType::Layout);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 06:04:08 +04:00
|
|
|
SVGDocument* SVGDocumentWrapper::GetDocument() {
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2013-02-14 06:04:08 +04:00
|
|
|
return nullptr;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = mViewer->GetDocument();
|
2018-04-21 19:48:29 +03:00
|
|
|
if (!doc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return doc->AsSVGDocument();
|
2013-02-14 06:04:08 +04:00
|
|
|
}
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
SVGSVGElement* SVGDocumentWrapper::GetRootSVGElem() {
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; // Can happen during destruction
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:40 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = mViewer->GetDocument();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!doc) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; // Can happen during destruction
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:40 +04:00
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
Element* rootElem = mViewer->GetDocument()->GetRootElement();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!rootElem || !rootElem->IsSVGElement(nsGkAtoms::svg)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
return static_cast<SVGSVGElement*>(rootElem);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-09-09 00:40:39 +04:00
|
|
|
} // namespace mozilla
|